org.w3c.dom.DOMErrorHandler Java Examples

The following examples show how to use org.w3c.dom.DOMErrorHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 * @param   contentHandler serialHandler The implemention of the SerializationHandler interface
 */
DOM3TreeWalker(
    SerializationHandler serialHandler,
    DOMErrorHandler errHandler,
    LSSerializerFilter filter,
    String newLine) {
    fSerializer = serialHandler;
    //fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
    fErrorHandler = errHandler;
    fFilter = filter;
    fLexicalHandler = null;
    fNewLine = newLine;

    fNSBinder = new NamespaceSupport();
    fLocalNSBinder = new NamespaceSupport();

    fDOMConfigProperties = fSerializer.getOutputFormat();
    fSerializer.setDocumentLocator(fLocator);
    initProperties(fDOMConfigProperties);
}
 
Example #2
Source File: DOMNormalizer.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example #3
Source File: DOMNormalizer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example #4
Source File: DOMNormalizer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example #5
Source File: DOMNormalizer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example #6
Source File: DOMNormalizer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example #7
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor.
 * @param   contentHandler serialHandler The implemention of the SerializationHandler interface
 */
DOM3TreeWalker(
    SerializationHandler serialHandler,
    DOMErrorHandler errHandler,
    LSSerializerFilter filter,
    String newLine) {
    fSerializer = serialHandler;
    //fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
    fErrorHandler = errHandler;
    fFilter = filter;
    fLexicalHandler = null;
    fNewLine = newLine;

    fNSBinder = new NamespaceSupport();
    fLocalNSBinder = new NamespaceSupport();

    fDOMConfigProperties = fSerializer.getOutputFormat();
    fSerializer.setDocumentLocator(fLocator);
    initProperties(fDOMConfigProperties);
}
 
Example #8
Source File: DOMNormalizer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example #9
Source File: DOMNormalizer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example #10
Source File: DOMNormalizer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw abort;
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw abort;
}
 
Example #11
Source File: XSParser.java    From jlibs with Apache License 2.0 6 votes vote down vote up
public XSParser(LSResourceResolver entityResolver, DOMErrorHandler errorHandler){
    System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName());
    DOMImplementationRegistry registry;
    try{
        registry = DOMImplementationRegistry.newInstance();
    }catch(Exception ex){
        throw new ImpossibleException(ex);
    }
    XSImplementationImpl xsImpl = (XSImplementationImpl)registry.getDOMImplementation("XS-Loader");

    xsLoader = xsImpl.createXSLoader(null);
    DOMConfiguration config = xsLoader.getConfig();

    config.setParameter(Constants.DOM_VALIDATE, Boolean.TRUE);

    if(entityResolver!=null)
        config.setParameter(Constants.DOM_RESOURCE_RESOLVER, entityResolver);

    if(errorHandler!=null)
        config.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler);
}
 
Example #12
Source File: DOMNormalizer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example #13
Source File: DOMNormalizer.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Reports a DOM error to the user handler.
 *
 * If the error is fatal, the processing will be always aborted.
 */
public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
                    String message, short severity, String type ) {
    if( errorHandler!=null ) {
        error.reset();
        error.fMessage = message;
        error.fSeverity = severity;
        error.fLocator = locator;
        error.fType = type;
        error.fRelatedData = locator.fRelatedNode;

        if(!errorHandler.handleError(error))
            throw new AbortException();
    }
    if( severity==DOMError.SEVERITY_FATAL_ERROR )
        throw new AbortException();
}
 
Example #14
Source File: LSSerializerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if setting a parameter to a specific value is supported.
 *
 * @see org.w3c.dom.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
 * @since DOM Level 3
 * @param name A String containing the DOMConfiguration parameter name.
 * @param value An Object specifying the value of the corresponding parameter.
 */
