Or you create an instance, register the TagListeners and use the getParser() - * method to create a Parser. Then start parsing by calling it's parse() method. - */ - -public class TagHandler extends HandlerBase { - - /** - * The current active level - */ - private int level; - - /** - * cache used to handle nesting of tags - */ - private List contents; - - /** - * cache used to handle nesting of tags - */ - private List tags; - - /** - * cache used to handle nesting of tags - */ - private List args; - - // Current active content writer - private CharArrayWriter content; - - // List of TagListener's who want to be fed data - private HashSet tagListeners; - - /** - * default constructor - */ - public TagHandler() { - level=0; - contents = new ArrayList(); - tags = new ArrayList(); - args = new ArrayList(); - tagListeners = new HashSet(); - } - - /** - * Called by SAX when a tag is begun. This simply creates a new level in the - * cache and stores the parameters and tag name in there. - */ - public void startElement(String p0, AttributeList p1) throws SAXException { - - // Now move up and fetch a CharArrayWriter from the cache - // creating if this is the first time at this level - if(contents.size()<=level) { - contents.add(new CharArrayWriter()); - tags.add(p0); - args.add(new HashMap()); - } - - content=(CharArrayWriter) contents.get(level); - content.reset(); - - // Also cache the tag's text and argument list - tags.set(level,p0); - - HashMap h = (HashMap) args.get(level); - h.clear(); - for(int i=p1.getLength()-1;i>-1;i--) { - h.put(p1.getName(i),p1.getValue(i)); - } - - // Now notify any TagListeners - Iterator it = tagListeners.iterator(); - while(it.hasNext()) - ( (TagListener) it.next() ).tagStart(level,p0,h); - - // Now move up a level - level++; - } - - /** - * This is called by SAX at the end of a tag. This calls handleTag() and then - * raises the level, so that the previous parent tag may continue. - */ - public void endElement(String p0) throws SAXException { - // move up a level retrieving that level's current content - // Now this exception should never occur as the underlying parser should - // actually trap it. - if(level<1) - throw new SAXException("Already at top level?"); - level--; - - // Now notify any TagListeners - Iterator it = tagListeners.iterator(); - while(it.hasNext()) - ( (TagListener) it.next() ).tagContent(content); - - // allows large content to be released early - content.reset(); - - // Now reset content to the previous level - content=(CharArrayWriter) contents.get(level); - } - - /** - * Called by SAX so that content between the start and end tags are captured. - */ - public void characters(char[] p0, int p1, int p2) throws SAXException { - content.write(p0,p1,p2); - } - - /** - * Adds a TagListener so that it is notified of tags as they are processed. - * @param handler TagListener to add - */ - public void addTagListener(TagListener h) { - tagListeners.add(h); - } - - /** - * Removes the TagListener so it no longer receives notifications of tags - */ - public void removeTagListener(TagListener h) { - tagListeners.remove(h); - } - - /** - * This method returns a org.xml.sax.Parser object that will parse the - * contents of a URI. - * - *
Normally you would call this method, then call the parse(uri) method of - * the returned object. - * @return org.xml.sax.Parser object - */ - public Parser getParser() - throws SAXException - { - try { - SAXParserFactory spf = SAXParserFactory.newInstance(); - - String validation = System.getProperty ("javax.xml.parsers.validation", "false"); - if (validation.equalsIgnoreCase("true")) - spf.setValidating (true); - - SAXParser sp = spf.newSAXParser(); - Parser parser = sp.getParser (); - - parser.setDocumentHandler(this); - - return(parser); - } catch(ParserConfigurationException pce) { - throw new SAXException(pce.toString()); - } - } - - /** - * This method will parse the specified URI. - * - *
Internally this is the same as getParser().parse(uri); - * @param uri The URI to parse - */ - public void parse(String uri) - throws IOException, SAXException - { - getParser().parse(uri); - } - - /** - * This method will parse the specified InputSource. - * - *
Internally this is the same as getParser().parse(is); - * @param is The InputSource to parse - */ - public void parse(InputSource is) - throws IOException, SAXException - { - getParser().parse(is); - } - -} \ No newline at end of file diff --git a/contrib/retep/uk/org/retep/xml/parser/TagListener.java b/contrib/retep/uk/org/retep/xml/parser/TagListener.java deleted file mode 100644 index 24146b3e245..00000000000 --- a/contrib/retep/uk/org/retep/xml/parser/TagListener.java +++ /dev/null @@ -1,30 +0,0 @@ -package uk.org.retep.xml.parser; - -import java.util.HashMap; -import java.io.CharArrayWriter; - -/** - * This interface defines the methods a class needs to implement if it wants the - * xml parser to notify it of any xml tags. - */ - -public interface TagListener { - /** - * This is called when a tag has just been started. - *
NB: args is volatile, so if you use it beyond the lifetime of - * this call, then you must make a copy of the HashMap (and not use simply - * store this HashMap). - * @param level The number of tags above this - * @param tag The tag name - * @param args A HashMap of any arguments - */ - public void tagStart(int level,String tag,HashMap args); - /** - * This method is called by ContHandler to process a tag once it has been - * fully processed. - *
NB: content is volatile, so you must copy its contents if you use
- * it beyond the lifetime of this call.
- * @param content CharArrayWriter containing the content of the tag.
- */
- public void tagContent(CharArrayWriter content);
-}
\ No newline at end of file
diff --git a/contrib/retep/uk/org/retep/xml/test/XMLExport.java b/contrib/retep/uk/org/retep/xml/test/XMLExport.java
deleted file mode 100644
index 116f2509060..00000000000
--- a/contrib/retep/uk/org/retep/xml/test/XMLExport.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package uk.org.retep.xml.test;
-
-import java.lang.Exception;
-import java.io.*;
-import java.sql.*;
-import java.util.Properties;
-import uk.org.retep.xml.core.XMLFactoryException;
-import uk.org.retep.xml.jdbc.XMLDatabase;
-import uk.org.retep.xml.jdbc.XMLResultSet;
-
-/**
- * This "test" class is a fully functional tool in its own right. It utilises
- * the xml classes to query and export to XML, or to dump database structures
- * into XML.
- */
-
-public class XMLExport
-{
- /**
- * The current Database Connection
- */
- protected Connection conn;
- protected Statement stat;
- protected String drvr,url,table;
-
- protected XMLResultSet xrs;
- protected XMLDatabase xdb;
- protected Properties prop;
- protected boolean outXML;
- protected boolean outDTD;
- protected boolean outTAB;
- protected int maxRows=0;
-
- public XMLExport(String[] args)
- throws IOException,SQLException,XMLFactoryException,ClassNotFoundException
- {
- xrs = new XMLResultSet();
- xrs.setWriter(new OutputStreamWriter(System.out));
- //Properties p = new Properties(xrs.getDefaultProperties());
- prop = (Properties) xrs.getDefaultProperties().clone();
-
- xdb = new XMLDatabase(xrs.getXMLFactory());
-
- for(int i=0;i