From 1140a940bd5f0f16fb1c742425b5796e24bc431c Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 18 Jun 2011 17:29:52 +0000 Subject: [PATCH] goodbye XMLElement --- core/src/processing/xml/CDATAReader.java | 193 --- core/src/processing/xml/ContentReader.java | 212 --- core/src/processing/xml/PIReader.java | 157 -- core/src/processing/xml/StdXMLBuilder.java | 330 ---- core/src/processing/xml/StdXMLParser.java | 685 -------- core/src/processing/xml/StdXMLReader.java | 626 ------- core/src/processing/xml/XMLAttribute.java | 153 -- core/src/processing/xml/XMLElement.java | 1513 ----------------- .../src/processing/xml/XMLEntityResolver.java | 173 -- core/src/processing/xml/XMLException.java | 287 ---- .../src/processing/xml/XMLParseException.java | 70 - core/src/processing/xml/XMLUtil.java | 758 --------- .../xml/XMLValidationException.java | 191 --- core/src/processing/xml/XMLValidator.java | 631 ------- core/src/processing/xml/XMLWriter.java | 304 ---- 15 files changed, 6283 deletions(-) delete mode 100644 core/src/processing/xml/CDATAReader.java delete mode 100644 core/src/processing/xml/ContentReader.java delete mode 100644 core/src/processing/xml/PIReader.java delete mode 100644 core/src/processing/xml/StdXMLBuilder.java delete mode 100644 core/src/processing/xml/StdXMLParser.java delete mode 100644 core/src/processing/xml/StdXMLReader.java delete mode 100644 core/src/processing/xml/XMLAttribute.java delete mode 100644 core/src/processing/xml/XMLElement.java delete mode 100644 core/src/processing/xml/XMLEntityResolver.java delete mode 100644 core/src/processing/xml/XMLException.java delete mode 100644 core/src/processing/xml/XMLParseException.java delete mode 100644 core/src/processing/xml/XMLUtil.java delete mode 100644 core/src/processing/xml/XMLValidationException.java delete mode 100644 core/src/processing/xml/XMLValidator.java delete mode 100644 core/src/processing/xml/XMLWriter.java diff --git a/core/src/processing/xml/CDATAReader.java b/core/src/processing/xml/CDATAReader.java deleted file mode 100644 index 11b6849a7..000000000 --- a/core/src/processing/xml/CDATAReader.java +++ /dev/null @@ -1,193 +0,0 @@ -/* CDATAReader.java NanoXML/Java - * - * $Revision: 1.3 $ - * $Date: 2002/01/04 21:03:28 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.Reader; -import java.io.IOException; - - -/** - * This reader reads data from another reader until the end of a CDATA section - * (]]>) has been encountered. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ - */ -class CDATAReader - extends Reader -{ - - /** - * The encapsulated reader. - */ - private StdXMLReader reader; - - - /** - * Saved char. - */ - private char savedChar; - - - /** - * True if the end of the stream has been reached. - */ - private boolean atEndOfData; - - - /** - * Creates the reader. - * - * @param reader the encapsulated reader - */ - CDATAReader(StdXMLReader reader) - { - this.reader = reader; - this.savedChar = 0; - this.atEndOfData = false; - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.reader = null; - super.finalize(); - } - - - /** - * Reads a block of data. - * - * @param buffer where to put the read data - * @param offset first position in buffer to put the data - * @param size maximum number of chars to read - * - * @return the number of chars read, or -1 if at EOF - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public int read(char[] buffer, - int offset, - int size) - throws IOException - { - int charsRead = 0; - - if (this.atEndOfData) { - return -1; - } - - if ((offset + size) > buffer.length) { - size = buffer.length - offset; - } - - while (charsRead < size) { - char ch = this.savedChar; - - if (ch == 0) { - ch = this.reader.read(); - } else { - this.savedChar = 0; - } - - if (ch == ']') { - char ch2 = this.reader.read(); - - if (ch2 == ']') { - char ch3 = this.reader.read(); - - if (ch3 == '>') { - this.atEndOfData = true; - break; - } - - this.savedChar = ch2; - this.reader.unread(ch3); - } else { - this.reader.unread(ch2); - } - } - buffer[charsRead] = ch; - charsRead++; - } - - if (charsRead == 0) { - charsRead = -1; - } - - return charsRead; - } - - - /** - * Skips remaining data and closes the stream. - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public void close() - throws IOException - { - while (! this.atEndOfData) { - char ch = this.savedChar; - - if (ch == 0) { - ch = this.reader.read(); - } else { - this.savedChar = 0; - } - - if (ch == ']') { - char ch2 = this.reader.read(); - - if (ch2 == ']') { - char ch3 = this.reader.read(); - - if (ch3 == '>') { - break; - } - - this.savedChar = ch2; - this.reader.unread(ch3); - } else { - this.reader.unread(ch2); - } - } - } - - this.atEndOfData = true; - } - -} diff --git a/core/src/processing/xml/ContentReader.java b/core/src/processing/xml/ContentReader.java deleted file mode 100644 index 66430c06b..000000000 --- a/core/src/processing/xml/ContentReader.java +++ /dev/null @@ -1,212 +0,0 @@ -/* ContentReader.java NanoXML/Java - * - * $Revision: 1.4 $ - * $Date: 2002/01/04 21:03:28 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.Reader; -import java.io.IOException; - - -/** - * This reader reads data from another reader until a new element has - * been encountered. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ -class ContentReader - extends Reader -{ - - /** - * The encapsulated reader. - */ - private StdXMLReader reader; - - - /** - * Buffer. - */ - private String buffer; - - - /** - * Pointer into the buffer. - */ - private int bufferIndex; - - - /** - * The entity resolver. - */ - private XMLEntityResolver resolver; - - - /** - * Creates the reader. - * - * @param reader the encapsulated reader - * @param resolver the entity resolver - * @param buffer data that has already been read from reader - */ - ContentReader(StdXMLReader reader, - XMLEntityResolver resolver, - String buffer) - { - this.reader = reader; - this.resolver = resolver; - this.buffer = buffer; - this.bufferIndex = 0; - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.reader = null; - this.resolver = null; - this.buffer = null; - super.finalize(); - } - - - /** - * Reads a block of data. - * - * @param outputBuffer where to put the read data - * @param offset first position in buffer to put the data - * @param size maximum number of chars to read - * - * @return the number of chars read, or -1 if at EOF - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public int read(char[] outputBuffer, - int offset, - int size) - throws IOException - { - try { - int charsRead = 0; - int bufferLength = this.buffer.length(); - - if ((offset + size) > outputBuffer.length) { - size = outputBuffer.length - offset; - } - - while (charsRead < size) { - String str = ""; - char ch; - - if (this.bufferIndex >= bufferLength) { - str = XMLUtil.read(this.reader, '&'); - ch = str.charAt(0); - } else { - ch = this.buffer.charAt(this.bufferIndex); - this.bufferIndex++; - outputBuffer[charsRead] = ch; - charsRead++; - continue; // don't interprete chars in the buffer - } - - if (ch == '<') { - this.reader.unread(ch); - break; - } - - if ((ch == '&') && (str.length() > 1)) { - if (str.charAt(1) == '#') { - ch = XMLUtil.processCharLiteral(str); - } else { - XMLUtil.processEntity(str, this.reader, this.resolver); - continue; - } - } - - outputBuffer[charsRead] = ch; - charsRead++; - } - - if (charsRead == 0) { - charsRead = -1; - } - - return charsRead; - } catch (XMLParseException e) { - throw new IOException(e.getMessage()); - } - } - - - /** - * Skips remaining data and closes the stream. - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public void close() - throws IOException - { - try { - int bufferLength = this.buffer.length(); - - for (;;) { - String str = ""; - char ch; - - if (this.bufferIndex >= bufferLength) { - str = XMLUtil.read(this.reader, '&'); - ch = str.charAt(0); - } else { - ch = this.buffer.charAt(this.bufferIndex); - this.bufferIndex++; - continue; // don't interprete chars in the buffer - } - - if (ch == '<') { - this.reader.unread(ch); - break; - } - - if ((ch == '&') && (str.length() > 1)) { - if (str.charAt(1) != '#') { - XMLUtil.processEntity(str, this.reader, this.resolver); - } - } - } - } catch (XMLParseException e) { - throw new IOException(e.getMessage()); - } - } - -} diff --git a/core/src/processing/xml/PIReader.java b/core/src/processing/xml/PIReader.java deleted file mode 100644 index d6a2bf298..000000000 --- a/core/src/processing/xml/PIReader.java +++ /dev/null @@ -1,157 +0,0 @@ -/* PIReader.java NanoXML/Java - * - * $Revision: 1.3 $ - * $Date: 2002/01/04 21:03:28 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.Reader; -import java.io.IOException; - - -/** - * This reader reads data from another reader until the end of a processing - * instruction (?>) has been encountered. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ - */ -class PIReader - extends Reader -{ - - /** - * The encapsulated reader. - */ - private StdXMLReader reader; - - - /** - * True if the end of the stream has been reached. - */ - private boolean atEndOfData; - - - /** - * Creates the reader. - * - * @param reader the encapsulated reader - */ - PIReader(StdXMLReader reader) - { - this.reader = reader; - this.atEndOfData = false; - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.reader = null; - super.finalize(); - } - - - /** - * Reads a block of data. - * - * @param buffer where to put the read data - * @param offset first position in buffer to put the data - * @param size maximum number of chars to read - * - * @return the number of chars read, or -1 if at EOF - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public int read(char[] buffer, - int offset, - int size) - throws IOException - { - if (this.atEndOfData) { - return -1; - } - - int charsRead = 0; - - if ((offset + size) > buffer.length) { - size = buffer.length - offset; - } - - while (charsRead < size) { - char ch = this.reader.read(); - - if (ch == '?') { - char ch2 = this.reader.read(); - - if (ch2 == '>') { - this.atEndOfData = true; - break; - } - - this.reader.unread(ch2); - } - - buffer[charsRead] = ch; - charsRead++; - } - - if (charsRead == 0) { - charsRead = -1; - } - - return charsRead; - } - - - /** - * Skips remaining data and closes the stream. - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - public void close() - throws IOException - { - while (! this.atEndOfData) { - char ch = this.reader.read(); - - if (ch == '?') { - char ch2 = this.reader.read(); - - if (ch2 == '>') { - this.atEndOfData = true; - } - } - } - } - -} diff --git a/core/src/processing/xml/StdXMLBuilder.java b/core/src/processing/xml/StdXMLBuilder.java deleted file mode 100644 index b66f7f447..000000000 --- a/core/src/processing/xml/StdXMLBuilder.java +++ /dev/null @@ -1,330 +0,0 @@ -/* StdXMLBuilder.java NanoXML/Java - * - * $Revision: 1.3 $ - * $Date: 2002/01/04 21:03:28 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - -import java.io.IOException; -import java.io.Reader; -import java.util.Stack; - - -/** - * StdXMLBuilder creates a tree of XML elements from a data source. - * - * @see processing.xml.XMLElement - * - * @author Marc De Scheemaecker - */ -public class StdXMLBuilder { - /** - * This stack contains the current element and its parents. - */ - private Stack stack; - - - /** - * The root element of the parsed XML tree. - */ - private XMLElement root; - - private XMLElement parent; - - /** - * Creates the builder. - */ - public StdXMLBuilder() { - this(new XMLElement()); - this.stack = null; - this.root = null; - } - - - public StdXMLBuilder(XMLElement parent) { - this.parent = parent; - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - //this.prototype = null; - this.root = null; - this.stack.clear(); - this.stack = null; - super.finalize(); - } - - - /** - * This method is called before the parser starts processing its input. - * - * @param systemID the system ID of the XML data source. - * @param lineNr the line on which the parsing starts. - */ - public void startBuilding(String systemID, - int lineNr) - { - this.stack = new Stack(); - this.root = null; - } - - - /** - * This method is called when a processing instruction is encountered. - * PIs with target "xml" are handled by the parser. - * - * @param target the PI target. - * @param reader to read the data from the PI. - */ - public void newProcessingInstruction(String target, - Reader reader) - { - // nothing to do - } - - - /** - * This method is called when a new XML element is encountered. - * - * @see #endElement - * - * @param name the name of the element. - * @param nsPrefix the prefix used to identify the namespace. If no - * namespace has been specified, this parameter is null. - * @param nsURI the URI associated with the namespace. If no - * namespace has been specified, or no URI is - * associated with nsPrefix, this parameter is null. - * @param systemID the system ID of the XML data source. - * @param lineNr the line in the source where the element starts. - */ - public void startElement(String name, - String nsPrefix, - String nsURI, - String systemID, - int lineNr) - { - String fullName = name; - - if (nsPrefix != null) { - fullName = nsPrefix + ':' + name; - } - - //XMLElement elt = this.prototype.createElement(fullName, nsURI, - // systemID, lineNr); - -// XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr); -// -// if (this.stack.empty()) { -// this.root = elt; -// } else { -// XMLElement top = (XMLElement) this.stack.peek(); -// top.addChild(elt); -// } -// stack.push(elt); - - if (this.stack.empty()) { - //System.out.println("setting root"); - parent.init(fullName, nsURI, systemID, lineNr); - stack.push(parent); - root = parent; - } else { - XMLElement top = (XMLElement) this.stack.peek(); - //System.out.println("stack has " + top.getName()); - XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr); - top.addChild(elt); - stack.push(elt); - } - } - - - /** - * This method is called when the attributes of an XML element have been - * processed. - * - * @see #startElement - * @see #addAttribute - * - * @param name the name of the element. - * @param nsPrefix the prefix used to identify the namespace. If no - * namespace has been specified, this parameter is null. - * @param nsURI the URI associated with the namespace. If no - * namespace has been specified, or no URI is - * associated with nsPrefix, this parameter is null. - */ - public void elementAttributesProcessed(String name, - String nsPrefix, - String nsURI) - { - // nothing to do - } - - - /** - * This method is called when the end of an XML elemnt is encountered. - * - * @see #startElement - * - * @param name the name of the element. - * @param nsPrefix the prefix used to identify the namespace. If no - * namespace has been specified, this parameter is null. - * @param nsURI the URI associated with the namespace. If no - * namespace has been specified, or no URI is - * associated with nsPrefix, this parameter is null. - */ - public void endElement(String name, - String nsPrefix, - String nsURI) - { - XMLElement elt = (XMLElement) this.stack.pop(); - - if (elt.getChildCount() == 1) { - XMLElement child = elt.getChild(0); - - if (child.getLocalName() == null) { - elt.setContent(child.getContent()); - elt.removeChild(0); - } - } - } - - - /** - * This method is called when a new attribute of an XML element is - * encountered. - * - * @param key the key (name) of the attribute. - * @param nsPrefix the prefix used to identify the namespace. If no - * namespace has been specified, this parameter is null. - * @param nsURI the URI associated with the namespace. If no - * namespace has been specified, or no URI is - * associated with nsPrefix, this parameter is null. - * @param value the value of the attribute. - * @param type the type of the attribute. If no type is known, - * "CDATA" is returned. - * - * @throws java.lang.Exception - * If an exception occurred while processing the event. - */ - public void addAttribute(String key, - String nsPrefix, - String nsURI, - String value, - String type) - throws Exception - { - String fullName = key; - - if (nsPrefix != null) { - fullName = nsPrefix + ':' + key; - } - - XMLElement top = (XMLElement) this.stack.peek(); - - if (top.hasAttribute(fullName)) { - throw new XMLParseException(top.getSystemID(), - top.getLine(), - "Duplicate attribute: " + key); - } - -// if (nsPrefix != null) { -// top.setAttribute(fullName, nsURI, value); -// } else { - top.setString(fullName, value); -// } - } - - - /** - * This method is called when a PCDATA element is encountered. A Java - * reader is supplied from which you can read the data. The reader will - * only read the data of the element. You don't need to check for - * boundaries. If you don't read the full element, the rest of the data - * is skipped. You also don't have to care about entities; they are - * resolved by the parser. - * - * @param reader the Java reader from which you can retrieve the data. - * @param systemID the system ID of the XML data source. - * @param lineNr the line in the source where the element starts. - */ - public void addPCData(Reader reader, - String systemID, - int lineNr) - { - int bufSize = 2048; - int sizeRead = 0; - StringBuffer str = new StringBuffer(bufSize); - char[] buf = new char[bufSize]; - - for (;;) { - if (sizeRead >= bufSize) { - bufSize *= 2; - str.ensureCapacity(bufSize); - } - - int size; - - try { - size = reader.read(buf); - } catch (IOException e) { - break; - } - - if (size < 0) { - break; - } - - str.append(buf, 0, size); - sizeRead += size; - } - - //XMLElement elt = this.prototype.createElement(null, systemID, lineNr); - XMLElement elt = new XMLElement(null, null, systemID, lineNr); - elt.setContent(str.toString()); - - if (! this.stack.empty()) { - XMLElement top = (XMLElement) this.stack.peek(); - top.addChild(elt); - } - } - - - /** - * Returns the result of the building process. This method is called just - * before the parse method of StdXMLParser returns. - * - * @return the result of the building process. - */ - public Object getResult() - { - return this.root; - } - -} diff --git a/core/src/processing/xml/StdXMLParser.java b/core/src/processing/xml/StdXMLParser.java deleted file mode 100644 index b38f9d73c..000000000 --- a/core/src/processing/xml/StdXMLParser.java +++ /dev/null @@ -1,685 +0,0 @@ -/* StdXMLParser.java NanoXML/Java - * - * $Revision: 1.5 $ - * $Date: 2002/03/24 11:37:00 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.Reader; -import java.util.Enumeration; -import java.util.Properties; -import java.util.Vector; - - -/** - * StdXMLParser is the core parser of NanoXML. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $ - */ -public class StdXMLParser { - - /** - * The builder which creates the logical structure of the XML data. - */ - private StdXMLBuilder builder; - - - /** - * The reader from which the parser retrieves its data. - */ - private StdXMLReader reader; - - - /** - * The entity resolver. - */ - private XMLEntityResolver entityResolver; - - - /** - * The validator that will process entity references and validate the XML - * data. - */ - private XMLValidator validator; - - - /** - * Creates a new parser. - */ - public StdXMLParser() - { - this.builder = null; - this.validator = null; - this.reader = null; - this.entityResolver = new XMLEntityResolver(); - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.builder = null; - this.reader = null; - this.entityResolver = null; - this.validator = null; - super.finalize(); - } - - - /** - * Sets the builder which creates the logical structure of the XML data. - * - * @param builder the non-null builder - */ - public void setBuilder(StdXMLBuilder builder) - { - this.builder = builder; - } - - - /** - * Returns the builder which creates the logical structure of the XML data. - * - * @return the builder - */ - public StdXMLBuilder getBuilder() - { - return this.builder; - } - - - /** - * Sets the validator that validates the XML data. - * - * @param validator the non-null validator - */ - public void setValidator(XMLValidator validator) - { - this.validator = validator; - } - - - /** - * Returns the validator that validates the XML data. - * - * @return the validator - */ - public XMLValidator getValidator() - { - return this.validator; - } - - - /** - * Sets the entity resolver. - * - * @param resolver the non-null resolver - */ - public void setResolver(XMLEntityResolver resolver) - { - this.entityResolver = resolver; - } - - - /** - * Returns the entity resolver. - * - * @return the non-null resolver - */ - public XMLEntityResolver getResolver() - { - return this.entityResolver; - } - - - /** - * Sets the reader from which the parser retrieves its data. - * - * @param reader the reader - */ - public void setReader(StdXMLReader reader) - { - this.reader = reader; - } - - - /** - * Returns the reader from which the parser retrieves its data. - * - * @return the reader - */ - public StdXMLReader getReader() - { - return this.reader; - } - - - /** - * Parses the data and lets the builder create the logical data structure. - * - * @return the logical structure built by the builder - * - * @throws net.n3.nanoxml.XMLException - * if an error occurred reading or parsing the data - */ - public Object parse() - throws XMLException - { - try { - this.builder.startBuilding(this.reader.getSystemID(), - this.reader.getLineNr()); - this.scanData(); - return this.builder.getResult(); - } catch (XMLException e) { - throw e; - } catch (Exception e) { - throw new XMLException(e); - } - } - - - /** - * Scans the XML data for elements. - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void scanData() throws Exception { - while ((! this.reader.atEOF()) && (this.builder.getResult() == null)) { - String str = XMLUtil.read(this.reader, '&'); - char ch = str.charAt(0); - if (ch == '&') { - XMLUtil.processEntity(str, this.reader, this.entityResolver); - continue; - } - - switch (ch) { - case '<': - this.scanSomeTag(false, // don't allow CDATA - null, // no default namespace - new Properties()); - break; - - case ' ': - case '\t': - case '\r': - case '\n': - // skip whitespace - break; - - default: - XMLUtil.errorInvalidInput(reader.getSystemID(), - reader.getLineNr(), - "`" + ch + "' (0x" - + Integer.toHexString((int) ch) - + ')'); - } - } - } - - - /** - * Scans an XML tag. - * - * @param allowCDATA true if CDATA sections are allowed at this point - * @param defaultNamespace the default namespace URI (or null) - * @param namespaces list of defined namespaces - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void scanSomeTag(boolean allowCDATA, - String defaultNamespace, - Properties namespaces) - throws Exception - { - String str = XMLUtil.read(this.reader, '&'); - char ch = str.charAt(0); - - if (ch == '&') { - XMLUtil.errorUnexpectedEntity(reader.getSystemID(), - reader.getLineNr(), - str); - } - - switch (ch) { - case '?': - this.processPI(); - break; - - case '!': - this.processSpecialTag(allowCDATA); - break; - - default: - this.reader.unread(ch); - this.processElement(defaultNamespace, namespaces); - } - } - - - /** - * Processes a "processing instruction". - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void processPI() - throws Exception - { - XMLUtil.skipWhitespace(this.reader, null); - String target = XMLUtil.scanIdentifier(this.reader); - XMLUtil.skipWhitespace(this.reader, null); - Reader r = new PIReader(this.reader); - - if (!target.equalsIgnoreCase("xml")) { - this.builder.newProcessingInstruction(target, r); - } - - r.close(); - } - - - /** - * Processes a tag that starts with a bang (<!...>). - * - * @param allowCDATA true if CDATA sections are allowed at this point - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void processSpecialTag(boolean allowCDATA) - throws Exception - { - String str = XMLUtil.read(this.reader, '&'); - char ch = str.charAt(0); - - if (ch == '&') { - XMLUtil.errorUnexpectedEntity(reader.getSystemID(), - reader.getLineNr(), - str); - } - - switch (ch) { - case '[': - if (allowCDATA) { - this.processCDATA(); - } else { - XMLUtil.errorUnexpectedCDATA(reader.getSystemID(), - reader.getLineNr()); - } - - return; - - case 'D': - this.processDocType(); - return; - - case '-': - XMLUtil.skipComment(this.reader); - return; - } - } - - - /** - * Processes a CDATA section. - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void processCDATA() throws Exception { - if (! XMLUtil.checkLiteral(this.reader, "CDATA[")) { - XMLUtil.errorExpectedInput(reader.getSystemID(), - reader.getLineNr(), - "') { - XMLUtil.errorExpectedInput(reader.getSystemID(), - reader.getLineNr(), - "`>'"); - } - - // TODO DTD checking is currently disabled, because it breaks - // applications that don't have access to a net connection - // (since it insists on going and checking out the DTD). - if (false) { - if (systemID != null) { - Reader r = this.reader.openStream(publicID.toString(), systemID); - this.reader.startNewStream(r); - this.reader.setSystemID(systemID); - this.reader.setPublicID(publicID.toString()); - this.validator.parseDTD(publicID.toString(), - this.reader, - this.entityResolver, - true); - } - } - } - - - /** - * Processes a regular element. - * - * @param defaultNamespace the default namespace URI (or null) - * @param namespaces list of defined namespaces - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void processElement(String defaultNamespace, - Properties namespaces) - throws Exception - { - String fullName = XMLUtil.scanIdentifier(this.reader); - String name = fullName; - XMLUtil.skipWhitespace(this.reader, null); - String prefix = null; - int colonIndex = name.indexOf(':'); - - if (colonIndex > 0) { - prefix = name.substring(0, colonIndex); - name = name.substring(colonIndex + 1); - } - - Vector attrNames = new Vector(); - Vector attrValues = new Vector(); - Vector attrTypes = new Vector(); - - this.validator.elementStarted(fullName, - this.reader.getSystemID(), - this.reader.getLineNr()); - char ch; - - for (;;) { - ch = this.reader.read(); - - if ((ch == '/') || (ch == '>')) { - break; - } - - this.reader.unread(ch); - this.processAttribute(attrNames, attrValues, attrTypes); - XMLUtil.skipWhitespace(this.reader, null); - } - - Properties extraAttributes = new Properties(); - this.validator.elementAttributesProcessed(fullName, - extraAttributes, - this.reader.getSystemID(), - this.reader.getLineNr()); - Enumeration en = extraAttributes.keys(); - - while (en.hasMoreElements()) { - String key = (String) en.nextElement(); - String value = extraAttributes.getProperty(key); - attrNames.addElement(key); - attrValues.addElement(value); - attrTypes.addElement("CDATA"); - } - - // post 1.2.1, just treat namespaces like any other attribute -// for (int i = 0; i < attrNames.size(); i++) { -// String key = (String) attrNames.elementAt(i); -// String value = (String) attrValues.elementAt(i); -// //String type = (String) attrTypes.elementAt(i); - -// if (key.equals("xmlns")) { -// defaultNamespace = value; -// } else if (key.startsWith("xmlns:")) { -// namespaces.put(key.substring(6), value); -// } -// } - - if (prefix == null) { - this.builder.startElement(name, prefix, defaultNamespace, - this.reader.getSystemID(), - this.reader.getLineNr()); - } else { - this.builder.startElement(name, prefix, - namespaces.getProperty(prefix), - this.reader.getSystemID(), - this.reader.getLineNr()); - } - - for (int i = 0; i < attrNames.size(); i++) { - String key = (String) attrNames.elementAt(i); - -// if (key.startsWith("xmlns")) { -// continue; -// } - - String value = (String) attrValues.elementAt(i); - String type = (String) attrTypes.elementAt(i); - colonIndex = key.indexOf(':'); - - if (colonIndex > 0) { - String attPrefix = key.substring(0, colonIndex); - key = key.substring(colonIndex + 1); - this.builder.addAttribute(key, attPrefix, - namespaces.getProperty(attPrefix), - value, type); - } else { - this.builder.addAttribute(key, null, null, value, type); - } - } - - if (prefix == null) { - this.builder.elementAttributesProcessed(name, prefix, - defaultNamespace); - } else { - this.builder.elementAttributesProcessed(name, prefix, - namespaces - .getProperty(prefix)); - } - - if (ch == '/') { - if (this.reader.read() != '>') { - XMLUtil.errorExpectedInput(reader.getSystemID(), - reader.getLineNr(), - "`>'"); - } - - this.validator.elementEnded(name, - this.reader.getSystemID(), - this.reader.getLineNr()); - - if (prefix == null) { - this.builder.endElement(name, prefix, defaultNamespace); - } else { - this.builder.endElement(name, prefix, - namespaces.getProperty(prefix)); - } - - return; - } - - StringBuffer buffer = new StringBuffer(16); - - for (;;) { - buffer.setLength(0); - String str; - - for (;;) { - XMLUtil.skipWhitespace(this.reader, buffer); - str = XMLUtil.read(this.reader, '&'); - - if ((str.charAt(0) == '&') && (str.charAt(1) != '#')) { - XMLUtil.processEntity(str, this.reader, - this.entityResolver); - } else { - break; - } - } - - if (str.charAt(0) == '<') { - str = XMLUtil.read(this.reader, '\0'); - - if (str.charAt(0) == '/') { - XMLUtil.skipWhitespace(this.reader, null); - str = XMLUtil.scanIdentifier(this.reader); - - if (! str.equals(fullName)) { - XMLUtil.errorWrongClosingTag(reader.getSystemID(), - reader.getLineNr(), - name, str); - } - - XMLUtil.skipWhitespace(this.reader, null); - - if (this.reader.read() != '>') { - XMLUtil.errorClosingTagNotEmpty(reader.getSystemID(), - reader.getLineNr()); - } - - this.validator.elementEnded(fullName, - this.reader.getSystemID(), - this.reader.getLineNr()); - if (prefix == null) { - this.builder.endElement(name, prefix, defaultNamespace); - } else { - this.builder.endElement(name, prefix, - namespaces.getProperty(prefix)); - } - break; - } else { // <[^/] - this.reader.unread(str.charAt(0)); - this.scanSomeTag(true, //CDATA allowed - defaultNamespace, - (Properties) namespaces.clone()); - } - } else { // [^<] - if (str.charAt(0) == '&') { - ch = XMLUtil.processCharLiteral(str); - buffer.append(ch); - } else { - reader.unread(str.charAt(0)); - } - this.validator.PCDataAdded(this.reader.getSystemID(), - this.reader.getLineNr()); - Reader r = new ContentReader(this.reader, - this.entityResolver, - buffer.toString()); - this.builder.addPCData(r, this.reader.getSystemID(), - this.reader.getLineNr()); - r.close(); - } - } - } - - - /** - * Processes an attribute of an element. - * - * @param attrNames contains the names of the attributes. - * @param attrValues contains the values of the attributes. - * @param attrTypes contains the types of the attributes. - * - * @throws java.lang.Exception - * if something went wrong - */ - protected void processAttribute(Vector attrNames, - Vector attrValues, - Vector attrTypes) - throws Exception - { - String key = XMLUtil.scanIdentifier(this.reader); - XMLUtil.skipWhitespace(this.reader, null); - - if (! XMLUtil.read(this.reader, '&').equals("=")) { - XMLUtil.errorExpectedInput(reader.getSystemID(), - reader.getLineNr(), - "`='"); - } - - XMLUtil.skipWhitespace(this.reader, null); - String value = XMLUtil.scanString(this.reader, '&', - this.entityResolver); - attrNames.addElement(key); - attrValues.addElement(value); - attrTypes.addElement("CDATA"); - this.validator.attributeAdded(key, value, - this.reader.getSystemID(), - this.reader.getLineNr()); - } - -} diff --git a/core/src/processing/xml/StdXMLReader.java b/core/src/processing/xml/StdXMLReader.java deleted file mode 100644 index e2d97a580..000000000 --- a/core/src/processing/xml/StdXMLReader.java +++ /dev/null @@ -1,626 +0,0 @@ -/* StdXMLReader.java NanoXML/Java - * - * $Revision: 1.4 $ - * $Date: 2002/01/04 21:03:28 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.IOException; -//import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.LineNumberReader; -import java.io.PushbackReader; -import java.io.PushbackInputStream; -import java.io.Reader; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Stack; - - -/** - * StdXMLReader reads the data to be parsed. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ -public class StdXMLReader -{ - - /** - * A stacked reader. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ - private class StackedReader - { - - PushbackReader pbReader; - - LineNumberReader lineReader; - - URL systemId; - - String publicId; - - } - - - /** - * The stack of readers. - */ - private Stack readers; - - - /** - * The current push-back reader. - */ - private StackedReader currentReader; - - - /** - * Creates a new reader using a string as input. - * - * @param str the string containing the XML data - */ - public static StdXMLReader stringReader(String str) - { - return new StdXMLReader(new StringReader(str)); - } - - - /** - * Creates a new reader using a file as input. - * - * @param filename the name of the file containing the XML data - * - * @throws java.io.FileNotFoundException - * if the file could not be found - * @throws java.io.IOException - * if an I/O error occurred - */ - public static StdXMLReader fileReader(String filename) - throws FileNotFoundException, - IOException - { - StdXMLReader r = new StdXMLReader(new FileInputStream(filename)); - r.setSystemID(filename); - - for (int i = 0; i < r.readers.size(); i++) { - StackedReader sr = (StackedReader) r.readers.elementAt(i); - sr.systemId = r.currentReader.systemId; - } - - return r; - } - - - /** - * Initializes the reader from a system and public ID. - * - * @param publicID the public ID which may be null. - * @param systemID the non-null system ID. - * - * @throws MalformedURLException - * if the system ID does not contain a valid URL - * @throws FileNotFoundException - * if the system ID refers to a local file which does not exist - * @throws IOException - * if an error occurred opening the stream - */ - public StdXMLReader(String publicID, - String systemID) - throws MalformedURLException, - FileNotFoundException, - IOException - { - URL systemIDasURL = null; - - try { - systemIDasURL = new URL(systemID); - } catch (MalformedURLException e) { - systemID = "file:" + systemID; - - try { - systemIDasURL = new URL(systemID); - } catch (MalformedURLException e2) { - throw e; - } - } - - this.currentReader = new StackedReader(); - this.readers = new Stack(); - Reader reader = this.openStream(publicID, systemIDasURL.toString()); - this.currentReader.lineReader = new LineNumberReader(reader); - this.currentReader.pbReader - = new PushbackReader(this.currentReader.lineReader, 2); - } - - - /** - * Initializes the XML reader. - * - * @param reader the input for the XML data. - */ - public StdXMLReader(Reader reader) - { - this.currentReader = new StackedReader(); - this.readers = new Stack(); - this.currentReader.lineReader = new LineNumberReader(reader); - this.currentReader.pbReader - = new PushbackReader(this.currentReader.lineReader, 2); - this.currentReader.publicId = ""; - - try { - this.currentReader.systemId = new URL("file:."); - } catch (MalformedURLException e) { - // never happens - } - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.currentReader.lineReader = null; - this.currentReader.pbReader = null; - this.currentReader.systemId = null; - this.currentReader.publicId = null; - this.currentReader = null; - this.readers.clear(); - super.finalize(); - } - - - /** - * Scans the encoding from an <?xml...?> tag. - * - * @param str the first tag in the XML data. - * - * @return the encoding, or null if no encoding has been specified. - */ - protected String getEncoding(String str) - { - if (! str.startsWith("= 'a') - && (str.charAt(index) <= 'z')) { - key.append(str.charAt(index)); - index++; - } - - while ((index < str.length()) && (str.charAt(index) <= ' ')) { - index++; - } - - if ((index >= str.length()) || (str.charAt(index) != '=')) { - break; - } - - while ((index < str.length()) && (str.charAt(index) != '\'') - && (str.charAt(index) != '"')) { - index++; - } - - if (index >= str.length()) { - break; - } - - char delimiter = str.charAt(index); - index++; - int index2 = str.indexOf(delimiter, index); - - if (index2 < 0) { - break; - } - - if (key.toString().equals("encoding")) { - return str.substring(index, index2); - } - - index = index2 + 1; - } - - return null; - } - - - /** - * Converts a stream to a reader while detecting the encoding. - * - * @param stream the input for the XML data. - * @param charsRead buffer where to put characters that have been read - * - * @throws java.io.IOException - * if an I/O error occurred - */ - protected Reader stream2reader(InputStream stream, - StringBuffer charsRead) - throws IOException - { - PushbackInputStream pbstream = new PushbackInputStream(stream); - int b = pbstream.read(); - - switch (b) { - case 0x00: - case 0xFE: - case 0xFF: - pbstream.unread(b); - return new InputStreamReader(pbstream, "UTF-16"); - - case 0xEF: - for (int i = 0; i < 2; i++) { - pbstream.read(); - } - - return new InputStreamReader(pbstream, "UTF-8"); - - case 0x3C: - b = pbstream.read(); - charsRead.append('<'); - - while ((b > 0) && (b != 0x3E)) { - charsRead.append((char) b); - b = pbstream.read(); - } - - if (b > 0) { - charsRead.append((char) b); - } - - String encoding = this.getEncoding(charsRead.toString()); - - if (encoding == null) { - return new InputStreamReader(pbstream, "UTF-8"); - } - - charsRead.setLength(0); - - try { - return new InputStreamReader(pbstream, encoding); - } catch (UnsupportedEncodingException e) { - return new InputStreamReader(pbstream, "UTF-8"); - } - - default: - charsRead.append((char) b); - return new InputStreamReader(pbstream, "UTF-8"); - } - } - - - /** - * Initializes the XML reader. - * - * @param stream the input for the XML data. - * - * @throws java.io.IOException - * if an I/O error occurred - */ - public StdXMLReader(InputStream stream) - throws IOException - { - // unused? - //PushbackInputStream pbstream = new PushbackInputStream(stream); - StringBuffer charsRead = new StringBuffer(); - Reader reader = this.stream2reader(stream, charsRead); - this.currentReader = new StackedReader(); - this.readers = new Stack(); - this.currentReader.lineReader = new LineNumberReader(reader); - this.currentReader.pbReader - = new PushbackReader(this.currentReader.lineReader, 2); - this.currentReader.publicId = ""; - - try { - this.currentReader.systemId = new URL("file:."); - } catch (MalformedURLException e) { - // never happens - } - - this.startNewStream(new StringReader(charsRead.toString())); - } - - - /** - * Reads a character. - * - * @return the character - * - * @throws java.io.IOException - * if no character could be read - */ - public char read() - throws IOException - { - int ch = this.currentReader.pbReader.read(); - - while (ch < 0) { - if (this.readers.empty()) { - throw new IOException("Unexpected EOF"); - } - - this.currentReader.pbReader.close(); - this.currentReader = (StackedReader) this.readers.pop(); - ch = this.currentReader.pbReader.read(); - } - - return (char) ch; - } - - - /** - * Returns true if the current stream has no more characters left to be - * read. - * - * @throws java.io.IOException - * if an I/O error occurred - */ - public boolean atEOFOfCurrentStream() - throws IOException - { - int ch = this.currentReader.pbReader.read(); - - if (ch < 0) { - return true; - } else { - this.currentReader.pbReader.unread(ch); - return false; - } - } - - - /** - * Returns true if there are no more characters left to be read. - * - * @throws java.io.IOException - * if an I/O error occurred - */ - public boolean atEOF() - throws IOException - { - int ch = this.currentReader.pbReader.read(); - - while (ch < 0) { - if (this.readers.empty()) { - return true; - } - - this.currentReader.pbReader.close(); - this.currentReader = (StackedReader) this.readers.pop(); - ch = this.currentReader.pbReader.read(); - } - - this.currentReader.pbReader.unread(ch); - return false; - } - - - /** - * Pushes the last character read back to the stream. - * - * @param ch the character to push back. - * - * @throws java.io.IOException - * if an I/O error occurred - */ - public void unread(char ch) - throws IOException - { - this.currentReader.pbReader.unread(ch); - } - - - /** - * Opens a stream from a public and system ID. - * - * @param publicID the public ID, which may be null - * @param systemID the system ID, which is never null - * - * @throws java.net.MalformedURLException - * if the system ID does not contain a valid URL - * @throws java.io.FileNotFoundException - * if the system ID refers to a local file which does not exist - * @throws java.io.IOException - * if an error occurred opening the stream - */ - public Reader openStream(String publicID, - String systemID) - throws MalformedURLException, - FileNotFoundException, - IOException - { - URL url = new URL(this.currentReader.systemId, systemID); - - if (url.getRef() != null) { - String ref = url.getRef(); - - if (url.getFile().length() > 0) { - url = new URL(url.getProtocol(), url.getHost(), url.getPort(), - url.getFile()); - url = new URL("jar:" + url + '!' + ref); - } else { - url = StdXMLReader.class.getResource(ref); - } - } - - this.currentReader.publicId = publicID; - this.currentReader.systemId = url; - StringBuffer charsRead = new StringBuffer(); - Reader reader = this.stream2reader(url.openStream(), charsRead); - - if (charsRead.length() == 0) { - return reader; - } - - String charsReadStr = charsRead.toString(); - PushbackReader pbreader = new PushbackReader(reader, - charsReadStr.length()); - - for (int i = charsReadStr.length() - 1; i >= 0; i--) { - pbreader.unread(charsReadStr.charAt(i)); - } - - return pbreader; - } - - - /** - * Starts a new stream from a Java reader. The new stream is used - * temporary to read data from. If that stream is exhausted, control - * returns to the parent stream. - * - * @param reader the non-null reader to read the new data from - */ - public void startNewStream(Reader reader) - { - this.startNewStream(reader, false); - } - - - /** - * Starts a new stream from a Java reader. The new stream is used - * temporary to read data from. If that stream is exhausted, control - * returns to the parent stream. - * - * @param reader the non-null reader to read the new data from - * @param isInternalEntity true if the reader is produced by resolving - * an internal entity - */ - public void startNewStream(Reader reader, - boolean isInternalEntity) - { - StackedReader oldReader = this.currentReader; - this.readers.push(this.currentReader); - this.currentReader = new StackedReader(); - - if (isInternalEntity) { - this.currentReader.lineReader = null; - this.currentReader.pbReader = new PushbackReader(reader, 2); - } else { - this.currentReader.lineReader = new LineNumberReader(reader); - this.currentReader.pbReader - = new PushbackReader(this.currentReader.lineReader, 2); - } - - this.currentReader.systemId = oldReader.systemId; - this.currentReader.publicId = oldReader.publicId; - } - - - /** - * Returns the current "level" of the stream on the stack of streams. - */ - public int getStreamLevel() - { - return this.readers.size(); - } - - - /** - * Returns the line number of the data in the current stream. - */ - public int getLineNr() - { - if (this.currentReader.lineReader == null) { - StackedReader sr = (StackedReader) this.readers.peek(); - - if (sr.lineReader == null) { - return 0; - } else { - return sr.lineReader.getLineNumber() + 1; - } - } - - return this.currentReader.lineReader.getLineNumber() + 1; - } - - - /** - * Sets the system ID of the current stream. - * - * @param systemID the system ID - * - * @throws java.net.MalformedURLException - * if the system ID does not contain a valid URL - */ - public void setSystemID(String systemID) - throws MalformedURLException - { - this.currentReader.systemId = new URL(this.currentReader.systemId, - systemID); - } - - - /** - * Sets the public ID of the current stream. - * - * @param publicID the public ID - */ - public void setPublicID(String publicID) - { - this.currentReader.publicId = publicID; - } - - - /** - * Returns the current system ID. - */ - public String getSystemID() - { - return this.currentReader.systemId.toString(); - } - - - /** - * Returns the current public ID. - */ - public String getPublicID() - { - return this.currentReader.publicId; - } - -} diff --git a/core/src/processing/xml/XMLAttribute.java b/core/src/processing/xml/XMLAttribute.java deleted file mode 100644 index ebb71d1f0..000000000 --- a/core/src/processing/xml/XMLAttribute.java +++ /dev/null @@ -1,153 +0,0 @@ -/* XMLAttribute.java NanoXML/Java - * - * $Revision: 1.4 $ - * $Date: 2002/01/04 21:03:29 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -/** - * An attribute in an XML element. This is an internal class. - * - * @see net.n3.nanoxml.XMLElement - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ -class XMLAttribute -{ - - /** - * The full name of the attribute. - */ - private String name; - - - /** - * The short name of the attribute. - */ - private String localName; - - - /** - * The namespace URI of the attribute. - */ - private String namespace; - - - /** - * The value of the attribute. - */ - private String value; - - - /** - * The type of the attribute. - */ - private String type; - - - /** - * Creates a new attribute. - * - * @param fullName the non-null full name - * @param name the non-null short name - * @param namespace the namespace URI, which may be null - * @param value the value of the attribute - * @param type the type of the attribute - */ - XMLAttribute(String fullName, - String name, - String namespace, - String value, - String type) - { - this.name = fullName; - this.localName = name; - this.namespace = namespace; - this.value = value; - this.type = type; - } - - - /** - * Returns the full name of the attribute. - */ - String getName() - { - return this.name; - } - - - /** - * Returns the short name of the attribute. - */ - String getLocalName() - { - return this.localName; - } - - - /** - * Returns the namespace of the attribute. - */ - String getNamespace() - { - return this.namespace; - } - - - /** - * Returns the value of the attribute. - */ - String getValue() - { - return this.value; - } - - - /** - * Sets the value of the attribute. - * - * @param value the new value. - */ - void setValue(String value) - { - this.value = value; - } - - - /** - * Returns the type of the attribute. - * - * @param type the new type. - */ - String getType() - { - return this.type; - } - -} diff --git a/core/src/processing/xml/XMLElement.java b/core/src/processing/xml/XMLElement.java deleted file mode 100644 index 2e376dca9..000000000 --- a/core/src/processing/xml/XMLElement.java +++ /dev/null @@ -1,1513 +0,0 @@ -/* XMLElement.java NanoXML/Java - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - -import java.io.*; -import java.util.*; - -import processing.core.PApplet; - - -/** - * XMLElement is a representation of an XML object. The object is able to parse XML code. The methods described here are the most basic. More are documented in the Developer's Reference. - *

- * The encoding parameter inside XML files is ignored, only UTF-8 (or plain ASCII) are parsed properly. - * =advanced - * XMLElement is an XML element. This is the base class used for the - * Processing XML library, representing a single node of an XML tree. - * - * This code is based on a modified version of NanoXML by Marc De Scheemaecker. - * - * @author Marc De Scheemaecker - * @author processing.org - * - * @webref data:composite - * @usage Web & Application - * @instanceName xml any variable of type XMLElement - */ -@SuppressWarnings("serial") -public class XMLElement implements Serializable { - /** No line number defined. */ - public static final int NO_LINE = -1; - - /** The sketch creating this element. */ - private PApplet sketch; - - /** The parent element. */ - private XMLElement parent; - - /** The attributes of the element. */ - private Vector attributes; - - /** The child elements. */ - private Vector children; - - /** The name of the element. */ - private String name; - - /** The full name of the element (includes the namespace). */ - private String fullName; - - /** The namespace URI. */ - private String namespace; - - /** The content of the element. */ - private String content; - - /** The system ID of the source data where this element is located. */ - private String systemID; - - /** The line in the source data where this element starts. */ - private int line; - - - /** - * Creates an empty element to be used for #PCDATA content. - * @nowebref - */ - public XMLElement() { - this(null, null, null, NO_LINE); - } - - - /** - * Creates an empty element. - * - * @param fullName the name of the element. - */ - public XMLElement(String fullName) { - this(fullName, null, null, NO_LINE); - } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the name of the element. -// * @param systemID the system ID of the XML data where the element starts. -// * @param lineNr the line in the XML data where the element starts. -// */ -// public XMLElement(String fullName, -// String systemID, -// int lineNr) { -// this(fullName, null, systemID, lineNr); -// } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the full name of the element -// * @param namespace the namespace URI. -// */ -// public XMLElement(String fullName, -// String namespace) { -// this(fullName, namespace, null, NO_LINE); -// } - - - /** - * Creates an empty element. (Used internally for parsing/building.) - * - * @param fullName the full name of the element - * @param namespace the namespace URI. - * @param systemID the system ID of the XML data where the element starts. - * @param lineNr the line in the XML data where the element starts. - * @nowebref - */ - public XMLElement(String fullName, - String namespace, - String systemID, - int lineNr) { - this.attributes = new Vector(); - this.children = new Vector(8); - this.fullName = fullName; - if (namespace == null) { - this.name = fullName; - } else { - int index = fullName.indexOf(':'); - if (index >= 0) { - this.name = fullName.substring(index + 1); - } else { - this.name = fullName; - } - } - this.namespace = namespace; - this.content = null; - this.line = lineNr; - this.systemID = systemID; - this.parent = null; - } - - - /** - * Begin parsing XML data passed in from a PApplet. This code - * wraps exception handling, for more advanced exception handling, - * use the constructor that takes a Reader or InputStream. - * @author processing.org - * @param filename name of the XML file to load - * @param parent typically use "this" - */ - public XMLElement(PApplet sketch, String filename) { - this(); - this.sketch = sketch; - init(sketch.createReader(filename)); - } - - - public XMLElement(Reader reader) { - this(); - init(reader); - } - - - static public XMLElement parse(String xml) { - return parse(new StringReader(xml)); - } - - - static public XMLElement parse(Reader r) { - try { - StdXMLParser parser = new StdXMLParser(); - parser.setBuilder(new StdXMLBuilder()); - parser.setValidator(new XMLValidator()); - parser.setReader(new StdXMLReader(r)); - return (XMLElement) parser.parse(); - } catch (XMLException e) { - e.printStackTrace(); - return null; - } - } - - - protected void init(String fullName, - String namespace, - String systemID, - int lineNr) { - this.fullName = fullName; - if (namespace == null) { - this.name = fullName; - } else { - int index = fullName.indexOf(':'); - if (index >= 0) { - this.name = fullName.substring(index + 1); - } else { - this.name = fullName; - } - } - this.namespace = namespace; - this.line = lineNr; - this.systemID = systemID; - } - - - protected void init(Reader r) { - try { - StdXMLParser parser = new StdXMLParser(); - parser.setBuilder(new StdXMLBuilder(this)); - parser.setValidator(new XMLValidator()); - parser.setReader(new StdXMLReader(r)); - parser.parse(); - } catch (XMLException e) { - e.printStackTrace(); - } - } - - -// /** -// * Creates an element to be used for #PCDATA content. -// */ -// public XMLElement createPCDataElement() { -// return new XMLElement(); -// } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the name of the element. -// */ -// public XMLElement createElement(String fullName) { -// return new XMLElement(fullName); -// } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the name of the element. -// * @param systemID the system ID of the XML data where the element starts. -// * @param lineNr the line in the XML data where the element starts. -// */ -// public XMLElement createElement(String fullName, -// String systemID, -// int lineNr) { -// //return new XMLElement(fullName, systemID, lineNr); -// return new XMLElement(fullName, null, systemID, lineNr); -// } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the full name of the element -// * @param namespace the namespace URI. -// */ -// public XMLElement createElement(String fullName, -// String namespace) { -// //return new XMLElement(fullName, namespace); -// return new XMLElement(fullName, namespace, null, NO_LINE); -// } - - -// /** -// * Creates an empty element. -// * -// * @param fullName the full name of the element -// * @param namespace the namespace URI. -// * @param systemID the system ID of the XML data where the element starts. -// * @param lineNr the line in the XML data where the element starts. -// */ -// public XMLElement createElement(String fullName, -// String namespace, -// String systemID, -// int lineNr) { -// return new XMLElement(fullName, namespace, systemID, lineNr); -// } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() throws Throwable { - this.attributes.clear(); - this.attributes = null; - this.children = null; - this.fullName = null; - this.name = null; - this.namespace = null; - this.content = null; - this.systemID = null; - this.parent = null; - super.finalize(); - } - - - /** - * Returns the parent element. This method returns null for the root - * element. - */ - public XMLElement getParent() { - return this.parent; - } - - - /** - * Returns the full name (i.e. the name including an eventual namespace - * prefix) of the element. - * - * @webref - * @brief Returns the name of the element. - * @return the name, or null if the element only contains #PCDATA. - */ - public String getName() { - return this.fullName; - } - - - /** - * Returns the name of the element without its namespace. - * - * @return the name, or null if the element only contains #PCDATA. - */ - public String getLocalName() { - return this.name; - } - - - /** - * Returns the namespace of the element. - * - * @return the namespace, or null if no namespace is associated with the - * element. - */ - public String getNamespace() { - return this.namespace; - } - - - /** - * Sets the full name. This method also sets the short name and clears the - * namespace URI. - * - * @param name the non-null name. - */ - public void setName(String name) { - this.name = name; - this.fullName = name; - this.namespace = null; - } - - - /** - * Sets the name. - * - * @param fullName the non-null full name. - * @param namespace the namespace URI, which may be null. - */ - public void setName(String fullName, String namespace) { - int index = fullName.indexOf(':'); - if ((namespace == null) || (index < 0)) { - this.name = fullName; - } else { - this.name = fullName.substring(index + 1); - } - this.fullName = fullName; - this.namespace = namespace; - } - - - /** - * Adds a child element. - * - * @param child the non-null child to add. - */ - public void addChild(XMLElement child) { - if (child == null) { - throw new IllegalArgumentException("child must not be null"); - } - if ((child.getLocalName() == null) && (! this.children.isEmpty())) { - XMLElement lastChild = (XMLElement) this.children.lastElement(); - - if (lastChild.getLocalName() == null) { - lastChild.setContent(lastChild.getContent() - + child.getContent()); - return; - } - } - ((XMLElement)child).parent = this; - this.children.addElement(child); - } - - - /** - * Inserts a child element. - * - * @param child the non-null child to add. - * @param index where to put the child. - */ - public void insertChild(XMLElement child, int index) { - if (child == null) { - throw new IllegalArgumentException("child must not be null"); - } - if ((child.getLocalName() == null) && (! this.children.isEmpty())) { - XMLElement lastChild = (XMLElement) this.children.lastElement(); - if (lastChild.getLocalName() == null) { - lastChild.setContent(lastChild.getContent() - + child.getContent()); - return; - } - } - ((XMLElement) child).parent = this; - this.children.insertElementAt(child, index); - } - - - /** - * Removes a child element. - * - * @param child the non-null child to remove. - */ - public void removeChild(XMLElement child) { - if (child == null) { - throw new IllegalArgumentException("child must not be null"); - } - this.children.removeElement(child); - } - - - /** - * Removes the child located at a certain index. - * - * @param index the index of the child, where the first child has index 0. - */ - public void removeChild(int index) { - children.removeElementAt(index); - } - - -// /** -// * Returns an enumeration of all child elements. -// * -// * @return the non-null enumeration -// */ -// public Enumeration enumerateChildren() { -// return this.children.elements(); -// } - - - /** - * Returns whether the element is a leaf element. - * - * @return true if the element has no children. - */ - public boolean isLeaf() { - return children.isEmpty(); - } - - - /** - * Returns whether the element has children. - * - * @return true if the element has children. - */ - public boolean hasChildren() { - return (!children.isEmpty()); - } - - - /** - * Returns the number of children for the element. - * - * @return the count. - * @webref - * @see processing.xml.XMLElement#getChild(int) - * @see processing.xml.XMLElement#getChildren(String) - */ - public int getChildCount() { - return this.children.size(); - } - - - /** - * Returns a vector containing all the child elements. - * - * @return the vector. - */ -// public Vector getChildren() { -// return this.children; -// } - - - /** - * Put the names of all children into an array. Same as looping through - * each child and calling getName() on each XMLElement. - */ - public String[] listChildren() { - int childCount = getChildCount(); - String[] outgoing = new String[childCount]; - for (int i = 0; i < childCount; i++) { - outgoing[i] = getChild(i).getName(); - } - return outgoing; - } - - - /** - * Returns an array containing all the child elements. - */ - public XMLElement[] getChildren() { - int childCount = getChildCount(); - XMLElement[] kids = new XMLElement[childCount]; - children.copyInto(kids); - return kids; - } - - - /** - * Quick accessor for an element at a particular index. - * @author processing.org - * @param index the element - */ - public XMLElement getChild(int index) { - return (XMLElement) children.elementAt(index); - } - - - /** - * Returns the child XMLElement as specified by the index parameter. The value of the index parameter must be less than the total number of children to avoid going out of the array storing the child elements. - * When the path parameter is specified, then it will return all children that match that path. The path is a series of elements and sub-elements, separated by slashes. - * - * @return the element - * @author processing.org - * - * @webref - * @see processing.xml.XMLElement#getChildCount() - * @see processing.xml.XMLElement#getChildren(String) - * @brief Get a child by its name or path. - * @param path path to a particular element - */ - public XMLElement getChild(String path) { - if (path.indexOf('/') != -1) { - return getChildRecursive(PApplet.split(path, '/'), 0); - } - int childCount = getChildCount(); - for (int i = 0; i < childCount; i++) { - XMLElement kid = getChild(i); - String kidName = kid.getName(); - if (kidName != null && kidName.equals(path)) { - return kid; - } - } - return null; - } - - - /** - * Internal helper function for getChild(String). - * @param items result of splitting the query on slashes - * @param offset where in the items[] array we're currently looking - * @return matching element or null if no match - * @author processing.org - */ - protected XMLElement getChildRecursive(String[] items, int offset) { - // if it's a number, do an index instead - if (Character.isDigit(items[offset].charAt(0))) { - XMLElement kid = getChild(Integer.parseInt(items[offset])); - if (offset == items.length-1) { - return kid; - } else { - return kid.getChildRecursive(items, offset+1); - } - } - int childCount = getChildCount(); - for (int i = 0; i < childCount; i++) { - XMLElement kid = getChild(i); - String kidName = kid.getName(); - if (kidName != null && kidName.equals(items[offset])) { - if (offset == items.length-1) { - return kid; - } else { - return kid.getChildRecursive(items, offset+1); - } - } - } - return null; - } - - -// /** -// * Returns the child at a specific index. -// * -// * @param index the index of the child -// * -// * @return the non-null child -// * -// * @throws java.lang.ArrayIndexOutOfBoundsException -// * if the index is out of bounds. -// */ -// public XMLElement getChildAtIndex(int index) throws ArrayIndexOutOfBoundsException { -// return (XMLElement) this.children.elementAt(index); -// } - - - /** - * Returns all of the children as an XMLElement array. - * When the path parameter is specified, then it will return all children that match that path. - * The path is a series of elements and sub-elements, separated by slashes. - * - * @param path element name or path/to/element - * @return array of child elements that match - * @author processing.org - * - * @webref - * @brief Returns all of the children as an XMLElement array. - * @see processing.xml.XMLElement#getChildCount() - * @see processing.xml.XMLElement#getChild(int) - */ - public XMLElement[] getChildren(String path) { - if (path.indexOf('/') != -1) { - return getChildrenRecursive(PApplet.split(path, '/'), 0); - } - // if it's a number, do an index instead - // (returns a single element array, since this will be a single match - if (Character.isDigit(path.charAt(0))) { - return new XMLElement[] { getChild(Integer.parseInt(path)) }; - } - int childCount = getChildCount(); - XMLElement[] matches = new XMLElement[childCount]; - int matchCount = 0; - for (int i = 0; i < childCount; i++) { - XMLElement kid = getChild(i); - String kidName = kid.getName(); - if (kidName != null && kidName.equals(path)) { - matches[matchCount++] = kid; - } - } - return (XMLElement[]) PApplet.subset(matches, 0, matchCount); - } - - - protected XMLElement[] getChildrenRecursive(String[] items, int offset) { - if (offset == items.length-1) { - return getChildren(items[offset]); - } - XMLElement[] matches = getChildren(items[offset]); - XMLElement[] outgoing = new XMLElement[0]; - for (int i = 0; i < matches.length; i++) { - XMLElement[] kidMatches = matches[i].getChildrenRecursive(items, offset+1); - outgoing = (XMLElement[]) PApplet.concat(outgoing, kidMatches); - } - return outgoing; - } - - - /** - * Searches an attribute. - * - * @param fullName the non-null full name of the attribute. - * - * @return the attribute, or null if the attribute does not exist. - */ - private XMLAttribute findAttribute(String fullName) { - Enumeration en = this.attributes.elements(); - while (en.hasMoreElements()) { - XMLAttribute attr = (XMLAttribute) en.nextElement(); - if (attr.getName().equals(fullName)) { - return attr; - } - } - return null; - } - - -// /** -// * Searches an attribute. -// * -// * @param name the non-null short name of the attribute. -// * @param namespace the name space, which may be null. -// * -// * @return the attribute, or null if the attribute does not exist. -// */ -// private XMLAttribute findAttribute(String name, -// String namespace) { -// Enumeration en = this.attributes.elements(); -// while (en.hasMoreElements()) { -// XMLAttribute attr = (XMLAttribute) en.nextElement(); -// boolean found = attr.getName().equals(name); -// if (namespace == null) { -// found &= (attr.getNamespace() == null); -// } else { -// found &= namespace.equals(attr.getNamespace()); -// } -// -// if (found) { -// return attr; -// } -// } -// return null; -// } - - - /** - * Returns the number of attributes. - */ - public int getAttributeCount() { - return attributes.size(); - } - - - public String[] listAttributes() { - String[] outgoing = new String[attributes.size()]; - for (int i = 0; i < attributes.size(); i++) { - outgoing[i] = attributes.get(i).getName(); - } - return outgoing; - } - - - /** - * Returns the value of an attribute. - * @param name the non-null name of the attribute. - * @return the value, or null if the attribute does not exist. - */ -// public String getAttribute(String name) { -// return getAttribute(name, null); -// } - - - /** - * Returns the value of an attribute. - * - * @param name the non-null full name of the attribute. - * @param defaultValue the default value of the attribute. - * - * @return the value, or defaultValue if the attribute does not exist. - */ -// public String getAttribute(String name, String defaultValue) { -// XMLAttribute attr = this.findAttribute(name); -// if (attr == null) { -// return defaultValue; -// } else { -// return attr.getValue(); -// } -// } - - -// /** -// * Returns the value of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * @param defaultValue the default value of the attribute. -// * -// * @return the value, or defaultValue if the attribute does not exist. -// * @deprecated namespace code is more trouble than it's worth -// */ -// public String getAttribute(String name, -// String namespace, -// String defaultValue) { -// XMLAttribute attr = this.findAttribute(name, namespace); -// if (attr == null) { -// return defaultValue; -// } else { -// return attr.getValue(); -// } -// } - - - /** - * @deprecated use getString() or getAttribute() - */ - public String getStringAttribute(String name) { - return getString(name); - } - - - /** - * Returns a String attribute of the element. - * If the default parameter is used and the attribute doesn't exist, the default value is returned. - * When using the version of the method without the default parameter, if the attribute doesn't exist, the value 0 is returned. - * - * @webref - * @param name the name of the attribute - * @param default Value value returned if the attribute is not found - * - * @brief Returns a String attribute of the element. - * @deprecated use getString() or getAttribute() - */ - public String getStringAttribute(String name, String defaultValue) { - return getString(name, defaultValue); - } - - -// /** -// * @deprecated namespace code is more trouble than it's worth -// */ -// public String getStringAttribute(String name, -// String namespace, -// String defaultValue) { -// return getAttribute(name, namespace, defaultValue); -// } - - - public String getString(String name) { - return getString(name, null); - } - - - public String getString(String name, String defaultValue) { - XMLAttribute attr = this.findAttribute(name); - if (attr == null) { - return defaultValue; - } else { - return attr.getValue(); - } - } - - - /** - * Returns a boolean attribute of the element. - */ - public boolean getBoolean(String name) { - return getBoolean(name, false); - } - - - /** - * Returns a boolean attribute of the element. - * If the defaultValue parameter is used and the attribute doesn't exist, the defaultValue is returned. - * When using the version of the method without the defaultValue parameter, if the attribute doesn't exist, the value false is returned. - * - * @param name the name of the attribute - * @param defaultValue value returned if the attribute is not found - * - * @webref - * @brief Returns a boolean attribute of the element. - * @return the value, or defaultValue if the attribute does not exist. - */ - public boolean getBoolean(String name, boolean defaultValue) { - String value = getString(name); - if (value == null) { - return defaultValue; - } - return (value.equals("1") || value.toLowerCase().equals("true")); - } - - -// /** -// * Returns the value of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * @param defaultValue the default value of the attribute. -// * -// * @return the value, or defaultValue if the attribute does not exist. -// */ -// public boolean getBooleanAttribute(String name, -// String namespace, -// boolean defaultValue) { -// String value = this.getAttribute(name, namespace, -// Boolean.toString(defaultValue)); -// return value.equals("1") || value.toLowerCase().equals("true"); -// } - - - /** - * @deprecated use getInt() instead - */ - public int getIntAttribute(String name) { - return getInt(name, 0); - } - - - /** - * @deprecated use getInt() instead - */ - public int getIntAttribute(String name, int defaultValue) { - return getInt(name, defaultValue); - } - - - /** - * Returns an integer attribute of the element. - */ - public int getInt(String name) { - return getInt(name, 0); - } - - - /** - * Returns an integer attribute of the element. - * If the default parameter is used and the attribute doesn't exist, the default value is returned. - * When using the version of the method without the default parameter, if the attribute doesn't exist, the value 0 is returned. - * - * @param name the name of the attribute - * @param defaultValue value returned if the attribute is not found - * - * @webref - * @brief Returns an integer attribute of the element. - * @return the value, or defaultValue if the attribute does not exist. - */ - public int getInt(String name, int defaultValue) { - String value = getString(name); - return (value == null) ? defaultValue : PApplet.parseInt(value, defaultValue); - } - - -// /** -// * Returns the value of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * @param defaultValue the default value of the attribute. -// * -// * @return the value, or defaultValue if the attribute does not exist. -// * @deprecated namespace code is more trouble than it's worth -// */ -// public int getIntAttribute(String name, -// String namespace, -// int defaultValue) { -// String value = this.getAttribute(name, namespace, -// Integer.toString(defaultValue)); -// return Integer.parseInt(value); -// } - - - /** - * @deprecated use getFloat() instead - */ - public float getFloatAttribute(String name) { - return getFloat(name, 0); - } - - - /** - * @deprecated use getFloat() instead - */ - public float getFloatAttribute(String name, float defaultValue) { - return getFloat(name, 0); - } - - - public float getFloat(String name) { - return getFloat(name, 0); - } - - - /** - * Returns a float attribute of the element. - * If the default parameter is used and the attribute doesn't exist, the default value is returned. - * When using the version of the method without the default parameter, if the attribute doesn't exist, the value 0 is returned. - * - * @param name the name of the attribute - * @param defaultValue value returned if the attribute is not found - * - * @return the value, or defaultValue if the attribute does not exist. - * - * @webref - * @brief Returns a float attribute of the element. - */ - public float getFloat(String name, float defaultValue) { - String value = getString(name); - if (value == null) { - return defaultValue; - } - return PApplet.parseFloat(value, defaultValue); -// String value = this.getAttribute(name, Float.toString(defaultValue)); -// return Float.parseFloat(value); - } - - -// /** -// * Returns the value of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * @param defaultValue the default value of the attribute. -// * -// * @return the value, or defaultValue if the attribute does not exist. -// * @nowebref -// * @deprecated namespace code is more trouble than it's worth -// */ -// public float getFloatAttribute(String name, -// String namespace, -// float defaultValue) { -// String value = this.getAttribute(name, namespace, -// Float.toString(defaultValue)); -// return Float.parseFloat(value); -// } - - - public double getDouble(String name) { - return getDouble(name, 0); - } - - - /** - * Returns the value of an attribute. - * - * @param name the non-null full name of the attribute. - * @param defaultValue the default value of the attribute. - * - * @return the value, or defaultValue if the attribute does not exist. - */ - public double getDouble(String name, double defaultValue) { - String value = getString(name); - return (value == null) ? defaultValue : Double.parseDouble(value); - } - - -// /** -// * Returns the value of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * @param defaultValue the default value of the attribute. -// * -// * @return the value, or defaultValue if the attribute does not exist. -// */ -// public double getDoubleAttribute(String name, -// String namespace, -// double defaultValue) { -// String value = this.getAttribute(name, namespace, -// Double.toString(defaultValue)); -// return Double.parseDouble(value); -// } - - -// /** -// * Returns the type of an attribute. -// * -// * @param name the non-null full name of the attribute. -// * -// * @return the type, or null if the attribute does not exist. -// */ -// public String getAttributeType(String name) { -// XMLAttribute attr = this.findAttribute(name); -// if (attr == null) { -// return null; -// } else { -// return attr.getType(); -// } -// } - - -// /** -// * Returns the namespace of an attribute. -// * -// * @param name the non-null full name of the attribute. -// * -// * @return the namespace, or null if there is none associated. -// */ -// public String getAttributeNamespace(String name) { -// XMLAttribute attr = this.findAttribute(name); -// if (attr == null) { -// return null; -// } else { -// return attr.getNamespace(); -// } -// } - - -// /** -// * Returns the type of an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI, which may be null. -// * -// * @return the type, or null if the attribute does not exist. -// */ -// public String getAttributeType(String name, -// String namespace) { -// XMLAttribute attr = this.findAttribute(name, namespace); -// if (attr == null) { -// return null; -// } else { -// return attr.getType(); -// } -// } - - -// /** -// * @deprecated use set() -// */ -// public void setAttribute(String name, String value) { -// set(name, value); -// } - - - /** - * Sets an attribute. - * - * @param name the non-null full name of the attribute. - * @param value the non-null value of the attribute. - */ - public void setString(String name, String value) { - XMLAttribute attr = this.findAttribute(name); - if (attr == null) { - attr = new XMLAttribute(name, name, null, value, "CDATA"); - this.attributes.addElement(attr); - } else { - attr.setValue(value); - } - } - - - public void setBoolean(String name, boolean value) { - setString(name, String.valueOf(value)); - } - - - public void setInt(String name, int value) { - setString(name, String.valueOf(value)); - } - - - public void setFloat(String name, float value) { - setString(name, String.valueOf(value)); - } - - - public void setDouble(String name, double value) { - setString(name, String.valueOf(value)); - } - - -// /** -// * Sets an attribute. -// * -// * @param fullName the non-null full name of the attribute. -// * @param namespace the namespace URI of the attribute, which may be null. -// * @param value the non-null value of the attribute. -// */ -// public void setAttribute(String fullName, -// String namespace, -// String value) { -// int index = fullName.indexOf(':'); -// String vorname = fullName.substring(index + 1); -// XMLAttribute attr = this.findAttribute(vorname, namespace); -// if (attr == null) { -// attr = new XMLAttribute(fullName, vorname, namespace, value, "CDATA"); -// this.attributes.addElement(attr); -// } else { -// attr.setValue(value); -// } -// } - - - /** - * Removes an attribute. Formerly removeAttribute(). - * - * @param name the non-null name of the attribute. - */ - public void remove(String name) { - for (int i = 0; i < this.attributes.size(); i++) { - XMLAttribute attr = (XMLAttribute) this.attributes.elementAt(i); - if (attr.getName().equals(name)) { - this.attributes.removeElementAt(i); - return; - } - } - } - - -// /** -// * Removes an attribute. -// * -// * @param name the non-null name of the attribute. -// * @param namespace the namespace URI of the attribute, which may be null. -// */ -// public void removeAttribute(String name, -// String namespace) { -// for (int i = 0; i < this.attributes.size(); i++) { -// XMLAttribute attr = (XMLAttribute) this.attributes.elementAt(i); -// boolean found = attr.getName().equals(name); -// if (namespace == null) { -// found &= (attr.getNamespace() == null); -// } else { -// found &= attr.getNamespace().equals(namespace); -// } -// -// if (found) { -// this.attributes.removeElementAt(i); -// return; -// } -// } -// } - - -// /** -// * Returns an enumeration of all attribute names. -// * -// * @return the non-null enumeration. -// */ -// public Enumeration enumerateAttributeNames() { -// Vector result = new Vector(); -// Enumeration en = this.attributes.elements(); -// while (en.hasMoreElements()) { -// XMLAttribute attr = (XMLAttribute) en.nextElement(); -// result.addElement(attr.getFullName()); -// } -// return result.elements(); -// } - - - /** - * Returns whether an attribute exists. - * - * @return true if the attribute exists. - */ - public boolean hasAttribute(String name) { - return this.findAttribute(name) != null; - } - - -// /** -// * Returns whether an attribute exists. -// * -// * @return true if the attribute exists. -// */ -// public boolean hasAttribute(String name, -// String namespace) { -// return this.findAttribute(name, namespace) != null; -// } - - -// /** -// * Returns all attributes as a Properties object. -// * -// * @return the non-null set. -// */ -// public Properties getAttributes() { -// Properties result = new Properties(); -// Enumeration en = this.attributes.elements(); -// while (en.hasMoreElements()) { -// XMLAttribute attr = (XMLAttribute) en.nextElement(); -// result.put(attr.getFullName(), attr.getValue()); -// } -// return result; -// } - - -// /** -// * Returns all attributes in a specific namespace as a Properties object. -// * -// * @param namespace the namespace URI of the attributes, which may be null. -// * -// * @return the non-null set. -// */ -// public Properties getAttributesInNamespace(String namespace) { -// Properties result = new Properties(); -// Enumeration en = this.attributes.elements(); -// while (en.hasMoreElements()) { -// XMLAttribute attr = (XMLAttribute) en.nextElement(); -// if (namespace == null) { -// if (attr.getNamespace() == null) { -// result.put(attr.getName(), attr.getValue()); -// } -// } else { -// if (namespace.equals(attr.getNamespace())) { -// result.put(attr.getName(), attr.getValue()); -// } -// } -// } -// return result; -// } - - - /** - * Returns the system ID of the data where the element started. - * - * @return the system ID, or null if unknown. - * - * @see #getLineNr - */ - public String getSystemID() { - return this.systemID; - } - - - /** - * Returns the line number in the data where the element started. - * - * @return the line number, or NO_LINE if unknown. - * - * @see #NO_LINE - * @see #getSystemID - */ - public int getLine() { - return this.line; - } - - - /** - * Returns the content of an element. If there is no such content, null is returned. - * =advanced - * Return the #PCDATA content of the element. If the element has a - * combination of #PCDATA content and child elements, the #PCDATA - * sections can be retrieved as unnamed child objects. In this case, - * this method returns null. - * - * @webref - * @brief Returns the content of an element - * @return the content. - */ - public String getContent() { - return this.content; - } - - - /** - * Sets the #PCDATA content. It is an error to call this method with a - * non-null value if there are child objects. - * - * @param content the (possibly null) content. - */ - public void setContent(String content) { - this.content = content; - } - - - /** - * Returns true if the element equals another element. - * - * @param rawElement the element to compare to - */ - public boolean equals(Object object) { - if (!(object instanceof XMLElement)) { - return false; - } - XMLElement rawElement = (XMLElement) object; - - if (! this.name.equals(rawElement.getLocalName())) { - return false; - } - if (this.attributes.size() != rawElement.getAttributeCount()) { - return false; - } - Enumeration en = this.attributes.elements(); - while (en.hasMoreElements()) { - XMLAttribute attr = (XMLAttribute) en.nextElement(); - // if (! rawElement.hasAttribute(attr.getName(), attr.getNamespace())) { - if (!rawElement.hasAttribute(attr.getName())) { - return false; - } - // String value = rawElement.getAttribute(attr.getName(), - // attr.getNamespace(), - // null); - String value = rawElement.getString(attr.getName(), null); - if (! attr.getValue().equals(value)) { - return false; - } - // String type = - // rawElement.getAttributeType(attr.getName(), attr.getNamespace()); - // if (!attr.getType().equals(type)) { - // return false; - // } - } - if (this.children.size() != rawElement.getChildCount()) { - return false; - } - for (int i = 0; i < this.children.size(); i++) { - XMLElement child1 = this.getChild(i); - XMLElement child2 = rawElement.getChild(i); - - if (!child1.equals(child2)) { - return false; - } - } - return true; - } - -// /** -// * Returns true if the element equals another element. -// * -// * @param rawElement the element to compare to -// */ -// public boolean equals(Object rawElement) { -// if (!(rawElement instanceof XMLElement)) { -// return false; -// } -// try { -// return this.equalsXMLElement((XMLElement) rawElement); -// } catch (ClassCastException e) { -// return false; -// } -// } - - -// /** -// * Returns true if the element equals another element. -// * -// * @param rawElement the element to compare to -// */ -// public boolean equalsXMLElement(XMLElement rawElement) { -// if (! this.name.equals(rawElement.getLocalName())) { -// return false; -// } -// if (this.attributes.size() != rawElement.getAttributeCount()) { -// return false; -// } -// Enumeration en = this.attributes.elements(); -// while (en.hasMoreElements()) { -// XMLAttribute attr = (XMLAttribute) en.nextElement(); -//// if (! rawElement.hasAttribute(attr.getName(), attr.getNamespace())) { -// if (!rawElement.hasAttribute(attr.getFullName())) { -// return false; -// } -//// String value = rawElement.getAttribute(attr.getName(), -//// attr.getNamespace(), -//// null); -// String value = rawElement.getAttribute(attr.getFullName(), null); -// if (! attr.getValue().equals(value)) { -// return false; -// } -//// String type = -//// rawElement.getAttributeType(attr.getName(), attr.getNamespace()); -//// if (!attr.getType().equals(type)) { -//// return false; -//// } -// } -// if (this.children.size() != rawElement.getChildCount()) { -// return false; -// } -// for (int i = 0; i < this.children.size(); i++) { -// XMLElement child1 = this.getChildAtIndex(i); -// XMLElement child2 = rawElement.getChildAtIndex(i); -// -// if (! child1.equalsXMLElement(child2)) { -// return false; -// } -// } -// return true; -// } - - - public String toString() { - return toString(true); - } - - - public String toString(boolean pretty) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(baos); - XMLWriter writer = new XMLWriter(osw); - try { - writer.write(this, pretty); - } catch (IOException e) { - e.printStackTrace(); - } - return baos.toString(); - } - - - private PApplet findSketch() { - if (sketch != null) { - return sketch; - } - if (parent != null) { - return parent.findSketch(); - } - return null; - } - - - public boolean save(String filename) { - if (sketch == null) { - sketch = findSketch(); - } - if (sketch == null) { - System.err.println("save() can only be used on elements loaded by a sketch"); - throw new RuntimeException("no sketch found, use write(PrintWriter) instead."); - } - return write(sketch.createWriter(filename)); - } - - - public boolean write(PrintWriter writer) { - writer.println(XMLWriter.HEADER); - XMLWriter xmlw = new XMLWriter(writer); - try { - xmlw.write(this, true); - writer.flush(); - return true; - - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } -} diff --git a/core/src/processing/xml/XMLEntityResolver.java b/core/src/processing/xml/XMLEntityResolver.java deleted file mode 100644 index f12c4c0d4..000000000 --- a/core/src/processing/xml/XMLEntityResolver.java +++ /dev/null @@ -1,173 +0,0 @@ -/* XMLEntityResolver.java NanoXML/Java - * - * $Revision: 1.4 $ - * $Date: 2002/01/04 21:03:29 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.util.Hashtable; -import java.io.Reader; -import java.io.StringReader; - - -/** - * An XMLEntityResolver resolves entities. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ -public class XMLEntityResolver -{ - - /** - * The entities. - */ - private Hashtable entities; - - - /** - * Initializes the resolver. - */ - public XMLEntityResolver() - { - this.entities = new Hashtable(); - this.entities.put("amp", "&"); - this.entities.put("quot", """); - this.entities.put("apos", "'"); - this.entities.put("lt", "<"); - this.entities.put("gt", ">"); - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.entities.clear(); - this.entities = null; - super.finalize(); - } - - - /** - * Adds an internal entity. - * - * @param name the name of the entity. - * @param value the value of the entity. - */ - public void addInternalEntity(String name, - String value) - { - if (! this.entities.containsKey(name)) { - this.entities.put(name, value); - } - } - - - /** - * Adds an external entity. - * - * @param name the name of the entity. - * @param publicID the public ID of the entity, which may be null. - * @param systemID the system ID of the entity. - */ - public void addExternalEntity(String name, - String publicID, - String systemID) - { - if (! this.entities.containsKey(name)) { - this.entities.put(name, new String[] { publicID, systemID } ); - } - } - - - /** - * Returns a Java reader containing the value of an entity. - * - * @param xmlReader the current XML reader - * @param name the name of the entity. - * - * @return the reader, or null if the entity could not be resolved. - */ - public Reader getEntity(StdXMLReader xmlReader, - String name) - throws XMLParseException - { - Object obj = this.entities.get(name); - - if (obj == null) { - return null; - } else if (obj instanceof java.lang.String) { - return new StringReader((String)obj); - } else { - String[] id = (String[]) obj; - return this.openExternalEntity(xmlReader, id[0], id[1]); - } - } - - - /** - * Returns true if an entity is external. - * - * @param name the name of the entity. - */ - public boolean isExternalEntity(String name) - { - Object obj = this.entities.get(name); - return ! (obj instanceof java.lang.String); - } - - - /** - * Opens an external entity. - * - * @param xmlReader the current XML reader - * @param publicID the public ID, which may be null - * @param systemID the system ID - * - * @return the reader, or null if the reader could not be created/opened - */ - protected Reader openExternalEntity(StdXMLReader xmlReader, - String publicID, - String systemID) - throws XMLParseException - { - String parentSystemID = xmlReader.getSystemID(); - - try { - return xmlReader.openStream(publicID, systemID); - } catch (Exception e) { - throw new XMLParseException(parentSystemID, - xmlReader.getLineNr(), - "Could not open external entity " - + "at system ID: " + systemID); - } - } - -} diff --git a/core/src/processing/xml/XMLException.java b/core/src/processing/xml/XMLException.java deleted file mode 100644 index 953ae2204..000000000 --- a/core/src/processing/xml/XMLException.java +++ /dev/null @@ -1,287 +0,0 @@ -/* XMLException.java NanoXML/Java - * - * $Revision: 1.4 $ - * $Date: 2002/01/04 21:03:29 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - -import java.io.PrintStream; -import java.io.PrintWriter; - - -/** - * An XMLException is thrown when an exception occurred while processing the - * XML data. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ - */ -@SuppressWarnings("serial") -public class XMLException - extends Exception -{ - - /** - * The message of the exception. - */ - private String msg; - - - /** - * The system ID of the XML data where the exception occurred. - */ - private String systemID; - - - /** - * The line number in the XML data where the exception occurred. - */ - private int lineNr; - - - /** - * Encapsulated exception. - */ - private Exception encapsulatedException; - - - /** - * Creates a new exception. - * - * @param msg the message of the exception. - */ - public XMLException(String msg) - { - this(null, -1, null, msg, false); - } - - - /** - * Creates a new exception. - * - * @param e the encapsulated exception. - */ - public XMLException(Exception e) - { - this(null, -1, e, "Nested Exception", false); - } - - - /** - * Creates a new exception. - * - * @param systemID the system ID of the XML data where the exception - * occurred - * @param lineNr the line number in the XML data where the exception - * occurred. - * @param e the encapsulated exception. - */ - public XMLException(String systemID, - int lineNr, - Exception e) - { - this(systemID, lineNr, e, "Nested Exception", true); - } - - - /** - * Creates a new exception. - * - * @param systemID the system ID of the XML data where the exception - * occurred - * @param lineNr the line number in the XML data where the exception - * occurred. - * @param msg the message of the exception. - */ - public XMLException(String systemID, - int lineNr, - String msg) - { - this(systemID, lineNr, null, msg, true); - } - - - /** - * Creates a new exception. - * - * @param systemID the system ID from where the data came - * @param lineNr the line number in the XML data where the exception - * occurred. - * @param e the encapsulated exception. - * @param msg the message of the exception. - * @param reportParams true if the systemID, lineNr and e params need to be - * appended to the message - */ - public XMLException(String systemID, - int lineNr, - Exception e, - String msg, - boolean reportParams) - { - super(XMLException.buildMessage(systemID, lineNr, e, msg, - reportParams)); - this.systemID = systemID; - this.lineNr = lineNr; - this.encapsulatedException = e; - this.msg = XMLException.buildMessage(systemID, lineNr, e, msg, - reportParams); - } - - - /** - * Builds the exception message - * - * @param systemID the system ID from where the data came - * @param lineNr the line number in the XML data where the exception - * occurred. - * @param e the encapsulated exception. - * @param msg the message of the exception. - * @param reportParams true if the systemID, lineNr and e params need to be - * appended to the message - */ - private static String buildMessage(String systemID, - int lineNr, - Exception e, - String msg, - boolean reportParams) - { - String str = msg; - - if (reportParams) { - if (systemID != null) { - str += ", SystemID='" + systemID + "'"; - } - - if (lineNr >= 0) { - str += ", Line=" + lineNr; - } - - if (e != null) { - str += ", Exception: " + e; - } - } - - return str; - } - - - /** - * Cleans up the object when it's destroyed. - */ - protected void finalize() - throws Throwable - { - this.systemID = null; - this.encapsulatedException = null; - super.finalize(); - } - - - /** - * Returns the system ID of the XML data where the exception occurred. - * If there is no system ID known, null is returned. - */ - public String getSystemID() - { - return this.systemID; - } - - - /** - * Returns the line number in the XML data where the exception occurred. - * If there is no line number known, -1 is returned. - */ - public int getLineNr() - { - return this.lineNr; - } - - - /** - * Returns the encapsulated exception, or null if no exception is - * encapsulated. - */ - public Exception getException() - { - return this.encapsulatedException; - } - - - /** - * Dumps the exception stack to a print writer. - * - * @param writer the print writer - */ - public void printStackTrace(PrintWriter writer) - { - super.printStackTrace(writer); - - if (this.encapsulatedException != null) { - writer.println("*** Nested Exception:"); - this.encapsulatedException.printStackTrace(writer); - } - } - - - /** - * Dumps the exception stack to an output stream. - * - * @param stream the output stream - */ - public void printStackTrace(PrintStream stream) - { - super.printStackTrace(stream); - - if (this.encapsulatedException != null) { - stream.println("*** Nested Exception:"); - this.encapsulatedException.printStackTrace(stream); - } - } - - - /** - * Dumps the exception stack to System.err. - */ - public void printStackTrace() - { - super.printStackTrace(); - - if (this.encapsulatedException != null) { - System.err.println("*** Nested Exception:"); - this.encapsulatedException.printStackTrace(); - } - } - - - /** - * Returns a string representation of the exception. - */ - public String toString() - { - return this.msg; - } - -} diff --git a/core/src/processing/xml/XMLParseException.java b/core/src/processing/xml/XMLParseException.java deleted file mode 100644 index 6775cc76d..000000000 --- a/core/src/processing/xml/XMLParseException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* XMLParseException.java NanoXML/Java - * - * $Revision: 1.3 $ - * $Date: 2002/01/04 21:03:29 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -/** - * An XMLParseException is thrown when the XML passed to the XML parser is not - * well-formed. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ - */ -@SuppressWarnings("serial") -public class XMLParseException - extends XMLException -{ - - /** - * Creates a new exception. - * - * @param msg the message of the exception. - */ - public XMLParseException(String msg) - { - super(msg); - } - - - /** - * Creates a new exception. - * - * @param systemID the system ID from where the data came - * @param lineNr the line number in the XML data where the exception - * occurred. - * @param msg the message of the exception. - */ - public XMLParseException(String systemID, - int lineNr, - String msg) - { - super(systemID, lineNr, null, msg, true); - } - -} diff --git a/core/src/processing/xml/XMLUtil.java b/core/src/processing/xml/XMLUtil.java deleted file mode 100644 index 6adad79be..000000000 --- a/core/src/processing/xml/XMLUtil.java +++ /dev/null @@ -1,758 +0,0 @@ -/* XMLUtil.java NanoXML/Java - * - * $Revision: 1.5 $ - * $Date: 2002/02/03 21:19:38 $ - * $Name: RELEASE_2_2_1 $ - * - * This file is part of NanoXML 2 for Java. - * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from the - * use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - */ - -package processing.xml; - - -import java.io.IOException; -import java.io.Reader; - - -/** - * Utility methods for NanoXML. - * - * @author Marc De Scheemaecker - * @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $ - */ -class XMLUtil -{ - - /** - * Skips the remainder of a comment. - * It is assumed that <!- is already read. - * - * @param reader the reader - * - * @throws java.io.IOException - * if an error occurred reading the data - */ - static void skipComment(StdXMLReader reader) - throws IOException, - XMLParseException - { - if (reader.read() != '-') { - XMLUtil.errorExpectedInput(reader.getSystemID(), - reader.getLineNr(), - "