public boolean canSetParameter(String name, Object value) {
    if (value instanceof Boolean){
        if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
                || name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)
                || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)
                || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)
                || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)
                || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)
                || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)
                || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)
                || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
                || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
                || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
                || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
            // both values supported
            return true;
        }
        else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
                || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
                || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
                || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
                || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
                // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
                ) {
            // true is not supported
            return !((Boolean)value).booleanValue();
        }
        else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
            // false is not supported
            return ((Boolean)value).booleanValue();
        }
    }
    else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
            value == null || value instanceof DOMErrorHandler){
        return true;
    }
    return false;
}
 
Example #15
Source File: CMXSDContentModelProvider.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public XSLoaderImpl getLoader() {		
	XSLoaderImpl loader = new XSLoaderImpl();
	loader.setParameter("http://apache.org/xml/properties/internal/entity-resolver", resolverExtensionManager);
	loader.setParameter(Constants.DOM_ERROR_HANDLER, new DOMErrorHandler() {

		@Override
		public boolean handleError(DOMError error) {
			if (error.getRelatedException() instanceof CacheResourceDownloadingException) {
				throw ((CacheResourceDownloadingException) error.getRelatedException());
			}
			return false;
		}
	});
	return loader;
}
 
Example #16
Source File: LSSerializerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if setting a parameter to a specific value is supported.
 *
 * @see org.w3c.dom.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
 * @since DOM Level 3
 * @param name A String containing the DOMConfiguration parameter name.
 * @param value An Object specifying the value of the corresponding parameter.
 */
public boolean canSetParameter(String name, Object value) {
    if (value instanceof Boolean){
        if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
                || name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)
                || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)
                || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)
                || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)
                || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)
                || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)
                || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)
                || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
                || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
                || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
                || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
            // both values supported
            return true;
        }
        else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
                || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
                || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
                || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
                || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
                // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
                ) {
            // true is not supported
            return !((Boolean)value).booleanValue();
        }
        else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
            // false is not supported
            return ((Boolean)value).booleanValue();
        }
    }
    else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
            value == null || value instanceof DOMErrorHandler){
        return true;
    }
    return false;
}
 
Example #17
Source File: DOM3TreeWalker.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 * @param   contentHandler serialHandler The implemention of the SerializationHandler interface
 */
DOM3TreeWalker(
    SerializationHandler serialHandler,
    DOMErrorHandler errHandler,
    LSSerializerFilter filter,
    String newLine) {
    fSerializer = serialHandler;
    //fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
    fErrorHandler = errHandler;
    fFilter = filter;
    fLexicalHandler = null;
    fNewLine = newLine;

    fNSBinder = new NamespaceSupport();
    fLocalNSBinder = new NamespaceSupport();
    
    fDOMConfigProperties = fSerializer.getOutputFormat();
    fSerializer.setDocumentLocator(fLocator);
    initProperties(fDOMConfigProperties);
    
    try {
        // Bug see Bugzilla  26741
        fLocator.setSystemId(
            System.getProperty("user.dir") + File.separator + "dummy.xsl");
    } catch (SecurityException se) { // user.dir not accessible from applet

    }
}
 
