1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.io.BufferedWriter ; 27 import java.io.File ; 28 import java.io.FileWriter ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.StringReader ; 32 import java.io.StringWriter ; 33 import java.io.Writer ; 34 import javax.xml.transform.Result ; 35 import javax.xml.transform.Source ; 36 import javax.xml.transform.Transformer ; 37 import javax.xml.transform.TransformerConfigurationException ; 38 import javax.xml.transform.TransformerException ; 39 import javax.xml.transform.TransformerFactory ; 40 import javax.xml.transform.TransformerFactoryConfigurationError ; 41 import javax.xml.transform.stream.StreamResult ; 42 import javax.xml.transform.stream.StreamSource ; 43 44 59 60 class Schematron 61 { 62 private Transformer transformer; 63 64 76 Schematron(final String schemaName) throws TransformerConfigurationException { 77 transformer = getTransformer(schemaName); 78 } 79 80 89 void analyze(final Source src, final Result result) throws TransformerException { 90 transformer.transform(src, result); 91 } 92 93 private Transformer getTransformer(final String schema) throws TransformerConfigurationException { 94 final InputStream is = this.getClass().getResourceAsStream(schema); 95 if (null == is){ 96 throw new TransformerConfigurationException ("Couldn't construct a transformer to perform validation because I couldn't find the resource named \""+schema+"\" from "+this.getClass().getName()); 97 } 98 final TransformerFactory f = TransformerFactory.newInstance(); 99 100 final Transformer t = f.newTransformer(new StreamSource (is)); 101 102 return t; 103 } 104 105 } 106 107 | Popular Tags |