Module: HealthDataStandards::Validate::Schematron::JavaProcessor
- Included in:
- Validator
- Defined in:
- lib/health-data-standards/validate/schematron/java_processor.rb
Defined Under Namespace
Classes: HdsUrlResolver
Constant Summary collapse
- ISO_SCHEMATRON2 =
File.join(DIR, 'resources/schematron/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl')
Instance Method Summary collapse
- #build_transformer(xslt, input_file, url = false) ⇒ Object
- #get_document_j(doc) ⇒ Object
- #get_errors(document) ⇒ Object
- #processor ⇒ Object
- #schematron_file ⇒ Object
Instance Method Details
#build_transformer(xslt, input_file, url = false) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/health-data-standards/validate/schematron/java_processor.rb', line 81 def build_transformer(xslt, input_file, url=false) factory = TransformerFactory.newInstance(TRANSFORMER_FACTORY_IMPL, nil) factory.uri_resolver = HdsUrlResolver.new(@schematron_file) if url transformer = factory.new_transformer(StreamSource.new(xslt)) sw = StringWriter.new output = StreamResult.new(sw) transformer.transform(input_file, output) sw.to_s end |
#get_document_j(doc) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/health-data-standards/validate/schematron/java_processor.rb', line 48 def get_document_j(doc) case doc when File java.io.File.new(doc.path) else StringReader.new(doc.to_s) end end |
#get_errors(document) ⇒ Object
42 43 44 45 46 |
# File 'lib/health-data-standards/validate/schematron/java_processor.rb', line 42 def get_errors(document) document_j = get_document_j(document) output = build_transformer(StringReader.new(processor), StreamSource.new(document_j), true) Nokogiri::XML(output) end |
#processor ⇒ Object
57 58 59 |
# File 'lib/health-data-standards/validate/schematron/java_processor.rb', line 57 def processor @processor ||= build_transformer(java.io.File.new(ISO_SCHEMATRON2), schematron_file) end |
#schematron_file ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/health-data-standards/validate/schematron/java_processor.rb', line 61 def schematron_file # this allows us to run the validation utility app in jBoss/TorqueBox # for some reason it breaks the first time you call DocumentBuilderFactory, # so the solution is to catch the error and retry # TODO: pull this out when the above is no longer the case. begin dbf = DocumentBuilderFactory.new_instance rescue Exception => ex retry end dbf.setIgnoringElementContentWhitespace(true); db = dbf.new_document_builder document = db.parse(java.io.File.new(@schematron_file)) root = document.document_element phase = root.set_attribute("defaultPhase", "errors") DOMSource.new(root) end |