Revision 1495

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/pom.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 3
    <modelVersion>4.0.0</modelVersion>
4
    <groupId>org.gvsig</groupId>    
4
    <groupId>org.gvsig</groupId>
5 5
    <artifactId>org.gvsig.tools</artifactId>
6 6
    <packaging>pom</packaging>
7 7
    <version>3.0.105-SNAPSHOT</version>
8 8
    <name>org.gvsig.tools</name>
9
    <description>Tools related to application framework architecture 
9
    <description>Tools related to application framework architecture
10 10
        and implementations of design patterns</description>
11 11

  
12 12

  
......
23 23
            </comments>
24 24
        </license>
25 25
    </licenses>
26
    
26

  
27 27
    <organization>
28 28
        <name>gvSIG Association</name>
29 29
        <url>http://www.gvsig.com/</url>
30 30
    </organization>
31
    
31

  
32 32
    <scm>
33 33
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-tools/org.gvsig.tools/library/trunk/org.gvsig.tools</connection>
34 34
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-tools/org.gvsig.tools/library/trunk/org.gvsig.tools</developerConnection>
......
52 52
            </snapshots>
53 53
        </repository>
54 54
    </repositories>
55
    
55

  
56 56
    <distributionManagement>
57 57
        <site>
58 58
            <id>gvsig-repository</id>
......
71 71
            <uniqueVersion>false</uniqueVersion>
72 72
        </snapshotRepository>
73 73
    </distributionManagement>
74
    
74

  
75 75
    <issueManagement>
76 76
        <system>redmine</system>
77 77
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop</url>
......
112 112
            </otherArchives>
113 113
        </mailingList>
114 114
    </mailingLists>
115
    
115

  
116 116
    <developers>
117 117
        <developer>
118 118
            <id>jjdelcerro</id>
......
183 183
            <dependency>
184 184
                <groupId>org.apache.commons</groupId>
185 185
                <artifactId>commons-lang3</artifactId>
186
                <version>3.5</version>    
186
                <version>3.5</version>
187 187
            </dependency>
188 188
            <dependency>
189 189
                <groupId>net.sf</groupId>
......
209 209
                <groupId>com.jeta</groupId>
210 210
                <artifactId>formsrt</artifactId>
211 211
                <version>2.1.0_M3-1</version>
212
            </dependency>                
212
            </dependency>
213 213
            <dependency>
214 214
                <groupId>org.gvsig</groupId>
215 215
                <artifactId>org.gvsig.tools.lib</artifactId>
......
220 220
                <artifactId>org.gvsig.tools.lib</artifactId>
221 221
                <version>3.0.105-SNAPSHOT</version>
222 222
                <type>test-jar</type>
223
                <scope>test</scope>                    
224
            </dependency>        
223
                <scope>test</scope>
224
            </dependency>
225 225
            <dependency>
226 226
                <groupId>org.gvsig</groupId>
227 227
                <artifactId>org.gvsig.tools.swing</artifactId>
......
280 280
            <groupId>junit</groupId>
281 281
            <artifactId>junit</artifactId>
282 282
            <scope>test</scope>
283
        </dependency>        
283
        </dependency>
284 284
    </dependencies>
285 285

  
286 286
    <build>
......
291 291
                <version>2.4</version>
292 292
            </extension>
293 293
        </extensions>
294
        
294

  
295 295
        <pluginManagement>
296 296
            <plugins>
297 297
                <plugin>
298 298
                    <groupId>org.apache.maven.plugins</groupId>
299 299
                    <artifactId>maven-deploy-plugin</artifactId>
300 300
                    <version>2.6</version>
301
                </plugin>        
301
                </plugin>
302 302
                <plugin>
303 303
                    <groupId>org.apache.maven.plugins</groupId>
304 304
                    <artifactId>maven-surefire-plugin</artifactId>
......
326 326
                        <encoding>ISO-8859-1</encoding>
327 327
                    </configuration>
328 328
                </plugin>
329
        
329

  
330 330
                <plugin>
331 331
                    <groupId>org.apache.maven.plugins</groupId>
332 332
                    <artifactId>maven-javadoc-plugin</artifactId>
......
354 354
                        </javaApiLinks>
355 355
                    </configuration>
356 356
                </plugin>
357
        
357

  
358 358
                <plugin>
359 359
                    <groupId>org.apache.maven.plugins</groupId>
