Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /tada-sax/src/se/tada/util/sax/

tada-sax
Discussion topic

Back to topic list

CVS update: /tada-sax/src/se/tada/util/sax/

Reply

Author thhal
Full name Thomas Hallgren
Date 2005-11-11 08:14:01 PST
Message User: thhal
Date: 2005/11/11 08:14:01

Modified:
   tada-sax/src/se/tada​/util/sax/ChildHandl​er.java
   tada-sax/src/se/tada​/util/sax/AbstractHa​ndler.java

Log:
 Added prefix mapping capabilities.

File Changes:

Directory: /tada-sax/src/se/tada/util/sax/
====================​====================​==

File [changed]: ChildHandler.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/ChildHand​ler.java?r1=1.6&​r2=1.7
Delta lines: +7 -0
-------------------
--- ChildHandler.java 11 Nov 2005 15:24:03 -0000 1.6
+++ ChildHandler.java 11 Nov 2005 16:13:50 -0000 1.7
@@ -80,6 +80,13 @@
         this.popHandler();
     }
 
+ @Override
+ public String getPrefixMapping(String prefix)
+ {
+ String uri = super.getPrefixMapping(prefix);
+ return uri == null ? this.getParentHandle​r().getPrefixMapping​(prefix) : uri;
+ }
+
     /**
      * Obtain a new or cached handler that corresponds to the <code>uri</code>
      * and <code>localNam​e</code>.

File [changed]: AbstractHandler.java
Url: http://tada-sax.tigr​is.org/source/browse​/tada-sax/src/se/tad​a/util/sax/AbstractH​andler.java?r1=1.2​&r2=1.3
Delta lines: +112 -65
----------------------
--- AbstractHandler.java 26 Jan 2005 11:31:07 -0000 1.2
+++ AbstractHandler.java 11 Nov 2005 16:13:50 -0000 1.3
@@ -6,26 +6,30 @@
  */
 package se.tada.util.sax;
 
+import java.util.HashMap;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 import org.xml.sax.helpers.​DefaultHandler;
 
 /**
- * This handler is the subclass of all handlers in the
- * Tada SAX parser system. It provides utility methods
- * to extract attribute values.
+ * This handler is the subclass of all handlers in the Tada SAX parser system.
+ * It provides utility methods to extract attribute values.
  *
  * @author Thomas Hallgren
  */
 public abstract class AbstractHandler extends DefaultHandler
 {
+ private HashMap<String, String> m_prefixMappings;
+
     protected abstract Locator getDocumentLocator();
 
     /**
- * Returns the name of the element for which this class
- * is a handler. In essence, this method returns the
- * value of the static variable <code>TAG</code> declared
- * for the class of the instance that receives the call.
+ * Returns the name of the element for which this class is a handler. In
+ * essence, this method returns the value of the static variable
+ * <code>TAG</code> declared for the class of the instance that receives
+ * the call.
      *
      * @return The element name.
      */
@@ -36,8 +40,10 @@
      * greater then zero. This method returns the <code>null</code> if the
      * attribute does not exist or if it consists entirely of whitespace.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
      */
     public static final String getOptionalStringVal​ue(Attributes attrs, String qName)
@@ -54,12 +60,15 @@
 
     /**
      * Returns an attribute that is trimmed from whitespace and with a length
- * greater then zero. This method returns the <code>defaultV​alue</code> if the
- * attribute does not exist or if it consists entirely of whitespace.
+ * greater then zero. This method returns the <code>defaultV​alue</code> if
+ * the attribute does not exist or if it consists entirely of whitespace.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
- * @param defaultValue The value to be returned if the attribute is not set.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
+ * @param defaultValue
+ * The value to be returned if the attribute is not set.
      * @return The value of the attribute or <code>defaultV​alue</code>.
      */
     public static final String getOptionalStringVal​ue(Attributes attrs, String qName, String defaultValue)
@@ -70,14 +79,17 @@
         return value;
     }
 
-
     /**
- * Returns an boolean value. This method returns the <code>defaultV​alue</code> if the
- * attribute does not exist or if it consists entirely of whitespace.
- *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
- * @param defaultValue The value to be returned if the attribute is not set.
+ * Returns an boolean value. This method returns the
+ * <code>defaultV​alue</code> if the attribute does not exist or if it
+ * consists entirely of whitespace.
+ *
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
+ * @param defaultValue
+ * The value to be returned if the attribute is not set.
      * @return The value of the attribute or <code>defaultV​alue</code>.
      */
     public static boolean getOptionalBooleanVa​lue(Attributes attrs, String qName, boolean defaultValue)
@@ -94,12 +106,15 @@
     }
 
     /**
- * Returns an long value. This method returns the <code>defaultV​alue</code> if the
- * attribute does not exist or if it consists entirely of whitespace.
+ * Returns an long value. This method returns the <code>defaultV​alue</code>
+ * if the attribute does not exist or if it consists entirely of whitespace.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
- * @param defaultValue The value to be returned if the attribute is not set.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
+ * @param defaultValue
+ * The value to be returned if the attribute is not set.
      * @return The value of the attribute or <code>defaultV​alue</code>.
      */
     public static final double getOptionalDoubleVal​ue(Attributes attrs, String qName, double defaultValue)
