Example usage for org.jdom2 Element getNamespace

List of usage examples for org.jdom2 Element getNamespace

Introduction

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

Prototype

public Namespace getNamespace() 

Source Link

Document

Returns the element's Namespace .

Usage

From source file:org.helm.notation2.tools.MonomerParser.java

License:Open Source License

/**
 * Convert ATTACHMENT element to Attachment object
 *
 * @param attachment element//www .ja  va2s.co  m
 * @return Attachment
 */
public static Attachment getAttachment(Element attachment) {

    Namespace ns = attachment.getNamespace();

    Attachment att = new Attachment();
    att.setAlternateId(attachment.getChildText(ATTACHEMENT_ID_ELEMENT, ns));
    att.setLabel(attachment.getChildText(ATTACHEMENT_LABEL_ELEMENT, ns));
    att.setCapGroupName(attachment.getChildText(CAP_GROUP_NAME_ELEMENT, ns));
    att.setCapGroupSMILES(attachment.getChildText(CAP_GROUP_SMILES_ELEMENT, ns));

    return att;
}

From source file:org.helm.notation2.tools.MonomerParser.java

License:Open Source License

/**
 * Convert monomer element to Monomer object
 *
 * @param monomer element/*w  ww. j a  va2 s  .co m*/
 * @return Monomer
 */
public static Monomer getMonomer(Element monomer) throws MonomerException {
    Monomer m = new Monomer();
    Namespace ns = monomer.getNamespace();
    m.setAlternateId(monomer.getChildText(MONOMER_ID_ELEMENT, ns));
    m.setCanSMILES(monomer.getChildText(MONOMER_SMILES_ELEMENT, ns));
    String encodedMolfile = monomer.getChildText(MONOMER_MOL_FILE_ELEMENT, ns);

    String molfile = null;
    try {
        molfile = MolfileEncoder.decode(encodedMolfile);
    } catch (EncoderException ex) {
        throw new MonomerException("Invalid monomer molfile");
    }
    m.setMolfile(molfile);
    m.setMonomerType(monomer.getChildText(MONOMER_TYPE_ELEMENT, ns));
    m.setPolymerType(monomer.getChildText(POLYMER_TYPE_ELEMENT, ns));
    m.setNaturalAnalog(monomer.getChildText(NATURAL_ANALOG_ELEMENT, ns));
    m.setName(monomer.getChildText(MONOMER_NAME_ELEMENT, ns));
    Element attachmentElement = monomer.getChild(ATTACHEMENTS_ELEMENT, ns);

    if (null != attachmentElement) {
        List attachments = attachmentElement.getChildren(ATTACHEMENT_ELEMENT, ns);
        List<Attachment> l = new ArrayList<Attachment>();
        Iterator i = attachments.iterator();
        while (i.hasNext()) {
            Element attachment = (Element) i.next();
            Attachment att = getAttachment(attachment);
            l.add(att);
        }
        m.setAttachmentList(l);
    }
    return m;
}

From source file:org.helm.notation2.tools.NucleotideParser.java

License:Open Source License

