FileDocCategorySizeDatePackage
XMLValidationHandler.javaAPI DocGlassfish v2 API9469Fri May 04 22:34:20 BST 2007tools.com.sun.enterprise.util

XMLValidationHandler

public class XMLValidationHandler extends DefaultHandler
author
dochez
version

Fields Summary
protected static Hashtable
mapping
private Logger
logger
private boolean
throwsException
Constructors Summary
public XMLValidationHandler(boolean thowsException)
Creates new DTDEntityResolver


        
       
        this.throwsException = thowsException;
        Init();
    
public XMLValidationHandler()

        this.throwsException=true;
        Init();
    
Methods Summary
private static voidInit()

        if (mapping==null) {
            mapping = new Hashtable<String, String>();
            mapping.put(com.sun.enterprise.deployment.node.ApplicationNode.PUBLIC_DTD_ID ,  "application_1_3.dtd" );
            mapping.put(com.sun.enterprise.deployment.node.ApplicationNode.PUBLIC_DTD_ID_12 , "application_1_2.dtd");
            mapping.put(com.sun.enterprise.deployment.node.ejb.EjbBundleNode.PUBLIC_DTD_ID, "ejb-jar_2_0.dtd" ) ;
            mapping.put(com.sun.enterprise.deployment.node.ejb.EjbBundleNode.PUBLIC_DTD_ID_12, "ejb-jar_1_1.dtd" );
            mapping.put(com.sun.enterprise.deployment.node.appclient.AppClientNode.PUBLIC_DTD_ID, "application-client_1_3.dtd" );
            mapping.put(com.sun.enterprise.deployment.node.appclient.AppClientNode.PUBLIC_DTD_ID_12, "application-client_1_2.dtd" );

            mapping.put(com.sun.enterprise.deployment.node.web.WebBundleNode.PUBLIC_DTD_ID, "web-app_2_3.dtd" );
            mapping.put(com.sun.enterprise.deployment.node.web.WebBundleNode.PUBLIC_DTD_ID_12,   "web-app_2_2.dtd");

            //connector1.5
            mapping.put(com.sun.enterprise.deployment.node.connector.ConnectorNode.PUBLIC_DTD_ID, "connector_1_5.dtd" );
            mapping.put(com.sun.enterprise.deployment.node.connector.ConnectorNode.PUBLIC_DTD_ID_10,   "connector_1_0.dtd");

            //SunOne 8.0 Specific Stuff
            mapping.put(DTDRegistry.SUN_APPLICATION_130_DTD_PUBLIC_ID,"sun-application_1_3-0.dtd");
            mapping.put(DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID,"sun-application_1_4-0.dtd");
            mapping.put(DTDRegistry.SUN_APPLICATION_140beta_DTD_PUBLIC_ID,"sun-application_1_4-0.dtd");
            mapping.put(DTDRegistry.SUN_APPLICATION_500_DTD_PUBLIC_ID,"sun-application_5_0-0.dtd");

            mapping.put(DTDRegistry.SUN_APPCLIENT_130_DTD_PUBLIC_ID,"sun-application-client_1_3-0.dtd");
            mapping.put(DTDRegistry.SUN_APPCLIENT_140_DTD_PUBLIC_ID,"sun-application-client_1_4-0.dtd");
            mapping.put(DTDRegistry.SUN_APPCLIENT_140beta_DTD_PUBLIC_ID,"sun-application-client_1_4-0.dtd");
            mapping.put(DTDRegistry.SUN_APPCLIENT_141_DTD_PUBLIC_ID,"sun-application-client_1_4-1.dtd");
            mapping.put(DTDRegistry.SUN_APPCLIENT_500_DTD_PUBLIC_ID,"sun-application-client_5_0-0.dtd");

            mapping.put(DTDRegistry.SUN_WEBAPP_230_DTD_PUBLIC_ID,"sun-web-app_2_3-0.dtd");
            mapping.put(DTDRegistry.SUN_WEBAPP_231_DTD_PUBLIC_ID,"sun-web-app_2_3-1.dtd");
            mapping.put(DTDRegistry.SUN_WEBAPP_240_DTD_PUBLIC_ID,"sun-web-app_2_4-0.dtd");
            mapping.put(DTDRegistry.SUN_WEBAPP_240beta_DTD_PUBLIC_ID,"sun-web-app_2_4-0.dtd");
            mapping.put(DTDRegistry.SUN_WEBAPP_241_DTD_PUBLIC_ID,"sun-web-app_2_4-1.dtd");
            mapping.put(DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID,"sun-web-app_2_5-0.dtd");

            mapping.put(DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID,"sun-ejb-jar_2_0-0.dtd");
            mapping.put(DTDRegistry.SUN_EJBJAR_201_DTD_PUBLIC_ID,"sun-ejb-jar_2_0-1.dtd");
            mapping.put(DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID,"sun-ejb-jar_2_1-0.dtd");
            mapping.put(DTDRegistry.SUN_EJBJAR_210beta_DTD_PUBLIC_ID,"sun-ejb-jar_2_1-0.dtd");
            mapping.put(DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID,"sun-ejb-jar_2_1-1.dtd");
            mapping.put(DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID,"sun-ejb-jar_3_0-0.dtd");

            mapping.put(DTDRegistry.SUN_CONNECTOR_100_DTD_PUBLIC_ID,"sun-connector_1_0-0.dtd");
            mapping.put(DTDRegistry.SUN_CLIENTCONTAINER_700_DTD_PUBLIC_ID,"sun-application-client-container_1_0.dtd");

            mapping.put(DTDRegistry.SUN_CMP_MAPPING_700_DTD_PUBLIC_ID,"sun-cmp-mapping_1_0.dtd");
            mapping.put(DTDRegistry.SUN_CMP_MAPPING_800_DTD_PUBLIC_ID,"sun-cmp-mapping_1_1.dtd");
            mapping.put(DTDRegistry.SUN_CMP_MAPPING_810_DTD_PUBLIC_ID,"sun-cmp-mapping_1_2.dtd");

            mapping.put(DTDRegistry.TAGLIB_12_DTD_PUBLIC_ID,"web-jsptaglibrary_1_2.dtd");
            mapping.put(DTDRegistry.TAGLIB_11_DTD_PUBLIC_ID,"web-jsptaglibrary_1_1.dtd");
        }
    
