org.apache.xerces.impl.Constants Java Examples
The following examples show how to use
org.apache.xerces.impl.Constants.
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: TaskUtils.java From micro-integrator with Apache License 2.0 | 6 votes |
public static Document convertToDocument(File file) throws TaskException { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); fac.setXIncludeAware(false); fac.setExpandEntityReferences(false); try { fac.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); fac.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); fac.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(0); fac.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return fac.newDocumentBuilder().parse(file); } catch (Exception e) { throw new TaskException("Error in creating an XML document from file: " + e.getMessage(), TaskException.Code.CONFIG_ERROR, e); } }
Example #2
Source File: XMLParserUtils.java From teamengine with Apache License 2.0 | 6 votes |
/** * Creates a SAXParser that is configured to resolve XInclude references but * not perform schema validation. * * @param doBaseURIFixup * A boolean value that specifies whether or not to add xml:base * attributes when resolving xi:include elements; adding these * attributes may render an instance document schema-invalid. * @return An XInclude-aware SAXParser instance. * * @see <a href="http://www.w3.org/TR/xinclude/">XML Inclusions (XInclude) * Version 1.0, Second Edition</a> */ public static SAXParser createXIncludeAwareSAXParser(boolean doBaseURIFixup) { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setXIncludeAware(true); SAXParser parser = null; try { factory.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE, doBaseURIFixup); parser = factory.newSAXParser(); } catch (Exception x) { throw new RuntimeException(x); } return parser; }
Example #3
Source File: TaskUtils.java From carbon-commons with Apache License 2.0 | 6 votes |
public static Document convertToDocument(File file) throws TaskException { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); fac.setXIncludeAware(false); fac.setExpandEntityReferences(false); try { fac.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); fac.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); fac.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(0); fac.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return fac.newDocumentBuilder().parse(file); } catch (Exception e) { throw new TaskException("Error in creating an XML document from file: " + e.getMessage(), Code.CONFIG_ERROR, e); } }
Example #4
Source File: AbstractWSDLProcessor.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Returns a secured document builder to avoid XXE attacks * * @return secured document builder to avoid XXE attacks */ private DocumentBuilderFactory getSecuredDocumentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } catch (ParserConfigurationException e) { // Skip throwing the error as this exception doesn't break actual DocumentBuilderFactory creation log.error("Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE, e); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #5
Source File: APIMWSDLReader.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Deprecated private static DocumentBuilderFactory getSecuredDocumentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } catch (ParserConfigurationException e) { // Skip throwing the error as this exception doesn't break actual DocumentBuilderFactory creation log.error("Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE, e); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #6
Source File: Util.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Returns a secured DocumentBuilderFactory instance * * @return DocumentBuilderFactory */ public static DocumentBuilderFactory getSecuredDocumentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); } catch (ParserConfigurationException e) { log.error( "Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #7
Source File: Utils.java From balana with Apache License 2.0 | 6 votes |
/** * Create DocumentBuilderFactory with the XXE prevention measurements * * @return DocumentBuilderFactory instance */ public static DocumentBuilderFactory getSecuredDocumentBuilderFactory() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } catch (ParserConfigurationException e) { logger.error( "Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #8
Source File: XSParser.java From jlibs with Apache License 2.0 | 6 votes |
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 #9
Source File: IdentityUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Create DocumentBuilderFactory with the XXE and XEE prevention measurements. * * @return DocumentBuilderFactory instance */ public static DocumentBuilderFactory getSecuredDocumentBuilderFactory() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); } catch (ParserConfigurationException e) { log.error("Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE + " or secure-processing."); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #10
Source File: CarbonServerConfigurationService.java From micro-integrator with Apache License 2.0 | 6 votes |
private static DocumentBuilderFactory getSecuredDocumentBuilder() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setXIncludeAware(false); dbf.setExpandEntityReferences(false); try { dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); dbf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); dbf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); } catch (ParserConfigurationException e) { log.error( "Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE); } SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT); dbf.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); return dbf; }
Example #11
Source File: XSLTTransformer.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * This method provides a secured document builder which will secure XXE attacks. * * @param setIgnoreComments whether to set setIgnoringComments in DocumentBuilderFactory. * @return DocumentBuilder * @throws ParserConfigurationException */ private static DocumentBuilder getSecuredDocumentBuilder(boolean setIgnoreComments) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setIgnoringComments(setIgnoreComments); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setXIncludeAware(false); documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(0); documentBuilderFactory.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); documentBuilder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { throw new SAXException("Possible XML External Entity (XXE) attack. Skip resolving entity"); } }); return documentBuilder; }
Example #12
Source File: CMXSDContentModelProvider.java From lemminx with Eclipse Public License 2.0 | 5 votes |
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 #13
Source File: NDataSourceHelper.java From carbon-commons with Apache License 2.0 | 5 votes |
public static Element stringToElement(String xml) { if (xml == null || xml.trim().length() == 0) { return null; } try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(false); docFactory.setXIncludeAware(false); docFactory.setExpandEntityReferences(false); docFactory.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false); docFactory.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false); docFactory.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); SecurityManager securityManager = new SecurityManager(); securityManager.setEntityExpansionLimit(0); docFactory.setAttribute(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, securityManager); DocumentBuilder db = docFactory.newDocumentBuilder(); return db.parse(new ByteArrayInputStream(xml.getBytes())).getDocumentElement(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
Example #14
Source File: SchemaBuilder.java From xml-avro with Apache License 2.0 | 5 votes |
public Schema createSchema(LSInput input) { ErrorHandler errorHandler = new ErrorHandler(); XMLSchemaLoader loader = new XMLSchemaLoader(); if (resolver != null) loader.setEntityResolver(new EntityResolver(resolver)); loader.setErrorHandler(errorHandler); loader.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler); XSModel model = loader.load(input); errorHandler.throwExceptionIfHasError(); return createSchema(model); }
Example #15
Source File: XercesXmlValidator.java From iaf with Apache License 2.0 | 5 votes |
private synchronized PreparseResult preparse(String schemasId, List<Schema> schemas) throws ConfigurationException { SymbolTable symbolTable = getSymbolTable(); XMLGrammarPool grammarPool = new XMLGrammarPoolImpl(); Set<String> namespaceSet = new HashSet<String>(); XMLGrammarPreparser preparser = new XMLGrammarPreparser(symbolTable); preparser.setEntityResolver(new ClassLoaderXmlEntityResolver(getConfigurationClassLoader())); preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); preparser.setProperty(GRAMMAR_POOL, grammarPool); preparser.setFeature(NAMESPACES_FEATURE_ID, true); preparser.setFeature(VALIDATION_FEATURE_ID, true); preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true); preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, isFullSchemaChecking()); try { preparser.setProperty(XML_SCHEMA_VERSION_PROPERTY, isXmlSchema1_0() ? Constants.W3C_XML_SCHEMA10EX_NS_URI : Constants.W3C_XML_SCHEMA11_NS_URI); } catch (NoSuchFieldError e) { String msg="Cannot set property ["+XML_SCHEMA_VERSION_PROPERTY+"], requested xmlSchemaVersion ["+getXmlSchemaVersion()+"] xercesVersion ("+org.apache.xerces.impl.Version.getVersion()+"]"; if (isXmlSchema1_0()) { log.warn(msg+", assuming XML-Schema version 1.0 will be supported", e); } else { throw new ConfigurationException(msg, e); } } MyErrorHandler errorHandler = new MyErrorHandler(); errorHandler.warn = warn; preparser.setErrorHandler(errorHandler); for (Schema schema : schemas) { Grammar grammar = preparse(preparser, schemasId, schema); registerNamespaces(grammar, namespaceSet); } grammarPool.lockPool(); PreparseResult preparseResult = new PreparseResult(); preparseResult.setSchemasId(schemasId); preparseResult.setSymbolTable(symbolTable); preparseResult.setGrammarPool(grammarPool); preparseResult.setNamespaceSet(namespaceSet); return preparseResult; }
Example #16
Source File: DataStoreFactory.java From fess with Apache License 2.0 | 5 votes |
protected List<String> loadDataStoreNameList() { final Set<String> nameSet = new HashSet<>(); final File[] jarFiles = ResourceUtil.getPluginJarFiles(PluginHelper.ArtifactType.DATA_STORE.getId()); for (final File jarFile : jarFiles) { try (FileSystem fs = FileSystems.newFileSystem(jarFile.toPath(), ClassLoader.getSystemClassLoader())) { final Path xmlPath = fs.getPath("fess_ds++.xml"); try (InputStream is = Files.newInputStream(xmlPath)) { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(org.codelibs.fess.crawler.Constants.FEATURE_SECURE_PROCESSING, true); factory.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document doc = builder.parse(is); final NodeList nodeList = doc.getElementsByTagName("component"); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); final NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { final Node classAttr = attributes.getNamedItem("class"); if (classAttr != null) { final String value = classAttr.getNodeValue(); if (StringUtil.isNotBlank(value)) { final String[] values = value.split("\\."); nameSet.add(values[values.length - 1]); } } } } } } catch (final Exception e) { logger.warn("Failed to load " + jarFile.getAbsolutePath(), e); } } return nameSet.stream().sorted().collect(Collectors.toList()); }
Example #17
Source File: XMLParserUtilsTest.java From teamengine with Apache License 2.0 | 5 votes |
@Test public void xincludeParserNoBaseURIFixup() throws SAXException { SAXParser parser = XMLParserUtils.createXIncludeAwareSAXParser(false); assertNotNull(parser); XMLReader reader = parser.getXMLReader(); // Fortify mod to prevent External Entity Injections reader.setFeature("http://xml.org/sax/features/external-general-entities", false); boolean baseURIFixup = reader .getFeature(Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE); assertFalse("Expected feature to be false: " + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE, baseURIFixup); }
Example #18
Source File: XSParser.java From jlibs with Apache License 2.0 | 4 votes |
/** * for schema version "1.1", xerces 2.11.0-beta must be in classpath */ public void enableSchema11(){ xsLoader.getConfig().setParameter( Constants.XERCES_PROPERTY_PREFIX + "validation/schema/version", "http://www.w3.org/XML/XMLSchema/v1.1"); }
Example #19
Source File: XSDValidator.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public static void doDiagnostics(DOMDocument document, XMLEntityResolver entityResolver, List<Diagnostic> diagnostics, CancelChecker monitor) { try { XMLErrorReporter reporter = new LSPErrorReporterForXSD(document, diagnostics); XMLGrammarPreparser grammarPreparser = new LSPXMLGrammarPreparser(); XMLSchemaLoader schemaLoader = createSchemaLoader(reporter); grammarPreparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, schemaLoader); grammarPreparser.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, new XMLGrammarPoolImpl()); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, false); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, true); grammarPreparser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, true); // Add LSP content handler to stop XML parsing if monitor is canceled. // grammarPreparser.setContentHandler(new LSPContentHandler(monitor)); // Add LSP error reporter to fill LSP diagnostics from Xerces errors grammarPreparser.setProperty("http://apache.org/xml/properties/internal/error-reporter", reporter); if (entityResolver != null) { grammarPreparser.setEntityResolver(entityResolver); } String content = document.getText(); String uri = document.getDocumentURI(); InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); XMLInputSource is = new XMLInputSource(null, uri, uri, inputStream, null); grammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA); grammarPreparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, is); } catch (IOException | CancellationException | XMLParseException exception) { // ignore error } catch (Exception e) { LOGGER.log(Level.SEVERE, "Unexpected XSDValidator error", e); } }
Example #20
Source File: XSParser.java From jlibs with Apache License 2.0 | 2 votes |
/** * enables feature "http://apache.org/xml/features/honour-all-schemaLocations" * see https://xerces.apache.org/xerces2-j/features.html */ public void honourAllSchemaLocations(){ setParameter(Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE, true); }