Revision 817
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
|
|
3 |
<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"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.sldsupport</artifactId> |
|
6 |
|
|
7 |
<packaging>pom</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description>SLD read/write support for importing/exporting symbols and legends</description> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.sld</artifactId> |
|
13 |
<version>2.0.154</version> |
|
14 |
</parent> |
|
15 |
|
|
16 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-sldtools</url> |
|
17 |
|
|
18 |
<scm> |
|
19 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport</connection> |
|
20 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport</developerConnection> |
|
21 |
<url>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport</url> |
|
22 |
</scm> |
|
23 |
|
|
24 |
<build> |
|
25 |
<plugins> |
|
26 |
<plugin> |
|
27 |
<groupId>org.apache.maven.plugins</groupId> |
|
28 |
<artifactId>maven-release-plugin</artifactId> |
|
29 |
<configuration> |
|
30 |
<tagBase>https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sldsupport/tags/</tagBase> |
|
31 |
<goals>deploy</goals> |
|
32 |
</configuration> |
|
33 |
</plugin> |
|
34 |
|
|
35 |
<plugin> |
|
36 |
<groupId>org.codehaus.mojo</groupId> |
|
37 |
<artifactId>animal-sniffer-maven-plugin</artifactId> |
|
38 |
<configuration> |
|
39 |
<skip>true</skip> |
|
40 |
</configuration> |
|
41 |
</plugin> |
|
42 |
|
|
43 |
</plugins> |
|
44 |
</build> |
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
<dependencies> |
|
51 |
|
|
52 |
<dependency> |
|
53 |
<groupId>org.gvsig</groupId> |
|
54 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
55 |
<type>test-jar</type> |
|
56 |
</dependency> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
60 |
<type>test-jar</type> |
|
61 |
</dependency> |
|
62 |
|
|
63 |
</dependencies> |
|
64 |
|
|
65 |
<modules> |
|
66 |
<module>org.gvsig.sldsupport.lib</module> |
|
67 |
</modules> |
|
68 |
</project> |
|
69 |
|
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2013 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 3 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<!-- |
|
30 |
Log4J configuration file for unit tests execution. |
|
31 |
--> |
|
32 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
33 |
|
|
34 |
<!-- Appender configuration to show logging messages through the console --> |
|
35 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
36 |
<layout class="org.apache.log4j.PatternLayout"> |
|
37 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
38 |
</layout> |
|
39 |
</appender> |
|
40 |
|
|
41 |
<!-- |
|
42 |
Activate logging messages of DEBUG level of higher only for the |
|
43 |
org.gvsig.tools packages. |
|
44 |
You can put full classes names or packages instead, to configure |
|
45 |
logging for all the classes and subpackages of the package. |
|
46 |
--> |
|
47 |
<category name="org.gvsig.tools"> |
|
48 |
<priority value="DEBUG" /> |
|
49 |
</category> |
|
50 |
<category name="org.gvsig.symbology"> |
|
51 |
<priority value="DEBUG" /> |
|
52 |
</category> |
|
53 |
|
|
54 |
<!-- |
|
55 |
By default, show only logging messages of INFO level or higher, |
|
56 |
through the previously configured CONSOLE appender. |
|
57 |
--> |
|
58 |
<root> |
|
59 |
<priority value="INFO" /> |
|
60 |
<appender-ref ref="CONSOLE" /> |
|
61 |
</root> |
|
62 |
</log4j:configuration> |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.sldsupport.impl.SLDSupportDefaultLibrary |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/SLDSupportDefaultLibrary.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl; |
|
27 |
|
|
28 |
import org.gvsig.sldsupport.SLDSupportLibrary; |
|
29 |
import org.gvsig.sldsupport.SLDSupportLocator; |
|
30 |
import org.gvsig.sldsupport.SLDSupportManager; |
|
31 |
import org.gvsig.sldsupport.impl.reader.DefaultSLDReaderFactory; |
|
32 |
import org.gvsig.sldsupport.impl.writer.DefaultSLDWriterFactory; |
|
33 |
import org.gvsig.tools.library.AbstractLibrary; |
|
34 |
import org.gvsig.tools.library.LibraryException; |
|
35 |
|
|
36 |
public class SLDSupportDefaultLibrary extends AbstractLibrary { |
|
37 |
|
|
38 |
@Override |
|
39 |
public void doRegistration() { |
|
40 |
registerAsImplementationOf(SLDSupportLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
|
|
46 |
SLDSupportLocator.getInstance().registerSLDSupportManager( |
|
47 |
DefaultSLDSupportManager.class); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void doPostInitialize() throws LibraryException { |
|
52 |
SLDSupportManager man = |
|
53 |
SLDSupportLocator.getInstance().getSLDSupportManager(); |
|
54 |
|
|
55 |
man.registerReader(new DefaultSLDReaderFactory("1.0.0")); |
|
56 |
man.registerReader(new DefaultSLDReaderFactory("1.1.0")); |
|
57 |
|
|
58 |
man.registerWriter(new DefaultSLDWriterFactory("1.0.0")); |
|
59 |
man.registerWriter(new DefaultSLDWriterFactory("1.1.0")); |
|
60 |
} |
|
61 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/parser/ExtendedKXmlParser.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.parser; |
|
27 |
|
|
28 |
import org.kxml2.io.KXmlParser; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
31 |
import org.xmlpull.v1.XmlPullParser; |
|
32 |
import org.xmlpull.v1.XmlPullParserException; |
|
33 |
|
|
34 |
/** |
|
35 |
* Overrides getName() method to get name without namespace (if namespace |
|
36 |
* exists) |
|
37 |
* Addes getLongName() to get name with namespace (if namespace exists) |
|
38 |
* |
|
39 |
* @author jldominguez |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class ExtendedKXmlParser extends KXmlParser { |
|
43 |
|
|
44 |
private static Logger logger = LoggerFactory |
|
45 |
.getLogger(ExtendedKXmlParser.class); |
|
46 |
|
|
47 |
public ExtendedKXmlParser() { |
|
48 |
super(); |
|
49 |
/* |
|
50 |
* Ensure super.getName() gets 'namespace:name' |
|
51 |
*/ |
|
52 |
try { |
|
53 |
this.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); |
|
54 |
} catch (XmlPullParserException e) { |
|
55 |
// This should not happen... |
|
56 |
logger.info("While setting property in ExtendedKXmlParser.", e); |
|
57 |
} |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* |
|
63 |
* Returns name without namespace |
|
64 |
* |
|
65 |
* @return |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public String getName() { |
|
69 |
return this.getSimpleName(); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Gets name with namespace |
|
74 |
* |
|
75 |
* @return |
|
76 |
*/ |
|
77 |
public String getLongName() { |
|
78 |
return super.getName(); |
|
79 |
} |
|
80 |
|
|
81 |
private String getSimpleName() { |
|
82 |
String name = super.getName(); |
|
83 |
|
|
84 |
if (name == null) { |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
int ind = name.indexOf(":"); |
|
89 |
if (ind != -1) { |
|
90 |
// +1 to remove ':' also |
|
91 |
name = name.substring(ind + 1); |
|
92 |
} |
|
93 |
return name; |
|
94 |
} |
|
95 |
|
|
96 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/writer/DefaultSLDWriter.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.writer; |
|
27 |
|
|
28 |
import java.io.IOException; |
|
29 |
import java.io.OutputStream; |
|
30 |
import java.io.OutputStreamWriter; |
|
31 |
|
|
32 |
import org.gvsig.sldsupport.exception.InvalidSLDObjectException; |
|
33 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
34 |
import org.gvsig.sldsupport.impl.sld.handler.Handler; |
|
35 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
|
36 |
import org.gvsig.sldsupport.impl.util.XmlBuilder; |
|
37 |
import org.gvsig.sldsupport.sld.SLDObject; |
|
38 |
import org.gvsig.sldsupport.writer.SLDWriter; |
|
39 |
|
|
40 |
public class DefaultSLDWriter implements SLDWriter { |
|
41 |
|
|
42 |
private String version = null; |
|
43 |
|
|
44 |
public DefaultSLDWriter(String v) { |
|
45 |
version = v; |
|
46 |
} |
|
47 |
|
|
48 |
public String getVersion() { |
|
49 |
return version; |
|
50 |
} |
|
51 |
|
|
52 |
public void check(SLDObject obj) throws InvalidSLDObjectException, |
|
53 |
UnsupportedSLDObjectException { |
|
54 |
|
|
55 |
Handler.getXML(obj); |
|
56 |
} |
|
57 |
|
|
58 |
public void write(SLDObject obj, OutputStream outs) |
|
59 |
throws InvalidSLDObjectException, UnsupportedSLDObjectException, |
|
60 |
IOException { |
|
61 |
|
|
62 |
XmlBuilder xmlb = Handler.getXML(obj); |
|
63 |
|
|
64 |
OutputStreamWriter writer = |
|
65 |
new OutputStreamWriter(outs, SLDUtils.DEFAULT_ENCODING); |
|
66 |
writer.write(xmlb.getXML()); |
|
67 |
writer.close(); |
|
68 |
} |
|
69 |
|
|
70 |
public void forceWrite(SLDObject obj, OutputStream outs) throws IOException { |
|
71 |
// TODO Auto-generated method stub |
|
72 |
|
|
73 |
} |
|
74 |
|
|
75 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/writer/DefaultSLDWriterFactory.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.writer; |
|
27 |
|
|
28 |
import org.gvsig.sldsupport.writer.SLDWriter; |
|
29 |
import org.gvsig.sldsupport.writer.SLDWriterFactory; |
|
30 |
|
|
31 |
public class DefaultSLDWriterFactory implements SLDWriterFactory { |
|
32 |
|
|
33 |
private String version = null; |
|
34 |
|
|
35 |
public DefaultSLDWriterFactory(String v) { |
|
36 |
version = v; |
|
37 |
} |
|
38 |
|
|
39 |
public String getVersion() { |
|
40 |
return version; |
|
41 |
} |
|
42 |
|
|
43 |
public SLDWriter create() { |
|
44 |
return new DefaultSLDWriter(version); |
|
45 |
} |
|
46 |
|
|
47 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/util/XmlBuilder.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.util; |
|
27 |
|
|
28 |
import java.util.Map; |
|
29 |
import java.util.Stack; |
|
30 |
|
|
31 |
/** |
|
32 |
* Title: XmlBuilder |
|
33 |
* Description: Util class to build xml |
|
34 |
* |
|
35 |
* @author laura |
|
36 |
*/ |
|
37 |
public class XmlBuilder { |
|
38 |
|
|
39 |
// Default size of the XML document to be generated. Used to set the initial |
|
40 |
// capacity of m_xml. |
|
41 |
private static final int DEF_XMLDOC_SIZE = 256; |
|
42 |
|
|
43 |
// Pad unit. |
|
44 |
private static final String PAD = " "; |
|
45 |
|
|
46 |
// Number of pre-defined pad strings, one for each pad |
|
47 |
// level (0..NUM_PADSTRINGS-1). Should at least be set to 10 for |
|
48 |
// performance. |
|
49 |
private static final int NUM_PADSTRINGS = 20; |
|
50 |
|
|
51 |
// Byte representation of '\n'. |
|
52 |
private static final byte[] NEWLINE_BYTES = "\n".getBytes(); |
|
53 |
|
|
54 |
// Array of pad strings, each preceded by a '\n' character. |
|
55 |
private static String s_padStrings[]; |
|
56 |
|
|
57 |
// XML-encoded newline character. |
|
58 |
private static String s_newlineXmlEnc; |
|
59 |
|
|
60 |
// XML document being built. |
|
61 |
private StringBuffer m_xml = new StringBuffer(DEF_XMLDOC_SIZE); |
|
62 |
|
|
63 |
// Scratch buffer exclusively used to encode strings. |
|
64 |
private StringBuffer m_encodeBuf = new StringBuffer(40); |
|
65 |
|
|
66 |
// Current pad string. |
|
67 |
private String m_pad = ""; |
|
68 |
|
|
69 |
// If set, indentation will be added to the XML document. |
|
70 |
private boolean m_autoPad; |
|
71 |
|
|
72 |
// Stack of strings. The string at the top is the tag name of the current |
|
73 |
// XML block. The string immediately below the top is the tag name of the |
|
74 |
// XML block that immediately encloses the current XML block. |
|
75 |
protected Stack m_openElements = new Stack(); |
|
76 |
|
|
77 |
// Current pad level (0, 1, 2, ...). |
|
78 |
private int m_padLevel = 0; |
|
79 |
|
|
80 |
private String encoding = "UTF-8"; |
|
81 |
|
|
82 |
/* |
|
83 |
* Create the pad strings. |
|
84 |
*/ |
|
85 |
static { |
|
86 |
s_padStrings = new String[NUM_PADSTRINGS]; |
|
87 |
String pad = ""; |
|
88 |
|
|
89 |
for (int i = 0; i < NUM_PADSTRINGS; i++) { |
|
90 |
s_padStrings[i] = "\n" + pad; |
|
91 |
pad += PAD; |
|
92 |
} |
|
93 |
|
|
94 |
StringBuffer tmp = new StringBuffer(); |
|
95 |
|
|
96 |
for (int i = 0; i < NEWLINE_BYTES.length; i++) { |
|
97 |
tmp.append("&#"); |
|
98 |
tmp.append(NEWLINE_BYTES[i]); |
|
99 |
tmp.append(";"); |
|
100 |
} |
|
101 |
|
|
102 |
s_newlineXmlEnc = tmp.toString(); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Constructor. The XML document to be generated will automatically be |
|
107 |
* indented. |
|
108 |
*/ |
|
109 |
public XmlBuilder() { |
|
110 |
this(true); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Constructor. |
|
115 |
* |
|
116 |
* @param autoPad |
|
117 |
* if set, the XML document to be generated will |
|
118 |
* automatically be indented. |
|
119 |
*/ |
|
120 |
public XmlBuilder(boolean autoPad) { |
|
121 |
m_autoPad = autoPad; |
|
122 |
m_padLevel = 0; |
|
123 |
m_pad = s_padStrings[m_padLevel]; |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* Reset this XmlBuilder. |
|
128 |
*/ |
|
129 |
public void reset() { |
|
130 |
m_padLevel = 0; |
|
131 |
m_pad = s_padStrings[m_padLevel]; |
|
132 |
m_xml.setLength(0); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Adds raw data to the xml. |
|
137 |
*/ |
|
138 |
public void writeRaw(String raw) { |
|
139 |
m_xml.append(raw); |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Adds a comment to the xml. |
|
144 |
*/ |
|
145 |
public void writeComment(String comment) { |
|
146 |
if (m_autoPad) { |
|
147 |
m_xml.append(m_pad); |
|
148 |
} |
|
149 |
|
|
150 |
m_xml.append("<!-- "); |
|
151 |
encode(comment, m_xml); |
|
152 |
m_xml.append(" -->\n"); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* Writes the XML document header. |
|
157 |
*/ |
|
158 |
public void writeHeader() { |
|
159 |
// XML document header. |
|
160 |
final String HEADER = |
|
161 |
"<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"; |
|
162 |
|
|
163 |
m_xml.append(HEADER); |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Sets the encoding used in the XML. By default UTF-8 is used. |
|
168 |
* |
|
169 |
* @param encoding |
|
170 |
*/ |
|
171 |
public void setEncoding(String encoding) { |
|
172 |
this.encoding = encoding; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Adds a opening and closing tag with charcter data. |
|
177 |
*/ |
|
178 |
public void writeTag(String name, String data) { |
|
179 |
name = encode(name); |
|
180 |
|
|
181 |
if (m_autoPad) { |
|
182 |
m_xml.append(m_pad); |
|
183 |
} |
|
184 |
|
|
185 |
m_xml.append("<"); |
|
186 |
m_xml.append(name); |
|
187 |
m_xml.append(">"); |
|
188 |
encode(data, m_xml); |
|
189 |
m_xml.append("</"); |
|
190 |
m_xml.append(name); |
|
191 |
m_xml.append(">"); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Adds a opening and closing tag with attributes. |
|
196 |
*/ |
|
197 |
public void writeTag(String name, Map attributes) { |
|
198 |
if (m_autoPad) { |
|
199 |
m_xml.append(m_pad); |
|
200 |
} |
|
201 |
|
|
202 |
m_xml.append("<"); |
|
203 |
encode(name, m_xml); |
|
204 |
m_xml.append(" "); |
|
205 |
|
|
206 |
Object elems[] = attributes.keySet().toArray(); |
|
207 |
|
|
208 |
for (int i = 0; i < elems.length; i++) { |
|
209 |
String nm = (String) elems[i]; |
|
210 |
String val = (String) attributes.get(nm); |
|
211 |
|
|
212 |
encode(nm, m_xml); |
|
213 |
m_xml.append("=\""); |
|
214 |
encode(val, m_xml); |
|
215 |
m_xml.append("\" "); |
|
216 |
} |
|
217 |
|
|
218 |
m_xml.append("/>"); |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Adds a opening and closing tag with an attribute and character data. |
|
223 |
*/ |
|
224 |
public void writeTag(String name, String attr1Name, String attr1Value, |
|
225 |
String attr2Name, String attr2Value) { |
|
226 |
if (m_autoPad) { |
|
227 |
m_xml.append(m_pad); |
|
228 |
} |
|
229 |
|
|
230 |
m_xml.append("<"); |
|
231 |
encode(name, m_xml); |
|
232 |
m_xml.append(" "); |
|
233 |
|
|
234 |
encode(attr1Name, m_xml); |
|
235 |
m_xml.append("=\""); |
|
236 |
encode(attr1Value, m_xml); |
|
237 |
m_xml.append("\" "); |
|
238 |
|
|
239 |
encode(attr2Name, m_xml); |
|
240 |
m_xml.append("=\""); |
|
241 |
encode(attr2Value, m_xml); |
|
242 |
m_xml.append("\" "); |
|
243 |
|
|
244 |
m_xml.append("/>"); |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* Adds a opening and closing tag with an attribute and character data. |
|
249 |
*/ |
|
250 |
public void writeTag(String name, String data, String attrName, |
|
251 |
String attrValue) { |
|
252 |
name = encode(name); |
|
253 |
|
|
254 |
if (m_autoPad) { |
|
255 |
m_xml.append(m_pad); |
|
256 |
} |
|
257 |
|
|
258 |
m_xml.append("<"); |
|
259 |
m_xml.append(name); |
|
260 |
m_xml.append(" "); |
|
261 |
|
|
262 |
encode(attrName, m_xml); |
|
263 |
m_xml.append("=\""); |
|
264 |
encode(attrValue, m_xml); |
|
265 |
m_xml.append("\" "); |
|
266 |
|
|
267 |
m_xml.append(">"); |
|
268 |
encode(data, m_xml); |
|
269 |
m_xml.append("</"); |
|
270 |
m_xml.append(name); |
|
271 |
m_xml.append(">"); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Adds a opening and closing tag with two attributes and character data. |
|
276 |
*/ |
|
277 |
public void writeTag(String name, String data, String attr1Name, |
|
278 |
String attr1Value, String attr2Name, String attr2Value) { |
|
279 |
name = encode(name); |
|
280 |
|
|
281 |
if (m_autoPad) { |
|
282 |
m_xml.append(m_pad); |
|
283 |
} |
|
284 |
|
|
285 |
m_xml.append("<"); |
|
286 |
m_xml.append(name); |
|
287 |
m_xml.append(" "); |
|
288 |
|
|
289 |
encode(attr1Name, m_xml); |
|
290 |
m_xml.append("=\""); |
|
291 |
encode(attr1Value, m_xml); |
|
292 |
m_xml.append("\" "); |
|
293 |
|
|
294 |
encode(attr2Name, m_xml); |
|
295 |
m_xml.append("=\""); |
|
296 |
encode(attr2Value, m_xml); |
|
297 |
m_xml.append("\" "); |
|
298 |
|
|
299 |
m_xml.append(">"); |
|
300 |
encode(data, m_xml); |
|
301 |
m_xml.append("</"); |
|
302 |
m_xml.append(name); |
|
303 |
m_xml.append(">"); |
|
304 |
} |
|
305 |
|
|
306 |
/** |
|
307 |
* Adds a opening and closing tag with attributes and character data. |
|
308 |
*/ |
|
309 |
public void writeTag(String name, String data, Map attributes) { |
|
310 |
name = encode(name); |
|
311 |
|
|
312 |
if (m_autoPad) { |
|
313 |
m_xml.append(m_pad); |
|
314 |
} |
|
315 |
|
|
316 |
m_xml.append("<"); |
|
317 |
m_xml.append(name); |
|
318 |
m_xml.append(" "); |
|
319 |
|
|
320 |
Object elems[] = attributes.keySet().toArray(); |
|
321 |
|
|
322 |
for (int i = 0; i < elems.length; i++) { |
|
323 |
String nm = (String) elems[i]; |
|
324 |
String val = (String) attributes.get(nm); |
|
325 |
|
|
326 |
encode(nm, m_xml); |
|
327 |
m_xml.append("=\""); |
|
328 |
encode(val, m_xml); |
|
329 |
m_xml.append("\" "); |
|
330 |
} |
|
331 |
|
|
332 |
m_xml.append(">"); |
|
333 |
encode(data, m_xml); |
|
334 |
m_xml.append("</"); |
|
335 |
m_xml.append(name); |
|
336 |
m_xml.append(">"); |
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
340 |
* Writes an opening tag |
|
341 |
*/ |
|
342 |
public void openTag(String name) { |
|
343 |
name = encode(name); |
|
344 |
|
|
345 |
m_openElements.push(name); // must be encoded! |
|
346 |
|
|
347 |
if (m_autoPad) { |
|
348 |
m_xml.append(m_pad); |
|
349 |
} |
|
350 |
|
|
351 |
m_xml.append("<"); |
|
352 |
m_xml.append(name); |
|
353 |
m_xml.append(">"); |
|
354 |
|
|
355 |
if (m_autoPad) { |
|
356 |
m_padLevel++; |
|
357 |
|
|
358 |
if (m_padLevel < NUM_PADSTRINGS) { |
|
359 |
m_pad = s_padStrings[m_padLevel]; |
|
360 |
} else // really deep nesting level |
|
361 |
{ |
|
362 |
m_pad += PAD; |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
/** |
|
368 |
* Writes an opening tag with one attribute. |
|
369 |
*/ |
|
370 |
public void openTag(String name, String attrName, String attrValue) { |
|
371 |
name = encode(name); |
|
372 |
|
|
373 |
m_openElements.push(name); // must be encoded! |
|
374 |
|
|
375 |
if (m_autoPad) { |
|
376 |
m_xml.append(m_pad); |
|
377 |
} |
|
378 |
|
|
379 |
m_xml.append("<"); |
|
380 |
m_xml.append(name); |
|
381 |
m_xml.append(" "); |
|
382 |
|
|
383 |
encode(attrName, m_xml); |
|
384 |
m_xml.append("=\""); |
|
385 |
encode(attrValue, m_xml); |
|
386 |
m_xml.append("\" "); |
|
387 |
|
|
388 |
m_xml.append(">"); |
|
389 |
|
|
390 |
if (m_autoPad) { |
|
391 |
m_padLevel++; |
|
392 |
|
|
393 |
if (m_padLevel < NUM_PADSTRINGS) { |
|
394 |
m_pad = s_padStrings[m_padLevel]; |
|
395 |
} else // really deep nesting level |
|
396 |
{ |
|
397 |
m_pad += PAD; |
|
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
|
|
402 |
/** |
|
403 |
* Writes an opening tag with two attributes. |
|
404 |
*/ |
|
405 |
public void openTag(String name, String attr1Name, String attr1Value, |
|
406 |
String attr2Name, String attr2Value) { |
|
407 |
name = encode(name); |
|
408 |
|
|
409 |
m_openElements.push(name); // must be encoded! |
|
410 |
|
|
411 |
if (m_autoPad) { |
|
412 |
m_xml.append(m_pad); |
|
413 |
} |
|
414 |
|
|
415 |
m_xml.append("<"); |
|
416 |
m_xml.append(name); |
|
417 |
m_xml.append(" "); |
|
418 |
|
|
419 |
encode(attr1Name, m_xml); |
|
420 |
m_xml.append("=\""); |
|
421 |
encode(attr1Value, m_xml); |
|
422 |
m_xml.append("\" "); |
|
423 |
|
|
424 |
encode(attr2Name, m_xml); |
|
425 |
m_xml.append("=\""); |
|
426 |
encode(attr2Value, m_xml); |
|
427 |
m_xml.append("\" "); |
|
428 |
|
|
429 |
m_xml.append(">"); |
|
430 |
|
|
431 |
if (m_autoPad) { |
|
432 |
m_padLevel++; |
|
433 |
|
|
434 |
if (m_padLevel < NUM_PADSTRINGS) { |
|
435 |
m_pad = s_padStrings[m_padLevel]; |
|
436 |
} else // really deep nesting level |
|
437 |
{ |
|
438 |
m_pad += PAD; |
|
439 |
} |
|
440 |
} |
|
441 |
} |
|
442 |
|
|
443 |
/** |
|
444 |
* Writes an opening tag with attributes. |
|
445 |
*/ |
|
446 |
public void openTag(String name, Map attributes) { |
|
447 |
name = encode(name); |
|
448 |
|
|
449 |
m_openElements.push(name); // must be encoded! |
|
450 |
|
|
451 |
if (m_autoPad) { |
|
452 |
m_xml.append(m_pad); |
|
453 |
} |
|
454 |
|
|
455 |
m_xml.append("<"); |
|
456 |
m_xml.append(name); |
|
457 |
m_xml.append(" "); |
|
458 |
|
|
459 |
Object elems[] = attributes.keySet().toArray(); |
|
460 |
|
|
461 |
for (int i = 0; i < elems.length; i++) { |
|
462 |
String nm = (String) elems[i]; |
|
463 |
String val = (String) attributes.get(nm); |
|
464 |
|
|
465 |
encode(nm, m_xml); |
|
466 |
m_xml.append("=\""); |
|
467 |
encode(val, m_xml); |
|
468 |
m_xml.append("\" "); |
|
469 |
} |
|
470 |
|
|
471 |
m_xml.append(">"); |
|
472 |
|
|
473 |
if (m_autoPad) { |
|
474 |
m_padLevel++; |
|
475 |
|
|
476 |
if (m_padLevel < NUM_PADSTRINGS) { |
|
477 |
m_pad = s_padStrings[m_padLevel]; |
|
478 |
} else // really deep nesting level |
|
479 |
{ |
|
480 |
m_pad += PAD; |
|
481 |
} |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
/** |
|
486 |
* Closes an open tag. |
|
487 |
*/ |
|
488 |
public void closeTag() { |
|
489 |
if (m_autoPad) { |
|
490 |
if (m_padLevel > 0) { |
|
491 |
m_padLevel--; |
|
492 |
} |
|
493 |
|
|
494 |
if (m_padLevel < NUM_PADSTRINGS) { |
|
495 |
m_pad = s_padStrings[m_padLevel]; |
|
496 |
} else // really deep nesting level |
|
497 |
{ |
|
498 |
int len = m_pad.length() - PAD.length(); |
|
499 |
if (len > 0) { |
|
500 |
m_pad = m_pad.substring(0, len); |
|
501 |
} |
|
502 |
} |
|
503 |
|
|
504 |
m_xml.append(m_pad); |
|
505 |
} |
|
506 |
|
|
507 |
String name = (String) m_openElements.pop(); // already encoded |
|
508 |
|
|
509 |
m_xml.append("</"); |
|
510 |
m_xml.append(name); |
|
511 |
m_xml.append(">"); |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* Get the xml. |
|
516 |
*/ |
|
517 |
public String getXML() { |
|
518 |
return m_xml.toString(); |
|
519 |
} |
|
520 |
|
|
521 |
/** |
|
522 |
* Encodes the funny characters (e.g., '&', '<', '\"') in an XML |
|
523 |
* string. |
|
524 |
* |
|
525 |
* @param src XML string to encode. |
|
526 |
* @return the encoded string. |
|
527 |
*/ |
|
528 |
private String encode(String src) { |
|
529 |
m_encodeBuf.setLength(0); // clear old contents |
|
530 |
encode(src, m_encodeBuf); |
|
531 |
return m_encodeBuf.toString(); |
|
532 |
} |
|
533 |
|
|
534 |
/** |
|
535 |
* Encodes the funny characters (e.g., '&', '<', '\"') in an XML |
|
536 |
* string. |
|
537 |
* |
|
538 |
* @param src XML string to encode. |
|
539 |
* @param dst string buffer to write the encoded XML string to. |
|
540 |
*/ |
|
541 |
private static final void encode(String src, StringBuffer dst) { |
|
542 |
int n = src.length(); |
|
543 |
|
|
544 |
for (int i = 0; i < n; i++) { |
|
545 |
char c = src.charAt(i); |
|
546 |
|
|
547 |
switch (c) { |
|
548 |
case '&': |
|
549 |
dst.append("&"); |
|
550 |
break; |
|
551 |
case '<': |
|
552 |
dst.append("<"); |
|
553 |
break; |
|
554 |
case '>': |
|
555 |
dst.append(">"); |
|
556 |
break; |
|
557 |
case '\'': |
|
558 |
dst.append("'"); |
|
559 |
break; |
|
560 |
case '\"': |
|
561 |
dst.append("""); |
|
562 |
break; |
|
563 |
case '\n': |
|
564 |
dst.append(s_newlineXmlEnc); |
|
565 |
break; |
|
566 |
default: |
|
567 |
dst.append(c); |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/util/DummyOutputStream.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.util; |
|
27 |
|
|
28 |
import java.io.IOException; |
|
29 |
import java.io.OutputStream; |
|
30 |
|
|
31 |
public class DummyOutputStream extends OutputStream { |
|
32 |
|
|
33 |
public DummyOutputStream() { |
|
34 |
|
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public void write(int b) throws IOException { |
|
39 |
// Nothing! |
|
40 |
} |
|
41 |
|
|
42 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/util/SLDUtils.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl.util; |
|
27 |
|
|
28 |
import java.awt.geom.Point2D; |
|
29 |
import java.io.File; |
|
30 |
import java.io.FileInputStream; |
|
31 |
import java.io.IOException; |
|
32 |
import java.text.DecimalFormat; |
|
33 |
import java.text.DecimalFormatSymbols; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.List; |
|
36 |
|
|
37 |
import org.slf4j.Logger; |
|
38 |
import org.slf4j.LoggerFactory; |
|
39 |
import org.xmlpull.v1.XmlPullParser; |
|
40 |
import org.xmlpull.v1.XmlPullParserException; |
|
41 |
|
|
42 |
import org.gvsig.sldsupport.exception.SLDReadException; |
|
43 |
import org.gvsig.sldsupport.impl.parser.ExtendedKXmlParser; |
|
44 |
import org.gvsig.sldsupport.sld.SLDTags; |
|
45 |
|
|
46 |
/** |
|
47 |
* |
|
48 |
* Basic symbology utility methods for SLD version 1.0.0 |
|
49 |
* |
|
50 |
* @author jldominguez |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class SLDUtils { |
|
54 |
|
|
55 |
private static Logger logger = LoggerFactory.getLogger(SLDUtils.class); |
|
56 |
public static final String DEFAULT_ENCODING = "utf-8"; |
|
57 |
|
|
58 |
public static final String VERSION_1_0_0 = "1.0.0"; |
|
59 |
public static final String VERSION_1_1_0 = "1.1.0"; |
|
60 |
public static final String DEFAULT_VERSION = VERSION_1_0_0; |
|
61 |
|
|
62 |
public static DecimalFormat df = null; |
|
63 |
|
|
64 |
static { |
|
65 |
DecimalFormatSymbols dformater_rules = new DecimalFormatSymbols(); |
|
66 |
dformater_rules.setDecimalSeparator('.'); |
|
67 |
df = new DecimalFormat("##########.0##########", dformater_rules); |
|
68 |
} |
|
69 |
|
|
70 |
public static String detectVersion(File infile) |
|
71 |
throws XmlPullParserException, IOException, SLDReadException { |
|
72 |
|
|
73 |
XmlPullParser parser = new ExtendedKXmlParser(); |
|
74 |
FileInputStream fis = new FileInputStream(infile); |
|
75 |
// xmlSchemaParser = new XMLSchemaParser(); |
|
76 |
parser.setInput(fis, "utf-8"); |
|
77 |
|
|
78 |
int tag = parser.getEventType(); |
|
79 |
if (tag == XmlPullParser.START_DOCUMENT) { |
|
80 |
parser.nextTag(); |
|
81 |
} else { |
|
82 |
if (tag != XmlPullParser.START_TAG) { |
|
83 |
throw new IOException( |
|
84 |
"Misplaced input stream (it's not before opening tag)"); |
|
85 |
} |
|
86 |
} |
|
87 |
String value = parser.getAttributeValue(null, SLDTags.VERSION_ATTR); |
|
88 |
fis.close(); |
|
89 |
if (value == null) { |
|
90 |
throw new SLDReadException("Version attribute not found"); |
|
91 |
} else { |
|
92 |
return value; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public static String getTextUntilTag(XmlPullParser parser) |
|
97 |
throws XmlPullParserException, IOException { |
|
98 |
|
|
99 |
String resp = ""; |
|
100 |
/* |
|
101 |
* This allows entering the iteratioin even if current tag is not TEXT |
|
102 |
*/ |
|
103 |
int t = XmlPullParser.TEXT; |
|
104 |
while ((t != XmlPullParser.START_TAG) && (t != XmlPullParser.END_TAG) |
|
105 |
&& (t != XmlPullParser.END_DOCUMENT)) { |
|
106 |
|
|
107 |
t = parser.getEventType(); |
|
108 |
if (t == XmlPullParser.TEXT) { |
|
109 |
resp = resp + parser.getText(); |
|
110 |
} |
|
111 |
t = parser.next(); |
|
112 |
} |
|
113 |
return resp; |
|
114 |
} |
|
115 |
|
|
116 |
public static boolean isStr(String a, String b) { |
|
117 |
|
|
118 |
if ((a == null) && (b == null)) { |
|
119 |
return true; |
|
120 |
} else { |
|
121 |
if ((a == null) || (b == null)) { |
|
122 |
return false; |
|
123 |
} else { |
|
124 |
return a.compareToIgnoreCase(b) == 0; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Returns -1 if not parseable |
|
132 |
*/ |
|
133 |
public static int parseInteger(String str) { |
|
134 |
|
|
135 |
int resp = -1; |
|
136 |
try { |
|
137 |
resp = Integer.parseInt(str); |
|
138 |
} catch (Exception ex) { |
|
139 |
logger.info("Unable to parse integer: " + str + ", returned -1"); |
|
140 |
} |
|
141 |
return resp; |
|
142 |
} |
|
143 |
|
|
144 |
public static Point2D parsePair(String str) { |
|
145 |
|
|
146 |
Point2D resp = null; |
|
147 |
try { |
|
148 |
String[] xy = str.split(" "); |
|
149 |
double x = Double.parseDouble(xy[0]); |
|
150 |
double y = Double.parseDouble(xy[1]); |
|
151 |
resp = new Point2D.Double(x, y); |
|
152 |
} catch (Exception ex) { |
|
153 |
logger.info("Unable to parse doubles: " + str + ", returned 0,0"); |
|
154 |
resp = new Point2D.Double(0, 0); |
|
155 |
|
|
156 |
} |
|
157 |
return resp; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Returns -1 if not parseable |
|
162 |
*/ |
|
163 |
public static double parseDouble(String str) { |
|
164 |
|
|
165 |
double resp = -1; |
|
166 |
try { |
|
167 |
resp = Double.parseDouble(str); |
|
168 |
} catch (Exception ex) { |
|
169 |
logger.info("Unable to parse double: " + str + ", returned -1"); |
|
170 |
} |
|
171 |
return resp; |
|
172 |
} |
|
173 |
|
|
174 |
public static String getAsString(List<Float> list, String sep) { |
|
175 |
|
|
176 |
if ((list == null) || (list.size() == 0)) { |
|
177 |
return ""; |
|
178 |
} |
|
179 |
String resp = df.format(list.get(0).floatValue()); |
|
180 |
for (int i = 1; i < list.size(); i++) { |
|
181 |
resp = resp + sep + df.format(list.get(i).floatValue()); |
|
182 |
} |
|
183 |
return resp; |
|
184 |
} |
|
185 |
|
|
186 |
public static List<Float> getAsFloats(String value, String sep) { |
|
187 |
|
|
188 |
List<Float> resp = new ArrayList<Float>(); |
|
189 |
if (value != null) { |
|
190 |
String[] pp = value.split(sep); |
|
191 |
float fi = 0; |
|
192 |
for (int i = 0; i < pp.length; i++) { |
|
193 |
try { |
|
194 |
fi = Float.parseFloat(pp[i]); |
|
195 |
resp.add(new Float(fi)); |
|
196 |
} catch (Exception ex) { |
|
197 |
logger.info("Unable to parse float in flaot array: " |
|
198 |
+ pp[i]); |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
return resp; |
|
203 |
} |
|
204 |
|
|
205 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.154/org.gvsig.sldsupport/org.gvsig.sldsupport.lib/org.gvsig.sldsupport.lib.impl/src/main/java/org/gvsig/sldsupport/impl/DefaultSLDSupportManager.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
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 |
package org.gvsig.sldsupport.impl; |
|
27 |
|
|
28 |
import java.io.File; |
|
29 |
import java.io.FileInputStream; |
|
30 |
import java.io.FileOutputStream; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
33 |
import java.io.OutputStream; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.HashMap; |
|
36 |
import java.util.HashSet; |
|
37 |
import java.util.Iterator; |
|
38 |
import java.util.List; |
|
39 |
import java.util.Map; |
|
40 |
import java.util.Set; |
|
41 |
|
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
import org.gvsig.sldsupport.SLDSupportManager; |
|
46 |
import org.gvsig.sldsupport.exception.SLDException; |
|
47 |
import org.gvsig.sldsupport.exception.SLDReadException; |
|
48 |
import org.gvsig.sldsupport.exception.SLDWriteException; |
|
49 |
import org.gvsig.sldsupport.exception.UnsupportedSLDVersionException; |
|
50 |
import org.gvsig.sldsupport.impl.filter.DefaultSLDFilter; |
|
51 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
|
52 |
import org.gvsig.sldsupport.reader.SLDReader; |
|
53 |
import org.gvsig.sldsupport.reader.SLDReaderFactory; |
|
54 |
import org.gvsig.sldsupport.sld.SLDObject; |
|
55 |
import org.gvsig.sldsupport.sld.filter.SLDFilter; |
|
56 |
import org.gvsig.sldsupport.writer.SLDWriter; |
|
57 |
import org.gvsig.sldsupport.writer.SLDWriterFactory; |
|
58 |
|
|
59 |
public class DefaultSLDSupportManager implements SLDSupportManager { |
|
60 |
|
|
61 |
private static Logger logger = LoggerFactory |
|
62 |
.getLogger(DefaultSLDSupportManager.class); |
|
63 |
|
|
64 |
private Map<String, Set<SLDReaderFactory>> versionToReaders = |
|
65 |
new HashMap<String, Set<SLDReaderFactory>>(); |
|
66 |
private Map<String, Set<SLDWriterFactory>> versionToWriters = |
|
67 |
new HashMap<String, Set<SLDWriterFactory>>(); |
|
68 |
|
|
69 |
public void registerReader(SLDReaderFactory fact) { |
|
70 |
|
|
71 |
String v = fact.getVersion(); |
|
72 |
Set<SLDReaderFactory> set = versionToReaders.get(v); |
|
73 |
if (set == null) { |
|
74 |
set = new HashSet<SLDReaderFactory>(); |
|
75 |
set.add(fact); |
|
76 |
versionToReaders.put(v, set); |
|
77 |
} else { |
|
78 |
set.add(fact); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
public void registerWriter(SLDWriterFactory fact) { |
|
83 |
|
|
84 |
String v = fact.getVersion(); |
|
85 |
Set<SLDWriterFactory> set = versionToWriters.get(v); |
|
86 |
if (set == null) { |
|
87 |
set = new HashSet<SLDWriterFactory>(); |
|
88 |
set.add(fact); |
|
89 |
versionToWriters.put(v, set); |
|
90 |
} else { |
|
91 |
set.add(fact); |
|
92 |
} |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
public List<SLDWriter> createWriters(String version) |
|
97 |
throws UnsupportedSLDVersionException { |
|
98 |
|
|
99 |
Set<SLDWriterFactory> set = versionToWriters.get(version); |
|
100 |
if ((set == null) || (set.size() == 0)) { |
|
101 |
throw new UnsupportedSLDVersionException(version); |
|
102 |
} |
|
103 |
|
|
104 |
List<SLDWriter> resp = new ArrayList<SLDWriter>(); |
|
105 |
Iterator<SLDWriterFactory> iter = set.iterator(); |
|
106 |
SLDWriterFactory fact = null; |
|
107 |
while (iter.hasNext()) { |
|
108 |
fact = iter.next(); |
|
109 |
try { |
|
110 |
resp.add(fact.create()); |
|
111 |
} catch (Exception exc) { |
|
112 |
logger.info("Error while creating writer (ignored)", exc); |
|
113 |
} |
|
114 |
} |
|
115 |
return resp; |
|
116 |
} |
|
117 |
|
|
118 |
public List<SLDReader> createReaders(String version) |
|
119 |
throws UnsupportedSLDVersionException { |
|
120 |
|
|
121 |
Set<SLDReaderFactory> set = versionToReaders.get(version); |
|
122 |
if ((set == null) || (set.size() == 0)) { |
|
123 |
throw new UnsupportedSLDVersionException(version); |
|
124 |
} |
|
125 |
|
|
126 |
List<SLDReader> resp = new ArrayList<SLDReader>(); |
|
127 |
Iterator<SLDReaderFactory> iter = set.iterator(); |
|
128 |
SLDReaderFactory fact = null; |
|
129 |
while (iter.hasNext()) { |
|
130 |
fact = iter.next(); |
|
131 |
try { |
|
132 |
resp.add(fact.create()); |
|
133 |
} catch (Exception exc) { |
|
134 |
logger.info("Error while creating reader (ignored)", exc); |
|
135 |
} |
|
136 |
} |
|
137 |
return resp; |
|
138 |
} |
|
139 |
|
|
140 |
public void write(SLDObject obj, String version, File outfile) |
|
141 |
throws IOException, SLDException { |
|
142 |
|
|
143 |
if (obj == null) { |
|
144 |
throw new IOException("Input SLDObject is null"); |
|
145 |
} |
|
146 |
|
|
147 |
Set<SLDWriterFactory> wset = this.versionToWriters.get(version); |
|
148 |
if ((wset == null) || (wset.size() == 0)) { |
|
149 |
throw new UnsupportedSLDVersionException(version); |
|
150 |
} |
|
151 |
|
|
152 |
OutputStream outstream = null; |
|
153 |
Iterator<SLDWriterFactory> witer = wset.iterator(); |
|
154 |
SLDWriterFactory fact_item = null; |
|
155 |
SLDWriter witem = null; |
|
156 |
/* |
|
157 |
* Trying to write without forcing... |
|
158 |
*/ |
|
159 |
while (witer.hasNext()) { |
|
160 |
fact_item = witer.next(); |
|
161 |
witem = fact_item.create(); |
|
162 |
outstream = new FileOutputStream(outfile); |
|
163 |
try { |
|
164 |
witem.write(obj, outstream); |
|
165 |
// It was possible to write without forcing |
|
166 |
return; |
|
167 |
} catch (Exception exc) { |
|
168 |
logger.info("One of the writers was unable to write object: " |
|
169 |
+ obj.getClass().getSimpleName()); |
|
170 |
// Go on... |
|
171 |
} finally { |
|
172 |
try { |
|
173 |
outstream.close(); |
|
174 |
} catch (Exception exc) { |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
/* |
|
179 |
* It was not possible to write without forcing. |
|
180 |
* Now we'll try to write with forceWrite |
|
181 |
*/ |
|
182 |
witer = wset.iterator(); |
|
183 |
while (witer.hasNext()) { |
|
184 |
fact_item = witer.next(); |
|
185 |
witem = fact_item.create(); |
|
186 |
outstream = new FileOutputStream(outfile); |
|
187 |
try { |
|
188 |
witem.forceWrite(obj, outstream); |
|
189 |
// It was possible to write without forcing |
|
190 |
return; |
|
191 |
} catch (Exception exc) { |
|
192 |
logger |
|
193 |
.info("One of the writers was unable to force-write object: " |
|
194 |
+ obj.getClass().getSimpleName()); |
|
195 |
// Go on... |
|
196 |
} finally { |
|
197 |
try { |
|
198 |
outstream.close(); |
|
199 |
} catch (Exception exc) { |
|
200 |
} |
|
201 |
} |
Also available in: Unified diff