Example usage for org.jdom2 Attribute getName

List of usage examples for org.jdom2 Attribute getName

Introduction

In this page you can find the example usage for org.jdom2 Attribute getName.

Prototype

public String getName() 

Source Link

Document

This will retrieve the local name of the Attribute.

Usage

From source file:org.jumpmind.metl.ui.views.design.EditXmlFormatPanel.java

License:Open Source License

protected void buildXpathChoicesFromElement(String prefix, Element parentElement) {
    for (Element element : parentElement.getChildren()) {
        String text = prefix + "/" + element.getName();
        xpathChoices.add(text);/*from w  ww .jav a  2s  . com*/
        for (Attribute attr : element.getAttributes()) {
            String attrText = text + "/@" + attr.getName();
            xpathChoices.add(attrText);
        }
        buildXpathChoicesFromElement(text, element);
    }
}

From source file:org.jumpmind.metl.ui.views.design.EditXmlParserPanel.java

License:Open Source License

protected void buildXpathChoicesForElement(String prefix, Element element) {
    String base = "/" + element.getName();
    String newPrefix = prefix + base;
    xpathChoices.add(newPrefix);// www .  j av  a 2s .  c o m
    for (Attribute attr : element.getAttributes()) {
        xpathChoices.add(newPrefix + "/@" + attr.getName());
    }
    xpathChoices.add(base);
    for (Attribute attr : element.getAttributes()) {
        xpathChoices.add(base + "/@" + attr.getName());
    }
    buildXpathChoicesForChildElements(newPrefix, element);
}

From source file:org.kdp.word.transformer.AttributeTransformer.java

License:Apache License

private void transformInternal(Parser parser, Element el, Set<Replace> replace) {
    String elname = el.getName();
    for (Attribute att : new ArrayList<Attribute>(el.getAttributes())) {
        String attname = att.getName();
        String attvalue = att.getValue();
        String attid = elname + "." + attname;
        for (Replace rep : replace) {
            if (attid.equals(rep.attid)) {
                if (rep.substr == null || attvalue.contains(rep.substr)) {
                    if (rep.newval == null || rep.newval.length() == 0) {
                        log.debug("Remote attribute: {}", att);
                        el.getAttributes().remove(att);
                    } else {
                        log.debug("Replace attribute: {}", att);
                        att.setValue(rep.newval);
                    }/*from  w w w.  ja v  a2s. c  o  m*/
                    break;
                }
            }
        }
    }
    for (Element ch : el.getChildren()) {
        transformInternal(parser, ch, replace);
    }
}

From source file:org.kdp.word.transformer.StyleTransformer.java

License:Apache License

private void classStyleReplace(Context context, Element element, Attribute attClass) {
    String value = null;/*w  w w  .ja va 2 s.  c o m*/
    String attname = attClass.getName();
    String attvalue = attClass.getValue();
    for (Replacement rep : replacements) {
        if (attname.equals(rep.attname)) {
            if (isWhitelisted(attvalue)) {
                value = attvalue;
            } else if (rep.pattern.matcher(attvalue).matches()) {
                value = rep.value;
                break;
            }
        }
    }
    if (value != null) {
        attClass.setValue(value);
    } else {
        element.removeAttribute(attClass);
    }
}

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

License:Open Source License

public Map<String, String> getAttributes() {
    Map<String, String> retVal = new LinkedHashMap<String, String>();

    List<Attribute> tmp = element.getAttributes();
    for (Attribute a : tmp) {
        retVal.put(a.getName(), a.getValue());
    }// w w w .ja v a 2 s  . com

    return retVal;
}

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

License:Open Source License

private Attribute buildAttribute(Namespace ns, String name, String value, Element parent) {
    Attribute attribute = new Attribute(name, value == null ? "" : value, ns);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("building new attribute " + attribute.getName());
    if (parent != null)
        parent.setAttribute(attribute);//  w  w  w  .  j  av a 2s . c  o m
    return attribute;
}

From source file:org.mycore.datamodel.metadata.MCRObjectMetadata.java

License:Open Source License