360 360
                    <artifactId>maven-site-plugin</artifactId>
......
363 363
                        <chmodMode>a+rwX</chmodMode>
364 364
                    </configuration>
365 365
                </plugin>
366
          
366

  
367 367
                <plugin>
368 368
                    <groupId>org.apache.maven.plugins</groupId>
369 369
                    <artifactId>maven-jar-plugin</artifactId>
......
376 376
                        </archive>
377 377
                    </configuration>
378 378
                </plugin>
379
          
379

  
380 380
                <plugin>
381 381
                    <groupId>org.codehaus.mojo</groupId>
382 382
                    <artifactId>properties-maven-plugin</artifactId>
383 383
                    <version>1.0-alpha-2</version>
384 384
                </plugin>
385
  
385

  
386 386
                <plugin>
387 387
                    <groupId>org.codehaus.gmaven</groupId>
388 388
                    <artifactId>gmaven-plugin</artifactId>
389 389
                    <version>1.4</version>
390 390
                </plugin>
391
  
391

  
392 392
                <plugin>
393 393
                    <groupId>org.apache.maven.plugins</groupId>
394 394
                    <artifactId>maven-antrun-plugin</artifactId>
......
418 418
                    <artifactId>maven-clean-plugin</artifactId>
419 419
                    <version>2.4.1</version>
420 420
                </plugin>
421
          
421

  
422 422
                <plugin>
423 423
                    <groupId>org.codehaus.mojo</groupId>
424 424
                    <artifactId>exec-maven-plugin</artifactId>
425 425
                    <version>1.2</version>
426
                </plugin>    
426
                </plugin>
427 427

  
428 428
                <plugin>
429 429
                    <groupId>com.mycila.maven-license-plugin</groupId>
430 430
                    <artifactId>maven-license-plugin</artifactId>
431 431
                    <version>1.10.b1</version>
432
                </plugin>    
432
                </plugin>
433 433

  
434 434
                <plugin>
435 435
                    <groupId>org.apache.maven.plugins</groupId>
......
439 439

  
440 440
            </plugins>
441 441
        </pluginManagement>
442
      
442

  
443 443
        <plugins>
444 444
            <plugin>
445 445
                <groupId>org.apache.maven.plugins</groupId>
446 446
                <artifactId>maven-release-plugin</artifactId>
447 447
                <configuration>
448 448
                    <tagBase>https://devel.gvsig.org/svn/gvsig-tools/org.gvsig.tools/library/tags</tagBase>
449
                    <!-- This is a 2.0 beta 6 bug. By default the goals are 'clean verify', so the modules  
450
                    are not installed, so the dependencies between modules are not met. With this configuration   
451
                    we force the module installation. -->  
452
                    <preparationGoals>clean install</preparationGoals>  
449
                    <!-- This is a 2.0 beta 6 bug. By default the goals are 'clean verify', so the modules
450
                    are not installed, so the dependencies between modules are not met. With this configuration
451
                    we force the module installation. -->
452
                    <preparationGoals>clean install</preparationGoals>
453 453
                    <autoVersionSubmodules>true</autoVersionSubmodules>
454 454
                    <goals>deploy</goals>
455 455
                </configuration>
456 456
            </plugin>
457
            
457

  
458 458
            <plugin>
459 459
                <groupId>org.codehaus.mojo</groupId>
460 460
                <artifactId>animal-sniffer-maven-plugin</artifactId>
......
476 476
                    </execution>
477 477
                </executions>
478 478
            </plugin>
479
                        
479

  
480 480
            <plugin>
481 481
                <!-- to continue building  when test fail -->
482 482
                <groupId>org.apache.maven.plugins</groupId>
......
487 487
            </plugin>
488 488
        </plugins>
489 489
    </build>
490
    
490

  
491 491
    <reporting>
492 492
        <excludeDefaults>true</excludeDefaults>
493 493
        <plugins>
......
511 511
            </plugin>
512 512
        </plugins>
513 513
    </reporting>
514
	
515
  
514

  
515

  
516 516
    <properties>
517 517
        <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
518 518
        <localRepository>${user.home}/.m2/repository</localRepository>
519 519
        <site-repository>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</site-repository>
520 520

  
521 521
    </properties>
522
    
522

  
523 523
    <profiles>
524 524
        <profile>
525 525
            <id>cdc</id>