public voiderror(org.xml.sax.SAXParseException spe)

        logger.log(Level.FINE,"XML Error line : " + spe.getLineNumber() + " " + spe.getLocalizedMessage());        
        if (throwsException)
            throw spe;
    
public voidfatalError(org.xml.sax.SAXParseException spe)

        logger.log(Level.FINE,"XML Error line : " + spe.getLineNumber() + " " + spe.getLocalizedMessage());
        throw spe;
    
protected java.lang.StringgetAbsoluteFilenameForDTD(java.lang.String dtdFilename)

        //String j2ee13 = DirLocation.getDTDDirRoot();
        String j2ee13 = DTDRegistry.DTD_LOCATION;
    	File f = new File(j2ee13 +File.separator+ dtdFilename);
	    return f.getAbsolutePath();
    
protected java.io.FilegetSchemaFileFor(java.lang.String schemaSystemID)


	    String schemaLoc = DTDRegistry.SCHEMA_LOCATION.replace('/", File.separatorChar);
        File f = new File(schemaLoc +File.separatorChar+ schemaSystemID);
        if (!f.exists()) {
            return null;
        }
        return f;
    
protected java.lang.StringgetSchemaURLFor(java.lang.String schemaSystemID)

        File f = getSchemaFileFor(schemaSystemID);
        if (f!=null) {
            return f.toURL().toString();
        } else {
            return null;
        }
    
public org.xml.sax.InputSourceresolveEntity(java.lang.String publicID, java.lang.String systemID)

        try{
            if (publicID==null) {
                // unspecified schema
                if (systemID==null || systemID.lastIndexOf('/")==systemID.length()) {
                    return null;
                }

                String fileName = getSchemaURLFor(systemID.substring(systemID.lastIndexOf('/")+1));
                // if this is not a request for a schema located in our repository,
                // let's hope that the hint provided by schemaLocation is correct
                if (fileName==null) {
                    fileName = systemID;
                }
                return new InputSource(fileName);
            }

            if (mapping.containsKey(publicID)) {
                return new InputSource(new FileInputStream(new File(getAbsoluteFilenameForDTD((String) mapping.get(publicID)))));
            }
        } catch(java.io.IOException ioe) {
            throw new SAXException(ioe);
        }
        return null;