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:nl.nn.adapterframework.jdbc.XmlQuerySender.java

protected String sendMessage(Connection connection, String correlationID, String message,
        ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement;
    String tableName = null;/*from   ww w  . ja v  a  2s. c o m*/
    Vector columns = null;
    String where = null;
    String order = null;
    String result = null;
    try {
        queryElement = XmlUtils.buildElement(message);
        String root = queryElement.getTagName();
        tableName = XmlUtils.getChildTagAsString(queryElement, "tableName");
        Element columnsElement = XmlUtils.getFirstChildTag(queryElement, "columns");
        if (columnsElement != null) {
            columns = getColumns(columnsElement);
        }
        where = XmlUtils.getChildTagAsString(queryElement, "where");
        order = XmlUtils.getChildTagAsString(queryElement, "order");

        if (root.equalsIgnoreCase("select")) {
            result = selectQuery(connection, correlationID, tableName, columns, where, order);
        } else {
            if (root.equalsIgnoreCase("insert")) {
                result = insertQuery(connection, correlationID, prc, tableName, columns);
            } else {
                if (root.equalsIgnoreCase("delete")) {
                    result = deleteQuery(connection, correlationID, tableName, where);
                } else {
                    if (root.equalsIgnoreCase("update")) {
                        result = updateQuery(connection, correlationID, tableName, columns, where);
                    } else {
                        if (root.equalsIgnoreCase("alter")) {
                            String sequenceName = XmlUtils.getChildTagAsString(queryElement, "sequenceName");
                            int startWith = Integer
                                    .parseInt(XmlUtils.getChildTagAsString(queryElement, "startWith"));
                            result = alterQuery(connection, sequenceName, startWith);
                        } else {
                            if (root.equalsIgnoreCase("sql")) {
                                String type = XmlUtils.getChildTagAsString(queryElement, "type");
                                String query = XmlUtils.getChildTagAsString(queryElement, "query");
                                result = sql(connection, correlationID, query, type);
                            } else {
                                throw new SenderException(
                                        getLogPrefix() + "unknown root element [" + root + "]");
                            }
                        }
                    }
                }
            }
        }
    } catch (DomBuilderException e) {
        throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
    } catch (JdbcException e) {
        throw new SenderException(getLogPrefix() + "got exception preparing [" + message + "]", e);
    }

    return result;
}

From source file:nl.strohalm.cyclos.utils.conversion.HtmlConverter.java

private static void removeBadNodes(final Document document) {
    final NodeList elements = document.getElementsByTagName("*");
    for (int i = 0; i < elements.getLength(); i++) {
        final Element element = (Element) elements.item(i);
        if (ArrayUtils.contains(BAD_TAGS, element.getTagName())) {
            element.getParentNode().removeChild(element);
        }//from www  . jav  a 2 s .co m
        final NamedNodeMap attributes = element.getAttributes();
        for (int j = 0; j < attributes.getLength(); j++) {
            final Attr attr = (Attr) attributes.item(j);
            if (attr.getNodeName().startsWith("on")) {
                // This is an event handler: remove it
                element.removeAttributeNode(attr);
            }
        }
    }
}

From source file:no.kantega.publishing.admin.content.util.EditContentHelper.java

/**
 * Create attributes recursively/*w  w  w  .j  av a 2s.  co m*/
 * @param attributeDataType - type of attributes to create, content or metadata
 * @param defaultValues - used to initialize attributes with default values
 * @param newParentAttribute - parent of attributes
 * @param newAttributes - list with new attributes
 * @param oldAttributes - list with old attributes
 * @param xmlAttributes - XML element with definition
 * @throws SystemException -
 * @throws InvalidTemplateException -
 */
private static void addAttributes(ContentTemplate template, AttributeDataType attributeDataType,
        Map<String, String> defaultValues, RepeaterAttribute newParentAttribute, List<Attribute> newAttributes,
        List<? extends Attribute> oldAttributes, List<Element> xmlAttributes)
        throws SystemException, InvalidTemplateException {
    for (Element xmlAttribute : xmlAttributes) {

        String name = xmlAttribute.getAttribute("name");
        String type;
        if (xmlAttribute.getTagName().equalsIgnoreCase("repeater")) {
            type = "repeater";
        } else if (xmlAttribute.getTagName().equalsIgnoreCase("separator")) {
            type = "separator";
        } else {
            type = xmlAttribute.getAttribute("type");
        }

        Attribute attribute = createAttribute(template, attributeDataType, defaultValues, newParentAttribute,
                xmlAttribute, name, type);

        addRepeaterAttribute(template, attributeDataType, defaultValues, oldAttributes, xmlAttribute,
                attribute);

        newAttributes.add(attribute);

        // Copy value from old attribute
        if (oldAttributes != null) {
            Attribute oldAttribute = getAttributeByName(oldAttributes, attribute.getName());
            if (oldAttribute != null) {
                attribute.cloneValue(oldAttribute);
            }
        }
    }
}

