org.w3c.dom.ls.LSResourceResolver Java Examples

The following examples show how to use org.w3c.dom.ls.LSResourceResolver. 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: XsdBasedValidator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected Schema getCompiledSchema(Source[] schemas,
        LSResourceResolver lsResourceResolver,
        ErrorHandler errorHandler) {
    
    Schema schema = null;
    
    // Create a compiled Schema object.
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schemaFactory.setResourceResolver(lsResourceResolver);
    schemaFactory.setErrorHandler(errorHandler);
    try {
        schema = schemaFactory.newSchema(schemas);            
    } catch(SAXException ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getCompiledSchema", ex);
    } 
    
    return schema;
}
 
Example #2
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 #3
Source File: JavaxXmlValidator.java    From iaf with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link Schema} associated with this validator. This is an XSD schema containing knowledge about the
 * schema source as returned by {@link #getSchemaSources(List)}
 */
protected synchronized Schema getSchemaObject(String schemasId, List<nl.nn.adapterframework.validation.Schema> schemas) throws  ConfigurationException {
	Schema schema = javaxSchemas.get(schemasId);
	if (schema == null) {
		SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		factory.setResourceResolver(new LSResourceResolver() {
			@Override
			public LSInput resolveResource(String s, String s1, String s2, String s3, String s4) {
				return null;
			}
		});
		try {
			Collection<Source> sources = getSchemaSources(schemas);
			schema = factory.newSchema(sources.toArray(new Source[sources.size()]));
			javaxSchemas.put(schemasId, schema);
		} catch (Exception e) {
			throw new ConfigurationException("cannot read schema's ["
					+ schemasId + "]", e);
		}
	}
	return schema;
}
 
Example #4
Source File: CatalogSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "data_SchemaA")
public void testValidationA(boolean setUseCatalog, boolean useCatalog,
        String catalog, String xsd, LSResourceResolver resolver)
        throws Exception {

    testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
}
 
Example #5
Source File: SchemaCache.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public SchemaCache (@Nonnull final String sSchemaTypeName,
                    @Nonnull final SchemaFactory aSchemaFactory,
                    @Nullable final ErrorHandler aErrorHandler,
                    @Nullable final LSResourceResolver aResourceResolver)
{
  super (aKey -> createSchema (aSchemaFactory, sSchemaTypeName, aKey),
         500,
         SchemaCache.class.getName () + "$" + sSchemaTypeName);
  ValueEnforcer.notNull (sSchemaTypeName, "SchemaTypeName");
  ValueEnforcer.notNull (aSchemaFactory, "SchemaFactory");
  m_sSchemaTypeName = sSchemaTypeName;
  m_aSchemaFactory = aSchemaFactory;
  m_aSchemaFactory.setErrorHandler (aErrorHandler);
  m_aSchemaFactory.setResourceResolver (aResourceResolver);
}
 
Example #6
Source File: CatalogSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "data_ValidatorA")
public Object[][] getDataValidator() {
    DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);

    SAXSource ss = new SAXSource(new InputSource(xml_val_test));
    ss.setSystemId(xml_val_test_id);

    StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);
    StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);

    StreamSource source = new StreamSource(new File(xml_val_test));

    String[] systemIds = {"system.dtd", "val_test.xsd"};
    XmlInput[] returnValues = {new XmlInput(null, dtd_system, null), new XmlInput(null, xsd_val_test, null)};
    LSResourceResolver resolver = new SourceResolver(null, systemIds, returnValues);

    StAXSource stax2 = getStaxSource(xml_val_test, xml_val_test_id, false, true, xml_catalog);

    return new Object[][]{
        // use catalog
        {false, false, true, ds, null, null, xml_catalog, null},
        {false, false, true, ds, null, null, null, xml_catalog},
        {false, false, true, ss, null, null, xml_catalog, null},
        {false, false, true, ss, null, null, null, xml_catalog},
        {false, false, true, stax, null, null, xml_catalog, null},
        {false, false, true, stax1, null, null, null, xml_catalog},
        {false, false, true, source, null, null, xml_catalog, null},
        {false, false, true, source, null, null, null, xml_catalog},
        // use resolver
        {false, false, true, ds, resolver, resolver, xml_bogus_catalog, xml_bogus_catalog},
        {false, false, true, ss, resolver, resolver, xml_bogus_catalog, xml_bogus_catalog},
        {false, false, true, stax2, resolver, resolver, xml_bogus_catalog, xml_bogus_catalog},
        {false, false, true, source, resolver, resolver, xml_bogus_catalog, xml_bogus_catalog}
    };
}
 
