Improve XML parsing to handle attributes as well.
[cfb.git] / prod / net / jaekl / cfb / xml / SourceLine.java
index c78ae3af8717835bf21d207b3c9660a19d55edcf..c719529e2d9231c1a396253174571c932767ca0b 100644 (file)
@@ -1,14 +1,16 @@
 package net.jaekl.cfb.xml;
 
-import org.xml.sax.Attributes;
+import java.io.PrintWriter;
 
 import net.jaekl.qd.xml.MissingAttributeException;
 import net.jaekl.qd.xml.ParseResult;
 import net.jaekl.qd.xml.XmlParseException;
 
+import org.xml.sax.Attributes;
+
 public class SourceLine extends ParseResult {
 
-       static final String ROOT_TAG = "SourceLine";
+       static final String TAG = "SourceLine";
        static final String[] INTERNAL = { };
        static final Object[][] EXTERNAL = { };
        
@@ -21,41 +23,44 @@ public class SourceLine extends ParseResult {
        int m_end;
 
        public SourceLine() {
-               super(ROOT_TAG, INTERNAL, EXTERNAL);
+               super(TAG, INTERNAL, EXTERNAL);
                m_className = null;
                m_start = m_end = (-1);
        }       
        
        @Override
-       public void endContents(String uri, String localName, String qName,     String chars, Attributes attr) 
-               throws XmlParseException 
-       {
+       public void handleMainAttributes(Attributes attr) throws MissingAttributeException {
                String scratch;
                
-               m_className = getRequiredAttr(localName, attr, ATTR_CLASS_NAME);
+               m_className = getRequiredAttr(TAG, attr, ATTR_CLASS_NAME);
                
-               scratch = getRequiredAttr(localName, attr, ATTR_START);
+               scratch = getRequiredAttr(TAG, attr, ATTR_START);
                m_start = Integer.parseInt(scratch);
                
-               scratch = getRequiredAttr(localName, attr, ATTR_END);
+               scratch = getRequiredAttr(TAG, attr, ATTR_END);
                m_end = Integer.parseInt(scratch);
        }
        
-       String getRequiredAttr(String tagName, Attributes attr, String attrName)
-               throws MissingAttributeException
+       @Override
+       public void endContents(String uri, String localName, String qName,     String chars) 
+               throws XmlParseException 
        {
-               String result = attr.getValue(attrName);
-               if (null == result) {
-                       throw new MissingAttributeException(tagName, attrName);
-               }
-               return result;
+               // no-op
        }
-
+       
        @Override
        public void endExternal(String uri, String localName, String qName)
                throws XmlParseException 
        {
                // no-op
        }
-
+       
+       @Override
+       public void dump(PrintWriter pw, int indent) 
+       {
+               super.dump(pw, indent);
+               String tab = String.format("%" + (indent + 2) + "s", "");
+               
+               pw.println(tab + m_className + " (" + m_start + " .. " + m_end + ")");
+       }
 }