use of javax.xml.validation.Schema in project midpoint by Evolveum.
the class TestExtraSchema method testUserExtensionSchemaParseUser.
@Test
public void testUserExtensionSchemaParseUser() throws SAXException, IOException, SchemaException {
System.out.println("===[ testUserExtensionSchemaParseUser ]===");
Document dataDoc = DOMUtil.parseFile(USER_JACK_FILE_XML);
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
context.initialize();
// Parsing user
// items from user extension are not correctly defined in the schema
PrismObject<UserType> user = context.parserFor(DOMUtil.getFirstChildElement(dataDoc)).compat().parse();
assertNotNull("No definition for user", user.getDefinition());
System.out.println("Parsed root object:");
System.out.println(user.debugDump());
// TODO: assert user
// Try javax schemas by validating a XML file
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(dataDoc), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.validation.Schema in project midpoint by Evolveum.
the class TestSchemaRegistry method testBasic.
/**
* Test whether the midpoint prism context was constructed OK and if it can validate
* ordinary user object.
*/
@Test
public void testBasic() throws SAXException, IOException, SchemaException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry reg = context.getSchemaRegistry();
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
// Try to use the schema to validate Jack
// PrismObject<UserType> user = context.parseObject(new File("src/test/resources/common/user-jack.xml"));
// Element document = context.serializeToDom(user);
Document document = DOMUtil.parseFile("src/test/resources/common/user-jack.xml");
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(document), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.validation.Schema in project jdk8u_jdk by JetBrains.
the class AnyURITest method main.
public static void main(String[] args) throws Exception {
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src", "."), XSDFILE));
throw new RuntimeException("Illegal URI // should be rejected.");
} catch (SAXException e) {
//expected:
//Enumeration value '//' is not in the value space of the base type, anyURI.
}
}
use of javax.xml.validation.Schema in project ORCID-Source by ORCID.
the class OrcidValidationJaxbContextResolver method getContext.
@Override
public Unmarshaller getContext(Class<?> type) {
try {
String apiVersion = getApiVersion();
String schemaFilenamePrefix = getSchemaFilenamePrefix(type, apiVersion);
Unmarshaller unmarshaller = getJAXBContext(apiVersion).createUnmarshaller();
// the controller
if (OrcidMessage.class.equals(type) || org.orcid.jaxb.model.record_rc3.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_rc4.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_v2.WorkBulk.class.equals(type)) {
return unmarshaller;
}
if (schemaFilenamePrefix != null) {
Schema schema = getSchema(schemaFilenamePrefix, apiVersion);
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(new OrcidValidationHandler());
}
return unmarshaller;
} catch (JAXBException e) {
throw new WebApplicationException(getResponse(e));
} catch (SAXException e) {
throw new WebApplicationException(getResponse(e));
}
}
use of javax.xml.validation.Schema in project ORCID-Source by ORCID.
the class ValidateV2_1SamplesTest method unmarshall.
private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try {
JAXBContext context = JAXBContext.newInstance(type);
Unmarshaller unmarshaller = context.createUnmarshaller();
if (schemaPath != null) {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
unmarshaller.setSchema(schema);
}
return unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
Aggregations