Example usage for org.w3c.dom Element getTagName

List of usage examples for org.w3c.dom Element getTagName

Introduction

In this page you can find the example usage for org.w3c.dom Element getTagName.

Prototype

public String getTagName();

Source Link

Document

The name of the element.

Usage

From source file:org.kuali.test.utils.Utils.java

/**
 *
 * @param node//  w w  w. j ava2s  .  co  m
 * @param childTagMatch
 * @return
 */
public static boolean isChildTagMatchFailure(Element node, ChildTagMatch childTagMatch) {
    boolean retval = false;

    if ((childTagMatch != null) && (node != null)) {
        if (node.hasChildNodes()) {
            boolean foundone = false;
            Set<String> childTagNames = new HashSet<String>();

            StringTokenizer st = new StringTokenizer(childTagMatch.getChildTagName(), "|");

            while (st.hasMoreTokens()) {
                childTagNames.add(st.nextToken());
            }

            for (Element child : getChildElements(node)) {
                if (childTagNames.contains(child.getTagName())) {
                    foundone = true;
                    if (childTagMatch.getMatchAttributes() != null) {
                        if (childTagMatch.getMatchAttributes().sizeOfMatchAttributeArray() > 0) {
                            for (TagMatchAttribute att : childTagMatch.getMatchAttributes()
                                    .getMatchAttributeArray()) {
                                if ((att != null) && StringUtils.isNotBlank(att.getName())) {
                                    String childAttr = child.getAttribute(att.getName());
                                    if (StringUtils.isBlank(childAttr)) {
                                        retval = true;
                                    } else {
                                        int pos = att.getValue().indexOf('*');

                                        if (pos > -1) {
                                            if (pos == 0) {
                                                retval = !childAttr.endsWith(att.getValue().substring(1));
                                            } else {
                                                String s1 = att.getValue().substring(0, pos);
                                                String s2 = att.getValue().substring(pos + 1);

                                                retval = (!childAttr.startsWith(s1) || !childAttr.endsWith(s2));
                                            }
                                        } else {
                                            retval = !childAttr.equalsIgnoreCase(att.getValue());
                                        }
                                    }
                                    break;
                                } else {
                                    retval = true;
                                    break;
                                }
                            }
                            // if retval is false then we found a match so break
                            if (!retval) {
                                break;
                            }
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }

                if ((retval || !foundone) && childTagMatch.getDeep()) {
                    retval = isChildTagMatchFailure(child, childTagMatch);
                    if (!retval) {
                        foundone = true;
                        break;
                    }
                }
            }

            if (!foundone) {
                retval = true;
            }
        } else {
            retval = true;
        }
    }

    return retval;
}

From source file:org.kuali.test.utils.Utils.java

/**
 *
 * @param node//w ww .  ja  va2s . c o  m
 * @return
 */
public static Element getParentNodeByTagName(Element node, String parentTagName) {
    Element retval = null;

    Element curnode = (Element) node.getParentNode();

    while (curnode != null) {
        if (parentTagName.equalsIgnoreCase(curnode.getTagName())) {
            retval = curnode;
            break;
        }

        if (curnode.getParentNode() instanceof Element) {
            curnode = (Element) curnode.getParentNode();
        } else {
            break;
        }
    }

    return retval;
}

From source file:org.kuali.test.utils.Utils.java

public static boolean isAutoReplaceParameterMatch(AutoReplaceParameter param, Node node) {
    boolean retval = false;

    if ((node != null) && (node.getNodeType() == Node.ELEMENT_NODE)) {
        Element e = (Element) node;
        if (param.getTagName().equals(e.getTagName())) {
            if (param.getParameterName().equals(e.getAttribute(Constants.HTML_TAG_ATTRIBUTE_NAME))) {
                retval = true;/*from w w w  .j a v  a 2  s  .com*/
                if ((param.getTagAttributes() != null)
                        && (param.getTagAttributes().sizeOfAttributeArray() > 0)) {
                    for (TagAttribute att : param.getTagAttributes().getAttributeArray()) {
                        if (!att.getValue().equals(e.getAttribute(att.getName()))) {
                            retval = false;
                            break;
                        }
                    }
                }
            }
        }
    }

    return retval;
}

From source file:org.kuali.test.utils.Utils.java

public static Element getFirstChildNodeByNodeNameAndAttribute(Element parent, String nodeName,
        String attributeName, String attributeValue) {
    Element retval = null;// w  w  w. j a  v a  2  s.c o  m
    Element firstChildElement = null;
    if (parent.hasChildNodes()) {
        NodeList nl = parent.getChildNodes();

        for (int i = 0; i < nl.getLength(); ++i) {
            if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element curElement = (Element) nl.item(i);

                // if the first child element is a span, div or nobr then we will save it
                // if we do not find the desired child we will look in the first child span
                if ((firstChildElement == null)
                        && (Constants.HTML_TAG_TYPE_SPAN.equalsIgnoreCase(curElement.getTagName())
                                || Constants.HTML_TAG_TYPE_DIV.equalsIgnoreCase(curElement.getTagName())
                                || Constants.HTML_TAG_TYPE_NOBR.equalsIgnoreCase(curElement.getTagName()))) {
                    firstChildElement = curElement;
                }

                if (curElement.getNodeName().equalsIgnoreCase(nodeName)) {
                    if (StringUtils.isBlank(attributeName) && StringUtils.isBlank(attributeValue)) {
                        retval = curElement;
                        break;
                    } else if (attributeValue.equalsIgnoreCase(curElement.getAttribute(attributeName))) {
                        retval = curElement;
                        break;
                    }
                }
            }
        }
    }

    if ((retval == null) && (firstChildElement != null)) {
        retval = getFirstChildNodeByNodeNameAndAttribute(firstChildElement, nodeName, attributeName,
                attributeValue);
    }

    return retval;
}

From source file:org.lilyproject.indexer.model.indexerconf.LilyIndexerConfBuilder.java

public void addChildNodes(Element el, ContainerMappingNode parent, String... allowedTagNames) throws Exception {
    Set<String> allowed = Sets.newHashSet(allowedTagNames);

    for (Element childEl : DocumentHelper.getElementChildren(el)) {
        String name = childEl.getTagName();

        if (!allowed.contains(name)) {
            throw new IndexerConfException(
                    String.format("Unexpected tag name '%s' while parsing indexerconf", childEl.getTagName()));
        }//from  w  w w .j  ava  2s  . c  o  m

        if (name.equals("fields")) {
            parent.addChildNode(buildIndexFields(childEl));
        } else if (name.equals("match")) {
            parent.addChildNode(buildMatchNode(childEl));
        } else if (name.equals("field")) {
            final IndexField indexField;
            if (parent instanceof ForEachNode
                    && ((ForEachNode) parent).getFollow() instanceof ForwardVariantFollow) {
                indexField = buildIndexField(childEl,
                        ((ForwardVariantFollow) ((ForEachNode) parent).getFollow()).getDimensions().keySet());
            } else {
                indexField = buildIndexField(childEl, null);
            }
            parent.addChildNode(indexField);
        } else if (name.equals("forEach")) {
            parent.addChildNode(buildForEachNode(childEl));
        } else {
            throw new IndexerConfException(
                    String.format("Unexpected tag name '%s' while parsing indexerconf", childEl.getTagName()));
        }
    }
}

From source file:org.mindswap.pellet.dig.DIGHandler.java

public static String getTagName(Element node) {
    return node.getTagName();
}

From source file:org.mule.security.oauth.config.AbstractDevkitBasedDefinitionParser.java

protected ManagedMap parseMap(Element element, String childElementName,
        AbstractDevkitBasedDefinitionParser.ParseDelegate parserDelegate) {
    ManagedMap managedMap = new ManagedMap();
    List<Element> childDomElements = DomUtils.getChildElementsByTagName(element, childElementName);
    if (childDomElements.size() == 0) {
        childDomElements = DomUtils.getChildElements(element);
    }//from ww w . j ava 2  s .c  o m
    for (Element childDomElement : childDomElements) {
        Object key = null;
        if (hasAttribute(childDomElement, "key-ref")) {
            key = new RuntimeBeanReference(childDomElement.getAttribute("key-ref"));
        } else {
            if (hasAttribute(childDomElement, "key")) {
                key = childDomElement.getAttribute("key");
            } else {
                key = childDomElement.getTagName();
            }
        }
        if (hasAttribute(childDomElement, "value-ref")) {
            if (!isMuleExpression(childDomElement.getAttribute("value-ref"))) {
                managedMap.put(key, new RuntimeBeanReference(childDomElement.getAttribute("value-ref")));
            } else {
                managedMap.put(key, childDomElement.getAttribute("value-ref"));
            }
        } else {
            managedMap.put(key, parserDelegate.parse(childDomElement));
        }
    }
    return managedMap;
}

From source file:org.obm.caldav.server.resultBuilder.PropertyListBuilder.java

public Document build(CalDavToken t, DavRequest req, List<DavComponent> comps,
        Set<PropfindPropertyHandler> toLoad, Set<Element> notUsed, IBackend proxy) {
    try {//from  w  w w  . j  av  a2 s .c  om

        Document ret = createMultiStatusDocument();
        Element r = ret.getDocumentElement();
        for (DavComponent comp : comps) {
            Element response = DOMUtils.createElement(r, "D:response");
            DOMUtils.createElementAndText(response, "D:href", comp.getURL());

            if (toLoad.size() > 0) {
                Element pStat = DOMUtils.createElement(response, "D:propstat");
                Element p = DOMUtils.createElement(pStat, "D:prop");
                for (PropfindPropertyHandler dph : toLoad) {
                    dph.appendPropertyValue(p, t, req, proxy, comp);
                }
                DOMUtils.createElementAndText(pStat, "D:status", "HTTP/1.1 200 OK");
            }

            if (notUsed.size() > 0) {
                Element pStatNotUsed = DOMUtils.createElement(response, "D:propstat");
                Element pNotUsed = DOMUtils.createElement(pStatNotUsed, "D:prop");
                for (Element enu : notUsed) {
                    DOMUtils.createElement(pNotUsed, enu.getNamespaceURI(), enu.getTagName());
                }
                DOMUtils.createElementAndText(pStatNotUsed, "D:status", "HTTP/1.1 404 Not Found");
            }
        }

        return ret;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }

}

From source file:org.odk.aggregate.parser.SubmissionParser.java

/**
 * Recursive function that prints the nodes from an XML tree
 * //w  w  w. j  a  v a  2s .  co m
 * @param node xml node to be recursively printed
 */
private void printNode(Element node) {
    System.out.println(ParserConsts.NODE_FORMATTED + node.getTagName());
    if (node.hasAttributes()) {
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attr = attributes.item(i);
            System.out.println(ParserConsts.ATTRIBUTE_FORMATTED + attr.getNodeName() + BasicConsts.EQUALS
                    + attr.getNodeValue());
        }
    }
    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                printNode((Element) child);
            } else if (child.getNodeType() == Node.TEXT_NODE) {
                String value = child.getNodeValue().trim();
                if (value.length() > 0) {
                    System.out.println(ParserConsts.VALUE_FORMATTED + value);
                }
            }
        }
    }

}

From source file:org.onehippo.cms7.autoexport.InitializeItem.java

private DeltaInstruction parseInstructionElement(Element element, DeltaInstruction parent) {

    boolean isNode = element.getTagName().equals(QNODE);
    String name = element.getAttribute(QNAME);
    String directive = element.getAttributeNS(DELTA_URI, MERGE);

    DeltaInstruction instruction;//from w  w w. ja v  a2  s.co  m
    if (parent == null) {
        instruction = new DeltaInstruction(isNode, name, directive, contextPath);
    } else {
        instruction = new DeltaInstruction(isNode, name, directive, parent);
    }
    if (instruction.isCombineDirective()) {
        final NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            final Node item = childNodes.item(i);
            if (item instanceof Element) {
                DeltaInstruction child = parseInstructionElement((Element) item, instruction);
                if (child == null) {
                    return null;
                }
                instruction.addInstruction(child);
            }
        }
    }
    if (instruction.isUnsupportedDirective()) {
        return null;
    }
    return instruction;
}