FileDocCategorySizeDatePackage
SaxParserHandlerBundled.javaAPI DocGlassfish v2 API6750Fri May 04 22:31:38 BST 2007com.sun.enterprise.deployment.node

SaxParserHandlerBundled

public class SaxParserHandlerBundled extends SaxParserHandler
Provides access to schemas and DTDs to Java Web Start-launched app clients that do not have an app server product installation at hand.

The DTDs and schemas are assumed to be in the classpath so that schemas are at /schemas/ and DTDs at /dtds/

author
tjquinn

Fields Summary
private static final String
BUNDLED_SCHEMA_ROOT
prefixes for the paths to use for looking up schemas and dtds as resources
private static final String
BUNDLED_DTD_ROOT
Constructors Summary
public SaxParserHandlerBundled()
Creates a new instance of SaxParserHandlerBundled

    
           
      
    
Methods Summary
private java.io.InputStreamopenDTDStream(java.lang.String publicID)
Returns an InputStream for the DTD with the requested public ID.

param
the publicID of the DTD requested
return
an InputStream to the selected DTD; null if the DTD is not available

        String targetID = BUNDLED_DTD_ROOT + "/" + getMapping().get(publicID);
        InputStream result = this.getClass().getResourceAsStream(targetID);
        return result;
    
private java.io.InputStreamopenSchemaStream(java.lang.String systemID)
Returns an InputStream for the schema with the requested system ID.

param
systemID of the schema
return
an InputStream to the selected schema; null if the schema is not available

        String targetID = BUNDLED_SCHEMA_ROOT + "/" + systemID.substring(systemID.lastIndexOf("/") + 1 );
        InputStream result = this.getClass().getResourceAsStream(targetID);
        return result;
    
public org.xml.sax.InputSourceresolveEntity(java.lang.String publicID, java.lang.String systemID)
Returns an InputSource for the requested DTD or schema.

This implementation returns an InputSource that wraps the result of getResourceAsStream, having located the requested schema in the classpath.

param
the public ID of the requested entity
param
the system ID of the requested entity
return
InputSource for the requested entity; null if not available
throws
SAXException in case of errors resolving the entity

        InputSource result = null;
        
        /*
         *This logic was patterned after that in the superclass.
         */
        try {
            if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
                DOLUtils.getDefaultLogger().fine("Asked to resolve  " + publicID + " system id = " + systemID);
            }
            if (publicID==null) {
                // unspecified schema
                if (systemID==null || systemID.lastIndexOf('/")==systemID.length()) {
                    return null;
                }
                
                /*
                 *Attempt to open a stream to the requested resource as a schema.
                 */
                InputStream is = openSchemaStream(systemID);
                
                if (is != null) {
                    /*
                     *We found the entity, so wrap an InputSource around the stream.
                     */
                    result = new InputSource(is);
                } else {
                    /*
                     *The entity was not found, so wrap an InputSource around the system ID string instead.
                     */
                    result = new InputSource(systemID);
                }
            } else {
                /*
                 *Try to find a DTD for the entity.
                 */
                if ( getMapping().containsKey(publicID)) {
                    this.publicID = publicID;
                    InputStream is = openDTDStream(publicID);
                    if (is != null) {
                        result = new InputSource(is);
                    } 
                } else if (systemID != null) {
                    /*
                     *The DTD lookup failed but a system ID was also specified.  Try
                     *looking up the DTD in the schemas path, because some reside
                     *there and were not registered in the DTD map by SaxParserHandler.
                     */
                    InputStream is = openSchemaStream(systemID);
                    if (is != null) {
                        result = new InputSource(is);
                    }
                }
            }
        } catch (Exception exc) {
            exc.printStackTrace();
            throw new SAXException(exc);
        }
        return result;