Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

/**
 * Parses the value of the given attribute as a {@linkplain QName qualified name}.
 * @param attr the attribute whose value will be parsed
 * @return the attribute value as a {@link QName}
 *///from   w  w  w .  j a  va2 s. com
public static QName getQNameValue(Attr attr) {
    return parseQName(attr.getValue(), attr.getOwnerElement());
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the value of the specified node attribute or null if it is missing.
 * <p>//from   w w w  .j a v a 2s.co m
 * 
 * @param name
 *          (local) name of attribute
 * @param node
 *          current element
 * @return the textual contents of the attribute or null
 */
public static String getAttrValue(final String name, final Node node) {
    String value = null;
    final NamedNodeMap atts = node.getAttributes();

    if (atts != null) {
        final Attr attribute = (Attr) atts.getNamedItem(name);

        if (attribute != null) {
            value = attribute.getValue();
        }
    }
    return value;
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the value of the specified node attribute.
 * <p>/*from  w ww.ja v a2 s .co  m*/
 * 
 * @param name
 *          (local) name of attribute
 * @param node
 *          current element
 * @return the textual contents of the attribute
 * @throws XMLParsingException
 *           if specified attribute is missing
 */
public static String getRequiredAttrValue(final String name, final Node node) throws XMLParsingException {
    String value = null;
    final NamedNodeMap atts = node.getAttributes();

    if (atts != null) {
        final Attr attribute = (Attr) atts.getNamedItem(name);

        if (attribute != null) {
            value = attribute.getValue();
        }
    }
    if (value == null) {
        throw new XMLParsingException(
                "Required attribute '" + name + "' of element '" + node.getNodeName() + "' is missing.");
    }
    return value;
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the value of the specified node attribute. // * FIXME: Due to apparent bugs in getNamedItemNS (name,
 * namespace), // * when used to find attribute nodes, the current implementation // * uses a workaround.
 * <p>//w  w w  .  j  av a2s  .c  o  m
 * 
 * @param name
 *          (local) name of attribute
 * @param namespace
 *          namespace of attribute
 * @param node
 *          current element
 * @return the textual contents of the attribute
 * @throws XMLParsingException
 *           if specified attribute is missing
 */
public static String getRequiredAttrValue(final String name, final String namespace, final Node node)
        throws XMLParsingException {
    String value = null;

    final NamedNodeMap atts = node.getAttributes();

    if (atts != null) {
        final Attr attribute = (Attr) atts.getNamedItemNS(namespace, name);

        if (attribute != null) {
            value = attribute.getValue();
        }
    }

    // for (int i = 0; i < atts.getLength (); i++) {
    // Node n = atts.item (i);
    // System.out.println ("Nodename: " + toLocalName (n.getNodeName ()));
    // System.out.println ("NamespaceURI: " + n.getNamespaceURI ());
    // if (n.getNamespaceURI ().equals (namespace) && toLocalName
    // (n.getNodeName
    // ()).equals (name)) {
    // System.out.println ("Me is here!");
    // value = ((Attr) n).getValue ();
    // break;
    // }
    // }

    if (value == null) {
        throw new XMLParsingException("Required attribute '" + namespace + ":" + name + "' of element '"
                + node.getNodeName() + "' is missing.");
    }
    return value;
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the attribute value of the given node.
 *//*  w  w w.j a v  a 2s  . c o m*/
public static String getAttrValue(final Node node, final String attrName) {
    // get attr name and dtype
    final NamedNodeMap atts = node.getAttributes();

    if (atts == null) {
        return null;
    }

    final Attr a = (Attr) atts.getNamedItem(attrName);

    if (a != null) {
        return a.getValue();
    }

    return null;
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the attribute value of the given node.
 *//*from w w  w. j a  v a  2  s .com*/
public static String getAttrValue(final Node node, final String namespace, final String attrName) {
    // get attr name and dtype
    final NamedNodeMap atts = node.getAttributes();

    if (atts == null) {
        return null;
    }

    final Attr a = (Attr) atts.getNamedItemNS(namespace, attrName);

    if (a != null) {
        return a.getValue();
    }

    return null;
}

From source file:org.kepler.sms.util.OntologyConfiguration.java

/**
 * Get the file path names for the ontologies
 *///ww w .j  ava  2s  .c o  m
public Iterator getFilePathNames() {
    Vector result = new Vector();
    if (_document == null)
        return result.iterator();

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return result.iterator();

    // iterate through root, get each ontology element and its
    // filename
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filename != null)
                result.addElement(getAbsoluteOntologyPath(filename));
        }
    }

    return result.iterator();
}

From source file:org.kepler.sms.util.OntologyConfiguration.java

public Color getLibraryColor(String filepath) {
    if (_document == null || filepath == null)
        return null;

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return null;

    filepath = new File(filepath).getAbsolutePath();

    // iterate to find the ontology with filepath
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filepath.equals(getAbsoluteOntologyPath(filename))) {
                Attr libatt = elem.getAttributeNode("color");
                if (libatt != null) {
                    String colorString = libatt.getValue();
                    return new Color(colorString);
                }/*from  w w  w  .  ja v a 2  s .c o  m*/
            }
        }
    }

    if (!defaultSetColors.containsKey(filepath)) {
        if (defaultColors.isEmpty()) {
            return Color.getDefaultColor();
        }
        defaultSetColors.put(filepath, defaultColors.remove(defaultColors.size() - 1));
    }
    return defaultSetColors.get(filepath);
}

From source file:org.kepler.sms.util.OntologyConfiguration.java

public Boolean isLibraryLocal(String filepath) {
    if (_document == null || filepath == null)
        return null;

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return null;
    // iterate to find the ontology with filepath
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filepath.equals(getAbsoluteOntologyPath(filename))) {
                Attr libatt = elem.getAttributeNode("local");
                if (libatt != null) {
                    String localityString = libatt.getValue();
                    return "true".equals(localityString);
                } else {
                    // Default to not editable
                    return false;
                }//from  w  w w. ja  v a2 s . c om
            }
        }
    }
    return false;
}

From source file:org.kepler.sms.util.OntologyConfiguration.java

/**
 * @return True if the filepath is suitable as a library categorization.
 */// w w w.j av a 2s. com
public boolean isLibraryOntology(String filepath) {
    if (_document == null || filepath == null)
        return false;

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return false;
    // iterate to find the ontology with filepath
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filepath.equals(getAbsoluteOntologyPath(filename))) {
                Attr libatt = elem.getAttributeNode("library");
                if (libatt != null) {
                    String library = libatt.getValue();
                    if (library != null && library.equals("true"))
                        return true;
                }
            }
        }
    }
    return false;
}