List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter()
XMLOutputter
with a default Format and XMLOutputProcessor . From source file:de.unigoettingen.sub.search.opac.ConfigOpacCatalogue.java
License:Open Source License
/** * Print given DomNode to defined File ================================================================ *///from ww w .java2 s . c o m private void debugMyNode(Node inNode, String fileName) { try { XMLOutputter outputter = new XMLOutputter(); Document tempDoc = new DOMBuilder().build(inNode.getOwnerDocument()); FileOutputStream output = new FileOutputStream(fileName); outputter.output(tempDoc.getRootElement(), output); } catch (FileNotFoundException e) { logger.error("debugMyNode(Node, String)", e); } catch (IOException e) { logger.error("debugMyNode(Node, String)", e); } }
From source file:devicemodel.conversions.XmlConversions.java
public static String document2XmlStringNoHeader(final Document doc) throws IOException { final StringWriter stringWriter = new StringWriter(); final XMLOutputter xmlOutput = new XMLOutputter(); final Format plainFormat = Format.getPrettyFormat(); plainFormat.setOmitDeclaration(true); xmlOutput.setFormat(plainFormat);/*from ww w . j a v a 2 s. co m*/ xmlOutput.output(doc, stringWriter); return stringWriter.toString(); }
From source file:ditatools.translate.DitaTranslator.java
License:Apache License
protected void translateTopicXML(Document doc, File outputXmlFile) throws JDOMException, IOException { // caller should have verified that root element // is a DITA topic: concept, task, or reference Element rootElement = doc.getRootElement(); // XXX handle case where xml:lang attr is not present rootElement.getAttribute("lang", Namespace.XML_NAMESPACE).setValue(language); process(rootElement);//w w w . jav a 2 s . c om XMLOutputter xmlOutput = new XMLOutputter(); // force use of UTF-8 in output FileOutputStream fos = null; OutputStreamWriter osw = null; try { fos = new FileOutputStream(outputXmlFile); osw = new OutputStreamWriter(fos, "UTF-8"); xmlOutput.output(doc, osw); } finally { if (osw != null) { try { osw.close(); } catch (Exception x) { } } if (fos != null) { try { fos.close(); } catch (Exception x) { } } } }
From source file:edu.kit.trufflehog.model.configdata.SettingsDataModel.java
License:Open Source License
/** * <p>//from ww w . j a v a 2 s . co m * Actually make the change to the XML and save it to the hard drive. * </p> * * @param typeClass The type of the value (i.e. String, Integer or Boolean are examples) * @param key The key mapped to the value, classic key value mapping. * @param oldValue The old value that should be updated. * @param newValue The new value, that should overwrite the old value. * @param document The document object that represent the parsed XML. * @param entry The entry that should be updated in the XML file. * @throws IOException Thrown if something goes wrong during the write operation. */ private void saveNewValue(final Class typeClass, final String key, final String oldValue, final String newValue, final Document document, final Element entry) throws IOException { // Get the only one we found entry.getChild("value").setText(newValue); // Save the new XML to the file XMLOutputter xmlOutput = new XMLOutputter(); PrintWriter writer = new PrintWriter(settingsFile, "UTF-8"); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(document, writer); writer.close(); logger.debug("Changed key: " + key + " of type: " + typeClass.getName() + " from old value: " + oldValue + " to new value: " + newValue); }
From source file:edu.pitt.apollo.runmanagerservice.methods.stage.StageExperimentMethod.java
License:Apache License
@Override public void runApolloService() { XMLSerializer serializer = new XMLSerializer(); XMLDeserializer deserializer = new XMLDeserializer(); InfectiousDiseaseScenario baseScenario = idtes.getInfectiousDiseaseScenarioWithoutIntervention(); // clear all set control strategies in base baseScenario.getInfectiousDiseaseControlStrategies().clear(); List<SoftwareIdentification> modelIds = idtes.getInfectiousDiseaseTransmissionModelIds(); try {/*from w w w . j a v a 2 s . c om*/ DataServiceAccessor dataServiceAccessor = new DataServiceAccessor(); for (SoftwareIdentification modelId : modelIds) { // create a base scenario copy String baseXml = serializer.serializeObject(baseScenario); InfectiousDiseaseScenario baseScenarioCopy = deserializer.getObjectFromMessage(baseXml, InfectiousDiseaseScenario.class); for (InfectiousDiseaseControlStrategy strategy : idtes.getInfectiousDiseaseControlStrategies()) { for (InfectiousDiseaseControlMeasure controlMeasure : strategy.getControlMeasures()) { baseScenarioCopy.getInfectiousDiseaseControlStrategies().add(controlMeasure); } } List<SensitivityAnalysisSpecification> sensitivityAnalyses = idtes.getSensitivityAnalyses(); for (SensitivityAnalysisSpecification sensitivityAnalysis : sensitivityAnalyses) { if (sensitivityAnalysis instanceof OneWaySensitivityAnalysisOfContinousVariableSpecification) { OneWaySensitivityAnalysisOfContinousVariableSpecification owsaocv = (OneWaySensitivityAnalysisOfContinousVariableSpecification) sensitivityAnalysis; double min = owsaocv.getMinimumValue(); double max = owsaocv.getMaximumValue(); double increment = (max - min) / owsaocv.getNumberOfDiscretizations().intValueExact(); String scenarioXML = serializer.serializeObject(baseScenarioCopy); double val = min; while (val <= max) { String param = owsaocv.getUniqueApolloLabelOfParameter(); Document jdomDocument; SAXBuilder jdomBuilder = new SAXBuilder(); try { jdomDocument = jdomBuilder.build( new ByteArrayInputStream(scenarioXML.getBytes(StandardCharsets.UTF_8))); } catch (JDOMException | IOException ex) { ErrorUtils.reportError(runId, "Error inserting experiment run. Error was " + ex.getMessage(), authentication); return; } Element e = jdomDocument.getRootElement(); List<Namespace> namespaces = e.getNamespacesInScope(); for (Namespace namespace : namespaces) { if (namespace.getURI().contains("http://types.apollo.pitt.edu")) { param = param.replaceAll("/", "/" + namespace.getPrefix() + ":"); param = param.replaceAll("\\[", "\\[" + namespace.getPrefix() + ":"); break; } } XPathFactory xpf = XPathFactory.instance(); XPathExpression<Element> expr; expr = xpf.compile(param, Filters.element(), null, namespaces); List<Element> elements = expr.evaluate(jdomDocument); for (Element element : elements) { element.setText(Double.toString(val)); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.output(jdomDocument, baos); InfectiousDiseaseScenario newScenario = deserializer.getObjectFromMessage( new String(baos.toByteArray()), InfectiousDiseaseScenario.class); // new scenario is ready to be staged RunSimulationMessage runSimulationMessage = new RunSimulationMessage(); runSimulationMessage.setAuthentication(authentication); runSimulationMessage .setSimulatorTimeSpecification(message.getSimulatorTimeSpecification()); runSimulationMessage.setSoftwareIdentification(modelId); runSimulationMessage.setInfectiousDiseaseScenario(newScenario); StageMethod stageMethod = new StageMethod(runSimulationMessage, runId); InsertRunResult result = stageMethod.stage(); BigInteger newRunId = result.getRunId(); MethodCallStatus status = dataServiceAccessor.getRunStatus(newRunId, authentication); if (status.getStatus().equals(MethodCallStatusEnum.FAILED)) { ErrorUtils.reportError(runId, "Error inserting run in experiment with run ID " + runId + "" + ". Error was for inserting ID " + newRunId + " with message " + status.getMessage(), authentication); return; } val += increment; } } } } dataServiceAccessor.updateStatusOfRun(runId, MethodCallStatusEnum.TRANSLATION_COMPLETED, "All runs for this experiment have been translated", authentication); } catch (DeserializationException | IOException | SerializationException | RunManagementException ex) { ErrorUtils.reportError(runId, "Error inserting experiment run. Error was " + ex.getMessage(), authentication); return; } }
From source file:edu.ucla.loni.server.ServerUtils.java
License:Open Source License
/** * Write a document (XML file) to a particular absolute path * @throws Exception /*from w w w .j a v a 2s .c o m*/ */ public static void writeXML(File file, Document doc) throws Exception { XMLOutputter xmlOut = new XMLOutputter(); FileOutputStream fileOut = new FileOutputStream(file); xmlOut.output(doc, fileOut); fileOut.flush(); fileOut.close(); }
From source file:edu.utep.cs.jasg.apiGenerator.APIGenerator.java
License:Open Source License
/** Creates a XML file with an XSL reference using JDom */ private void createXMLFileWithXSLLink() { try (FileWriter fileWriter = new FileWriter(outputPath + File.separator + fileName + ".xml");) { // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); HashMap<String, String> piMap = new HashMap<String, String>(); piMap.put("type", "text/xsl"); piMap.put("href", "stylesheet.xsl"); ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet", piMap); doc.getContent().add(0, pi);//from w ww. j a va2 s. c o m xmlOutput.output(doc, fileWriter); System.out.println("File \"" + outputPath + File.separator + fileName + ".xml" + "\" created"); } catch (IOException io) { System.err.println("IOException in APIGenerator: " + io.getMessage()); } }
From source file:edu.utep.cs.jasg.specificationGenerator.XMLParser.java
License:Open Source License
/** Print XML file using XMLOutputter. */ public void printXMLFile(File file) { try {/*from w ww .java 2 s .c o m*/ // Build the document with SAX and Xerces, no validation SAXBuilder builder = new SAXBuilder(); // Create the document Document doc = builder.build(file); // Output the document, use standard formatter XMLOutputter fmt = new XMLOutputter(); fmt.output(doc, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.wisc.ssec.adapter.NetCDFFile.java
License:Open Source License
public static NetCDFFile makeUnion(String filename, String other) throws Exception { Object obj = new Object(); URL url = obj.getClass().getResource("/edu/wisc/ssec/mcidasv/data/hydra/resources/union.ncml"); SAXBuilder builder = new SAXBuilder(false); Document doc = null;//from w ww . jav a2s . co m try { doc = builder.build(url); } catch (Exception e) { e.printStackTrace(); } Element root = doc.getRootElement(); List list = root.getChildren(); list = ((Element) list.get(1)).getChildren(); org.jdom2.Attribute attr1 = (org.jdom2.Attribute) (((Element) list.get(0)).getAttributes()).get(0); attr1.setValue(filename); org.jdom2.Attribute attr2 = (org.jdom2.Attribute) (((Element) list.get(1)).getAttributes()).get(0); attr2.setValue(other); XMLOutputter xmlOut = new XMLOutputter(); String newStr = xmlOut.outputString(doc); ByteArrayInputStream is = new ByteArrayInputStream(newStr.getBytes()); return new NetCDFFile(is); }
From source file:edu.wisc.ssec.mcidasv.data.hydra.NetCDFFile.java
License:Open Source License
public static NetCDFFile makeUnion(String filename, String other) throws Exception { Object obj = new Object(); URL url = obj.getClass().getResource("/edu/wisc/ssec/mcidasv/data/hydra/resources/union.ncml"); SAXBuilder builder = new SAXBuilder(false); Document doc = null;/*from w w w. j a v a2s .com*/ try { doc = builder.build(url); } catch (Exception e) { e.printStackTrace(); } Element root = doc.getRootElement(); List list = root.getChildren(); list = ((Element) list.get(1)).getChildren(); org.jdom2.Attribute attr1 = (((Element) list.get(0)).getAttributes()).get(0); attr1.setValue(filename); org.jdom2.Attribute attr2 = (((Element) list.get(1)).getAttributes()).get(0); attr2.setValue(other); XMLOutputter xmlOut = new XMLOutputter(); String newStr = xmlOut.outputString(doc); logger.trace("union string:\n{}", newStr); ByteArrayInputStream is = new ByteArrayInputStream(newStr.getBytes()); return new NetCDFFile(is); }