Example #18
Source File: DOMParserImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean canSetParameter (String name, Object value) {
    if (value == null){
            return true;
    }

    if(value instanceof Boolean){
        boolean state = ((Boolean)value).booleanValue ();
        if ( name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY)
        || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
        || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION )
        || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM) ) {
            // true is not supported
            return (state) ? false : true;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_WELLFORMED)
        || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
            // false is not supported
            return (state) ? true : false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_CDATA_SECTIONS)
        || name.equalsIgnoreCase (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING)
        || name.equalsIgnoreCase (Constants.DOM_COMMENTS)
        || name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION)
        || name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE)
        || name.equalsIgnoreCase (Constants.DOM_ENTITIES)
        || name.equalsIgnoreCase (Constants.DOM_INFOSET)
        || name.equalsIgnoreCase (Constants.DOM_NAMESPACES)
        || name.equalsIgnoreCase (Constants.DOM_NAMESPACE_DECLARATIONS)
        || name.equalsIgnoreCase (Constants.DOM_VALIDATE)
        || name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA)
        || name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE)
        || name.equalsIgnoreCase (Constants.DOM_XMLDECL)) {
            return true;
        }

        // Recognize Xerces features.
        try {
            String normalizedName;
            if (name.equalsIgnoreCase(NAMESPACE_GROWTH)) {
                normalizedName = NAMESPACE_GROWTH;
            }
            else if (name.equalsIgnoreCase(TOLERATE_DUPLICATES)) {
                normalizedName = TOLERATE_DUPLICATES;
            }
            else {
                normalizedName = name.toLowerCase(Locale.ENGLISH);
            }
            fConfiguration.getFeature(normalizedName);
            return true;
        }
        catch (XMLConfigurationException e) {
            return false;
        }
    }
    else { // check properties
        if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) {
            if (value instanceof DOMErrorHandler || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) {
            if (value instanceof LSResourceResolver || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) {
            if ((value instanceof String
            && (value.equals (Constants.NS_XMLSCHEMA)
            || value.equals (Constants.NS_DTD))) || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) {
            if (value instanceof String || value == null)
                return true;
            return false;
        }
        else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)){
            return true;
        }
        return false;
    }
}
 
Example #19
Source File: DOMErrorHandlerWrapper.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public DOMErrorHandler getErrorHandler(){
    return fDomErrorHandler;
}
 
