Logo Search packages:      
Sourcecode: xae version File versions

void com::icl::saxon::aelfred::XmlParser::pushURL ( String  ename,
String  publicId,
String  systemId,
Reader  reader,
InputStream  stream,
String  encoding 
) throws SAXException, IOException [inline, private]

Push a new external input source. The source will be some kind of parsed entity, such as a PE (including the external DTD subset) or content for the body.

TODO: Right now, this method always attempts to autodetect the encoding; in the future, it should allow the caller to request an encoding explicitly, and it should also look at the headers with an HTTP connection.

Parameters:
url The java.net.URL object for the entity.
See also:
SAXDriver::resolveEntity

pushString

sourceType

pushInput

detectEncoding

sourceType

readBuffer

Definition at line 3495 of file XmlParser.java.

References detectEncoding(), pushInput(), com::icl::saxon::aelfred::SAXDriver::resolveEntity(), setupDecoding(), com::icl::saxon::aelfred::SAXDriver::startExternalEntity(), and tryEncodingDecl().

Referenced by doParse(), parseDoctypedecl(), parseEntityRef(), and parsePEReference().

    {
      URL   url;
      boolean     ignoreEncoding = false;

      // Push the existing status.
      pushInput (ename);

      // Create a new read buffer.
      // (Note the four-character margin)
      readBuffer = new char [READ_BUFFER_MAX + 4];
      readBufferPos = 0;
      readBufferLength = 0;
      readBufferOverflow = -1;
      is = null;
      line = 1;

      currentByteCount = 0;

      // Make any system ID (URI/URL) absolute.  There's one case
      // where it may be null:  parser was invoked without providing
      // one, e.g. since the XML data came from a memory buffer.

      if (systemId != null && externalEntity != null) {
          systemId = new URL (externalEntity.getURL (), systemId).toString ();
      } else if (baseURI != null) {
          systemId = new URL (new URL (baseURI), systemId).toString ();
          // throws IOException if couldn't create new URL
      }

      // See if the application wants to
      // redirect the system ID and/or
      // supply its own character stream.
      if (reader == null && stream == null && systemId != null) {
          Object input = handler.resolveEntity (publicId, systemId);
          if (input != null) {
            if (input instanceof String) {
                systemId = (String) input;
            } else if (input instanceof InputStream) {
                stream = (InputStream) input;
            } else if (input instanceof Reader) {
                reader = (Reader) input;
            }
          }
      }

      // Start the entity.
      if (systemId != null) {
          handler.startExternalEntity (systemId);
      } else {
          handler.startExternalEntity ("[unidentified data stream]");
      }

      // If there's an explicit character stream, just
      // ignore encoding declarations.
      if (reader != null) {
          sourceType = INPUT_READER;
          this.reader = reader;
          tryEncodingDecl (true);
          return;
      }
      
      // Else we handle the conversion, and need to ensure
      // it's done right.
      if (stream != null) {
          sourceType = INPUT_STREAM;
          is = stream;
          url = null;
      } else {
          // We have to open our own stream to the URL.

          // Set the new status
          sourceType = INPUT_EXTERNAL;
          url = new URL (systemId);

          externalEntity = url.openConnection ();
          externalEntity.connect ();
          is = externalEntity.getInputStream ();
      }

      // If we get to here, there must be
      // an InputStream available.
      if (!is.markSupported ()) {
          is = new BufferedInputStream (is);
      }

      // Get any external encoding label.
      if (encoding == null && externalEntity != null) {
          // External labels can be untrustworthy; filesystems in
          // particular often have the wrong default for content
          // that wasn't locally originated.  Those we autodetect.
          if (!"file".equals (externalEntity.getURL ().getProtocol ())) {
            int temp;

            // application/xml;charset=something;otherAttr=...
            // ... with many variants on 'something'
            encoding = externalEntity.getContentType ();
            temp = encoding.indexOf ("charset");

            // RFC 2376 sez MIME text defaults to ASCII, but since the
            // JDK will create a MIME type out of thin air, we always
            // autodetect when there's no explicit charset attribute.
            if (temp < 0)
                encoding = null;    // autodetect
            else {
                temp = encoding.indexOf ('=', temp + 7);
                encoding = encoding.substring (temp);
                if ((temp = encoding.indexOf (';')) > 0)
                  encoding = encoding.substring (0, temp);

                // attributes can have comment fields (RFC 822)
                if ((temp = encoding.indexOf ('(')) > 0)
                  encoding = encoding.substring (0, temp);
                // ... and values may be quoted
                if ((temp = encoding.indexOf ('"')) > 0)
                  encoding = encoding.substring (temp + 1,
                        encoding.indexOf ('"', temp + 2));
                encoding.trim ();
            }
          }
      }

      // if we got an external encoding label, use it ...
      if (encoding != null) {
          this.encoding = ENCODING_EXTERNAL;
          setupDecoding (encoding);
          ignoreEncoding = true;
      
      // ... else autodetect
      } else {
          detectEncoding ();
          ignoreEncoding = false;
      }

      // Read any XML or text declaration.
      tryEncodingDecl (ignoreEncoding);
    }


Generated by  Doxygen 1.6.0   Back to index