List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:net.alegen.easyhash.utils.Settings.java
License:Open Source License
public void save() { Element elemSettings = new Element("settings"); Document doc = new Document(elemSettings); Element elemAlgorithm = new Element("algorithm"); elemAlgorithm.addContent(this.algorithm); doc.getRootElement().addContent(elemAlgorithm); Element elemEcho = new Element("echo"); elemEcho.addContent(String.valueOf(this.echo)); doc.getRootElement().addContent(elemEcho); Element elemToClipboard = new Element("to-clipboard"); elemToClipboard.addContent(String.valueOf(this.tocb)); doc.getRootElement().addContent(elemToClipboard); Element elemCaps = new Element("caps"); elemCaps.addContent(String.valueOf(this.caps)); doc.getRootElement().addContent(elemCaps); Element elemChain = new Element("chain"); elemChain.addContent(String.valueOf(this.chain)); doc.getRootElement().addContent(elemChain); Element elemResetTime = new Element("reset-time"); elemResetTime.addContent(String.valueOf(this.resetTime)); doc.getRootElement().addContent(elemResetTime); Element elemSalt = new Element("salt"); elemSalt.addContent(this.salt); doc.getRootElement().addContent(elemSalt); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); try {/*www. jav a 2 s.c o m*/ xmlOutput.output(doc, new FileWriter("settings.eh.xml")); } catch (IOException ex) { System.out.println("eh > Could not save settings - " + ex.getMessage()); } }
From source file:net.FriendsUnited.Services.FileServer.java
License:Open Source License
private void sendDirectoryListing(FriendPacket pkt, String path) { log.info("Received Request for Listing of {}--{}", SharedFolder, path); File dir = new File(SharedFolder + path); File[] files = dir.listFiles(); if (null == files) { replyWithFailurePacket(pkt, "Directory " + dir.getPath() + " can not be read"); } else {/*from w ww . j a va 2 s.c o m*/ Element root = new Element("FolderListing"); for (int i = 0; i < files.length; i++) { File f = files[i]; Element fe; if (true == f.isDirectory()) { fe = new Element("Directory"); fe.setText(f.getName()); } else { fe = new Element("File"); fe.setText(f.getName()); Element size = new Element("Size"); size.addContent("" + f.length()); fe.addContent(size); } Element lastModified = new Element("lastModified"); long time = f.lastModified(); lastModified.addContent("" + time); fe.addContent(lastModified); root.addContent(fe); } Document doc = new Document(root); XMLOutputter xout = new XMLOutputter(Format.getCompactFormat()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { xout.output(doc, bout); ByteConverter bc = new ByteConverter(); bc.add(DIRECTORY_LISTING); bout.flush(); log.debug("Size of Listing XML : " + bout.size()); bc.add(bout.size()); // length of String bc.add(bout.toByteArray()); // String Data FriendPacket replyPacket = new FriendPacket(pkt.getTargetServer(), pkt.getTargetService(), // source pkt.getSourceServer(), pkt.getSourceService(), // target bc.toByteArray()); // payload log.debug("sending : " + replyPacket); server.sendPacketIntoNetwork(this, replyPacket); log.debug("Send reply with Listing !"); } catch (IOException e) { replyWithFailurePacket(pkt, Tool.fromExceptionToString(e)); } } }
From source file:net.instantcom.mm7.MM7Message.java
License:Open Source License
@Override public String toString() { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); Document doc = new Document(toSOAP(new MM7Context())); StringWriter w = new StringWriter(); try {/* w w w. j a va2 s. c o m*/ out.output(doc, w); return w.toString(); } catch (IOException e) { return super.toString(); } }
From source file:net.osgiliath.helpers.cxf.exception.handling.jaxrs.mapper.ExceptionXmlMapper.java
License:Apache License
/** * Map the catched Exception to the response body (xml format). */// w w w. jav a 2 s . c o m @Override public Response toResponse(Exception arg0) { // On cree une instance de SAXBuilder final Element root = new Element("Exception"); final Document doc = new Document(root); this.populateXML(arg0, root); final String res = new XMLOutputter(Format.getPrettyFormat()).outputString(doc); LOG.info("CXF exception thrown: " + res, arg0); return Response.status(Response.Status.FORBIDDEN).type(MediaType.APPLICATION_XML) .header(ExceptionMappingConstants.EXCEPTION_BODY_HEADER, res).build(); }
From source file:nl.colorize.multimedialib.graphics.ImageAtlasLoader.java
License:Apache License
public Document export(ImageAtlas imageAtlas) { Element imageAtlasElement = new Element("imageAtlas"); for (String name : imageAtlas.getSubImages().keySet()) { imageAtlasElement.addContent(buildSubImageElement(imageAtlas, name)); }/* w ww . j a v a 2 s. co m*/ return new Document(imageAtlasElement); }
From source file:nl.colorize.util.xml.PropertyList.java
License:Apache License
private Document serialize() { Element rootElement = new Element("plist"); rootElement.setAttribute("version", PLIST_FILE_FORMAT_VERSION); rootElement.addContent(serializeProperty(rootProperty)); return new Document(rootElement); }
From source file:nl.colorize.util.xml.XMLConverter.java
License:Apache License
/** * Converts the specified object to XML. The object will be serialized using * either the provided custom serialization format for the object's type, or * the default serialization format if no custom one has been registered. * @param rootElementName Will be used as the element name for the root element * in the created XML document./* w w w . j a v a2 s . c o m*/ * @throws NullPointerException when {@code obj} is {@code null}. */ public Document toXML(Object obj, String rootElementName) { if (obj == null || rootElementName == null) { throw new NullPointerException(); } Element rootElement = serializeObject(obj, rootElementName); return new Document(rootElement); }
From source file:nl.nn.adapterframework.util.XmlBuilder.java
License:Apache License
public String toXML(boolean xmlHeader) { Document document = new Document(element.detach()); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(!xmlHeader)); return xmlOutputter.outputString(document); }
From source file:open.dolphin.message.ClaimMessageBuilder.java
public String build(ClaimHelper helper) { // Mml element? Element root = new Mml(helper); // MmlHeader? root.addContent(new MmlHeader(helper)); // MmlBody?/*from w w w . j a v a2 s . c om*/ root.addContent(new MmlBody(helper)); // xml Document doc = new Document(root); return outputter.outputString(doc); }
From source file:open.dolphin.message.ClaimMessageBuilder.java
public String build(DiseaseHelper helper) { // Mml element? Element root = new Mml(helper); // MmlHeader? root.addContent(new MmlHeader(helper)); // MmlBody?// ww w .j a va2s . c o m root.addContent(new MmlBody(helper)); // xml Document doc = new Document(root); return outputter.outputString(doc); }