Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

In this page you can find the example usage for org.jdom2 Element getAttributeValue.

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

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./*from  w ww  . j  av a2  s  .  c om*/
 * @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.reg.CapabilitiesReader.java

License:Open Source License

private Interface buildInterface(final Element intfElement) {
    AccessURL accessURL = this.parseAccessURL(intfElement.getChild("accessURL"));
    URI securityMethod = this.parseSecurityMethod(intfElement.getChild("securityMethod"));
    String roleString = intfElement.getAttributeValue("role");
    Interface intf = new Interface(accessURL, securityMethod);
    intf.role = roleString;//  ww w . j  a  va  2 s  . com
    return intf;
}

From source file:ca.nrc.cadc.reg.CapabilitiesReader.java

License:Open Source License

private URI parseSecurityMethod(final Element securityMethodElement) {
    URI standardID;//from   w w  w  . j a  v a2s .c  o m

    if (securityMethodElement == null) {
        // anonymous access
        standardID = Standards.getSecurityMethod(AuthMethod.ANON);
    } else {
        // get the standardID for secure access
        String standardIDString = securityMethodElement.getAttributeValue("standardID");

        if (standardIDString == null) {
            String prefix = this.resourceIDStr + this.standardIDStr + this.accessURLStr;
            String msg = prefix + ", standardID attribute not found in securityMethod element";
            throw new RuntimeException(msg);
        }

        this.securityMethodStr = ", securityMethod standardID=" + standardIDString;
        try {
            standardID = new URI(standardIDString);
        } catch (URISyntaxException e) {
            String prefix = this.resourceIDStr + this.standardIDStr + this.accessURLStr
                    + this.securityMethodStr;
            String msg = prefix + ", invalid securityMethod standardID in xml: " + e.getMessage();
            throw new RuntimeException(msg);
        }
    }

    log.debug("securityMethod standardID: " + standardID);
    return standardID;
}

From source file:ca.nrc.cadc.reg.CapabilitiesReader.java

License:Open Source License

private String parseUse(final Element accessURLElement) {
    String useString = accessURLElement.getAttributeValue("use");
    if (useString == null) {
        String msg = this.resourceIDStr + this.standardIDStr + this.accessURLStr
                + ", use attribute not found in accessURL element";
        throw new RuntimeException(msg);
    }//from www . jav  a  2  s  . c  o  m

    log.debug("accessURL use: " + useString);
    return useString;
}

From source file:ca.nrc.cadc.reg.CapabilitiesReader.java

License:Open Source License

private URI parseStandardID(final Element capElement) {
    String standardIDString = capElement.getAttributeValue("standardID");
    if (standardIDString == null) {
        String msg = this.resourceIDStr + ", standardID attribute not found in capability element";
        throw new RuntimeException(msg);
    }/* w w w  .  j  ava2 s.  c o m*/

    this.standardIDStr = ", standardID=" + standardIDString;
    URI standardID;

    try {
        standardID = new URI(standardIDString);
    } catch (URISyntaxException e) {
        String msg = this.resourceIDStr + this.standardIDStr + ", invalid standardID in xml: " + e.getMessage();
        throw new RuntimeException(msg);
    }

    log.debug("capabilities standardID: " + standardIDString);
    return standardID;
}

From source file:ca.nrc.cadc.uws.JobListReader.java

License:Open Source License

private List<JobRef> parseJobList(Document doc) throws ParseException, DataConversionException {
    Element root = doc.getRootElement();
    List<Element> children = root.getChildren();
    Iterator<Element> childIterator = children.iterator();
    List<JobRef> jobs = new ArrayList<JobRef>();
    Element next = null;
    JobRef jobRef = null;// w w w  .java  2 s .com
    ExecutionPhase executionPhase = null;
    Date creationTime = null;
    Attribute nil = null;
    String runID = null;
    String ownerID = null;
    while (childIterator.hasNext()) {
        next = childIterator.next();
        String jobID = next.getAttributeValue("id");

        Element phaseElement = next.getChild(JobAttribute.EXECUTION_PHASE.getAttributeName(), UWS.NS);
        String phase = phaseElement.getValue();
        executionPhase = ExecutionPhase.valueOf(phase);

        Element creationTimeElement = next.getChild(JobAttribute.CREATION_TIME.getAttributeName(), UWS.NS);
        String time = creationTimeElement.getValue();
        creationTime = dateFormat.parse(time);

        Element runIDElement = next.getChild(JobAttribute.RUN_ID.getAttributeName(), UWS.NS);
        nil = runIDElement.getAttribute("nil", UWS.XSI_NS);
        if (nil != null && nil.getBooleanValue())
            runID = null;
        else
            runID = runIDElement.getTextTrim();

        Element ownerIDElement = next.getChild(JobAttribute.OWNER_ID.getAttributeName(), UWS.NS);
        ownerID = ownerIDElement.getTextTrim();

        jobRef = new JobRef(jobID, executionPhase, creationTime, runID, ownerID);
        jobs.add(jobRef);
    }

    return jobs;
}

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 ww . jav  a2 s  . 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 w w.ja v a 2  s .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  . java  2  s .co 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.vos.NodeReader.java

License:Open Source License

/**
 *  Construct a Node from a Reader./*from  w  w w.  jav a2  s.  c o m*/
 *
 * @param reader Reader.
 * @return Node Node.
 * @throws NodeParsingException if there is an error parsing the XML.
 */
public Node read(Reader reader) throws NodeParsingException, IOException {
    if (reader == null)
        throw new IllegalArgumentException("reader must not be null");

    // Create a JDOM Document from the XML
    Document document;
    try {
        // TODO: investigate creating a SAXBuilder once and re-using it
        // as long as we can detect concurrent access (a la java collections)
        document = XmlUtil.validateXml(reader, schemaMap);
    } catch (JDOMException jde) {
        String error = "XML failed schema validation: " + jde.getMessage();
        throw new NodeParsingException(error, jde);
    }

    // Root element and namespace of the Document
    Element root = document.getRootElement();
    Namespace namespace = root.getNamespace();
    log.debug("node namespace uri: " + namespace.getURI());
    log.debug("node namespace prefix: " + namespace.getPrefix());

    /* Node base elements */
    // uri attribute of the node element
    String uri = root.getAttributeValue("uri");
    if (uri == null) {
        String error = "uri attribute not found in root element";
        throw new NodeParsingException(error);
    }
    log.debug("node uri: " + uri);

    // Get the xsi:type attribute which defines the Node class
    String xsiType = root.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);

    try {
        if (type.equals(ContainerNode.class.getSimpleName()))
            return buildContainerNode(root, namespace, uri);
        else if (type.equals(DataNode.class.getSimpleName()))
            return buildDataNode(root, namespace, uri);
        else if (type.equals(UnstructuredDataNode.class.getSimpleName()))
            return buildUnstructuredDataNode(root, namespace, uri);
        else if (type.equals(LinkNode.class.getSimpleName()))
            return buildLinkNode(root, namespace, uri);
        else if (type.equals(StructuredDataNode.class.getSimpleName()))
            return buildStructuredDataNode(root, namespace, uri);
        else
            throw new NodeParsingException("unsupported node type " + type);
    } catch (URISyntaxException e) {
        throw new NodeParsingException("invalid uri in xml: " + e.getMessage());
    }
}