List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Get an Element representing the Job parameters. * * @return The Job parameters Element./* w w w . j a va 2s . c om*/ */ public Element getParameters(Job job) { Element element = new Element(JobAttribute.PARAMETERS.getAttributeName(), UWS.NS); for (Parameter parameter : job.getParameterList()) { Element e = new Element(JobAttribute.PARAMETER.getAttributeName(), UWS.NS); e.setAttribute("id", parameter.getName()); e.addContent(parameter.getValue()); element.addContent(e); } return element; }
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Get an Element representing the Job results. * * @return The Job results Element.// w w w .j a v a2 s. c om */ public Element getResults(Job job) { Element element = new Element(JobAttribute.RESULTS.getAttributeName(), UWS.NS); for (Result result : job.getResultsList()) { Element e = new Element(JobAttribute.RESULT.getAttributeName(), UWS.NS); e.setAttribute("id", result.getName()); e.setAttribute("href", result.getURI().toASCIIString(), UWS.XLINK_NS); element.addContent(e); } return element; }
From source file:ca.nrc.cadc.uws.JobWriter.java
License:Open Source License
/** * Get an Element representing the Job errorSummary. * * @return The Job errorSummary Element. *//*from w w w .j a va 2 s .co m*/ public Element getErrorSummary(Job job) { Element eleErrorSummary = null; ErrorSummary es = job.getErrorSummary(); if (es != null) { eleErrorSummary = new Element(JobAttribute.ERROR_SUMMARY.getAttributeName(), UWS.NS); eleErrorSummary.setAttribute("type", es.getErrorType().toString().toLowerCase()); eleErrorSummary.setAttribute("hasDetail", Boolean.toString(es.getHasDetail())); Element eleMessage = new Element(JobAttribute.ERROR_SUMMARY_MESSAGE.getAttributeName(), UWS.NS); eleMessage.addContent(job.getErrorSummary().getSummaryMessage()); eleErrorSummary.addContent(eleMessage); } return eleErrorSummary; }
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.// w w w . j a v a2 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 .j a v a 2 s.co 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./* w w w .j a va 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 w w . j a v a 2 s . co m*/ * * @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.// w w w .ja va 2 s . 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 w w w . j a v a2 s.c om*/ * @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.RssFeed.java
License:Open Source License
/** * Builds a JDOM Element representing the RRS feed of set of Nodes. * * @param parent The parent Node of all other Nodes in the feed. * @param nodes Collection of nodes to display in the feed. * @param baseURL base url for the nodes resource * @return JDOM Element representing the RRS feed. *///from w w w. j a v a2 s.co m public static Element createFeed(Node parent, Collection<RssFeedItem> nodes, String baseURL) { // Get the title and description from the parent properties. String parentTitle = null; String parentDescription = null; for (NodeProperty nodeProperty : parent.getProperties()) { if (nodeProperty.getPropertyURI().equals(VOS.PROPERTY_URI_TITLE)) { parentTitle = nodeProperty.getPropertyValue(); } if (nodeProperty.getPropertyURI().equals(VOS.PROPERTY_URI_DESCRIPTION)) { parentDescription = nodeProperty.getPropertyValue(); } } // Root element. Element rss = new Element("rss"); rss.setAttribute("version", "2.0"); // channel element. Element channel = new Element("channel"); rss.addContent(channel); // channel title. if (parentTitle == null) { parentTitle = "Last modified nodes for " + parent.getName(); } Element channelTitle = new Element("title"); channelTitle.setText(parentTitle); channel.addContent(channelTitle); // channel description. if (parentDescription == null) { parentDescription = nodes.size() + " last modified nodes"; } Element channelDescription = new Element("description"); channelDescription.setText(parentDescription); channel.addContent(channelDescription); // channel link. Element link = new Element("link"); link.setText(baseURL + parent.getUri().getPath() + "?view=rss"); channel.addContent(link); // channel author NodeProperty creator = parent.findProperty(VOS.PROPERTY_URI_CREATOR); if (creator != null && StringUtil.hasText(creator.getPropertyValue())) { Element author = new Element("author"); author.setText(creator.getPropertyValue()); channel.addContent(author); } log.debug("num nodes: " + nodes.size()); // Create an item for each Node and add to channel. for (RssFeedItem rssFeedItem : nodes) { // Get the title, description, and date from the node properties. String nodeTitle = null; String nodeDescription = null; String nodeDate = null; for (NodeProperty nodeProperty : rssFeedItem.node.getProperties()) { if (nodeProperty.getPropertyURI().equals(VOS.PROPERTY_URI_TITLE)) { nodeTitle = nodeProperty.getPropertyValue(); } if (nodeProperty.getPropertyURI().equals(VOS.PROPERTY_URI_DESCRIPTION)) { nodeDescription = nodeProperty.getPropertyValue(); } if (nodeProperty.getPropertyURI().equals(VOS.PROPERTY_URI_DATE)) { nodeDate = nodeProperty.getPropertyValue(); } } // item element. Element item = new Element("item"); // item title. if (nodeTitle == null) { nodeTitle = rssFeedItem.node.getName(); } Element itemTitle = new Element("title"); itemTitle.setText(nodeTitle); item.addContent(itemTitle); // item description. if (nodeDescription == null) { if (rssFeedItem.node instanceof DataNode) { nodeDescription = "File"; } else { nodeDescription = "Directory"; } } Element itemDescription = new Element("description"); itemDescription.setText(nodeDescription); item.addContent(itemDescription); // item pubDate if (nodeDate != null) { Element itemPubDate = new Element("pubDate"); itemPubDate.setText(nodeDate); item.addContent(itemPubDate); } // item link, comment Element itemLink = new Element("link"); Element comments = new Element("comments"); String linkText = baseURL + rssFeedItem.node.getUri().getPath(); if (rssFeedItem.node instanceof DataNode) { linkText += "?view=data"; comments.setText("Click to download this file."); } else { linkText += "?view=rss"; comments.setText("Click to see the last modified nodes within this directory."); } itemLink.setText(linkText); item.addContent(itemLink); item.addContent(comments); // item author creator = rssFeedItem.node.findProperty(VOS.PROPERTY_URI_CREATOR); if (creator != null && StringUtil.hasText(creator.getPropertyValue())) { Element author = new Element("author"); author.setText(creator.getPropertyValue()); item.addContent(author); } // Add item to channel channel.addContent(item); } return rss; }