1 19 20 package com.sslexplorer.applications.server; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.IOException ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import com.sslexplorer.boot.XMLElement; 31 32 public class ParameterTransformation { 33 34 final static Log log = LogFactory.getLog(ParameterTransformation.class); 35 36 XMLElement el; 37 ServerLauncher launcher; 38 Transformation trans; 39 String outputParam; 40 String inputParam; 41 42 ParameterTransformation(XMLElement el, ServerLauncher launcher) throws IOException { 43 44 if (el.getAttribute("class") == null || el.getAttribute("input") == null || el.getAttribute("output") == null) 45 throw new IOException ("<transform> element requires class, input and output attributes!"); 46 47 this.el = el; 48 this.launcher = launcher; 49 50 } 51 52 public void processTransformation() throws IOException { 53 54 String classFile = el.getAttribute("class").toString(); 55 inputParam = el.getAttribute("input").toString(); 56 outputParam = el.getAttribute("output").toString(); 57 58 File f = new File (launcher.getInstallDir(), classFile + ".class"); 59 60 if (!f.exists()) 61 throw new IOException (classFile + " does not exist! Did you forget to place the .class file in a <file> element?"); 62 63 FileInputStream in = new FileInputStream (f); 64 ByteArrayOutputStream out = new ByteArrayOutputStream (); 65 66 byte[] buf = new byte[16384]; 67 int read; 68 69 while ((read = in.read(buf)) > -1) { 70 out.write(buf, 0, read); 71 } 72 73 in.close(); 74 buf = out.toByteArray(); 75 try { 76 77 log.debug("Loading transformation class " + classFile); 78 Class cls = ByteArrayClassLoader.getInstance().createFromByteArray(classFile, buf, 0, buf.length); 79 80 log.debug("Creating transformation instance"); 81 Transformation t = (Transformation) cls.newInstance(); 82 83 log.debug("Invoking transformation"); 84 launcher.addParameter(outputParam, t.transform(launcher.replaceTokens(inputParam))); 85 } catch (Exception ex) { 86 log.debug("Exception in Transformation class: " + ex.getMessage()); 87 } 88 89 } 90 } 91 | Popular Tags |