Example usage for org.dom4j Element attributeCount

List of usage examples for org.dom4j Element attributeCount

Introduction

In this page you can find the example usage for org.dom4j Element attributeCount.

Prototype

int attributeCount();

Source Link

Document

DOCUMENT ME!

Usage

From source file:nl.nn.ibistesttool.PipeDescriptionProvider.java

License:Apache License

private void addResourceNamesToPipeDescription(Element element, PipeDescription pipeDescription) {
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
        Attribute attribute = element.attribute(i);
        if ("styleSheetName".equals(attribute.getName())
                || "serviceSelectionStylesheetFilename".equals(attribute.getName())
                || "schema".equals(attribute.getName()) || "wsdl".equals(attribute.getName())
                || "fileName".equals(attribute.getName()) || "schemaLocation".equals(attribute.getName())) {
            if ("schemaLocation".equals(attribute.getName())) {
                StringTokenizer st = new StringTokenizer(attribute.getValue(), ", \t\r\n\f");
                while (st.hasMoreTokens()) {
                    st.nextToken();//from   w  w  w . j  av a2 s.  co  m
                    String resourceName = st.nextToken();
                    if (!pipeDescription.containsResourceName(resourceName)) {
                        pipeDescription.addResourceName(resourceName);
                    }
                }
            } else {
                String resourceName = attribute.getValue();
                if (!pipeDescription.containsResourceName(resourceName)) {
                    pipeDescription.addResourceName(resourceName);
                }
            }
        }
    }
    for (int i = 0, size = element.nodeCount(); i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element && "sender".equals(node.getName())) {
            addResourceNamesToPipeDescription((Element) node, pipeDescription);
        }
    }
}

From source file:org.foxbpm.engine.impl.util.FoxBPMCfgParseUtil.java

License:Apache License

private void doAttributes(Element element, Object paramObj) {
    // ?element/*from w w  w  . java 2 s . c o  m*/
    Method method = null;
    Attribute attribute = null;
    Map<String, Method> methodMap = getSetMethods(GENERAL_M_PREFIX, paramObj);
    for (int i = 0, length = element.attributeCount(); i < length; i++) {
        attribute = element.attribute(i);
        method = methodMap.get(generateMethodName(GENERAL_M_PREFIX, attribute.getName()));
        if (null != method) {
            doAttributeValue(paramObj, method, attribute.getValue(), method.getParameterTypes()[0]);
        }
    }
}

From source file:org.foxbpm.engine.impl.util.XMLToObject.java

License:Apache License

/**
 * ?/*from  ww  w .ja  v a 2 s. c  o m*/
 * 
 * @param element
 * @param paramObj
 * @param temp
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private void doAttributes(Element element, Object paramObj, Map<String, Method> methods)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    // ?element
    Method method = null;
    Attribute attribute = null;
    for (int i = 0, length = element.attributeCount(); i < length; i++) {
        attribute = element.attribute(i);
        method = methods.get(generateMethodName(GENERAL_M_PREFIX, attribute.getName()));
        if (null != method && method.getParameterTypes().length == 1) {
            doAttributeValue(paramObj, method, attribute.getValue(), method.getParameterTypes()[0]);
        }
    }
}

From source file:org.hudsonci.xpath.impl.Dom2Dom.java

License:Open Source License

