1 5 6 package mc.formgenerator.ggf; 7 8 import java.io.File ; 9 import java.io.FileNotFoundException ; 10 import java.io.IOException ; 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import javax.xml.transform.TransformerConfigurationException ; 15 import javax.xml.transform.TransformerException ; 16 17 import mc.formgenerator.ggf.xslprocessing.XalanExecutor; 18 19 import org.w3c.dom.Document ; 20 21 import java.io.ByteArrayOutputStream ; 22 import org.apache.xml.serialize.XMLSerializer; 23 import org.apache.xml.serialize.OutputFormat; 24 25 26 31 public class GGF{ 32 33 public XalanExecutor xalanExe; 35 36 public String contextPath = null; 38 39 public String actionURL = null; 41 42 private Map parameterNames = null; 44 45 46 52 public GGF(String contextPath, String actionURL, String userLanguage) throws TransformerConfigurationException { 53 54 this.contextPath = contextPath; 56 57 this.actionURL = actionURL; 59 60 String fileXformsBonita = contextPath + File.separator + "web" + File.separator + "xml" + File.separator + "xformsBonita.xml"; 62 63 64 this.xalanExe = new XalanExecutor( this.contextPath + File.separator + "web" + File.separator + "xslt" + File.separator + "generator.xsl", 66 userLanguage, fileXformsBonita); 67 68 this.parameterNames = new HashMap (); 70 71 } 72 73 public GGF(String contextPath, String actionURL, String xslURI, String userLanguage) 74 throws TransformerConfigurationException { 75 76 this.contextPath = contextPath; 78 79 this.actionURL = actionURL; 81 82 String fileXformsBonita = contextPath + File.separator + "web" + File.separator + "xml" + File.separator + "xformsBonita.xml"; 84 85 this.xalanExe = XalanExecutor.xalanExecutorFormURL( xslURI , userLanguage, fileXformsBonita); 87 88 this.parameterNames = new HashMap (); 90 } 91 92 public static String toString(Document doc) throws Exception { 94 95 ByteArrayOutputStream os = new ByteArrayOutputStream (); 96 OutputFormat outputFormat = new OutputFormat(doc); 97 outputFormat.setPreserveSpace(true); 98 outputFormat.setIndenting(true); 99 XMLSerializer serializer = new XMLSerializer(os, outputFormat); 101 serializer.serialize(doc); 102 103 return new String (os.toByteArray()); 104 } 105 106 107 117 private Document generateXforms (Document instance, String xmlBase) throws TransformerConfigurationException , FileNotFoundException , TransformerException , IOException { 118 Document xformsOutput; 120 121 try { 122 } 123 catch(Exception e){ 124 System.out.println(e + " " + e.getMessage()); 125 } 126 127 xformsOutput = this.xalanExe.XalanExecutionDOM(instance,xmlBase); 129 130 try { 131 } 132 catch(Exception e){ 133 } 134 135 136 return xformsOutput; 138 } 139 140 141 149 public Document runGGF(Document instance, String xmlBase) throws TransformerConfigurationException , FileNotFoundException , TransformerException , IOException { 150 151 try { 152 } 153 catch(Exception e){ 154 } 155 156 Document xformsDocument = this.generateXforms(instance,xmlBase); 158 159 if(xformsDocument == null){ 160 } 161 return xformsDocument; 162 } 163 164 165 169 public String getUniqueParameterName(String prefix) { 170 String id = prefix + Integer.toHexString((int) (Math.random() * 10000)); 171 172 while (this.parameterNames.get(id) != null) { 173 id = prefix + Integer.toHexString((int) (Math.random() * 10000)); 174 } 175 176 return id; 177 } 178 179 } 180 | Popular Tags |