/[classpath]/classpath/gnu/xml/stream/XMLStreamReaderImpl.java
ViewVC logotype

Diff of /classpath/gnu/xml/stream/XMLStreamReaderImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dog, Sun Sep 4 09:52:10 2005 UTC revision 1.2 by dog, Mon Sep 5 12:37:38 2005 UTC
# Line 87  import org.xml.sax.XMLReader; Line 87  import org.xml.sax.XMLReader;
87  import org.xml.sax.ext.Attributes2;  import org.xml.sax.ext.Attributes2;
88  import org.xml.sax.ext.DeclHandler;  import org.xml.sax.ext.DeclHandler;
89  import org.xml.sax.ext.LexicalHandler;  import org.xml.sax.ext.LexicalHandler;
90    import org.xml.sax.ext.Locator2;
91  import org.xml.sax.helpers.NamespaceSupport;  import org.xml.sax.helpers.NamespaceSupport;
92    
93  /**  /**
# Line 156  public class XMLStreamReaderImpl Line 157  public class XMLStreamReaderImpl
157      // Configure the SAX parser and perform the parse      // Configure the SAX parser and perform the parse
158      try      try
159        {        {
         CallbackHandler ch = this.new CallbackHandler();  
160          SAXParserFactory f = SAXParserFactory.newInstance();          SAXParserFactory f = SAXParserFactory.newInstance();
161          f.setNamespaceAware(namespaceAware);          f.setNamespaceAware(namespaceAware);
162          f.setValidating(validating);          f.setValidating(validating);
163          SAXParser p = f.newSAXParser();          SAXParser p = f.newSAXParser();
164          XMLReader r = p.getXMLReader();          XMLReader r = p.getXMLReader();
165            CallbackHandler ch = this.new CallbackHandler(r);
166          r.setFeature("http://xml.org/sax/features/external-general-entities",          r.setFeature("http://xml.org/sax/features/external-general-entities",
167                       externalEntities);                       externalEntities);
168            r.setFeature("http://xml.org/sax/features/namespaces",
169                         namespaceAware);
170          r.setContentHandler(ch);          r.setContentHandler(ch);
171          r.setDTDHandler(ch);          r.setDTDHandler(ch);
172          r.setEntityResolver(ch);          r.setEntityResolver(ch);
# Line 220  public class XMLStreamReaderImpl Line 223  public class XMLStreamReaderImpl
223      // Configure the SAX parser and perform the parse      // Configure the SAX parser and perform the parse
224      try      try
225        {        {
         CallbackHandler ch = this.new CallbackHandler();  
226          SAXParserFactory f = SAXParserFactory.newInstance();          SAXParserFactory f = SAXParserFactory.newInstance();
227          f.setNamespaceAware(namespaceAware);          f.setNamespaceAware(namespaceAware);
228          f.setValidating(validating);          f.setValidating(validating);
229          SAXParser p = f.newSAXParser();          SAXParser p = f.newSAXParser();
230          XMLReader r = p.getXMLReader();          XMLReader r = p.getXMLReader();
231            CallbackHandler ch = this.new CallbackHandler(r);
232          r.setFeature("http://xml.org/sax/features/external-general-entities",          r.setFeature("http://xml.org/sax/features/external-general-entities",
233                       externalEntities);                       externalEntities);
234            r.setFeature("http://xml.org/sax/features/namespaces",
235                         namespaceAware);
236          r.setContentHandler(ch);          r.setContentHandler(ch);
237          r.setDTDHandler(ch);          r.setDTDHandler(ch);
238          r.setEntityResolver(ch);          r.setEntityResolver(ch);
# Line 265  public class XMLStreamReaderImpl Line 270  public class XMLStreamReaderImpl
270    {    {
271      if (events.isEmpty())      if (events.isEmpty())
272        throw new XMLStreamException("EOF");        throw new XMLStreamException("EOF");
273      Object event = events.removeLast();      Object event = events.removeFirst();
274      if (event instanceof Exception)      if (event instanceof Exception)
275        {        {
276          Exception e = (Exception) event;          Exception e = (Exception) event;
# Line 378  public class XMLStreamReaderImpl Line 383  public class XMLStreamReaderImpl
383      int count = 0;      int count = 0;
384      for (Iterator i = se.getAttributes(); i.hasNext(); )      for (Iterator i = se.getAttributes(); i.hasNext(); )
385        {        {
386            i.next();
387          count++;          count++;
388        }        }
389      return count;      return count;
# Line 462  public class XMLStreamReaderImpl Line 468  public class XMLStreamReaderImpl
468    
469    public int getNamespaceCount()    public int getNamespaceCount()
470    {    {
471      StartElement se = (StartElement) currentEvent;      Iterator i = null;
472        switch (eventType)
473          {
474          case XMLStreamConstants.START_ELEMENT:
475            i = ((StartElement) currentEvent).getNamespaces();
476            break;
477          case XMLStreamConstants.END_ELEMENT:
478            i = ((EndElement) currentEvent).getNamespaces();
479            break;
480          default:
481            throw new IllegalStateException();
482          }
483      int count = 0;      int count = 0;
484      for (Iterator i = se.getNamespaces(); i.hasNext(); )      while (i.hasNext())
485        {        {
486            i.next();
487          count++;          count++;
488        }        }
489      return count;      return count;
# Line 473  public class XMLStreamReaderImpl Line 491  public class XMLStreamReaderImpl
491    
492    public String getNamespacePrefix(int index)    public String getNamespacePrefix(int index)
493    {    {
494      StartElement se = (StartElement) currentEvent;      Iterator i = null;
495        switch (eventType)
496          {
497          case XMLStreamConstants.START_ELEMENT:
498            i = ((StartElement) currentEvent).getNamespaces();
499            break;
500          case XMLStreamConstants.END_ELEMENT:
501            i = ((EndElement) currentEvent).getNamespaces();
502            break;
503          default:
504            throw new IllegalStateException();
505          }
506      int count = 0;      int count = 0;
507      for (Iterator i = se.getNamespaces(); i.hasNext(); )      while (i.hasNext())
508        {        {
509          Namespace ns = (Namespace) i.next();          Namespace ns = (Namespace) i.next();
510          if (index == count)          if (index == count)
# Line 487  public class XMLStreamReaderImpl Line 516  public class XMLStreamReaderImpl
516    
517    public String getNamespaceURI(int index)    public String getNamespaceURI(int index)
518    {    {
519      StartElement se = (StartElement) currentEvent;      Iterator i = null;
520        switch (eventType)
521          {
522          case XMLStreamConstants.START_ELEMENT:
523            i = ((StartElement) currentEvent).getNamespaces();
524            break;
525          case XMLStreamConstants.END_ELEMENT:
526            i = ((EndElement) currentEvent).getNamespaces();
527            break;
528          default:
529            throw new IllegalStateException();
530          }
531      int count = 0;      int count = 0;
532      for (Iterator i = se.getNamespaces(); i.hasNext(); )      while (i.hasNext())
533        {        {
534          Namespace ns = (Namespace) i.next();          Namespace ns = (Namespace) i.next();
535          if (index == count)          if (index == count)
# Line 653  public class XMLStreamReaderImpl Line 693  public class XMLStreamReaderImpl
693                 DeclHandler, EntityResolver, ErrorHandler                 DeclHandler, EntityResolver, ErrorHandler
694    {    {
695    
696        XMLReader reader;
697        Locator locator;
698      Location location;      Location location;
699      private boolean inCDATA;      private boolean inCDATA;
700      private LinkedList namespaces = new LinkedList();      private LinkedList namespaces = new LinkedList();
701      private LinkedList notations;      private LinkedList notations;
702      private LinkedList entities;      private LinkedList entities;
703    
704        CallbackHandler(XMLReader reader)
705        {
706          this.reader = reader;
707        }
708    
709      public void setDocumentLocator(Locator locator)      public void setDocumentLocator(Locator locator)
710      {      {
711          this.locator = locator;
712        location = new LocationImpl(-1,        location = new LocationImpl(-1,
713                                    locator.getColumnNumber(),                                    locator.getColumnNumber(),
714                                    locator.getLineNumber(),                                    locator.getLineNumber(),
# Line 670  public class XMLStreamReaderImpl Line 718  public class XMLStreamReaderImpl
718      public void startDocument()      public void startDocument()
719        throws SAXException        throws SAXException
720      {      {
721        String version = null;        String version = (locator instanceof Locator2) ?
722        String encoding = null;          ((Locator2) locator).getXMLVersion() : null;
723        boolean standalone = false;        String encoding = (locator instanceof Locator2) ?
724        boolean standaloneDeclared = false;          ((Locator2) locator).getEncoding() : null;
725        boolean encodingDeclared = false;        boolean standalone =
726        // XXX can't get these values from SAX          reader.getFeature("http://xml.org/sax/features/is-standalone");
727          boolean standaloneDeclared = standalone;
728          boolean encodingDeclared = (encoding != null);
729        events.add(new StartDocumentImpl(location,        events.add(new StartDocumentImpl(location,
730                                         location.getLocationURI(),                                         location.getLocationURI(),
731                                         encoding,                                         encoding,
# Line 722  public class XMLStreamReaderImpl Line 772  public class XMLStreamReaderImpl
772                                                   attrs, ns, null);                                                   attrs, ns, null);
773        events.add(se);        events.add(se);
774        // Add namespaces        // Add namespaces
775        for (Iterator i = ns.iterator(); i.hasNext(); )        //for (Iterator i = ns.iterator(); i.hasNext(); )
776          {        //  events.add(i.next());
           events.add(i.next());  
         }  
777        // Add attributes        // Add attributes
778        int len = atts.getLength();        int len = atts.getLength();
779        for (int i = 0; i < len; i++)        for (int i = 0; i < len; i++)
# Line 750  public class XMLStreamReaderImpl Line 798  public class XMLStreamReaderImpl
798            AttributeImpl attr = new AttributeImpl(location, attrName,            AttributeImpl attr = new AttributeImpl(location, attrName,
799                                                   value, type, specified);                                                   value, type, specified);
800            attrs.add(attr);            attrs.add(attr);
801            events.add(attr);            //events.add(attr);
802          }          }
803      }      }
804    
# Line 859  public class XMLStreamReaderImpl Line 907  public class XMLStreamReaderImpl
907        Object n = new NotationDeclarationImpl(location, name, publicId,        Object n = new NotationDeclarationImpl(location, name, publicId,
908                                               systemId);                                               systemId);
909        notations.add(n);        notations.add(n);
910        events.add(n);        //events.add(n);
911      }      }
912    
913      public void unparsedEntityDecl(String name, String publicId,      public void unparsedEntityDecl(String name, String publicId,
# Line 870  public class XMLStreamReaderImpl Line 918  public class XMLStreamReaderImpl
918                                             name, notationName,                                             name, notationName,
919                                             null, null);                                             null, null);
920        entities.add(e);        entities.add(e);
921        events.add(e);        //events.add(e);
922      }      }
923    
924      public void elementDecl(String name, String model)      public void elementDecl(String name, String model)
# Line 890  public class XMLStreamReaderImpl Line 938  public class XMLStreamReaderImpl
938        Object e = new EntityDeclarationImpl(location, null, null,        Object e = new EntityDeclarationImpl(location, null, null,
939                                             name, null, value, null);                                             name, null, value, null);
940        entities.add(e);        entities.add(e);
941        events.add(e);        //events.add(e);
942      }      }
943    
944      public void externalEntityDecl(String name, String publicId,      public void externalEntityDecl(String name, String publicId,
# Line 900  public class XMLStreamReaderImpl Line 948  public class XMLStreamReaderImpl
948        Object e = new EntityDeclarationImpl(location, publicId, systemId,        Object e = new EntityDeclarationImpl(location, publicId, systemId,
949                                             name, null, null, null);                                             name, null, null, null);
950        entities.add(e);        entities.add(e);
951        events.add(e);        //events.add(e);
952      }      }
953    
954      public void warning(SAXParseException e)      public void warning(SAXParseException e)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26