fixes + preliminary html tagsoup support in the tal template engine
authorzapata <zapata>
Sat, 22 Nov 2003 05:09:21 +0000 (05:09 +0000)
committerzapata <zapata>
Sat, 22 Nov 2003 05:09:21 +0000 (05:09 +0000)
lib/README.txt
lib/tagsoup-0.8-zapmod.jar [new file with mode: 0755]
source/mir/generator/tal/TALTemplate.java
source/mir/generator/tal/TALTemplateParser.java
source/mir/generator/tal/TALTest.java
source/mir/util/XMLReader.java

index a1c58aa..a49f9bf 100755 (executable)
@@ -183,4 +183,8 @@ url        :
 description: Extracted from struts 1.0
 todo       : update
 
-
+velocity
+------------------------------------------------
+version    : 1.3.1 
+url        : http://jakarta.apache.org/velocity
+description: template engine
diff --git a/lib/tagsoup-0.8-zapmod.jar b/lib/tagsoup-0.8-zapmod.jar
new file mode 100755 (executable)
index 0000000..bbf18dd
Binary files /dev/null and b/lib/tagsoup-0.8-zapmod.jar differ
index 2b03189..68a2c0e 100755 (executable)
@@ -238,25 +238,6 @@ public class TALTemplate {
           else {\r
             innerProcess(aParser, aContext, aDestination);\r
           }\r
-\r
-          /*\r
-               define\r
-               condition\r
-               repeat\r
-                   attributes\r
-                   content\r
-               OR\r
-                   replace\r
-               OR\r
-                   omit-tag\r
-                   content\r
-           * define\r
-           * condition\r
-           * repeat\r
-           * content\r
-           * attributes\r
-           * omit-tag\r
-           */\r
         }\r
     };\r
 \r