private org.w3c.dom.Node createChild(Node child, org.w3c.dom.Node wparent) {
    int type = child.getNodeType();

    // Collapse multiple consecutive text nodes to a single text node
    // with trimmed value.
    if (type != Node.TEXT_NODE)
        endText(wparent);//w w w  .  j av a  2  s  . com

    Name name;
    org.w3c.dom.Node node = null;

    switch (type) {
    case Node.ATTRIBUTE_NODE:
        break;
    case Node.CDATA_SECTION_NODE:
        CDATA cd = (CDATA) child;
        wparent.appendChild(node = wdoc.createCDATASection(cd.getText()));
        break;
    case Node.COMMENT_NODE:
        Comment co = (Comment) child;
        wparent.appendChild(node = wdoc.createComment(co.getText()));
        break;
    case Node.DOCUMENT_TYPE_NODE:
        DocumentType dt = (DocumentType) child;
        wparent.appendChild(new XDocumentType(dt, wparent));
        break;
    case Node.ELEMENT_NODE:
        Element el = (Element) child;
        name = new Name(el);
        org.w3c.dom.Element e = name.namespaceURI == null ? wdoc.createElement(name.qualifiedName)
                : wdoc.createElementNS(name.namespaceURI, name.qualifiedName);
        wparent.appendChild(e);
        node = currentElement = e;

        for (int i = 0, n = el.attributeCount(); i < n; i++) {
            Attribute at = el.attribute(i);
            name = new Name(at);
            if (name.namespaceURI == null)
                e.setAttribute(name.qualifiedName, at.getValue());
            else
                e.setAttributeNS(name.namespaceURI, name.qualifiedName, at.getValue());
        }
        return e;
    case Node.ENTITY_REFERENCE_NODE:
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        ProcessingInstruction p = (ProcessingInstruction) child;
        wparent.appendChild(node = wdoc.createProcessingInstruction(p.getTarget(), p.getText()));
        break;
    case Node.TEXT_NODE:
        textBuilder.append(child.getText());
        lastText = (Text) child;
        break;
    case Node.NAMESPACE_NODE:
        Namespace ns = (Namespace) child;
        name = new Name(ns);
        currentElement.setAttribute(name.qualifiedName, ns.getURI());
        break;
    default:
        throw new IllegalStateException("Unknown node type");
    }
    if (node != null)
        reverseMap.put(node, child);
    return null;
}

From source file:org.onecmdb.ui.gwt.desktop.server.service.content.adapter.GXTModelContentAdapter.java

License:Open Source License

private boolean isSimpleElement(Element e) {
    if (e.elements().size() > 0) {
        return (false);
    }/* ww  w .  j a  v  a 2 s  .c  o  m*/
    if (e.attributeCount() > 0) {
        return (false);
    }
    return true;
}

From source file:org.opencms.xml.CmsXmlContentDefinition.java

License:Open Source License

/**
 * Validates if a given element has exactly the required attributes set.<p>
 * /*from ww w  .  ja  va  2 s .  c  o m*/
 * @param element the element to validate
 * @param requiredAttributes the list of required attributes
 * @param optionalAttributes the list of optional attributes
 * 
 * @throws CmsXmlException if the validation fails 
 */
protected static void validateAttributesExists(Element element, String[] requiredAttributes,
        String[] optionalAttributes) throws CmsXmlException {

    if (element.attributeCount() < requiredAttributes.length) {
        throw new CmsXmlException(
                Messages.get().container(Messages.ERR_EL_ATTRIBUTE_TOOFEW_3, element.getUniquePath(),
                        new Integer(requiredAttributes.length), new Integer(element.attributeCount())));
    }

    if (element.attributeCount() > (requiredAttributes.length + optionalAttributes.length)) {
        throw new CmsXmlException(Messages.get().container(Messages.ERR_EL_ATTRIBUTE_TOOMANY_3,
                element.getUniquePath(), new Integer(requiredAttributes.length + optionalAttributes.length),
                new Integer(element.attributeCount())));
    }

    for (int i = 0; i < requiredAttributes.length; i++) {
        String attributeName = requiredAttributes[i];
        if (element.attribute(attributeName) == null) {
            throw new CmsXmlException(Messages.get().container(Messages.ERR_EL_MISSING_ATTRIBUTE_2,
                    element.getUniquePath(), attributeName));
        }
    }

    List<String> rA = Arrays.asList(requiredAttributes);
    List<String> oA = Arrays.asList(optionalAttributes);

    for (int i = 0; i < element.attributes().size(); i++) {
        String attributeName = element.attribute(i).getName();
        if (!rA.contains(attributeName) && !oA.contains(attributeName)) {
            throw new CmsXmlException(Messages.get().container(Messages.ERR_EL_INVALID_ATTRIBUTE_2,
                    element.getUniquePath(), attributeName));
        }
    }
}

From source file:org.opensha.commons.data.TimeSpan.java

License:Apache License

