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:mx.bigdata.sat.cfd.CFDv22.java
public void validar(ErrorHandler handler) throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source[] schemas = new Source[XSD.length]; for (int i = 0; i < XSD.length; i++) { schemas[i] = new StreamSource(getClass().getResourceAsStream(XSD[i])); }//w w w. ja v a 2s . c o m Schema schema = sf.newSchema(schemas); Validator validator = schema.newValidator(); if (handler != null) { validator.setErrorHandler(handler); } validator.validate(new JAXBSource(context, document)); }
From source file:com.adaptris.core.transform.XmlSchemaValidator.java
@Override public void init() throws CoreException { try {/*w ww .j a v a 2 s . c o m*/ if (StringUtils.isBlank(getSchema()) && StringUtils.isBlank(getSchemaMetadataKey())) { throw new CoreException("metadata-key & schema are blank"); } LifecycleHelper.init(getSchemaCache()); schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } }
From source file:io.inkstand.scribble.jcr.rules.util.XMLContentLoaderTest.java
@Test(expected = AssertionError.class) public void testLoadContent_validating_invalidResource() throws Exception { // prepare/* ww w .ja va 2s. c om*/ final URL resource = getClass().getResource("XMLContentLoaderTest_inkstandJcrImport_v1-0_invalid.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); }
From source file:com.amalto.core.storage.hibernate.SystemScatteredMappingCreator.java
@Override public TypeMapping visit(ReferenceFieldMetadata referenceField) { ComplexTypeMetadata fieldReferencedType = referenceField.getReferencedType(); ComplexTypeMetadata referencedType;/*ww w . j a v a 2s.co m*/ if (fieldReferencedType.isInstantiable()) { String typeName = fieldReferencedType.getName().replace('-', '_'); referencedType = new SoftTypeRef(internalRepository, fieldReferencedType.getNamespace(), typeName, true); } else { referencedType = new SoftTypeRef(internalRepository, fieldReferencedType.getNamespace(), newNonInstantiableTypeName(fieldReferencedType), true); } String referencedTypeName = referencedType.getName().replace('-', '_'); FieldMetadata referencedFieldCopy = new SoftIdFieldRef(internalRepository, referencedTypeName); ComplexTypeMetadata database = currentType.peek(); boolean fkIntegrity = referenceField.isFKIntegrity() && (fieldReferencedType != entityMapping.getUser()); // Don't enforce FK integrity for references to itself. ReferenceFieldMetadata newFlattenField = new ReferenceFieldMetadata(currentType.peek(), referenceField.isKey(), referenceField.isMany(), referenceField.isMandatory(), context.getFieldColumn(referenceField), referencedType, referencedFieldCopy, Collections.<FieldMetadata>emptyList(), StringUtils.EMPTY, fkIntegrity, referenceField.allowFKIntegrityOverride(), new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING), referenceField.getWriteUsers(), referenceField.getHideUsers(), referenceField.getWorkflowAccessRights(), StringUtils.EMPTY, StringUtils.EMPTY); newFlattenField.setData(MetadataRepository.DATA_MAX_LENGTH, UUID_LENGTH); // TODO Not very true... database.addField(newFlattenField); entityMapping.map(referenceField, newFlattenField); currentMapping.peek().map(referenceField, newFlattenField); return null; }
From source file:alter.vitro.vgw.service.query.SimpleQueryHandler.java
/** * * Constructor method (for handling responses to queries) * TODO: resolve this obscurity with the two constructors (for the user and gw sides) *//*from w ww . j a va 2s . c om*/ // TODO: maybe make this into singleton private SimpleQueryHandler() { myPeerId = null; // not needed myPeerName = null; // not needed myPipeDataProducer = null; // not needed myPipeDataSession = null; // not needed this.myDCon = null; if (schema == null) { try { schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/aggrquery/PublicQueryAggrMsg.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema from PublicQueryAggrMsg.xsd", saxEx); } } if (enDisFromVSPschema == null) { try { enDisFromVSPschema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/enablednodessynch/fromvsp/fromvsp.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema (enable synch) from fromvsp.xsd", saxEx); } } if (equivSynchFromVSPschema == null) { try { equivSynchFromVSPschema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/equivlistsynch/fromvsp/fromvsp.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema (equiv list synch) from fromvsp.xsd", saxEx); } } }
From source file:io.tourniquet.junit.jcr.rules.util.XMLContentLoaderTest.java
@Test(expected = AssertionError.class) public void testLoadContent_validating_invalidResource() throws Exception { // prepare//from w w w. j a v a 2s. c o m final URL resource = getClass().getResource("XMLContentLoaderTest_tourniquetJcrImport_v1-0_invalid.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(resolver.resolve("/tourniquetJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); }
From source file:ca.uhn.fhir.validation.SchemaBaseValidator.java
private Schema loadSchema(String theVersion, String theSchemaName) { String key = theVersion + "-" + theSchemaName; synchronized (myKeyToSchema) { Schema schema = myKeyToSchema.get(key); if (schema != null) { return schema; }//from w w w . j a va 2 s. c o m Source baseSource = loadXml(null, theSchemaName); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new MyResourceResolver()); try { try { /* * See https://github.com/jamesagnew/hapi-fhir/issues/339 * https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing */ schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); } catch (SAXNotRecognizedException snex) { ourLog.warn("Jaxp 1.5 Support not found.", snex); } schema = schemaFactory.newSchema(new Source[] { baseSource }); } catch (SAXException e) { throw new ConfigurationException("Could not load/parse schema file: " + theSchemaName, e); } myKeyToSchema.put(key, schema); return schema; } }
From source file:com.amalto.core.storage.hibernate.ScatteredMappingCreator.java
@Override public TypeMapping visit(ReferenceFieldMetadata referenceField) { ComplexTypeMetadata fieldReferencedType = referenceField.getReferencedType(); ComplexTypeMetadata referencedType;//from w w w .ja va2 s . c o m if (fieldReferencedType.isInstantiable()) { String typeName = fieldReferencedType.getName().replace('-', '_'); referencedType = new SoftTypeRef(internalRepository, fieldReferencedType.getNamespace(), typeName, true); } else { referencedType = new SoftTypeRef(internalRepository, fieldReferencedType.getNamespace(), newNonInstantiableTypeName(fieldReferencedType), true); } String referencedTypeName = referencedType.getName().replace('-', '_'); FieldMetadata referencedFieldCopy = new SoftIdFieldRef(internalRepository, referencedTypeName); ComplexTypeMetadata database = currentType.peek(); boolean fkIntegrity = referenceField.isFKIntegrity() && (fieldReferencedType != entityMapping.getUser()); // Don't enforce FK integrity for references to itself. ReferenceFieldMetadata newFlattenField = new ReferenceFieldMetadata(currentType.peek(), referenceField.isKey(), referenceField.isMany(), isDatabaseMandatory(referenceField, referenceField.getDeclaringType()), context.getFieldColumn(referenceField), referencedType, referencedFieldCopy, Collections.<FieldMetadata>emptyList(), referenceField.getForeignKeyInfoFormat(), fkIntegrity, referenceField.allowFKIntegrityOverride(), new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING), referenceField.getWriteUsers(), referenceField.getHideUsers(), referenceField.getWorkflowAccessRights(), StringUtils.EMPTY, StringUtils.EMPTY); newFlattenField.setData(MetadataRepository.DATA_MAX_LENGTH, Types.UUID_LENGTH); database.addField(newFlattenField); entityMapping.map(referenceField, newFlattenField); currentMapping.peek().map(referenceField, newFlattenField); return null; }
From source file:edu.lternet.pasta.common.XmlUtility.java
/** * Returns the provided XML string as a schema. * * @param xmlString an XML schema.//from w w w .j ava 2 s . c o m * * @return a schema object that corresponds to the provided string. */ public static Schema xmlStringToSchema(String xmlString) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setErrorHandler(new XmlParsingErrorHandler(xmlString)); StreamSource source = new StreamSource(new StringReader(xmlString)); try { return factory.newSchema(source); } catch (SAXException e) { throw new IllegalStateException(e); // shouldn't be reached } }
From source file:dk.netarkivet.common.utils.XmlUtils.java
/** * Validate that the settings xml files conforms to the XSD. * * @param xsdFile Schema to check settings against. * @throws ArgumentNotValid if unable to validate the settings files * @throws IOFailure If unable to read the settings files and/or * the xsd file.//from w w w. j a v a 2s .c o m */ public static void validateWithXSD(File xsdFile) { ArgumentNotValid.checkNotNull(xsdFile, "File xsdFile"); List<File> settingsFiles = Settings.getSettingsFiles(); for (File settingsFile : settingsFiles) { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder parser = builderFactory.newDocumentBuilder(); org.w3c.dom.Document document = parser.parse(settingsFile); // create a SchemaFactory capable of understanding WXS schemas SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // load a WXS schema, represented by a Schema instance Source schemaFile = new StreamSource(xsdFile); Schema schema = factory.newSchema(schemaFile); // create a Validator instance, which can be used to validate an // instance document Validator validator = schema.newValidator(); // validate the DOM tree try { validator.validate(new DOMSource(document)); } catch (SAXException e) { // instance document is invalid! final String msg = "Settings file '" + settingsFile + "' does not validate using '" + xsdFile + "'"; log.warn(msg, e); throw new ArgumentNotValid(msg, e); } } catch (IOException e) { throw new IOFailure("Error while validating: ", e); } catch (ParserConfigurationException e) { final String msg = "Error validating settings file '" + settingsFile + "'"; log.warn(msg, e); throw new ArgumentNotValid(msg, e); } catch (SAXException e) { final String msg = "Error validating settings file '" + settingsFile + "'"; log.warn(msg, e); throw new ArgumentNotValid(msg, e); } } }