Example #7
Source File: SimpleLSResourceResolverTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testOSGIBundle () throws BundleException
{
  LSInput aRes;

  // Initializing Apache Felix as OSGI container is required to get the
  // "bundle" URL protocol installed correctly
  // Otherwise the first call would end up as a "file" resource ;-)
  final Framework aOSGI = new FrameworkFactory ().newFramework (new HashMap <String, String> ());
  aOSGI.start ();
  try
  {
    // Bundle 0 is the org.apache.felix.framework bundle
    final Bundle b = aOSGI.getBundleContext ().getBundle (0);
    assertNotNull (b);
    assertEquals (Bundle.ACTIVE, b.getState ());

    // No leading slash is important as the ClassLoader is used!
    assertNotNull (b.getResource ("org/apache/felix/framework/util/Util.class"));

    final LSResourceResolver aRR = new SimpleLSResourceResolver ();

    // No class loader
    aRes = aRR.resolveResource (XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                null,
                                null,
                                "../Felix.class",
                                "bundle://0.0:1/org/apache/felix/framework/util/Util.class");
    assertTrue (aRes instanceof ResourceLSInput);
    final IHasInputStream aISP = ((ResourceLSInput) aRes).getInputStreamProvider ();
    assertTrue (aISP instanceof URLResource);
    // Path maybe a "jar:file:" resource
    assertTrue (((URLResource) aISP).getPath ().endsWith ("org/apache/felix/framework/Felix.class"));
  }
  finally
  {
    aOSGI.stop ();
  }
}
 
Example #8
Source File: CatalogSupport4.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "data_SchemaA")
public void testValidationA(boolean setUseCatalog, boolean useCatalog,
        String catalog, String xsd, LSResourceResolver resolver)
        throws Exception {

    testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
}
 
Example #9
Source File: DOMConfigurationImpl.java    From openjdk-jdk8u with GNU General Public License v2.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
       return ( (value instanceof String) && value.equals(Constants.NS_XMLSCHEMA) ) ? 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 #10
Source File: DOMEntityResolverWrapper.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Wraps the specified DOM entity resolver. */
public DOMEntityResolverWrapper(LSResourceResolver entityResolver) {
    setEntityResolver(entityResolver);
}
 
Example #11
Source File: ValidatorImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setResourceResolver(LSResourceResolver resourceResolver) {
    fResourceResolverChanged = (resourceResolver != null);
    fComponentManager.setResourceResolver(resourceResolver);
}
 
Example #12
Source File: XercesSchemaValidationUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
void tryToParseSchemas(XmlSchemaCollection collection, DOMErrorHandler handler)
    throws Exception {

    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());
        resolverMap.put(schema.getTargetNamespace(), input);
        inputs.add(input);
    }

    try {

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

        config.setParameter("validate", Boolean.TRUE);
        config.setParameter("error-handler", handler);
        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());
        m.invoke(schemaLoader, inputList);
    } catch (InvocationTargetException e) {
        throw (Exception)e.getTargetException();
    }
}
 
Example #13
Source File: DOMConfigurationImpl.java    From JDKSourceCode1.8 with MIT License 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
       return ( (value instanceof String) && value.equals(Constants.NS_XMLSCHEMA) ) ? 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 #14
Source File: ValidatorImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public LSResourceResolver getResourceResolver() {
    return fComponentManager.getResourceResolver();
}
 
Example #15
Source File: XMLSchemaValidatorComponentManager.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
LSResourceResolver getResourceResolver() {
    return fResourceResolver;
}
 
Example #16
Source File: XMLSchemaFactory.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public LSResourceResolver getResourceResolver() {
    return fLSResourceResolver;
}
 
Example #17
Source File: RelaxNGCompactSchemaCache.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public RelaxNGCompactSchemaCache (@Nullable final ErrorHandler aErrorHandler,
                                  @Nullable final LSResourceResolver aResourceResolver)
{
  super ("RelaxNGCompact", SchemaFactory.newInstance (XMLConstants.RELAXNG_NS_URI), aErrorHandler, aResourceResolver);
}
 
