private void appendResult(String param, Document result) { StringWriter sw = new StringWriter(); DOMBuilder builder = new DOMBuilder(); org.jdom.Document jdomDoc = builder.build(result); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); try { // out.output(jdomDoc, System.out); out.output(jdomDoc, sw); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // OutputFormat format = new OutputFormat(result); // format.setIndenting(true); // format.setPreserveSpace(true); // format.setLineSeparator(System.getProperty("line.separator")); // format.setMethod(Method.XML); // XMLSerializer serial = new XMLSerializer(sw, format); // try { // DOMSerializer domserial = serial.asDOMSerializer(); // domserial.serialize(result); // } catch (Exception e) { // // TODO: handle exception // } try { response.put(param, sw.getBuffer().toString()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // if(response.length() == 0) { // response.append(param); // response.append("="); // response.append(sw.getBuffer().toString()); // } else { // response.append("&"); // response.append(param); // response.append("="); // response.append(sw.getBuffer().toString()); // } }
public Document transform(Document input, @SuppressWarnings("rawtypes") Map additional_properties) throws FragmentTransformationException { DOMBuilder builder = new DOMBuilder(); org.jdom.Document jdomDoc = builder.build(input); ContextContainer cnt = (ContextContainer) ctx.getBean("ContextGateway"); // now transform using stylesheet passed in org.jdom.Element elem = null; try { // Call GetSchemaInfo to place schema titles and codelists into // xpath /root/gui/schemas/{} for xsl transformation to use org.jdom.Element root = new org.jdom.Element(Jeeves.Elem.ROOT); org.jdom.Element gui = new org.jdom.Element(Jeeves.Elem.GUI); GetSchemaInfo gsi = new GetSchemaInfo(); gui.addContent(gsi.exec(new org.jdom.Element(Jeeves.Elem.REQUEST), cnt.getSrvctx())); root.addContent(gui); org.jdom.Element metadata = new org.jdom.Element(Geonet.Elem.METADATA); metadata.addContent(jdomDoc.detachRootElement()); root.addContent(metadata); elem = Xml.transform(root, stylesheetPath); } catch (Exception e) { throw new FragmentTransformationException(e.getMessage()); } // give back a DOM document with html as text (suits jzkit which expects // html output to be text because parsing may not work) Document output = null; try { output = htmldb.newDocument(); Element root = output.createElement("HTML"); root.appendChild(output.createTextNode(Xml.getString(elem))); output.appendChild(root); } catch (Exception e) { throw new FragmentTransformationException(e.getMessage()); } return output; }