List of usage examples for org.jdom2 Element addContent
@Override public Element addContent(final Collection<? extends Content> newContent)
From source file:ca.nrc.cadc.vos.server.RssFeed.java
License:Open Source License
/** * Builds a JDOM Element representing a RRS feed that displays an error state. * * @param node The Node causing the error. * @param message The message to display. * @param baseURL base url for the nodes resource * @return JDOM Element representing the RRS feed. *///from w w w . j a va 2s.com public static Element createErrorFeed(Node node, String message, String baseURL) { // Root element. Element rss = new Element("rss"); rss.setAttribute("version", "2.0"); // channel element. Element channel = new Element("channel"); rss.addContent(channel); // channel title. Element title = new Element("title"); String nodeName = node.getName(); if (nodeName == null) { nodeName = "unknown node"; } title.setText("Error processing Node " + nodeName); channel.addContent(title); // channel link. Element link = new Element("link"); String nodePath = node.getUri().getPath(); if (nodePath == null) { link.setText("unknown link"); } else { link.setText(baseURL + nodePath + "?view=rss"); } channel.addContent(link); // channel description. Element description = new Element("description"); description.setText(message); channel.addContent(description); return rss; }
From source file:ca.nrc.cadc.vos.server.ViewsWriter.java
License:Open Source License
/** * Write accepts and provides to a Writer. * * @param node Node to write./*from w ww. ja v a 2s. c o m*/ * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ public void write(List<String> accepts, List<String> provides, Writer writer) throws IOException { // Create the root node element Element root = getRootElement(); // accepts element root.addContent(getViewsListElement("accepts", accepts)); // provides element root.addContent(getViewsListElement("provides", provides)); // write out the Document write(root, writer); }
From source file:ca.nrc.cadc.vos.server.ViewsWriter.java
License:Open Source License
/** * Create a URI list for the views.//from w ww. j a v a2 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./* ww w. ja va2 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.Capabilities.java
License:Open Source License
public Document toXmlDocument() { Namespace xsi = Namespace.getNamespace("xsi", VOSI.XSI_NS_URI); Namespace cap = Namespace.getNamespace("vosi", VOSI.CAPABILITIES_NS_URI); Namespace vod = Namespace.getNamespace("vod", VOSI.VODATASERVICE_NS_URI); Element eleCapabilities = new Element("capabilities", cap); eleCapabilities.addNamespaceDeclaration(xsi); eleCapabilities.addNamespaceDeclaration(cap); eleCapabilities.addNamespaceDeclaration(vod); //Attribute attSchemaLocation = new Attribute("schemaLocation", XSI_LOC, xsi); //eleCapabilities.setAttribute(attSchemaLocation); Document document = new Document(); document.addContent(eleCapabilities); for (Capability capability : this._caps) { eleCapabilities.addContent(capability.toXmlElement(xsi, cap, vod)); }/*from ww w . j a va 2s .com*/ return document; }
From source file:ca.nrc.cadc.vosi.Capability.java
License:Open Source License
public Element toXmlElement(Namespace xsi, Namespace cap, Namespace vor) { Element eleCapability = new Element("capability"); eleCapability.setAttribute("standardID", _standardID); Element eleInterface = new Element("interface"); eleCapability.addContent(eleInterface); Attribute attType = new Attribute("type", vor.getPrefix() + ":ParamHTTP", xsi); eleInterface.setAttribute(attType);/*from w w w . j a va2s .c om*/ if (_role != null) eleInterface.setAttribute("role", _role); Element eleAccessURL = new Element("accessURL"); eleInterface.addContent(eleAccessURL); eleAccessURL.setAttribute("use", "full"); eleAccessURL.setText(_hostContext + _resourceName); return eleCapability; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param ts/* w w w . j a v a 2s. co m*/ * @return */ private Element toXmlElement(TapSchema ts) { if (ts.getSchemaDescs().isEmpty()) throw new IllegalArgumentException("Error: at least one schema is required."); Element eleTableset = new Element("tableset", vosi); for (SchemaDesc sd : ts.getSchemaDescs()) { eleTableset.addContent(toXmlElement(sd, Namespace.NO_NAMESPACE)); } return eleTableset; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param sd// www.j a v a 2 s . c o m * @return */ private Element toXmlElement(SchemaDesc sd, Namespace ns) { Element eleSchema = new Element("schema", ns); Element ele; ele = new Element("name"); if (sd.getSchemaName() == null) ele.setText(DEFAULT_SCHEMA); else ele.setText(sd.getSchemaName()); eleSchema.addContent(ele); if (sd.getTableDescs() != null) for (TableDesc td : sd.getTableDescs()) { eleSchema.addContent(toXmlElement(td, Namespace.NO_NAMESPACE)); } return eleSchema; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param td/*from ww w . j a v a 2 s . c o m*/ * @return */ private Element toXmlElement(TableDesc td, Namespace ns) { Element eleTable = new Element("table", ns); eleTable.setAttribute("type", "output"); Element ele; ele = new Element("name"); ele.setText(td.getTableName()); eleTable.addContent(ele); if (td.getColumnDescs() != null) for (ColumnDesc cd : td.getColumnDescs()) { Element e = toXmlElement(cd); if (e != null) eleTable.addContent(e); } if (td.getKeyDescs() != null) for (KeyDesc kd : td.getKeyDescs()) { Element e = toXmlElement(kd); if (e != null) eleTable.addContent(e); } return eleTable; }
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
private Element toXmlElement(KeyDesc kd) { Element ret = new Element("foreignKey"); addChild(ret, "targetTable", kd.getTargetTable()); for (KeyColumnDesc kc : kd.getKeyColumnDescs()) { Element fkc = new Element("fkColumn"); addChild(fkc, "fromColumn", kc.getFromColumn()); addChild(fkc, "targetColumn", kc.getTargetColumn()); ret.addContent(fkc); }//from www .j ava 2 s . c om addChild(ret, "description", kd.description); addChild(ret, "utype", kd.utype); return ret; }