use of javax.xml.validation.SchemaFactory in project hibernate-orm by hibernate.
the class JaxbCfgProcessor method resolveLocalSchema.
private Schema resolveLocalSchema(String schemaName, String schemaLanguage) {
URL url = classLoaderService.locateResource(schemaName);
if (url == null) {
throw new XsdException("Unable to locate schema [" + schemaName + "] via classpath", schemaName);
}
try {
InputStream schemaStream = url.openStream();
try {
StreamSource source = new StreamSource(url.openStream());
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
return schemaFactory.newSchema(source);
} catch (SAXException e) {
throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
} catch (IOException e) {
throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
} finally {
try {
schemaStream.close();
} catch (IOException e) {
log.debugf("Problem closing schema stream [%s]", e.toString());
}
}
} catch (IOException e) {
throw new XsdException("Stream error handling schema url [" + url.toExternalForm() + "]", schemaName);
}
}
use of javax.xml.validation.SchemaFactory in project hazelcast by hazelcast.
the class XmlClientConfigBuilderTest method testXSDConfigXML.
private void testXSDConfigXML(String xmlFileName) throws SAXException, IOException {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaResource = XMLConfigBuilderTest.class.getClassLoader().getResource("hazelcast-client-config-3.9.xsd");
InputStream xmlResource = XMLConfigBuilderTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Schema schema = factory.newSchema(schemaResource);
Source source = new StreamSource(xmlResource);
Validator validator = schema.newValidator();
try {
validator.validate(source);
} catch (SAXException ex) {
fail(xmlFileName + " is not valid because: " + ex.toString());
}
}
use of javax.xml.validation.SchemaFactory in project languagetool by languagetool-org.
the class XMLValidator method getValidator.
private Validator getValidator(URL xmlSchema) throws SAXException {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(xmlSchema);
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler());
return validator;
}
use of javax.xml.validation.SchemaFactory in project head by mifos.
the class MenuParser method parse.
/**
* Method to parse xml and return crude menu
*
* @return array of crude Menu objects
*/
public static Menu[] parse() throws SystemException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
SchemaFactory schfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schfactory.setErrorHandler(null);
Schema schema = schfactory.newSchema(new StreamSource(MifosResourceUtil.getClassPathResourceAsStream(FilePaths.MENUSCHEMA)));
factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setSchema(schema);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(FilePaths.MENUPATH));
NodeList tabNodeList = document.getElementsByTagName(MenuConstants.TOPMENUTAB);
Menu[] leftMenus = new Menu[tabNodeList.getLength()];
for (int i = 0; i < tabNodeList.getLength(); i++) {
leftMenus[i] = new Menu();
leftMenus[i].setTopMenuTabName(((Element) tabNodeList.item(i)).getAttribute(MenuConstants.NAME));
leftMenus[i].setMenuGroups(createMenuGroup(tabNodeList.item(i)));
String menuHeading = ((Element) tabNodeList.item(i)).getElementsByTagName(MenuConstants.LEFTMENULABEL).item(0).getFirstChild().getTextContent().trim();
leftMenus[i].setMenuHeading(menuHeading);
}
return leftMenus;
} catch (SAXParseException spe) {
throw new MenuParseException(spe);
} catch (SAXException sxe) {
throw new MenuParseException(sxe);
} catch (ParserConfigurationException pce) {
throw new MenuParseException(pce);
} catch (IOException ioe) {
throw new MenuParseException(ioe);
}
}
use of javax.xml.validation.SchemaFactory in project head by mifos.
the class TableTagParser method parser.
public Table parser(String file) throws TableTagParseException {
Table table = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
SchemaFactory schfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schfactory.setErrorHandler(null);
Schema schema = schfactory.newSchema(new StreamSource(MifosResourceUtil.getClassPathResourceAsURIString(FilePaths.CUSTOMTABLETAGXSD)));
factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setSchema(schema);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsURIString(file));
table = createTable(document);
} catch (Exception e) {
throw new TableTagParseException(e);
}
return table;
}
Aggregations