use of javax.xml.validation.SchemaFactory in project oxCore by GluuFederation.
the class FacesConfigPopulator method isValidFacesConfig.
/**
* Validates *.faces-config.xml file
*
* @param xml
* @return
*/
private boolean isValidFacesConfig(InputStream xml) {
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
InputStream xsd = this.getClass().getResourceAsStream(FACES_2_2_XSD);
Schema schema = factory.newSchema(new StreamSource(xsd));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(xml));
return true;
} catch (Exception ex) {
return false;
}
}
use of javax.xml.validation.SchemaFactory in project uPortal by Jasig.
the class BaseXsltDataUpgraderTest method loadSchema.
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException {
Assert.notEmpty(resources, "No resources given");
Assert.hasLength(schemaLanguage, "No schema language provided");
Source[] schemaSources = new Source[resources.length];
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
for (int i = 0; i < resources.length; i++) {
Assert.notNull(resources[i], "Resource is null");
Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist");
InputSource inputSource = SaxResourceUtils.createInputSource(resources[i]);
schemaSources[i] = new SAXSource(xmlReader, inputSource);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
return schemaFactory.newSchema(schemaSources);
}
use of javax.xml.validation.SchemaFactory in project webservices-axiom by apache.
the class ValidateSample method validate.
// START SNIPPET: sax
public void validate(InputStream in, URL schemaUrl) throws Exception {
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8");
SOAPEnvelope envelope = builder.getSOAPEnvelope();
OMElement bodyContent = envelope.getBody().getFirstElement();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaUrl);
Validator validator = schema.newValidator();
validator.validate(bodyContent.getSAXSource(true));
}
use of javax.xml.validation.SchemaFactory in project tomee by apache.
the class JaxbJavaee method validateJavaee.
/**
* validate the inputStream, which should be a Java EE standard deployment descriptor against its schema type
* Note, this method will use the new Java EE 6 schema to validate the old descriptors after changing their namespace and version.
*
* @param type
* @param in
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
*/
public static void validateJavaee(final JavaeeSchema type, final InputStream in) throws ParserConfigurationException, SAXException, IOException {
final URL javaeeSchemaURL = resolveJavaeeSchemaURL(type);
if (javaeeSchemaURL == null) {
throw new IllegalArgumentException("Can not find the xsd file against type:" + type);
}
final URL xmlSchemaURL = JaxbJavaee.getSchemaURL("xml.xsd");
if (xmlSchemaURL == null) {
throw new IllegalArgumentException("Can not find the xml.xsd file");
}
// get the parser
final SAXParserFactory parserfactory = SAXParserFactory.newInstance();
parserfactory.setNamespaceAware(true);
parserfactory.setValidating(false);
final SAXParser parser = parserfactory.newSAXParser();
// get the xml filter
final Javaee6SchemaFilter xmlFilter = new Javaee6SchemaFilter(parser.getXMLReader());
// get the source
final SAXSource sourceForValidate = new SAXSource(xmlFilter, new InputSource(in));
// get the schema
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final JaxbJavaeeSchemaResourceResolver resourceResolver = new JaxbJavaeeSchemaResourceResolver();
schemaFactory.setResourceResolver(resourceResolver);
final Schema schema = schemaFactory.newSchema(new Source[] { new StreamSource(xmlSchemaURL.openStream()), new StreamSource(javaeeSchemaURL.openStream()) });
// validate
schema.newValidator().validate(sourceForValidate);
}
use of javax.xml.validation.SchemaFactory in project jqa-core-framework by buschmais.
the class XmlReportTest method readReport.
private JqassistantReport readReport(String xmlReport) throws SAXException, JAXBException {
SchemaFactory xsdFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = xsdFactory.newSchema(new StreamSource(XmlReportTest.class.getResourceAsStream("/META-INF/xsd/jqassistant-report-1.3.xsd")));
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
StreamSource streamSource = new StreamSource(new StringReader(xmlReport));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema(schema);
return unmarshaller.unmarshal(streamSource, JqassistantReport.class).getValue();
}
Aggregations