You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Wayne Jenkins <Wa...@sausage.com> on 2000/08/10 09:31:47 UTC

Patch for resolving entities

 
Hi all,
 
I have found a slight bug with entity resolvers.  If the resolveEntity
method is used and a 
system id is provided as an input source then the current Xerces (1.1.3)
ignores the system id.
 
For example,  when the resolve entity method is defined as:
 
  public InputSource resolveEntity(String publicId, String systemId) throws
SAXException     
    return new InputSource("<some URL>");
  }
 
the Xerces system ignores the new URL and uses the original system
identifier of the
external entity for reading the entity.
 
The patch is straightforward and is included within the class
org.apache.xerces.readers.DefaultReaderFactory.
 
The change required is within the method createReader and is given as
follows:
 
    public XMLEntityHandler.EntityReader createReader(XMLEntityHandler
entityHandler,
                                                            XMLErrorReporter
errorReporter,
                                                            InputSource
source,
                                                      String systemId,
boolean xmlDecl, StringPool stringPool) throws Exception {
 
        // create reader from source's character stream
        if (source.getCharacterStream() != null) {
            return createCharReader(entityHandler, errorReporter,
fSendCharDataAsCharArray, source.getCharacterStream(), stringPool);
        }
 
        // create reader from source's byte stream
        if (source.getEncoding() != null && source.getByteStream() != null)
{
            java.io.Reader reader = new
InputStreamReader(source.getByteStream(), source.getEncoding());
            return createCharReader(entityHandler, errorReporter,
fSendCharDataAsCharArray, reader, stringPool);
        }
 
        // create new input stream
        InputStream is = source.getByteStream();
        if (is == null) {
 
           /*********** Start modifaction ***************/
          // Check to see whether the input source has a system id.  Use the

          // original one if not.
          String urlString = source.getSystemId() != null ?
source.getSystemId() : systemId;
          
            // create url and open the stream
            URL url = new URL(urlString);
          /******** End modification ******************/

            is = url.openStream();
        }
   ...
 
If this patch is incorrect, I would appreciate it if you could let me know
because we require this patch in
our application.
 
Cheers,
 
Wayne.