public void doOutput(List<StudentEntity> students){ Element root = new Element("students"); Document document = new Document(root); Iterator<StudentEntity> iter = students.iterator(); while(iter.hasNext()){ StudentEntity student = iter.next(); Element studentEl = new Element("student"); studentEl.addContent(new Element("studentnumber").setText(student.getStudentNumber())); studentEl.addContent(new Element("studentname").setText(student.getStudentName())); studentEl.addContent(new Element("major").setText(student.getMajor())); studentEl.addContent(new Element("grade").setText(student.getGrade())); studentEl.addContent(new Element("classname").setText(student.getClassName())); studentEl.addContent(new Element("gender").setText(student.getGender())); root.addContent(studentEl); } try { XMLOutputter out = new XMLOutputter(); Format f = Format.getPrettyFormat(); f.setEncoding("UTF-8"); out.setFormat(f); out.output(document, new FileOutputStream(outputFile)); } catch (Exception e) { e.printStackTrace(); } }
private void executeForArrayType(Map<String, Object> result, List<Element> children) { ArrayTypeDescriptor arrayDescriptor = (ArrayTypeDescriptor) typeDescriptor; List<String> values = new ArrayList<String>(); XMLOutputter outputter = new XMLOutputter(); boolean isInnerBaseType = arrayDescriptor.getElementType() instanceof BaseTypeDescriptor; if (isInnerBaseType) { values = extractBaseTypeArrayFromChildren(children); } else { for (Element child : children) { values.add(outputter.outputString(child)); } } result.put(outputNames[0], values); }
private Content parseContent(Element e) { String value = null; String src = e.getAttributeValue("src");//getAtomNamespace()); DONT KNOW WHY DOESN'T WORK String type = e.getAttributeValue("type");//getAtomNamespace()); DONT KNOW WHY DOESN'T WORK type = (type!=null) ? type : Content.TEXT; if (type.equals(Content.TEXT)) { // do nothing XML Parser took care of this value = e.getText(); } else if (type.equals(Content.HTML)) { value = e.getText(); } else if (type.equals(Content.XHTML)) { XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom.Content c = (org.jdom.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } Content content = new Content(); content.setSrc(src); content.setType(type); content.setValue(value); return content; }
private Content parseContent(Element e) { String value = null; String type = e.getAttributeValue("type");//getAtomNamespace()); DONT KNOW WHY DOESN'T WORK type = (type!=null) ? type : "text/plain"; String mode = e.getAttributeValue("mode");//getAtomNamespace())); DONT KNOW WHY DOESN'T WORK if (mode == null) { mode = Content.XML; // default to xml content } if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); } else if (mode.equals(Content.BASE64)) { value = Base64.decode(e.getText()); } else if (mode.equals(Content.XML)) { XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom.Content c = (org.jdom.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
/** * Convert the received jdom doc to a Document element. * * @param doc the doc * @return the org.w3c.dom. document */ private 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); return dbf.newDocumentBuilder().parse( new ByteArrayInputStream(xmlBytes)); } catch (final Exception e) { logger.trace(e.getMessage(), e); return null; } }
/** * Writes the JDOM document to the outputstream specified * @param out the outputstream to which the JDOM document should be writed * @param validate if true, validate the dom structure before writing. If there is a validation error, * or the xsd is not in the classpath, an exception will be thrown. * @throws ConverterException */ public void writeToXml(Pathway pwy, OutputStream out, boolean validate) throws ConverterException { Document doc = createJdom(pwy); //Validate the JDOM document if (validate) validateDocument(doc); // Get the XML code XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat()); Format f = xmlcode.getFormat(); f.setEncoding("UTF-8"); f.setTextMode(Format.TextMode.PRESERVE); xmlcode.setFormat(f); try { //Send XML code to the outputstream xmlcode.output(doc, out); } catch (IOException ie) { throw new ConverterException(ie); } }
/** * Returns the sorted xml as an OutputStream. * * @return the sorted xml */ public String getSortedXml(Document newDocument) { try (ByteArrayOutputStream sortedXml = new ByteArrayOutputStream()) { BufferedLineSeparatorOutputStream bufferedLineOutputStream = new BufferedLineSeparatorOutputStream(lineSeparatorUtil.toString(), sortedXml); XMLOutputter xmlOutputter = new PatchedXMLOutputter(bufferedLineOutputStream, indentBlankLines); xmlOutputter.setFormat(createPrettyFormat()); xmlOutputter.output(newDocument, bufferedLineOutputStream); IOUtils.closeQuietly(bufferedLineOutputStream); return sortedXml.toString(encoding); } catch (IOException ioex) { throw new FailureException("Could not format pom files content", ioex); } }
public static boolean writeXMLDocument(Document doc, String fName) throws FileNotFoundException { // Assert.assertNotNull(doc); if (doc == null) _log.error("null document"); else { final long start = System.currentTimeMillis(); FileOutputStream fos = new FileOutputStream(fName); try { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, fos); return true; } catch (IOException ioe) { _log.error(ioe); } _log.trace("Document written to " + fName + " in: " + TimeUtility.msToHumanReadableDelta(start)); } return false; }
static void write(File file) throws FileNotFoundException, IOException{ Document document = new Document(); Element root = new Element("document"); root.setAttribute("version", Main.VERSION_ID); for(Blueprint bp : Main.blueprints){ Element blueprint = writeGraphEditor(bp); for(VFunction f : bp.getFunctions()){ blueprint.addContent(writeGraphEditor(f.getEditor())); } root.addContent(blueprint); } document.setRootElement(root); XMLOutputter output = new XMLOutputter(); Format format = Format.getPrettyFormat();//getRawFormat(); format.setOmitDeclaration(true); format.setOmitEncoding(true); format.setTextMode(TextMode.PRESERVE); output.setFormat(format); output.output(document, new FileOutputStream(file)); }
/** * This method assumes a single invocation was passed to it * <p> * * @param name * the article name of the simple that you are looking for * @param xml * the xml that you want to query * @return a String object that represent the simple found. * @throws MobyException * if no simple was found given the article name and/or data * type or if the xml was not valid moby xml or if an unexpected * error occurs. */ public static String getSimple(String name, String xml) throws MobyException { Element element = getDOMDocument(xml).getRootElement(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat() .setOmitDeclaration(false)); Element simples = getSimple(name, element); if (simples != null) { try { return outputter.outputString(simples); } catch (Exception e) { throw new MobyException(newline + "Unexpected error occured while creating String[]:" + newline + Utils.format(e.getLocalizedMessage(), 3)); } } throw new MobyException(newline + "The simple named '" + name + "' was not found in the xml:" + newline + xml + newline); }
/** * * @param name * the name of the collection to extract the simples from. * @param xml * the XML to extract from * @return an array of String objects that represent the simples * @throws MobyException */ public static String[] getSimplesFromCollection(String name, String xml) throws MobyException { Element[] elements = getSimplesFromCollection(name, getDOMDocument(xml) .getRootElement()); String[] strings = new String[elements.length]; XMLOutputter output = new XMLOutputter(Format.getPrettyFormat() .setOmitDeclaration(false)); for (int i = 0; i < elements.length; i++) { try { strings[i] = output.outputString(elements[i]); } catch (Exception e) { throw new MobyException(newline + "Unknown error occured while creating String[]." + newline + Utils.format(e.getLocalizedMessage(), 3)); } } return strings; }
/** * * @param name * the name of the collection to extract the simples from. * @param xml * the XML to extract from * @return an array of String objects that represent the simples, with the * name of the collection * @throws MobyException * if the collection doesnt exist or the xml is invalid */ public static String[] getWrappedSimplesFromCollection(String name, String xml) throws MobyException { Element[] elements = getWrappedSimplesFromCollection(name, getDOMDocument(xml).getRootElement()); String[] strings = new String[elements.length]; XMLOutputter output = new XMLOutputter(Format.getPrettyFormat() .setOmitDeclaration(false)); for (int i = 0; i < elements.length; i++) { try { strings[i] = output.outputString(elements[i]); } catch (Exception e) { throw new MobyException(newline + "Unknown error occured while creating String[]." + newline + Utils.format(e.getLocalizedMessage(), 3)); } } return strings; }
public static void printXML(Element element){ Format format = Format.getPrettyFormat(); format.setIndent("\t"); XMLOutputter op = new XMLOutputter(format); if(element == null){ System.err.println("Null element"); } else{ try { op.output(element, System.out); } catch (IOException e) { e.printStackTrace(); } System.out.println(); } }
public static void printXML(Document doc){ Format format = Format.getPrettyFormat(); format.setIndent("\t"); XMLOutputter op = new XMLOutputter(format); if(doc == null){ System.err.println("Null document"); } else{ try { op.output(doc, System.out); } catch (IOException e) { e.printStackTrace(); } System.out.println(); } }
public void testInsertAtPreferredLocation() throws Exception { NetbeansBuildActionJDOMWriter writer = new NetbeansBuildActionJDOMWriter(); XMLOutputter xmlout = new XMLOutputter(); xmlout.setFormat(Format.getRawFormat().setLineSeparator("\n")); Element p = new Element("p"); NetbeansBuildActionJDOMWriter.Counter c = writer.new Counter(1); writer.insertAtPreferredLocation(p, new Element("one"), c); assertEquals("<p>\n <one />\n</p>", xmlout.outputString(p)); c.increaseCount(); writer.insertAtPreferredLocation(p, new Element("two"), c); assertEquals("<p>\n <one />\n <two />\n</p>", xmlout.outputString(p)); c = writer.new Counter(1); writer.insertAtPreferredLocation(p, new Element("zero"), c); assertEquals("<p>\n <zero />\n <one />\n <two />\n</p>", xmlout.outputString(p)); c.increaseCount(); writer.insertAtPreferredLocation(p, new Element("hemi"), c); assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <two />\n</p>", xmlout.outputString(p)); c.increaseCount(); c.increaseCount(); writer.insertAtPreferredLocation(p, new Element("sesqui"), c); assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n</p>", xmlout.outputString(p)); c.increaseCount(); c.increaseCount(); writer.insertAtPreferredLocation(p, new Element("ultimate"), c); assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n <ultimate />\n</p>", xmlout.outputString(p)); c = writer.new Counter(1); writer.insertAtPreferredLocation(p, new Element("initial"), c); assertEquals("<p>\n <initial />\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n <ultimate />\n</p>", xmlout.outputString(p)); // XXX indentation still not right; better to black-box test write(ActionToGoalMapping...) }
/** * 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; } }
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(); final DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance(); dbf.setNamespaceAware(true); return dbf.newDocumentBuilder().parse( new ByteArrayInputStream(xmlBytes)); } catch (final Exception e) { return null; } }
private void processFullCreoleXmlTree(Plugin plugin, Document jdomDoc, CreoleAnnotationHandler annotationHandler) throws GateException, IOException, JDOMException { // now we can process any annotations on the new classes // and augment the XML definition annotationHandler.processAnnotations(jdomDoc); // debugging if(DEBUG) { XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(jdomDoc, System.out); } // finally, parse the augmented definition with the normal parser DefaultHandler handler = new CreoleXmlHandler(this, plugin); SAXOutputter outputter = new SAXOutputter(handler, handler, handler, handler); outputter.output(jdomDoc); if(DEBUG) { Out.prln("done parsing " + plugin); } }
public void save(File sav) { Document document = new Document(); Element root = new Element("blocks"); document.setRootElement(root); for (int x = 0; x < BLOCKS_WIDTH; x++) { for (int y = 0; y < BLOCKS_HEIGHT; y++) { Element block = new Element("block"); block.setAttribute("x", String.valueOf((int) (blocks[x][y].getX() / BLOCK_SIZE))); block.setAttribute("y", String.valueOf((int) (blocks[x][y].getY() / BLOCK_SIZE))); block.setAttribute("type", String.valueOf(blocks[x][y].getType())); root.addContent(block); } } XMLOutputter output = new XMLOutputter(); try { output.output(document, new FileOutputStream(sav)); } catch (IOException e) { e.printStackTrace(); } }
public static Element convertToThirdVersion(Element state, Project project) throws StudyUnrecognizedFormatException { Element taskManagerElement = state.getChild(MAIN_ELEMENT); XMLOutputter outputter = new XMLOutputter(); Map<String, String> placeholderTextToStatus = fillStatusMap(taskManagerElement, STUDY_STATUS_MAP, outputter); Map<String, String> taskFileToStatusMap = fillStatusMap(taskManagerElement, TASK_STATUS_MAP, outputter); Element courseElement = getChildWithName(taskManagerElement, COURSE).getChild(COURSE_TITLED); for (Element lesson : getChildList(courseElement, LESSONS)) { int lessonIndex = getAsInt(lesson, INDEX); for (Element task : getChildList(lesson, TASK_LIST)) { String taskStatus = null; int taskIndex = getAsInt(task, INDEX); Map<String, Element> taskFiles = getChildMap(task, TASK_FILES); for (Map.Entry<String, Element> entry : taskFiles.entrySet()) { Element taskFileElement = entry.getValue(); String taskFileText = outputter.outputString(taskFileElement); String taskFileStatus = taskFileToStatusMap.get(taskFileText); if (taskFileStatus != null && (taskStatus == null || taskFileStatus.equals(StudyStatus.Failed.toString()))) { taskStatus = taskFileStatus; } Document document = StudyUtils.getDocument(project.getBasePath(), lessonIndex, taskIndex, entry.getKey()); if (document == null) { continue; } for (Element placeholder : getChildList(taskFileElement, ANSWER_PLACEHOLDERS)) { taskStatus = addStatus(outputter, placeholderTextToStatus, taskStatus, placeholder); addOffset(document, placeholder); addInitialState(document, placeholder); } } if (taskStatus != null) { addChildWithName(task, STATUS, taskStatus); } } } return state; }
public static String addStatus(XMLOutputter outputter, Map<String, String> placeholderTextToStatus, String taskStatus, Element placeholder) { String placeholderText = outputter.outputString(placeholder); String status = placeholderTextToStatus.get(placeholderText); if (status != null) { addChildWithName(placeholder, STATUS, status); if (taskStatus == null || status.equals(StudyStatus.Failed.toString())) { taskStatus = status; } } return taskStatus; }
/** * Method write * * @param project * @param stream * @param document * @deprecated */ public void write( Model project, Document document, OutputStream stream ) throws java.io.IOException { updateModel( project, "project", new Counter( 0 ), document.getRootElement() ); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) ); outputter.setFormat( format ); outputter.output( document, stream ); }
/** * Method write * * @param project * @param jdomFormat * @param writer * @param document */ public void write( Model project, Document document, Writer writer, Format jdomFormat ) throws java.io.IOException { updateModel( project, "project", new Counter( 0 ), document.getRootElement() ); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat( jdomFormat ); outputter.output( document, writer ); }
/** * Write the HMM parameters to a xml file. * * @param hmm the markovmodel of which should be written * @param file the output file */ public static void writeXML(HMM hmm, String file) { try { _LOGGER.info("Writing markovmodel to xml."); Element hmmxml = new Element("markovmodel"); Document doc = new Document(hmmxml); doc.setRootElement(hmmxml); Element meta = new Element("meta"); hmmxml.addContent(meta); addMeta(hmm, meta); if (hmm.isTrained()) { Element ortho = new Element("ortho"); hmmxml.addContent(ortho); addOrtho(hmm, ortho); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, new FileWriter(file)); } catch (IOException e) { _LOGGER.error("Error when writing xmlFile: " + e.getMessage()); } }
private String getStringXmlFromResultSet(ProviderLabRoutingModel record) throws Exception{ ResultSetBuilder builder = new ResultSetBuilder(record); Document doc = builder.build(); XMLOutputter xml = new XMLOutputter(); String xmlStr = xml.outputString(doc); return xmlStr; }
public String export (EctMeasurementTypesBean mtb){ Element measurement = createXMLMeasurement(mtb.getType(),mtb.getTypeDesc(),mtb.getTypeDisplayName(),mtb.getMeasuringInstrc()); EctValidationsBeanHandler valBeanHandler = new EctValidationsBeanHandler(); EctValidationsBean v = valBeanHandler.getValidation(mtb.getValidationName());//(EctValidationsBean) validationRules.get(i); measurement.addContent(createXMLValidation(v.getName(),v.getMaxValue(),v.getMinValue(),v.getIsDate(),v.getIsNumeric(),v.getRegularExp(),v.getMaxLength(),v.getMinLength())); XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); return outp.outputString(measurement); }
public RuleBase getRuleBase(String rulesetName, List<Element> elementRules) throws Exception { long timer = System.currentTimeMillis(); try { Element va = new Element("rule-set"); addAttributeifValueNotNull(va, "name", rulesetName); va.setNamespace(namespace); va.addNamespaceDeclaration(javaNamespace); va.addNamespaceDeclaration(xsNs); va.setAttribute("schemaLocation", "http://drools.org/rules rules.xsd http://drools.org/semantics/java java.xsd", xsNs); for (Element ele : elementRules) { va.addContent(ele); } XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); String ooo = outp.outputString(va); log.debug(ooo); RuleBase ruleBase=RuleBaseFactory.getRuleBase("RuleBaseCreator:"+ooo); if (ruleBase!=null) return(ruleBase); ruleBase = RuleBaseLoader.loadFromInputStream(new ByteArrayInputStream(ooo.getBytes())); RuleBaseFactory.putRuleBase("RuleBaseCreator:"+ooo, ruleBase); return ruleBase; } finally { log.debug("generateRuleBase TimeMs : " + (System.currentTimeMillis() - timer)); } }
public void outputXML(File outputFile, Element element, boolean append) { try { FileWriter xmlout = new FileWriter(outputFile, append); org.jdom.output.Format format = org.jdom.output.Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(format); outputter.output(element, xmlout); xmlout.write("\n"); // Close the FileWriter xmlout.close(); } catch (java.io.IOException e) { System.err.println(e.getMessage()); } }
static public void outputXML(String outfile, Document doc) { try { File outputFile = new File(outfile); FileWriter xmlout = new FileWriter(outputFile); org.jdom.output.Format format = org.jdom.output.Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(format); outputter.output(doc, xmlout); // Close the FileWriter xmlout.close(); } catch (java.io.IOException e) { System.err.println(e.getMessage()); } }
public String toString(Format format) { StringWriter xmlout = new StringWriter(); try { format.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(format); outputter.output(this.element, xmlout); // Close the FileWriter xmlout.close(); } catch (java.io.IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } return xmlout.toString(); }
public String write() { String xml = null; try { StringWriter xmlout = new StringWriter(); org.jdom.output.Format format = org.jdom.output.Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(format); outputter.output(this, xmlout); xml = xmlout.toString(); xmlout.close(); return xml; } catch (Exception e) { return null; } }
/** * Return a pretty printed string formatted according to the JDOM Format * @param format the Format object that controls the pretty printing. * @return the pretty printed string. */ public String toString(Format format) { StringWriter xmlout = new StringWriter(); try { format.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(format); outputter.output(this, xmlout); // Close the FileWriter xmlout.close(); } catch (java.io.IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } return xmlout.toString(); }
/** * Write the new data to the xml file */ private void writeToXmlFile() throws Exception { XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(configurationXmlDocument, new OutputStreamWriter( new FileOutputStream(new File(configurationFilePath)), "UTF-8")); }
public boolean storeUserToExternalFile(String userName, String folderPath) { try { //if folder does not exist, create it File folder = new File(folderPath); if (!folder.exists()) { folder.mkdir(); } //set file String filePath = folderPath + File.separator + userName + ".xml"; File file = new File(filePath); //get profile from configuration xml Element profile = talkAndPlayProfileconfiguration.getConfigurationHandler().getUserElement(userName); //write profile to selected file OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); osw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); XMLOutputter xmlout = new XMLOutputter(); xmlout.output(profile, osw); osw.close(); } catch (Exception ex) { Logger.getLogger(UserFormPanel.class.getName()).log(Level.SEVERE, null, ex); return false; } return true; }
public void writeSettingsToFile(File f) { Element component = new Element("component"); component.setAttribute("name", Rearranger.COMPONENT_NAME); Element r = new Element(Rearranger.COMPONENT_NAME); component.getChildren().add(r); writeExternal(r); Format format = Format.getPrettyFormat(); XMLOutputter outputter = new XMLOutputter(format); try { final FileOutputStream fileOutputStream = new FileOutputStream(f); outputter.output(component, fileOutputStream); fileOutputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } }
private static void writeAlertsToFile(File outputFile, Document doc) { XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); try { xmlOutput.output(doc, new FileWriter(outputFile)); System.out.println("alert xml report saved to: "+outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }