Esempio n. 1
0
 /**
  * Opens a stream from a public and system ID.
  *
  * @param publicID the public ID, which may be null
  * @param systemID the system ID, which is never null
  * @throws java.net.MalformedURLException if the system ID does not contain a valid URL
  * @throws java.io.FileNotFoundException if the system ID refers to a local file which does not
  *     exist
  * @throws java.io.IOException if an error occurred opening the stream
  */
 public Reader openStream(final String publicID, final String systemID)
     throws MalformedURLException, FileNotFoundException, IOException {
   URL url = new URL(currentReader.systemId, systemID);
   if (url.getRef() != null) {
     final String ref = url.getRef();
     if (url.getFile().length() > 0) {
       url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile());
       url = new URL("jar:" + url + '!' + ref);
     } else {
       url = StdXMLReader.class.getResource(ref);
     }
   }
   currentReader.publicId = publicID;
   currentReader.systemId = url;
   final StringBuilder charsRead = new StringBuilder();
   final Reader reader = this.stream2reader(url.openStream(), charsRead);
   if (charsRead.length() == 0) {
     return reader;
   }
   final String charsReadStr = charsRead.toString();
   final PushbackReader pbreader = new PushbackReader(reader, charsReadStr.length());
   for (int i = charsReadStr.length() - 1; i >= 0; i--) {
     pbreader.unread(charsReadStr.charAt(i));
   }
   return pbreader;
 }
Esempio n. 2
0
 /**
  * Creates a new reader using a file as input.
  *
  * @param filename the name of the file containing the XML data
  * @throws java.io.FileNotFoundException if the file could not be found
  * @throws java.io.IOException if an I/O error occurred
  */
 public static IXMLReader fileReader(final String filename)
     throws FileNotFoundException, IOException {
   final StdXMLReader r = new StdXMLReader(new FileInputStream(filename));
   r.setSystemID(filename);
   for (int i = 0; i < r.readers.size(); i++) {
     final StackedReader sr = (StackedReader) r.readers.elementAt(i);
     sr.systemId = r.currentReader.systemId;
   }
   return r;
 }
Esempio n. 3
0
 /** Cleans up the object when it's destroyed. */
 @Override
 protected void finalize() throws Throwable {
   currentReader.lineReader = null;
   currentReader.pbReader = null;
   currentReader.systemId = null;
   currentReader.publicId = null;
   currentReader = null;
   readers.clear();
   super.finalize();
 }
Esempio n. 4
0
 /**
  * Initializes the XML reader.
  *
  * @param reader the input for the XML data.
  */
 public StdXMLReader(final Reader reader) {
   currentReader = new StackedReader();
   readers = new Stack<StackedReader>();
   currentReader.lineReader = new LineNumberReader(reader);
   currentReader.pbReader = currentReader.lineReader;
   currentReader.publicId = "";
   charReadTooMuch = '\0';
   try {
     currentReader.systemId = new URL("file:.");
   } catch (final MalformedURLException e) {
   }
 }
Esempio n. 5
0
 /**
  * Initializes the XML reader.
  *
  * @param stream the input for the XML data.
  * @throws java.io.IOException if an I/O error occurred
  */
 public StdXMLReader(final InputStream stream) throws IOException {
   new PushbackInputStream(stream);
   final StringBuilder charsRead = new StringBuilder();
   final Reader reader = this.stream2reader(stream, charsRead);
   currentReader = new StackedReader();
   readers = new Stack<StackedReader>();
   currentReader.lineReader = new LineNumberReader(reader);
   currentReader.pbReader = currentReader.lineReader;
   currentReader.publicId = "";
   charReadTooMuch = '\0';
   try {
     currentReader.systemId = new URL("file:.");
   } catch (final MalformedURLException e) {
   }
   this.startNewStream(new StringReader(charsRead.toString()));
 }
Esempio n. 6
0
 /**
  * Initializes the reader from a system and public ID.
  *
  * @param publicID the public ID which may be null.
  * @param systemID the non-null system ID.
  * @throws MalformedURLException if the system ID does not contain a valid URL
  * @throws FileNotFoundException if the system ID refers to a local file which does not exist
  * @throws IOException if an error occurred opening the stream
  */
 public StdXMLReader(final String publicID, String systemID)
     throws MalformedURLException, FileNotFoundException, IOException {
   URL systemIDasURL = null;
   charReadTooMuch = '\0';
   try {
     systemIDasURL = new URL(systemID);
   } catch (final MalformedURLException e) {
     systemID = "file:" + systemID;
     try {
       systemIDasURL = new URL(systemID);
     } catch (final MalformedURLException e2) {
       throw e;
     }
   }
   currentReader = new StackedReader();
   readers = new Stack<StackedReader>();
   final Reader reader = this.openStream(publicID, systemIDasURL.toString());
   currentReader.lineReader = new LineNumberReader(reader);
   currentReader.pbReader = currentReader.lineReader;
 }
Esempio n. 7
0
 /**
  * Starts a new stream from a Java reader. The new stream is used temporary to read data from. If
  * that stream is exhausted, control returns to the parent stream.
  *
  * @param reader the non-null reader to read the new data from
  * @param isInternalEntity true if the reader is produced by resolving an internal entity
  */
 public void startNewStream(final Reader reader, final boolean isInternalEntity) {
   final StackedReader oldReader = currentReader;
   readers.push(currentReader);
   currentReader = new StackedReader();
   if (isInternalEntity) {
     currentReader.lineReader = null;
     currentReader.pbReader = reader;
   } else {
     currentReader.lineReader = new LineNumberReader(reader);
     currentReader.pbReader = new PushbackReader(currentReader.lineReader, 2);
   }
   currentReader.systemId = oldReader.systemId;
   currentReader.publicId = oldReader.publicId;
 }
Esempio n. 8
0
 /**
  * Sets the system ID of the current stream.
  *
  * @param systemID the system ID
  * @throws java.net.MalformedURLException if the system ID does not contain a valid URL
  */
 public void setSystemID(final String systemID) throws MalformedURLException {
   currentReader.systemId = new URL(currentReader.systemId, systemID);
 }
Esempio n. 9
0
 /**
  * Sets the public ID of the current stream.
  *
  * @param publicID the public ID
  */
 public void setPublicID(final String publicID) {
   currentReader.publicId = publicID;
 }