From source file:no.sesat.search.query.analyser.AnalysisRuleFactory.java

private Map<String, Predicate> readPredicates(final Element element, final Map<String, Predicate> predicateMap,
        final Map<String, Predicate> inheritedPredicates) {

    final NodeList predicates = element.getChildNodes();

    for (int i = 0; i < predicates.getLength(); ++i) {
        final Node node = predicates.item(i);
        if (node instanceof Element) {
            final Element e = (Element) node;
            if ("predicate".equals(e.getTagName())) {
                readPredicate(e, predicateMap, inheritedPredicates);
            }//from www .j  a  va 2 s. com
        }
    }
    return predicateMap;
}

From source file:no.sesat.search.query.analyser.AnalysisRuleFactory.java

private Predicate createPredicate(final Element element, final Map predicateMap,
        final Map inheritedPredicates) {

    Predicate result = null;//from  w  w w  .ja  va2s . c  o  m
    // The operator to use from PredicateUtils.
    //   The replaceAll's are so we end up with a method with one Predicate[] argument.
    final String methodName = element.getTagName().replaceAll("and", "all").replaceAll("or", "any")
            .replaceAll("either", "one").replaceAll("neither", "none") + "Predicate";
    // because we can't use the above operator methods with only one child predicate
    //  the not operator must be a special case.
    final boolean notPredicate = "not".equals(element.getTagName());

    try {
        // Find PredicateUtils static method through reflection
        final Method method = notPredicate ? null
                : PredicateUtils.class.getMethod(methodName, new Class[] { Collection.class });

        // load all the predicates it will apply to
        final List childPredicates = new LinkedList();
        final NodeList predicates = element.getChildNodes();
        for (int i = 0; i < predicates.getLength(); ++i) {
            final Node node = predicates.item(i);
            if (node instanceof Element) {
                final Element e = (Element) node;
                if ("predicate".equals(e.getTagName())) {
                    childPredicates.add(readPredicate(e, predicateMap, inheritedPredicates));
                }
            }
        }
        if (notPredicate) {
            // there should only be one in the list
            if (childPredicates.size() > 1) {
                throw new IllegalStateException(ERR_TOO_MANY_PREDICATES_IN_NOT + element.getParentNode());
            }
            result = PredicateUtils.notPredicate((Predicate) childPredicates.get(0));
        } else {
            // use the operator through reflection
            result = (Predicate) method.invoke(null, new Object[] { childPredicates });
        }

    } catch (SecurityException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_FIND_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (NoSuchMethodException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_FIND_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (IllegalAccessException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (InvocationTargetException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    } catch (IllegalArgumentException ex) {
        LOG.error(ERR_WHILE_READING_ELEMENT + element);
        LOG.error(ERR_UNABLE_TO_USE_PREDICATE_UTILS_METHOD + methodName, ex);
    }

    return result;
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

@SuppressWarnings("unchecked")
public static void rebuildInstance(final Node prototypeNode, final Node oldInstanceNode,
        final Node newInstanceNode,

        final HashMap<String, String> schemaNamespaces) {
    final JXPathContext prototypeContext = JXPathContext.newContext(prototypeNode);
    prototypeContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI);
    final JXPathContext instanceContext = JXPathContext.newContext(oldInstanceNode);
    instanceContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI);

    for (final String prefix : schemaNamespaces.keySet()) {
        prototypeContext.registerNamespace(prefix, schemaNamespaces.get(prefix));
        instanceContext.registerNamespace(prefix, schemaNamespaces.get(prefix));
    }//from   w w  w .  j a  v  a  2 s  .  c om

    // Evaluate non-recursive XPaths for all prototype elements at this level
    final Iterator<Pointer> it = prototypeContext.iteratePointers("*");
    while (it.hasNext()) {
        final Pointer p = it.next();
        Element proto = (Element) p.getNode();
        String path = p.asPath();
        // check if this is a prototype element with the attribute set
        boolean isPrototype = proto.hasAttributeNS(NamespaceService.ALFRESCO_URI, "prototype")
                && proto.getAttributeNS(NamespaceService.ALFRESCO_URI, "prototype").equals("true");

        // We shouldn't locate a repeatable child with a fixed path
        if (isPrototype) {
            path = path.replaceAll("\\[(\\d+)\\]", "[position() >= $1]");
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] evaluating prototyped nodes " + path);
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] evaluating child node with positional path " + path);
            }
        }

        Document newInstanceDocument = newInstanceNode.getOwnerDocument();

        // Locate the corresponding nodes in the instance document
        List<Node> l = (List<Node>) instanceContext.selectNodes(path);

        // If the prototype node isn't a prototype element, copy it in as a missing node, complete with all its children. We won't need to recurse on this node
        if (l.isEmpty()) {
            if (!isPrototype) {
                LOGGER.debug("[rebuildInstance] copying in missing node " + proto.getNodeName() + " to "
                        + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement()));

                // Clone the prototype node and all its children
                Element clone = (Element) proto.cloneNode(true);
                newInstanceNode.appendChild(clone);

                if (oldInstanceNode instanceof Document) {
                    // add XMLSchema instance NS
                    addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_NS);
                }
            }
        } else {
            // Otherwise, append the matches from the old instance document in order
            for (Node old : l) {
                Element oldEl = (Element) old;

                // Copy the old instance element rather than cloning it, so we don't copy over attributes
                Element clone = null;
                String nSUri = oldEl.getNamespaceURI();
                if (nSUri == null) {
                    clone = newInstanceDocument.createElement(oldEl.getTagName());
                } else {
                    clone = newInstanceDocument.createElementNS(nSUri, oldEl.getTagName());
                }
                newInstanceNode.appendChild(clone);

                if (oldInstanceNode instanceof Document) {
                    // add XMLSchema instance NS
                    addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_NS);
                }

                // Copy over child text if this is not a complex type
                boolean isEmpty = true;
                for (Node n = old.getFirstChild(); n != null; n = n.getNextSibling()) {
                    if (n instanceof Text) {
                        clone.appendChild(newInstanceDocument.importNode(n, false));
                        isEmpty = false;
                    } else if (n instanceof Element) {
                        break;
                    }
                }

                // Populate the nil attribute. It may be true or false
                if (proto.hasAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, "nil")) {
                    clone.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", String.valueOf(isEmpty));
                }

                // Copy over attributes present in the prototype
                NamedNodeMap attributes = proto.getAttributes();
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attribute = (Attr) attributes.item(i);
                    String localName = attribute.getLocalName();
                    if (localName == null) {
                        String name = attribute.getName();
                        if (oldEl.hasAttribute(name)) {
                            clone.setAttributeNode(
                                    (Attr) newInstanceDocument.importNode(oldEl.getAttributeNode(name), false));
                        } else {
                            LOGGER.debug("[rebuildInstance] copying in missing attribute "
                                    + attribute.getNodeName() + " to "
                                    + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement()));

                            clone.setAttributeNode((Attr) attribute.cloneNode(false));
                        }
                    } else {
                        String namespace = attribute.getNamespaceURI();
                        if (!((!isEmpty
                                && (namespace.equals(NamespaceConstants.XMLSCHEMA_INSTANCE_NS)
                                        && localName.equals("nil"))
                                || (namespace.equals(NamespaceService.ALFRESCO_URI)
                                        && localName.equals("prototype"))))) {
                            if (oldEl.hasAttributeNS(namespace, localName)) {
                                clone.setAttributeNodeNS((Attr) newInstanceDocument
                                        .importNode(oldEl.getAttributeNodeNS(namespace, localName), false));
                            } else {
                                LOGGER.debug("[rebuildInstance] copying in missing attribute "
                                        + attribute.getNodeName() + " to "
                                        + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement()));

                                clone.setAttributeNodeNS((Attr) attribute.cloneNode(false));
                            }
                        }
                    }
                }

                // recurse on children
                rebuildInstance(proto, oldEl, clone, schemaNamespaces);
            }
        }

        // Now add in a new copy of the prototype
        if (isPrototype) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] appending " + proto.getNodeName() + " to "
                        + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement()));
            }
            newInstanceNode.appendChild(proto.cloneNode(true));
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

