libnanoxml2-java-2.2.3.dfsg/0000755000175000017500000000000007616770720016076 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/ThirdParty/0000755000175000017500000000000007616770707020175 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/ThirdParty/SAX/0000755000175000017500000000000011045140126020601 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/0000755000175000017500000000000007616770707020714 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/0000755000175000017500000000000011045140126023034 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/0000755000175000017500000000000011045140126024011 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/introduction.tex0000644000175000017500000001073407616770720027303 0ustar sveinungsveinung\chapter{Introduction} This chapter gives a short introduction to XML and NanoXML. \section{About \ltext{XML}} The extensible markup language, \href{http://www.w3c.org/TR/REC-xml}{\ltext{XML}}, is a way to mark up text in a structured document. \ltext{XML} is a simplification of the complex \ltext{SGML} standard. \ltext{SGML}, the Standard Generalized Markup Language, is an international (\ltext{ISO}) standard for marking up text and graphics. The best known application of \ltext{SGML} is \ltext{HTML}. Although \ltext{SGML} data is very easy to write, it's very difficult to write a generic \ltext{SGML} parser. When designing \ltext{XML} however, the authors removed much of the flexibility of \ltext{SGML} making it much easier to parse \ltext{XML} documents correctly. \ltext{XML} data is structured as a tree of \term{entities}. An entity can be a string of character data or an element which can contain other entities. Elements can optionally have a set of attributes. Attributes are key/value pairs which set some properties of an element. The following example shows some XML data: \begin{example} $<$book$>$ ~~$<$chapter id="my chapter"$>$ ~~~~$<$title$>$The title$<$/title$>$ ~~~~Some text. ~~$<$/chapter$>$ $<$/book$>$ \end{example} At the root of the tree, you can find the element ``book''. This element contains one child element: ``chapter''. The chapter element has one attribute which maps the key ``id'' to ``my chapter''. The chapter element has two child entities: the element ``title'' and the character data ``Some text.''. Finally, the title element has one child, the string ``The title''. \section{About \ltext{NanoXML}} In April 2000, \ltext{NanoXML} was first released as a spin-off project of \ltext{AUIT}, the Abstract User Interface Toolkit. The intent of NanoXML was to be a small parser which was easy to use. \ltext{SAX} and \ltext{DOM} are much too complex for what I needed and the mainstream parsers were either much too big or had a very restrictive license. \ltext{NanoXML 1} has all the features I needed: it is very small (about 6K), is reasonably fast for small \ltext{XML} documents, is very easy to use and is free (\ltext{zlib/libpng} license). As I never intended to use \ltext{NanoXML} to parse \ltext{DocBook} documents, there was no support for mixed data or \ltext{DTD} parsing. \ltext{NanoXML} was released as a \ltext{SourceForge} project and, because of the very good response from its users, it matured to a small and stable parser. The final version, release \ltext{1.6.8} was released in May 2001. Because of its small size, people started to use \ltext{NanoXML} for embedded systems (\ltext{KVM}, \ltext{J2ME}) and kindly submitted patches to make \ltext{NanoXML} work in such restricted environment. \section{\ltext{NanoXML} 2} In July 2001, \ltext{NanoXML} 2 has been released. Unlike \ltext{NanoXML 1}, speed and \ltext{XML} compliancy were considered to be very important when the new parser was designed. \ltext{NanoXML 2} is also very modular: you can easily replace the different components in the parser to customize it to your needs. The modularity of \ltext{NanoXML 2} also benefits extensions like \acronym{e.g.} \ltext{SAX} support which can now directly access the parser. In \ltext{NanoXML 1}, the \ltext{SAX} adapter had to iterate the data structure built by the base product. Although many features were added to \ltext{NanoXML}, the second release was still very small. The full parser with builder fits in a \ltext{JAR} file of about 32K. This is still very tiny, especially when you compare this with the ``standard'' parsers of more than four times its size. As there is still need for a tiny parser like \ltext{NanoXML 1}, there is a special branch of \ltext{NanoXML 2}: \ltext{NanoXML/Lite}. This parser is source compatible with \ltext{NanoXML 1} but features a new parsing algorithm which makes it more than twice as fast as the older version. It is however more restrictive on the \ltext{XML} data it parses: the older version allowed some not-wellformed data to be parsed. There are three branches of NanoXML 2: \begin{itemize} \item[$\bullet$] \term{NanoXML/Lite} is the successor of \ltext{NanoXML 1}. It features an almost compatible parser which is extremely small. \item[$\bullet$] \term{NanoXML/Java} is the standard parser. \item[$\bullet$] \term{NanoXML/SAX} is the \ltext{SAX} adapter for \ltext{NanoXML/Java}. \end{itemize} The latest version of \ltext{NanoXML} is \ltext{NanoXML 2.2.1}, which has been released in February 2002. libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/NanoXML-Lite.tex0000644000175000017500000000101607616770720026722 0ustar sveinungsveinung\documentclass[a4paper]{book} \usepackage{hyperref} \title{NanoXML/Lite 2.2} \author{Marc De Scheemaecker $<$cyberelf@mac.com$>$} \pdfinfo { /Title (NanoXML/Lite 2.2) /Creator (LaTeX) /Producer (pdfTeX 0.14a) /Author (Marc De Scheemaecker) /CreationDate (D:20010204000000) /ModDate (D:20030201171156) /Subject (NanoXML/Lite) /Keywords (NanoXML,XML) } \include{defs} \begin{document} \titlepage \maketitle \tableofcontents \include{introduction} \include{retrieving_data} \end{document} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/retrieving_data.tex0000644000175000017500000001124507616770720027727 0ustar sveinungsveinung\chapter{Retrieving Data From An \ltext{XML} Datasource} This chapter shows how to retrieve \ltext{XML} data from a standard data source. Such source can be a file, an \ltext{HTTP} object or a text string. \section{A Very Simple Example} This section describes a very simple \ltext{XML} application. It parses \ltext{XML} data from a stream and dumps it to the standard output. While its use is very limited, it shows how to set up a parser and parse an \ltext{XML} document. \begin{example} \xkeyword{import} nanoxml.*;\xcallout{1} \xkeyword{import} java.io.*; \xkeyword{public class} DumpXML \{ ~~\xkeyword{public static void} main(String[] args) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~XMLElement xml = new XMLElement();\xcallout{2} ~~~~FileReader reader = new FileReader("test.xml"); ~~~~xml.parseFromReader(reader);\xcallout{3} ~~~~System.out.println(xml);\xcallout{4} ~~\} \} \end{example} \begin{callout} \coitem The \ltext{NanoXML} classes are located in the package \packagename{nanoxml}. \coitem This command creates an empty \ltext{XML} element. \coitem The method \methodname{parseFromReader} parses the data in the file \filename{test.xml} and fills the empty element. \coitem The \ltext{XML} element is dumped to the standard output. \end{callout} \section{Analyzing The Data} You can easily traverse the logical tree generated by the parser. By calling one of the \methodname{parse*} methods, you fill an empty \ltext{XML} element with the parsed contents. Every such object can have a name, attributes, \ltext{\#PCDATA} content and child objects. The following XML data: \begin{example} $<$FOO attr1="fred" attr2="barney"$>$ ~~$<$BAR a1="flintstone" a2="rubble"$>$ ~~~~Some data. ~~$<$/BAR$>$ ~~$<$QUUX/$>$ $<$/FOO$>$ \end{example} is parsed to the following objects: \begin{itemize} \item[] Element FOO: \begin{itemize} \item[] Attributes = \{ "attr1"="fred", "attr2"="barney" \} \item[] Children = \{ BAR, QUUX \} \item[] PCData = null \end{itemize} \item[] Element BAR: \begin{itemize} \item[] Attributes = \{ "a1"="flintstone", "a2"="rubble" \} \item[] Children = \{\} \item[] PCData = "Some data." \end{itemize} \item[] Element QUUX: \begin{itemize} \item[] Attributes = \{\} \item[] Children = \{\} \item[] PCData = null \end{itemize} \end{itemize} You can retrieve the name of an element using the method \methodname{getName}, thus: \begin{example} FOO.getName() $\to$ "FOO" \end{example} You can enumerate the attribute names using the method \methodname{enumerateAttributeNames}: \begin{example} Enumeration enum = FOO.enumerateAttributeNames(); \xkeyword{while} (enum.hasMoreElements()) \{ ~~System.out.print(enum.nextElement()); ~~System.out.print(' '); \} $\to$ attr1 attr2 \end{example} You can retrieve the value of an attribute using \methodname{getAttribute}: \begin{example} FOO.getAttribute("attr1") $\to$ "fred" \end{example} The child elements can be enumerated using the method \methodname{enumerateChildren}: \begin{example} Enumeration enum = FOO.enumerateChildren(); \xkeyword{while} (enum.hasMoreElements()) \{ ~~XMLElement child = (XMLElement) enum.nextElement(); ~~System.out.print(child.getName() + ' '); \} $\to$ BAR QUUX \end{example} If the element contains parsed character data (\ltext{\#PCDATA}) as its only child. You can retrieve that data using \methodname{getContent}: \begin{example} BAR.getContent() $\to$ "Some data." \end{example} Note that in \ltext{NanoXML/Lite}, a child cannot have children and \ltext{\#PCDATA} content at the same time. \section{Generating \ltext{XML}} You can very easily create a tree of \ltext{XML} elements or modify an existing one. To create a new tree, just create an \classname{XMLElement} object: \begin{example} XMLElement elt = new XMLElement("ElementName"); \end{example} You can add an attribute to the element by calling \methodname{setAttribute}: \begin{example} elt.setAttribute("key", "value"); \end{example} You can add a child element to an element by calling \methodname{addChild}: \begin{example} XMLElement child = new XMLElement("Child"); elt.addChild(child); \end{example} If an element has no children, you can add \ltext{\#PCDATA} content to it using \methodname{setContent}: \begin{example} child.setContent("Some content"); \end{example} Note that in \ltext{NanoXML/Lite}, a child cannot have children and \ltext{\#PCDATA} content at the same time. When you have created or edited the \ltext{XML} element tree, you can write it out to an output stream or writer using the method \methodname{toString}: \begin{example} java.io.PrintWriter output = ...; XMLElement xmltree = ...; output.println(xmltree); \end{example} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/defs.tex0000644000175000017500000000134307616770720025477 0ustar sveinungsveinung\newcommand\ltext[1]{\mbox{#1}} \newcommand\term[1]{\emph{\mbox{#1}}} \newcommand\acronym[1]{\ltext{#1}} \newcommand\classname[1]{\mbox{\tt #1}} \newcommand\propertykey[1]{\mbox{\tt #1}} \newcommand\propertyvalue[1]{\mbox{\tt #1}} \newcommand\methodname[1]{\mbox{\tt #1}} \newcommand\filename[1]{\mbox{\sl #1}} \newcommand\packagename[1]{\mbox{\tt\sl #1}} \newcommand\xcallout[1]{\hfill\textcircled{#1}} \newcommand\xkeyword[1]{{\bf #1}} \newcounter{calloutindex} \newenvironment{callout}% {\begin{itemize}\setcounter{calloutindex}{1}}% {\end{itemize}} \newcommand\coitem{\item[\textcircled{\arabic{calloutindex}}% \addtocounter{calloutindex}{1}]} \newenvironment{example}% {\par\vskip 6pt\tt\small\obeylines\obeyspaces}% {\vskip 6pt} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Lite/LaTeX/Makefile0000644000175000017500000000100607616770720025470 0ustar sveinungsveinungMAIN=NanoXML-Lite COMPONENTS=NanoXML-Lite.tex defs.tex introduction.tex retrieving_data.tex PDFLATEX=/usr/local/teTeX/bin/powerpc-apple-darwin-current/pdflatex all: $(MAIN).pdf clean: rm -f $(MAIN).pdf $(COMPONENTS:.tex=.aux) $(MAIN).log $(MAIN).toc $(MAIN).pdf: $(COMPONENTS) sed "s/ModDate (D:[0-9]*)/ModDate (D:`date +'%Y%m%d%H%M%S'`)/" \ < $(MAIN).tex >$(MAIN).tmp mv $(MAIN).tmp $(MAIN).tex $(PDFLATEX) $(MAIN).tex $(PDFLATEX) $(MAIN).tex >/dev/null 2>&1 $(PDFLATEX) $(MAIN).tex >/dev/null 2>&1 libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/0000755000175000017500000000000011045140126023020 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/0000755000175000017500000000000011045140126023775 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/introduction.tex0000644000175000017500000001231707616770720027266 0ustar sveinungsveinung\chapter{Introduction} This chapter gives a short introduction to \XML{} and \NanoXML{}. \section{About \XML{}} The extensible markup language, \href{http://www.w3c.org/TR/REC-xml}{\XML{}}, is a way to mark up text in a structured document. \XML is a simplification of the complex \ltext{SGML} standard. \ltext{SGML}, the Standard Generalized Markup Language, is an international (\ltext{ISO}) standard for marking up text and graphics. The best known application of \ltext{SGML} is \ltext{HTML}. Although \ltext{SGML} data is very easy to write, it's very difficult to write a generic \ltext{SGML} parser. When designing \XML{} however, the authors removed much of the flexibility of \ltext{SGML} making it much easier to parse \XML{} documents correctly. \XML{} data is structured as a tree of \term{entities}. An entity can be a string of character data or an element which can contain other entities. Elements can optionally have a set of attributes. Attributes are key/value pairs which set some properties of an element. The following example shows some \XML{} data: \begin{example} $<$book$>$ ~~$<$chapter id="my chapter"$>$ ~~~~$<$title$>$The title$<$/title$>$ ~~~~Some text. ~~$<$/chapter$>$ $<$/book$>$ \end{example} At the root of the tree, you can find the element ``book''. This element contains one child element: ``chapter''. The chapter element has one attribute which maps the key ``id'' to ``my chapter''. The chapter element has two child entities: the element ``title'' and the character data ``Some text.''. Finally, the title element has one child, the string ``The title''. \section{About \NanoXML{}} In April 2000, \NanoXML{} was first released as a spin-off project of \ltext{AUIT}, the Abstract User Interface Toolkit. The intent of NanoXML was to be a small parser which was easy to use. \ltext{SAX} and \ltext{DOM} are much too complex for what I needed and the mainstream parsers were either much too big or had a very restrictive license. \ltext{NanoXML 1} has all the features I needed: it is very small (about 6K), is reasonably fast for small \XML{} documents, is very easy to use and is free (\ltext{zlib/libpng} license). As I never intended to use \NanoXML{} to parse \ltext{DocBook} documents, there was no support for mixed data or \ltext{DTD} parsing. \NanoXML{} was released as a \ltext{SourceForge} project and, because of the very good response from its users, it matured to a small and stable parser. The final version, release \ltext{1.6.8} was released in May 2001. Because of its small size, people started to use \NanoXML{} for embedded systems (\ltext{KVM}, \ltext{J2ME}) and kindly submitted patches to make \NanoXML{} work in such restricted environment. \section{\NanoXML{} 2} In July 2001, \ltext{NanoXML 2} has been released. Unlike \ltext{NanoXML 1}, speed and \XML{} compliancy were considered to be very important when the new parser was designed. \ltext{NanoXML 2} is also very modular: you can easily replace the different components in the parser to customize it to your needs. The modularity of \ltext{NanoXML 2} also benefits extensions like \acronym{e.g.} \ltext{SAX} support which can now directly access the parser. In \ltext{NanoXML 1}, the \ltext{SAX} adapter had to iterate the data structure built by the base product. Although many features were added to \NanoXML{}, the second release was still very small. The full parser with builder fits in a \ltext{JAR} file of about 32K. This is still very tiny, especially when you compare this with the ``standard'' parsers of more than four times its size. As there is still need for a tiny parser like \ltext{NanoXML 1}, there is a special branch of \ltext{NanoXML 2}: \ltext{NanoXML/Lite}. This parser is source compatible with \ltext{NanoXML 1} but features a new parsing algorithm which makes it more than twice as fast as the older version. It is however more restrictive on the \XML{} data it parses: the older version allowed some not-wellformed data to be parsed. There are three branches of \ltext{NanoXML 2}: \begin{itemize} \item[$\bullet$] \term{NanoXML/Lite} is the successor of \ltext{NanoXML 1}. It features an almost compatible parser which is extremely small. \item[$\bullet$] \term{NanoXML/Java} is the standard parser. \item[$\bullet$] \term{NanoXML/SAX} is the \ltext{SAX} adapter for \ltext{NanoXML/Java}. \end{itemize} The latest version of \NanoXML{} is \ltext{NanoXML 2.2.1}, which has been released in April 2002. \section{\NanoXML{} Extension to the \XML{} System ID} Because it's convenient to put data files into jar files, we need some way to specify that we want some resource which can be found in the class path. There is no support for such resources in the \XML{} 1.0 specification. NanoXML allows you to specify such resources using the \emph{reference part} of a \ltext{URL}. This means that if the \ltext{DTD} of the \XML{} data is put in the resource \filename{/data/foo.dtd}, you can specify such path using the following document type declaration: \begin{example} $<$!DOCTYPE foo SYSTEM 'file:\#/data/foo.dtd'$>$ \end{example} It's even possible to specify a resource found in a particular jar, like in the following example: \begin{example} $<$!DOCTYPE foo SYSTEM 'http://myserver.com/dtds.jar\#/foo.dtd'$>$ \end{example} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/streaming_data.tex0000644000175000017500000001055507616770720027531 0ustar sveinungsveinung\chapter{Retrieving Data From An \XML{} Stream} If you're retrieving data from a stream, but you don't want to wait to process the data until it's completely read, you can use streaming. \section{The \XML{} Builder} The \XML{} data tree is created using an \XML{} builder. By default, the builder creates a tree of \classname{IXMLElement}. While the parser parses the data, it notifies the builder of any elements it encounters. Using this information, the builder generate the object tree. When the parser is done processing the data, it retrieves the object tree from the builder using \methodname{getResult}. The following example shows a simple builder that prints the notifications on the standard output. \begin{example} \xkeyword{import} java.io.*; \xkeyword{import} net.n3.nanoxml.*; ~ \xkeyword{public class} MyBuilder ~~~~\xkeyword{implements} IXMLBuilder ~~\{ ~~\xkeyword{public void} startBuilding(String systemID,\xcallout{1} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~\{ ~~~~System.out.println("Document started"); ~~\} ~ ~~\xkeyword{public void} newProcessingInstruction(String target, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Reader reader) ~~~~\xkeyword{throws} IOException ~~\{ ~~~~System.out.println("New PI with target " + target); ~~\} ~ ~~\xkeyword{public void} startElement(String name,\xcallout{3} ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~\{ ~~~~System.out.println("Element started: " + name); ~~\} ~ ~~\xkeyword{public void} endElement(String name,\xcallout{4} ~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID) ~~\{ ~~~~System.out.println("Element ended: " + name); ~~\} ~ ~~\xkeyword{public void} addAttribute(String key,\xcallout{5} ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String value, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String type) ~~\{ ~~~~System.out.println(" " + key + ": " + type + " = " + value); ~~\} ~ ~~\xkeyword{public void} elementAttributesProcessed(String name,\xcallout{6} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID) ~~\{ ~~~~// nothing to do ~~\} ~ ~~\xkeyword{public void} addPCData(Reader reader,\xcallout{7} ~~~~~~~~~~~~~~~~~~~~~~~~String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~~~\xkeyword{throws} IOException ~~\{ ~~~~System.out.println("\#PCDATA"); ~~\} ~ ~~\xkeyword{public} Object getResult()\xcallout{8} ~~\{ ~~~~\xkeyword{return null}; ~~\} \} \end{example} \begin{callout} \coitem The \XML{} parser started parsing the document. The \variable{lineNr} parameter contains the line number where the document starts. \coitem The \XML{} parser encountered a processing instruction (PI) which is not handled by the parser itself. The target contains the target of the PI. The contents of the PI can be read from reader. \coitem A new element has been started at line \variable{lineNr}. The name of the element is stored in \variable{name}. \coitem The current element has ended. For convenience, the name of that element is put in the parameter \variable{name}. \coitem An attribute is added to the current element. \coitem This method is called when all the attributes of the current element have been processed. \coitem A \ltext{\#PCDATA} section has been encountered. The contents of the section can be read from reader. \coitem This method is called when the parsing has finished. If the builder has a result, it has to return it to the parser in this method. \end{callout} \section{Registering an XML Builder} You can register the builder to the parser using the method \methodname{setBuilder}. The following example shows how to create a parser which uses the builder we created in the previous section: \begin{example} \xkeyword{import} net.n3.nanoxml.*; \xkeyword{import} java.io.*; ~ \xkeyword{public class} DumpXML \{ ~~\xkeyword{public static void} main(String args[]) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); ~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml"); ~~~~parser.setReader(reader); ~~~~parser.setBuilder(new MyBuilder()); ~~~~parser.parse(); ~~\} \} \end{example} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/retrieving_data.tex0000644000175000017500000002446107616770720027717 0ustar sveinungsveinung\chapter{Retrieving Data From An \XML{} Datasource} This chapter shows how to retrieve \XML{} data from a standard data source. Such source can be a file, an \ltext{HTTP} object or a text string. The method described in this chapter is the simplest way to retrieve \XML{} data. More advanced ways are described in the next chapters. \section{A Very Simple Example} This section describes a very simple \XML{} application. It parses \XML{} data from a stream and dumps it ``pretty-printed'' to the standard output. While its use is very limited, it shows how to set up a parser and parse an \XML{} document. \begin{example} \xkeyword{import} net.n3.nanoxml.*;\xcallout{1} \xkeyword{import} java.io.*; \xkeyword{public class} DumpXML \{ ~~\xkeyword{public static void} main(String[] args) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser();\xcallout{2} ~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml");\xcallout{3} ~~~~parser.setReader(reader); ~~~~IXMLElement xml = (IXMLElement) parser.parse();\xcallout{4} ~~~~XMLWriter writer = new XMLWriter(System.out);\xcallout{5} ~~~~writer.write(xml); ~~\} \} \end{example} \begin{callout} \coitem The \NanoXML{} classes are located in the package \packagename{net.n3.nanoxml}. \coitem This command creates an \XML{} parser. The actual class of the parser is dependent on the value of the system property \propertykey{net.n3.nanoxml.XMLParser}, which is by default \propertyvalue{net.n3.nanoxml.StdXMLParser}. \coitem The command creates a ``standard'' reader which reads its data from the file called \filename{test.xml}. Usually you can use \classname{StdXMLReader} to feed the \XML{} data to the parser. The default reader is able to set up HTTP connections when retrieving \ltext{DTDs} or entities from different machines. If necessary, you can supply your own reader to \acronym{e.g.} provide support for \ltext{PUBLIC} identifiers. \coitem The \XML{} parser now parses the data read from \filename{test.xml} and creates a tree of parsed \XML{} elements. The structure of those elements will be described in the next section. \coitem An \classname{XMLWriter} can be used to dump a ``pretty-printed'' view of the parsed \XML data on an output stream. In this case, we dump the read data to the standard output \ltext{(System.out)}. \end{callout} \section{Analyzing The Data} You can easily traverse the logical tree generated by the parser. If you need to create your own object tree, you can create your custom % TODO: make "chapter 3" a xref builder, which is described in chapter 3. The default \XML{} builder, \classname{StdXMLBuilder} generates a tree of \classname{IXMLElement} objects. Every such object has a name and can have attributes, \ltext{\#PCDATA} content and child objects. The following XML data: \begin{example} $<$FOO attr1="fred" attr2="barney"$>$ ~~~~$<$BAR a1="flintstone" a2="rubble"$>$ ~~~~~~~~Some data. ~~~~$<$/BAR$>$ ~~~~$<$QUUX/$>$ $<$/FOO$>$ \end{example} is parsed to the following objects: \begin{itemize} \item[] Element FOO: \begin{itemize} \item[] Attributes = \{ "attr1"="fred", "attr2"="barney" \} \item[] Children = \{ BAR, QUUX \} \item[] PCData = null \end{itemize} \item[] Element BAR: \begin{itemize} \item[] Attributes = \{ "a1"="flintstone", "a2"="rubble" \} \item[] Children = \{\} \item[] PCData = "Some data." \end{itemize} \item[] Element QUUX: \begin{itemize} \item[] Attributes = \{\} \item[] Children = \{\} \item[] PCData = null \end{itemize} \end{itemize} You can retrieve the name of an element using \methodname{getFullName}, thus: \begin{example} FOO.getFullName() $\to$ "FOO" \end{example} You can enumerate the attribute keys using \methodname{enumerateAttributeNames}: \begin{example} Enumeration enum = FOO.enumerateAttributeNames(); \xkeyword{while} (enum.hasMoreElements()) \{ ~~System.out.print(enum.nextElement()); ~~System.out.print(' '); \} $\to$ attr1 attr2 \end{example} You can retrieve the value of an attribute using \methodname{getAttribute}: \begin{example} FOO.getAttribute ("attr1", null) $\to$ "fred" \end{example} The child elements can be enumerated using \methodname{enumerateChildren}: \begin{example} Enumeration enum = FOO.enumerateChildren(); \xkeyword{while} (enum.hasMoreElements()) \{ ~~System.out.print(enum.nextElement() + ' '); \} $\to$ BAR QUUX \end{example} If the element contains parsed character data \ltext{(\#PCDATA)} as its only child. You can retrieve that data using \methodname{getContent}: \begin{example} BAR.getContent() $\to$ "Some data." \end{example} If an element contains both \ltext{\#PCDATA} and \XML elements as its children, the character data segments will be put in untitled \XML elements (whose name is \ltext{null}). \classname{IXMLElement} contains many convenience methods for retrieving data and traversing the \XML tree. \section{Generating \XML} You can very easily create a tree of \XML elements or modify an existing one. To create a new tree, just create an \classname{IXMLElement} object: \begin{example} IXMLElement elt = \xkeyword{new} XMLElement("ElementName"); \end{example} You can add an attribute to the element by calling \methodname{setAttribute}. \begin{example} elt.setAttribute("key", "value"); \end{example} You can add a child element to an element by calling \methodname{addChild}: \begin{example} IXMLElement child = elt.createElement("Child"); elt.addChild(child); \end{example} Note that the child element is created calling \methodname{createElement}. This insures that the child instance is compatible with its new parent. If an element has no children, you can add \ltext{\#PCDATA} content to it using \methodname{setContent}: \begin{example} child.setContent("Some content"); \end{example} If the element does have children, you can add \ltext{\#PCDATA} content to it by adding an untitled element, which you create by calling \methodname{createPCDataElement}: \begin{example} IXMLElement pcdata = elt.createPCDataElement(); pcdata.setContent("Blah blah"); elt.addChild(pcdata); \end{example} When you have created or edited the XML element tree, you can write it out to an output stream or writer using an \classname{XMLWriter}: \begin{example} java.io.Writer output = \ldots; IXMLElement xmltree = \ldots; XMLWriter xmlwriter = new XMLWriter(output); writer.write(xmltree); \end{example} \section{Namespaces} As of version 2.1, \ltext{NanoXML} has support for namespaces. Namespaces allow you to attach a \ltext{URI} to the name of an element name or an attribute. This \ltext{URI} allows you to make a distinction between similary named entities coming from different sources. More information about namespaces can be found in the XML Namespaces recommendation, which can be found at \href{http://www.w3c.org/TR/REC-xml-names/}% {http://www.w3c.org/TR/REC-xml-names/}. Please note that a \ltext{DTD} has no support for namespaces. It is important to understand that an \XML document can have only one \ltext{DTD}. Though the namespace \ltext{URI} is often presented as a \ltext{URL}, that \ltext{URL} is not a system id for a \ltext{DTD}. The only function of a namespace \ltext{URI} is to provide a globally unique name. As an example, letŐs have the following \XML data: \begin{example} $<$doc:book xmlns:doc="http://nanoxml.n3.net/book"$>$ ~~$<$chapter xmlns="http://nanoxml.n3.net/chapter" ~~~~~~~~~~~title="Introduction" ~~~~~~~~~~~doc:id="chapter1"/$>$ $<$/doc:book$>$ \end{example} The top-level element uses the namespace \ltext{``http://nanoxml.n3.net/book''}. The prefix is used as an alias for the namespace, which is defined in the attribute \ltext{xmlns:doc}. This prefix is defined for the \ltext{doc:book} element and its child elements. The chapter element uses the namespace \ltext{``http://nanoxml.n3.net/chapter''}. Because the namespace \ltext{URI} has been defined as the value of the xmlns attribute, the namespace is the default namespace for the chapter element. Default namespaces are inherited by the child elements, but only for their names. Attributes never have a default namespace. The chapter element has an attribute \ltext{doc:id}, which is defined in the same namespace as \ltext{doc:book} because of the doc prefix. \ltext{NanoXML 2.1} offers some variants on the standard retrieval methods to allow the application to access the namespace information. In the following examples, we assume the variable book to contain the \ltext{doc:book} element and the variable chapter to contain the chapter element. To get the full name, which includes the namespace prefix, of the element, use \methodname{getFullName}: \begin{example} book.getFullName() $\to$ "doc:book" chapter.getFullName() $\to$ "chapter" \end{example} To get the short name, which excludes the namespace prefix, of the element, use \methodname{getName}: \begin{example} book.getName() $\to$ "book" chapter.getName $\to$ "chapter" \end{example} For elements that have no associated namespace, \methodname{getName} and \methodname{getFullName} are equivalent. To get the namespace \ltext{URI} associated with the name of the element, use \methodname{getNamespace}: \begin{example} book.getNamespace() $\to$ "http://nanoxml.n3.net/book" chapter.getNamespace() $\to$ "http://nanoxml.n3.net/chapter" \end{example} If no namespace is associated with the name of the element, this method returns \variable{null}. You can get an attribute of an element using either its full name (which includes its prefix) or its short name together with its namespace \ltext{URI}, so the following two instructions are equivalent: \begin{example} chapter.getAttribute("doc:id", null) chapter.getAttribute("id", "http://nanoxml.n3.net/book", null) \end{example} Note that the title attribute of chapter has no namespace, even though the chapter element name has a default namespace. You can create a new element which uses a namespace this way: \begin{example} book = \xkeyword{new} XMLElement("doc:book", "http://nanoxml.n3.net/book"); chapter = book.createElement("chapter", ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"http://nanoxml.n3.net/chapter"); \end{example} You can add an attribute which uses a namespace this way: \begin{example} chapter.setAttribute("doc:id", ~~~~~~~~~~~~~~~~~~~~~"http://nanoxml.n3.net/book", ~~~~~~~~~~~~~~~~~~~~~chapterId); \end{example} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/NanoXML-Java.tex0000644000175000017500000000117307616770720026676 0ustar sveinungsveinung\documentclass[a4paper]{book} \usepackage[pdftex]{graphicx} \usepackage{hyperref} \DeclareGraphicsExtensions{.pdf} \title{NanoXML/Java 2.2} \author{Marc De Scheemaecker $<$cyberelf@mac.com$>$} \pdfinfo { /Title (NanoXML/Java 2.2) /Creator (LaTeX) /Producer (pdfTeX 0.14a) /Author (Marc De Scheemaecker) /CreationDate (D:20020205000000) /ModDate (D:20030201171151) /Subject (NanoXML/Java) /Keywords (NanoXML,XML) } \include{defs} \begin{document} \titlepage \maketitle \tableofcontents \include{introduction} \include{retrieving_data} \include{streaming_data} \include{advanced} \end{document} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/defs.tex0000644000175000017500000000151407616770720025463 0ustar sveinungsveinung\newcommand\ltext[1]{\mbox{#1}} \newcommand\XML{\ltext{XML}} \newcommand\NanoXML{\ltext{NanoXML}} \newcommand\term[1]{\emph{\mbox{#1}}} \newcommand\acronym[1]{\ltext{#1}} \newcommand\classname[1]{\mbox{\tt #1}} \newcommand\variable[1]{\mbox{\tt #1}} \newcommand\propertykey[1]{\mbox{\tt #1}} \newcommand\propertyvalue[1]{\mbox{\tt #1}} \newcommand\methodname[1]{\mbox{\tt #1}} \newcommand\filename[1]{\mbox{\sl #1}} \newcommand\packagename[1]{\mbox{\tt\sl #1}} \newcommand\xcallout[1]{\hfill\textcircled{#1}} \newcommand\xkeyword[1]{{\bf #1}} \newcounter{calloutindex} \newenvironment{callout}% {\begin{itemize}\setcounter{calloutindex}{1}}% {\end{itemize}} \newcommand\coitem{\item[\textcircled{\arabic{calloutindex}}% \addtocounter{calloutindex}{1}]} \newenvironment{example}% {\par\vskip 6pt\tt\small\obeylines\obeyspaces}% {\vskip 6pt} libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/structure.graffle0000744000175000017500000004330707616770720027417 0ustar sveinungsveinung CanvasColor w 1.000000e+00 ColumnAlign 0 ColumnSpacing 3.600000e+01 GraphDocumentVersion 2 GraphicsList Class LineGraphic Head ID 3 ID 21 Points {271.396, 149.4} {271.405, 198.45} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 2 Class LineGraphic Head ID 2 Info 2 ID 20 Points {270.442, 76.475} {271.404, 113.4} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 1 Class LineGraphic Head ID 8 ID 19 Points {271.396, 305.325} {272.238, 340.2} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 7 Class LineGraphic Head ID 7 ID 18 Points {271.395, 234.45} {271.404, 269.325} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 3 Class LineGraphic Head ID 5 ID 17 Points {246.967, 149.4} {178.856, 212.625} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 2 Info 5 Class LineGraphic Head ID 3 ID 16 Points {160.875, 159.371} {226.8, 216.227} Style stroke HeadArrow FilledArrow LineType 1 TailArrow FilledArrow Tail ID 4 Class LineGraphic Head ID 5 ID 15 Points {115.428, 177.75} {115.397, 212.625} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 4 Class LineGraphic Head ID 6 ID 14 Points {316.8, 131.198} {368.55, 166.139} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 2 Class LineGraphic Head ID 4 ID 13 Points {226.8, 131.202} {160.875, 159.371} Style stroke HeadArrow FilledArrow LineType 1 TailArrow 0 Tail ID 2 Class LineGraphic Head ID 10 ID 12 Points {272.231, 368.55} {315, 396.9} Style stroke HeadArrow 0 LineType 1 TailArrow 0 Tail ID 8 Info 1 Class LineGraphic Head ID 9 Info 2 ID 11 Points {272.231, 368.55} {223.33, 396.9} Style stroke HeadArrow 0 LineType 1 TailArrow 0 Tail ID 12 Bounds {{283.5, 396.9}, {63, 42.525}} Class ShapedGraphic ID 10 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape RoundedRectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 BAR\ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f1\b0 \cf0 id='2'} Bounds {{192.15, 396.9}, {63, 42.525}} Class ShapedGraphic ID 9 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape RoundedRectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 BAR\ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f1\b0 \cf0 id='1'} Bounds {{240.975, 340.2}, {63, 28.35}} Class ShapedGraphic ID 8 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape RoundedRectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 FOO} Bounds {{226.8, 269.325}, {90, 36}} Class ShapedGraphic ID 7 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Builder} Bounds {{368.55, 148.275}, {113.4, 36}} Class ShapedGraphic ID 6 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Entity Resolver} Bounds {{52, 212.625}, {127.575, 42.525}} Class ShapedGraphic ID 5 Magnets {1, 1} {1, -1} {-1, -1} {-1, 1} {0, 1} {0, -1} {1, 0} {-1, 0} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Entity Resolver\ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f1\b0 \cf0 (parameter entities)} Bounds {{70.875, 141.75}, {90, 36}} Class ShapedGraphic ID 4 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Validator} Bounds {{226.8, 198.45}, {90, 36}} Class ShapedGraphic ID 3 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Parser} Bounds {{226.8, 113.4}, {90, 36}} Class ShapedGraphic ID 2 Magnets {0, 1} {0, -1} {1, 0} {-1, 0} {-0.325556, 0.613889} Shape Rectangle Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc \f0\b\fs24 \cf0 Reader} Bounds {{220.7, 16.475}, {98, 60}} Class ShapedGraphic FitText YES ID 1 Shape Rectangle Style fill Draws NO shadow Draws NO stroke Draws NO Text Text {\rtf1\mac\ansicpg10000\cocoartf100 {\fonttbl\f0\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural \f0\fs24 \cf0 <FOO>\ <BAR id='1'/>\ <BAR id='2'/>\ </FOO>} GridInfo GridSpacing 1.417500e+01 MajorGridSpacing 10 HPages 1 ImageCounter 2 IsPalette NO Layers Lock NO Name Layer 1 Print YES View YES LayoutInfo AutoAdjust YES MagneticFieldCenter {0, 0} MagnetsEnabled YES MagnetsVisible YES PageBreakColor w 6.666667e-01 PageBreaks YES PageSetup BAt0eXBlZHN0cmVhbYED6IQBQISEhAtOU1ByaW50SW5mbwGEhAhOU09iamVjdACFkoSE hBNOU011dGFibGVEaWN0aW9uYXJ5AISEDE5TRGljdGlvbmFyeQCUhAFpFZKEhIQITlNT dHJpbmcBlIQBKw9OU1BhZ2VzUGVyU2hlZXSGkoSEhAhOU051bWJlcgCEhAdOU1ZhbHVl AJSEASqEhAFznQGGkoSZmRBOU0pvYkRpc3Bvc2l0aW9uhpKEmZkPTlNQcmludFNwb29s Sm9ihpKEmZkOTlNCb3R0b21NYXJnaW6GkoSbnISEAWaeJIaShJmZC05TUGFwZXJOYW1l hpKEmZkCQTSGkoSZmQ9OU1ByaW50QWxsUGFnZXOGkoSbnJ2dAIaShJmZDU5TSm9iRmVh dHVyZXOGkoSWlwCGkoSZmRVOU0hvcml6b25hbFBhZ2luYXRpb26GkoSbnJ2dAIaShJmZ CE5TQ29waWVzhpKEm5yEhAFTnwGGkoSZmQ9OU1NjYWxpbmdGYWN0b3KGkoSbnISEAWSg AYaShJmZC05TRmlyc3RQYWdlhpKEm5ytnwGGkoSZmRROU1ZlcnRpY2FsUGFnaW5hdGlv boaShJucnZ0AhpKEmZkSTlNSZXZlcnNlUGFnZU9yZGVyhpKmkoSZmQ1OU1JpZ2h0TWFy Z2luhpKEm5yiniSGkoSZmRZOU0hvcml6b250YWxseUNlbnRlcmVkhpKEm5ydnQGGkoSZ mQxOU0xlZnRNYXJnaW6GkoSbnKKeJIaShJmZDU5TT3JpZW50YXRpb26GkoSbnJ2dAIaS hJmZGU5TUHJpbnRSZXZlcnNlT3JpZW50YXRpb26GkqaShJmZCk5TTGFzdFBhZ2WGkoSb nISXl4J/////hpKEmZkLTlNUb3BNYXJnaW6GkoSbnKKeJIaShJmZFE5TVmVydGljYWxs eUNlbnRlcmVkhpK5koSZmQtOU1BhcGVyU2l6ZYaShJychIQGez89ZmZ9oYECU4EDSoaG hg== RowAlign 0 RowSpacing 3.600000e+01 VPages 1 WindowInfo Frame {{21, 0}, {538, 746}} VisibleRegion {{0, 0}, {523, 669}} Zoom 1 libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/Makefile0000644000175000017500000000104607616770720025460 0ustar sveinungsveinungMAIN=NanoXML-Java COMPONENTS=NanoXML-Java.tex defs.tex introduction.tex \ retrieving_data.tex streaming_data.tex PDFLATEX=/usr/local/teTeX/bin/powerpc-apple-darwin-current/pdflatex all: $(MAIN).pdf clean: rm -f $(MAIN).pdf $(COMPONENTS:.tex=.aux) $(MAIN).log $(MAIN).toc $(MAIN).pdf: $(COMPONENTS) sed "s/ModDate (D:[0-9]*)/ModDate (D:`date +'%Y%m%d%H%M%S'`)/" \ < $(MAIN).tex >$(MAIN).tmp mv $(MAIN).tmp $(MAIN).tex $(PDFLATEX) $(MAIN).tex $(PDFLATEX) $(MAIN).tex >/dev/null 2>&1 $(PDFLATEX) $(MAIN).tex >/dev/null 2>&1 libnanoxml2-java-2.2.3.dfsg/Documentation/NanoXML-Java/LaTeX/advanced.tex0000644000175000017500000004006607616770720026314 0ustar sveinungsveinung\chapter{Advanced Topics} This chapter explains how you can customize the \NanoXML{} parser setup. Unlike \ltext{NanoXML 1}, \ltext{NanoXML/Java 2} is designed as a framework: it is composed of many different components which you can plug together. It's possible to change the reader, the builder, the validator and even the parser. \ltext{NanoXML/Java} comes with one set of components. Except for \ltext{NanoXML/Lite}, every branch offers its own set of components customized for a certain purpose. \ltext{NanoXML/SAX} offers components for using \NanoXML{} as a parser for the \ltext{SAX} framework. The following figure gives a short representation of the major components. \begin{figure}[ht] \begin{center} \includegraphics[width=8cm]{structure.pdf} \end{center} \caption{Design of NanoXML/Java} \end{figure} The \emph{reader} retrieves data from a Java input stream and provides character data to the other components. The \emph{parser} converts the character data it retrieves from the reader to \XML{} events which it sends to the builder. The \emph{validator} parses a \ltext{DTD} and validates the \XML{} data. The current validator does only the minimum necessary for a non-validating parser. The \emph{entity resolvers} converts entity references (\&\ldots;) and parameter entity references (\%\ldots;) to character data. The resolver uses the reader to access external entities. The \emph{builder} interpretes \XML{} events coming from the parser and builds a tree of \XML{} elements. The standard builder creates a tree of \classname{IXMLElement}. You can provide your own builder to create a custom tree or if you are interested in the \XML{} events themselves, \acronym{e.g.} to use \XML{} streaming. \section{The \NanoXML{} Reader} The reader retrieves data from some source and feeds it to the other components. The reader is basically a stack of push-back readers. Every time a new data stream becomes active, the current reader is pushed on a stack. When the current reader has no more data left, the parent reader is popped from the stack. If you want to implement public IDs using \acronym{e.g.} a catalog file similar to SGML, you could implement a reader by overriding the method \methodname{openStream} of \classname{StdXMLReader}: \begin{example} \xkeyword{public class} MyReader ~~\xkeyword{extends} StdXMLReader \{ ~~\xkeyword{private} Properties publicIDs; ~ ~~\xkeyword{public} MyReader(Properties publicIDs) ~~\{ ~~~~\xkeyword{this}.publicIDs = publicIDs; ~~\} ~ ~~\xkeyword{public} Reader openStream(String publicID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String systemID) ~~~~\xkeyword{throws} MalformedURLException, ~~~~~~~~~~~FileNotFoundException, ~~~~~~~~~~~IOException ~~\{ ~~~~\xkeyword{if} (publicID != \xkeyword{null}) \{ ~~~~~~systemID = publicIDs.getProperty(publicID, systemID); ~~~~\} ~~~~\xkeyword{return super}.openStream(publicID, systemID); ~~\} \} \end{example} In this example, you have to provide a properties object which maps public IDs to system IDs. \section{The \NanoXML{} Parser} The parser analyzes the character stream it retrieves from the reader and sends \XML{} events to the builder. It uses a validator to validate the data and an entity resolver to resolve general entities. You rarely need to create a custom parser. If you need to, you have to implement \classname{IXMLParser}. \section{The \NanoXML{} Validator} The validator parses the \ltext{DTD} and checks the \XML{} data. \ltext{NanoXML 2.0} uses a \classname{NonValidator} implementation that only performs the minimum necessary for a non-validating parser. As a \ltext{DTD} is very vague, you can implement your own validator to perform a more fine-grained check of the \XML{} data. The easiest way to create your own validator is to create a subclass of \classname{ValidatorPlugin}. The following example shows how to implement a validator. It checks that every attribute named ``id'' starts with three capital letters. \begin{example} \xkeyword{public class} MyValidator ~~\xkeyword{extends} ValidatorPlugin \{ ~~\xkeyword{public void} attributeAdded(String key, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String value, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~\{ ~~~~\xkeyword{boolean} valid = true; ~~~~\xkeyword{if} (key.equals("id")) \{ ~~~~~~\xkeyword{if} (value.length() < 3) \{ ~~~~~~~~valid = \xkeyword{false}; ~~~~~~\} \xkeyword{else} \{ ~~~~~~~~\xkeyword{for} (\xkeyword{int} i = 0; i < 3; i++) \{ ~~~~~~~~~~\xkeyword{char} ch = value.charAt(i); ~~~~~~~~~~\xkeyword{if} ((ch < 'A') || (ch > 'Z')) \{ ~~~~~~~~~~~~valid = \xkeyword{false}; ~~~~~~~~~~\} ~~~~~~~~\} ~~~~~~\} ~~~~\} ~~~~\xkeyword{if} (valid) \{ ~~~~~~\xkeyword{super}.attributeAdded(key, value, systemID, lineNr); ~~~~\} \xkeyword{else} \{ ~~~~~~\xkeyword{this}.attributeWithInvalidValue(systemID, lineNr, \xkeyword{null}, key, value); ~~~~\} ~~\} \} \end{example} To register the validator to a parser, use the following code: \begin{example} IXMLParser parser \ldots \ldots IXMLValidator val1 = parser.getValidator(); MyValidator val2 = \xkeyword{new} MyValidator(); val2.setDelegate(val1); parser.setValidator(val2); \end{example} \section{The \NanoXML{} Entity Resolvers} The entity resolver converts entity references to \XML{} data. If you want \acronym{e.g.} to retrieve entity values from a database, you have to create your own resolver. Entity resolvers have to implement \classname{IXMLEntityResolver}. Usually, you only have to make a subclass of \classname{XMLEntityResolver} and implement the method \methodname{getEntity} or \methodname{openExternalEntity}. Entities can be used in the \XML{} data and in the \ltext{DTD}. As these entities are independent of each other, there are two entity resolvers. \subsection{Standard Entities} The resolver for standard entities has to be registered to the parser by calling \methodname{setResolver}. The following example registers a resolver that forces the entity ``\&foo;'' to be resolved to ``bar'': \begin{example} \xkeyword{import} net.n3.nanoxml.*; \xkeyword{import} java.io.*; ~ \xkeyword{class} MyResolver ~~\xkeyword{extends} XMLEntityResolver \{ ~~\xkeyword{public} Reader getEntity(IXMLReader xmlReader, ~~~~~~~~~~~~~~~~~~~~~~~~~~String name) ~~~~\xkeyword{throws} XMLParseException ~~\{ ~~~~\xkeyword{if} (name.equals("foo")) \{ ~~~~~~\xkeyword{return new} StringReader("bar"); ~~~~\} \xkeyword{else} \{ ~~~~~~\xkeyword{return super}.getEntity(xmlReader, name); ~~~~\} ~~\} \} ~ \xkeyword{public class} Demo \{ ~~\xkeyword{public static void} main(String[] args) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); ~~~~parser.setResolver(new MyResolver()); ~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml"); ~~~~parser.setReader(reader); ~~~~IXMLElement xml = (IXMLElement) parser.parse(); ~~~~XMLWriter writer = new XMLWriter(System.out); ~~~~writer.write(xml); ~~\} \} \end{example} \subsection{Parameter Entities} The resolver for parameter entities has to be registered to the validator by calling \methodname{setParameterEntityResolver}. The following example show a custom version of the \classname{Demo} class that registers \methodname{MyResolver} as a parameter entity resolver. \begin{example} \xkeyword{public class} Demo \{ ~~\xkeyword{public static void} main(String[] args) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); ~~~~IXMLValidator validator = parser.getValidator(); ~~~~validator.setParameterEntityResolver(new MyResolver()); ~~~~IXMLReader reader = StdXMLReader.fileReader("test.xml"); ~~~~parser.setReader(reader); ~~~~IXMLElement xml = (IXMLElement) parser.parse(); ~~~~XMLWriter writer = new XMLWriter(System.out); ~~~~writer.write(xml); ~~\} \} \end{example} \section{The \NanoXML{} Builder} The builder interpretes \XML{} events coming from the parser and builds a tree of \ltext{Java} objects. When the parsing is done, the builder hands over its result to the parser. As explained in chapter 3, the builder can also be used to read \XML{} data while it's being streamed. This feature is useful if you don't want to wait until all the data has been read before processing the information. As an example, we have the following XML structure (document.dtd): \begin{example} $<$!ELEMENT Chapter (Paragraph*)$>$ $<$!ATTLIST Chapter ~~~~~~~~title~CDATA~\#REQUIRED ~~~~~~~~id~~~~CDATA~\#REQUIRED$>$ $<$!ELEMENT Paragraph (\#PCDATA)$>$ $<$!ATTLIST Paragraph ~~~~~~~~align~(left|center|right)~"left"$>$ \end{example} The elements are put in the \ltext{Java} classes \classname{Chapter} and \classname{Paragraph} which, for convenience, extend the following base class: \begin{example} \xkeyword{public class} DocumentElement \{ ~~\xkeyword{protected} Properties attrs; ~~\xkeyword{protected} Vector children; ~ ~~\xkeyword{public} DocumentElement() ~~\{ ~~~~\xkeyword{this}.attrs = \xkeyword{new} Properties(); ~~~~\xkeyword{this}.children = \xkeyword{new} Vector(); ~~\} ~ ~~\xkeyword{public void} setAttribute(String attrName, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String value) ~~\{ ~~~~\xkeyword{this}.attrs.put(attrName, value); ~~\} ~ ~~\xkeyword{public void} addChild(DocumentElement elt) ~~\{ ~~~~\xkeyword{this}.children.addElement(elt); ~~\} \} \end{example} This base class simply makes it easy for our builder to set attributes and to add children to an element. The \classname{Chapter} and \classname{Paragraph} classes extend this base class to give more practical access to their attributes and children: \begin{example} \xkeyword{public class} Chapter ~~\xkeyword{extends} DocumentElement \{ ~~\xkeyword{public} String getTitle() ~~\{ ~~~~\xkeyword{return this}.attrs.getProperty("title"); ~~\} ~ ~~\xkeyword{public} String getID() ~~\{ ~~~~\xkeyword{return this}.attrs.getProperty("id"); ~~\} ~ ~~\xkeyword{public} Enumeration getParagraphs() ~~\{ ~~~~\xkeyword{return this}.children.elements(); ~~\} \} ~ \xkeyword{public class} Paragraph ~~\xkeyword{extends} DocumentElement \{ ~~\xkeyword{public static final int} LEFT = 0; ~~\xkeyword{public static final int} CENTER = 1; ~~\xkeyword{public static final int} RIGHT = 2; ~ ~~\xkeyword{private static} Hashtable alignments; ~ ~~\xkeyword{static} ~~\{ ~~~~alignments = \xkeyword{new} Hashtable(); ~~~~alignments.put("left", \xkeyword{new} Integer(LEFT)); ~~~~alignments.put("center", \xkeyword{new} Integer(CENTER)); ~~~~alignments.put("right", \xkeyword{new} Integer(RIGHT)); ~~\} ~ ~~\xkeyword{public} String getContent() ~~\{ ~~~~\xkeyword{return this}.attrs.getProperty("\#PCDATA"); ~~\} ~ ~~\xkeyword{public int} getAlignment() ~~\{ ~~~~String str = \xkeyword{this}.attrs.getProperty("align"); ~~~~Integer align = alignments.get(str); ~~~~\xkeyword{return} align.intValue(); ~~\} \} \end{example} The builder creates the data structure based on the \XML{} events it receives from the parser. Because both \classname{Chapter} and \classname{Paragraph} extend \classname{DocumentElement}, the builder is fairly simple. \begin{example} \xkeyword{import} net.n3.nanoxml.*; \xkeyword{import} java.util.*; \xkeyword{import} java.io.*; ~ \xkeyword{public class} DocumentBuilder ~~\xkeyword{implements} IXMLBuilder \{ ~~\xkeyword{private static} Hashtable classes; ~~\xkeyword{private} Stack elements; ~~\xkeyword{private} DocumentElement topElement; ~ ~~\xkeyword{static} ~~\{ ~~~~classes = \xkeyword{new} Hashtable(); ~~~~classes.put("Chapter", Chapter.\xkeyword{class}); ~~~~classes.put("Paragraph", Paragraph.\xkeyword{class}); ~~\} ~ ~~\xkeyword{public void} startBuilding(String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~\{ ~~~~\xkeyword{this}.elements = \xkeyword{new} Stack(); ~~~~\xkeyword{this}.topElement = \xkeyword{null}; ~~\} ~ ~~\xkeyword{public void} newProcessingInstruction(String target, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Reader reader) ~~\{ ~~~~// nothing to do ~~\} ~ ~~\xkeyword{public void} startElement(String name, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~\{ ~~~~DocumentElement elt = \xkeyword{null}; ~~~~\xkeyword{try} \{ ~~~~~~Class cls = (Class) classes.get(name); ~~~~~~elt = (DocumentElement) cls.newInstance(); ~~~~\} \xkeyword{catch} (Exception e) \{ ~~~~~~// ignore the exception ~~~~\} ~~~~\xkeyword{this}.elements.push(elt); ~~~~\xkeyword{if} (\xkeyword{this}.topElement == \xkeyword{null}) \{ ~~~~~~\xkeyword{this}.topElement = elt; ~~~~\} ~~\} ~ ~~\xkeyword{public void} endElement(String name, ~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID) ~~\{ ~~~~DocumentElement child = (DocumentElement) \xkeyword{this}.elements.pop(); ~~~~\xkeyword{if} (! \xkeyword{this}.elements.isEmpty()) \{ ~~~~~~DocumentElement parent = (DocumentElement) \xkeyword{this}.elements.peek(); ~~~~~~parent.addChild(child); ~~~~\} ~~\} ~ ~~\xkeyword{public void} addAttribute(String key, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String value, ~~~~~~~~~~~~~~~~~~~~~~~~~~~String type) ~~\{ ~~~~DocumentElement child = (DocumentElement) \xkeyword{this}.elements.peek(); ~~~~child.setAttribute(key, value); ~~\} ~ ~~\xkeyword{public void} elementAttributesProcessed(String name, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsPrefix, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~String nsSystemID) ~~\{ ~~~~// nothing to do ~~\} ~ ~~\xkeyword{public void} addPCData(Reader reader, ~~~~~~~~~~~~~~~~~~~~~~~~String systemID, ~~~~~~~~~~~~~~~~~~~~~~~~\xkeyword{int} lineNr) ~~~~\xkeyword{throws} IOException ~~\{ ~~~~StringBuffer str = \xkeyword{new} StringBuffer(1024); ~~~~\xkeyword{char}[] buf = \xkeyword{new char}[bufSize]; ~~~~\xkeyword{for} (;;) \{ ~~~~~~\xkeyword{int} size = reader.read(buf); ~~~~~~\xkeyword{if} (size < 0) \{ ~~~~~~~~\xkeyword{break}; ~~~~~~\} ~~~~~~str.append(buf, 0, size); ~~~~\} ~~~~\xkeyword{this}.addAttribute("\#PCDATA", \xkeyword{null}, \xkeyword{null}, str.toString(), "CDATA"); ~~\} ~ ~~\xkeyword{public} Object getResult() ~~\{ ~~~~\xkeyword{return} topElement; ~~\} \} \end{example} Note that, for simplicity, error and exception handling is not present in this example. The builder holds a stack of the current elements it builds. Character data is read from a reader. The method \methodname{addPCData} reads this data in blocks of 1K. Finally, this application sets up the \NanoXML{} parser and converts an \XML{} document to \ltext{HTML} which it dumps on the standard output: \begin{example} \xkeyword{import} java.util.*; \xkeyword{import} net.n3.nanoxml.*; ~ \xkeyword{public class} XML2HTML \{ ~~\xkeyword{public static void} main(String[] params) ~~~~\xkeyword{throws} Exception ~~\{ ~~~~IXMLBuilder builder = \xkeyword{new} DocumentBuilder(); ~~~~IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); ~~~~parser.setBuilder(builder); ~~~~IXMLReader reader = StdXMLReader.fileReader(param[0]); ~~~~parser.setReader(reader); ~~~~Chapter chapter = (Chapter) parser.parse(); ~~~~System.out.println("$<$!DOCTYPE \ldots{} $>$"); ~~~~System.out.print("$<$HTML$><$HEAD$><$TITLE$>$"); ~~~~System.out.print(chapter.getTitle()); ~~~~System.out.println(""); ~~~~System.out.print("$<$H1$>$"); ~~~~System.out.print(chapter.getTitle()); ~~~~System.out.println("$<$/H1$>$"); ~~~~Enumeration enum = chapter.getParagraphs(); ~~~~\xkeyword{while} (enum.hasMoreElements()) \{ ~~~~~~Paragraph para = (Paragraph) enum.nextElement(); ~~~~~~System.out.print("$<$P$>$"); ~~~~~~System.out.print(para.getContent()); ~~~~~~System.out.println("$<$/P$>$"); ~~~~\} ~~~~System.out.println("$<$/BODY$><$/HTML$>$"); ~~\} \} \end{example} If we run the example on the following \XML{} file: \begin{example} $<$!DOCTYPE Chapter SYSTEM "document.dtd"$>$ ~ $<$Chapter id="ch01" title="The Title"$>$ ~~~~$<$Paragraph$>$First paragraph...$<$/Paragraph$>$ ~~~~$<$Paragraph$>$Second paragraph...$<$/Paragraph$>$ $<$/Chapter$>$ \end{example} The output will be: \begin{example} $<$!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' ~~'http://www.w3.org/TR/html4/strict.dtd'> $<$HTML$><$HEAD$><$TITLE$>$The Title$<$/TITLE$><$/HEAD$><$BODY$>$ $<$H1$>$The Title$<$/H1$>$ $<$P$>$First paragraph...$<$/P$>$ $<$P$>$Second paragraph...$<$/P$>$ $<$/BODY$>$ \end{example} libnanoxml2-java-2.2.3.dfsg/Test/0000755000175000017500000000000007616770707017022 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Test/Java/0000755000175000017500000000000007616770717017704 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Test/Java/internal_dtd.xml0000644000175000017500000000065007616770717023076 0ustar sveinungsveinung ]> &value;&tab;&lf; &cr; libnanoxml2-java-2.2.3.dfsg/Test/Java/test.dtd0000644000175000017500000000033107616770717021355 0ustar sveinungsveinung libnanoxml2-java-2.2.3.dfsg/Test/Java/simple.xml0000644000175000017500000000051007616770717021713 0ustar sveinungsveinung blah blah '"]]> ac < <&>"'!:‰ libnanoxml2-java-2.2.3.dfsg/Test/Java/namespaces.xml0000644000175000017500000000072007616770717022544 0ustar sveinungsveinung ]> libnanoxml2-java-2.2.3.dfsg/Test/Java/external_dtd.xml.out0000644000175000017500000000007107616770717023707 0ustar sveinungsveinungINCLUDE libnanoxml2-java-2.2.3.dfsg/Test/Java/DumpXML.java0000644000175000017500000000326207616770717022040 0ustar sveinungsveinung/* DumpXML.java NanoXML/Java * * $Revision: 1.2 $ * $Date: 2002/01/03 20:25:27 $ * $Name: $ * * 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. */ import net.n3.nanoxml.*; public class DumpXML { public static void main(String args[]) throws Exception { if (args.length == 0) { System.err.println("Usage: java DumpXML file.xml"); Runtime.getRuntime().exit(1); } IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLReader reader = StdXMLReader.fileReader(args[0]); parser.setReader(reader); XMLElement xml = (XMLElement) parser.parse(); (new XMLWriter(System.out)).write(xml, false); } } libnanoxml2-java-2.2.3.dfsg/Test/Java/external_dtd.xml0000644000175000017500000000007407616770717023104 0ustar sveinungsveinung &value; libnanoxml2-java-2.2.3.dfsg/Test/Java/simple.xml.out0000644000175000017500000000034307616770717022525 0ustar sveinungsveinungblahblah<&>'"abc < <&>"'!:‰ libnanoxml2-java-2.2.3.dfsg/Test/Java/internal_dtd.xml.out0000644000175000017500000000011107616770717023674 0ustar sveinungsveinungINCLUDE libnanoxml2-java-2.2.3.dfsg/Test/Java/include.ent0000644000175000017500000000001007616770717022026 0ustar sveinungsveinungINCLUDE libnanoxml2-java-2.2.3.dfsg/Test/Java/attributes.xml.out0000644000175000017500000000023307616770717023420 0ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Test/Java/double_dtd.xml.out0000644000175000017500000000006507616770717023342 0ustar sveinungsveinungblahlibnanoxml2-java-2.2.3.dfsg/Test/Java/double_dtd.xml0000644000175000017500000000014707616770717022535 0ustar sveinungsveinung ]> &value; libnanoxml2-java-2.2.3.dfsg/Test/Java/complex_pe.xml.out0000644000175000017500000000007707616770717023373 0ustar sveinungsveinungThis sample shows a error-prone method.libnanoxml2-java-2.2.3.dfsg/Test/Java/namespaces.xml.out0000644000175000017500000000031107616770717023346 0ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Test/Java/attributes.xml0000644000175000017500000000064507616770717022621 0ustar sveinungsveinung ]> libnanoxml2-java-2.2.3.dfsg/Test/Java/complex_pe.xml0000644000175000017500000000043307616770717022561 0ustar sveinungsveinung ' > %xx; ]> This sample shows a &tricky; method. libnanoxml2-java-2.2.3.dfsg/Test/Lite/0000755000175000017500000000000007616770717017720 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Test/Lite/simple.xml0000644000175000017500000000057107616770717021736 0ustar sveinungsveinung blah blah '"]]> ac <&>"'!:‰ libnanoxml2-java-2.2.3.dfsg/Test/Lite/DumpXML_Lite.java0000644000175000017500000000353307616770717023032 0ustar sveinungsveinung/* DumpXML_Lite.java NanoXML/Lite * * $Revision: 1.2 $ * $Date: 2002/01/03 20:19:36 $ * $Name: $ * * This file is part of NanoXML 2 Lite. * 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. */ import nanoxml.*; import java.util.*; import java.io.*; public class DumpXML_Lite { public static void main(String args[]) throws Exception { if (args.length == 0) { System.err.println("Usage: java DumpXML_Lite file.xml"); Runtime.getRuntime().exit(1); } Hashtable entities = new Hashtable(); entities.put("foo", "bar"); XMLElement xml = new XMLElement(entities, false, false); FileReader reader = new FileReader(args[0]); xml.parseFromReader(reader); reader.close(); reader = new FileReader(args[0]); xml.parseFromReader(reader); reader.close(); System.out.println(xml.toString()); } } libnanoxml2-java-2.2.3.dfsg/Test/Lite/simple.xml.out0000644000175000017500000000034507616770717022543 0ustar sveinungsveinungblah blah<&>'"abc<&>"'!:‰ libnanoxml2-java-2.2.3.dfsg/Test/Lite/comments.xml.out0000644000175000017500000000003007616770717023066 0ustar sveinungsveinung libnanoxml2-java-2.2.3.dfsg/Test/Lite/comments.xml0000644000175000017500000000027607616770717022274 0ustar sveinungsveinung libnanoxml2-java-2.2.3.dfsg/Examples/0000755000175000017500000000000007616770707017661 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/0000755000175000017500000000000007616770720020535 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter02-01/0000755000175000017500000000000007616770720022503 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter02-01/DumpXML.java0000644000175000017500000000310307616770720024631 0ustar sveinungsveinung/* DumpXML.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 17:46:19 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class DumpXML { public static void main(String[] args) throws Exception { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLReader reader = StdXMLReader.fileReader("test.xml"); parser.setReader(reader); XMLElement xml = (XMLElement) parser.parse(); XMLWriter writer = new XMLWriter(System.out); writer.write(xml); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter02-01/test.xml0000644000175000017500000000016007616770720024201 0ustar sveinungsveinung The title Some text. libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/0000755000175000017500000000000007616770720022510 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/document.dtd0000644000175000017500000000031507616770720025022 0ustar sveinungsveinung libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/DocumentBuilder.java0000644000175000017500000000757407616770720026455 0ustar sveinungsveinung/* DocumentBuilder.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/17 18:37:28 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import java.io.*; import java.util.*; import net.n3.nanoxml.*; public class DocumentBuilder implements IXMLBuilder { private static Hashtable classes; private Stack elements; private DocumentElement topElement; static { classes = new Hashtable(); classes.put("Chapter", Chapter.class); classes.put("Paragraph", Paragraph.class); } public void startBuilding(String systemID, int lineNr) { this.elements = new Stack(); this.topElement = null; } public void newProcessingInstruction(String target, Reader reader) { // nothing to do } public void startElement(String name, String nsPrefix, String nsSystemID, String systemID, int lineNr) { DocumentElement elt = null; try { Class cls = (Class) classes.get(name); elt = (DocumentElement) cls.newInstance(); } catch (Exception e) { // ignore the exception } this.elements.push(elt); if (this.topElement == null) { this.topElement = elt; } } public void endElement(String name, String nsPrefix, String nsSystemID) { DocumentElement child = (DocumentElement) this.elements.pop(); if (! this.elements.isEmpty()) { DocumentElement parent = (DocumentElement) this.elements.peek(); parent.addChild(child); } } public void addAttribute(String key, String nsPrefix, String nsSystemID, String value, String type) { DocumentElement child = (DocumentElement) this.elements.peek(); child.setAttribute(key, value); } public void elementAttributesProcessed(String name, String nsPrefix, String nsSystemID) { // nothing to do } public void addPCData(Reader reader, String systemID, int lineNr) throws IOException { StringBuffer str = new StringBuffer(1024); char[] buf = new char[1024]; for (;;) { int size = reader.read(buf); if (size < 0) { break; } str.append(buf, 0, size); } this.addAttribute("#PCDATA", null, null, str.toString(), "CDATA"); } public Object getResult() { return topElement; } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/test.xml0000644000175000017500000000027007616770720024210 0ustar sveinungsveinung First paragraph... Second paragraph... libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/Chapter.java0000644000175000017500000000277207616770720024751 0ustar sveinungsveinung/* Chapter.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:38:06 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.util.*; import java.io.*; public class Chapter extends DocumentElement { public String getTitle() { return this.attrs.getProperty("title"); } public String getID() { return this.attrs.getProperty("id"); } public Enumeration getParagraphs() { return this.children.elements(); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/Paragraph.java0000644000175000017500000000360707616770720025266 0ustar sveinungsveinung/* Paragraph.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/17 18:00:08 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.util.*; import java.io.*; public class Paragraph extends DocumentElement { public static final int LEFT = 0; public static final int CENTER = 1; public static final int RIGHT = 2; private static final Hashtable alignments; static { alignments = new Hashtable(); alignments.put("left", new Integer(LEFT)); alignments.put("center", new Integer(CENTER)); alignments.put("right", new Integer(RIGHT)); } public String getContent() { return this.attrs.getProperty("#PCDATA"); } public int getAlignment() { String str = this.attrs.getProperty("align"); Integer align = (Integer) alignments.get(str); return align.intValue(); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/Chapter.java.xml0000644000175000017500000001076007616770720025544 0ustar sveinungsveinung/* Chapter.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/17 07:33:37 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */import net.n3.nanoxml.*;import java.util.*;import java.io.*;public class Chapter extends DocumentElement{ public String getTitle() { return this.attrs.getProperty("title"); } public String getID() { return this.attrs.getProperty("id"); } public Enumeration getParagraphs() { return this.children.elements(); }} libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/XML2HTML.java0000644000175000017500000000443607616770720024571 0ustar sveinungsveinung/* XML2HTML.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/17 18:33:34 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.util.*; public class XML2HTML { public static void main(String[] param) throws Exception { IXMLBuilder builder = new DocumentBuilder(); IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); parser.setBuilder(builder); IXMLReader reader = StdXMLReader.fileReader(param[0]); parser.setReader(reader); Chapter chapter = (Chapter) parser.parse(); System.out.println(""); System.out.print(""); System.out.print(chapter.getTitle()); System.out.println(""); System.out.print("

"); System.out.print(chapter.getTitle()); System.out.println("

"); Enumeration enum = chapter.getParagraphs(); while (enum.hasMoreElements()) { Paragraph para = (Paragraph) enum.nextElement(); System.out.print("

"); System.out.print(para.getContent()); System.out.println("

"); } System.out.println(""); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-04/DocumentElement.java0000644000175000017500000000320507616770720026443 0ustar sveinungsveinung/* DocumentElement.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/17 17:55:44 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.util.*; import java.io.*; public class DocumentElement { protected Properties attrs; protected Vector children; public DocumentElement() { this.attrs = new Properties(); this.children = new Vector(); } public void setAttribute(String attrName, String value) { this.attrs.put(attrName, value); } public void addChild(DocumentElement elt) { this.children.addElement(elt); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter03-01/0000755000175000017500000000000007616770720022504 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter03-01/DumpXML.java0000644000175000017500000000300007616770720024626 0ustar sveinungsveinung/* DumpXML.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 18:18:58 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class DumpXML { public static void main(String[] args) throws Exception { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLReader reader = StdXMLReader.fileReader("test.xml"); parser.setReader(reader); parser.setBuilder(new MyBuilder()); parser.parse(); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter03-01/test.xml0000644000175000017500000000016007616770720024202 0ustar sveinungsveinung The title Some text. libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter03-01/MyBuilder.java0000644000175000017500000000543307616770720025250 0ustar sveinungsveinung/* XMLWriter.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 18:17:15 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import java.io.*; import net.n3.nanoxml.*; public class MyBuilder implements IXMLBuilder { public void startBuilding(String systemID, int lineNr) { System.out.println("Document started"); } public void newProcessingInstruction(String target, Reader reader) { System.out.println("New PI with target " + target); } public void startElement(String name, String nsPrefix, String nsSystemID, String systemID, int lineNr) { System.out.println("Element started: " + name); } public void endElement(String name, String nsPrefix, String nsSystemID) { System.out.println("Element ended: " + name); } public void addAttribute(String key, String nsPrefix, String nsSystemID, String value, String type) { System.out.println(" " + key + ": " + type + " = " + value); } public void elementAttributesProcessed(String name, String nsPrefix, String nsSystemID) { // nothing to do } public void addPCData(Reader reader, String systemID, int lineNr) { System.out.println("#PCDATA"); } public Object getResult() { return null; } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-03/0000755000175000017500000000000007616770720022507 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-03/Demo.java0000644000175000017500000000327107616770720024241 0ustar sveinungsveinung/* Demo.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:24:40 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class Demo { public static void main(String[] args) throws Exception { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLValidator validator = parser.getValidator(); validator.setParameterEntityResolver(new MyResolver()); IXMLReader reader = StdXMLReader.fileReader("test.xml"); parser.setReader(reader); XMLElement xml = (XMLElement) parser.parse(); XMLWriter writer = new XMLWriter(System.out); writer.write(xml); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-03/test.xml0000644000175000017500000000023407616770720024207 0ustar sveinungsveinung ]> The title Some text. libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-03/MyResolver.java0000644000175000017500000000300607616770720025460 0ustar sveinungsveinung/* MyResolver.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:22:59 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class MyResolver extends XMLEntityResolver { public Reader getEntity(IXMLReader reader, String name) throws XMLParseException { if (name.equals("foo")) { return new StringReader("bar"); } else { return super.getEntity(reader, name); } } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-02/0000755000175000017500000000000007616770720022506 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-02/Demo.java0000644000175000017500000000315607616770720024242 0ustar sveinungsveinung/* Demo.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:19:40 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class Demo { public static void main(String[] args) throws Exception { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); parser.setResolver(new MyResolver()); IXMLReader reader = StdXMLReader.fileReader("test.xml"); parser.setReader(reader); XMLElement xml = (XMLElement) parser.parse(); XMLWriter writer = new XMLWriter(System.out); writer.write(xml); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-02/test.xml0000644000175000017500000000015307616770720024206 0ustar sveinungsveinung The title Some text. libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-02/MyResolver.java0000644000175000017500000000300607616770720025457 0ustar sveinungsveinung/* MyResolver.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:21:21 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class MyResolver extends XMLEntityResolver { public Reader getEntity(IXMLReader reader, String name) throws XMLParseException { if (name.equals("foo")) { return new StringReader("bar"); } else { return super.getEntity(reader, name); } } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-01/0000755000175000017500000000000007616770720022505 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-01/Demo.java0000644000175000017500000000334507616770720024241 0ustar sveinungsveinung/* Demo.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 18:53:26 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class Demo { public static void main(String[] args) throws Exception { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLValidator val1 = parser.getValidator(); MyValidator val2 = new MyValidator(); val2.setDelegate(val1); parser.setValidator(val2); IXMLReader reader = StdXMLReader.fileReader("test.xml"); parser.setReader(reader); XMLElement xml = (XMLElement) parser.parse(); XMLWriter writer = new XMLWriter(System.out); writer.write(xml); } } libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-01/test.xml0000644000175000017500000000015407616770720024206 0ustar sveinungsveinung The title Some text. libnanoxml2-java-2.2.3.dfsg/Examples/Java/Chapter04-01/MyValidator.java0000644000175000017500000000424407616770720025607 0ustar sveinungsveinung/* MyValidator.java NanoXML/Java * * $Revision: 1.1.1.1 $ * $Date: 2001/07/16 22:10:51 $ * $Name: $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2001 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. */ import net.n3.nanoxml.*; import java.io.*; public class MyValidator extends ValidatorPlugin { public void attributeAdded(String key, String nsPrefix, String nsSystemID, String value, String systemID, int lineNr) throws Exception { boolean valid = true; if (key.equals("id")) { if (value.length() < 3) { valid = false; } else { for (int i = 0; i < 3; i++) { char ch = value.charAt(i); if ((ch < 'A') || (ch > 'Z')) { valid = false; } } } } if (valid) { super.attributeAdded(key, nsPrefix, nsSystemID, value, systemID, lineNr); } else { this.invalidAttributeValue(systemID, lineNr, null, key, value); } } } libnanoxml2-java-2.2.3.dfsg/build.sh0000755000175000017500000000457407616770720017546 0ustar sveinungsveinung#!/bin/sh CURRDIR="`pwd`"; export CURRDIR mkdir Output rm -rf "/tmp/nanoxml-build-$$" rm -rf "/tmp/nanoxml-sax-build-$$" rm -rf "/tmp/nanoxml-lite-build-$$" echo "Compiling NanoXML/Lite 2.2.3" mkdir "/tmp/nanoxml-lite-build-$$" (cd Sources/Lite; javac -deprecation -target 1.1 -g:none -d "/tmp/nanoxml-lite-build-$$" nanoxml/*.java) || exit 1 (cd /tmp/nanoxml-lite-build-$$; jar cMf "$CURRDIR/Output/nanoxml-lite.jar" nanoxml/*.class) || exit 1 (cd Test/Lite; javac -classpath ":$CURRDIR/Output/nanoxml-lite.jar:." DumpXML_Lite.java) || exit 1 echo "Compiling NanoXML/Java 2.2.3" mkdir "/tmp/nanoxml-build-$$" (cd Sources/Java; javac -deprecation -g:none -d "/tmp/nanoxml-build-$$" net/n3/nanoxml/*.java) || exit 1 (cd /tmp/nanoxml-build-$$; jar cMf "$CURRDIR/Output/nanoxml.jar" net/n3/nanoxml/*.class) || exit 1 (cd Test/Java; javac -classpath ":$CURRDIR/Output/nanoxml.jar:." DumpXML.java) || exit 1 echo "Compiling NanoXML/SAX 2.2.3" CLASSPATH=":$CURRDIR/ThirdParty/SAX/sax.jar:/tmp/nanoxml-build-$$:."; export CLASSPATH mkdir "/tmp/nanoxml-sax-build-$$" mkdir "/tmp/nanoxml-sax-build-$$/net" mkdir "/tmp/nanoxml-sax-build-$$/net/n3" mkdir "/tmp/nanoxml-sax-build-$$/net/n3/nanoxml" for a in ContentReader.class IXMLBuilder.class IXMLParser.class IXMLReader.class IXMLValidator.class NonValidator.class StdXMLParser.class StdXMLReader.class XMLEntityResolver.class XMLParseException.class XMLParserFactory.class XMLUtil.class XMLValidationException.class do cp "/tmp/nanoxml-build-$$/net/n3/nanoxml/$a" "/tmp/nanoxml-sax-build-$$/net/n3/nanoxml/" done (cd Sources/SAX; javac -g:none -d "/tmp/nanoxml-build-$$" net/n3/nanoxml/sax/*.java) || exit 1 (cd /tmp/nanoxml-build-$$; jar cMf "$CURRDIR/Output/nanoxml-sax.jar" net/n3/nanoxml/sax/*.class) echo "Generating JavaDoc" mkdir "$CURRDIR/Documentation/JavaDoc" javadoc -protected -sourcepath "$CURRDIR/Sources/Lite:$CURRDIR/Sources/Java:$CURRDIR/Sources/SAX" -classpath "/tmp/nanoxml-lite-build-$$:/tmp/nanoxml-build-$$:/tmp/nanoxml-sax-build-$$:$CURRDIR/Thirdparty/SAX/sax.jar" -d "$CURRDIR/Documentation/JavaDoc" -version -author -windowtitle "NanoXML 2.2.3" net.n3.nanoxml net.n3.nanoxml.sax nanoxml >"/tmp/javadoc.log" 2>&1 || (cat /tmp/javadoc.log; exit 1) || exit 1 rm -rf "/tmp/nanoxml-lite-build-$$" rm -rf "/tmp/nanoxml-sax-build-$$" rm -rf "/tmp/nanoxml-build-$$" echo "Done" echo "Output is in $CURRDIR/Output/" libnanoxml2-java-2.2.3.dfsg/Sources/0000755000175000017500000000000007616770707017526 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/0000755000175000017500000000000007616770707020161 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/0000755000175000017500000000000007616770707020747 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/0000755000175000017500000000000007616770707021267 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/nanoxml/0000755000175000017500000000000007616770707022743 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/nanoxml/sax/0000755000175000017500000000000007616770707023536 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/nanoxml/sax/SAXParser.java0000644000175000017500000001530207616770707026212 0ustar sveinungsveinung/* SAXParser.java NanoXML/SAX * * $Revision: 1.5 $ * $Date: 2002/03/24 11:39:20 $ * $Name: RELEASE_2_2_1 $ * * This file is part of the SAX adapter for 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 net.n3.nanoxml.sax; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.util.Locale; import net.n3.nanoxml.IXMLBuilder; import net.n3.nanoxml.IXMLParser; import net.n3.nanoxml.IXMLReader; import net.n3.nanoxml.StdXMLReader; import net.n3.nanoxml.XMLParserFactory; import org.xml.sax.Parser; import org.xml.sax.DocumentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributeListImpl; import org.xml.sax.helpers.LocatorImpl; /** * SAXParser implements the SAX Parser interface. It is the frontend to SAX * for the NanoXML parser. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $ */ public class SAXParser implements Parser { /** * The SAX adapter. */ private SAXAdapter adapter; /** * The client error handler. */ private ErrorHandler errorHandler; /** * The entity resolver. */ private SAXEntityResolver entityResolver; /** * Creates the SAX parser. */ public SAXParser() { this.adapter = new SAXAdapter(); this.errorHandler = new HandlerBase(); this.entityResolver = new SAXEntityResolver(); } /** * Cleans up the object when it's destroyed. */ protected void finalize() throws Throwable { this.adapter = null; this.errorHandler = null; this.entityResolver = null; super.finalize(); } /** * Sets the locale. Only locales using the language english are accepted. * * @param locale the locale * * @exception org.xml.sax.SAXException * if locale is null or the associated * language is not english. */ public void setLocale(Locale locale) throws SAXException { if ((locale == null) || (! locale.getLanguage().equals("en"))) { throw new SAXException("NanoXML/SAX doesn't support locale: " + locale); } } /** * Sets the entity resolver. * * @param resolver the entity resolver */ public void setEntityResolver(EntityResolver resolver) { this.entityResolver.setEntityResolver(resolver); } /** * Sets the DTD handler. As the parser is non-validating, this handler is * never called. * * @param handler the DTD handler */ public void setDTDHandler(DTDHandler handler) { // nothing to do } /** * Allows an application to register a document event handler. * * @param handler the document handler */ public void setDocumentHandler(DocumentHandler handler) { this.adapter.setDocumentHandler(handler); } /** * Allow an application to register an error event handler. * * @param handler the error handler */ public void setErrorHandler(ErrorHandler handler) { this.errorHandler = handler; } /** * Creates the XML parser. */ private IXMLParser createParser() throws SAXException { try { return XMLParserFactory.createDefaultXMLParser(); } catch (Exception exception) { throw new SAXException(exception); } } /** * Parse an XML document. * * @param source the input source */ public void parse(InputSource source) throws SAXException, IOException { IXMLParser parser = this.createParser(); parser.setBuilder(this.adapter); parser.setResolver(this.entityResolver); Reader reader = source.getCharacterStream(); if (reader != null) { parser.setReader(new StdXMLReader(reader)); } else { InputStream stream = source.getByteStream(); if (stream != null) { String encoding = source.getEncoding(); if (encoding != null) { try { reader = new InputStreamReader(stream, encoding); parser.setReader(new StdXMLReader(reader)); } catch (UnsupportedEncodingException exception) { throw new SAXException(exception); } } else { // if encoding == null parser.setReader(new StdXMLReader(stream)); } } else { // if stream == null parser.setReader(new StdXMLReader(source.getPublicId(), source.getSystemId())); } } try { parser.parse(); this.adapter.endDocument(); } catch (IOException exception) { throw exception; } catch (Exception exception) { throw new SAXException(exception); } finally { reader.close(); } } /** * Parse an XML document from a system identifier (URI). * * @param systemId the system ID */ public void parse(String systemId) throws SAXException, IOException { IXMLParser parser = this.createParser(); parser.setBuilder(this.adapter); parser.setReader(new StdXMLReader(null, systemId)); try { parser.parse(); this.adapter.endDocument(); } catch (IOException exception) { throw exception; } catch (Exception exception) { throw new SAXException(exception); } } } libnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/nanoxml/sax/SAXEntityResolver.java0000644000175000017500000000766107616770707027765 0ustar sveinungsveinung/* SAXEntityResolver.java NanoXML/SAX * * $Revision: 1.4 $ * $Date: 2002/01/04 21:03:28 $ * $Name: RELEASE_2_2_1 $ * * This file is part of the SAX adapter for 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 net.n3.nanoxml.sax; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import net.n3.nanoxml.XMLEntityResolver; import net.n3.nanoxml.IXMLReader; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; /** * SAXEntityResolver is a subclass of XMLEntityResolver that supports the * SAX EntityResolver listener. * * @see net.n3.nanoxml.IXMLEntityResolver * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public class SAXEntityResolver extends XMLEntityResolver { /** * The SAX EntityResolver listener. */ private EntityResolver saxEntityResolver; /** * Creates the resolver. */ public SAXEntityResolver() { this.saxEntityResolver = null; } /** * Cleans up the object when it's destroyed. */ protected void finalize() throws Throwable { this.saxEntityResolver = null; super.finalize(); } /** * Sets the SAX EntityResolver listener. * * @param resolver the entity resolver */ public void setEntityResolver(EntityResolver resolver) { this.saxEntityResolver = resolver; } /** * 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(IXMLReader xmlReader, String publicID, String systemID) { try { URL url = new URL(xmlReader.getSystemID()); url = new URL(url, systemID); if (this.saxEntityResolver != null) { InputSource source = this.saxEntityResolver .resolveEntity(publicID, url.toString()); if (source != null) { Reader reader = source.getCharacterStream(); if (reader != null) { return reader; } InputStream stream = source.getByteStream(); if (stream == null) { publicID = source.getPublicId(); systemID = source.getSystemId(); } else { String encoding = source.getEncoding(); if (encoding != null) { return new InputStreamReader(stream, encoding); } else { // if encoding == null return new InputStreamReader(stream); } } } } return super.openExternalEntity(xmlReader, publicID, systemID); } catch (Exception e) { return null; } } } libnanoxml2-java-2.2.3.dfsg/Sources/SAX/net/n3/nanoxml/sax/SAXAdapter.java0000644000175000017500000002167007616770707026343 0ustar sveinungsveinung/* SAXAdapter.java NanoXML/SAX * * $Revision: 1.4 $ * $Date: 2002/01/04 21:03:28 $ * $Name: RELEASE_2_2_1 $ * * This file is part of the SAX adapter for 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 net.n3.nanoxml.sax; import java.io.Reader; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import net.n3.nanoxml.IXMLBuilder; import net.n3.nanoxml.IXMLReader; import org.xml.sax.AttributeList; import org.xml.sax.DocumentHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.HandlerBase; import org.xml.sax.Locator; import org.xml.sax.helpers.AttributeListImpl; import org.xml.sax.helpers.LocatorImpl; /** * SAXAdapter is the core adapter for using NanoXML/Java with SAX, the "Simple" * API For XML. * * @see net.n3.nanoxml.IXMLBuilder * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public class SAXAdapter implements IXMLBuilder { /** * The NanoXML reader. */ private IXMLReader nanoxmlReader; /** * The SAX document handler. */ private DocumentHandler saxDocumentHandler; /** * The SAX error handler. */ private ErrorHandler saxErrorHandler; /** * The SAX locator. */ private LocatorImpl saxLocator; /** * The SAX attribute list. */ private AttributeListImpl saxAttributes; /** * Creates the adapter. */ public SAXAdapter() { this.saxDocumentHandler = new HandlerBase(); this.saxLocator = new LocatorImpl(); this.saxLocator.setColumnNumber(-1); } /** * Cleans up the object when it's destroyed. */ protected void finalize() throws Throwable { this.nanoxmlReader = null; this.saxDocumentHandler = null; this.saxErrorHandler = null; this.saxLocator = null; this.saxAttributes = null; super.finalize(); } /** * Sets the document handler. * * @param handler the document handler */ public void setDocumentHandler(DocumentHandler handler) { this.saxDocumentHandler = handler; } /** * Sets the reader. * * @param reader the reader. */ public void setReader(IXMLReader reader) { this.nanoxmlReader = reader; } /** * This method is called before the parser starts processing its input. * * @param systemID the system ID of the data source * @param lineNr the line on which the parsing starts */ public void startBuilding(String systemID, int lineNr) throws Exception { this.saxLocator.setLineNumber(lineNr); this.saxLocator.setSystemId(systemID); this.saxDocumentHandler.setDocumentLocator(this.saxLocator); this.saxDocumentHandler.startDocument(); } /** * 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) throws Exception { StringBuffer data = new StringBuffer(); char[] chars = new char[1024]; int charsRead = reader.read(chars); while (charsRead > 0) { data.append(chars, 0, charsRead); charsRead = reader.read(chars); } this.saxDocumentHandler.processingInstruction(target, data.toString()); } /** * 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 * @param nsSystemId the system ID associated with the namespace * @param systemID the system ID of the data source * @param lineNr the line in the source where the element starts */ public void startElement(String name, String nsPrefix, String nsSystemId, String systemID, int lineNr) throws Exception { if (nsPrefix != null) { name = nsPrefix + ':' + name; } this.saxLocator.setLineNumber(lineNr); this.saxLocator.setSystemId(systemID); this.saxAttributes = new AttributeListImpl(); } /** * 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 * @param nsSystemId the system ID associated with the namespace */ public void elementAttributesProcessed(String name, String nsPrefix, String nsSystemId) throws Exception { if (nsPrefix != null) { name = nsPrefix + ':' + name; } this.saxDocumentHandler.startElement(name, this.saxAttributes); } /** * 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 * @param nsSystemId the system ID associated with the namespace */ public void endElement(String name, String nsPrefix, String nsSystemId) throws Exception { if (nsPrefix != null) { name = nsPrefix + ':' + name; } this.saxDocumentHandler.endElement(name); } /** * 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 * @param nsSystemId the system ID associated with the namespace * @param value the value of the attribute * @param type the type of the attribute ("CDATA" if unknown) */ public void addAttribute(String key, String nsPrefix, String nsSystemId, String value, String type) throws Exception { if (nsPrefix != null) { key = nsPrefix + ':' + key; } this.saxAttributes.addAttribute(key, type, 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 data source * @param lineNr the line in the source where the element starts * * @throws java.io.IOException * when the reader throws such exception */ public void addPCData(Reader reader, String systemID, int lineNr) throws Exception { this.saxLocator.setLineNumber(lineNr); this.saxLocator.setSystemId(systemID); char[] chars = new char[2048]; int charsRead = reader.read(chars); while (charsRead > 0) { this.saxDocumentHandler.characters(chars, 0, charsRead); charsRead = reader.read(chars); } } /** * Returns the result of the building process. This method is called just * before the parse() method of IXMLParser returns. * * @see net.n3.nanoxml.IXMLParser#parse * * @return the result of the building process. */ public Object getResult() throws Exception { return null; } /** * Indicates that parsing has been completed. */ public void endDocument() throws Exception { this.saxDocumentHandler.endDocument(); } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/0000755000175000017500000000000007616770707020407 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/Java/net/0000755000175000017500000000000007616770707021175 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/0000755000175000017500000000000007616770707021515 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/0000755000175000017500000000000007616770707023171 5ustar sveinungsveinunglibnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/CDATAReader.java0000644000175000017500000001051407616770707025774 0ustar sveinungsveinung/* 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 net.n3.nanoxml; 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 IXMLReader 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(IXMLReader 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; } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/ValidatorPlugin.java0000644000175000017500000003243407616770707027146 0ustar sveinungsveinung/* ValidatorPlugin.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 net.n3.nanoxml; import java.io.Reader; import java.io.IOException; import java.util.Properties; /** * ValidatorPlugin allows the application to insert additional validators into * NanoXML. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ */ public class ValidatorPlugin implements IXMLValidator { /** * The delegate. */ private IXMLValidator delegate; /** * Initializes the plugin. */ public ValidatorPlugin() { this.delegate = null; } /** * Cleans up the object when it's destroyed. */ protected void finalize() throws Throwable { this.delegate = null; super.finalize(); } /** * Returns the delegate. */ public IXMLValidator getDelegate() { return this.delegate; } /** * Sets the delegate. * * @param delegate the delegate */ public void setDelegate(IXMLValidator delegate) { this.delegate = delegate; } /** * Sets the parameter entity resolver. * * @param resolver the entity resolver. */ public void setParameterEntityResolver(IXMLEntityResolver resolver) { this.delegate.setParameterEntityResolver(resolver); } /** * Returns the parameter entity resolver. * * @return the entity resolver. */ public IXMLEntityResolver getParameterEntityResolver() { return this.delegate.getParameterEntityResolver(); } /** * Parses the DTD. The validator object is responsible for reading the * full DTD. * * @param publicID the public ID, which may be null. * @param reader the reader to read the DTD from. * @param entityResolver the entity resolver. * @param external true if the DTD is external. * * @throws java.lang.Exception * if something went wrong. */ public void parseDTD(String publicID, IXMLReader reader, IXMLEntityResolver entityResolver, boolean external) throws Exception { this.delegate.parseDTD(publicID, reader, entityResolver, external); } /** * Indicates that an element has been started. * * @param name the name of the element. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. * * @throws java.lang.Exception * if the element could not be validated. */ public void elementStarted(String name, String systemId, int lineNr) throws Exception { this.delegate.elementStarted(name, systemId, lineNr); } /** * Indicates that the current element has ended. * * @param name the name of the element. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. * * @throws java.lang.Exception * if the element could not be validated. */ public void elementEnded(String name, String systemId, int lineNr) throws Exception { this.delegate.elementEnded(name,systemId, lineNr); } /** * Indicates that an attribute has been added to the current element. * * @param key the name of the attribute. * @param value the value of the attribute. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. * * @throws java.lang.Exception * if the attribute could not be validated. */ public void elementAttributesProcessed(String name, Properties extraAttributes, String systemId, int lineNr) throws Exception { this.delegate.elementAttributesProcessed(name, extraAttributes, systemId, lineNr); } /** * This method is called when the attributes of an XML element have been * processed. * If there are attributes with a default value which have not been * specified yet, they have to be put into extraAttributes. * * @param name the name of the element. * @param extraAttributes where to put extra attributes. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. * * @throws java.lang.Exception * if the element could not be validated. */ public void attributeAdded(String key, String value, String systemId, int lineNr) throws Exception { this.delegate.attributeAdded(key, value, systemId, lineNr); } /** * Indicates that a new #PCDATA element has been encountered. * * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. * * @throws java.lang.Exception * if the element could not be validated. */ public void PCDataAdded(String systemId, int lineNr) throws Exception { this.delegate.PCDataAdded(systemId, lineNr); } /** * Throws an XMLValidationException to indicate that an element is missing. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param parentElementName the name of the parent element * @param missingElementName the name of the missing element * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void missingElement(String systemID, int lineNr, String parentElementName, String missingElementName) throws XMLValidationException { XMLUtil.errorMissingElement(systemID, lineNr, parentElementName, missingElementName); } /** * Throws an XMLValidationException to indicate that an element is * unexpected. * * @param systemID the system ID of the XML data of the * element * @param lineNr the line number in the XML data of the * element * @param parentElementName the name of the parent element * @param unexpectedElementName the name of the missing element * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void unexpectedElement(String systemID, int lineNr, String parentElementName, String unexpectedElementName) throws XMLValidationException { XMLUtil.errorUnexpectedElement(systemID, lineNr, parentElementName, unexpectedElementName); } /** * Throws an XMLValidationException to indicate that an attribute is * missing. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param elementName the name of the element * @param attributeName the name of the missing attribute * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void missingAttribute(String systemID, int lineNr, String elementName, String attributeName) throws XMLValidationException { XMLUtil.errorMissingAttribute(systemID, lineNr, elementName, attributeName); } /** * Throws an XMLValidationException to indicate that an attribute is * unexpected. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param elementName the name of the element * @param attributeName the name of the unexpected attribute * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void unexpectedAttribute(String systemID, int lineNr, String elementName, String attributeName) throws XMLValidationException { XMLUtil.errorUnexpectedAttribute(systemID, lineNr, elementName, attributeName); } /** * Throws an XMLValidationException to indicate that an attribute has an * invalid value. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param elementName the name of the element * @param attributeName the name of the attribute * @param attributeValue the value of the attribute * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void invalidAttributeValue(String systemID, int lineNr, String elementName, String attributeName, String attributeValue) throws XMLValidationException { XMLUtil.errorInvalidAttributeValue(systemID, lineNr, elementName, attributeName, attributeValue); } /** * Throws an XMLValidationException to indicate that a #PCDATA element was * missing. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param parentElementName the name of the parent element * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void missingPCData(String systemID, int lineNr, String parentElementName) throws XMLValidationException { XMLUtil.errorMissingPCData(systemID, lineNr, parentElementName); } /** * Throws an XMLValidationException to indicate that a #PCDATA element was * unexpected. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param parentElementName the name of the parent element * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void unexpectedPCData(String systemID, int lineNr, String parentElementName) throws XMLValidationException { XMLUtil.errorUnexpectedPCData(systemID, lineNr, parentElementName); } /** * Throws an XMLValidationException. * * @param systemID the system ID of the XML data of the element * @param lineNr the line number in the XML data of the element * @param message the error message * @param elementName the name of the element (may be null) * @param attributeName the name of the attribute (may be null) * @param attributeValue the value of the attribute (may be null) * * @throws net.n3.nanoxml.XMLValidationException * of course :-) */ public void validationError(String systemID, int lineNr, String message, String elementName, String attributeName, String attributeValue) throws XMLValidationException { XMLUtil.validationError(systemID, lineNr, message, elementName, attributeName, attributeValue); } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLParseException.java0000644000175000017500000000401607616770707027347 0ustar sveinungsveinung/* 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 net.n3.nanoxml; /** * 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 $ */ 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); } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLException.java0000644000175000017500000001631307616770707026357 0ustar sveinungsveinung/* 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 net.n3.nanoxml; 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 $ */ 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; } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLElement.java0000644000175000017500000007071107616770707026014 0ustar sveinungsveinung/* XMLElement.java NanoXML/Java * * $Revision: 1.5 $ * $Date: 2002/02/06 18:50:12 $ * $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 net.n3.nanoxml; import java.io.Serializable; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; import java.util.Vector; /** * XMLElement is an XML element. The standard NanoXML builder generates a * tree of such elements. * * @see net.n3.nanoxml.StdXMLBuilder * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $ */ public class XMLElement implements IXMLElement, Serializable { /** * Necessary for serialization. */ static final long serialVersionUID = -2383376380548624920L; /** * No line number defined. */ public static final int NO_LINE = -1; /** * The parent element. */ private IXMLElement 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. */ 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 lineNr; /** * Creates an empty element to be used for #PCDATA content. */ 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. * * @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(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.lineNr = lineNr; this.systemID = systemID; this.parent = null; } /** * Creates an element to be used for #PCDATA content. */ public IXMLElement createPCDataElement() { return new XMLElement(); } /** * Creates an empty element. * * @param fullName the name of the element. */ public IXMLElement 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 IXMLElement createElement(String fullName, String systemID, int lineNr) { return new XMLElement(fullName, systemID, lineNr); } /** * Creates an empty element. * * @param fullName the full name of the element * @param namespace the namespace URI. */ public IXMLElement createElement(String fullName, String namespace) { return new XMLElement(fullName, namespace); } /** * 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 IXMLElement 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 IXMLElement getParent() { return this.parent; } /** * Returns the full name (i.e. the name including an eventual namespace * prefix) of the element. * * @return the name, or null if the element only contains #PCDATA. */ public String getFullName() { return this.fullName; } /** * Returns the name of the element. * * @return the name, or null if the element only contains #PCDATA. */ public String getName() { 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(IXMLElement child) { if (child == null) { throw new IllegalArgumentException("child must not be null"); } if ((child.getName() == null) && (! this.children.isEmpty())) { IXMLElement lastChild = (IXMLElement) this.children.lastElement(); if (lastChild.getName() == 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(IXMLElement child, int index) { if (child == null) { throw new IllegalArgumentException("child must not be null"); } if ((child.getName() == null) && (! this.children.isEmpty())) { IXMLElement lastChild = (IXMLElement) this.children.lastElement(); if (lastChild.getName() == 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(IXMLElement 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 removeChildAtIndex(int index) { this.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 this.children.isEmpty(); } /** * Returns whether the element has children. * * @return true if the element has children. */ public boolean hasChildren() { return (! this.children.isEmpty()); } /** * Returns the number of children. * * @return the count. */ public int getChildrenCount() { return this.children.size(); } /** * Returns a vector containing all the child elements. * * @return the vector. */ public Vector getChildren() { return this.children; } /** * 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 IXMLElement getChildAtIndex(int index) throws ArrayIndexOutOfBoundsException { return (IXMLElement) this.children.elementAt(index); } /** * Searches a child element. * * @param name the full name of the child to search for. * * @return the child element, or null if no such child was found. */ public IXMLElement getFirstChildNamed(String name) { Enumeration enum = this.children.elements(); while (enum.hasMoreElements()) { IXMLElement child = (IXMLElement) enum.nextElement(); String childName = child.getFullName(); if ((childName != null) && childName.equals(name)) { return child; } } return null; } /** * Searches a child element. * * @param name the name of the child to search for. * @param namespace the namespace, which may be null. * * @return the child element, or null if no such child was found. */ public IXMLElement getFirstChildNamed(String name, String namespace) { Enumeration enum = this.children.elements(); while (enum.hasMoreElements()) { IXMLElement child = (IXMLElement) enum.nextElement(); String str = child.getName(); boolean found = (str != null) && (str.equals(name)); str = child.getNamespace(); if (str == null) { found &= (name == null); } else { found &= str.equals(namespace); } if (found) { return child; } } return null; } /** * Returns a vector of all child elements named name. * * @param name the full name of the children to search for. * * @return the non-null vector of child elements. */ public Vector getChildrenNamed(String name) { Vector result = new Vector(this.children.size()); Enumeration enum = this.children.elements(); while (enum.hasMoreElements()) { IXMLElement child = (IXMLElement) enum.nextElement(); String childName = child.getFullName(); if ((childName != null) && childName.equals(name)) { result.addElement(child); } } return result; } /** * Returns a vector of all child elements named name. * * @param name the name of the children to search for. * @param namespace the namespace, which may be null. * * @return the non-null vector of child elements. */ public Vector getChildrenNamed(String name, String namespace) { Vector result = new Vector(this.children.size()); Enumeration enum = this.children.elements(); while (enum.hasMoreElements()) { IXMLElement child = (IXMLElement) enum.nextElement(); String str = child.getName(); boolean found = (str != null) && (str.equals(name)); str = child.getNamespace(); if (str == null) { found &= (name == null); } else { found &= str.equals(namespace); } if (found) { result.addElement(child); } } return result; } /** * 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 enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.nextElement(); if (attr.getFullName().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 enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.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 this.attributes.size(); } /** * @deprecated As of NanoXML/Java 2.1, replaced by * {@link #getAttribute(java.lang.String,java.lang.String)} * 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 this.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. */ public String getAttribute(String name, String namespace, String defaultValue) { XMLAttribute attr = this.findAttribute(name, namespace); if (attr == null) { return defaultValue; } else { return attr.getValue(); } } /** * 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 int getAttribute(String name, int defaultValue) { String value = this.getAttribute(name, Integer.toString(defaultValue)); return Integer.parseInt(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 int getAttribute(String name, String namespace, int defaultValue) { String value = this.getAttribute(name, namespace, Integer.toString(defaultValue)); return Integer.parseInt(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(); } } /** * Sets an attribute. * * @param name the non-null full name of the attribute. * @param value the non-null value of the attribute. */ public void setAttribute(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); } } /** * 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 name = fullName.substring(index + 1); XMLAttribute attr = this.findAttribute(name, namespace); if (attr == null) { attr = new XMLAttribute(fullName, name, namespace, value, "CDATA"); this.attributes.addElement(attr); } else { attr.setValue(value); } } /** * Removes an attribute. * * @param name the non-null name of the attribute. */ public void removeAttribute(String name) { for (int i = 0; i < this.attributes.size(); i++) { XMLAttribute attr = (XMLAttribute) this.attributes.elementAt(i); if (attr.getFullName().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 enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.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 enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.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 enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.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 getLineNr() { return this.lineNr; } /** * 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. * * @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 rawElement) { try { return this.equalsXMLElement((IXMLElement) rawElement); } catch (ClassCastException e) { return false; } } /** * Returns true if the element equals another element. * * @param rawElement the element to compare to */ public boolean equalsXMLElement(IXMLElement elt) { if (! this.name.equals(elt.getName())) { return false; } if (this.attributes.size() != elt.getAttributeCount()) { return false; } Enumeration enum = this.attributes.elements(); while (enum.hasMoreElements()) { XMLAttribute attr = (XMLAttribute) enum.nextElement(); if (! elt.hasAttribute(attr.getName(), attr.getNamespace())) { return false; } String value = elt.getAttribute(attr.getName(), attr.getNamespace(), null); if (! attr.getValue().equals(value)) { return false; } String type = elt.getAttributeType(attr.getName(), attr.getNamespace()); if (! attr.getType().equals(type)) { return false; } } if (this.children.size() != elt.getChildrenCount()) { return false; } for (int i = 0; i < this.children.size(); i++) { IXMLElement child1 = this.getChildAtIndex(i); IXMLElement child2 = elt.getChildAtIndex(i); if (! child1.equalsXMLElement(child2)) { return false; } } return true; } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLEntityResolver.java0000644000175000017500000001127207616770707027416 0ustar sveinungsveinung/* 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 net.n3.nanoxml; 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 implements IXMLEntityResolver { /** * 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(IXMLReader 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(IXMLReader 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); } } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/NonValidator.java0000644000175000017500000004320107616770707026434 0ustar sveinungsveinung/* NonValidator.java NanoXML/Java * * $Revision: 1.4 $ * $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 net.n3.nanoxml; import java.io.Reader; import java.io.IOException; import java.io.StringReader; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; import java.util.Stack; /** * NonValidator is a concrete implementation of IXMLValidator which processes * the DTD and handles entity definitions. It does not do any validation * itself. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public class NonValidator implements IXMLValidator { /** * The parameter entity resolver. */ protected IXMLEntityResolver parameterEntityResolver; /** * Contains the default values for attributes for the different element * types. */ protected Hashtable attributeDefaultValues; /** * The stack of elements to be processed. */ protected Stack currentElements; /** * Creates the "validator". */ public NonValidator() { this.attributeDefaultValues = new Hashtable(); this.currentElements = new Stack(); this.parameterEntityResolver = new XMLEntityResolver(); } /** * Cleans up the object when it's destroyed. */ protected void finalize() throws Throwable { this.parameterEntityResolver = null; this.attributeDefaultValues.clear(); this.attributeDefaultValues = null; this.currentElements.clear(); this.currentElements = null; super.finalize(); } /** * Sets the parameter entity resolver. * * @param resolver the entity resolver. */ public void setParameterEntityResolver(IXMLEntityResolver resolver) { this.parameterEntityResolver = resolver; } /** * Returns the parameter entity resolver. * * @return the entity resolver. */ public IXMLEntityResolver getParameterEntityResolver() { return this.parameterEntityResolver; } /** * Parses the DTD. The validator object is responsible for reading the * full DTD. * * @param publicID the public ID, which may be null. * @param reader the reader to read the DTD from. * @param entityResolver the entity resolver. * @param external true if the DTD is external. * * @throws java.lang.Exception * If something went wrong. */ public void parseDTD(String publicID, IXMLReader reader, IXMLEntityResolver entityResolver, boolean external) throws Exception { XMLUtil.skipWhitespace(reader, null); int origLevel = reader.getStreamLevel(); for (;;) { String str = XMLUtil.read(reader, '%'); char ch = str.charAt(0); if (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); continue; } else if (ch == '<') { this.processElement(reader, entityResolver); } else if (ch == ']') { return; // end internal DTD } else { XMLUtil.errorInvalidInput(reader.getSystemID(), reader.getLineNr(), str); } do { ch = reader.read(); if (external && (reader.getStreamLevel() < origLevel)) { reader.unread(ch); return; // end external DTD } } while ((ch == ' ') || (ch == '\t') || (ch == '\n') || (ch == '\r')); reader.unread(ch); } } /** * Processes an element in the DTD. * * @param reader the reader to read data from. * @param entityResolver the entity resolver. * * @throws java.lang.Exception * If something went wrong. */ protected void processElement(IXMLReader reader, IXMLEntityResolver entityResolver) throws Exception { String str = XMLUtil.read(reader, '%'); char ch = str.charAt(0); if (ch != '!') { XMLUtil.skipTag(reader); return; } str = XMLUtil.read(reader, '%'); ch = str.charAt(0); switch (ch) { case '-': XMLUtil.skipComment(reader); break; case '[': this.processConditionalSection(reader, entityResolver); break; case 'E': this.processEntity(reader, entityResolver); break; case 'A': this.processAttList(reader, entityResolver); break; default: XMLUtil.skipTag(reader); } } /** * Processes a conditional section. * * @param reader the reader to read data from. * @param entityResolver the entity resolver. * * @throws java.lang.Exception * If something went wrong. */ protected void processConditionalSection(IXMLReader reader, IXMLEntityResolver entityResolver) throws Exception { XMLUtil.skipWhitespace(reader, null); String str = XMLUtil.read(reader, '%'); char ch = str.charAt(0); if (ch != 'I') { XMLUtil.skipTag(reader); return; } str = XMLUtil.read(reader, '%'); ch = str.charAt(0); switch (ch) { case 'G': this.processIgnoreSection(reader, entityResolver); return; case 'N': break; default: XMLUtil.skipTag(reader); return; } if (! XMLUtil.checkLiteral(reader, "CLUDE")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); if (ch != '[') { XMLUtil.skipTag(reader); return; } Reader subreader = new CDATAReader(reader); StringBuffer buf = new StringBuffer(1024); for (;;) { int ch2 = subreader.read(); if (ch2 < 0) { break; } buf.append((char) ch2); } subreader.close(); reader.startNewStream(new StringReader(buf.toString())); } /** * Processes an ignore section. * * @param reader the reader to read data from. * @param entityResolver the entity resolver. * * @throws java.lang.Exception * If something went wrong. */ protected void processIgnoreSection(IXMLReader reader, IXMLEntityResolver entityResolver) throws Exception { if (! XMLUtil.checkLiteral(reader, "NORE")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); String str = XMLUtil.read(reader, '%'); char ch = str.charAt(0); if (ch != '[') { XMLUtil.skipTag(reader); return; } Reader subreader = new CDATAReader(reader); subreader.close(); } /** * Processes an ATTLIST element. * * @param reader the reader to read data from. * @param entityResolver the entity resolver. * * @throws java.lang.Exception * If something went wrong. */ protected void processAttList(IXMLReader reader, IXMLEntityResolver entityResolver) throws Exception { if (! XMLUtil.checkLiteral(reader, "TTLIST")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); String str = XMLUtil.read(reader, '%'); char ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } reader.unread(ch); String elementName = XMLUtil.scanIdentifier(reader); XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } Properties props = new Properties(); while (ch != '>') { reader.unread(ch); String attName = XMLUtil.scanIdentifier(reader); XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } if (ch == '(') { while (ch != ')') { str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } } } else { reader.unread(ch); XMLUtil.scanIdentifier(reader); } XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } if (ch == '#') { str = XMLUtil.scanIdentifier(reader); XMLUtil.skipWhitespace(reader, null); if (! str.equals("FIXED")) { XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } continue; } } else { reader.unread(ch); } String value = XMLUtil.scanString(reader, '%', this.parameterEntityResolver); props.put(attName, value); XMLUtil.skipWhitespace(reader, null); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); while (ch == '%') { XMLUtil.processEntity(str, reader, this.parameterEntityResolver); str = XMLUtil.read(reader, '%'); ch = str.charAt(0); } } if (! props.isEmpty()) { this.attributeDefaultValues.put(elementName, props); } } /** * Processes an ENTITY element. * * @param reader the reader to read data from. * @param entityResolver the entity resolver. * * @throws java.lang.Exception * If something went wrong. */ protected void processEntity(IXMLReader reader, IXMLEntityResolver entityResolver) throws Exception { if (! XMLUtil.checkLiteral(reader, "NTITY")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); char ch = XMLUtil.readChar(reader, '\0'); if (ch == '%') { XMLUtil.skipWhitespace(reader, null); entityResolver = this.parameterEntityResolver; } else { reader.unread(ch); } String key = XMLUtil.scanIdentifier(reader); XMLUtil.skipWhitespace(reader, null); ch = XMLUtil.readChar(reader, '%'); String systemID = null; String publicID = null; switch (ch) { case 'P': if (! XMLUtil.checkLiteral(reader, "UBLIC")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); publicID = XMLUtil.scanString(reader, '%', this.parameterEntityResolver); XMLUtil.skipWhitespace(reader, null); systemID = XMLUtil.scanString(reader, '%', this.parameterEntityResolver); XMLUtil.skipWhitespace(reader, null); XMLUtil.readChar(reader, '%'); break; case 'S': if (! XMLUtil.checkLiteral(reader, "YSTEM")) { XMLUtil.skipTag(reader); return; } XMLUtil.skipWhitespace(reader, null); systemID = XMLUtil.scanString(reader, '%', this.parameterEntityResolver); XMLUtil.skipWhitespace(reader, null); XMLUtil.readChar(reader, '%'); break; case '"': case '\'': reader.unread(ch); String value = XMLUtil.scanString(reader, '%', this.parameterEntityResolver); entityResolver.addInternalEntity(key, value); XMLUtil.skipWhitespace(reader, null); XMLUtil.readChar(reader, '%'); break; default: XMLUtil.skipTag(reader); } if (systemID != null) { entityResolver.addExternalEntity(key, publicID, systemID); } } /** * Indicates that an element has been started. * * @param name the name of the element. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. */ public void elementStarted(String name, String systemId, int lineNr) { Properties attribs = (Properties) this.attributeDefaultValues.get(name); if (attribs == null) { attribs = new Properties(); } else { attribs = (Properties) attribs.clone(); } this.currentElements.push(attribs); } /** * Indicates that the current element has ended. * * @param name the name of the element. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. */ public void elementEnded(String name, String systemId, int lineNr) { // nothing to do } /** * This method is called when the attributes of an XML element have been * processed. * If there are attributes with a default value which have not been * specified yet, they have to be put into extraAttributes. * * @param name the name of the element. * @param extraAttributes where to put extra attributes. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. */ public void elementAttributesProcessed(String name, Properties extraAttributes, String systemId, int lineNr) { Properties props = (Properties) this.currentElements.pop(); Enumeration enum = props.keys(); while (enum.hasMoreElements()) { String key = (String) enum.nextElement(); extraAttributes.put(key, props.get(key)); } } /** * Indicates that an attribute has been added to the current element. * * @param key the name of the attribute. * @param value the value of the attribute. * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. */ public void attributeAdded(String key, String value, String systemId, int lineNr) { Properties props = (Properties) this.currentElements.peek(); if (props.containsKey(key)) { props.remove(key); } } /** * Indicates that a new #PCDATA element has been encountered. * * @param systemId the system ID of the XML data of the element. * @param lineNr the line number in the XML data of the element. */ public void PCDataAdded(String systemId, int lineNr) { // nothing to do } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/IXMLBuilder.java0000644000175000017500000001755107616770707026125 0ustar sveinungsveinung/* IXMLBuilder.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 net.n3.nanoxml; import java.io.Reader; import java.io.IOException; /** * NanoXML uses IXMLBuilder to construct the XML data structure it retrieved * from its data source. You can supply your own builder or you can use the * default builder of NanoXML. *

* If a method of the builder throws an exception, the parsing is aborted and * {@link net.n3.nanoxml.IXMLParser#parse} throws an * {@link net.n3.nanoxml.XMLException} which encasulates the original * exception. * * @see net.n3.nanoxml.IXMLParser * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ */ public interface IXMLBuilder { /** * 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. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void startBuilding(String systemID, int lineNr) throws Exception; /** * This method is called when a processing instruction is encountered. * A PI with a reserved target ("xml" with any case) is never reported. * * @param target the processing instruction target. * @param reader the method can retrieve the parameter of the PI from this * reader. You may close the reader before reading all its * data and you cannot read too much data. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void newProcessingInstruction(String target, Reader reader) throws Exception; /** * 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. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void startElement(String name, String nsPrefix, String nsURI, String systemID, int lineNr) throws Exception; /** * 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; /** * 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. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void elementAttributesProcessed(String name, String nsPrefix, String nsURI) throws Exception; /** * 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. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void endElement(String name, String nsPrefix, String nsURI) throws Exception; /** * 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 method can retrieve the data from this reader. You * may close the reader before reading all its data and you * cannot read too much data. * @param systemID the system ID of the XML data source. * @param lineNr the line in the source where the element starts. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public void addPCData(Reader reader, String systemID, int lineNr) throws Exception; /** * Returns the result of the building process. This method is called just * before the parse method of IXMLParser returns. * * @see net.n3.nanoxml.IXMLParser#parse * * @return the result of the building process. * * @throws java.lang.Exception * If an exception occurred while processing the event. */ public Object getResult() throws Exception; } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/IXMLParser.java0000644000175000017500000000620107616770707025761 0ustar sveinungsveinung/* IXMLParser.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 net.n3.nanoxml; import java.io.IOException; /** * IXMLParser is the core parser of NanoXML. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ */ public interface IXMLParser { /** * Sets the reader from which the parser retrieves its data. * * @param reader the reader. */ public void setReader(IXMLReader reader); /** * Returns the reader from which the parser retrieves its data. * * @return the reader. */ public IXMLReader getReader(); /** * Sets the builder which creates the logical structure of the XML data. * * @param builder the builder. */ public void setBuilder(IXMLBuilder builder); /** * Returns the builder which creates the logical structure of the XML data. * * @return the builder. */ public IXMLBuilder getBuilder(); /** * Sets the validator that validates the XML data. * * @param validator the validator. */ public void setValidator(IXMLValidator validator); /** * Returns the validator that validates the XML data. * * @return the validator. */ public IXMLValidator getValidator(); /** * Sets the entity resolver. * * @param resolver the non-null resolver. */ public void setResolver(IXMLEntityResolver resolver); /** * Returns the entity resolver. * * @return the non-null resolver. */ public IXMLEntityResolver getResolver(); /** * Parses the data and lets the builder create the logical data structure. * The method returns the result of getResult of the builder. if an * error occurred while reading or parsing the data, the method may throw * an XMLException. * * @see net.n3.nanoxml.IXMLBuilder#getResult * * @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; } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLParserFactory.java0000644000175000017500000001040407616770707027200 0ustar sveinungsveinung/* XMLParserFactory.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 net.n3.nanoxml; import java.io.IOException; /** * Creates an XML parser. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $ */ public class XMLParserFactory { /** * The class name of the default XML parser. */ public static final String DEFAULT_CLASS = "net.n3.nanoxml.StdXMLParser"; /** * The Java properties key of the XML parser class name. */ public static final String CLASS_KEY = "net.n3.nanoxml.XMLParser"; /** * Creates a default parser. * * @see #DEFAULT_CLASS * @see #CLASS_KEY * * @return the non-null parser. * * @throws java.lang.ClassNotFoundException * if the class of the parser or validator could not be found. * @throws java.lang.InstantiationException * if the parser could not be created * @throws java.lang.IllegalAccessException * if the parser could not be created */ public static IXMLParser createDefaultXMLParser() throws ClassNotFoundException, InstantiationException, IllegalAccessException { String className = System.getProperty(XMLParserFactory.CLASS_KEY, XMLParserFactory.DEFAULT_CLASS); return XMLParserFactory.createXMLParser(className, new StdXMLBuilder()); } /** * Creates a default parser. * * @see #DEFAULT_CLASS * @see #CLASS_KEY * * @param builder the XML builder. * * @return the non-null parser. * * @throws java.lang.ClassNotFoundException * if the class of the parser could not be found. * @throws java.lang.InstantiationException * if the parser could not be created * @throws java.lang.IllegalAccessException * if the parser could not be created */ public static IXMLParser createDefaultXMLParser(IXMLBuilder builder) throws ClassNotFoundException, InstantiationException, IllegalAccessException { String className = System.getProperty(XMLParserFactory.CLASS_KEY, XMLParserFactory.DEFAULT_CLASS); return XMLParserFactory.createXMLParser(className, builder); } /** * Creates a parser. * * @param className the name of the class of the XML parser * @param builder the XML builder. * * @return the non-null parser. * * @throws java.lang.ClassNotFoundException * if the class of the parser could not be found. * @throws java.lang.InstantiationException * if the parser could not be created * @throws java.lang.IllegalAccessException * if the parser could not be created */ public static IXMLParser createXMLParser(String className, IXMLBuilder builder) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class cls = Class.forName(className); IXMLParser parser = (IXMLParser) cls.newInstance(); parser.setBuilder(builder); parser.setValidator(new NonValidator()); return parser; } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/IXMLElement.java0000644000175000017500000003250507616770707026124 0ustar sveinungsveinung/* IXMLElement.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 net.n3.nanoxml; import java.io.Serializable; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; import java.util.Vector; /** * IXMLElement is an XML element. It provides an easy to use generic interface * on top of an XML like data structure like e.g. a DOM like structure. * Elements returned by StdXMLBuilder also implement this interface. * * @see net.n3.nanoxml.StdXMLBuilder * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public interface IXMLElement { /** * No line number defined. */ public static final int NO_LINE = -1; /** * Creates an element to be used for #PCDATA content. */ public IXMLElement createPCDataElement(); /** * Creates an empty element. * * @param fullName the name of the element. */ public IXMLElement createElement(String 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 IXMLElement createElement(String fullName, String systemID, int lineNr); /** * Creates an empty element. * * @param fullName the full name of the element * @param namespace the namespace URI. */ public IXMLElement createElement(String fullName, String namespace); /** * 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 IXMLElement createElement(String fullName, String namespace, String systemID, int lineNr); /** * Returns the parent element. This method returns null for the root * element. */ public IXMLElement getParent(); /** * Returns the full name (i.e. the name including an eventual namespace * prefix) of the element. * * @return the name, or null if the element only contains #PCDATA. */ public String getFullName(); /** * Returns the name of the element. * * @return the name, or null if the element only contains #PCDATA. */ public String getName(); /** * Returns the namespace of the element. * * @return the namespace, or null if no namespace is associated with the * element. */ public String getNamespace(); /** * 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); /** * 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); /** * Adds a child element. * * @param child the non-null child to add. */ public void addChild(IXMLElement child); /** * Removes a child element. * * @param child the non-null child to remove. */ public void removeChild(IXMLElement 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 removeChildAtIndex(int index); /** * Returns an enumeration of all child elements. * * @return the non-null enumeration */ public Enumeration enumerateChildren(); /** * Returns whether the element is a leaf element. * * @return true if the element has no children. */ public boolean isLeaf(); /** * Returns whether the element has children. * * @return true if the element has children. */ public boolean hasChildren(); /** * Returns the number of children. * * @return the count. */ public int getChildrenCount(); /** * Returns a vector containing all the child elements. * * @return the vector. */ public Vector getChildren(); /** * 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 IXMLElement getChildAtIndex(int index) throws ArrayIndexOutOfBoundsException; /** * Searches a child element. * * @param name the full name of the child to search for. * * @return the child element, or null if no such child was found. */ public IXMLElement getFirstChildNamed(String name); /** * Searches a child element. * * @param name the name of the child to search for. * @param namespace the namespace, which may be null. * * @return the child element, or null if no such child was found. */ public IXMLElement getFirstChildNamed(String name, String namespace); /** * Returns a vector of all child elements named name. * * @param name the full name of the children to search for. * * @return the non-null vector of child elements. */ public Vector getChildrenNamed(String name); /** * Returns a vector of all child elements named name. * * @param name the name of the children to search for. * @param namespace the namespace, which may be null. * * @return the non-null vector of child elements. */ public Vector getChildrenNamed(String name, String namespace); /** * Returns the number of attributes. */ public int getAttributeCount(); /** * @deprecated As of NanoXML/Java 2.0.1, replaced by * {@link #getAttribute(java.lang.String,java.lang.String)} * 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); /** * 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); /** * 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 String getAttribute(String name, String namespace, String defaultValue); /** * 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 int getAttribute(String name, int 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. */ public int getAttribute(String name, String namespace, int defaultValue); /** * 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); /** * 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); /** * 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); /** * Sets an attribute. * * @param name the non-null full name of the attribute. * @param value the non-null value of the attribute. */ public void setAttribute(String name, String 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); /** * Removes an attribute. * * @param name the non-null name of the attribute. */ public void removeAttribute(String name); /** * 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); /** * Returns an enumeration of all attribute names. * * @return the non-null enumeration. */ public Enumeration enumerateAttributeNames(); /** * Returns whether an attribute exists. * * @param name the non-null name of the attribute. * * @return true if the attribute exists. */ public boolean hasAttribute(String name); /** * Returns whether an attribute exists. * * @param name the non-null name of the attribute. * @param namespace the namespace URI of the attribute, which may be null. * * @return true if the attribute exists. */ public boolean hasAttribute(String name, String namespace); /** * Returns all attributes as a Properties object. * * @return the non-null set. */ public Properties getAttributes(); /** * 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); /** * Returns the system ID of the data where the element started. * * @return the system ID, or null if unknown. * * @see #getLineNr */ public String getSystemID(); /** * 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 getLineNr(); /** * 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. * * @return the content. */ public String getContent(); /** * 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); /** * Returns true if the element equals another element. * * @param rawElement the element to compare to */ public boolean equals(Object rawElement); /** * Returns true if the element equals another element. * * @param rawElement the element to compare to */ public boolean equalsXMLElement(IXMLElement elt); } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLAttribute.java0000644000175000017500000000620207616770707026360 0ustar sveinungsveinung/* 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 net.n3.nanoxml; /** * 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 fullName; /** * The short name of the attribute. */ private String name; /** * 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.fullName = fullName; this.name = name; this.namespace = namespace; this.value = value; this.type = type; } /** * Returns the full name of the attribute. */ String getFullName() { return this.fullName; } /** * Returns the short name of the attribute. */ String getName() { return this.name; } /** * 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; } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/IXMLReader.java0000644000175000017500000001115607616770707025734 0ustar sveinungsveinung/* IXMLReader.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 net.n3.nanoxml; import java.io.Reader; import java.io.IOException; import java.io.FileNotFoundException; import java.net.MalformedURLException; /** * IXMLReader reads the data to be parsed. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public interface IXMLReader { /** * Reads a character. * * @return the character * * @throws java.io.IOException * If no character could be read. */ public char read() throws IOException; /** * 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; /** * 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; /** * 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; /** * Returns the line number of the data in the current stream. */ public int getLineNr(); /** * 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; /** * 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 reader to read the new data from. */ public void startNewStream(Reader reader); /** * 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); /** * Returns the current "level" of the stream on the stack of streams. */ public int getStreamLevel(); /** * 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; /** * Sets the public ID of the current stream. * * @param publicID the public ID. */ public void setPublicID(String publicID); /** * Returns the current system ID. */ public String getSystemID(); /** * Returns the current public ID. */ public String getPublicID(); } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/ContentReader.java0000644000175000017500000001250107616770707026570 0ustar sveinungsveinung/* 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 net.n3.nanoxml; 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 IXMLReader reader; /** * Buffer. */ private String buffer; /** * Pointer into the buffer. */ private int bufferIndex; /** * The entity resolver. */ private IXMLEntityResolver 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(IXMLReader reader, IXMLEntityResolver 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()); } } } libnanoxml2-java-2.2.3.dfsg/Sources/Java/net/n3/nanoxml/XMLUtil.java0000644000175000017500000005712407616770707025343 0ustar sveinungsveinung/* 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 net.n3.nanoxml; import java.io.IOException; import java.io.Reader; import java.io.CharArrayReader; /** * 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(IXMLReader reader) throws IOException, XMLParseException { if (reader.read() != '-') { XMLUtil.errorExpectedInput(reader.getSystemID(), reader.getLineNr(), "