List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI
String W3C_XML_SCHEMA_NS_URI
To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.
Click Source Link
From source file:org.raml.parser.visitor.SchemaCompiler.java
public Schema compile(String schema, String path) { Schema compiledSchema = null; String trimmedSchema = StringUtils.trimToEmpty(schema); if (trimmedSchema.startsWith("<") && trimmedSchema.endsWith(">")) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); ContextPath actualContextPath = contextPath; if (path != null) { actualContextPath = new ContextPath(new IncludeInfo(path)); }//w w w. j a v a2 s . c om factory.setResourceResolver(new XsdResourceResolver(actualContextPath, resourceLoader)); try { compiledSchema = factory.newSchema(new StreamSource(new StringReader(trimmedSchema))); } catch (Exception e) { //ignore exception as the error is detected by the validator // and here we cannot tell if the schema is intended for xml or not } } return compiledSchema; }
From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java
/** * Parses a descriptor from InputStream without a validator. * @param is input to check//from ww w .j a v a2s .com * @return parsed PluginDescriptor * @throws PluginContainerException if validation fails */ public static PluginDescriptor parsePluginDescriptor(InputStream is, ValidationEventCollector validationEventCollector) throws PluginContainerException { JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN); } catch (Exception e) { throw new PluginContainerException("Failed to create JAXB Context.", new WrappedRemotingException(e)); } Unmarshaller unmarshaller; try { unmarshaller = jaxbContext.createUnmarshaller(); // Enable schema validation URL pluginSchemaURL = AgentPluginDescriptorUtil.class.getClassLoader().getResource(PLUGIN_SCHEMA_PATH); Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(pluginSchemaURL); unmarshaller.setSchema(pluginSchema); unmarshaller.setEventHandler(validationEventCollector); PluginDescriptor pluginDescriptor = (PluginDescriptor) unmarshaller.unmarshal(is); return pluginDescriptor; } catch (JAXBException e) { throw new PluginContainerException(e); } catch (SAXException e) { throw new PluginContainerException(e); } }
From source file:org.rhq.enterprise.server.plugins.url.XmlIndexParser.java
@SuppressWarnings("unchecked") protected Map<String, RemotePackageInfo> jaxbParse(InputStream indexStream, URL indexUrl, String rootUrlString) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(XmlSchemas.PKG_CONTENTSOURCE_PACKAGEDETAILS); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); // Enable schema validation URL pluginSchemaURL = XmlIndexParser.class.getClassLoader().getResource(PLUGIN_SCHEMA_PATH); Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(pluginSchemaURL); unmarshaller.setSchema(pluginSchema); ValidationEventCollector vec = new ValidationEventCollector(); unmarshaller.setEventHandler(vec);/* w w w . ja v a 2s. com*/ BufferedReader reader = new BufferedReader(new InputStreamReader(indexStream)); JAXBElement<PackageType> packagesXml = (JAXBElement<PackageType>) unmarshaller.unmarshal(reader); for (ValidationEvent event : vec.getEvents()) { log.debug("URL content source index [" + indexUrl + "] message {Severity: " + event.getSeverity() + ", Message: " + event.getMessage() + ", Exception: " + event.getLinkedException() + "}"); } Map<String, RemotePackageInfo> fileList = new HashMap<String, RemotePackageInfo>(); List<PackageDetailsType> allPackages = packagesXml.getValue().getPackage(); for (PackageDetailsType pkg : allPackages) { URL locationUrl = new URL(rootUrlString + pkg.getLocation()); ContentProviderPackageDetails details = translateXmlToDomain(pkg); FullRemotePackageInfo rpi = new FullRemotePackageInfo(locationUrl, details); fileList.put(stripLeadingSlash(rpi.getLocation()), rpi); } return fileList; }
From source file:org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil.java
/** * This will return a JAXB unmarshaller that will enable the caller to parse a server plugin * descriptor. The returned unmarshaller will have a {@link ValidationEventCollector} * installed as an {@link Unmarshaller#getEventHandler() event handler} which can be used * to obtain error messages if the unmarshaller fails to parse an XML document. * /*w w w.j a v a 2s. c om*/ * @return a JAXB unmarshaller enabling the caller to parse server plugin descriptors * * @throws Exception if an unmarshaller could not be created */ public static Unmarshaller getServerPluginDescriptorUnmarshaller() throws Exception { // create the JAXB context with all the generated plugin packages in it JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(PLUGIN_CONTEXT_PATH); } catch (Exception e) { throw new Exception("Failed to create JAXB Context.", e); } // create the unmarshaller that can be used to parse XML documents containing server plugin descriptors Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); // enable schema validation to ensure the XML documents parsed by the unmarshaller are valid descriptors ClassLoader cl = ServerPluginDescriptorUtil.class.getClassLoader(); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); StreamSource[] schemaSources = new StreamSource[PLUGIN_SCHEMA_PACKAGES.size()]; int i = 0; for (String schemaPath : PLUGIN_SCHEMA_PACKAGES.keySet()) { URL schemaURL = cl.getResource(schemaPath); schemaSources[i++] = new StreamSource(schemaURL.toExternalForm()); } Schema pluginSchema = schemaFactory.newSchema(schemaSources); unmarshaller.setSchema(pluginSchema); ValidationEventCollector vec = new ValidationEventCollector(); unmarshaller.setEventHandler(vec); return unmarshaller; }
From source file:org.rimudb.configuration.AbstractXmlLoader.java
/** * @param document//w ww . j a v a2s. c o m * @param compoundDbSchemaUrl * @return SAXParseException * @throws Exception */ protected SAXParseException validate(Document document, String compoundDbSchemaUrl) throws Exception { // Compile a schema for the XSD SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // Look up the schema URL and find it's local resource file URL schemaURL = null; String schemaPath = RimuDBNamespace.lookupInternalSchema(compoundDbSchemaUrl); if (schemaPath != null) { schemaURL = getClass().getClassLoader().getResource(schemaPath); } else { schemaURL = new URL(compoundDbSchemaUrl); } Schema schema = schemaFactory.newSchema(schemaURL); // Validate the document against the schema Validator validator = schema.newValidator(); validator.setErrorHandler(new StrictErrorHandler()); try { validator.validate(new DOMSource(document), new DOMResult()); } catch (SAXParseException e) { return e; } return null; }
From source file:org.sejda.core.context.XmlConfigurationStrategy.java
private void initializeSchemaValidation(DocumentBuilderFactory factory) throws SAXException { if (Boolean.getBoolean(Sejda.PERFORM_SCHEMA_VALIDATION_PROPERTY_NAME)) { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setSchema(schemaFactory.newSchema(new Source[] { new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream(DEFAULT_SEJDA_CONFIG)) })); factory.setNamespaceAware(true); }//from ww w . ja v a 2 s.c o m }
From source file:org.silverpeas.core.importexport.control.ImportExport.java
/** * Mthode retournant l'arbre des objets mapps sur le fichier xml pass en paramtre. * @param xmlFileName le fichier xml interprt par JAXB * @return Un objet SilverPeasExchangeType contenant le mapping d'un fichier XML * @throws ImportExportException//from w w w . j av a 2 s . co m */ private SilverPeasExchangeType loadSilverpeasExchange(String xmlFileName) throws ImportExportException { try { File xmlInputSource = new File(xmlFileName); String xsdSystemId = settings.getString("xsdDefaultSystemId"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new URL(xsdSystemId)); // Unmarshall the import model Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new ImportExportErrorHandler()); SilverPeasExchangeType silverpeasExchange = (SilverPeasExchangeType) unmarshaller .unmarshal(xmlInputSource); return silverpeasExchange; } catch (JAXBException me) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_UNMARSHALLING_FAILED", "XML Filename " + xmlFileName + ": " + me.getLocalizedMessage(), me); } catch (MalformedURLException ue) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_UNMARSHALLING_FAILED", "XML Filename " + xmlFileName + ": " + ue.getLocalizedMessage(), ue); } catch (SAXException ve) { throw new ImportExportException("ImportExport.loadSilverpeasExchange", "importExport.EX_PARSING_FAILED", "XML Filename " + xmlFileName + ": " + ve.getLocalizedMessage(), ve); } }
From source file:org.slc.sli.ingestion.parser.impl.EdfiRecordParserImpl.java
private static Schema initializeSchema(Resource schemaResource) throws XmlParseException { Schema schema;//from w ww . j a v a 2s. c om try { schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(schemaResource.getURL()); } catch (SAXException e) { throw new XmlParseException("Exception while initializing XSD schema", e); } catch (IOException e) { throw new XmlParseException("Exception while accessing XSD schema file", e); } return schema; }
From source file:org.slc.sli.ingestion.parser.impl.EdfiRecordParserImpl2.java
public static void parse(InputStream input, Resource schemaResource, TypeProvider typeProvider, RecordVisitor visitor) throws SAXException, IOException, XmlParseException { EdfiRecordParserImpl2 parser = new EdfiRecordParserImpl2(); parser.addVisitor(visitor);//from w ww . j av a 2s . co m parser.typeProvider = typeProvider; SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(schemaResource.getURL()); parser.parseAndValidate(input, schema); }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.server.WsmoLiteDataServiceImpl.java
public String getSAWSDLService(String restURL) throws Exception { Document parsed = getContentAsXML(restURL); Element root = parsed.getDocumentElement(); ServiceDataProcessor.markElementsWithIDs(root); ServiceDataProcessor.buildLabels(root); ServiceDataProcessor.encodeWSDL11AnnOnOperations(root); NodeList schemas = root.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema"); for (int i = 0; i < schemas.getLength(); i++) { ServiceDataProcessor.simplifyTree((Element) schemas.item(i)); }//from www . j a va 2 s .c o m return getXMLString(parsed); }