@@ -278,7 +259,7 @@ public class TALTemplate {
         aDestination.append("<");\r
         aDestination.append(tag);\r
 \r
-        i = generatedAttributes.keySet().iterator();\r
+        i = generatedAttributes.entrySet().iterator();\r
         while (i.hasNext()) {\r
           Map.Entry entry = (Map.Entry) i.next();\r
           aDestination.append(" ");\r
index ba73919..a03a4ed 100755 (executable)
@@ -72,6 +72,16 @@ public class TALTemplateParser {
     }\r
   }\r
 \r
+  private static String normalizeXMLName(XMLReader.XMLName aName) {\r
+    String result = aName.getLocalName();\r
+    if (aName.getPrefix().length() > 0)\r
+      result = aName.getPrefix() + ":" + result;\r
+\r
+    return result;\r
+  }\r
+\r
+\r
+\r
   private static final String CONDITION_ATTRIBUTE = "tal:condition";\r
   private static final String REPEAT_ATTRIBUTE = "tal:repeat";\r
   private static final String CONTENT_ATTRIBUTE = "tal:content";\r
@@ -107,9 +117,7 @@ public class TALTemplateParser {
     public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc {\r
       smartTag = false;\r
 \r
-      currentTag = aTag.getLocalName();\r
-      if (aTag.getPrefix().length()>0)\r
-        currentTag = aTag.getPrefix() + ":" + currentTag;\r
+      currentTag = normalizeXMLName(aTag);\r
 \r
       smartTag = (aTag.getPrefix().equals(TAL_PREFIX));\r
 \r
@@ -127,7 +135,7 @@ public class TALTemplateParser {
         while (i.hasNext()) {\r
           Map.Entry entry = (Map.Entry) i.next();\r
 \r
-          appendCode(" "+ (String) entry.getKey());\r
+          appendCode(" "+ normalizeXMLName((XMLReader.XMLName) entry.getKey()));\r
           appendCode("=\"");\r
           appendText((String) entry.getValue());\r
           appendCode("\"");\r
@@ -145,7 +153,7 @@ public class TALTemplateParser {
           XMLReader.XMLName name = (XMLReader.XMLName) entry.getKey();\r
 \r
           if (!name.getPrefix().equals(TAL_PREFIX)) {\r
-            smartNode.addFixedAttribute(name.getLocalName(), (String) entry.getValue());\r
+            smartNode.addFixedAttribute(normalizeXMLName(name), (String) entry.getValue());\r
           }\r
           else {\r
             if (name.getLocalName().equalsIgnoreCase(DEFINITION_ATTRIBUTE)) {\r
index 02e63f8..64d7f85 100755 (executable)
  */\r
 package mir.generator.tal;\r
 \r
-/**\r
- * <p>Title: </p>\r
- * <p>Description: </p>\r
- * <p>Copyright: Copyright (c) 2003</p>\r
- * <p>Company: </p>\r
- * @author not attributable\r
- * @version 1.0\r
- */\r
-\r
 import java.io.PrintWriter;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
@@ -50,7 +41,7 @@ public class TALTest {
       Map test = new HashMap();\r
       test.put("name", "zapata");\r
 \r
-      TALTemplate template = parser.parseString("<html tal:on-error='exception.message'><head></head><body><tal:test tal:content='name'></tal:test><h1 tal:content=\"name.bla\">test</h1></body></html>", expressionParser);\r
+      TALTemplate template = parser.parseString("<td tal:on-error='exception.message'><tal:test tal:content='name.bla'></tal:test><h1 tal:content=\"name\">test</h1></TD>", expressionParser);\r
       PrintWriter o = new PrintWriter(System.out);\r
       template.processTemplate(test, o);\r
       o.close();\r
index a1be97c..3e2f0cb 100755 (executable)
-/*
- * Copyright (C) 2001, 2002 The Mir-coders group
- *
- * This file is part of Mir.
- *
- * Mir is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Mir is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mir; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two.  You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries.  If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
- * If you do not wish to do so, delete this exception statement from your version.
- */
-package mir.util;
-
-import java.io.*;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import multex.Exc;
-import multex.Failure;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-public class XMLReader {
-  private Locator locator;
-  private String filename;
-  private boolean namespaceAware;
-
-  public XMLReader() {
-    this(false);
-  }
-
-  public XMLReader(boolean aNameSpaceAware) {
-    namespaceAware = aNameSpaceAware;
-    filename="";
-  }
-
-  public void parseString(String aString, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {
-    try {
-      parseInputSource(new InputSource(new StringReader(aString)), aRootHandler);
-    }
-    catch (Throwable t) {
-      throw new XMLReaderFailure(t);
-    }
-  }
-
-  public void parseFile(String aFileName, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {
-    filename= aFileName;
-    try {
-      parseInputStream(new FileInputStream(aFileName), aRootHandler);
-    }
-    catch (Throwable t) {
-      throw new XMLReaderFailure(t);
-    }
-  }
-
-  public void parseInputStream(InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {
-    parseInputSource(new InputSource(anInputStream), aRootHandler);
-  }
-
-  public void parseInputSource(InputSource anInputSource, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {
-    try {
-      SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-
-      parserFactory.setNamespaceAware(true);
-      parserFactory.setValidating(true);
-
-      XMLReaderHandler handler = new XMLReaderHandler(parserFactory, aRootHandler);
-
-      handler.processInputSource(anInputSource);
-    }
-    catch (Throwable e) {
-      Throwable t = ExceptionFunctions.traceCauseException(e);
-
-      if (t instanceof XMLReaderExc) {
-        throw (XMLReaderExc) t;
-      }
-
-      if (t instanceof XMLReaderFailure) {
-        throw (XMLReaderFailure) t;
-      }
-
-      throw new XMLReaderFailure(t);
-    }
-  }
-  private class XMLReaderHandler extends DefaultHandler {
-    private SAXParserFactory parserFactory;
-    private SectionsManager manager;
-
-    public XMLReaderHandler(SAXParserFactory aParserFactory, SectionHandler aRootHandler) {
-      super();
-
-      parserFactory=aParserFactory;
-      manager = new SectionsManager();
-      manager.pushHandler(aRootHandler);
-   }
-
-    public void setDocumentLocator(Locator aLocator) {
-      locator=aLocator;
-    }
-
-    private void processInputSource(InputSource anInputSource) throws XMLReaderExc, XMLReaderFailure {
-      try {
-        SAXParser parser=parserFactory.newSAXParser();
-
-        parser.parse(anInputSource, this);
-      }
-      catch (Throwable e) {
-        Throwable t = ExceptionFunctions.traceCauseException(e);
-
-        if (t instanceof XMLReaderExc) {
-          if (locator!=null && filename!=null)
-            ((XMLReaderExc) t).setLocation(filename, locator.getLineNumber(), locator.getColumnNumber());
-          throw (XMLReaderExc) t;
-        }
-
-        if (t instanceof SAXParseException) {
-          XMLReaderExc r = new XMLReaderExc(t.getMessage());
-
-          if (locator!=null && filename!=null)
-            r.setLocation(filename, locator.getLineNumber(), locator.getColumnNumber());
-
-          throw r;
-        }
-
-        if (t instanceof XMLReaderFailure) {
-          throw (XMLReaderFailure) t;
-        }
-
-        if (t instanceof ParserConfigurationException) {
-          throw new XMLReaderFailure("Internal exception: "+t.toString(), t);
-        }
-
-        throw new XMLReaderFailure(t);
-      }
-    }
-
-    public void startElement(String aUri, String aLocalName, String aQualifiedName, Attributes anAttributes) throws SAXException {
-      Map attributesMap;
-      int i;
-
-      try {
-        attributesMap = new HashMap();
-
-//        if (namespaceAware)
-          for (i=0; i<anAttributes.getLength(); i++)
-            attributesMap.put(new XMLName(anAttributes.getURI(i), XMLReaderTool.getNameSpaceFromQualifiedName(anAttributes.getQName(i)), anAttributes.getLocalName(i)), anAttributes.getValue(i));
-/*        else
-          for (i=0; i<anAttributes.getLength(); i++)
-            attributesMap.put(anAttributes.getLocalName(i), anAttributes.getValue(i));
-*/
-
-        SectionHandler handler = manager.currentHandler().startElement(new XMLName(aUri, XMLReaderTool.getNameSpaceFromQualifiedName(aQualifiedName), aLocalName), attributesMap);
-
-        manager.pushHandler( handler );
-      }
-      catch (XMLReaderExc e) {
-        throw new SAXParseException(e.getMessage(), null, e);
-      }
-      catch (Exception e) {
-        throw new SAXException(e);
-      }
-    }
-
-    public void endElement(String aUri, String aLocalName, String aQualifiedName) throws SAXException {
-      try
-      {
-        if (!aQualifiedName.equals("include")) {
-          SectionHandler handler = manager.popHandler();
-
-          handler.finishSection();
-
-          if (!manager.isEmpty()) {
-            manager.currentHandler().endElement(handler);
-          }
-        }
-      }
-      catch (XMLReaderExc e) {
-        throw new SAXParseException(e.getMessage(), null, e);
-      }
-      catch (Exception e) {
-        throw new SAXException(e);
-      }
-    }
-
-    public void characters(char[] aBuffer, int aStart, int anEnd) throws SAXException {
-      try {
-        String text = new String(aBuffer, aStart, anEnd);
-
-        manager.currentHandler().characters(text);
-      }
-      catch (XMLReaderExc e) {
-        throw new SAXParseException(e.getMessage(), null, e);
-      }
-      catch (Exception e) {
-        throw new SAXException(e);
-      }
-    }
-  }
-
-  private class SectionsManager {
-    Stack handlerStack;
-
-    public SectionsManager() {
-      handlerStack = new Stack();
-    }
-
-    public void pushHandler(SectionHandler aSectionHandler) {
-      handlerStack.push(aSectionHandler);
-    }
-
-    public SectionHandler popHandler() {
-      return (SectionHandler) handlerStack.pop();
-    }
-
-    public SectionHandler currentHandler() {
-      return (SectionHandler) handlerStack.peek();
-    }
-
-    public boolean isEmpty() {
-      return handlerStack.isEmpty();
-    }
-  }
-
-  public static interface SectionHandler {
-    public abstract SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc;
-
-    public abstract void endElement(SectionHandler aHandler) throws XMLReaderExc;
-
-    public void characters(String aCharacters) throws XMLReaderExc;
-
-    public void finishSection() throws XMLReaderExc;
-  }
-
-  public static abstract class AbstractSectionHandler implements SectionHandler {
-    public SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc {
-      return startElement(aTag.getLocalName(), anAttributes);
-    };
-
-    public SectionHandler startElement(String aLocalName, Map anAttributes) throws XMLReaderExc {
-      return null;
-    };
-
-    public void endElement(SectionHandler aHandler) throws XMLReaderExc {
-    };
-
-    public void finishSection() throws XMLReaderExc {
-    }
-
-    public void characters(String aCharacters) throws XMLReaderExc {
-      if ( aCharacters.trim().length() > 0) {
-        throw new XMLReaderExc("Text not allowed");
-      }
-    }
-  }
-
-  public static class XMLReaderExc extends Exc {
-    private boolean hasLocation;
-    private String filename;
-    private int lineNr;
-    private int columnNr;
-
-    public XMLReaderExc(String aMessage) {
-      super(aMessage);
-      hasLocation = false;
-    }
-
-    protected void setLocation(String aFilename, int aLineNr, int aColumnNr) {
-      filename = aFilename;
-      lineNr = aLineNr;
-      columnNr = aColumnNr;
-      hasLocation = true;
-    }
-
-    public boolean getHasLocation() {
-      return hasLocation;
-    }
-
-    public int getLineNr() {
-      return lineNr;
-    }
-
-    public int getColumnNr() {
-      return columnNr;
-    }
-
-    public String getFilename() {
-      return filename;
-    }
-  }
-
-  public static class XMLReaderFailure extends Failure {
-    public XMLReaderFailure(String aMessage, Throwable aCause) {
-      super(aMessage, aCause);
-    }
-
-    public XMLReaderFailure(Throwable aCause) {
-      super(aCause.getMessage(), aCause);
-    }
-  }
-
-  public static class XMLName {
-    private String namespaceURI;
-    private String localName;
-    private String prefix;
-
-    public XMLName(String aLocalName) {
-      this(null, null, aLocalName);
-    }
-
-    public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) {
-      localName="";
-      prefix="";
-      namespaceURI="";
-
-      if (aLocalName!=null)
-        localName = aLocalName;
-      if (aPrefix!=null)
-        prefix = aPrefix;
-      if (aNamespaceURI!=null)
-        namespaceURI = aNamespaceURI;
-    }
-
-    public XMLName(String aNamespaceURI, String aLocalName) {
-      this (aNamespaceURI, null, aLocalName);
-    }
-
-    public String getNamespaceURI() {
-      return namespaceURI;
-    }
-
-    public String getLocalName() {
-      return localName;
-    }
-
-    public String getPrefix() {
-      return prefix;
-    }
-
-    public int hashCode() {
-      if (namespaceURI == null)
-        return localName.hashCode() + 3*prefix.hashCode();
-      else
-        return localName.hashCode() + 3*namespaceURI.hashCode();
-    }
-
-    public String toString() {
-      return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName;
-    }
-
-    public boolean equals(Object anObject) {
-      if (anObject instanceof XMLName) {
-        if (namespaceURI==null)
-          return (((XMLName) anObject).namespaceURI == null) &&
-                 prefix.equals(((XMLName) anObject).prefix) &&
-                 localName.equals(((XMLName) anObject).localName);
-        else
-          return namespaceURI.equals(((XMLName) anObject).namespaceURI) &&
-                 localName.equals(((XMLName) anObject).localName);
-      }
-      else
-        return false;
-    }
-  }
-
+/*\r
+ * Copyright (C) 2001, 2002 The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with  any library licensed under the Apache Software License,\r
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
+ * (or with modified versions of the above that use the same license as the above),\r
+ * and distribute linked combinations including the two.  You must obey the\r
+ * GNU General Public License in all respects for all of the code used other than\r
+ * the above mentioned libraries.  If you modify this file, you may extend this\r
+ * exception to your version of the file, but you are not obligated to do so.\r
+ * If you do not wish to do so, delete this exception statement from your version.\r
+ */\r
+package mir.util;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.InputStream;\r
+import java.io.StringReader;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Stack;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+import javax.xml.parsers.SAXParser;\r
+import javax.xml.parsers.SAXParserFactory;\r
+\r
+import org.ccil.cowan.tagsoup.Parser;\r
+import org.xml.sax.Attributes;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.Locator;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.SAXParseException;\r
+import org.xml.sax.helpers.DefaultHandler;\r
+import multex.Exc;\r
+import multex.Failure;\r
+\r
+public class XMLReader {\r
+  private Locator locator;\r
+  private String filename;\r
+  private boolean namespaceAware;\r
+\r
+  public XMLReader() {\r
+    this(false);\r
+  }\r
+\r
+  public XMLReader(boolean aNameSpaceAware) {\r
+    namespaceAware = aNameSpaceAware;\r
+    filename="";\r
+  }\r
+\r
+  public void parseString(String aString, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    try {\r
+      parseInputSource(new InputSource(new StringReader(aString)), aRootHandler);\r
+    }\r
+    catch (Throwable t) {\r
+      throw new XMLReaderFailure(t);\r
+    }\r
+  }\r
+\r
+  public void parseString(boolean aTagSoup, String aString, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    try {\r
+      parseInputSource(aTagSoup, new InputSource(new StringReader(aString)), aRootHandler);\r
+    }\r
+    catch (Throwable t) {\r
+      throw new XMLReaderFailure(t);\r
+    }\r
+  }\r
+\r
+  public void parseFile(String aFileName, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    filename= aFileName;\r
+    try {\r
+      parseInputStream(new FileInputStream(aFileName), aRootHandler);\r
+    }\r
+    catch (Throwable t) {\r
+      throw new XMLReaderFailure(t);\r
+    }\r
+  }\r
+\r
+  public void parseInputStream(InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    parseInputSource(new InputSource(anInputStream), aRootHandler);\r
+  }\r
+\r
+  public void parseInputStream(boolean aTagSoup, InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    parseInputSource(aTagSoup, new InputSource(anInputStream), aRootHandler);\r
+  }\r
+\r
+  public void parseInputSource(InputSource anInputSource, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    try {\r
+      parseInputSource(false, anInputSource, aRootHandler);\r
+    }\r
+    catch (Throwable e) {\r
+      Throwable t = ExceptionFunctions.traceCauseException(e);\r
+\r
+      if (t instanceof XMLReaderExc) {\r
+        throw (XMLReaderExc) t;\r
+      }\r
+\r
+      if (t instanceof XMLReaderFailure) {\r
+        throw (XMLReaderFailure) t;\r
+      }\r
+\r
+      throw new XMLReaderFailure(t);\r
+    }\r
+  }\r
+\r
+  public void parseInputSource(boolean aTagSoup, InputSource anInputSource, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc {\r
+    try {\r
+      XMLReaderHandler handler = new XMLReaderHandler(aRootHandler);\r
+\r
+      if (aTagSoup) {\r
+        org.ccil.cowan.tagsoup.Parser parser = new Parser();\r
+        parser.setContentHandler(handler);\r
+        parser.setDTDHandler(handler);\r
+        parser.parse(anInputSource);\r
+      }\r
+      else {\r
+        SAXParserFactory parserFactory = SAXParserFactory.newInstance();\r
+\r
+        parserFactory.setNamespaceAware(true);\r
+        parserFactory.setValidating(true);\r
+        SAXParser parser = parserFactory.newSAXParser();\r
+\r
+        parser.parse(anInputSource, handler);\r
+      }\r
+    }\r
+    catch (Throwable e) {\r
+      Throwable t = ExceptionFunctions.traceCauseException(e);\r
+\r
+      if (t instanceof XMLReaderExc) {\r
+        throw (XMLReaderExc) t;\r
+      }\r
+\r
+      if (t instanceof XMLReaderFailure) {\r
+        throw (XMLReaderFailure) t;\r
+      }\r
+\r
+      if (t instanceof XMLReaderExc) {\r
+        if (locator!=null && filename!=null)\r
+          ((XMLReaderExc) t).setLocation(filename, locator.getLineNumber(), locator.getColumnNumber());\r
+        throw (XMLReaderExc) t;\r
+      }\r
+\r
+      if (t instanceof SAXParseException) {\r
+        XMLReaderExc r = new XMLReaderExc(t.getMessage());\r
+\r
+        if (locator!=null && filename!=null)\r
+          r.setLocation(filename, locator.getLineNumber(), locator.getColumnNumber());\r
+\r
+        throw r;\r
+      }\r
+\r
+      if (t instanceof XMLReaderFailure) {\r
+        throw (XMLReaderFailure) t;\r
+      }\r
+\r
+      if (t instanceof ParserConfigurationException) {\r
+        throw new XMLReaderFailure("Internal exception: "+t.toString(), t);\r
+      }\r
+\r
+      throw new XMLReaderFailure(t);\r
+    }\r
+  }\r
+  private class XMLReaderHandler extends DefaultHandler {\r
+    private SectionsManager manager;\r
+\r
+    public XMLReaderHandler(SectionHandler aRootHandler) {\r
+      super();\r
+\r
+      manager = new SectionsManager();\r
+      manager.pushHandler(aRootHandler);\r
+   }\r
+\r
+    public void setDocumentLocator(Locator aLocator) {\r
+      locator=aLocator;\r
+    }\r
+\r
+    public void startElement(String aUri, String aLocalName, String aQualifiedName, Attributes anAttributes) throws SAXException {\r
+      Map attributesMap;\r
+      int i;\r
+\r
+      try {\r
+        attributesMap = new HashMap();\r
+\r
+        if (namespaceAware)\r
+          for (i=0; i<anAttributes.getLength(); i++)\r
+            attributesMap.put(new XMLName(anAttributes.getURI(i), XMLReaderTool.getNameSpaceFromQualifiedName(anAttributes.getQName(i)), anAttributes.getLocalName(i)), anAttributes.getValue(i));\r
+        else\r
+          for (i=0; i<anAttributes.getLength(); i++)\r
+            attributesMap.put(anAttributes.getLocalName(i), anAttributes.getValue(i));\r
+\r
+        SectionHandler handler = manager.currentHandler().startElement(new XMLName(aUri, XMLReaderTool.getNameSpaceFromQualifiedName(aQualifiedName), aLocalName), attributesMap);\r
+\r
+        manager.pushHandler( handler );\r
+      }\r
+      catch (XMLReaderExc e) {\r
+        throw new SAXParseException(e.getMessage(), null, e);\r
+      }\r
+      catch (Exception e) {\r
+        throw new SAXException(e);\r
+      }\r
+    }\r
+\r
+    public void endElement(String aUri, String aLocalName, String aQualifiedName) throws SAXException {\r
+      try\r
+      {\r
+        SectionHandler handler = manager.popHandler();\r
+\r
+        handler.finishSection();\r
+\r
+        if (!manager.isEmpty()) {\r
+          manager.currentHandler().endElement(handler);\r
+        }\r
+      }\r
+      catch (XMLReaderExc e) {\r
+        throw new SAXParseException(e.getMessage(), null, e);\r
+      }\r
+      catch (Exception e) {\r
+        throw new SAXException(e);\r
+      }\r
+    }\r
+\r
+    public void endDocument() throws SAXException {\r
+      try\r
+      {\r
+        SectionHandler handler = manager.popHandler();\r
+\r
+        handler.finishSection();\r
+      }\r
+      catch (XMLReaderExc e) {\r
+        throw new SAXParseException(e.getMessage(), null, e);\r
+      }\r
+      catch (Exception e) {\r
+        throw new SAXException(e);\r
+      }\r
+    }\r
+\r
+    public void characters(char[] aBuffer, int aStart, int anEnd) throws SAXException {\r
+      try {\r
+        String text = new String(aBuffer, aStart, anEnd);\r
+\r
+        manager.currentHandler().characters(text);\r
+      }\r
+      catch (XMLReaderExc e) {\r
+        throw new SAXParseException(e.getMessage(), null, e);\r
+      }\r
+      catch (Exception e) {\r
+        throw new SAXException(e);\r
+      }\r
+    }\r
+  }\r
+\r
+  private class SectionsManager {\r
+    Stack handlerStack;\r
+\r
+    public SectionsManager() {\r
+      handlerStack = new Stack();\r
+    }\r
+\r
+    public void pushHandler(SectionHandler aSectionHandler) {\r
+      handlerStack.push(aSectionHandler);\r
+    }\r
+\r
+    public SectionHandler popHandler() {\r
+      return (SectionHandler) handlerStack.pop();\r
+    }\r
+\r
+    public SectionHandler currentHandler() {\r
+      return (SectionHandler) handlerStack.peek();\r
+    }\r
+\r
+    public boolean isEmpty() {\r
+      return handlerStack.isEmpty();\r
+    }\r
+  }\r
+\r
+  public static interface SectionHandler {\r
+    public abstract SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc;\r
+\r
+    public abstract void endElement(SectionHandler aHandler) throws XMLReaderExc;\r
+\r
+    public void characters(String aCharacters) throws XMLReaderExc;\r
+\r
+    public void finishSection() throws XMLReaderExc;\r
+  }\r
+\r
+  public static abstract class AbstractSectionHandler implements SectionHandler {\r
+    public SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc {\r
+      return startElement(aTag.getLocalName(), anAttributes);\r
+    };\r
+\r
+    public SectionHandler startElement(String aLocalName, Map anAttributes) throws XMLReaderExc {\r
+      return null;\r
+    };\r
+\r
+    public void endElement(SectionHandler aHandler) throws XMLReaderExc {\r
+    };\r
+\r
+    public void finishSection() throws XMLReaderExc {\r
+    }\r
+\r
+    public void characters(String aCharacters) throws XMLReaderExc {\r
+      if ( aCharacters.trim().length() > 0) {\r
+        throw new XMLReaderExc("Text not allowed");\r
+      }\r
+    }\r
+  }\r
+\r
+  public static class XMLReaderExc extends Exc {\r
+    private boolean hasLocation;\r
+    private String filename;\r
+    private int lineNr;\r
+    private int columnNr;\r
+\r
+    public XMLReaderExc(String aMessage) {\r
+      super(aMessage);\r
+      hasLocation = false;\r
+    }\r
+\r
+    protected void setLocation(String aFilename, int aLineNr, int aColumnNr) {\r
+      filename = aFilename;\r
+      lineNr = aLineNr;\r
+      columnNr = aColumnNr;\r
+      hasLocation = true;\r
+    }\r
+\r
+    public boolean getHasLocation() {\r
+      return hasLocation;\r
+    }\r
+\r
+    public int getLineNr() {\r
+      return lineNr;\r
+    }\r
+\r
+    public int getColumnNr() {\r
+      return columnNr;\r
+    }\r
+\r
+    public String getFilename() {\r
+      return filename;\r
+    }\r
+  }\r
+\r
+  public static class XMLReaderFailure extends Failure {\r
+    public XMLReaderFailure(String aMessage, Throwable aCause) {\r
+      super(aMessage, aCause);\r
+    }\r
+\r
+    public XMLReaderFailure(Throwable aCause) {\r
+      super(aCause.getMessage(), aCause);\r
+    }\r
+  }\r
+\r
+  public static class XMLName {\r
+    private String namespaceURI;\r
+    private String localName;\r
+    private String prefix;\r
+\r
+    public XMLName(String aLocalName) {\r
+      this(null, null, aLocalName);\r
+    }\r
+\r
+    public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) {\r
+      localName="";\r
+      prefix="";\r
+      namespaceURI="";\r
+\r
+      if (aLocalName!=null)\r
+        localName = aLocalName;\r
+      if (aPrefix!=null)\r
+        prefix = aPrefix;\r
+      if (aNamespaceURI!=null)\r
+        namespaceURI = aNamespaceURI;\r
+    }\r
+\r
+    public XMLName(String aNamespaceURI, String aLocalName) {\r
+      this (aNamespaceURI, null, aLocalName);\r
+    }\r
+\r
+    public String getNamespaceURI() {\r
+      return namespaceURI;\r
+    }\r
+\r
+    public String getLocalName() {\r
+      return localName;\r
+    }\r
+\r
+    public String getPrefix() {\r
+      return prefix;\r
+    }\r
+\r
+    public int hashCode() {\r
+      if (namespaceURI == null)\r
+        return localName.hashCode() + 3*prefix.hashCode();\r
+      else\r
+        return localName.hashCode() + 3*namespaceURI.hashCode();\r
+    }\r
+\r
+    public String toString() {\r
+      return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName;\r
+    }\r
+\r
+    public boolean equals(Object anObject) {\r
+      if (anObject instanceof XMLName) {\r
+        if (namespaceURI==null)\r
+          return (((XMLName) anObject).namespaceURI == null) &&\r
+                 prefix.equals(((XMLName) anObject).prefix) &&\r
+                 localName.equals(((XMLName) anObject).localName);\r
+        else\r
+          return namespaceURI.equals(((XMLName) anObject).namespaceURI) &&\r
+                 localName.equals(((XMLName) anObject).localName);\r
+      }\r
+      else\r
+        return false;\r
+    }\r
+  }\r
+\r
 }
\ No newline at end of file