......
542 542
                        <checksumPolicy>warn</checksumPolicy>
543 543
                    </snapshots>
544 544
                </repository>
545
                <!-- 
545
                <!--
546 546
                <repository>
547 547
                    <id>osgeo</id>
548 548
                    <name>Open Source Geospatial Foundation</name>
......
589 589
                <module>org.gvsig.tools.swing</module>
590 590
                <module>org.gvsig.tools.main</module>
591 591
                <module>org.gvsig.tools.dynform</module>
592
                <module>org.gvsig.tools.util</module>
592 593
            </modules>
593 594
        </profile>
594 595
    </profiles>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.tools.util.ToolsUtilLibrary
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/java/org/gvsig/tools/util/ToolsUtilLocator.java
1
package org.gvsig.tools.util;
2
/**
3
 * gvSIG. Desktop Geographic Information System.
4
 *
5
 * Copyright (C) 2007-2013 gvSIG Association.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 3
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 * For any additional information, do not hesitate to contact us
23
 * at info AT gvsig.com, or visit our website www.gvsig.com.
24
 */
25

  
26

  
27
import org.gvsig.tools.locator.AbstractLocator;
28
import org.gvsig.tools.locator.Locator;
29
import org.gvsig.tools.locator.LocatorException;
30

  
31
/**
32
 * @author fdiaz
33
 *
34
 */