Example #20
Source File: LSParserTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testDOMConfiguration() {

    final DOMErrorHandler handler = new DOMErrorHandler() {
        public boolean handleError(final DOMError error) {
            return false;
        }
    };

    final LSResourceResolver resolver = new LSResourceResolver() {
        public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
            return null;
        }
    };

    final Object[][] values = {
            // parameter, value
            { "canonical-form", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, { "cdata-sections", Boolean.TRUE },
            { "check-character-normalization", Boolean.FALSE }, { "comments", Boolean.FALSE }, { "comments", Boolean.TRUE },
            { "datatype-normalization", Boolean.FALSE }, { "entities", Boolean.FALSE }, { "entities", Boolean.TRUE }, { "error-handler", handler },
            { "infoset", Boolean.TRUE }, { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE },
            { "namespace-declarations", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "split-cdata-sections", Boolean.TRUE },
            { "split-cdata-sections", Boolean.FALSE }, { "validate", Boolean.FALSE }, { "validate-if-schema", Boolean.FALSE },
            { "well-formed", Boolean.TRUE }, { "element-content-whitespace", Boolean.TRUE },

            { "charset-overrides-xml-encoding", Boolean.TRUE }, { "charset-overrides-xml-encoding", Boolean.FALSE }, { "disallow-doctype", Boolean.FALSE },
            { "ignore-unknown-character-denormalizations", Boolean.TRUE }, { "resource-resolver", resolver }, { "resource-resolver", null },
            { "supported-media-types-only", Boolean.FALSE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    }

    DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");

    LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    DOMConfiguration config = lsParser.getDomConfig();

    for (int i = values.length; --i >= 0;) {
        Object val = values[i][1];
        String param = (String) values[i][0];
        try {
            config.setParameter(param, val);
            Object returned = config.getParameter(param);
            Assert.assertEquals(val, returned, "'" + param + "' is set to " + returned + ", but expected " + val);
            System.out.println("set '" + param + "'" + " to '" + val + "'" + " and returned '" + returned + "'");
        } catch (DOMException e) {
            String settings = "setting '" + param + "' to " + val;
            System.err.println(settings);
            e.printStackTrace();
            Assert.fail(settings + ", " + e.toString());
        }
    }
}
 
Example #21
Source File: DOMErrorHandlerWrapper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public DOMErrorHandler getErrorHandler(){
    return fDomErrorHandler;
}
 
Example #22
Source File: DOMNormalizer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Normalizes document.
* Note: reset() must be called before this method.
*/
   protected void normalizeDocument(CoreDocumentImpl document, DOMConfigurationImpl config) {

           fDocument = document;
           fConfiguration = config;

           // intialize and reset DOMNormalizer component
           //
           fSymbolTable = (SymbolTable) fConfiguration.getProperty(DOMConfigurationImpl.SYMBOL_TABLE);
           // reset namespace context
           fNamespaceContext.reset();
           fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING);

           if ((fConfiguration.features & DOMConfigurationImpl.VALIDATE) != 0) {
       String schemaLang = (String)fConfiguration.getProperty(DOMConfigurationImpl.JAXP_SCHEMA_LANGUAGE);

       if(schemaLang != null && schemaLang.equals(Constants.NS_XMLSCHEMA)) {
                   fValidationHandler =
                           CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA);
           fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true);
           fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA_FULL_CHECKING, true);
           // report fatal error on DOM Level 1 nodes
           fNamespaceValidation = true;

           // check if we need to fill in PSVI
           fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false;
       }

                   fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);

       // reset ID table
       fDocument.clearIdentifiers();

       if(fValidationHandler != null)
       // reset schema validator
           ((XMLComponent) fValidationHandler).reset(fConfiguration);

           }

           fErrorHandler = (DOMErrorHandler) fConfiguration.getParameter(Constants.DOM_ERROR_HANDLER);
           if (fValidationHandler != null) {
                   fValidationHandler.setDocumentHandler(this);
                   fValidationHandler.startDocument(
               new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI,
                                           -1, -1 ), fDocument.encoding, fNamespaceContext, null);

           }
           try {
                   Node kid, next;
                   for (kid = fDocument.getFirstChild(); kid != null; kid = next) {
                           next = kid.getNextSibling();
                           kid = normalizeNode(kid);
                           if (kid != null) { // don't advance
                                   next = kid;
                           }
                   }

                   // release resources
                   if (fValidationHandler != null) {
                           fValidationHandler.endDocument(null);
                           CoreDOMImplementationImpl.singleton.releaseValidator(
                                   XMLGrammarDescription.XML_SCHEMA, fValidationHandler);
                           fValidationHandler = null;
                   }
           } catch (AbortException e) {
               return;
           }

   }
 
Example #23
Source File: DOMErrorHandlerWrapper.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/** Sets the DOM error handler. */
public void setErrorHandler(DOMErrorHandler errorHandler) {
    fDomErrorHandler = errorHandler;
}
 
Example #24
Source File: DOMErrorHandlerWrapper.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public DOMErrorHandlerWrapper(DOMErrorHandler domErrorHandler) {
    fDomErrorHandler = domErrorHandler;
}
 