/**
 * This method adds MCRMetaElement's from a given MCRObjectMetadata to
 * this data set if there are any differences between the data sets.
 * /*w  ww .j  a  v  a  2  s. c o  m*/
 * @param input
 *            the MCRObjectMetadata, that should merged into this data set
 *            
 * @deprecated use {@link MCRObjectMerger#mergeMetadata(MCRObject, boolean)} instead
 */
public final void mergeMetadata(MCRObjectMetadata input) {

    for (MCRMetaElement metaElement : input) {
        int pos = -1;
        for (int j = 0; j < size(); j++) {
            if (meta_list.get(j).getTag().equals(metaElement.getTag())) {
                pos = j;
            }
        }
        if (pos != -1) {
            for (int j = 0; j < metaElement.size(); j++) {
                boolean found = false;
                for (MCRMetaInterface mcrMetaInterface : meta_list.get(pos)) {
                    Element xml = mcrMetaInterface.createXML();
                    Element xmlNEW = metaElement.getElement(j).createXML();
                    List<Element> childrenXML = xml.getChildren();
                    if (childrenXML.size() > 0 && xmlNEW.getChildren().size() > 0) {
                        int i = 0;
                        for (Element element : childrenXML) {
                            Element elementNew = xmlNEW.getChild(element.getName());

                            if (elementNew != null && element != null) {
                                if (element.getText().equals(elementNew.getText())) {
                                    i++;
                                }
                            }
                        }
                        if (i == childrenXML.size()) {
                            found = true;
                        }
                    } else {
                        if (xml.getText().equals(xmlNEW.getText())) {
                            found = true;
                        } else if (!found) {
                            int i = 0;
                            List<Attribute> attributes = xml.getAttributes();
                            for (Attribute attribute : attributes) {
                                Attribute attr = xmlNEW.getAttribute(attribute.getName());
                                if ((attr != null) && attr.equals(attribute)) {
                                    i++;
                                }
                            }
                            if (i == attributes.size()) {
                                found = true;
                            }

                        }
                    }
                }
                MCRMetaInterface obj = metaElement.getElement(j);
                if (!found) {
                    meta_list.get(pos).addMetaObject(obj);
                } else if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Found equal tags: \n\r"
                            + new XMLOutputter(Format.getPrettyFormat()).outputString(obj.createXML()));
                }
            }
        } else {
            meta_list.add(metaElement);
        }
    }
}

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  w  w  w  . j a  v a2  s . c o m*/
        key = getNamespacePrefix(element.getNamespace()) + element.getName() + ATTR_SEP + name + ATTR_SEP
                + value;
        if (predicates.containsKey(key)) {
            setVariablesFromXML(prefix, key, element, predecessors);
        }
    }
}

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

License:Open Source License

private void setVariablesFromXML(String prefix, String key, Element element, Hashtable predecessors) {
    int pos = 1;// ww  w  .ja v a  2 s  .  c  om
    if (predecessors.containsKey(key)) {
        pos = (Integer) predecessors.get(key) + 1;
    }
    predecessors.put(key, pos);

    String path = prefix + "/" + key;
    if (pos > 1) {
        path = path + "[" + pos + "]";
    }

    // Add element text
    addVariable(path, element.getText());

    // Add value of all attributes
    List attributes = element.getAttributes();
    for (Object attribute1 : attributes) {
        Attribute attribute = (Attribute) attribute1;
        String value = attribute.getValue();
        if (value != null && value.length() > 0) {
            addVariable(path + "/@" + getNamespacePrefix(attribute.getNamespace()) + attribute.getName(),
                    value);
        }
    }

    // Add values of all children
    predecessors = new Hashtable();
    List children = element.getChildren();
    for (Object aChildren : children) {
        Element child = (Element) aChildren;
        setVariablesFromXML(path, child, predecessors);
    }
}

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

License:Open Source License

private void setValidatorProperties(MCRValidator validator, Element condition) {
    for (Attribute attribute : (List<Attribute>) (condition.getAttributes())) {
        if (!attribute.getValue().isEmpty())
            validator.setProperty(attribute.getName(), attribute.getValue());
    }/*from   www  . j av  a2  s . c  o m*/
}