use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.
the class AntigenicPlotter method writeKML.
/**
* Discrete KML
* @param fileName
* @param labels
* @param data
* @param clusterIndices
* @param clusterSizes
*/
private void writeKML(String fileName, String[] labels, double[][][] data, int[][] clusterIndices, int[][] clusterSizes) {
int[] traceOrder = sortTraces(labels);
Element traceSchema = new Element("Schema");
traceSchema.setAttribute("id", "Cluster_Schema");
traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Label").setAttribute("type", "string").addContent(new Element("displayName").addContent("Label")));
traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Number").setAttribute("type", "double").addContent(new Element("displayName").addContent("Number")));
traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Year").setAttribute("type", "double").addContent(new Element("displayName").addContent("Year")));
traceSchema.addContent(new Element("SimpleField").setAttribute("name", "State").setAttribute("type", "double").addContent(new Element("displayName").addContent("State")));
Element virusSchema = new Element("Schema");
virusSchema.setAttribute("id", "Virus_Schema");
virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Label").setAttribute("type", "string").addContent(new Element("displayName").addContent("Label")));
virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Year").setAttribute("type", "double").addContent(new Element("displayName").addContent("Year")));
virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Trace").setAttribute("type", "double").addContent(new Element("displayName").addContent("Trace")));
// final Element contourFolderElement = new Element("Folder");
// Element contourFolderNameElement = new Element("name");
// contourFolderNameElement.addContent("HPDs");
// contourFolderElement.addContent(contourFolderNameElement);
final Element traceFolderElement = new Element("Folder");
Element traceFolderNameElement = new Element("name");
traceFolderNameElement.addContent("traces");
traceFolderElement.addContent(traceFolderNameElement);
final Element clustersFolderElement = new Element("Folder");
Element clustersFolderNameElement = new Element("name");
clustersFolderNameElement.addContent("clusters");
clustersFolderElement.addContent(clustersFolderNameElement);
Element documentNameElement = new Element("name");
String documentName = fileName;
if (documentName.endsWith(".kml"))
documentName = documentName.replace(".kml", "");
documentNameElement.addContent(documentName);
final Element documentElement = new Element("Document");
documentElement.addContent(documentNameElement);
documentElement.addContent(traceSchema);
documentElement.addContent(virusSchema);
// documentElement.addContent(hpdSchema);
documentElement.addContent(clustersFolderElement);
documentElement.addContent(traceFolderElement);
// documentElement.addContent(contourFolderElement);
final Element rootElement = new Element("kml");
rootElement.addContent(documentElement);
Element traceElement = generateTraceElement(labels, data, traceOrder);
traceFolderElement.addContent(traceElement);
Element clustersElement = generateClusterElement(labels, data, clusterIndices, clusterSizes, traceOrder);
clustersFolderElement.addContent(clustersElement);
// Element contourElement = generateKDEElement(0.95, labels, data, traceOrder);
// contourFolderElement.addContent(contourElement);
PrintStream resultsStream;
try {
resultsStream = new PrintStream(new File(fileName));
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
xmlOutputter.output(rootElement, resultsStream);
} catch (IOException e) {
System.err.println("Error opening file: " + fileName);
System.exit(-1);
}
}
use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.
the class TreeKMLGenerator method main.
public static void main(String[] args) {
String inputTreeFile = args[0];
RootedTree tree = null;
try {
TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
tree = (RootedTree) importer.importNextTree();
} catch (ImportException e) {
e.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}
TreeKMLGenerator generator = new TreeKMLGenerator(tree);
Settings settings = new Settings(AnalysisType.CONTINUOUS);
// settings.getAltitudeTreeSettings().setTreeType(TreeType.ARC_TREE);
// settings.getAltitudeTreeSettings().getBranchStyle().setColorProperty("height");
settings.getGroundTreeSettings().setTreeType(TreeType.SURFACE_TREE);
settings.getGroundTreeSettings().getBranchStyle().setColorProperty("height");
settings.setPlotAltitude(0);
settings.setMostRecentDate(2003);
//settings.setAgeCutOff(1995);
settings.setTimeDivisionCount(0);
settings.setTraitName("antigenic");
settings.setLatitudeName("antigenic1");
settings.setLongitudeName("antigenic2");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(args[0] + ".kml"));
Document doc = new Document(generator.generate(args[0], settings));
try {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(doc, out);
} catch (IOException e) {
System.err.println(e);
}
out.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
}
use of org.jdom.output.XMLOutputter in project cas by apereo.
the class AbstractSamlObjectBuilder method toDom.
/**
* Convert the received jdom doc to a Document element.
*
* @param doc the doc
* @return the org.w3c.dom. document
*/
private static org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
LOGGER.trace(e.getMessage(), e);
return null;
}
}
use of org.jdom.output.XMLOutputter in project cas by apereo.
the class AbstractSamlObjectBuilder method signSamlResponse.
/**
* Sign SAML response.
*
* @param samlResponse the SAML response
* @param privateKey the private key
* @param publicKey the public key
* @return the response
*/
public static String signSamlResponse(final String samlResponse, final PrivateKey privateKey, final PublicKey publicKey) {
final Document doc = constructDocumentFromXml(samlResponse);
if (doc != null) {
final org.jdom.Element signedElement = signSamlElement(doc.getRootElement(), privateKey, publicKey);
doc.setRootElement((org.jdom.Element) signedElement.detach());
return new XMLOutputter().outputString(doc);
}
throw new IllegalArgumentException("Error signing SAML Response: Null document");
}
use of org.jdom.output.XMLOutputter in project vcell by virtualcell.
the class XmlUtil method writeXml.
/**
* @param doc non-null
* @param writer non-null
* @param bTrimAllWhiteSpace remove whitespace from output
* @throws IOException
*/
public static void writeXml(Document doc, Writer writer, boolean bTrimAllWhiteSpace) throws IOException {
Objects.requireNonNull(doc);
Objects.requireNonNull(writer);
XMLOutputter xmlOut = new XMLOutputter();
Format f = Format.getPrettyFormat();
if (bTrimAllWhiteSpace) {
f.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
}
xmlOut.setFormat(f);
xmlOut.output(doc, writer);
}
Aggregations