/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
public void setFeature(String name, boolean value) throws SAXNotSupportedException, SAXNotRecognizedException { actual.setFeature(name, value); }
/** * Creates schema factory * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException */ private SchemaFactory createSchemaFactory() throws SAXNotRecognizedException, SAXNotSupportedException { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,true); return factory; }
/** * Creates schema factory * @return * @throws SAXNotRecognizedException * @throws SAXNotSupportedException */ private SchemaFactory createSchemaFactory() throws SAXNotRecognizedException, SAXNotSupportedException { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,true); return factory; }
javax.xml.validation.SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory .setFeature( "http://apache.org/xml/features/validation/schema-full-checking", false);
/** * Extends SchemaFactory.setFeature by implementing the secure processing feature. * The implementation simply sets an internal flag, which can be accessed using * getSecureProcessing. * @see SchemaFactory#setFeature * @see #getSecureProcessing */ public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name)) secureProcessing = value; else super.setFeature(name, value); }
/** * Extends SchemaFactory.setFeature by implementing the secure processing feature. * The implementation simply sets an internal flag, which can be accessed using * getSecureProcessing. * @see SchemaFactory#setFeature * @see #getSecureProcessing */ public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name)) secureProcessing = value; else super.setFeature(name, value); }
private Schema loadDataciteSchema() { try { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false); URL localSchemaURL = MCRDOIService.class.getClassLoader().getResource(schemaPath); if (localSchemaURL == null) { throw new MCRConfigurationException(schemaPath + " was not found!"); } return schemaFactory.newSchema(localSchemaURL); } catch (SAXException e) { throw new MCRConfigurationException("Error while loading datacite schema!", e); } }
private Schema createSchema(String[] schemas) throws SAXException, IOException { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); SchemaResourceResolver resourceResolver = new SchemaResourceResolver(); sf.setResourceResolver(resourceResolver); Source[] sources = new Source[schemas.length]; for (int i = 0; i < schemas.length; i++) { // need to validate the schema file Document doc = docBuilder.parse(schemas[i]); DOMSource stream = new DOMSource(doc, schemas[i]); sources[i] = stream; } return sf.newSchema(sources); }
private Schema createSchema(String[] schemas) throws SAXException, IOException { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); SchemaResourceResolver resourceResolver = new SchemaResourceResolver(); sf.setResourceResolver(resourceResolver); Source[] sources = new Source[schemas.length]; for (int i = 0; i < schemas.length; i++) { // need to validate the schema file Document doc = docBuilder.parse(schemas[i]); DOMSource stream = new DOMSource(doc, schemas[i]); sources[i] = stream; } return sf.newSchema(sources); }
/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
/** * We offer parameters for artemisInstance and artemisHome as they could be coming from the CLI or Maven Plugin */ public static <T> T decode(Class<T> clazz, File configuration, String artemisHome, String artemisInstance, URI artemisURIInstance) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.activemq.artemis.dto"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false); InputStream xsdStream = XmlUtil.class.getClassLoader().getResourceAsStream("org.apache.activemq/dto/activemq.xsd"); StreamSource xsdSource = new StreamSource(xsdStream); Schema schema = sf.newSchema(xsdSource); unmarshaller.setSchema(schema); Properties props = new Properties(System.getProperties()); if (artemisHome != null) { props.put("artemis.home", artemisHome); } if (artemisInstance != null) { props.put("artemis.instance", artemisInstance); } if (artemisURIInstance != null) { props.put("artemis.URI.instance", artemisURIInstance.toString()); } XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream(configuration)); reader = new PropertiesFilter(reader, props); return clazz.cast(unmarshaller.unmarshal(reader)); }
/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
/** * Returns properly configured (e.g. security features) schema factory * - namespaceAware == true * - securityProcessing == is set based on security processing property, default is true */ public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException { try { SchemaFactory factory = SchemaFactory.newInstance(language); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SchemaFactory instance: {0}", factory); } factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing)); return factory; } catch (SAXNotRecognizedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (SAXNotSupportedException ex) { LOGGER.log(Level.SEVERE, null, ex); throw new IllegalStateException(ex); } catch (AbstractMethodError er) { LOGGER.log(Level.SEVERE, null, er); throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er); } }
private Schema createSchema(List<InputSource> xsdsInJar, String[] schemas) throws SAXException, IOException { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); sf.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file"); SchemaResourceResolver resourceResolver = new SchemaResourceResolver(); sf.setResourceResolver(resourceResolver); List<Source> sources = new ArrayList<>(); for (InputSource is : xsdsInJar) { Message msg = new Message("CREATE_SCHEMA_LOADED_FROM_JAR", LOG, is.getSystemId()); LOG.log(Level.FINE, msg.toString()); Document doc = docBuilder.parse(is.getByteStream()); DOMSource stream = new DOMSource(doc, is.getSystemId()); stream.setSystemId(is.getSystemId()); sources.add(stream); } if (schemas != null) { for (int i = 0; i < schemas.length; i++) { Document doc = docBuilder.parse(schemas[i]); DOMSource stream = new DOMSource(doc, schemas[i]); sources.add(stream); } } Source[] args = new Source[sources.size()]; sources.toArray(args); return sf.newSchema(args); }
private Schema createSchema(List<InputSource> xsdsInJar, String[] schemas) throws SAXException, IOException { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); sf.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file"); SchemaResourceResolver resourceResolver = new SchemaResourceResolver(); sf.setResourceResolver(resourceResolver); List<Source> sources = new ArrayList<>(); for (InputSource is : xsdsInJar) { Message msg = new Message("CREATE_SCHEMA_LOADED_FROM_JAR", LOG, is.getSystemId()); LOG.log(Level.FINE, msg.toString()); Document doc = docBuilder.parse(is.getByteStream()); DOMSource stream = new DOMSource(doc, is.getSystemId()); stream.setSystemId(is.getSystemId()); sources.add(stream); } if (schemas != null) { for (int i = 0; i < schemas.length; i++) { Document doc = docBuilder.parse(schemas[i]); DOMSource stream = new DOMSource(doc, schemas[i]); sources.add(stream); } } Source[] args = new Source[sources.size()]; sources.toArray(args); return sf.newSchema(args); }
/** * add a feature which need to set for the Schema Factory * * @param featureName The name of the feature * @param isFeatureEnable should this feature enable?(true|false) * @throws SAXException on an unknown feature * @see #getFeature(String) */ public void addFeature(String featureName, boolean isFeatureEnable) throws SAXException { MediatorProperty mp = new MediatorProperty(); mp.setName(featureName); if (isFeatureEnable) { mp.setValue("true"); } else { mp.setValue("false"); } explicityFeatures.add(mp); factory.setFeature(featureName, isFeatureEnable); }
/** * add a feature which need to set for the Schema Factory * * @param featureName The name of the feature * @param isFeatureEnable should this feature enable?(true|false) * @see #getFeature(String) * @throws SAXException on an unknown feature */ public void addFeature(String featureName, boolean isFeatureEnable) throws SAXException { MediatorProperty mp = new MediatorProperty(); mp.setName(featureName); if (isFeatureEnable) { mp.setValue("true"); } else { mp.setValue("false"); } explicityFeatures.add(mp); factory.setFeature(featureName, isFeatureEnable); }