public static Nucleotide getNucleotide(Element nucleotideElement) {
    Element symbolE = nucleotideElement.getChild(NUCLEOTIDE_SYMBOL_ELEMENT, nucleotideElement.getNamespace());
    Element notationE = nucleotideElement.getChild(NUCLEOTIDE_MONOMER_NOTATION_ELEMENT,
            nucleotideElement.getNamespace());
    return new Nucleotide(symbolE.getText(), notationE.getText());
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public boolean hasNamespaceURI(Element element, String namespaceURI) {
    //getLog().debug("Main namespace URI=" + element.getNamespace().getURI());
    if (element.getNamespace().getURI().equals(namespaceURI)) {
        return true;
    }/*  w w  w  .j av a  2  s. c o  m*/
    List<Namespace> additionalNamespaces = (List<Namespace>) element.getAdditionalNamespaces();
    for (Namespace additionalNamespace : additionalNamespaces) {
        //getLog().debug("Additional namespace URI=" + additionalNamespace.getURI());
        if (additionalNamespace.getURI().equals(namespaceURI)) {
            return true;
        }
    }
    return false;
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public void dumpElementNamespaces(Element element) {
    Namespace mainNamespace = element.getNamespace();
    getLogger().debug("Main namespace prefix=[" + mainNamespace.getPrefix() + "] uri=[" + mainNamespace.getURI()
            + "] getNamespaceURI=[" + element.getNamespaceURI() + "]");
    for (Namespace additionalNamespace : (List<Namespace>) element.getAdditionalNamespaces()) {
        getLogger().debug("Additional namespace prefix=" + additionalNamespace.getPrefix() + " uri="
                + additionalNamespace.getURI());
    }//  w w w .  j av a 2 s.c  o  m
}

From source file:org.jumpmind.metl.core.runtime.component.AbstractXMLComponentRuntime.java

License:Open Source License

protected Map<Element, Namespace> removeNamespaces(Document document) {
    Map<Element, Namespace> namespaces = new HashMap<Element, Namespace>();
    if (ignoreNamespace && document.hasRootElement()) {
        namespaces.put(document.getRootElement(), document.getRootElement().getNamespace());
        document.getRootElement().setNamespace(null);
        for (Element el : document.getRootElement().getDescendants(new ElementFilter())) {
            Namespace nsp = el.getNamespace();
            if (nsp != null) {
                el.setNamespace(null);/*from  w w w  .  j a  va  2s  .c  o m*/
                namespaces.put(el, nsp);
            }
        }
    }
    return namespaces;
}

From source file:org.kisst.cordys.caas.util.XmlNode.java

License:Open Source License

public Object getWithCreate(String path) {
    String[] parts = path.split("/");
    Element e = element;
    for (String part : parts) {
        if (part.equals(".."))
            e = e.getParentElement();//w w w .  j av a2 s  .  co m
        else if (part.equals("text()"))
            return e.getText();
        else if (part.startsWith("@"))
            return e.getAttribute(part.substring(1)).getValue();
        else {
            Element child = e.getChild(part, null);
            if (child == null) {
                child = new Element(part, e.getNamespace());
                e.addContent(child);
            }
            e = child;
        }
    }
    return new XmlNode(e);
}

From source file:org.mycore.common.xml.MCRXPathBuilder.java

License:Open Source License

/**
 * Returns the namespace prefix for this element, followed by a ":", or the empty string if no namespace prefix known.
 */// ww w .j a  v a2 s . c  o m
public static String getNamespacePrefix(Element element) {
    Namespace nsElement = element.getNamespace();
    for (Namespace ns : MCRConstants.getStandardNamespaces())
        if (ns.equals(nsElement))
            return ns.getPrefix() + ":";

    String prefix = nsElement.getPrefix();
    if ((prefix != null) && !prefix.isEmpty())
        return prefix + ":";
    else
        return "";
}

From source file:org.mycore.common.xml.MCRXPathBuilder.java

License:Open Source License

private static String buildPositionPredicate(Element element) {
    Parent parent = element.getParent();
    if ((parent instanceof Document) || (parent == null))
        return "";

    Element parentElement = (Element) parent;
    int pos = parentElement.getChildren(element.getName(), element.getNamespace()).indexOf(element);
    return (pos == 0 ? "" : "[" + ++pos + "]");
}

From source file:org.mycore.frontend.editor.MCREditorSubmission.java

License:Open Source License

private void setVariablesFromXML(String prefix, Element element, Hashtable predecessors) {
    String key = getNamespacePrefix(element.getNamespace()) + element.getName();

    setVariablesFromXML(prefix, key, element, predecessors);

    List attributes = element.getAttributes();
    for (Object attribute1 : attributes) {
        Attribute attribute = (Attribute) attribute1;
        String name = getNamespacePrefix(attribute.getNamespace()) + attribute.getName();
        String value = attribute.getValue().replace(BLANK, BLANK_ESCAPED).replace(SLASH, SLASH_ESCAPED);
        if (value == null || value.length() == 0) {
            continue;
        }//from www  .j  a  va  2 s.  c om
        key = getNamespacePrefix(element.getNamespace()) + element.getName() + ATTR_SEP + name + ATTR_SEP
                + value;
        if (predicates.containsKey(key)) {
            setVariablesFromXML(prefix, key, element, predecessors);
        }
    }
}