aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/nanoxml
diff options
context:
space:
mode:
authorDeepak Bhole <[email protected]>2010-12-06 15:34:01 -0500
committerDeepak Bhole <[email protected]>2010-12-06 15:34:01 -0500
commit6ca1a9a369b10703da9af8f8a1ced0f3b02ae5c2 (patch)
tree568f8e454db94fa8abc896b46ce8cac7a9f3b74d /netx/net/sourceforge/nanoxml
parent0d66adf24179c33bbdccaacc10d4c8a5f5e2cd54 (diff)
Fixed indentation and spacing for all .java files.
Added a new .settings directory which contains Eclipse preferences for code style.
Diffstat (limited to 'netx/net/sourceforge/nanoxml')
-rw-r--r--netx/net/sourceforge/nanoxml/XMLElement.java185
-rw-r--r--netx/net/sourceforge/nanoxml/XMLParseException.java28
2 files changed, 61 insertions, 152 deletions
diff --git a/netx/net/sourceforge/nanoxml/XMLElement.java b/netx/net/sourceforge/nanoxml/XMLElement.java
index f8fd369..2284895 100644
--- a/netx/net/sourceforge/nanoxml/XMLElement.java
+++ b/netx/net/sourceforge/nanoxml/XMLElement.java
@@ -35,7 +35,6 @@ import java.util.*;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
-
/**
* XMLElement is a representation of an XML object. The object is able to parse
* XML code.
@@ -94,8 +93,7 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime;
* &lt;<A href="mailto:[email protected]">[email protected]</A>&gt;
* @version $Name: $, $Revision: 1.2 $
*/
-public class XMLElement
-{
+public class XMLElement {
/**
* The attributes given to the element.
@@ -106,8 +104,7 @@ public class XMLElement
* <li>The keys and the values are strings.
* </ul></dd></dl>
*/
- private Hashtable<String,Object> attributes;
-
+ private Hashtable<String, Object> attributes;
/**
* Child elements of the element.
@@ -121,7 +118,6 @@ public class XMLElement
*/
private Vector<XMLElement> children;
-
/**
* The name of the element.
*
@@ -135,7 +131,6 @@ public class XMLElement
*/
private String name;
-
/**
* The #PCDATA content of the object.
*
@@ -147,7 +142,6 @@ public class XMLElement
*/
private String contents;
-
/**
* Conversion table for &amp;...; entities. The keys are the entity names
* without the &amp; and ; delimiters.
@@ -162,8 +156,7 @@ public class XMLElement
* <li>The values are char arrays
* </ul></dd></dl>
*/
- private Hashtable<String,char[]> entities;
-
+ private Hashtable<String, char[]> entities;
/**
* The line number where the element starts.
@@ -174,21 +167,18 @@ public class XMLElement
*/
private int lineNr;
-
/**
* <code>true</code> if the case of the element and attribute names
* are case insensitive.
*/
private boolean ignoreCase;
-
/**
* <code>true</code> if the leading and trailing whitespace of #PCDATA
* sections have to be ignored.
*/
private boolean ignoreWhitespace;
-
/**
* Character read too much.
* This character provides push-back functionality to the input reader
@@ -212,7 +202,6 @@ public class XMLElement
*/
private Reader reader;
-
/**
* The current line number in the source content.
*
@@ -222,7 +211,6 @@ public class XMLElement
*/
private int parserLineNr;
-
/**
* Creates and initializes a new XML element.
* Calling the construction is equivalent to:
@@ -240,12 +228,10 @@ public class XMLElement
* </ul></dd></dl>
*
*/
- public XMLElement()
- {
- this(new Hashtable<String,char[]>(), false, true, true);
+ public XMLElement() {
+ this(new Hashtable<String, char[]>(), false, true, true);
}
-
/**
* Creates and initializes a new XML element.
* <P>
@@ -284,16 +270,15 @@ public class XMLElement
* </ul></dd></dl><dl>
*
*/
- protected XMLElement(Hashtable<String,char[]> entities,
- boolean skipLeadingWhitespace,
- boolean fillBasicConversionTable,
- boolean ignoreCase)
- {
+ protected XMLElement(Hashtable<String, char[]> entities,
+ boolean skipLeadingWhitespace,
+ boolean fillBasicConversionTable,
+ boolean ignoreCase) {
this.ignoreWhitespace = skipLeadingWhitespace;
this.ignoreCase = ignoreCase;
this.name = null;
this.contents = "";
- this.attributes = new Hashtable<String,Object>();
+ this.attributes = new Hashtable<String, Object>();
this.children = new Vector<XMLElement>();
this.entities = entities;
this.lineNr = 0;
@@ -314,7 +299,6 @@ public class XMLElement
}
}
-
/**
* Adds a child element.
*
@@ -334,12 +318,10 @@ public class XMLElement
* </ul></dd></dl><dl>
*
*/
- public void addChild(XMLElement child)
- {
+ public void addChild(XMLElement child) {
this.children.addElement(child);
}
-
/**
* Adds or modifies an attribute.
*
@@ -362,15 +344,13 @@ public class XMLElement
*
*/
public void setAttribute(String name,
- Object value)
- {
+ Object value) {
if (this.ignoreCase) {
name = name.toUpperCase();
}
this.attributes.put(name, value.toString());
}
-
/**
* Returns the number of child elements of the element.
*
@@ -379,12 +359,10 @@ public class XMLElement
* </ul></dd></dl>
*
*/
- public int countChildren()
- {
+ public int countChildren() {
return this.children.size();
}
-
/**
* Enumerates the attribute names.
*
@@ -393,12 +371,10 @@ public class XMLElement
* </ul></dd></dl>
*
*/
- public Enumeration enumerateAttributeNames()
- {
+ public Enumeration enumerateAttributeNames() {
return this.attributes.keys();
}
-
/**
* Enumerates the child elements.
*
@@ -407,23 +383,19 @@ public class XMLElement
* </ul></dd></dl>
*
*/
- public Enumeration enumerateChildren()
- {
+ public Enumeration enumerateChildren() {
return this.children.elements();
}
-
/**
* Returns the PCDATA content of the object. If there is no such content,
* <CODE>null</CODE> is returned.
*
*/
- public String getContent()
- {
+ public String getContent() {
return this.contents;
}
-
/**
* Returns the line nr in the source data on which the element is found.
* This method returns <code>0</code> there is no associated source data.
@@ -432,12 +404,10 @@ public class XMLElement
* <ul><li><code>result >= 0</code>
* </ul></dd></dl>
*/
- public int getLineNr()
- {
+ public int getLineNr() {
return this.lineNr;
}
-
/**
* Returns an attribute of the element.
* If the attribute doesn't exist, <code>null</code> is returned.
@@ -450,8 +420,7 @@ public class XMLElement
* </ul></dd></dl><dl>
*
*/
- public Object getAttribute(String name)
- {
+ public Object getAttribute(String name) {
if (this.ignoreCase) {
name = name.toUpperCase();
}
@@ -459,17 +428,14 @@ public class XMLElement
return value;
}
-
/**
* Returns the name of the element.
*
*/
- public String getName()
- {
+ public String getName() {
return this.name;
}
-
/**
* Reads one XML element from a java.io.Reader and parses it.
*
@@ -494,12 +460,10 @@ public class XMLElement
* If an error occured while parsing the read data.
*/
public void parseFromReader(Reader reader)
- throws IOException, XMLParseException
- {
- this.parseFromReader(reader, /*startingLineNr*/ 1);
+ throws IOException, XMLParseException {
+ this.parseFromReader(reader, /*startingLineNr*/1);
}
-
/**
* Reads one XML element from a java.io.Reader and parses it.
*
@@ -526,9 +490,8 @@ public class XMLElement
* If an error occured while parsing the read data.
*/
public void parseFromReader(Reader reader,
- int startingLineNr)
- throws IOException, XMLParseException
- {
+ int startingLineNr)
+ throws IOException, XMLParseException {
this.charReadTooMuch = '\0';
this.reader = reader;
this.parserLineNr = startingLineNr;
@@ -552,33 +515,28 @@ public class XMLElement
}
}
-
/**
* Creates a new similar XML element.
* <P>
* You should override this method when subclassing XMLElement.
*/
- protected XMLElement createAnotherElement()
- {
+ protected XMLElement createAnotherElement() {
return new XMLElement(this.entities,
this.ignoreWhitespace,
false,
this.ignoreCase);
}
-
/**
* Changes the content string.
*
* @param content
* The new content string.
*/
- public void setContent(String content)
- {
+ public void setContent(String content) {
this.contents = content;
}
-
/**
* Changes the name of the element.
*
@@ -591,12 +549,10 @@ public class XMLElement
* </ul></dd></dl>
*
*/
- public void setName(String name)
- {
+ public void setName(String name) {
this.name = name;
}
-
/**
* Scans an identifier from the current reader.
* The scanned identifier is appended to <code>result</code>.
@@ -616,13 +572,12 @@ public class XMLElement
* </ul></dd></dl><dl>
*/
protected void scanIdentifier(StringBuffer result)
- throws IOException
- {
+ throws IOException {
for (;;) {
char ch = this.readChar();
if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z'))
- && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.')
- && (ch != ':') && (ch != '-') && (ch <= '\u007E')) {
+ && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.')
+ && (ch != ':') && (ch != '-') && (ch <= '\u007E')) {
this.unreadChar(ch);
return;
}
@@ -630,15 +585,13 @@ public class XMLElement
}
}
-
/**
* This method scans an identifier from the current reader.
*
* @return the next character following the whitespace.
*/
protected char scanWhitespace()
- throws IOException
- {
+ throws IOException {
for (;;) {
char ch = this.readChar();
switch (ch) {
@@ -653,7 +606,6 @@ public class XMLElement
}
}
-
/**
* This method scans an identifier from the current reader.
* The scanned whitespace is appended to <code>result</code>.
@@ -665,8 +617,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected char scanWhitespace(StringBuffer result)
- throws IOException
- {
+ throws IOException {
for (;;) {
char ch = this.readChar();
switch (ch) {
@@ -683,7 +634,6 @@ public class XMLElement
}
}
-
/**
* This method scans a delimited string from the current reader.
* The scanned string without delimiters is appended to
@@ -695,8 +645,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void scanString(StringBuffer string)
- throws IOException
- {
+ throws IOException {
char delimiter = this.readChar();
if ((delimiter != '\'') && (delimiter != '"')) {
throw this.expectedInput("' or \"");
@@ -713,7 +662,6 @@ public class XMLElement
}
}
-
/**
* Scans a #PCDATA element. CDATA sections and entities are resolved.
* The next &lt; char is skipped.
@@ -724,8 +672,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void scanPCData(StringBuffer data)
- throws IOException
- {
+ throws IOException {
for (;;) {
char ch = this.readChar();
if (ch == '<') {
@@ -744,7 +691,6 @@ public class XMLElement
}
}
-
/**
* Scans a special tag and if the tag is a CDATA section, append its
* content to <code>buf</code>.
@@ -755,14 +701,13 @@ public class XMLElement
* </ul></dd></dl>
*/
protected boolean checkCDATA(StringBuffer buf)
- throws IOException
- {
+ throws IOException {
char ch = this.readChar();
if (ch != '[') {
this.unreadChar(ch);
this.skipSpecialTag(0);
return false;
- } else if (! this.checkLiteral("CDATA[")) {
+ } else if (!this.checkLiteral("CDATA[")) {
this.skipSpecialTag(1); // one [ has already been read
return false;
} else {
@@ -802,7 +747,6 @@ public class XMLElement
}
}
-
/**
* Skips a comment.
*
@@ -811,8 +755,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void skipComment()
- throws IOException
- {
+ throws IOException {
int dashesToRead = 2;
while (dashesToRead > 0) {
char ch = this.readChar();
@@ -841,7 +784,6 @@ public class XMLElement
*/
}
-
/**
* Skips a special tag or comment.
*
@@ -854,8 +796,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void skipSpecialTag(int bracketLevel)
- throws IOException
- {
+ throws IOException {
int tagLevel = 1; // <
char stringDelimiter = '\0';
if (bracketLevel == 0) {
@@ -899,7 +840,6 @@ public class XMLElement
}
}
-
/**
* Scans the data for literal text.
* Scanning stops when a character does not match or after the complete
@@ -912,8 +852,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected boolean checkLiteral(String literal)
- throws IOException
- {
+ throws IOException {
int length = literal.length();
for (int i = 0; i < length; i += 1) {
if (this.readChar() != literal.charAt(i)) {
@@ -923,13 +862,11 @@ public class XMLElement
return true;
}
-
/**
* Reads a character from a reader.
*/
protected char readChar()
- throws IOException
- {
+ throws IOException {
if (this.charReadTooMuch != '\0') {
char ch = this.charReadTooMuch;
this.charReadTooMuch = '\0';
@@ -947,7 +884,6 @@ public class XMLElement
}
}
-
/**
* Scans an XML element.
*
@@ -959,8 +895,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void scanElement(XMLElement elt)
- throws IOException
- {
+ throws IOException {
StringBuffer buf = new StringBuffer();
this.scanIdentifier(buf);
String name = buf.toString();
@@ -1051,7 +986,7 @@ public class XMLElement
throw this.expectedInput("/");
}
this.unreadChar(this.scanWhitespace());
- if (! this.checkLiteral(name)) {
+ if (!this.checkLiteral(name)) {
throw this.expectedInput(name);
}
if (this.scanWhitespace() != '>') {
@@ -1059,7 +994,6 @@ public class XMLElement
}
}
-
/**
* Resolves an entity. The name of the entity is read from the reader.
* The value of the entity is appended to <code>buf</code>.
@@ -1072,8 +1006,7 @@ public class XMLElement
* </ul></dd></dl>
*/
protected void resolveEntity(StringBuffer buf)
- throws IOException
- {
+ throws IOException {
char ch = '\0';
StringBuffer keyBuf = new StringBuffer();
for (;;) {
@@ -1104,7 +1037,6 @@ public class XMLElement
}
}
-
/**
* Pushes a character back to the read-back buffer.
*
@@ -1115,12 +1047,10 @@ public class XMLElement
* <li><code>ch != '\0'</code>
* </ul></dd></dl>
*/
- protected void unreadChar(char ch)
- {
+ protected void unreadChar(char ch) {
this.charReadTooMuch = ch;
}
-
/**
* Creates a parse exception for when an invalid valueset is given to
* a method.
@@ -1131,13 +1061,11 @@ public class XMLElement
* <ul><li><code>name != null</code>
* </ul></dd></dl>
*/
- protected XMLParseException invalidValueSet(String name)
- {
+ protected XMLParseException invalidValueSet(String name) {
String msg = "Invalid value set (entity name = \"" + name + "\")";
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
-
/**
* Creates a parse exception for when an invalid value is given to a
* method.
@@ -1151,25 +1079,21 @@ public class XMLElement
* </ul></dd></dl>
*/
protected XMLParseException invalidValue(String name,
- String value)
- {
+ String value) {
String msg = "Attribute \"" + name + "\" does not contain a valid "
+ "value (\"" + value + "\")";
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
-
/**
* Creates a parse exception for when the end of the data input has been
* reached.
*/
- protected XMLParseException unexpectedEndOfData()
- {
+ protected XMLParseException unexpectedEndOfData() {
String msg = "Unexpected end of data reached";
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
-
/**
* Creates a parse exception for when a syntax error occured.
*
@@ -1180,13 +1104,11 @@ public class XMLElement
* <li><code>context.length() &gt; 0</code>
* </ul></dd></dl>
*/
- protected XMLParseException syntaxError(String context)
- {
+ protected XMLParseException syntaxError(String context) {
String msg = "Syntax error while parsing " + context;
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
-
/**
* Creates a parse exception for when the next character read is not
* the character that was expected.
@@ -1199,8 +1121,7 @@ public class XMLElement
* <li><code>charSet.length() &gt; 0</code>
* </ul></dd></dl>
*/
- protected XMLParseException expectedInput(String charSet)
- {
+ protected XMLParseException expectedInput(String charSet) {
String msg = "Expected: " + charSet;
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
@@ -1217,9 +1138,8 @@ public class XMLElement
* <li><code>charSet.length() &gt; 0</code>
* </ul></dd></dl>
*/
- protected XMLParseException expectedInput(String charSet, char ch)
- {
- String msg = "Expected: '" + charSet +"'" + " but got: '" + ch + "'";
+ protected XMLParseException expectedInput(String charSet, char ch) {
+ String msg = "Expected: '" + charSet + "'" + " but got: '" + ch + "'";
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
@@ -1233,8 +1153,7 @@ public class XMLElement
* <li><code>name.length() &gt; 0</code>
* </ul></dd></dl>
*/
- protected XMLParseException unknownEntity(String name)
- {
+ protected XMLParseException unknownEntity(String name) {
String msg = "Unknown or invalid entity: &" + name + ";";
return new XMLParseException(this.getName(), this.parserLineNr, msg);
}
@@ -1257,7 +1176,7 @@ public class XMLElement
int newline = 2;
char prev = ' ';
- while(true) {
+ while (true) {
char ch;
if (this.sanitizeCharReadTooMuch != '\0') {
ch = this.sanitizeCharReadTooMuch;
diff --git a/netx/net/sourceforge/nanoxml/XMLParseException.java b/netx/net/sourceforge/nanoxml/XMLParseException.java
index dfbb637..329dea4 100644
--- a/netx/net/sourceforge/nanoxml/XMLParseException.java
+++ b/netx/net/sourceforge/nanoxml/XMLParseException.java
@@ -26,10 +26,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*****************************************************************************/
-
package net.sourceforge.nanoxml;
-
/**
* An XMLParseException is thrown when an error occures while parsing an XML
* string.
@@ -43,15 +41,13 @@ package net.sourceforge.nanoxml;
* @version $Name: $, $Revision: 1.1 $
*/
public class XMLParseException
- extends RuntimeException
-{
+ extends RuntimeException {
/**
* Indicates that no line number has been associated with this exception.
*/
public static final int NO_LINE = -1;
-
/**
* The line number in the source code where the error occurred, or
* <code>NO_LINE</code> if the line number is unknown.
@@ -62,7 +58,6 @@ public class XMLParseException
*/
private int lineNr;
-
/**
* Creates an exception.
*
@@ -78,16 +73,14 @@ public class XMLParseException
* </ul></dd></dl><dl>
*/
public XMLParseException(String name,
- String message)
- {
+ String message) {
super("XML Parse Exception during parsing of "
- + ((name == null) ? "the XML definition"
+ + ((name == null) ? "the XML definition"
: ("a " + name + " element"))
- + ": " + message);
+ + ": " + message);
this.lineNr = XMLParseException.NO_LINE;
}
-
/**
* Creates an exception.
*
@@ -105,25 +98,22 @@ public class XMLParseException
* </ul></dd></dl><dl>
*/
public XMLParseException(String name,
- int lineNr,
- String message)
- {
+ int lineNr,
+ String message) {
super("XML Parse Exception during parsing of "
- + ((name == null) ? "the XML definition"
+ + ((name == null) ? "the XML definition"
: ("a " + name + " element"))
- + " at line " + lineNr + ": " + message);
+ + " at line " + lineNr + ": " + message);
this.lineNr = lineNr;
}
-
/**
* Where the error occurred, or <code>NO_LINE</code> if the line number is
* unknown.
*
* @see net.sourceforge.nanoxml.XMLParseException#NO_LINE
*/
- public int getLineNr()
- {
+ public int getLineNr() {
return this.lineNr;
}