List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren(final String cname, final Namespace ns)
List
of all the child elements nested directly (one level deep) within this element with the given local name and belonging to the given Namespace, returned as Element
objects. From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
private void addSamples(Interval inter, Element sampleElement, Namespace namespace, ReadContext rc) throws ObservationParsingException { if (sampleElement != null) { List<Element> sse = sampleElement.getChildren("sample", namespace); for (Element se : sse) { double lb = getChildTextAsDouble("lower", se, namespace, true); double ub = getChildTextAsDouble("upper", se, namespace, true); inter.getSamples().add(new SubInterval(lb, ub)); }//from w w w . java2 s .com } if (rc.docVersion < 23 && inter.getSamples().isEmpty()) { // backwards compat inter.getSamples().add(new SubInterval(inter.getLower(), inter.getUpper())); } }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
protected void addKeywordsToList(Collection<String> list, Element element, Namespace ns) throws ObservationParsingException { Element kwe = element.getChild("keywords", ns); log.debug("addKeywordsToList: " + kwe); if (kwe == null) { return;//from ww w. j a va2s .c om } List kws = kwe.getChildren("keyword", ns); log.debug("addKeywordsToList: " + kws.size()); Iterator it = kws.iterator(); while (it.hasNext()) { Element k = (Element) it.next(); String s = k.getTextTrim(); log.debug("addKeywordsToList: " + s); list.add(s); } }
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
protected List getChildrenElements(String name, Element element, Namespace ns, boolean required) throws ObservationParsingException { List children = element.getChildren(name, ns); if (required && children.isEmpty()) { String error = name + " element not found in " + element.getName(); throw new ObservationParsingException(error); }/*from w w w. j a v a 2s. co m*/ return children; }
From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java
License:Open Source License
/** * Read a XML VOTable from a Reader and build a VOTable object. * * @param reader Reader to read from./*from ww w. j a v a2 s . co m*/ * @return a VOTable object. * @throws IOException if problem reading from the reader. */ public VOTable read(Reader reader) throws IOException { // Parse the input document. Document document; try { document = docBuilder.build(reader); } catch (JDOMException e) { throw new IOException("Unable to parse " + e.getMessage()); } // Returned VOTable object. VOTable votable = new VOTable(); // Document root element. Element root = document.getRootElement(); // Namespace for the root element. Namespace namespace = root.getNamespace(); log.debug("Namespace: " + namespace); // RESOURCE element. Element resource = root.getChild("RESOURCE", namespace); if (resource != null) { // Get the RESOURCE name attribute. Attribute resourceName = resource.getAttribute("name"); if (resourceName != null) { votable.setResourceName(resourceName.getValue()); } // INFO element. List<Element> infos = resource.getChildren("INFO", namespace); votable.getInfos().addAll(getInfos(infos, namespace)); // TABLE element. Element table = resource.getChild("TABLE", namespace); if (table != null) { // PARAM elements. List<Element> params = table.getChildren("PARAM", namespace); votable.getParams().addAll(getParams(params, namespace)); // FIELD elements. List<Element> fields = table.getChildren("FIELD", namespace); votable.getColumns().addAll(getFields(fields, namespace)); // DATA element. Element data = table.getChild("DATA", namespace); if (data != null) { // TABLEDATA element. Element tableData = data.getChild("TABLEDATA", namespace); votable.setTableData(getTableData(tableData, namespace, votable.getColumns())); } } } return votable; }
From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java
License:Open Source License
/** * Populate a TableField object with values from the FIELD element. * * @param tableField TableField to populate. * @param element source Element./* www . j a v a2 s. c o m*/ * @param namespace document namespace. */ protected void updateTableField(TableField tableField, Element element, Namespace namespace) { tableField.id = element.getAttributeValue("ID"); tableField.ucd = element.getAttributeValue("ucd"); tableField.unit = element.getAttributeValue("unit"); tableField.utype = element.getAttributeValue("utype"); tableField.xtype = element.getAttributeValue("xtype"); String arraysize = element.getAttributeValue("arraysize"); if (arraysize != null) { int index = arraysize.indexOf("*"); if (index == -1) { tableField.variableSize = Boolean.FALSE; } else { arraysize = arraysize.substring(0, index); tableField.variableSize = Boolean.TRUE; } if (!arraysize.trim().isEmpty()) { tableField.arraysize = Integer.parseInt(arraysize); } } // DESCRIPTION element for the FIELD. Element description = element.getChild("DESCRIPTION", namespace); if (description != null) { tableField.description = description.getText(); } // VALUES element for the PARAM. Element values = element.getChild("VALUES", namespace); if (values != null) { List<Element> options = values.getChildren("OPTION", namespace); if (!options.isEmpty()) { tableField.values = new ArrayList<String>(); for (Element option : options) { tableField.values.add(option.getAttributeValue("value")); } } } }
From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java
License:Open Source License
/** * Build a List that contains the TableData rows. * * @param element TABLEDATA element.// ww w . j a v a2 s . c om * @param namespace document namespace. * @return TableData object containing rows of data. */ TableData getTableData(Element element, Namespace namespace, List<TableField> fields) { ArrayListTableData tableData = new ArrayListTableData(); if (element != null) { List<Element> trs = element.getChildren("TR", namespace); for (Element tr : trs) { List<Object> row = new ArrayList<Object>(); List<Element> tds = tr.getChildren("TD", namespace); for (int i = 0; i < tds.size(); i++) { Element td = tds.get(i); TableField field = fields.get(i); Format format = FormatFactory.getFormat(field); String text = td.getText(); Object o = format.parse(text); row.add(o); } tableData.getArrayList().add(row); } } return tableData; }
From source file:ca.nrc.cadc.reg.CapabilitiesReader.java
License:Open Source License
private Capabilities buildCapabilities(final Element root) { Capabilities caps = new Capabilities(); List<Element> capElementList = root.getChildren("capability", Namespace.NO_NAMESPACE); for (Element capElement : capElementList) { Capability cap = this.buildCapability(capElement); caps.getCapabilities().add(cap); }/*from w w w. j a va 2 s . c o m*/ return caps; }
From source file:ca.nrc.cadc.uws.JobReader.java
License:Open Source License
private List<Parameter> parseParametersList(Document doc) { List<Parameter> rtn = null; Element root = doc.getRootElement(); Element elementParameters = root.getChild(JobAttribute.PARAMETERS.getAttributeName(), UWS.NS); if (elementParameters != null) { rtn = new ArrayList<Parameter>(); Parameter par = null;// w ww . java 2 s . c om List<?> listElement = elementParameters.getChildren(JobAttribute.PARAMETER.getAttributeName(), UWS.NS); for (Object obj : listElement) { Element e = (Element) obj; String id = e.getAttributeValue("id"); String value = e.getText(); par = new Parameter(id, value); rtn.add(par); } } return rtn; }
From source file:ca.nrc.cadc.uws.JobReader.java
License:Open Source License
private List<Result> parseResultsList(Document doc) { List<Result> rtn = null; Element root = doc.getRootElement(); Element e = root.getChild(JobAttribute.RESULTS.getAttributeName(), UWS.NS); if (e != null) { rtn = new ArrayList<Result>(); Result rs = null;/* w w w .j av a2s. c o m*/ List<?> listE = e.getChildren(JobAttribute.RESULT.getAttributeName(), UWS.NS); for (Object obj : listE) { Element eRs = (Element) obj; String id = eRs.getAttributeValue("id"); String href = eRs.getAttributeValue("href", UWS.XLINK_NS); try { rs = new Result(id, new URI(href)); rtn.add(rs); } catch (URISyntaxException ex) { // do nothing; just do not add rs to list log.debug(ex.getMessage()); } } } return rtn; }
From source file:ca.nrc.cadc.vos.NodeReader.java
License:Open Source License
/** * Constructs a ContainerNode from the given Element of the * Document, Document Namespace, and Node path. * * @param el a node Element of the Document. * @param namespace Document Namespace.//from www. ja v a2 s. c o m * @param uri Node uri attribute. * @return ContainerNode * @throws NodeParsingException if there is an error parsing the XML. * @throws URISyntaxException */ protected Node buildContainerNode(Element el, Namespace namespace, String uri) throws NodeParsingException, URISyntaxException { // Instantiate a ContainerNode class ContainerNode node; try { node = new ContainerNode(new VOSURI(uri)); } catch (URISyntaxException e) { String error = "invalid node uri " + uri; throw new NodeParsingException(error, e); } // properties element node.setProperties(getProperties(el, namespace)); // nodes element Element nodes = el.getChild("nodes", namespace); if (nodes == null) { String error = "nodes element not found in node"; throw new NodeParsingException(error); } // list of child nodes List<Element> nodesList = nodes.getChildren("node", namespace); for (Element childNode : nodesList) { String childNodeUri = childNode.getAttributeValue("uri"); if (childNodeUri == null) { String error = "uri attribute not found in nodes node element"; throw new NodeParsingException(error); } // Get the xsi:type attribute which defines the Node class String xsiType = childNode.getAttributeValue("type", xsiNamespace); if (xsiType == null) { String error = "xsi:type attribute not found in node element " + uri; throw new NodeParsingException(error); } // Split the type attribute into namespace and Node type String[] types = xsiType.split(":"); String type = types[1]; log.debug("node type: " + type); if (type.equals(ContainerNode.class.getSimpleName())) node.getNodes().add(buildContainerNode(childNode, namespace, childNodeUri)); else if (type.equals(DataNode.class.getSimpleName())) node.getNodes().add(buildDataNode(childNode, namespace, childNodeUri)); else if (type.equals(LinkNode.class.getSimpleName())) node.getNodes().add(buildLinkNode(childNode, namespace, childNodeUri)); else throw new NodeParsingException("unsupported node type " + type); log.debug("added child node: " + childNodeUri); } return node; }