/** * Should the validator validate the resource against the base schema (the schema provided with the FHIR distribution itself) * * @return Returns a referens to <code>this<code> for method chaining */ public synchronized FhirValidator setValidateAgainstStandardSchema(boolean theValidateAgainstStandardSchema) { addOrRemoveValidator(theValidateAgainstStandardSchema, SchemaBaseValidator.class, new SchemaBaseValidator(myContext)); return this; }
@Override public void validateResource(IValidationContext<IBaseResource> theContext) { doValidate(theContext, "fhir-single.xsd"); }
private Schema loadSchema(String theVersion, String theSchemaName) { String key = theVersion + "-" + theSchemaName; synchronized (myKeyToSchema) { Schema schema = myKeyToSchema.get(key); if (schema != null) { return schema; } 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; } }
private void doValidate(IValidationContext<?> theContext, String schemaName) { Schema schema = loadSchema("dstu", schemaName);
private void doValidate(IValidationContext<?> theContext, String schemaName) { Schema schema = loadSchema("dstu", schemaName);
IValidatorModule module1 = new SchemaBaseValidator(ctx); IValidatorModule module2 = new SchematronBaseValidator(ctx); val.registerValidatorModule(module1);
@Override public void validateResource(IValidationContext<IBaseResource> theContext) { doValidate(theContext, "fhir-single.xsd"); }
private Schema loadSchema(String theVersion, String theSchemaName) { String key = theVersion + "-" + theSchemaName; synchronized (myKeyToSchema) { Schema schema = myKeyToSchema.get(key); if (schema != null) { return schema; } 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; } }
public void validationIntro() { // START SNIPPET: validationIntro FhirContext ctx = FhirContext.forDstu3(); // Ask the context for a validator FhirValidator validator = ctx.newValidator(); // Create some modules and register them IValidatorModule module1 = new SchemaBaseValidator(ctx); validator.registerValidatorModule(module1); IValidatorModule module2 = new SchematronBaseValidator(ctx); validator.registerValidatorModule(module2); // Pass a resource in to be validated. The resource can // be an IBaseResource instance, or can be a raw String // containing a serialized resource as text. Patient resource = new Patient(); ValidationResult result = validator.validateWithResult(resource); String resourceText = "<Patient.....>"; ValidationResult result2 = validator.validateWithResult(resourceText); // The result object now contains the validation results for (SingleValidationMessage next : result.getMessages()) { System.out.println(next.getLocationString() + " " + next.getMessage()); } // END SNIPPET: validationIntro }
/** * Should the validator validate the resource against the base schema (the schema provided with the FHIR distribution itself) * * @return Returns a referens to <code>this<code> for method chaining */ public synchronized FhirValidator setValidateAgainstStandardSchema(boolean theValidateAgainstStandardSchema) { addOrRemoveValidator(theValidateAgainstStandardSchema, SchemaBaseValidator.class, new SchemaBaseValidator(myContext)); return this; }