module CqmValidators::Schematron::JavaProcessor

Constants

ISO_SCHEMATRON2

Public Instance Methods

build_transformer(xslt, input_file, url = false) click to toggle source
# File lib/schematron/java_processor.rb, line 79
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) click to toggle source
# File lib/schematron/java_processor.rb, line 46
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) click to toggle source
# File lib/schematron/java_processor.rb, line 40
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() click to toggle source
# File lib/schematron/java_processor.rb, line 55
def processor
  @processor ||= build_transformer(java.io.File.new(ISO_SCHEMATRON2), schematron_file)
end
schematron_file() click to toggle source
# File lib/schematron/java_processor.rb, line 59
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
    retry
  end
  dbf.setIgnoringElementContentWhitespace(true)
  db = dbf.new_document_builder
  document = db.parse(java.io.File.new(@schematron_file))

  root = document.document_element
  root.set_attribute('defaultPhase', 'errors')

  DOMSource.new(root)
end