Revision 31117
tags/gvsig_redes-1_0_0-1233/build/build.xml | ||
---|---|---|
1 |
<project name="Complete_build_system" basedir="." default="prepare-eclipse-workspace"> |
|
2 |
<description> |
|
3 |
Builds and prepare folders to work with eclipse using maven. |
|
4 |
Also is able to generate a release of all system with binaries distribution |
|
5 |
and sources distribution. |
|
6 |
</description> |
|
7 |
<!-- set global properties for this build --> |
|
8 |
<dirname file="${ant.file.Complete_build_system}" property="ant.file.Complete_build_system.dir"/> |
|
9 |
<property name="mavendir" location="${ant.file.Complete_build_system.dir}/maven" /> |
|
10 |
<property environment="environment"/> |
|
11 |
|
|
12 |
<condition property="mvn.executable" value="${mavendir}/bin/mvn.bat" else="${mavendir}/bin/mvn"> |
|
13 |
<os family="windows" /> |
|
14 |
</condition> |
|
15 |
|
|
16 |
<condition property="isLinux"> |
|
17 |
<and> |
|
18 |
<os family="unix" /> |
|
19 |
<not> |
|
20 |
<os family="mac" /> |
|
21 |
</not> |
|
22 |
</and> |
|
23 |
</condition> |
|
24 |
<condition property="isWindows"> |
|
25 |
<or> |
|
26 |
<os family="windows" /> |
|
27 |
<os family="win9x" /> |
|
28 |
<os name="Windows Vista" /> |
|
29 |
</or> |
|
30 |
</condition> |
|
31 |
<condition property="isMac"> |
|
32 |
<os family="mac" /> |
|
33 |
</condition> |
|
34 |
|
|
35 |
<condition property="gvsig.os" value="w32"> |
|
36 |
<os family="windows" /> |
|
37 |
</condition> |
|
38 |
<condition property="gvsig.os" value="linux"> |
|
39 |
<and> |
|
40 |
<os family="unix" /> |
|
41 |
<not> |
|
42 |
<os family="mac" /> |
|
43 |
</not> |
|
44 |
</and> |
|
45 |
</condition> |
|
46 |
<condition property="gvsig.os" value="mac"> |
|
47 |
<os family="mac" /> |
|
48 |
</condition> |
|
49 |
|
|
50 |
<property name="native-binaries-dir" value="../binaries" /> |
|
51 |
|
|
52 |
<presetdef name="maven"> |
|
53 |
<exec executable="${mvn.executable}"> |
|
54 |
<env key="JAVA_HOME" value="${java.home}"/> |
|
55 |
</exec> |
|
56 |
</presetdef> |
|
57 |
|
|
58 |
<target name="prepare-eclipse-workspace" depends="mvn-clean,mvn-install-without-tests"> |
|
59 |
<maven> |
|
60 |
<arg value="-Declipse.workspace=../" /> |
|
61 |
<arg value="eclipse:add-maven-repo" /> |
|
62 |
</maven> |
|
63 |
<maven> |
|
64 |
<arg value="eclipse:eclipse" /> |
|
65 |
</maven> |
|
66 |
|
|
67 |
</target> |
|
68 |
<target name="mvn-clean"> |
|
69 |
<maven> |
|
70 |
<arg value="clean" /> |
|
71 |
</maven> |
|
72 |
</target> |
|
73 |
<target name="mvn-install-without-tests"> |
|
74 |
<maven> |
|
75 |
<arg value="install" /> |
|
76 |
<arg value="-Dmaven.test.skip=true" /> |
|
77 |
</maven> |
|
78 |
</target> |
|
79 |
|
|
80 |
<target name="install-gvsig-base" depends="mvn-clean,mvn-install-extensions,mvn-eclipse-clean"> |
|
81 |
<maven> |
|
82 |
<arg value="eclipse:eclipse" /> |
|
83 |
</maven> |
|
84 |
</target> |
|
85 |
|
|
86 |
<target name="mvn-install-extensions"> |
|
87 |
<maven> |
|
88 |
<arg value="install" /> |
|
89 |
<arg value="-Dmaven.test.skip=true" /> |
|
90 |
<arg value="-Dinstall-extension" /> |
|
91 |
</maven> |
|
92 |
</target> |
|
93 |
|
|
94 |
<target name="mvn-install"> |
|
95 |
<maven> |
|
96 |
<arg value="install" /> |
|
97 |
</maven> |
|
98 |
</target> |
|
99 |
|
|
100 |
<target name="mvn-eclipse-clean"> |
|
101 |
<maven> |
|
102 |
<arg value="eclipse:clean" /> |
|
103 |
</maven> |
|
104 |
</target> |
|
105 |
|
|
106 |
<target name="mvn-eclipse-eclipse"> |
|
107 |
<maven> |
|
108 |
<arg value="eclipse:eclipse" /> |
|
109 |
</maven> |
|
110 |
</target> |
|
111 |
|
|
112 |
<!-- TODO: Target for make complete building of gvSIG, calling all enabled projects by default --> |
|
113 |
|
|
114 |
<!-- target name="work" description="prepares system to begin working with eclipse" depends="prepare-eclipse-workspace" / --> |
|
115 |
|
|
116 |
</project> |
|
117 |
|
tags/gvsig_redes-1_0_0-1233/build/distribution/IzPack/src/lib/net/n3/nanoxml/XMLValidationException.java | ||
---|---|---|
1 |
/* XMLValidationException.java NanoXML/Java |
|
2 |
* |
|
3 |
* $Revision: 5819 $ |
|
4 |
* $Date: 2006-06-14 09:29:09 +0200 $ |
|
5 |
* $Name$ |
|
6 |
* |
|
7 |
* This file is part of NanoXML 2 for Java. |
|
8 |
* Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved. |
|
9 |
* |
|
10 |
* This software is provided 'as-is', without any express or implied warranty. |
|
11 |
* In no event will the authors be held liable for any damages arising from the |
|
12 |
* use of this software. |
|
13 |
* |
|
14 |
* Permission is granted to anyone to use this software for any purpose, |
|
15 |
* including commercial applications, and to alter it and redistribute it |
|
16 |
* freely, subject to the following restrictions: |
|
17 |
* |
|
18 |
* 1. The origin of this software must not be misrepresented; you must not |
|
19 |
* claim that you wrote the original software. If you use this software in |
|
20 |
* a product, an acknowledgment in the product documentation would be |
|
21 |
* appreciated but is not required. |
|
22 |
* |
|
23 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
24 |
* misrepresented as being the original software. |
|
25 |
* |
|
26 |
* 3. This notice may not be removed or altered from any source distribution. |
|
27 |
*/ |
|
28 |
|
|
29 |
package net.n3.nanoxml; |
|
30 |
|
|
31 |
|
|
32 |
/** |
|
33 |
* An XMLValidationException is thrown when the XML passed to the XML parser is |
|
34 |
* well-formed but not valid. |
|
35 |
* |
|
36 |
* @author Marc De Scheemaecker |
|
37 |
* @version $Name$, $Revision: 5819 $ |
|
38 |
*/ |
|
39 |
public class XMLValidationException |
|
40 |
extends XMLException |
|
41 |
{ |
|
42 |
|
|
43 |
/** |
|
44 |
* An element was missing. |
|
45 |
*/ |
|
46 |
public static final int MISSING_ELEMENT = 1; |
|
47 |
|
|
48 |
|
|
49 |
/** |
|
50 |
* An unexpected element was encountered. |
|
51 |
*/ |
|
52 |
public static final int UNEXPECTED_ELEMENT = 2; |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* An attribute was missing. |
|
57 |
*/ |
|
58 |
public static final int MISSING_ATTRIBUTE = 3; |
|
59 |
|
|
60 |
|
|
61 |
/** |
|
62 |
* An unexpected attribute was encountered. |
|
63 |
*/ |
|
64 |
public static final int UNEXPECTED_ATTRIBUTE = 4; |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* An attribute has an invalid value. |
|
69 |
*/ |
|
70 |
public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5; |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* A PCDATA element was missing. |
|
75 |
*/ |
|
76 |
public static final int MISSING_PCDATA = 6; |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* An unexpected PCDATA element was encountered. |
|
81 |
*/ |
|
82 |
public static final int UNEXPECTED_PCDATA = 7; |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Another error than those specified in this class was encountered. |
|
87 |
*/ |
|
88 |
public static final int MISC_ERROR = 0; |
|
89 |
|
|
90 |
|
|
91 |
/** |
|
92 |
* Which error occurred. |
|
93 |
*/ |
|
94 |
private int errorType; |
|
95 |
|
|
96 |
|
|
97 |
/** |
|
98 |
* The name of the element where the exception occurred. |
|
99 |
*/ |
|
100 |
private String elementName; |
|
101 |
|
|
102 |
|
|
103 |
/** |
|
104 |
* The name of the attribute where the exception occurred. |
|
105 |
*/ |
|
106 |
private String attributeName; |
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* The value of the attribute where the exception occurred. |
|
111 |
*/ |
|
112 |
private String attributeValue; |
|
113 |
|
|
114 |
|
|
115 |
/** |
|
116 |
* Creates a new exception. |
|
117 |
* |
|
118 |
* @param errorType the type of validity error |
|
119 |
* @param systemID the system ID from where the data came |
|
120 |
* @param lineNr the line number in the XML data where the |
|
121 |
* exception occurred. |
|
122 |
* @param elementName the name of the offending element |
|
123 |
* @param attributeName the name of the offending attribute |
|
124 |
* @param attributeValue the value of the offending attribute |
|
125 |
* @param msg the message of the exception. |
|
126 |
*/ |
|
127 |
public XMLValidationException(int errorType, |
|
128 |
String systemID, |
|
129 |
int lineNr, |
|
130 |
String elementName, |
|
131 |
String attributeName, |
|
132 |
String attributeValue, |
|
133 |
String msg) |
|
134 |
{ |
|
135 |
super(systemID, lineNr, null, |
|
136 |
msg + ((elementName == null) ? "" : (", element=" + elementName)) |
|
137 |
+ ((attributeName == null) ? "" |
|
138 |
: (", attribute=" + attributeName)) |
|
139 |
+ ((attributeValue == null) ? "" |
|
140 |
: (", value='" + attributeValue + "'")), |
|
141 |
false); |
|
142 |
this.elementName = elementName; |
|
143 |
this.attributeName = attributeName; |
|
144 |
this.attributeValue = attributeValue; |
|
145 |
} |
|
146 |
|
|
147 |
|
|
148 |
/** |
|
149 |
* Cleans up the object when it's destroyed. |
|
150 |
*/ |
|
151 |
protected void finalize() |
|
152 |
throws Throwable |
|
153 |
{ |
|
154 |
this.elementName = null; |
|
155 |
this.attributeName = null; |
|
156 |
this.attributeValue = null; |
|
157 |
super.finalize(); |
|
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
/** |
|
162 |
* Returns the name of the element in which the validation is violated. |
|
163 |
* If there is no current element, null is returned. |
|
164 |
*/ |
|
165 |
public String getElementName() |
|
166 |
{ |
|
167 |
return this.elementName; |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
/** |
|
172 |
* Returns the name of the attribute in which the validation is violated. |
|
173 |
* If there is no current attribute, null is returned. |
|
174 |
*/ |
|
175 |
public String getAttributeName() |
|
176 |
{ |
|
177 |
return this.attributeName; |
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
/** |
|
182 |
* Returns the value of the attribute in which the validation is violated. |
|
183 |
* If there is no current attribute, null is returned. |
|
184 |
*/ |
|
185 |
public String getAttributeValue() |
|
186 |
{ |
|
187 |
return this.attributeValue; |
|
188 |
} |
|
189 |
|
|
190 |
} |
tags/gvsig_redes-1_0_0-1233/build/distribution/IzPack/src/lib/net/n3/nanoxml/IXMLReader.java | ||
---|---|---|
1 |
/* IXMLReader.java NanoXML/Java |
|
2 |
* |
|
3 |
* $Revision: 5819 $ |
|
4 |
* $Date: 2006-06-14 09:29:09 +0200 $ |
|
5 |
* $Name$ |
|
6 |
* |
|
7 |
* This file is part of NanoXML 2 for Java. |
|
8 |
* Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved. |
|
9 |
* |
|
10 |
* This software is provided 'as-is', without any express or implied warranty. |
|
11 |
* In no event will the authors be held liable for any damages arising from the |
|
12 |
* use of this software. |
|
13 |
* |
|
14 |
* Permission is granted to anyone to use this software for any purpose, |
|
15 |
* including commercial applications, and to alter it and redistribute it |
|
16 |
* freely, subject to the following restrictions: |
|
17 |
* |
|
18 |
* 1. The origin of this software must not be misrepresented; you must not |
|
19 |
* claim that you wrote the original software. If you use this software in |
|
20 |
* a product, an acknowledgment in the product documentation would be |
|
21 |
* appreciated but is not required. |
|
22 |
* |
|
23 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
24 |
* misrepresented as being the original software. |
|
25 |
* |
|
26 |
* 3. This notice may not be removed or altered from any source distribution. |
|
27 |
*/ |
|
28 |
|
|
29 |
package net.n3.nanoxml; |
|
30 |
|
|
31 |
|
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.Reader; |
|
35 |
import java.net.MalformedURLException; |
|
36 |
|
|
37 |
|
|
38 |
/** |
|
39 |
* IXMLReader reads the data to be parsed. |
|
40 |
* |
|
41 |
* @author Marc De Scheemaecker |
|
42 |
* @version $Name$, $Revision: 5819 $ |
|
43 |
*/ |
|
44 |
public interface IXMLReader |
|
45 |
{ |
|
46 |
|
|
47 |
/** |
|
48 |
* Reads a character. |
|
49 |
* |
|
50 |
* @return the character |
|
51 |
* |
|
52 |
* @throws java.io.IOException |
|
53 |
* if no character could be read |
|
54 |
*/ |
|
55 |
public char read() |
|
56 |
throws IOException; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* Returns true if the current stream has no more characters left to be |
|
61 |
* read. |
|
62 |
* |
|
63 |
* @throws java.io.IOException |
|
64 |
* if an I/O error occurred |
|
65 |
*/ |
|
66 |
public boolean atEOFOfCurrentStream() |
|
67 |
throws IOException; |
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* Returns true if there are no more characters left to be read. |
|
72 |
* |
|
73 |
* @throws java.io.IOException |
|
74 |
* if an I/O error occurred |
|
75 |
*/ |
|
76 |
public boolean atEOF() |
|
77 |
throws IOException; |
|
78 |
|
|
79 |
|
|
80 |
/** |
|
81 |
* Pushes the last character read back to the stream. |
|
82 |
* |
|
83 |
* @param ch the character to push back |
|
84 |
* |
|
85 |
* @throws java.io.IOException |
|
86 |
* if an I/O error occurred |
|
87 |
*/ |
|
88 |
public void unread(char ch) |
|
89 |
throws IOException; |
|
90 |
|
|
91 |
|
|
92 |
/** |
|
93 |
* Returns the line number of the data in the current stream. |
|
94 |
*/ |
|
95 |
public int getLineNr(); |
|
96 |
|
|
97 |
|
|
98 |
/** |
|
99 |
* Opens a stream from a public and system ID. |
|
100 |
* |
|
101 |
* @param publicID the public ID, which may be null |
|
102 |
* @param systemID the system ID, which is never null |
|
103 |
* |
|
104 |
* @throws java.net.MalformedURLException |
|
105 |
* if the system ID does not contain a valid URL |
|
106 |
* @throws java.io.FileNotFoundException |
|
107 |
* if the system ID refers to a local file which does not exist |
|
108 |
* @throws java.io.IOException |
|
109 |
* if an error occurred opening the stream |
|
110 |
*/ |
|
111 |
public Reader openStream(String publicID, |
|
112 |
String systemID) |
|
113 |
throws MalformedURLException, |
|
114 |
FileNotFoundException, |
|
115 |
IOException; |
|
116 |
|
|
117 |
|
|
118 |
/** |
|
119 |
* Starts a new stream from a Java reader. The new stream is used |
|
120 |
* temporary to read data from. If that stream is exhausted, control |
|
121 |
* returns to the parent stream. |
|
122 |
* |
|
123 |
* @param reader the reader to read the new data from |
|
124 |
*/ |
|
125 |
public void startNewStream(Reader reader); |
|
126 |
|
|
127 |
|
|
128 |
/** |
|
129 |
* Sets the system ID of the current stream. |
|
130 |
* |
|
131 |
* @param systemID the system ID |
|
132 |
* |
|
133 |
* @throws java.net.MalformedURLException |
|
134 |
* if the system ID does not contain a valid URL |
|
135 |
*/ |
|
136 |
public void setSystemID(String systemID) |
|
137 |
throws MalformedURLException; |
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* Sets the public ID of the current stream. |
|
142 |
* |
|
143 |
* @param publicID the public ID |
|
144 |
*/ |
|
145 |
public void setPublicID(String publicID); |
|
146 |
|
|
147 |
|
|
148 |
/** |
|
149 |
* Returns the current system ID. |
|
150 |
*/ |
|
151 |
public String getSystemID(); |
|
152 |
|
|
153 |
|
|
154 |
/** |
|
155 |
* Returns the current public ID. |
|
156 |
*/ |
|
157 |
public String getPublicID(); |
|
158 |
|
|
159 |
} |
tags/gvsig_redes-1_0_0-1233/build/distribution/IzPack/src/lib/net/n3/nanoxml/XMLWriter.java | ||
---|---|---|
1 |
/* XMLWriter.java NanoXML/Java |
|
2 |
* |
|
3 |
* $Revision: 5819 $ |
|
4 |
* $Date: 2006-06-14 09:29:09 +0200 $ |
|
5 |
* $Name$ |
|
6 |
* |
|
7 |
* This file is part of NanoXML 2 for Java. |
|
8 |
* Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved. |
|
9 |
* |
|
10 |
* This software is provided 'as-is', without any express or implied warranty. |
|
11 |
* In no event will the authors be held liable for any damages arising from the |
|
12 |
* use of this software. |
|
13 |
* |
|
14 |
* Permission is granted to anyone to use this software for any purpose, |
|
15 |
* including commercial applications, and to alter it and redistribute it |
|
16 |
* freely, subject to the following restrictions: |
|
17 |
* |
|
18 |
* 1. The origin of this software must not be misrepresented; you must not |
|
19 |
* claim that you wrote the original software. If you use this software in |
|
20 |
* a product, an acknowledgment in the product documentation would be |
|
21 |
* appreciated but is not required. |
|
22 |
* |
|
23 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
24 |
* misrepresented as being the original software. |
|
25 |
* |
|
26 |
* 3. This notice may not be removed or altered from any source distribution. |
|
27 |
*/ |
|
28 |
|
|
29 |
package net.n3.nanoxml; |
|
30 |
|
|
31 |
|
|
32 |
import java.io.IOException; |
|
33 |
import java.io.OutputStream; |
|
34 |
import java.io.PrintWriter; |
|
35 |
import java.io.Writer; |
|
36 |
import java.util.Enumeration; |
|
37 |
|
|
38 |
|
|
39 |
/** |
|
40 |
* An XMLWriter writes XML data to a stream. |
|
41 |
* |
|
42 |
* @see net.n3.nanoxml.XMLElement |
|
43 |
* @see java.io.Writer |
|
44 |
* |
|
45 |
* @author Marc De Scheemaecker |
|
46 |
* @version $Name$, $Revision: 5819 $ |
|
47 |
*/ |
|
48 |
public class XMLWriter |
|
49 |
{ |
|
50 |
|
|
51 |
/** |
|
52 |
* Where to write the output to. |
|
53 |
*/ |
|
54 |
private PrintWriter writer; |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* Creates a new XML writer. |
|
59 |
* |
|
60 |
* @param writer where to write the output to. |
|
61 |
*/ |
|
62 |
public XMLWriter(Writer writer) |
|
63 |
{ |
|
64 |
if (writer instanceof PrintWriter) { |
|
65 |
this.writer = (PrintWriter) writer; |
|
66 |
} else { |
|
67 |
this.writer = new PrintWriter(writer); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* Creates a new XML writer. |
|
74 |
* |
|
75 |
* @param stream where to write the output to. |
|
76 |
*/ |
|
77 |
public XMLWriter(OutputStream stream) |
|
78 |
{ |
|
79 |
this.writer = new PrintWriter(stream); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
/** |
|
84 |
* Cleans up the object when it's destroyed. |
|
85 |
*/ |
|
86 |
protected void finalize() |
|
87 |
throws Throwable |
|
88 |
{ |
|
89 |
this.writer = null; |
|
90 |
super.finalize(); |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
/** |
|
95 |
* Writes an XML element. |
|
96 |
* |
|
97 |
* @param xml the non-null XML element to write. |
|
98 |
*/ |
|
99 |
public void write(XMLElement xml) |
|
100 |
throws IOException |
|
101 |
{ |
|
102 |
this.write(xml, true, 0); |
|
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
/** |
|
107 |
* Writes an XML element. |
|
108 |
* |
|
109 |
* @param xml the non-null XML element to write. |
|
110 |
* @param prettyPrint if spaces need to be inserted to make the output more |
|
111 |
* readable |
|
112 |
*/ |
|
113 |
public void write(XMLElement xml, |
|
114 |
boolean prettyPrint) |
|
115 |
throws IOException |
|
116 |
{ |
|
117 |
this.write(xml, prettyPrint, 0); |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
/** |
|
122 |
* Writes an XML element. |
|
123 |
* |
|
124 |
* @param xml the non-null XML element to write. |
|
125 |
* @param prettyPrint if spaces need to be inserted to make the output more |
|
126 |
* readable |
|
127 |
* @param indent how many spaces to indent the element. |
|
128 |
*/ |
|
129 |
public void write(XMLElement xml, |
|
130 |
boolean prettyPrint, |
|
131 |
int indent) |
|
132 |
throws IOException |
|
133 |
{ |
|
134 |
if (prettyPrint) { |
|
135 |
for (int i = 0; i < indent; i++) { |
|
136 |
this.writer.print(' '); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
if (xml.getName() == null) { |
|
141 |
if (xml.getContent() != null) { |
|
142 |
if (prettyPrint) { |
|
143 |
this.writeEncoded(xml.getContent().trim()); |
|
144 |
writer.println(); |
|
145 |
} else { |
|
146 |
this.writeEncoded(xml.getContent()); |
|
147 |
} |
|
148 |
} |
|
149 |
} else { |
|
150 |
this.writer.print('<'); |
|
151 |
this.writer.print(xml.getName()); |
|
152 |
Enumeration enum = xml.enumerateAttributeNames(); |
|
153 |
|
|
154 |
while (enum.hasMoreElements()) { |
|
155 |
String key = (String) enum.nextElement(); |
|
156 |
String value = xml.getAttribute(key); |
|
157 |
this.writer.print(" " + key + "=\""); |
|
158 |
this.writeEncoded(value); |
|
159 |
this.writer.print('"'); |
|
160 |
} |
|
161 |
|
|
162 |
if ((xml.getContent() != null) |
|
163 |
&& (xml.getContent().length() > 0)) { |
|
164 |
writer.print('>'); |
|
165 |
this.writeEncoded(xml.getContent()); |
|
166 |
writer.print("</" + xml.getName() + '>'); |
|
167 |
|
|
168 |
if (prettyPrint) { |
|
169 |
writer.println(); |
|
170 |
} |
|
171 |
} else if (xml.hasChildren()) { |
|
172 |
writer.print('>'); |
|
173 |
|
|
174 |
if (prettyPrint) { |
|
175 |
writer.println(); |
|
176 |
} |
|
177 |
|
|
178 |
enum = xml.enumerateChildren(); |
|
179 |
|
|
180 |
while (enum.hasMoreElements()) { |
|
181 |
XMLElement child = (XMLElement) enum.nextElement(); |
|
182 |
this.write(child, prettyPrint, indent + 4); |
|
183 |
} |
|
184 |
|
|
185 |
if (prettyPrint) { |
|
186 |
for (int i = 0; i < indent; i++) { |
|
187 |
this.writer.print(' '); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
this.writer.print("</" + xml.getName() + ">"); |
|
192 |
|
|
193 |
if (prettyPrint) { |
|
194 |
writer.println(); |
|
195 |
} |
|
196 |
} else { |
|
197 |
this.writer.print("/>"); |
|
198 |
|
|
199 |
if (prettyPrint) { |
|
200 |
writer.println(); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
this.writer.flush(); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/** |
|
210 |
* Writes a string encoding reserved characters. |
|
211 |
* |
|
212 |
* @param str the string to write. |
|
213 |
*/ |
|
214 |
private void writeEncoded(String str) |
|
215 |
{ |
|
216 |
for (int i = 0; i < str.length(); i++) { |
|
217 |
char c = str.charAt(i); |
|
218 |
|
|
219 |
switch (c) { |
|
220 |
case 0x0D: |
|
221 |
case 0x0A: |
|
222 |
this.writer.print(c); |
|
223 |
break; |
|
224 |
|
|
225 |
case '<': |
|
226 |
this.writer.print("<"); |
|
227 |
break; |
|
228 |
|
|
229 |
case '>': |
|
230 |
this.writer.print(">"); |
|
231 |
break; |
|
232 |
|
|
233 |
case '&': |
|
234 |
this.writer.print("&"); |
|
235 |
break; |
|
236 |
|
|
237 |
case '\'': |
|
238 |
this.writer.print("'"); |
|
239 |
break; |
|
240 |
|
|
241 |
case '"': |
|
242 |
this.writer.print("""); |
|
243 |
break; |
|
244 |
|
|
245 |
default: |
|
246 |
if ((c < ' ') || (c > 0x7E)) { |
|
247 |
this.writer.print("&#x"); |
|
248 |
this.writer.print(Integer.toString(c, 16)); |
|
249 |
this.writer.print(';'); |
|
250 |
} else { |
|
251 |
this.writer.print(c); |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
} |
tags/gvsig_redes-1_0_0-1233/build/distribution/IzPack/src/lib/net/n3/nanoxml/ContentReader.java | ||
---|---|---|
1 |
/* ContentReader.java NanoXML/Java |
|
2 |
* |
|
3 |
* $Revision: 5819 $ |
|
4 |
* $Date: 2006-06-14 09:29:09 +0200 $ |
|
5 |
* $Name$ |
|
6 |
* |
|
7 |
* This file is part of NanoXML 2 for Java. |
|
8 |
* Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved. |
|
9 |
* |
|
10 |
* This software is provided 'as-is', without any express or implied warranty. |
|
11 |
* In no event will the authors be held liable for any damages arising from the |
|
12 |
* use of this software. |
|
13 |
* |
|
14 |
* Permission is granted to anyone to use this software for any purpose, |
|
15 |
* including commercial applications, and to alter it and redistribute it |
|
16 |
* freely, subject to the following restrictions: |
|
17 |
* |
|
18 |
* 1. The origin of this software must not be misrepresented; you must not |
|
19 |
* claim that you wrote the original software. If you use this software in |
|
20 |
* a product, an acknowledgment in the product documentation would be |
|
21 |
* appreciated but is not required. |
|
22 |
* |
|
23 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
24 |
* misrepresented as being the original software. |
|
25 |
* |
|
26 |
* 3. This notice may not be removed or altered from any source distribution. |
|
27 |
*/ |
|
28 |
|
|
29 |
package net.n3.nanoxml; |
|
30 |
|
|
31 |
|
|
32 |
import java.io.IOException; |
|
33 |
import java.io.Reader; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* This reader reads data from another reader until a certain string is |
|
38 |
* encountered. |
|
39 |
* |
|
40 |
* @author Marc De Scheemaecker |
|
41 |
* @version $Name$, $Version$ |
|
42 |
*/ |
|
43 |
class ContentReader |
|
44 |
extends Reader |
|
45 |
{ |
|
46 |
|
|
47 |
/** |
|
48 |
* The encapsulated reader. |
|
49 |
*/ |
|
50 |
private IXMLReader reader; |
|
51 |
|
|
52 |
|
|
53 |
/** |
|
54 |
* The encapsulated entityResolver. |
|
55 |
*/ |
|
56 |
private IXMLEntityResolver entityResolver; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* The escape char (& or %). |
|
61 |
*/ |
|
62 |
private char escapeChar; |
|
63 |
|
|
64 |
|
|
65 |
/** |
|
66 |
* The delimiter that will indicate the end of the stream. |
|
67 |
*/ |
|
68 |
private char[] delimiter; |
|
69 |
|
|
70 |
|
|
71 |
/** |
|
72 |
* The characters that have been read too much. |
|
73 |
*/ |
|
74 |
private String charsReadTooMuch; |
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* The number of characters in the delimiter that stil need to be |
|
79 |
* scanned. |
|
80 |
*/ |
|
81 |
private int charsToGo; |
|
82 |
|
|
83 |
|
|
84 |
/** |
|
85 |
* True if the escape char (& or %) needs to be left untouched. |
|
86 |
*/ |
|
87 |
private boolean useLowLevelReader; |
|
88 |
|
|
89 |
|
|
90 |
/** |
|
91 |
* True if we are passed the initial prefix. |
|
92 |
*/ |
|
93 |
private boolean pastInitialPrefix; |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Creates the reader. |
|
98 |
* |
|
99 |
* @param reader the encapsulated reader |
|
100 |
* @param entityResolver resolves entities |
|
101 |
* @param escapeChar escape character (& or %) |
|
102 |
* @param delimiter the delimiter, as a backwards string, that will |
|
103 |
* indicate the end of the stream |
|
104 |
* @param useLowLevelReader true if & needs to be left untouched; |
|
105 |
* false if entities need to be processed |
|
106 |
* @param prefix chars that are already read |
|
107 |
*/ |
|
108 |
ContentReader(IXMLReader reader, |
|
109 |
IXMLEntityResolver entityResolver, |
|
110 |
char escapeChar, |
|
111 |
char[] delimiter, |
|
112 |
boolean useLowLevelReader, |
|
113 |
String prefix) |
|
114 |
{ |
|
115 |
this.delimiter = delimiter; |
|
116 |
this.charsToGo = this.delimiter.length; |
|
117 |
this.charsReadTooMuch = prefix; |
|
118 |
this.useLowLevelReader = useLowLevelReader; |
|
119 |
this.pastInitialPrefix = false; |
|
120 |
this.reader = reader; |
|
121 |
this.entityResolver = entityResolver; |
|
122 |
this.escapeChar = escapeChar; |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** |
|
127 |
* Cleans up the object when it's destroyed. |
|
128 |
*/ |
|
129 |
protected void finalize() |
|
130 |
throws Throwable |
|
131 |
{ |
|
132 |
this.reader = null; |
|
133 |
this.entityResolver = null; |
|
134 |
this.delimiter = null; |
|
135 |
this.charsReadTooMuch = null; |
|
136 |
super.finalize(); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* Reads a block of data. |
|
142 |
* |
|
143 |
* @param buffer where to put the read data |
|
144 |
* @param offset first position in buffer to put the data |
|
145 |
* @param size maximum number of chars to read |
|
146 |
* |
|
147 |
* @return the number of chars read, or -1 if at EOF |
|
148 |
* |
|
149 |
* @throws java.io.IOException |
|
150 |
* if an error occurred reading the data |
|
151 |
*/ |
|
152 |
public int read(char[] buffer, |
|
153 |
int offset, |
|
154 |
int size) |
|
155 |
throws IOException |
|
156 |
{ |
|
157 |
int charsRead = 0; |
|
158 |
boolean isEntity[] = new boolean[1]; |
|
159 |
isEntity[0] = false; |
|
160 |
|
|
161 |
if ((offset + size) > buffer.length) { |
|
162 |
size = buffer.length - offset; |
|
163 |
} |
|
164 |
|
|
165 |
while ((this.charsToGo > 0) && (charsRead < size)) { |
|
166 |
char ch; |
|
167 |
|
|
168 |
if (this.charsReadTooMuch.length() > 0) { |
|
169 |
ch = this.charsReadTooMuch.charAt(0); |
|
170 |
this.charsReadTooMuch = this.charsReadTooMuch.substring(1); |
|
171 |
} else { |
|
172 |
this.pastInitialPrefix = true; |
|
173 |
|
|
174 |
try { |
|
175 |
if (useLowLevelReader) { |
|
176 |
ch = this.reader.read(); |
|
177 |
} else { |
|
178 |
ch = XMLUtil.read(this.reader, isEntity, |
|
179 |
this.escapeChar, |
|
180 |
this.entityResolver); |
|
181 |
|
|
182 |
if (! isEntity[0]) { |
|
183 |
if (ch == '&') { |
|
184 |
this.reader.startNewStream( |
|
185 |
XMLUtil.scanEntity(isEntity, |
|
186 |
this.reader, |
|
187 |
this.escapeChar, |
|
188 |
this.entityResolver)); |
|
189 |
ch = this.reader.read(); |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
} catch (XMLParseException e) { |
|
194 |
throw new RuntimeException(e.getMessage()); |
|
195 |
// necessary to be able to implement Reader |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
if (isEntity[0]) { |
|
200 |
buffer[offset + charsRead] = ch; |
|
201 |
charsRead++; |
|
202 |
} else { |
|
203 |
if ((ch == (this.delimiter[this.charsToGo - 1])) |
|
204 |
&& pastInitialPrefix) { |
|
205 |
--this.charsToGo; |
|
206 |
} else if (this.charsToGo < this.delimiter.length) { |
|
207 |
this.charsReadTooMuch |
|
208 |
= new String(this.delimiter, this.charsToGo + 1, |
|
209 |
this.delimiter.length - this.charsToGo) |
|
210 |
+ ch; |
|
211 |
this.charsToGo = this.delimiter.length; |
|
212 |
buffer[offset + charsRead] |
|
213 |
= this.delimiter[this.charsToGo - 1]; |
|
214 |
charsRead++; |
|
215 |
} else { |
|
216 |
buffer[offset + charsRead] = ch; |
|
217 |
charsRead++; |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
if (charsRead == 0) { |
|
223 |
charsRead = -1; |
|
224 |
} |
|
225 |
|
|
226 |
return charsRead; |
|
227 |
} |
|
228 |
|
|
229 |
|
|
230 |
/** |
|
231 |
* Skips remaining data and closes the stream. |
|
232 |
* |
|
233 |
* @throws java.io.IOException |
|
234 |
* if an error occurred reading the data |
|
235 |
*/ |
|
236 |
public void close() |
|
237 |
throws IOException |
|
238 |
{ |
|
239 |
while (this.charsToGo > 0) { |
|
240 |
char ch; |
|
241 |
|
|
242 |
if (this.charsReadTooMuch.length() > 0) { |
|
243 |
ch = this.charsReadTooMuch.charAt(0); |
|
244 |
this.charsReadTooMuch = this.charsReadTooMuch.substring(1); |
|
245 |
} else { |
|
246 |
if (useLowLevelReader) { |
|
247 |
ch = this.reader.read(); |
|
248 |
} else { |
|
249 |
try { |
|
250 |
ch = XMLUtil.read(this.reader, null, this.escapeChar, |
|
251 |
this.entityResolver); |
|
252 |
} catch (XMLParseException e) { |
|
253 |
throw new RuntimeException(e.getMessage()); |
|
254 |
// necessary to be able to implement Reader |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
if (ch == (this.delimiter[this.charsToGo - 1])) { |
|
260 |
--this.charsToGo; |
|
261 |
} else if (this.charsToGo < this.delimiter.length) { |
|
262 |
this.charsReadTooMuch |
|
263 |
= new String(this.delimiter, this.charsToGo + 1, |
|
264 |
this.delimiter.length - this.charsToGo) |
|
265 |
+ ch; |
|
266 |
this.charsToGo = this.delimiter.length; |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
|
|
271 |
} |
tags/gvsig_redes-1_0_0-1233/build/distribution/IzPack/src/lib/net/n3/nanoxml/StdXMLReader.java | ||
---|---|---|
1 |
/* StdXMLReader.java NanoXML/Java |
|
2 |
* |
|
3 |
* $Revision: 5819 $ |
|
4 |
* $Date: 2006-06-14 09:29:09 +0200 $ |
|
5 |
* $Name$ |
|
6 |
* |
|
7 |
* This file is part of NanoXML 2 for Java. |
|
8 |
* Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved. |
|
9 |
* |
|
10 |
* This software is provided 'as-is', without any express or implied warranty. |
|
11 |
* In no event will the authors be held liable for any damages arising from the |
|
12 |
* use of this software. |
|
13 |
* |
|
14 |
* Permission is granted to anyone to use this software for any purpose, |
|
15 |
* including commercial applications, and to alter it and redistribute it |
|
16 |
* freely, subject to the following restrictions: |
|
17 |
* |
|
18 |
* 1. The origin of this software must not be misrepresented; you must not |
|
19 |
* claim that you wrote the original software. If you use this software in |
|
20 |
* a product, an acknowledgment in the product documentation would be |
|
21 |
* appreciated but is not required. |
|
22 |
* |
|
23 |
* 2. Altered source versions must be plainly marked as such, and must not be |
|
24 |
* misrepresented as being the original software. |
|
25 |
* |
|
26 |
* 3. This notice may not be removed or altered from any source distribution. |
|
27 |
*/ |
|
28 |
|
|
29 |
package net.n3.nanoxml; |
|
30 |
|
|
31 |
|
|
32 |
import java.io.FileInputStream; |
|
33 |
import java.io.FileNotFoundException; |
|
34 |
import java.io.IOException; |
|
35 |
import java.io.InputStream; |
|
36 |
import java.io.InputStreamReader; |
|
37 |
import java.io.LineNumberReader; |
|
38 |
import java.io.PushbackInputStream; |
|
39 |
import java.io.PushbackReader; |
|
40 |
import java.io.Reader; |
|
41 |
import java.io.StringReader; |
|
42 |
import java.io.UnsupportedEncodingException; |
|
43 |
import java.net.MalformedURLException; |
|
44 |
import java.net.URL; |
|
45 |
import java.util.Stack; |
|
46 |
|
|
47 |
|
|
48 |
/** |
|
49 |
* StdXMLReader reads the data to be parsed. |
|
50 |
* |
|
51 |
* @author Marc De Scheemaecker |
|
52 |
* @version $Name$, $Revision: 5819 $ |
|
53 |
*/ |
|
54 |
public class StdXMLReader |
|
55 |
implements IXMLReader |
|
56 |
{ |
|
57 |
|
|
58 |
/** |
|
59 |
* The stack of push-back readers. |
|
60 |
*/ |
|
61 |
private Stack pbreaders; |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* The stack of line-number readers. |
|
66 |
*/ |
|
67 |
private Stack linereaders; |
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* The stack of system ids. |
|
72 |
*/ |
|
73 |
private Stack systemIds; |
|
74 |
|
|
75 |
|
|
76 |
/** |
|
77 |
* The stack of public ids. |
|
78 |
*/ |
|
79 |
private Stack publicIds; |
|
80 |
|
|
81 |
|
|
82 |
/** |
|
83 |
* The current push-back reader. |
|
84 |
*/ |
|
85 |
private PushbackReader currentPbReader; |
|
86 |
|
|
87 |
|
|
88 |
/** |
|
89 |
* The current line-number reader. |
|
90 |
*/ |
|
91 |
private LineNumberReader currentLineReader; |
|
92 |
|
|
93 |
|
|
94 |
/** |
|
95 |
* The current system ID. |
|
96 |
*/ |
|
97 |
private URL currentSystemID; |
|
98 |
|
|
99 |
|
|
100 |
/** |
|
101 |
* The current public ID. |
|
102 |
*/ |
|
103 |
private String currentPublicID; |
|
104 |
|
|
105 |
|
|
106 |
/** |
|
107 |
* Creates a new reader using a string as input. |
|
108 |
* |
|
109 |
* @param str the string containing the XML data |
|
110 |
*/ |
|
111 |
public static IXMLReader stringReader(String str) |
|
112 |
{ |
|
113 |
return new StdXMLReader(new StringReader(str)); |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
/** |
|
118 |
* Creates a new reader using a file as input. |
|
119 |
* |
|
120 |
* @param filename the name of the file containing the XML data |
|
121 |
* |
|
122 |
* @throws java.io.FileNotFoundException |
|
123 |
* if the file could not be found |
|
124 |
* @throws java.io.IOException |
|
125 |
* if an I/O error occurred |
|
126 |
*/ |
|
127 |
public static IXMLReader fileReader(String filename) |
|
128 |
throws FileNotFoundException, |
|
129 |
IOException |
|
130 |
{ |
|
131 |
IXMLReader reader = new StdXMLReader(new FileInputStream(filename)); |
|
132 |
reader.setSystemID(filename); |
|
133 |
return reader; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
/** |
|
138 |
* Initializes the reader from a system and public ID. |
|
139 |
* |
|
140 |
* @param publicID the public ID which may be null. |
|
141 |
* @param systemID the non-null system ID. |
|
142 |
* |
|
143 |
* @throws MalformedURLException |
|
144 |
* if the system ID does not contain a valid URL |
|
145 |
* @throws FileNotFoundException |
|
146 |
* if the system ID refers to a local file which does not exist |
|
147 |
* @throws IOException |
|
148 |
* if an error occurred opening the stream |
|
149 |
*/ |
|
150 |
public StdXMLReader(String publicID, |
|
151 |
String systemID) |
|
152 |
throws MalformedURLException, |
|
153 |
FileNotFoundException, |
|
154 |
IOException |
|
155 |
{ |
|
156 |
URL systemIDasURL = null; |
|
157 |
|
|
158 |
try { |
|
159 |
systemIDasURL = new URL(systemID); |
|
160 |
} catch (MalformedURLException e) { |
|
161 |
systemID = "file:" + systemID; |
|
162 |
|
|
163 |
try { |
|
164 |
systemIDasURL = new URL(systemID); |
|
165 |
} catch (MalformedURLException e2) { |
|
166 |
throw e; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
Reader reader = this.openStream(publicID, systemIDasURL.toString()); |
|
171 |
this.currentLineReader = new LineNumberReader(reader); |
|
172 |
this.currentPbReader = new PushbackReader(this.currentLineReader, 2); |
|
173 |
this.pbreaders = new Stack(); |
|
174 |
this.linereaders = new Stack(); |
|
175 |
this.publicIds = new Stack(); |
|
176 |
this.systemIds = new Stack(); |
|
177 |
this.currentPublicID = publicID; |
|
178 |
this.currentSystemID = systemIDasURL; |
|
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
/** |
|
183 |
* Initializes the XML reader. |
|
184 |
* |
|
185 |
* @param reader the input for the XML data. |
|
186 |
*/ |
|
187 |
public StdXMLReader(Reader reader) |
|
188 |
{ |
|
189 |
this.currentLineReader = new LineNumberReader(reader); |
|
190 |
this.currentPbReader = new PushbackReader(this.currentLineReader, 2); |
|
191 |
this.pbreaders = new Stack(); |
|
192 |
this.linereaders = new Stack(); |
|
193 |
this.publicIds = new Stack(); |
|
194 |
this.systemIds = new Stack(); |
|
195 |
this.currentPublicID = ""; |
|
196 |
|
|
197 |
try { |
|
198 |
this.currentSystemID = new URL("file:."); |
|
199 |
} catch (MalformedURLException e) { |
|
200 |
// never happens |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
|
|
205 |
/** |
|
206 |
* Cleans up the object when it's destroyed. |
|
207 |
*/ |
|
208 |
protected void finalize() |
|
209 |
throws Throwable |
|
210 |
{ |
|
211 |
this.currentLineReader = null; |
|
212 |
this.currentPbReader = null; |
|
213 |
this.pbreaders.clear(); |
|
214 |
this.pbreaders = null; |
|
215 |
this.linereaders.clear(); |
|
216 |
this.linereaders = null; |
|
217 |
this.publicIds.clear(); |
|
218 |
this.publicIds = null; |
|
219 |
this.systemIds.clear(); |
|
220 |
this.systemIds = null; |
|
221 |
this.currentPublicID = null; |
|
222 |
super.finalize(); |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
/** |
|
227 |
* Scans the encoding from an <?xml?> tag. |
|
228 |
* |
|
229 |
* @param str the first tag in the XML data. |
|
230 |
* |
|
231 |
* @return the encoding, or null if no encoding has been specified. |
|
232 |
*/ |
|
233 |
protected String getEncoding(String str) |
|
234 |
{ |
|
235 |
if (! str.startsWith("<?xml")) { |
|
236 |
return null; |
|
237 |
} |
|
238 |
|
|
239 |
int index = 5; |
|
240 |
|
|
241 |
while (index < str.length()) { |
|
242 |
StringBuffer key = new StringBuffer(); |
|
243 |
|
|
244 |
while ((index < str.length()) && (str.charAt(index) <= ' ')) { |
|
245 |
index++; |
|
246 |
} |
|
247 |
|
|
248 |
while ((index < str.length()) |
|
249 |
&& (str.charAt(index) >= 'a') |
|
250 |
&& (str.charAt(index) <= 'z')) { |
|
251 |
key.append(str.charAt(index)); |
|
252 |
index++; |
|
253 |
} |
|
254 |
|
|
255 |
while ((index < str.length()) && (str.charAt(index) <= ' ')) { |
|
256 |
index++; |
|
257 |
} |
|
258 |
|
|
259 |
if ((index >= str.length()) || (str.charAt(index) != '=')) { |
|
260 |
break; |
|
261 |
} |
|
262 |
|
|
263 |
while ((index < str.length()) && (str.charAt(index) != '\'') |
|
264 |
&& (str.charAt(index) != '"')) { |
|
265 |
index++; |
|
266 |
} |
|
267 |
|
|
268 |
if (index >= str.length()) { |
|
269 |
break; |
|
270 |
} |
|
271 |
|
|
272 |
char delimiter = str.charAt(index); |
|
273 |
index++; |
|
274 |
int index2 = str.indexOf(delimiter, index); |
|
275 |
|
|
276 |
if (index2 < 0) { |
|
277 |
break; |
|
278 |
} |
|
279 |
|
|
280 |
if (key.toString().equals("encoding")) { |
|
281 |
return str.substring(index, index2); |
|
282 |
} |
|
283 |
|
|
284 |
index = index2 + 1; |
|
285 |
} |
|
286 |
|
|
287 |
return null; |
|
288 |
} |
|
289 |
|
|
290 |
|
|
291 |
/** |
|
292 |
* Converts a stream to a reader while detecting the encoding. |
|
293 |
* |
|
294 |
* @param stream the input for the XML data. |
|
295 |
* @param charsRead buffer where to put characters that have been read |
|
296 |
* |
|
297 |
* @throws java.io.IOException |
|
298 |
* if an I/O error occurred |
|
299 |
*/ |
|
300 |
protected Reader stream2reader(InputStream stream, |
|
301 |
StringBuffer charsRead) |
|
302 |
throws IOException |
|
303 |
{ |
|
304 |
PushbackInputStream pbstream = new PushbackInputStream(stream); |
|
305 |
int b = pbstream.read(); |
|
306 |
|
|
307 |
switch (b) { |
|
308 |
case 0x00: |
|
309 |
case 0xFE: |
|
310 |
case 0xFF: |
|
311 |
pbstream.unread(b); |
|
312 |
return new InputStreamReader(pbstream, "UTF-16"); |
|
313 |
|
|
314 |
case 0xEF: |
|
315 |
for (int i = 0; i < 2; i++) { |
|
316 |
pbstream.read(); |
|
317 |
} |
|
318 |
|
|
319 |
return new InputStreamReader(pbstream, "UTF-8"); |
|
320 |
|
|
321 |
case 0x3C: |
|
322 |
b = pbstream.read(); |
|
323 |
charsRead.append('<'); |
|
324 |
|
|
325 |
while ((b > 0) && (b != 0x3E)) { |
|
326 |
charsRead.append((char) b); |
|
327 |
b = pbstream.read(); |
|
328 |
} |
|
329 |
|
|
330 |
if (b > 0) { |
|
331 |
charsRead.append((char) b); |
|
332 |
} |
|
333 |
|
|
334 |
String encoding = this.getEncoding(charsRead.toString()); |
|
335 |
|
|
336 |
if (encoding == null) { |
|
337 |
return new InputStreamReader(pbstream, "UTF-8"); |
|
338 |
} |
|
339 |
|
|
340 |
charsRead.setLength(0); |
|
341 |
|
|
342 |
try { |
|
343 |
return new InputStreamReader(pbstream, encoding); |
|
344 |
} catch (UnsupportedEncodingException e) { |
|
345 |
return new InputStreamReader(pbstream, "UTF-8"); |
|
346 |
} |
|
347 |
|
|
348 |
default: |
|
349 |
charsRead.append((char) b); |
|
350 |
return new InputStreamReader(pbstream, "UTF-8"); |
|
351 |
} |
|
352 |
} |
|
353 |
|
|
354 |
|
|
355 |
/** |
|
356 |
* Initializes the XML reader. |
|
357 |
* |
|
358 |
* @param stream the input for the XML data. |
|
359 |
* |
|
360 |
* @throws java.io.IOException |
|
361 |
* if an I/O error occurred |
|
362 |
*/ |
|
363 |
public StdXMLReader(InputStream stream) |
|
364 |
throws IOException |
|
365 |
{ |
|
366 |
PushbackInputStream pbstream = new PushbackInputStream(stream); |
|
367 |
StringBuffer charsRead = new StringBuffer(); |
|
368 |
Reader reader = this.stream2reader(stream, charsRead); |
|
369 |
this.currentLineReader = new LineNumberReader(reader); |
|
370 |
this.currentPbReader = new PushbackReader(this.currentLineReader, 2); |
|
371 |
this.pbreaders = new Stack(); |
|
372 |
this.linereaders = new Stack(); |
|
373 |
this.publicIds = new Stack(); |
|
374 |
this.systemIds = new Stack(); |
|
375 |
this.currentPublicID = ""; |
|
376 |
|
|
377 |
try { |
|
378 |
this.currentSystemID = new URL("file:."); |
|
379 |
} catch (MalformedURLException e) { |
|
380 |
// never happens |
|
381 |
} |
|
382 |
|
|
383 |
this.startNewStream(new StringReader(charsRead.toString())); |
|
384 |
} |
|
385 |
|
|
386 |
|
|
387 |
/** |
|
388 |
* Reads a character. |
|
389 |
* |
|
390 |
* @return the character |
|
391 |
* |
|
392 |
* @throws java.io.IOException |
|
393 |
* if no character could be read |
|
394 |
*/ |
|
395 |
public char read() |
|
396 |
throws IOException |
|
397 |
{ |
|
398 |
int ch = this.currentPbReader.read(); |
|
399 |
|
|
400 |
while (ch < 0) { |
|
401 |
if (this.pbreaders.empty()) { |
|
402 |
throw new IOException("Unexpected EOF"); |
|
403 |
} |
|
404 |
|
|
405 |
this.currentPbReader.close(); |
|
406 |
this.currentPbReader = (PushbackReader) this.pbreaders.pop(); |
|
407 |
this.currentLineReader = (LineNumberReader) this.linereaders.pop(); |
|
408 |
this.currentSystemID = (URL) this.systemIds.pop(); |
|
409 |
this.currentPublicID = (String) this.publicIds.pop(); |
|
410 |
ch = this.currentPbReader.read(); |
|
411 |
} |
|
412 |
|
|
413 |
if (ch == 0x0D) { // CR |
|
414 |
// using recursion could convert "\r\r\n" to "\n" (wrong), |
|
415 |
// newline combo "\r\n" isn't normalized if it spans streams |
|
416 |
// next 'read()' will pop pbreaders stack appropriately |
|
417 |
ch = this.currentPbReader.read(); |
|
418 |
|
|
419 |
if (ch != 0x0A && ch > 0) { // LF |
|
420 |
this.currentPbReader.unread(ch); |
|
421 |
} |
|
422 |
return (char) 0x0A; // normalized: always LF |
|
423 |
} |
|
424 |
|
|
425 |
return (char) ch; |
|
426 |
} |
|
427 |
|
|
428 |
|
|
429 |
/** |
|
430 |
* Returns true if the current stream has no more characters left to be |
|
431 |
* read. |
|
432 |
* |
|
433 |
* @throws java.io.IOException |
|
434 |
* if an I/O error occurred |
|
435 |
*/ |
|
436 |
public boolean atEOFOfCurrentStream() |
|
437 |
throws IOException |
|
438 |
{ |
|
439 |
int ch = this.currentPbReader.read(); |
|
440 |
|
|
441 |
if (ch < 0) { |
|
442 |
return true; |
|
443 |
} else { |
|
444 |
this.currentPbReader.unread(ch); |
|
445 |
return false; |
|
446 |
} |
|
447 |
} |
|
448 |
|
|
449 |
|
|
450 |
/** |
|
451 |
* Returns true if there are no more characters left to be read. |
|
452 |
* |
|
453 |
* @throws java.io.IOException |
|
454 |
* if an I/O error occurred |
|
455 |
*/ |
|
456 |
public boolean atEOF() |
|
457 |
throws IOException |
|
458 |
{ |
|
459 |
int ch = this.currentPbReader.read(); |
|
460 |
|
|
461 |
while (ch < 0) { |
|
462 |
if (this.pbreaders.empty()) { |
|
463 |
return true; |
|
464 |
} |
|
465 |
|
|
466 |
this.currentPbReader.close(); |
|
467 |
this.currentPbReader = (PushbackReader) this.pbreaders.pop(); |
|
468 |
this.currentLineReader = (LineNumberReader) this.linereaders.pop(); |
|
469 |
this.currentSystemID = (URL) this.systemIds.pop(); |
|
470 |
this.currentPublicID = (String) this.publicIds.pop(); |
|
471 |
ch = this.currentPbReader.read(); |
|
472 |
} |
|
473 |
|
|
474 |
this.currentPbReader.unread(ch); |
|
475 |
return false; |
|
476 |
} |
|
477 |
|
Also available in: Unified diff