KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml2 > AbstractParser


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml2;
30
31 import com.caucho.server.util.CauchoSystem;
32 import com.caucho.util.L10N;
33 import com.caucho.vfs.Path;
34 import com.caucho.vfs.ReadStream;
35 import com.caucho.vfs.Vfs;
36 import com.caucho.vfs.VfsStream;
37
38 import org.w3c.dom.Document JavaDoc;
39 import org.xml.sax.*;
40 import org.xml.sax.ext.LexicalHandler JavaDoc;
41
42 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
43 import java.io.FileNotFoundException JavaDoc;
44 import java.io.IOException JavaDoc;
45 import java.io.InputStream JavaDoc;
46 import java.util.Hashtable JavaDoc;
47 import java.util.Locale JavaDoc;
48 import java.util.logging.Logger JavaDoc;
49
50 abstract public class AbstractParser implements XMLReader, Parser
51 {
52   static final Logger JavaDoc log = Logger.getLogger(AbstractParser.class.getName());
53   static final L10N L = new L10N(AbstractParser.class);
54
55   static Hashtable JavaDoc<String JavaDoc,String JavaDoc> _attrTypes = new Hashtable JavaDoc<String JavaDoc,String JavaDoc>();
56   static Entities _xmlEntities = new XmlEntities();
57
58   boolean _isCoalescing = true;
59   
60   boolean _optionalTags = true;
61   boolean _skipWhitespace;
62   boolean _skipComments;
63   boolean _strictComments;
64   boolean _strictAttributes;
65   boolean _entitiesAsText = false;
66   boolean _expandEntities = true;
67   boolean _strictCharacters;
68   boolean _strictXml;
69   boolean _singleTopElement;
70
71   boolean _isNamespaceAware = true;
72   boolean _isNamespacePrefixes = true;
73   boolean _isSAXNamespaces = false;
74   
75   boolean _isXmlnsPrefix;
76   boolean _isXmlnsAttribute;
77   
78   boolean _isValidating = false;
79
80   boolean _isStaticEncoding = false;
81   String JavaDoc _defaultEncoding = "UTF-8";
82
83   // sax stuff
84
ContentHandler _contentHandler;
85   EntityResolver _entityResolver;
86   DTDHandler _dtdHandler;
87   LexicalHandler JavaDoc _lexicalHandler;
88   ErrorHandler _errorHandler;
89   Locale JavaDoc _locale;
90   
91   Entities _entities;
92   QDocument _owner;
93   QDocumentType _dtd;
94
95   DOMBuilder _builder;
96
97   Path _searchPath;
98   
99   String JavaDoc _publicId;
100   String JavaDoc _systemId;
101   String JavaDoc _filename;
102   int _line = 1;
103
104   /**
105    * Creates a new parser with the XmlPolicy and a new dtd.
106    */

107   AbstractParser()
108   {
109     this(null);
110   }
111
112   /**
113    * Creates a new parser with a given policy and dtd.
114    *
115    * @param policy the parsing policy, handling optional tags.
116    * @param dtd the parser's dtd.
117    */

118   AbstractParser(QDocumentType dtd)
119   {
120     if (dtd == null)
121       dtd = new QDocumentType(null);
122     _dtd = dtd;
123
124     _entities = _xmlEntities;
125   }
126
127   void clear()
128   {
129     _isCoalescing = true;
130
131     _isNamespaceAware = true;
132     _isSAXNamespaces = false;
133     _isNamespacePrefixes = false;
134     _optionalTags = true;
135     _skipWhitespace = false;
136     _skipComments = false;
137     _strictComments = false;
138     _strictAttributes = false;
139     _entitiesAsText = false;
140     _expandEntities = true;
141     _strictCharacters = false;
142     _strictXml = false;
143     _singleTopElement = false;
144
145     _defaultEncoding = "UTF-8";
146     _isStaticEncoding = false;
147   }
148
149   void init()
150   {
151     /*
152     _isXmlnsPrefix = (_isNamespaceAware ||
153               _isSAXNamespaces ||
154               _isNamespacePrefixes);
155     */

156     _isXmlnsPrefix = _isNamespaceAware || _isNamespacePrefixes;
157     _isXmlnsAttribute = _isNamespacePrefixes || ! _isNamespaceAware;
158   }
159
160   /**
161    * Sets the owner.
162    */

163   public void setOwner(QDocument doc)
164   {
165     _owner = doc;
166   }
167
168   /**
169    * Sets the configuration for a document builder.
170    */

171   public void setConfig(DocumentBuilderFactory JavaDoc factory)
172   {
173     if (_builder == null)
174       _builder = new DOMBuilder();
175
176     _isCoalescing = factory.isCoalescing();
177     setExpandEntities(factory.isExpandEntityReferences());
178     setSkipComments(factory.isIgnoringComments());
179     setSkipWhitespace(factory.isIgnoringElementContentWhitespace());
180     setNamespaceAware(factory.isNamespaceAware());
181     setNamespacePrefixes(false);
182     setValidating(factory.isValidating());
183   }
184     
185   public void setEntitiesAsText(boolean entitiesAsText)
186   {
187     _entitiesAsText = entitiesAsText;
188   }
189
190   public boolean getEntitiesAsText()
191   {
192     return _entitiesAsText;
193   }
194
195   public void setExpandEntities(boolean expandEntities)
196   {
197     _expandEntities = expandEntities;
198   }
199
200   /**
201    * Set to true if comments should be skipped. If false events will be
202    * generated for the comments.
203    */

204   public void setSkipComments(boolean skipComments)
205   {
206     _skipComments = skipComments;
207   }
208
209   /**
210    * Set to true if ignorable-whitespace should be skipped.
211    */

212   public void setSkipWhitespace(boolean skipWhitespace)
213   {
214     _skipWhitespace = skipWhitespace;
215   }
216
217   /**
218    * Returns true if text and cdata nodes will be combined.
219    */

220   public boolean isCoalescing()
221   {
222     return _isCoalescing;
223   }
224
225   /**
226    * Set true if text and cdata nodes should be combined.
227    */

228   public void setCoalescing(boolean isCoalescing)
229   {
230     _isCoalescing = isCoalescing;
231   }
232
233   /**
234    * Returns true if the XML should be validated
235    */

236   public boolean isValidating()
237   {
238     return _isValidating;
239   }
240
241   /**
242    * Set true if the XML should be validated
243    */

244   public void setValidating(boolean isValidating)
245   {
246     _isValidating = isValidating;
247   }
248
249   /**
250    * Returns true if the parsing is namespace aware.
251    */

252   public boolean isNamespaceAware()
253   {
254     return _isNamespaceAware;
255   }
256
257   /**
258    * Set true if the parsing is namespace aware.
259    */

260   public void setNamespaceAware(boolean isNamespaceAware)
261   {
262     _isNamespaceAware = isNamespaceAware;
263   }
264
265   /**
266    * Returns true if the parsing uses sax namespaces
267    */

268   public boolean isSAXNamespaces()
269   {
270     return _isSAXNamespaces;
271   }
272
273   /**
274    * Set true if the parsing uses sax namespaces
275    */

276   public void setSAXNamespaces(boolean isNamespaces)
277   {
278     _isSAXNamespaces = isNamespaces;
279   }
280
281   /**
282    * Returns true if the parsing uses namespace prefixes
283    */

284   public boolean isNamespacePrefixes()
285   {
286     return _isNamespacePrefixes;
287   }
288
289   /**
290    * Set true if the parsing uses sax namespaces
291    */

292   public void setNamespacePrefixes(boolean isNamespaces)
293   {
294     _isNamespacePrefixes = isNamespaces;
295   }
296
297   public boolean getSkipComments()
298   {
299     return _skipComments;
300   }
301
302   /**
303    * Sets the default encoding if none is specified.
304    *
305    * @param encoding the default encoding
306    */

307   public void setDefaultEncoding(String JavaDoc encoding)
308   {
309     _defaultEncoding = encoding;
310   }
311
312   /**
313    * Gets the default encoding if none is specified.
314    */

315   public String JavaDoc getDefaultEncoding()
316   {
317     return _defaultEncoding;
318   }
319
320   public Object JavaDoc getProperty(String JavaDoc name)
321     throws SAXNotRecognizedException
322   {
323     if (name.equals("http://xml.org/sax/properties/lexical-handler"))
324       return _lexicalHandler;
325     else if (name.equals("http://xml.org/sax/properties/dom-node"))
326       return null;
327     else if (name.equals("http://xml.org/sax/properties/xml-string"))
328       return null;
329     else
330       throw new SAXNotRecognizedException(name);
331   }
332
333   public void setProperty(String JavaDoc name, Object JavaDoc obj)
334     throws SAXNotSupportedException
335   {
336     if (name.equals("http://xml.org/sax/properties/lexical-handler"))
337       _lexicalHandler = (LexicalHandler JavaDoc) obj;
338     else if (name.equals("http://xml.org/sax/handlers/LexicalHandler"))
339       _lexicalHandler = (LexicalHandler JavaDoc) obj;
340     else
341       throw new SAXNotSupportedException(name);
342   }
343
344   public boolean getFeature(String JavaDoc name)
345     throws SAXNotRecognizedException
346   {
347     if (name.equals("http://xml.org/sax/features/namespaces"))
348       return _isSAXNamespaces;
349     else if (name.equals("http://xml.org/sax/features/namespace-prefixes"))
350       return _isNamespacePrefixes;
351     else if (name.equals("http://xml.org/sax/features/string-interning"))
352       return true;
353     else if (name.equals("http://xml.org/sax/features/validation"))
354       return _isValidating;
355     else if (name.equals("http://xml.org/sax/features/external-general-entities"))
356       return true;
357     else if (name.equals("http://xml.org/sax/features/external-parameter-entities"))
358       return false;
359     else if (name.equals("http://caucho.com/xml/features/skip-comments"))
360       return _skipComments;
361     else
362       throw new SAXNotRecognizedException(name);
363   }
364
365   public void setFeature(String JavaDoc name, boolean value)
366     throws SAXNotSupportedException
367   {
368     if (name.equals("http://xml.org/sax/features/namespaces")) {
369       _isNamespaceAware = value;
370     }
371     else if (name.equals("http://xml.org/sax/features/namespace-prefixes")) {
372       // setting namespace-prefixes, even if false, sets namespace-aware
373
// see xml/032b
374
_isNamespacePrefixes = value;
375       _isNamespaceAware = true;
376     }
377     else if (name.equals("http://caucho.com/xml/features/skip-comments")) {
378       _skipComments = value;
379     }
380     else if (name.equals("http://xml.org/sax/features/validation"))
381       _isValidating = value;
382     else
383       throw new SAXNotSupportedException(name);
384   }
385
386   public void setLexicalHandler(LexicalHandler JavaDoc handler)
387   {
388     _lexicalHandler = handler;
389   }
390
391   /**
392    * Sets the callback object to find files.
393    *
394    * @param resolver the object to find files.
395    */

396   public void setEntityResolver(EntityResolver resolver)
397   {
398     _entityResolver = resolver;
399   }
400
401   /**
402    * Sets the callback object finding files from system ids.
403    *
404    * @return the resolver to find files.
405    */

406   public EntityResolver getEntityResolver()
407   {
408     return _entityResolver;
409   }
410
411   public void setDTDHandler(DTDHandler handler)
412   {
413     _dtdHandler = handler;
414   }
415
416   public DTDHandler getDTDHandler()
417   {
418     return _dtdHandler;
419   }
420
421   public void setContentHandler(ContentHandler handler)
422   {
423     _contentHandler = handler;
424   }
425
426   public ContentHandler getContentHandler()
427   {
428     return _contentHandler;
429   }
430
431   /**
432    * Configures the document handler callback.
433    *
434    * @param handler the new document handler.
435    */

436   public void setDocumentHandler(DocumentHandler handler)
437   {
438     if (handler == null)
439       _contentHandler = null;
440     else
441       _contentHandler = new ContentHandlerAdapter(handler);
442   }
443
444   public void setErrorHandler(ErrorHandler handler)
445   {
446     _errorHandler = handler;
447   }
448
449   public ErrorHandler getErrorHandler()
450   {
451     return _errorHandler;
452   }
453
454   public void setLocale(Locale JavaDoc locale)
455   {
456     _locale = locale;
457   }
458
459   /**
460    * SAX parsing from a SAX InputSource
461    *
462    * @param source source containing the XML
463    */

464   public void parse(InputSource source)
465     throws IOException JavaDoc, SAXException
466   {
467     init();
468     
469     if (_searchPath == null) {
470       if (source.getSystemId() != null)
471         _searchPath = Vfs.lookup(source.getSystemId()).getParent();
472     }
473
474     _systemId = source.getSystemId();
475     _publicId = source.getPublicId();
476     ReadStream stream;
477     String JavaDoc encoding = null;
478
479     if (source.getByteStream() != null) {
480       stream = Vfs.openRead(source.getByteStream());
481       encoding = source.getEncoding();
482     }
483     else if (source.getCharacterStream() != null) {
484       encoding = "UTF-8";
485       _isStaticEncoding = true;
486       stream = Vfs.openRead(source.getCharacterStream());
487     }
488     else if (source.getSystemId() != null) {
489       InputStream JavaDoc is = openStream(source.getSystemId(),
490                   source.getPublicId(),
491                   null,
492                   true);
493       stream = Vfs.openRead(is);
494       encoding = source.getEncoding();
495     }
496     else
497       throw new FileNotFoundException JavaDoc(L.l("invalid InputSource"));
498
499     if (encoding != null)
500       stream.setEncoding(encoding);
501
502     try {
503       parseInt(stream);
504     } finally {
505       stream.close();
506     }
507   }
508   
509   /**
510    * SAX parsing from an InputStream
511    *
512    * @param is stream containing the XML
513    */

514   public void parse(InputStream JavaDoc is)
515     throws IOException JavaDoc, SAXException
516   {
517     init();
518
519     _systemId = "stream";
520     
521     if (is instanceof ReadStream) {
522       Path path = ((ReadStream) is).getPath();
523       _systemId = path.getURL();
524       _filename = path.getUserPath();
525       
526       if (_searchPath != null) {
527       }
528       else if (path != null)
529         _searchPath = path.getParent();
530
531       parseInt((ReadStream) is);
532     }
533     else {
534       ReadStream rs = VfsStream.openRead(is);
535       try {
536         parseInt(rs);
537       } finally {
538         if (rs != is)
539           rs.close();
540       }
541     }
542   }
543   
544   /**
545    * SAX parsing from an InputStream
546    *
547    * @param is stream containing the XML
548    */

549   public void parse(InputStream JavaDoc is, String JavaDoc systemId)
550     throws IOException JavaDoc, SAXException
551   {
552     init();
553     
554     parseImpl(is, systemId);
555   }
556   
557   /**
558    * SAX parsing from an InputStream
559    *
560    * @param is stream containing the XML
561    */

562   public void parseImpl(InputStream JavaDoc is, String JavaDoc systemId)
563     throws IOException JavaDoc, SAXException
564   {
565     if (is instanceof ReadStream) {
566       Path path = ((ReadStream) is).getPath();
567       
568       if (_searchPath != null) {
569       }
570       else if (path != null) {
571         _searchPath = path.getParent();
572         if (systemId != null)
573           _searchPath = _searchPath.lookup(systemId).getParent();
574       }
575       else if (systemId != null)
576         _searchPath = Vfs.lookup(systemId).getParent();
577
578       if (systemId == null) {
579         systemId = path.getURL();
580         _filename = ((ReadStream) is).getUserPath();
581       }
582       else
583         _filename = systemId;
584
585       _systemId = systemId;
586       
587       parseInt((ReadStream) is);
588     }
589     else {
590       if (systemId == null) {
591         _systemId = "anonymous.xml";
592       }
593       else {
594         _searchPath = Vfs.lookup(systemId).getParent();
595         _systemId = systemId;
596       }
597
598       ReadStream rs = VfsStream.openRead(is);
599       try {
600         parseInt(rs);
601       } finally {
602         if (rs != is)
603           rs.close();
604       }
605     }
606   }
607
608   /**
609    * SAX parsing from a file path
610    *
611    * @param systemId path to the file containing the XML
612    */

613   public void parse(String JavaDoc systemId)
614     throws IOException JavaDoc, SAXException
615   {
616     InputStream JavaDoc is = openTopStream(systemId, null);
617     try {
618       parse(is);
619     } finally {
620       is.close();
621     }
622   }
623   
624   /**
625    * SAX parsing from a VFS path
626    */

627   public void parse(Path path)
628     throws IOException JavaDoc, SAXException
629   {
630     init();
631     
632     if (_searchPath == null)
633       _searchPath = path.getParent();
634     
635     ReadStream is = path.openRead();
636     try {
637       parseInt(is);
638     } finally {
639       is.close();
640     }
641   }
642
643   /**
644    * SAX parsing from a string.
645    *
646    * @param string string containing the XML
647    */

648   public void parseString(String JavaDoc string)
649     throws IOException JavaDoc, SAXException
650   {
651     init();
652     
653     ReadStream is = Vfs.openString(string);
654
655     try {
656       parseInt(is);
657     } finally {
658       is.close();
659     }
660   }
661   
662   /**
663    * Parses a document from a SAX InputSource
664    *
665    * @param source SAX InputSource containing the XML data.
666    */

667   public Document JavaDoc parseDocument(InputSource source)
668     throws IOException JavaDoc, SAXException
669   {
670     init();
671     
672     QDocument doc = new QDocument();
673
674     if (_builder == null)
675       _builder = new DOMBuilder();
676
677     _builder.init(doc);
678     setOwner(doc);
679     
680     doc.setSystemId(source.getSystemId());
681     _builder.setSystemId(source.getSystemId());
682     _builder.setStrictXML(_strictXml);
683     _builder.setCoalescing(_isCoalescing);
684     _builder.setSkipWhitespace(_skipWhitespace);
685     _contentHandler = _builder;
686
687     parse(source);
688
689     return doc;
690   }
691
692   /**
693    * Parses a document from system path.
694    *
695    * @param systemId path to the XML data.
696    */

697   public Document JavaDoc parseDocument(String JavaDoc systemId)
698     throws IOException JavaDoc, SAXException
699   {
700     InputStream JavaDoc is = openTopStream(systemId, null);
701     try {
702       return parseDocument(is);
703     } finally {
704       is.close();
705     }
706   }
707
708   /**
709    * Parses a document from a VFS path
710    *
711    * @param path the VFS path containing the XML document.
712    */

713   public Document JavaDoc parseDocument(Path path)
714     throws IOException JavaDoc, SAXException
715   {
716     if (_searchPath == null)
717       _searchPath = path.getParent();
718     
719     ReadStream is = path.openRead();
720     try {
721       return parseDocument(is);
722     } finally {
723       is.close();
724     }
725   }
726
727   /**
728    * Parses an input stream into a DOM document
729    *
730    * @param is the input stream containing the XML
731    *
732    * @return the parsed document.
733    */

734   public Document JavaDoc parseDocument(InputStream JavaDoc is)
735     throws IOException JavaDoc, SAXException
736   {
737     return parseDocument(is, null);
738   }
739
740   /**
741    * Parses an input stream into a DOM document
742    *
743    * @param is the input stream containing the XML
744    * @param systemId the URL of the stream.
745    *
746    * @return the parsed document.
747    */

748   public Document JavaDoc parseDocument(InputStream JavaDoc is, String JavaDoc systemId)
749     throws IOException JavaDoc, SAXException
750   {
751     init();
752
753     QDocument doc = new QDocument();
754     parseDocument(doc, is, systemId);
755
756     return doc;
757   }
758
759   public void parseDocument(QDocument doc, InputStream JavaDoc is, String JavaDoc systemId)
760     throws IOException JavaDoc, SAXException
761   {
762     _owner = doc;
763
764     if (_builder == null)
765       _builder = new DOMBuilder();
766
767     _builder.init(_owner);
768     _builder.setSystemId(systemId);
769     _builder.setCoalescing(_isCoalescing);
770     _builder.setSkipWhitespace(_skipWhitespace);
771     _contentHandler = _builder;
772
773     parseImpl(is, systemId);
774   }
775
776   /**
777    * Parses a string into a DOM document
778    *
779    * @param string the string containing the XML
780    */

781   public Document JavaDoc parseDocumentString(String JavaDoc string)
782     throws IOException JavaDoc, SAXException
783   {
784     ReadStream is = Vfs.openString(string);
785
786     try {
787       _isStaticEncoding = true;
788       return parseDocument(is);
789     } finally {
790       is.close();
791     }
792   }
793
794   /**
795    * Looks up an input stream from the system id.
796    */

797   public InputStream JavaDoc openStream(String JavaDoc systemId, String JavaDoc publicId)
798     throws IOException JavaDoc, SAXException
799   {
800     return openStream(systemId, publicId, _entityResolver, false);
801   }
802
803   /**
804    * Looks up an input stream from the system id.
805    */

806   public InputStream JavaDoc openTopStream(String JavaDoc systemId, String JavaDoc publicId)
807     throws IOException JavaDoc, SAXException
808   {
809     return openStream(systemId, publicId, _entityResolver, true);
810   }
811
812   /**
813    * Looks up an input stream from the system id.
814    */

815   public InputStream JavaDoc openStream(String JavaDoc systemId, String JavaDoc publicId,
816                 EntityResolver entityResolver)
817     throws IOException JavaDoc, SAXException
818   {
819     return openStream(systemId, publicId, entityResolver, false);
820   }
821
822   /**
823    * Looks up an input stream from the system id.
824    */

825   protected InputStream JavaDoc openStream(String JavaDoc systemId, String JavaDoc publicId,
826                    EntityResolver entityResolver,
827                    boolean isTop)
828     throws IOException JavaDoc, SAXException
829   {
830     int colon = systemId.indexOf(':');
831     int slash = systemId.indexOf('/');
832     
833     boolean isAbsolute = colon > 0 && (colon < slash || slash < 0);
834     
835     if (slash == 0 || ! isAbsolute) {
836       Path pwd;
837
838       if (_searchPath != null)
839         pwd = _searchPath;
840       else
841         pwd = Vfs.lookup(systemId).getParent();
842       
843       String JavaDoc newId = pwd.lookup(systemId).getURL();
844       if (! newId.startsWith("error:"))
845         systemId = newId;
846       else {
847         int tail = _systemId.lastIndexOf('/');
848         if (tail >= 0)
849           systemId = _systemId.substring(0, tail + 1) + systemId;
850       }
851     }
852
853     // xml/03c5 -- must be after the normalization
854
if (entityResolver != null) {
855       InputSource source = entityResolver.resolveEntity(publicId, systemId);
856
857       if (source != null) {
858         _filename = systemId;
859         _systemId = systemId;
860
861         return openSource(source);
862       }
863     }
864
865     int ch;
866     if (CauchoSystem.isWindows() && systemId.startsWith("file:") &&
867         systemId.length() > 7 && systemId.charAt(6) == ':' &&
868         (((ch = systemId.charAt(5)) >= 'a' && ch <= 'z') ||
869          ch >= 'A' && ch <= 'Z')) {
870       colon = 1;
871       isAbsolute = false;
872       systemId = "/" + systemId.substring(5);
873     }
874
875     if (! isTop &&
876     isAbsolute && ! systemId.startsWith("file:") &&
877         ! systemId.startsWith("jar:") &&
878         ! (colon == 1 && CauchoSystem.isWindows())) {
879       throw new RemoteURLException(L.l("URL `{0}' was not opened because it is a remote URL. Any URL scheme other than file: must be handled by a custom entity resolver.",
880                                        systemId));
881     }
882     else if (_searchPath != null) {
883       return _searchPath.lookup(systemId).openRead();
884     }
885     else
886       return Vfs.lookup(systemId).openRead();
887   }
888
889   /**
890    * Opens the source
891    */

892   protected InputStream JavaDoc openSource(InputSource source)
893     throws IOException JavaDoc, SAXException
894   {
895     if (source.getByteStream() != null) {
896       return source.getByteStream();
897     }
898     else if (source.getCharacterStream() != null) {
899       return Vfs.openRead(source.getCharacterStream());
900     }
901     else if (source.getSystemId() != null) {
902       return Vfs.openRead(source.getSystemId());
903     }
904     else
905       throw new FileNotFoundException JavaDoc(L.l("invalid InputSource {0}", source));
906   }
907
908   /**
909    * Parse the document from a read stream.
910    *
911    * @param is read stream to parse from.
912    *
913    * @return The parsed document.
914    */

915   abstract Document JavaDoc parseInt(ReadStream is)
916     throws IOException JavaDoc, SAXException;
917   
918   static {
919     _attrTypes.put("CDATA", "CDATA");
920     _attrTypes.put("ID", "ID");
921     _attrTypes.put("IDREF", "IDREF");
922     _attrTypes.put("IDREFS", "IDREFS");
923     _attrTypes.put("ENTITY", "ENTITY");
924     _attrTypes.put("ENTITIES", "ENTITIES");
925     _attrTypes.put("NMTOKEN", "NMTOKEN");
926     _attrTypes.put("NMTOKENS", "NMTOKENS");
927   }
928 }
929
Popular Tags