35
@SuppressWarnings("rawtypes")
36
public class ToolsUtilLocator extends AbstractLocator {
37

  
38
	private static final String LOCATOR_NAME = "ToolsUtilLocator";
39

  
40
	public static final String TOOLS_UTIL_MANAGER_NAME =
41
			"org.gvsig.tools.util.manager";
42

  
43
	private static final String TOOLS_UTIL_MANAGER_DESCRIPTION =
44
			"Tools utilities.";
45

  
46
	private static final ToolsUtilLocator instance = new ToolsUtilLocator();
47

  
48
	private ToolsUtilLocator() {
49

  
50
	}
51

  
52
	/**
53
	 * Return the singleton instance.
54
	 *
55
	 * @return the singleton instance
56
	 */
57
	public static ToolsUtilLocator getInstance() {
58
		return instance;
59
	}
60

  
61
	public String getLocatorName() {
62
		return LOCATOR_NAME;
63
	}
64

  
65
	/**
66
	 * Return a reference to ToolsUtilManager.
67
	 *
68
	 * @return a reference to ToolsUtilManager
69
	 * @throws LocatorException
70
	 *             if there is no access to the class or the class cannot be
71
	 *             instantiated
72
	 * @see Locator#get(String)
73
	 */
74
	public static ToolsUtilManager getToolsUtilManager()
75
			throws LocatorException {
76
		return (ToolsUtilManager) getInstance().get(TOOLS_UTIL_MANAGER_NAME);
77
	}
78

  
79
	/**
80
	 * Registers the Class implementing the ToolsUtilManager interface.
81
	 *
82
	 * @param clazz
83
	 *            implementing the ToolsUtilManager interface
84
	 */
85
	public static void registerToolsUtilManager(Class clazz) {
86
		getInstance().register(TOOLS_UTIL_MANAGER_NAME,
87
		    TOOLS_UTIL_MANAGER_DESCRIPTION, clazz);
88
	}
89

  
90
	public static void registerDefaultToolsUtilManager(Class clazz) {
91
		getInstance().registerDefault(TOOLS_UTIL_MANAGER_NAME,
92
		    TOOLS_UTIL_MANAGER_DESCRIPTION, clazz);
93
	}
94

  
95

  
96
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/java/org/gvsig/tools/util/ToolsUtilLibrary.java
1
package org.gvsig.tools.util;
2

  
3
import org.gvsig.tools.ToolsLibrary;
4
import org.gvsig.tools.library.AbstractLibrary;
5
import org.gvsig.tools.library.LibraryException;
6
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
7

  
8
/**
9
 * gvSIG. Desktop Geographic Information System.
10
 *
11
 * Copyright (C) 2007-2013 gvSIG Association.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 3
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26
 * MA  02110-1301, USA.
27
 *
28
 * For any additional information, do not hesitate to contact us
29
 * at info AT gvsig.com, or visit our website www.gvsig.com.
30
 */
31

  
32

  
33

  
34
@SuppressWarnings("unchecked")
35
public class ToolsUtilLibrary extends AbstractLibrary {
36

  
37
	public void doRegistration() {
38
		super.doRegistration();
39
		registerAsAPI(ToolsUtilLibrary.class);
40
		this.require(ToolsLibrary.class);
41
	}
42

  
43
	protected void doInitialize() throws LibraryException {
44

  
45
	}
46

  
47
	protected void doPostInitialize() throws LibraryException {
48
		  // Validate there is any implementation registered.
49
        ToolsUtilManager manager = ToolsUtilLocator.getToolsUtilManager();
50
        if (manager == null) {
51
            throw new ReferenceNotRegisteredException(
52
            		ToolsUtilLocator.TOOLS_UTIL_MANAGER_NAME, ToolsUtilLocator
53
                    .getInstance());
54
        }
55

  
56
	}
57

  
58
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/java/org/gvsig/tools/util/ToolsUtilManager.java
1
package org.gvsig.tools.util;
2
/**
3
 * gvSIG. Desktop Geographic Information System.
4
 *
5
 * Copyright (C) 2007-2013 gvSIG Association.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 3
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 * MA  02110-1301, USA.
21
 *
22
 * For any additional information, do not hesitate to contact us
23
 * at info AT gvsig.com, or visit our website www.gvsig.com.
24
 */
25

  
26

  
27
import java.util.List;
28

  
29
import org.gvsig.tools.dynobject.DynObject;
30
import org.gvsig.tools.dynobject.DynObjectSet;
31
import org.gvsig.tools.dynobject.DynStruct;
32
import org.gvsig.tools.service.Manager;
33
import org.gvsig.tools.service.ServiceException;
34

  
35
public interface ToolsUtilManager extends Manager {
36

  
37
	/**
38
	 * @return
39
	 */
40
	public InformationBuilder createInformationBuilder();
41

  
42
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/java/org/gvsig/tools/util/InformationBuilder.java
1
package org.gvsig.tools.util;
2

  
3
public interface InformationBuilder {
4

  
5
    public interface Element {
6

  
7
        public String build();
8
    }
9

  
10
    public interface TitleElement extends Element {
11

  
12
        public TitleElement label(String label);
13
        public TitleElement labelkey(String labelkey);
14
    }
15

  
16
    public interface RawElement extends Element {
17

  
18
        public RawElement value(String format, Object... args);
19
    }
20

  
21
    public interface TextElement extends RawElement {
22

  
23
        @Override
24
        public TextElement value(String format, Object... args);
25

  
26
    }
27

  
28
    public interface PropertyElement extends TextElement {
29

  
30
        public PropertyElement monospace();
31

  
32
        public PropertyElement label(String label);
33

  
34
        public PropertyElement labelkey(String labelkey);
35

  
36
        @Override
37
        public PropertyElement value(String format, Object... args);
38

  
39
    }
40

  
41
    public InformationBuilder backgroundColor(String color);
42

  
43
    public InformationBuilder backgroundColorTitle(String color);
44

  
45
    public InformationBuilder backgroundColorPropertyLabel(String color);
46

  
47
    public InformationBuilder backgroundColorPropertyValue1(String color);
48

  
49
    public InformationBuilder backgroundColorPropertyValue2(String color);
50

  
51
    public TitleElement title();
52

  
53
    public PropertyElement property();
54

  
55
    public TextElement text();
56

  
57
    public RawElement raw();
58

  
59
    public String build();
60

  
61
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.tools.util</artifactId>
6
    <version>3.0.105-SNAPSHOT</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.tools.util.api</artifactId>
10
  <version>3.0.105-SNAPSHOT</version>
11
  <name>org.gvsig.tools.util.api</name>
12
  <dependencies>
13
    <dependency>
14
      <groupId>org.gvsig</groupId>
15
      <artifactId>org.gvsig.tools.lib</artifactId>
16
    </dependency>
17
  </dependencies>
18
</project>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.tools</artifactId>
6
    <version>3.0.105-SNAPSHOT</version>
7
  </parent>
8
  <artifactId>org.gvsig.tools.util</artifactId>
9
  <name>org.gvsig.tools.util</name>
10
  <packaging>pom</packaging>
11
  <modules>
12
    <module>org.gvsig.tools.util.api</module>
13
    <module>org.gvsig.tools.util.impl</module>
14
  </modules>
15
</project>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/tools/util/impl/DefaultInformationBuilder.java
1
package org.gvsig.tools.util.impl;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.apache.commons.lang3.StringEscapeUtils;
7
import org.apache.commons.lang3.StringUtils;
8

  
9
import org.gvsig.tools.ToolsLocator;
10
import org.gvsig.tools.util.InformationBuilder;
11

  
12
/**
13
 * @author fdiaz
14
 *
15
 */
16
public class DefaultInformationBuilder implements InformationBuilder {
17

  
18
    private String backgroundColor = "\"#FFFFFF\"";
19
    private String backgroundColorTitle = "\"#FBFFE1\""; // light yellow
20
    private String backgroundColorPropertyLabel = "\"#D6D6D6\""; // Gris
21
    private String backgroundColorPropertyValue1 = "\"#FEEDD6\""; // light salmon
22
    private String backgroundColorPropertyValue2 = "\"#EAEAEA\""; // light grey
23

  
24
    protected int propertyCount = 0;
25
    protected final List<Element> elements;
26

  
27
    private class DefaultTitleElement implements TitleElement {
28

  
29
        protected String label;
30

  
31
        @Override
32
        public DefaultTitleElement label(String label) {
33
            this.label = StringEscapeUtils.escapeHtml3(label);
34
            return this;
35
        }
36

  
37
        @Override
38
        public TitleElement labelkey(String labelkey) {
39
            return label(ToolsLocator.getI18nManager().getTranslation(labelkey));
40
        }
41

  
42
        @Override
43
        public String build() {
44
            propertyCount = 0;
45
            return "<tr valign=\"middle\" >"
46
                    + "<td bgcolor=" + backgroundColorTitle + " align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\"><b> " + this.label + "</b></font></td>"
47
                    + "</tr>";
48
        }
49
    }
50

  
51
    protected class DefaultRawElement implements RawElement {
52

  
53
        protected String value;
54

  
55
        @Override
56
        public RawElement value(String format, Object... args) {
57
            if (args == null) {
58
                this.value = format;
59
            } else {
60
                this.value = String.format(format, args);
61
            }
62
            return this;
63
        }
64

  
65
        @Override
66
        public String build() {
67
            String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2;
68
            String content = "<tr valign=\"top\">\n";
69
            content += "<td bgcolor=" + color + "align=\"left\" colspan=\"2\"><font face=\"Arial\" size=\"3\"><div>" + value.replace("\\n",  "<br>\n") + "</div></font></td>\n";
70
            content += "</tr>\n";
71
            return content;
72
        }
73
    }
74

  
75
    protected class DefaultTextElement extends DefaultRawElement implements TextElement {
76

  
77
        @Override
78
        public TextElement value(String format, Object... args) {
79
            if (args == null) {
80
                this.value = StringEscapeUtils.escapeHtml3(format);
81
            } else {
82
                this.value = StringEscapeUtils.escapeHtml3(String.format(format, args));
83
            }
84
            return this;
85
        }
86

  
87
        @Override
88
        public String build() {
89
            String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2;
90
            String content = "<tr valign=\"top\">\n";
91
            content += "<td bgcolor=" + color + "align=\"left\" colspan=\"2\"><font face=\"Arial\" size=\"3\">" + value.replace("\n",  "<br>\n") + "</font></td>\n";
92
            content += "</tr>\n";
93
            return content;
94
        }
95
    }
96

  
97
    protected class DefaultPropertyElement extends DefaultTextElement implements PropertyElement {
98

  
99
        protected String label;
100
        protected boolean monospace = false;
101

  
102
        @Override
103
        public DefaultPropertyElement label(String label) {
104
            this.label = StringEscapeUtils.escapeHtml3(label);
105
            return this;
106
        }
107

  
108
        @Override
109
        public PropertyElement labelkey(String labelkey) {
110
            return label(ToolsLocator.getI18nManager().getTranslation(labelkey));
111
        }
112

  
113
        @Override
114
        public String build() {
115
            String color = ((propertyCount++ % 2) == 0) ? backgroundColorPropertyValue1 : backgroundColorPropertyValue2;
116
            String content = "<tr valign=\"top\">\n";
117
            if (!StringUtils.isEmpty(label)) {
118
                content += "<td nowrap bgcolor=" + backgroundColorPropertyLabel + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + label + ":&nbsp;</font></td>\n";
119
            }
120
            if( this.monospace ) {
121
                content += "<td bgcolor=" + color + "align=\"left\"><font face=\"Monospaced\" size=\"3\">" + value.replace("\\n",  "<br>\n") + "</font></td>";
122
            } else {
123
                content += "<td bgcolor=" + color + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value.replace("\\n",  "<br>\n") + "</font></td>";
124
            }
125
            content += "</tr>\n";
126
            return content;
127
        }
128

  
129
        @Override
130
        public PropertyElement value(String format, Object... args) {
131
            return (PropertyElement) super.value(format, args);
132
        }
133

  
134
        @Override
135
        public PropertyElement monospace() {
136
            this.monospace = true;
137
            return this;
138
        }
139
    }
140

  
141
    public DefaultInformationBuilder() {
142
        this.elements = new ArrayList<>();
143
    }
144

  
145
    @Override
146
    public DefaultInformationBuilder backgroundColor(String color) {
147
        this.backgroundColor = color;
148
        return this;
149
    }
150

  
151
    @Override
152
    public DefaultInformationBuilder backgroundColorTitle(String color) {
153
        this.backgroundColorTitle = color;
154
        return this;
155
    }
156

  
157
    @Override
158
    public DefaultInformationBuilder backgroundColorPropertyLabel(String color) {
159
        this.backgroundColorPropertyLabel = color;
160
        return this;
161
    }
162

  
163
    @Override
164
    public DefaultInformationBuilder backgroundColorPropertyValue1(String color) {
165
        this.backgroundColorPropertyValue1 = color;
166
        return this;
167
    }
168

  
169
    @Override
170
    public DefaultInformationBuilder backgroundColorPropertyValue2(String color) {
171
        this.backgroundColorPropertyValue2 = color;
172
        return this;
173
    }
174

  
175
    @Override
176
    public TitleElement title() {
177
        TitleElement element = new DefaultTitleElement();
178
        this.elements.add(element);
179
        return element;
180
    }
181

  
182
    @Override
183
    public PropertyElement property() {
184
        PropertyElement element = new DefaultPropertyElement();
185
        this.elements.add(element);
186
        return element;
187
    }
188

  
189
    @Override
190
    public TextElement text() {
191
        TextElement element = new DefaultTextElement();
192
        this.elements.add(element);
193
        return element;
194
    }
195

  
196
    @Override
197
    public RawElement raw() {
198
        RawElement element = new DefaultRawElement();
199
        this.elements.add(element);
200
        return element;
201
    }
202

  
203
    @Override
204
    public String build() {
205
        StringBuilder html = new StringBuilder();
206
        html.append("<html>\n");
207
        html.append("<body bgcolor=").append(backgroundColor).append(" topmargin=\"0\" marginheight=\"0\">\n");
208
        html.append("<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">");
209
        boolean first = true;
210
        for (Element element : elements) {
211
            if( element instanceof TitleElement ) {
212
                if( first ) {
213
                    first = false;
214
                } else {
215
                    html.append("<tr>\n<td><br></td>\n<td></td></tr>\n");
216
                }
217
            }
218
            html.append(element.build());
219
        }
220
        html.append("</table>");
221
        html.append("</body>");
222
        html.append("</html>");
223
        return html.toString();
224
    }
225

  
226
    @Override
227
    public String toString() {
228
        return this.build();
229
    }
230
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.tools.util.ToolsUtilLibraryImpl
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.tools.util</artifactId>
6
    <version>3.0.105-SNAPSHOT</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.tools.util.impl</artifactId>
10
  <version>3.0.105-SNAPSHOT</version>
11
  <name>org.gvsig.tools.util.impl</name>
12
  <dependencies>
13
    <dependency>
14
      <groupId>org.apache.commons</groupId>
15
      <artifactId>commons-lang3</artifactId>
16
    </dependency>
17
    <dependency>
18
      <groupId>org.gvsig</groupId>
19
      <artifactId>org.gvsig.tools.lib</artifactId>
20
    </dependency>
21
    <dependency>
22
      <groupId>org.gvsig</groupId>
23
      <artifactId>org.gvsig.tools.util.api</artifactId>
24
      <version>3.0.105-SNAPSHOT</version>
25
    </dependency>
26
  </dependencies>
27
</project>

Also available in: Unified diff