1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.ByteArrayInputStream ; 5 import java.io.InputStream ; 6 7 import javax.xml.transform.Transformer ; 8 import javax.xml.transform.TransformerFactory ; 9 import javax.xml.transform.TransformerException ; 10 import javax.xml.transform.stream.StreamSource ; 11 import javax.xml.transform.stream.StreamResult ; 12 import org.exoplatform.services.xml.querying.InvalidStatementException; 13 14 15 21 public class InstructionCompiler { 22 23 protected Transformer queryResolver; 24 25 public InstructionCompiler(InputStream xslStream) throws InstructionCompilerException 26 { 27 28 try { 29 30 TransformerFactory tFactory = TransformerFactory.newInstance(); 31 queryResolver = tFactory.newTransformer( new StreamSource ( xslStream ) ); 32 33 } catch (Exception e) { 34 35 throw new InstructionCompilerException("Can not instantiate an InstructionCompiler Reason: " + e); 36 } 37 38 } 39 40 44 public Command compile( String instruction ) throws InvalidStatementException 45 { 46 try { 47 48 ByteArrayOutputStream os = new ByteArrayOutputStream (); 49 50 StreamResult strRes = new StreamResult ( os ); 51 52 queryResolver.transform(new StreamSource ( 53 new ByteArrayInputStream (instruction.getBytes()) ), strRes); 54 55 return new Command( os.toByteArray() ); 56 57 } catch (TransformerException e) { 58 59 throw new InvalidStatementException("Can not init XSLTStatement Reason: " + e); 60 61 } 62 } 63 } 64 | Popular Tags |