public static TimeSpan fromXMLMetadata(Element el) {
    String precision = el.attribute("startTimePrecision").getValue();
    String units = el.attribute("durationUnits").getValue();
    double duration = Double.parseDouble(el.attribute("duration").getValue());

    TimeSpan span = new TimeSpan(precision, units);
    span.setDuration(duration, units);//  ww w  .  j  a  v a2  s  .c om
    Element startTimes = el.element("startTimes");

    int count = startTimes.attributeCount();

    int num = 0;
    int year = -1;
    int month = -1;
    int day = -1;
    int hour = -1;
    int minute = -1;
    int second = -1;
    int millisecond = -1;

    for (int i = 0; i < count; i++) {
        Attribute att = startTimes.attribute(i);
        if (att.getName().equals(TimeSpan.START_DAY.replaceAll(" ", ""))) {
            day = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_HOUR.replaceAll(" ", ""))) {
            hour = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_MILLISECOND.replaceAll(" ", ""))) {
            millisecond = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_MINUTE.replaceAll(" ", ""))) {
            minute = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_MONTH.replaceAll(" ", ""))) {
            month = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_SECOND.replaceAll(" ", ""))) {
            second = Integer.parseInt(att.getValue());
            num++;
        } else if (att.getName().equals(TimeSpan.START_YEAR.replaceAll(" ", ""))) {
            year = Integer.parseInt(att.getValue());
            num++;
        }
    }

    if (num == 1)
        span.setStartTime(year);
    else if (num == 2)
        span.setStartTime(year, month);
    else if (num == 3)
        span.setStartTime(year, month, day);
    else if (num == 4)
        span.setStartTime(year, month, day, hour);
    else if (num == 5)
        span.setStartTime(year, month, day, hour, minute);
    else if (num == 6)
        span.setStartTime(year, month, day, hour, minute, second);
    else if (num == 7)
        span.setStartTime(year, month, day, hour, minute, second, millisecond);

    return span;
}

From source file:org.orbeon.oxf.xml.dom4j.NonLazyUserDataElement.java

License:Open Source License

public void appendAttributes(final org.dom4j.Element src) {
    for (int i = 0, size = src.attributeCount(); i < size; i++) {
        final org.dom4j.Attribute att = src.attribute(i);
        final org.dom4j.Attribute attCln = (org.dom4j.Attribute) att.clone();
        add(attCln);// w w  w.j av a  2s  . c o  m
    }

}

From source file:org.xmlactions.mapping.validation.CompareAttributes.java

License:Apache License

protected boolean compareAttributes(Element element1, Element element2) {
    boolean result = true;
    if (isIgnoreExtraAttributes() == false && element1.attributeCount() != element2.attributeCount()) {
        addError("Attribute count does not match between [" + element1.getName() + "] and ["
                + element2.getName() + "]");
        result = false;/*from   ww w  .  j av  a  2  s.c om*/
    } else {
        List<Attribute> atts1 = element1.attributes();
        List<Attribute> atts2 = element2.attributes();
        for (Attribute att1 : atts1) {
            Attribute att2 = findMatchingAttribute(att1, atts2);
            if (att2 == null) {
                addError("No matching attribute found [" + element1.getName() + "@" + att1.getName() + "["
                        + att1.getValue() + "]] in element [" + element2.getName() + "]");
                result = false;
                break;
            }
        }
    }
    return result;
}

From source file:org.xulux.dataprovider.contenthandlers.DOMTreeContentHandler.java

License:Apache License

/**
 * @see org.xulux.dataprovider.contenthandlers.TreeContentHandler#getChildCount(java.lang.Object)
 *//*from   w  ww  . ja v a 2 s .  co m*/
public int getChildCount(Object parent) {
    if (parent instanceof ContentView) {
        parent = ((ContentView) parent).getSource();
    }
    int children = 0;
    if (parent instanceof Document) {
        List list = ((Document) parent).content();
        if (list != null) {
            children = list.size();
        }
    } else if (parent instanceof Element) {
        Element element = (Element) parent;
        children = getRealContent(element.content()).size();
        children += element.attributeCount();
    }
    //System.err.println("Children : " + children);
    return children;
}