Example #25
Source File: DOMConfigurationImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
* DOM Level 3 WD - Experimental.
* Check if setting a parameter to a specific value is supported.
*
* @param name The name of the parameter to check.
*
* @param value An object. if null, the returned value is true.
*
* @return true if the parameter could be successfully set to the
* specified value, or false if the parameter is not recognized or
* the requested value is not supported. This does not change the
* current value of the parameter itself.
*/
   public boolean canSetParameter(String name, Object value) {

   if (value == null){
       //if null, the returned value is true.
       //REVISIT: I dont like this --- even for unrecognized parameter it would
       //return 'true'. I think it should return false in that case.
       // Application will be surprised to find that setParameter throws not
       //recognized exception when canSetParameter returns 'true' Then what is the use
       //of having canSetParameter ??? - nb.
       return true ;
   }
   if( value instanceof Boolean ){
       //features whose parameter value can be set either 'true' or 'false'
       // or they accept any boolean value -- so we just need to check that
       // its a boolean value..
       if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)
           || name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)
           || name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)
           || name.equalsIgnoreCase(Constants.DOM_ENTITIES)
           || name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)
           || name.equalsIgnoreCase(Constants.DOM_NAMESPACES)
           || name.equalsIgnoreCase(Constants.DOM_VALIDATE)
           || name.equalsIgnoreCase(Constants.DOM_WELLFORMED)
           || name.equalsIgnoreCase(Constants.DOM_INFOSET)
           || name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)
           ) {
           return true;
       }//features whose parameter value can not be set to 'true'
       else if (
           name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
               || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
               || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
               || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)
               ) {
               return (value.equals(Boolean.TRUE)) ? false : true;
       }//features whose parameter value can not be set to 'false'
       else if( name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)
               || name.equalsIgnoreCase(SEND_PSVI)
               ) {
               return (value.equals(Boolean.TRUE)) ? true : false;
       }// if name is not among the above listed above -- its not recognized. return false
       else {
           return false ;
       }
   }
           else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
       return (value instanceof DOMErrorHandler) ? true : false ;
   }
   else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
       return (value instanceof LSResourceResolver) ? true : false ;
   }
   else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
       return (value instanceof String) ? true : false ;
   }
   else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
       // REVISIT: should null value be supported?
       // as of now we are only supporting W3C XML Schema and DTD.
       return ((value instanceof String) &&
               (value.equals(Constants.NS_XMLSCHEMA) || value.equals(Constants.NS_DTD))) ? true : false;
   }
   else if (name.equalsIgnoreCase(ENTITY_RESOLVER)) {
       return (value instanceof XMLEntityResolver) ? true : false;
   }
   else if (name.equalsIgnoreCase(SYMBOL_TABLE)) {
       // Xerces Symbol Table
       return (value instanceof SymbolTable) ? true : false;
   }
   else if (name.equalsIgnoreCase (GRAMMAR_POOL)) {
       return (value instanceof XMLGrammarPool) ? true : false;
   }
   else {
       //false if the parameter is not recognized or the requested value is not supported.
       return false ;
   }

   }
 
Example #26
Source File: DOMParserImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public boolean canSetParameter (String name, Object value) {
    if (value == null){
            return true;
    }

    if(value instanceof Boolean){
        boolean state = ((Boolean)value).booleanValue ();
        if ( name.equalsIgnoreCase (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY)
        || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
        || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION )
        || name.equalsIgnoreCase (Constants.DOM_CANONICAL_FORM) ) {
            // true is not supported
            return (state) ? false : true;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_WELLFORMED)
        || name.equalsIgnoreCase (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
            // false is not supported
            return (state) ? true : false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_CDATA_SECTIONS)
        || name.equalsIgnoreCase (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING)
        || name.equalsIgnoreCase (Constants.DOM_COMMENTS)
        || name.equalsIgnoreCase (Constants.DOM_DATATYPE_NORMALIZATION)
        || name.equalsIgnoreCase (Constants.DOM_DISALLOW_DOCTYPE)
        || name.equalsIgnoreCase (Constants.DOM_ENTITIES)
        || name.equalsIgnoreCase (Constants.DOM_INFOSET)
        || name.equalsIgnoreCase (Constants.DOM_NAMESPACES)
        || name.equalsIgnoreCase (Constants.DOM_NAMESPACE_DECLARATIONS)
        || name.equalsIgnoreCase (Constants.DOM_VALIDATE)
        || name.equalsIgnoreCase (Constants.DOM_VALIDATE_IF_SCHEMA)
        || name.equalsIgnoreCase (Constants.DOM_ELEMENT_CONTENT_WHITESPACE)
        || name.equalsIgnoreCase (Constants.DOM_XMLDECL)) {
            return true;
        }

        // Recognize Xerces features.
        try {
            String normalizedName;
            if (name.equalsIgnoreCase(NAMESPACE_GROWTH)) {
                normalizedName = NAMESPACE_GROWTH;
            }
            else if (name.equalsIgnoreCase(TOLERATE_DUPLICATES)) {
                normalizedName = TOLERATE_DUPLICATES;
            }
            else {
                normalizedName = name.toLowerCase(Locale.ENGLISH);
            }
            fConfiguration.getFeature(normalizedName);
            return true;
        }
        catch (XMLConfigurationException e) {
            return false;
        }
    }
    else { // check properties
        if (name.equalsIgnoreCase (Constants.DOM_ERROR_HANDLER)) {
            if (value instanceof DOMErrorHandler || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_RESOURCE_RESOLVER)) {
            if (value instanceof LSResourceResolver || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_TYPE)) {
            if ((value instanceof String
            && (value.equals (Constants.NS_XMLSCHEMA)
            || value.equals (Constants.NS_DTD))) || value == null) {
                return true;
            }
            return false;
        }
        else if (name.equalsIgnoreCase (Constants.DOM_SCHEMA_LOCATION)) {
            if (value instanceof String || value == null)
                return true;
            return false;
        }
        else if (name.equalsIgnoreCase (DOCUMENT_CLASS_NAME)){
            return true;
        }
        return false;
    }
}
 
