private void load() throws SAXException { int c = 0; for (String s : schemas.keySet()) if (s.endsWith(".xsd")) c++; StreamSource[] sources = new StreamSource[c]; int i = 0; for (String s : schemas.keySet()) { if (s.endsWith(".xsd")) { sources[i] = new StreamSource(new ByteArrayInputStream(schemas.get(s)), s); i++; } } SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setErrorHandler(new MyErrorHandler(errors, null)); schemaFactory.setResourceResolver(new MyResourceResolver()); schema = schemaFactory.newSchema(sources); }
public void setErrorHandler(ErrorHandler errorHandler) { actual.setErrorHandler(errorHandler); }
/** * Creates a new <code>javax.xml.validation.SchemaFactory</code> instance * for validation with XML Schema, which reports errors via the specified * error handler. */ public synchronized static SchemaFactory newFactory(ErrorHandler errHandler) { SchemaFactory fact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); fact.setErrorHandler(errHandler); return fact; }
private Schema parseSchema(ErrorHandler h) throws SAXException { SchemaFactory fac = factory != null ? factory : SchemaFactory.newInstance(schemaLanguage); fac.setErrorHandler(h); try { return fac.newSchema((Source[]) sources.toArray(new Source[sources.size()])); } finally { fac.setErrorHandler(null); } }
java.net.URL url = getClass().getResource("resources/main.xsd"); SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setErrorHandler(new CustomErrorHandler()); try { schema = schemaFactory.newSchema(url); } catch (SAXException e) { //... }
/** * Get the schema factory for this validator. * @return a <code>SchemaFactory</code> instance. */ public SchemaFactory getSchemaFactory() { synchronized(SchemaValidator.class) { if (sf == null) { sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); sf.setErrorHandler(new ValidatorErrorHandler(null)); } } return sf; }
/** * Get the schema factory for this validator. * @return a <code>SchemaFactory</code> instance. */ public SchemaFactory getSchemaFactory() { synchronized(SchemaValidator.class) { if (sf == null) { sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); sf.setErrorHandler(new ValidatorErrorHandler(null)); } } return sf; }
public ModelValidator() { final ErrorCollector schemaErrorCollector = new ErrorCollector(); schemaFactory.setErrorHandler(schemaErrorCollector); final URL schemaUrl = this.getClass().getResource(SCHEMA_RESOURCE); if (schemaUrl == null) { final String msg = "Could not load schema classpath resource '" + SCHEMA_RESOURCE + "'"; log.error(msg); throw new IllegalArgumentException(msg); } try { dcpSchema = schemaFactory.newSchema(schemaUrl); } catch (SAXException e) { final String msg = "Error parsing schema '" + schemaUrl.toString() + "': " + e.getMessage(); log.error(msg, e); throw new IllegalArgumentException(msg, e); } }
static private void initClusterXSDSchema() throws SAXException, IllegalArgumentException { if (schemaXSD == null) { // build an XSD-aware SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // hook up org.xml.sax.ErrorHandler implementation. schemaFactory.setErrorHandler(new DefaultErrorHandler()); // get the custom xsd schema describing the required format for cluster XML files. schemaXSD = schemaFactory.newSchema(ResourceLoader.getResourceURL("clusterXML-Schema.xsd")); } }
public DefaultSchemaCache (@Nonnull final String sSchemaTypeName, @Nonnull final SchemaFactory aSchemaFactory, @Nullable final ErrorHandler aErrorHandler, @Nullable final LSResourceResolver aResourceResolver) { super (DefaultSchemaCache.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); m_aErrorHandler = aErrorHandler; }
private void load() throws SAXException { int c = 0; for (String s : schemas.keySet()) if (s.endsWith(".xsd")) c++; StreamSource[] sources = new StreamSource[c]; int i = 0; for (String s : schemas.keySet()) { if (s.endsWith(".xsd")) { sources[i] = new StreamSource(new ByteArrayInputStream(schemas.get(s)), s); i++; } } SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setErrorHandler(new MyErrorHandler(errors, null)); schemaFactory.setResourceResolver(new MyResourceResolver()); schema = schemaFactory.newSchema(sources); }
private javax.xml.validation.Schema getSchema() throws SAXException { final SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setErrorHandler(this); sf.setResourceResolver(getResourceResolver()); return sf.newSchema(getSchemaSourcesArray()); }
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); }
private static Schema getSchema(String schemaPublicId) throws SAXException { Schema schema = schemaCache.get(schemaPublicId); if (schema == null) { synchronized (schemaCache) { schema = schemaCache.get(schemaPublicId); if (schema == null) { SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver( new MyLSResourceResolver()); schemaFactory.setErrorHandler(new MyErrorHandler()); schema = schemaFactory.newSchema(new StreamSource( ParserUtils.class.getResourceAsStream( schemaResourcePrefix + schemaPublicId))); schemaCache.put(schemaPublicId, schema); } } } return schema; }
/** * Validate the XML content against the XSD. * * The whole XML content must be valid. */ static void validateXML(String xmlContent, String xsdPath, Properties resolvedProperties) throws Exception { String resolvedXml = resolveAllExpressions(xmlContent, resolvedProperties); InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xsdPath); final Source source = new StreamSource(stream); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setErrorHandler(ERROR_HANDLER); schemaFactory.setResourceResolver(new JBossEntityResolver()); Schema schema = schemaFactory.newSchema(source); javax.xml.validation.Validator validator = schema.newValidator(); validator.setErrorHandler(ERROR_HANDLER); validator.setFeature("http://apache.org/xml/features/validation/schema", true); validator.validate(new StreamSource(new StringReader(resolvedXml))); }
/** * Validate the XML content against the XSD. * * The whole XML content must be valid. */ static void validateXML(String xmlContent, String xsdPath, Properties resolvedProperties) throws Exception { String resolvedXml = resolveAllExpressions(xmlContent, resolvedProperties); InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xsdPath); final Source source = new StreamSource(stream); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setErrorHandler(ERROR_HANDLER); schemaFactory.setResourceResolver(new JBossEntityResolver()); Schema schema = schemaFactory.newSchema(source); javax.xml.validation.Validator validator = schema.newValidator(); validator.setErrorHandler(ERROR_HANDLER); validator.setFeature("http://apache.org/xml/features/validation/schema", true); validator.validate(new StreamSource(new StringReader(resolvedXml))); }
private static Schema getSchema() throws IOException { schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); schemaFactory.setResourceResolver(new IDFedLSInputResolver()); schemaFactory.setErrorHandler(new CustomErrorHandler()); Schema schemaGrammar = null; try { schemaGrammar = schemaFactory.newSchema(sources()); } catch (SAXException e) { log.error("Cannot get schema", e); } return schemaGrammar; }
private static Schema getSchema() throws IOException { schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); schemaFactory.setResourceResolver(new IDFedLSInputResolver()); schemaFactory.setErrorHandler(new CustomErrorHandler()); Schema schemaGrammar = null; try { schemaGrammar = schemaFactory.newSchema(sources()); } catch (SAXException e) { log.error("Cannot get schema", e); } return schemaGrammar; }
@Override public ValidationResult validateSchema() { ValidationHandler v = new ValidationHandler(); SchemaFactory f = getFactory(); f.setErrorHandler(v); try { f.newSchema(getSchemaSources()); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } finally { f.setErrorHandler(null); } return v.getResult(); }
private Schema generateSchema(JAXBContext context, Class<?> type) { LocalResolver resolver = new LocalResolver(); generateSchemaFromContext(context, resolver); resolver.postProcess(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setErrorHandler(new StrictErrorHandler()); sf.setResourceResolver(resolver); return createSchema(sf, type, resolver); }