List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname, final Namespace ns)
From source file:ca.nrc.cadc.uws.JobReader.java
License:Open Source License
private Job parseJob(Document doc) throws ParseException, DataConversionException { Element root = doc.getRootElement(); String jobID = root.getChildText(JobAttribute.JOB_ID.getAttributeName(), UWS.NS); if (jobID != null && jobID.trim().length() == 0) jobID = null;// www . j av a 2 s. co m String runID = parseStringContent(root.getChild(JobAttribute.RUN_ID.getAttributeName(), UWS.NS)); String ownerID = parseStringContent(root.getChild(JobAttribute.OWNER_ID.getAttributeName(), UWS.NS)); Date quote = parseDate(parseStringContent(root.getChild(JobAttribute.QUOTE.getAttributeName(), UWS.NS))); Date startTime = parseDate( parseStringContent(root.getChild(JobAttribute.START_TIME.getAttributeName(), UWS.NS))); Date endTime = parseDate( parseStringContent(root.getChild(JobAttribute.END_TIME.getAttributeName(), UWS.NS))); Date creationTime = parseDate( parseStringContent(root.getChild(JobAttribute.CREATION_TIME.getAttributeName(), UWS.NS))); Date destructionTime = parseDate( parseStringContent(root.getChild(JobAttribute.DESTRUCTION_TIME.getAttributeName(), UWS.NS))); Long executionDuration = new Long( parseStringContent(root.getChild(JobAttribute.EXECUTION_DURATION.getAttributeName(), UWS.NS))); ExecutionPhase executionPhase = parseExecutionPhase(doc); ErrorSummary errorSummary = null; if (executionPhase.equals(ExecutionPhase.ERROR)) errorSummary = parseErrorSummary(doc); List<Result> resultsList = parseResultsList(doc); List<Parameter> parameterList = parseParametersList(doc); JobInfo jobInfo = parseJobInfo(doc); Job job = new Job(jobID, executionPhase, executionDuration, destructionTime, quote, startTime, endTime, creationTime, errorSummary, ownerID, runID, null, null, jobInfo, parameterList, resultsList); return job; }
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;//from w w w .j av a2s . c o m 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;//from w ww.ja v a 2s .co 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.uws.JobReader.java
License:Open Source License
private ErrorSummary parseErrorSummary(Document doc) { ErrorSummary rtn = null;//from w ww.j ava2s . c o m Element root = doc.getRootElement(); Element e = root.getChild(JobAttribute.ERROR_SUMMARY.getAttributeName(), UWS.NS); if (e != null) { ErrorType errorType = null; String strType = e.getAttributeValue("type"); if (strType.equalsIgnoreCase(ErrorType.FATAL.toString())) errorType = ErrorType.FATAL; else if (strType.equalsIgnoreCase(ErrorType.TRANSIENT.toString())) errorType = ErrorType.TRANSIENT; boolean hasDetail = false; String strDetail = e.getAttributeValue("hasDetail"); if (strDetail.equalsIgnoreCase("true")) hasDetail = true; String summaryMessage = e.getChildText(JobAttribute.ERROR_SUMMARY_MESSAGE.getAttributeName(), UWS.NS); rtn = new ErrorSummary(summaryMessage, errorType, hasDetail); } return rtn; }
From source file:ca.nrc.cadc.uws.JobReader.java
License:Open Source License
private JobInfo parseJobInfo(Document doc) { JobInfo rtn = null;//from ww w.j a va 2 s.c o m Element root = doc.getRootElement(); Element e = root.getChild(JobAttribute.JOB_INFO.getAttributeName(), UWS.NS); if (e != null) { log.debug("found jobInfo element"); String content = e.getText(); List children = e.getChildren(); if (content != null) content = content.trim(); if (content.length() > 0) // it was text content { rtn = new JobInfo(content, null, null); } else if (children != null) { if (children.size() == 1) { try { Element ce = (Element) children.get(0); Document jiDoc = new Document((Element) ce.detach()); XMLOutputter outputter = new XMLOutputter(); StringWriter sw = new StringWriter(); outputter.output(jiDoc, sw); sw.close(); rtn = new JobInfo(sw.toString(), null, null); } catch (IOException ex) { throw new RuntimeException("BUG while writing element to string", ex); } } } } log.debug("parseJobInfo: " + rtn); return rtn; }
From source file:ca.nrc.cadc.vos.NodeReader.java
License:Open Source License
/** * Constructs a LinkNode from the given root Element of the * Document, Document Namespace, and Node path. * * @param el a node Element in the Document. * @param namespace Document Namespace./*from w w w. j av a 2s.c o m*/ * @param uri Node uri attribute. * @param target Target resource pointed to by the LinkNode * @return LinkNode. * @throws NodeParsingException if there is an error parsing the XML. * @throws URISyntaxException */ protected Node buildLinkNode(Element el, Namespace namespace, String uri) throws NodeParsingException, URISyntaxException { // Instantiate a LinkNode class LinkNode node; VOSURI vosuri; // target element in the node element Element target = el.getChild("target", namespace); if (target == null) { String error = "target element not found in node element"; throw new NodeParsingException(error); } log.debug("node target: " + target.getText()); try { vosuri = new VOSURI(uri); } catch (URISyntaxException e) { String error = "invalid node uri " + uri; throw new NodeParsingException(error, e); } try { node = new LinkNode(vosuri, new URI(target.getText())); } catch (URISyntaxException e) { String error = "invalid node target " + target.getText(); throw new NodeParsingException(error, e); } // properties element node.setProperties(getProperties(el, namespace)); return node; }
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 w ww . ja v a2 s. co 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; }
From source file:ca.nrc.cadc.vos.NodeReader.java
License:Open Source License
/** * Builds a List of NodeProperty objects from the Document property Elements. * * @param el a node Element of the Document. * @param namespace Document Namespace.//from w w w.j av a2 s . co m * @return List of NodeProperty objects. * @throws NodeParsingException if there is an error parsing the XML. */ protected List<NodeProperty> getProperties(Element el, Namespace namespace) throws NodeParsingException { // properties element Element properties = el.getChild("properties", namespace); if (properties == null) { String error = "properties element not found"; throw new NodeParsingException(error); } // new NodeProperty List List<NodeProperty> set = new ArrayList<NodeProperty>(); // properties property elements List<Element> propertyList = properties.getChildren("property", namespace); for (Element property : propertyList) { String propertyUri = property.getAttributeValue("uri"); if (propertyUri == null) { String error = "uri attribute not found in property element " + property; throw new NodeParsingException(error); } // xsi:nil set to true indicates Property is to be deleted String xsiNil = property.getAttributeValue("nil", xsiNamespace); boolean markedForDeletion = false; if (xsiNil != null) markedForDeletion = xsiNil.equalsIgnoreCase("true") ? true : false; // if marked for deletetion, property can not contain text content String text = property.getText(); if (markedForDeletion) text = ""; // create new NodeProperty NodeProperty nodeProperty = new NodeProperty(propertyUri, text); // set readOnly attribute String readOnly = property.getAttributeValue("readOnly"); if (readOnly != null) nodeProperty.setReadOnly((readOnly.equalsIgnoreCase("true") ? true : false)); // markedForDeletion attribute nodeProperty.setMarkedForDeletion(markedForDeletion); set.add(nodeProperty); } return set; }
From source file:ca.nrc.cadc.vos.NodeReader.java
License:Open Source License
protected List<URI> getViewURIs(Element root, Namespace namespace, String parent) throws NodeParsingException, URISyntaxException { // new View List List<URI> list = new ArrayList<URI>(); // view parent element Element parentElement = root.getChild(parent, namespace); if (parentElement == null) { return list; }//w w w . ja va 2s . c o m // view elements List<Element> uriList = parentElement.getChildren("view", namespace); for (Element view : uriList) { // view uri attribute String viewUri = view.getAttributeValue("uri"); if (viewUri == null) { String error = "uri attribute not found in " + parent + " view element"; throw new NodeParsingException(error); } log.debug(parent + "view uri: " + viewUri); list.add(new URI(viewUri)); } return list; }
From source file:ca.nrc.cadc.vos.NodeReader.java
License:Open Source License
/** * Builds a List of View objects from the view elements contained within * the given parent element.//from w w w .j a va 2s .c o m * * @param root Root Element of the Document. * @param namespace Document Namespace. * @param parent View Parent Node. * @return List of View objects. * @throws NodeParsingException if there is an error parsing the XML. */ protected List<View> getViews(Element root, Namespace namespace, String parent) throws NodeParsingException { // view parent element Element parentElement = root.getChild(parent, namespace); if (parentElement == null) { String error = parent + " element not found in node"; throw new NodeParsingException(error); } // new View List List<View> list = new ArrayList<View>(); // view elements List<Element> viewList = parentElement.getChildren("view", namespace); for (Element view : viewList) { // view uri attribute String viewUri = view.getAttributeValue("uri"); if (viewUri == null) { String error = "uri attribute not found in " + parent + " view element"; throw new NodeParsingException(error); } log.debug(parent + "view uri: " + viewUri); // new View // View acceptsView = new View(viewUri, node); // view original attribute String original = view.getAttributeValue("original"); if (original != null) { boolean isOriginal = original.equalsIgnoreCase("true") ? true : false; // view.setOriginal(isOriginal); log.debug(parent + " view original: " + isOriginal); } List<Element> paramList = view.getChildren("param", namespace); for (Element param : paramList) { String paramUri = param.getAttributeValue("uri"); if (paramUri == null) { String error = "param uri attribute not found in accepts view element"; throw new NodeParsingException(error); } log.debug("accepts view param uri: " + paramUri); // TODO: what are params??? } } return list; }