Example #27
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void tryToParseSchemas() throws Exception {
    // Get DOM Implementation using DOM Registry
    final List<DOMLSInput> inputs = new ArrayList<>();
    final Map<String, LSInput> resolverMap = new HashMap<>();

    for (XmlSchema schema : collection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
        DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
        dumpSchema(document);
        resolverMap.put(schema.getTargetNamespace(), input);
        inputs.add(input);
    }

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XS-Loader");


    try {
        Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
        DOMConfiguration config = (DOMConfiguration)findMethod(schemaLoader, "getConfig").invoke(schemaLoader);

        config.setParameter("validate", Boolean.TRUE);
        try {
            //bug in the JDK doesn't set this, but accesses it
            config.setParameter("http://www.oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager",
                                Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager")
                                    .newInstance());

            config.setParameter("http://apache.org/xml/properties/security-manager",
                                Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityManager")
                                    .newInstance());
        } catch (Throwable t) {
            //ignore
        }
        config.setParameter("error-handler", new DOMErrorHandler() {

            public boolean handleError(DOMError error) {
                LOG.info("Schema parsing error: " + error.getMessage()
                         + " " + error.getType()
                         + " " + error.getLocation().getUri()
                         + " " + error.getLocation().getLineNumber()
                         + ":" + error.getLocation().getColumnNumber());
                throw new DOMErrorException(error);
            }
        });
        config.setParameter("resource-resolver", new LSResourceResolver() {

            public LSInput resolveResource(String type, String namespaceURI, String publicId,
                                           String systemId, String baseURI) {
                return resolverMap.get(namespaceURI);
            }
        });

        Method m = findMethod(schemaLoader, "loadInputList");
        String name = m.getParameterTypes()[0].getName() + "Impl";
        name = name.replace("xs.LS", "impl.xs.util.LS");
        Class<?> c = Class.forName(name);
        Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE)
        .newInstance(inputs.toArray(new LSInput[0]), inputs.size());

        findMethod(schemaLoader, "loadInputList").invoke(schemaLoader, inputList);
    } catch (InvocationTargetException ite) {
        throw (Exception)ite.getTargetException();
    }
}
 
Example #28
Source File: DOMErrorHandlerWrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public DOMErrorHandler getErrorHandler(){
    return fDomErrorHandler;
}
 
Example #29
Source File: DOMErrorHandlerWrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Sets the DOM error handler. */
public void setErrorHandler(DOMErrorHandler errorHandler) {
    fDomErrorHandler = errorHandler;
}
 
Example #30
Source File: DOMErrorHandlerWrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public DOMErrorHandlerWrapper(DOMErrorHandler domErrorHandler) {
    fDomErrorHandler = domErrorHandler;
}