Example usage for org.jdom2 Attribute getParent

List of usage examples for org.jdom2 Attribute getParent

Introduction

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

Prototype

public Element getParent() 

Source Link

Document

This will return the parent of this Attribute.

Usage

From source file:com.googlesource.gerrit.plugins.manifest.CustomOutputter.java

License:Apache License

@Override
protected void printAttribute(java.io.Writer out, FormatStack fstack, Attribute attribute)
        throws java.io.IOException {
    // Do not print attributes that use default values
    for (DTDAttribute dtdAttribute : dtdAttributes) {
        if (attribute.getName().equals(dtdAttribute.getAttributeName())
                && attribute.getParent().getName().equals(dtdAttribute.getElementName())
                && attribute.getAttributeType().toString().equals(dtdAttribute.getType())
                && attribute.getValue().equals(dtdAttribute.getValue())) {
            return;
        }/*www .j  av a 2  s  .c  o  m*/
    }

    out.append(fstack.getLineSeparator());
    String indent = fstack.getIndent();
    out.append(fstack.getLevelIndent());
    out.append(indent);
    // super.printAttribute() indents with an extra space, this will offset that
    out.append(indent.substring(0, indent.length() - 1));
    super.printAttribute(out, fstack, attribute);
}

From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.TypesExtractorImpl.java

License:Apache License

/**
 * Returns a path of the attribute made of the name of the elements and their prefixes. 
 * Prefixes are separated from element names by :, so THEY MUST BE REPLACED BY _ if they are going to be used to build type names.
 * Note that the : WILL always appear, although there is not any namespace prefix.
 * @param attribute the attribute//  w  w  w .j  a  v  a  2 s .  c  o  m
 * @param config current inference configuration
 * @param solvedNamespaceToPrefixMapping the solved mappings between the namespace URIs and prefix
 * @return a list that represents the path
 * @throws NullPointerException if any argument is null
 */
public static List<String> getRealPathOfAttributeUnfiltered(Attribute attribute,
        XSDInferenceConfiguration config, Map<String, String> solvedNamespaceToPrefixMapping) {
    checkNotNull(attribute, "'attribute' must not be null");
    checkNotNull(config, "'config' must not be null");
    List<String> path = getRealPathOfElementUnfiltered(attribute.getParent(), config, false,
            solvedNamespaceToPrefixMapping);
    path.add("@" + attribute.getNamespacePrefix() + ":" + attribute.getName());
    return path;
}

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

License:Open Source License

private Map<String, DocElement> fillAttributeDetails(Document templateDoc) {

    Map<String, DocElement> attributeLevels = new HashMap<String, DocElement>();
    Map<Element, Namespace> namespaces = removeNamespaces(templateDoc);
    for (ComponentAttributeSetting compAttributeSetting : getComponent().getAttributeSettings()) {
        if (compAttributeSetting.getName().equals(XML_FORMATTER_XPATH)) {
            XPathExpression<Object> expression = XPathFactory.instance()
                    .compile(compAttributeSetting.getValue());
            List<Object> matches = expression.evaluate(templateDoc.getRootElement());
            if (matches.size() == 0) {
                log(LogLevel.WARN,//from   ww w . ja  va  2 s . c  o m
                        "XPath expression " + compAttributeSetting.getValue() + " did not find any matches");
            } else {
                if (matches.get(0) instanceof Element) {
                    Element element = (Element) matches.get(0);
                    // a model attribute could never be the root element of
                    // the doc
                    int level = 1;
                    Element elementToMatch = element.getParentElement();
                    while (!elementToMatch.getName().equalsIgnoreCase(templateDoc.getRootElement().getName())) {
                        elementToMatch = elementToMatch.getParentElement();
                        level++;
                    }
                    attributeLevels.put(compAttributeSetting.getAttributeId(),
                            new DocElement(level, element, null, compAttributeSetting.getValue()));
                }
                if (matches.get(0) instanceof Attribute) {
                    Attribute attribute = (Attribute) matches.get(0);
                    int level = 1;
                    Element elementToMatch = attribute.getParent();
                    while (!elementToMatch.getName().equalsIgnoreCase(templateDoc.getRootElement().getName())) {
                        elementToMatch = elementToMatch.getParentElement();
                        level++;
                    }
                    attributeLevels.put(compAttributeSetting.getAttributeId(),
                            new DocElement(level, null, attribute, compAttributeSetting.getValue()));
                }
            }
        }
    }
    restoreNamespaces(templateDoc, namespaces);
    return attributeLevels;
}

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

License:Open Source License

/**
 * Builds an absolute XPath expression for the given attribute within a JDOM XML structure.
 * In case any ancestor element in context is not the first one, the XPath will also contain position predicates.
 * For all namespaces commonly used in MyCoRe, their namespace prefixes will be used.
 *
 * @param attribute a JDOM attribute//from   ww w.j  a  v  a  2  s.  c o  m
 * @return absolute XPath of that attribute. In case there is a root Document, it will begin with a "/".
 */
public static String buildXPath(Attribute attribute) {
    String parentXPath = buildXPath(attribute.getParent());
    if (!parentXPath.isEmpty())
        parentXPath += "/";
    return parentXPath + "@" + attribute.getQualifiedName();
}