List of usage examples for org.jdom2 Element addNamespaceDeclaration
public boolean addNamespaceDeclaration(final Namespace additionalNamespace)
From source file:broadwick.graph.writer.GraphMl.java
License:Apache License
/** * Get the string representation of the network. * @param network the network object to be written. * @param directed a boolean flag, true if the network is directed. * @return a string representing a document. *//*from ww w . ja va2s . c o m*/ public static String toString(final Graph<? extends Vertex, ? extends Edge<?>> network, final boolean directed) { // graphml document header final Element graphml = new Element("graphml", "http://graphml.graphdrawing.org/xmlns"); final Document document = new Document(graphml); final Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); final Namespace schemLocation = Namespace.getNamespace("schemLocation", "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0rc/graphml.xsd"); // add Namespace graphml.addNamespaceDeclaration(xsi); graphml.addNamespaceDeclaration(schemLocation); // keys for graphic representation for (VertexAttribute attr : network.getVertexAttributes()) { final Element element = new Element("key"); element.setAttribute("id", attr.getName()); element.setAttribute("for", "node"); element.setAttribute("attr.name", attr.getName()); element.setAttribute("attr.type", attr.getType().getName()); if (attr.getDefaultValue() != null) { final Element defaultValueElement = new Element("default"); defaultValueElement.addContent(attr.getDefaultValue().toString()); element.addContent(defaultValueElement); } graphml.addContent(element); } for (EdgeAttribute attr : network.getEdgeAttributes()) { final Element element = new Element("key"); element.setAttribute("id", attr.getName()); element.setAttribute("for", "edge"); element.setAttribute("attr.name", attr.getName()); element.setAttribute("attr.type", attr.getType().getName()); if (attr.getDefaultValue() != null) { final Element defaultValueElement = new Element("default"); defaultValueElement.addContent(attr.getDefaultValue()); element.addContent(defaultValueElement); } graphml.addContent(element); } final Element graph = new Element("graph"); graph.setAttribute("id", "G"); if (directed) { graph.setAttribute("edgedefault", "directed"); } else { graph.setAttribute("edgedefault", "undirected"); } graphml.addContent(graph); final ImmutableList<Vertex> vertices = ImmutableList.copyOf(network.getVertices()); final Iterator<Vertex> vertexIterator = vertices.iterator(); while (vertexIterator.hasNext()) { final Vertex vertex = vertexIterator.next(); addNode(vertex, graph); } final ImmutableList<Edge<? extends Vertex>> edges; edges = (ImmutableList<Edge<? extends Vertex>>) ImmutableList.copyOf(network.getEdges()); final UnmodifiableIterator<Edge<? extends Vertex>> edgeIterator = edges.iterator(); while (edgeIterator.hasNext()) { addEdge(edgeIterator.next(), graph); } final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); return outputter.outputString(document).replaceAll("xmlns=\"\" ", ""); }
From source file:by.epam.lw05.xml.ListToXml.java
private static Document listToDocument(List<Gun> guns) { Element root = new Element("arsenal", "tns", "http://www.example.com/Tarifes"); root.addNamespaceDeclaration(Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); Attribute attr = new Attribute("schemaLocation", "http://www.example.com/Tarifes myschema.xsd", Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); root.setAttribute(attr);//from www. ja va2s .c o m for (Gun gun : guns) { Element combatUnit = new Element("combatunit"); combatUnit.setAttribute("serial", String.valueOf(gun.getSerial())); Element model = new Element("model"); model.setText(gun.getModel()); combatUnit.addContent(model); Element handy = new Element("handy"); handy.setText(gun.getHandy()); combatUnit.addContent(handy); Element origin = new Element("origin"); origin.setText(String.valueOf(gun.getOrigin())); combatUnit.addContent(origin); Element ttx = new Element("ttx"); Element distance = new Element("distance"); distance.setText(String.valueOf(gun.getDistance())); ttx.addContent(distance); Element optics = new Element("optics"); optics.setText(String.valueOf(gun.isOptics())); ttx.addContent(optics); combatUnit.addContent(ttx); root.addContent(combatUnit); } return new Document(root); }
From source file:ca.nrc.cadc.caom2.xml.ObservationWriter.java
License:Open Source License
/** * Build the root Element of a Observation. * * @param obs//w ww . j a v a 2 s .c o m * Observation. * @return root an Observation Element. */ protected Element getRootElement(Observation obs) { // Create the root element (observation). Element root = getObservationElement(obs); root.addNamespaceDeclaration(caom2Namespace); root.addNamespaceDeclaration(xsiNamespace); return root; }
From source file:ca.nrc.cadc.conformance.vos.InvalidTypeNodeWriter.java
License:Open Source License
/** * Returns the root JDOM Element of the node, with an invalid xsi:type * attribute./*from w w w . ja va 2 s. c o m*/ * * @param node the Node. * @return the root element. */ @Override protected Element getRootElement(Node node) { // Create the root element (node). Element root = new Element("node", NodeWriter.vosNamespace); root.addNamespaceDeclaration(NodeWriter.vosNamespace); root.addNamespaceDeclaration(NodeWriter.xsiNamespace); root.setAttribute("uri", node.getUri().toString()); root.setAttribute("type", "vos:invalid_type" + "Type", NodeWriter.xsiNamespace); return root; }
From source file:ca.nrc.cadc.dali.tables.votable.VOTableWriter.java
License:Open Source License
/** * Builds a empty VOTable document with the appropriate namespaces and * attributes./*w w w. jav a 2 s .c o m*/ * * @return VOTable document. */ protected Document createDocument() { // the root VOTABLE element Namespace vot = Namespace.getNamespace(VOTABLE_12_NS_URI); Namespace xsi = Namespace.getNamespace("xsi", XSI_SCHEMA); Element votable = new Element("VOTABLE", vot); votable.setAttribute("version", VOTABLE_VERSION); votable.addNamespaceDeclaration(xsi); Document document = new Document(); document.addContent(votable); return document; }
From source file:ca.nrc.cadc.uws.JobListWriter.java
License:Open Source License
public Element getRootElement(Iterator<JobRef> jobs) { ContentConverter<Element, JobRef> contentConverter = new ContentConverter<Element, JobRef>() { @Override//from w ww. j a va2s. com public Element convert(final JobRef jobRef) { return getShortJobDescription(jobRef); } }; Element root = new IterableContent<Element, JobRef>(JobAttribute.JOBS.getAttributeName(), UWS.NS, jobs, contentConverter); root.addNamespaceDeclaration(UWS.NS); root.addNamespaceDeclaration(UWS.XLINK_NS); root.setAttribute(JobAttribute.VERSION.getAttributeName(), UWS.XSD_VERSION); return root; }
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Get an Element representing a job Element. * * @return A job Element.// w w w. ja v a 2 s. c o m */ public static Element getJob() { Element element = new Element(JobAttribute.JOB.getAttributeName(), UWS.NS); element.addNamespaceDeclaration(UWS.NS); element.addNamespaceDeclaration(UWS.XLINK_NS); //element.setAttribute("schemaLocation", "http://www.ivoa.net/xml/UWS/v1.0 UWS.xsd", UWS.XSI_NS); return element; }
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Create the root element of a job document. * @param job/*from w w w. j av a 2s . c om*/ * @return */ public Element getRootElement(Job job) { Element root = new Element(JobAttribute.JOB.getAttributeName(), UWS.NS); root.addNamespaceDeclaration(UWS.NS); root.addNamespaceDeclaration(UWS.XLINK_NS); root.setAttribute(JobAttribute.VERSION.getAttributeName(), UWS.XSD_VERSION); root.addContent(getJobId(job)); root.addContent(getRunId(job)); root.addContent(getOwnerId(job)); root.addContent(getPhase(job)); root.addContent(getQuote(job)); root.addContent(getStartTime(job)); root.addContent(getEndTime(job)); root.addContent(getCreationTime(job)); root.addContent(getExecutionDuration(job)); root.addContent(getDestruction(job)); root.addContent(getParameters(job)); root.addContent(getResults(job)); Element errorSummary = getErrorSummary(job); if (errorSummary != null) root.addContent(errorSummary); Element jobInfo = getJobInfo(job); if (jobInfo != null) root.addContent(jobInfo); return root; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Build the root Element of a Node.//from w w w . j ava 2 s.c o m * * @param node Node. * @return root Element. */ protected Element getRootElement(Node node) { // Create the root element (node). Element root = getNodeElement(node); root.addNamespaceDeclaration(vosNamespace); root.addNamespaceDeclaration(xsiNamespace); return root; }
From source file:ca.nrc.cadc.vos.server.ViewsWriter.java
License:Open Source License
/** * Create the root views element.//www . ja v a 2s. co m * @return */ protected Element getRootElement() { // Create the root element (node). Element root = new Element("views", defaultNamespace); root.addNamespaceDeclaration(vosNamespace); root.addNamespaceDeclaration(xsiNamespace); return root; }