private void addAttributeSet(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSComplexTypeDefinition controlType, final XSElementDeclaration owner, final String pathToRoot,
        final boolean checkIfExtension, final ResourceBundle resourceBundle) throws FormBuilderException {
    XSObjectList attrUses = controlType.getAttributeUses();

    if (attrUses == null) {
        return;//from   w w w . ja  v a  2  s . c o  m
    }
    for (int i = 0; i < attrUses.getLength(); i++) {
        final XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i);
        final XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration();

        String attributeName = currentAttributeUse.getName();
        if (attributeName == null || attributeName.length() == 0) {
            attributeName = currentAttributeUse.getAttrDeclaration().getName();
        }

        //test if extended !
        if (checkIfExtension && SchemaUtil.doesAttributeComeFromExtension(currentAttributeUse, controlType)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(
                        "[addAttributeSet] This attribute comes from an extension: recopy form controls. Model section =\n"
                                + XMLUtil.toString(modelSection));
            }

            //find the existing bind Id
            //(modelSection is the enclosing bind of the element)
            final NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
            String bindId = null;
            for (int j = 0; j < binds.getLength() && bindId == null; j++) {
                Element bind = (Element) binds.item(j);
                String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");
                if (nodeset != null) {
                    //remove "@" in nodeset
                    String name = nodeset.substring(1);
                    if (name.equals(attributeName)) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }
            }

            //find the control
            Element control = null;
            if (bindId != null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addAttributeSet] bindId found: " + bindId);

                JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                final Pointer pointer = context
                        .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                if (pointer != null) {
                    control = (Element) pointer.getNode();
                } else if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("[addAttributeSet] unable to resolve pointer for: //*[@"
                            + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                }
            }

            if (LOGGER.isDebugEnabled()) {
                if (control == null) {
                    LOGGER.debug("[addAttributeSet] control = <not found>");
                } else {
                    LOGGER.debug("[addAttributeSet] control = " + control.getTagName());
                }
            }

            //copy it
            if (control == null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Corresponding control not found");
            } else {
                Element newControl = (Element) control.cloneNode(true);
                //set new Ids to XForm elements
                this.resetXFormIds(newControl);

                formSection.appendChild(newControl);
            }
        } else {
            String attrNamespace = currentAttribute.getNamespace();
            String namespacePrefix = "";
            if (attrNamespace != null && attrNamespace.length() > 0) {
                String prefix = NamespaceResolver.getPrefix(xformsDocument.getDocumentElement(), attrNamespace);
                if (prefix != null && prefix.length() > 0) {
                    namespacePrefix = prefix + ":";
                }
            }

            final String newPathToRoot = (pathToRoot == null || pathToRoot.length() == 0
                    ? "@" + namespacePrefix + currentAttribute.getName()
                    : (pathToRoot.endsWith("/")
                            ? pathToRoot + "@" + namespacePrefix + currentAttribute.getName()
                            : pathToRoot + "/@" + namespacePrefix + currentAttribute.getName()));

            if (LOGGER.isDebugEnabled())
                LOGGER.debug("[addAttributeSet] adding attribute " + attributeName + " at " + newPathToRoot);

            try {
                String defaultValue = (currentAttributeUse.getConstraintType() == XSConstants.VC_NONE ? null
                        : currentAttributeUse.getConstraintValue());
                // make sure boolean attributes have a default value
                if (defaultValue == null && "boolean".equals(currentAttribute.getTypeDefinition().getName())) {
                    defaultValue = "false";
                }

                if (namespacePrefix.length() > 0) {
                    defaultInstanceElement.setAttributeNS(this.targetNamespace, attributeName, defaultValue);
                } else {
                    defaultInstanceElement.setAttribute(attributeName, defaultValue);
                }
            } catch (Exception e) {
                throw new FormBuilderException("error retrieving default value for attribute " + attributeName
                        + " at " + newPathToRoot, e);
            }
            this.addSimpleType(xformsDocument, modelSection, formSection, schema,
                    currentAttribute.getTypeDefinition(), currentAttributeUse, newPathToRoot, resourceBundle);
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 *///from   w  w w  . j a  v  a2s.c  o  m
private void addGroup(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSModelGroup group, final XSComplexTypeDefinition controlType, final XSElementDeclaration owner,
        final String pathToRoot, final SchemaUtil.Occurrence occurs, final boolean checkIfExtension,
        final ResourceBundle resourceBundle) throws FormBuilderException {
    if (group == null) {
        return;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] Start of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
        LOGGER.debug("[addGroup] group before =\n" + XMLUtil.toString(formSection));
    }

    final Element repeatSection = this.addRepeatIfNecessary(xformsDocument, modelSection, formSection,
            owner.getTypeDefinition(), pathToRoot, occurs);

    final XSObjectList particles = group.getParticles();
    for (int counter = 0; counter < particles.getLength(); counter++) {
        final XSParticle currentNode = (XSParticle) particles.item(counter);
        XSTerm term = currentNode.getTerm();
        final SchemaUtil.Occurrence childOccurs = new SchemaUtil.Occurrence(currentNode);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("[addGroup] next term = " + term.getName() + ", occurs = " + childOccurs);
        }

        if (term instanceof XSModelGroup) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is a group");
            }

            this.addGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema,
                    ((XSModelGroup) term), controlType, owner, pathToRoot, childOccurs, checkIfExtension,
                    resourceBundle);
        } else if (term instanceof XSElementDeclaration) {
            XSElementDeclaration element = (XSElementDeclaration) term;

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is an element declaration: " + term.getName());
            }

            //special case for types already added because used in an extension
            //do not add it when it comes from an extension !!!
            //-> make a copy from the existing form control
            if (checkIfExtension && SchemaUtil.doesElementComeFromExtension(element, controlType)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(
                            "[addGroup] This element comes from an extension: recopy form controls. Model Section =\n"
                                    + XMLUtil.toString(modelSection));
                }

                //find the existing bind Id
                //(modelSection is the enclosing bind of the element)
                NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
                String bindId = null;
                for (int i = 0; i < binds.getLength() && bindId == null; i++) {
                    Element bind = (Element) binds.item(i);
                    String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");

                    Pair<String, String> parsed = parseName(nodeset, xformsDocument);

                    if (nodeset != null
                            && EqualsHelper.nullSafeEquals(parsed.getSecond(), element.getNamespace())
                            && parsed.getFirst().equals(element.getName())) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }

                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addGroup] found bindId " + bindId + " for element " + element.getName());

                //find the control
                Element control = null;
                if (bindId != null) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] bindId found: " + bindId);
                    }

                    final JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                    final Pointer pointer = context
                            .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    if (pointer != null) {
                        control = (Element) pointer.getNode();
                    } else if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] unable to resolve pointer for: //*[@"
                                + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    }
                }

                if (LOGGER.isDebugEnabled()) {
                    if (control == null) {
                        LOGGER.debug("[addGroup] control = <not found>");
                    } else {
                        LOGGER.debug("[addGroup] control = " + control.getTagName());
                    }
                }

                //copy it
                if (control == null) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Corresponding control not found");

                    this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                            schema, element, pathToRoot, childOccurs, resourceBundle);
                } else {
                    Element newControl = (Element) control.cloneNode(true);
                    //set new Ids to XForm elements
                    this.resetXFormIds(newControl);

                    repeatSection.appendChild(newControl);
                }
            } else {
                this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                        schema, element, pathToRoot, childOccurs, resourceBundle);
            }
        } else {
            LOGGER.warn("Unhandled term " + term + " found in group from " + owner.getName()
                    + " for pathToRoot = " + pathToRoot);
        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] group after =\n" + XMLUtil.toString(formSection));
        LOGGER.debug("[addGroup] End of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
    }
}

From source file:org.apache.cocoon.forms.util.DomHelper.java

/**
 * Returns the first child element with the given namespace and localName,
 * or null if there is no such element and required flag is unset or
 * throws an Exception if the "required" flag is set.
 *//*ww  w . j  a  v a  2  s .  c o  m*/
public static Element getChildElement(Element element, String namespace, String localName, boolean required)
        throws Exception {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI())
                && localName.equals(node.getLocalName())) {
            return (Element) node;
        }
    }
    if (required) {
        throw new Exception("Missing element \"" + localName + "\" as child of element \""
                + element.getTagName() + "\" at " + DomHelper.getLocation(element));
    } else {
        return null;
    }
}

From source file:org.apache.cocoon.forms.util.DomHelper.java

/**
 * Returns the value of an element's attribute, but throws an exception
 * if the element has no such attribute.
 *///from   ww  w.  j  av a2 s . c  om
public static String getAttribute(Element element, String attributeName) throws Exception {
    String attrValue = element.getAttribute(attributeName);
    if (attrValue.length() == 0) {
        throw new Exception("Missing attribute \"" + attributeName + "\" on element \"" + element.getTagName()
                + "\" at " + getLocation(element));
    }
    return attrValue;
}