List of usage examples for org.jdom2 Element Element
public Element(final String name, final String uri)
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Get an Element representing the Job jobInfo. * * @return The Job jobInfo Element.//from w ww . j a va 2 s.c o m */ public Element getJobInfo(Job job) { Element element = null; JobInfo jobInfo = job.getJobInfo(); if (jobInfo != null) { if (jobInfo.getContent() != null && jobInfo.getValid() != null && jobInfo.getValid()) { element = new Element(JobAttribute.JOB_INFO.getAttributeName(), UWS.NS); try { // The JobInfo content can't be validated since the schema(s) aren't known // but we still need to parse and extract the root/document element Document doc = XmlUtil.buildDocument(jobInfo.getContent()); element.addContent(doc.getRootElement().detach()); } catch (Exception e) { element = null; } } } return element; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Builds a single node element./*from www . jav a2 s . c o m*/ * * @param node * @return */ protected Element getNodeElement(Node node) { Element ret = new Element("node", vosNamespace); ret.setAttribute("uri", node.getUri().toString()); ret.setAttribute("type", vosNamespace.getPrefix() + ":" + node.getClass().getSimpleName(), xsiNamespace); Element props = getPropertiesElement(node); ret.addContent(props); if (node instanceof ContainerNode) { ContainerNode cn = (ContainerNode) node; ret.addContent(getNodesElement(cn)); } else if ((node instanceof DataNode) || (node instanceof UnstructuredDataNode) || (node instanceof StructuredDataNode)) { ret.addContent(getAcceptsElement(node)); ret.addContent(getProvidesElement(node)); DataNode dn = (DataNode) node; ret.setAttribute("busy", (dn.getBusy().equals(NodeBusyState.notBusy) ? "false" : "true")); } else if (node instanceof LinkNode) { LinkNode ln = (LinkNode) node; Element targetEl = new Element("target", vosNamespace); targetEl.setText(ln.getTarget().toString()); ret.addContent(targetEl); } return ret; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Build the properties Element of a Node. * * @param node Node./*from ww w . j a v a 2 s.c o m*/ * @return properties Element. */ protected Element getPropertiesElement(Node node) { Element ret = new Element("properties", vosNamespace); for (NodeProperty nodeProperty : node.getProperties()) { Element property = new Element("property", vosNamespace); if (nodeProperty.isMarkedForDeletion()) property.setAttribute(new Attribute("nil", "true", xsiNamespace)); else property.setText(nodeProperty.getPropertyValue()); property.setAttribute("uri", nodeProperty.getPropertyURI()); property.setAttribute("readOnly", (nodeProperty.isReadOnly() ? "true" : "false")); ret.addContent(property); } return ret; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Build the accepts Element of a Node.//from w ww .j a v a 2 s.com * * @param node Node. * @return accepts Element. */ protected Element getAcceptsElement(Node node) { Element accepts = new Element("accepts", vosNamespace); for (URI viewURI : node.accepts()) { Element viewElement = new Element("view", vosNamespace); viewElement.setAttribute("uri", viewURI.toString()); accepts.addContent(viewElement); } return accepts; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Build the accepts Element of a Node.//from w w w .j a va 2s . c o m * * @param node Node. * @return accepts Element. */ protected Element getProvidesElement(Node node) { Element provides = new Element("provides", vosNamespace); for (URI viewURI : node.provides()) { Element viewElement = new Element("view", vosNamespace); viewElement.setAttribute("uri", viewURI.toString()); provides.addContent(viewElement); } return provides; }
From source file:ca.nrc.cadc.vos.NodeWriter.java
License:Open Source License
/** * Build the nodes Element of a ContainerNode. * //from www . j a v a2s . co m * @param node Node. * @return nodes Element. */ protected Element getNodesElement(ContainerNode node) { Element nodes = new Element("nodes", vosNamespace); for (Node childNode : node.getNodes()) { Element nodeElement = getNodeElement(childNode); nodes.addContent(nodeElement); } return nodes; }
From source file:ca.nrc.cadc.vos.server.ViewsWriter.java
License:Open Source License
/** * Create the root views element./* ww w.j a v a 2 s. c o m*/ * @return */ protected Element getRootElement() { // Create the root element (node). Element root = new Element("views", defaultNamespace); root.addNamespaceDeclaration(vosNamespace); root.addNamespaceDeclaration(xsiNamespace); return root; }
From source file:ca.nrc.cadc.vos.server.ViewsWriter.java
License:Open Source License
/** * Create a URI list for the views./*from w w w . j a v a 2 s .c o m*/ * @param name * @param uris * @return */ protected Element getViewsListElement(String name, List<String> uris) { Element viewList = new Element(name, defaultNamespace); for (String uri : uris) { Element property = new Element("view", defaultNamespace); property.setAttribute("uri", uri); viewList.addContent(property); } return viewList; }
From source file:ca.nrc.cadc.vos.TransferWriter.java
License:Open Source License
/** * Build root element for the transfer.// www. j av a 2 s . c o m * @param transfer * @return root element */ private Element buildRoot(Transfer transfer) { Element root = new Element("transfer", TransferReader.VOS_NS); root.addNamespaceDeclaration(TransferReader.VOS_NS); Element e = null; e = new Element("target", TransferReader.VOS_NS); e.addContent(transfer.getTarget().getURIObject().toASCIIString()); root.addContent(e); e = new Element("direction", TransferReader.VOS_NS); e.addContent(transfer.getDirection().getValue()); root.addContent(e); e = new Element("view", TransferReader.VOS_NS); if (transfer.getView() != null) { e.setAttribute("uri", transfer.getView().getURI().toString()); for (View.Parameter param : transfer.getView().getParameters()) { Element pm = new Element("param", TransferReader.VOS_NS); pm.setAttribute("uri", param.getUri().toString()); pm.setText(param.getValue()); e.addContent(pm); } root.addContent(e); } if (transfer.getProtocols() != null) { for (Protocol protocol : transfer.getProtocols()) { Element pr = new Element("protocol", TransferReader.VOS_NS); pr.setAttribute("uri", protocol.getUri()); if (protocol.getEndpoint() != null) { Element ep = new Element("endpoint", TransferReader.VOS_NS); ep.addContent(protocol.getEndpoint()); pr.addContent(ep); } root.addContent(pr); } } e = new Element("keepBytes", TransferReader.VOS_NS); e.addContent(new Boolean(transfer.isKeepBytes()).toString()); root.addContent(e); return root; }
From source file:ca.nrc.cadc.vosi.Availability.java
License:Open Source License
public Document toXmlDocument() { DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); Namespace vosi = Namespace.getNamespace("vosi", VOSI.AVAILABILITY_NS_URI); Element eleAvailability = new Element("availability", vosi); Util.addChild(eleAvailability, vosi, "available", Boolean.toString(_status.isAvailable())); if (_status.getUpSince() != null) Util.addChild(eleAvailability, vosi, "upSince", df.format(_status.getUpSince())); if (_status.getDownAt() != null) Util.addChild(eleAvailability, vosi, "downAt", df.format(_status.getDownAt())); if (_status.getBackAt() != null) Util.addChild(eleAvailability, vosi, "backAt", df.format(_status.getBackAt())); if (_status.getNote() != null) Util.addChild(eleAvailability, vosi, "note", _status.getNote()); Document document = new Document(); document.addContent(eleAvailability); return document; }