Example #18
Source File: DOMParserImpl.java    From JDKSourceCode1.8 with MIT License 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: ValidatorImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setResourceResolver(LSResourceResolver resourceResolver) {
    fResourceResolverChanged = (resourceResolver != null);
    fComponentManager.setResourceResolver(resourceResolver);
}
 
Example #20
Source File: ValidatorHandlerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the DOM entity resolver. */
public LSResourceResolver getEntityResolver() {
    return fEntityResolver;
}
 
Example #21
Source File: XMLSchemaFactory.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public LSResourceResolver getResourceResolver() {
    return fLSResourceResolver;
}
 
Example #22
Source File: ValidatorImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public LSResourceResolver getResourceResolver() {
    return fComponentManager.getResourceResolver();
}
 
Example #23
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 #24
Source File: JAXPValidatorComponent.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param validatorHandler may not be null.
 */
public JAXPValidatorComponent( ValidatorHandler validatorHandler ) {
    this.validator = validatorHandler;
    TypeInfoProvider tip = validatorHandler.getTypeInfoProvider();
    if(tip==null)   tip = noInfoProvider;
    this.typeInfoProvider = tip;

    // configure wiring between internal components.
    xni2sax.setContentHandler(validator);
    validator.setContentHandler(sax2xni);
    this.setSide(xni2sax);

    // configure validator with proper EntityResolver/ErrorHandler.
    validator.setErrorHandler(new ErrorHandlerProxy() {
        protected XMLErrorHandler getErrorHandler() {
            XMLErrorHandler handler = fErrorReporter.getErrorHandler();
            if(handler!=null)   return handler;
            return new ErrorHandlerWrapper(DraconianErrorHandler.getInstance());
        }
    });
    validator.setResourceResolver(new LSResourceResolver() {
        public LSInput resolveResource(String type,String ns, String publicId, String systemId, String baseUri) {
            if(fEntityResolver==null)   return null;
            try {
                XMLInputSource is = fEntityResolver.resolveEntity(
                    new XMLResourceIdentifierImpl(publicId,systemId,baseUri,null));
                if(is==null)    return null;

                LSInput di = new DOMInputImpl();
                di.setBaseURI(is.getBaseSystemId());
                di.setByteStream(is.getByteStream());
                di.setCharacterStream(is.getCharacterStream());
                di.setEncoding(is.getEncoding());
                di.setPublicId(is.getPublicId());
                di.setSystemId(is.getSystemId());

                return di;
            } catch( IOException e ) {
                // erors thrown by the callback is not supposed to be
                // reported to users.
                throw new XNIException(e);
            }
        }
    });
}
 
Example #25
Source File: XMLSchemaFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setResourceResolver(LSResourceResolver resourceResolver) {
    fLSResourceResolver = resourceResolver;
    fDOMEntityResolverWrapper.setEntityResolver(resourceResolver);
    fXMLSchemaLoader.setEntityResolver(fDOMEntityResolverWrapper);
}
 
Example #26
Source File: ValidatorImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceResolver(LSResourceResolver resourceResolver) {
    fResourceResolverChanged = (resourceResolver != null);
    fComponentManager.setResourceResolver(resourceResolver);
}
 
Example #27
Source File: ValidatorHandlerImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void setResourceResolver(LSResourceResolver resourceResolver) {
    fComponentManager.setResourceResolver(resourceResolver);
}
 
Example #28
Source File: DOMEntityResolverWrapper.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/** Wraps the specified DOM entity resolver. */
public DOMEntityResolverWrapper(LSResourceResolver entityResolver) {
    setEntityResolver(entityResolver);
}
 
Example #29
Source File: DOMEntityResolverWrapper.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Sets the DOM entity resolver. */
public void setEntityResolver(LSResourceResolver entityResolver) {
    fEntityResolver = entityResolver;
}
 
Example #30
Source File: EntityResolverToLSResourceResolver.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public EntityResolverToLSResourceResolver(
        LSResourceResolver delegate, EntityResolver entityResolver) {
    this.entityResolver = entityResolver;
    this.delegate = delegate;
}