@@ -109,12 +124,15 @@
     }
 
     /**
- * Returns an long value. This method returns the <code>defaultV​alue</code> if the
- * attribute does not exist or if it consists entirely of whitespace.
+ * Returns an long value. This method returns the <code>defaultV​alue</code>
+ * if the attribute does not exist or if it consists entirely of whitespace.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
- * @param defaultValue The value to be returned if the attribute is not set.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
+ * @param defaultValue
+ * The value to be returned if the attribute is not set.
      * @return The value of the attribute or <code>defaultV​alue</code>.
      */
     public static final long getOptionalLongValue(Attributes attrs, String qName, long defaultValue)
@@ -124,11 +142,13 @@
     }
 
     /**
- * Returns an long value. This method returns the <code>defaultV​alue</code> if the
- * attribute does not exist or if it consists entirely of whitespace.
+ * Returns an long value. This method returns the <code>defaultV​alue</code>
+ * if the attribute does not exist or if it consists entirely of whitespace.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>defaultV​alue</code>.
      */
     public static final int getOptionalIntValue(Attributes attrs, String qName, int defaultValue)
@@ -141,32 +161,35 @@
      * Returns an attribute that is trimmed from whitespace and with a length
      * greater then zero.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
- * @throws MissingRequiredAttri​buteException if the attribute does not exist
- * or if it consists entirely of whitespace.
+ * @throws MissingRequiredAttri​buteException
+ * if the attribute does not exist or if it consists entirely of
+ * whitespace.
      */
- protected String getStringValue(Attributes attrs, String qName)
- throws MissingRequiredAttri​buteException
+ protected String getStringValue(Attributes attrs, String qName) throws MissingRequiredAttri​buteException
     {
         String value = getOptionalStringValue(attrs, qName);
         if(value == null)
- throw new MissingRequiredAttri​buteException(this.g​etTAG(), qName,
- this.getDocumentLocator());
+ throw new MissingRequiredAttri​buteException(this.g​etTAG(), qName, this.getDocumentLocator());
         return value;
     }
 
     /**
      * Returns the boolean value of an attribute.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
- * @throws MissingRequiredAttri​buteException if the attribute does not exist.
+ * @throws MissingRequiredAttri​buteException
+ * if the attribute does not exist.
      */
- protected boolean getBooleanValue(Attributes attrs, String qName)
- throws MissingRequiredAttri​buteException
+ protected boolean getBooleanValue(Attributes attrs, String qName) throws MissingRequiredAttri​buteException
     {
         String value = this.getStringValue(attrs, qName);
         if("1".equals(value))
@@ -179,13 +202,15 @@
     /**
      * Returns the int value of an attribute.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
- * @throws MissingRequiredAttri​buteException if the attribute does not exist.
+ * @throws MissingRequiredAttri​buteException
+ * if the attribute does not exist.
      */
- protected int getIntValue(Attributes attrs, String qName)
- throws MissingRequiredAttri​buteException
+ protected int getIntValue(Attributes attrs, String qName) throws MissingRequiredAttri​buteException
     {
         return Integer.parseInt(thi​s.getStringValue(att​rs, qName));
     }
@@ -193,13 +218,15 @@
     /**
      * Returns the long value of an attribute.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
- * @throws MissingRequiredAttri​buteException if the attribute does not exist.
+ * @throws MissingRequiredAttri​buteException
+ * if the attribute does not exist.
      */
- protected long getLongValue(Attributes attrs, String qName)
- throws MissingRequiredAttri​buteException
+ protected long getLongValue(Attributes attrs, String qName) throws MissingRequiredAttri​buteException
     {
         return Long.parseLong(this.​getStringValue(attrs​, qName));
     }
@@ -207,14 +234,34 @@
     /**
      * Returns the double value of an attribute.
      *
- * @param attrs The attribute container.
- * @param qName The qualified name of the attribute.
+ * @param attrs
+ * The attribute container.
+ * @param qName
+ * The qualified name of the attribute.
      * @return The value of the attribute or <code>null</code>.
- * @throws MissingRequiredAttri​buteException if the attribute does not exist.
+ * @throws MissingRequiredAttri​buteException
+ * if the attribute does not exist.
      */
- protected double getDoubleValue(Attributes attrs, String qName)
- throws MissingRequiredAttri​buteException
+ protected double getDoubleValue(Attributes attrs, String qName) throws MissingRequiredAttri​buteException
     {
         return Double.parseDouble(t​his.getStringValue(a​ttrs, qName));
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException
+ {
+ if(m_prefixMappings == null)
+ m_prefixMappings = new HashMap<String,String>();
+ m_prefixMappings.put(prefix, uri);
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException
+ {
+ if(m_prefixMappings != null)
+ m_prefixMappings.rem​ove(prefix);
+ }
+
+ public String getPrefixMapping(String prefix)
+ {
+ return m_prefixMappings == null ? null : m_prefixMappings.get(prefix);
     }
 }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /tada-sax/src/se/tada/util/sax/ thhal Thomas Hallgren 2005-11-11 08:14:01 PST
Messages per page: