Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:com.beetle.framework.business.service.server.ServiceConfig.java

License:Apache License

private static void gendoc(Document doc) throws ClassNotFoundException {
    Node node = doc.selectSingleNode("binder");
    if (node != null) {
        Iterator<?> it = node.selectNodes("item").iterator();
        while (it.hasNext()) {
            ServiceDef sdf = new ServiceDef();
            Element e = (Element) it.next();
            String face = e.valueOf("@interface");
            String imp = e.valueOf("@implement");
            String enabled = e.valueOf("@enabled");
            sdf.setIface(face);//from  ww w . j  av a 2  s  .  c  om
            sdf.setImp(imp);
            sdf.setEnabled(enabled);
            @SuppressWarnings("unchecked")
            Iterator<Attribute> ait = e.attributeIterator();
            while (ait.hasNext()) {
                Attribute at = ait.next();
                sdf.addExtension(at.getName(), at.getValue());
            }
            register(sdf);
        }
    }
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * ??/* w ww . jav a2s .co  m*/
 * 
 * 
 * 
 * @param element
 *            
 * @param name
 *            ??
 * @param optional
 *            ??
 * @return 
 * 
 * 
 * 
 * @throws XMLDocException
 * @throws BaseException
 */
public static String getAttribute(Element element, String name, boolean optional) throws BaseException {
    Attribute attr = element.attribute(name);
    if (attr == null && !optional) {
        throw new BaseException("UTIL-0001", "Attribute " + name + " of " + element.getName() + " expected.");
    } else if (attr != null) {
        return attr.getValue();
    } else {
        return null;
    }
}

From source file:com.buddycloud.channeldirectory.search.handler.nearby.NearbyQueryHandler.java

License:Apache License

@Override
public IQ handle(IQ iq) {

    Element queryElement = iq.getElement().element("query");
    Element pointElement = queryElement.element("point");

    if (pointElement == null) {
        return XMPPUtils.error(iq, "Query does not contain point element.", getLogger());
    }/* w  ww . j av  a 2 s.c  om*/

    Attribute latAtt = pointElement.attribute("lat");
    if (latAtt == null) {
        return XMPPUtils.error(iq, "Location point does not contain point latitude element.", getLogger());
    }

    Attribute lngAtt = pointElement.attribute("lon");
    if (lngAtt == null) {
        return XMPPUtils.error(iq, "Location point does not contain point longitude element.", getLogger());
    }

    double lat = Double.valueOf(latAtt.getValue());
    double lng = Double.valueOf(lngAtt.getValue());

    RSM rsm = RSMUtils.parseRSM(queryElement);
    List<ChannelData> nearbyObjects;

    try {
        nearbyObjects = findNearbyObjects(lat, lng, rsm);
    } catch (Exception e) {
        return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", getLogger());
    }

    return createIQResponse(iq, nearbyObjects, rsm);
}

From source file:com.buddycloud.friendfinder.handler.MatchContactHandler.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   w  w w . j  a  va2  s  .c om
public IQ handle(IQ iq) {
    Element queryElement = iq.getElement().element("query");
    Iterator<Element> itemIterator = queryElement.elementIterator("item");

    List<MatchedUser> reportedHashes = new LinkedList<MatchedUser>();

    while (itemIterator.hasNext()) {
        Element item = (Element) itemIterator.next();
        Attribute meAttr = item.attribute("me");
        Attribute hashAttr = item.attribute("item-hash");

        String hash = hashAttr.getValue();

        if (meAttr != null && meAttr.getValue().equals("true")) {
            HashUtils.reportHash(iq.getFrom().toBareJID(), hash, getDataSource());
        } else {
            String jid = HashUtils.retrieveJid(hash, getDataSource());
            if (jid != null) {
                reportedHashes.add(new MatchedUser(jid, hash));
            }
        }
    }

    return createResponse(iq, reportedHashes);
}

From source file:com.chinarewards.license.util.XmlUtil_dom4j.java

public static void searchAttribute(Element paramElement) {
    Iterator localIterator = paramElement.attributeIterator();
    while (localIterator.hasNext()) {
        Attribute localAttribute = (Attribute) localIterator.next();
        System.out.println(localAttribute.getName() + " " + localAttribute.getValue());
    }//from  ww  w . ja  v a2s.  c o  m
}

From source file:com.christophermrossi.jpt.PageTemplateImpl.java

License:Open Source License

AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator i = element.attributeIterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        Namespace namespace = attribute.getNamespace();
        //String prefix = namespace.getPrefix();
        //System.err.println( "attribute: name=" + attribute.getName() + "\t" +
        //                    "qualified name=" + attribute.getQualifiedName() + "\t" +
        //                    "ns prefix=" + namespace.getPrefix() + "\t" +
        //                    "ns uri=" + namespace.getURI() );
        //String qualifiedName = attribute.getName();
        //String name = qualifiedName;
        //if ( qualifiedName.startsWith( prefix + ":" ) ) {
        //    name = qualifiedName.substring( prefix.length() + 1 );
        //}/*  www  .ja  v a  2 s .  co  m*/
        String name = attribute.getName();

        // Handle JPT attributes
        //if ( prefix.equals( talNamespacePrefix ) ) {
        if (TAL_NAMESPACE_URI.equals(namespace.getURI())) {
            // tal:define
            if (name.equals("define")) {
                expressions.define = attribute.getValue();
            }

            // tal:condition
            else if (name.equals("condition")) {
                expressions.condition = attribute.getValue();
            }

            // tal:repeat
            else if (name.equals("repeat")) {
                expressions.repeat = attribute.getValue();
            }

            // tal:content
            else if (name.equals("content")) {
                expressions.content = attribute.getValue();
            }

            // tal:replace
            else if (name.equals("replace")) {
                if (expressions.omitTag == null) {
                    expressions.omitTag = "";
                }
                expressions.content = attribute.getValue();
            }

            // tal:attributes
            else if (name.equals("attributes")) {
                expressions.attributes = attribute.getValue();
            }

            // tal:omit-tag
            else if (name.equals("omit-tag")) {
                expressions.omitTag = attribute.getValue();
            }

            // tal:evaluate
            else if (name.equals("evaluate")) {
                expressions.evaluate = attribute.getValue();
            }

            // error
            else {
                throw new PageTemplateException("unknown tal attribute: " + name);
            }
        }
        //else if ( prefix.equals( metalNamespacePrefix ) ) 
        else if (METAL_NAMESPACE_URI.equals(namespace.getURI())) {
            // metal:use-macro
            if (name.equals("use-macro")) {
                expressions.useMacro = attribute.getValue();
            }

            // metal:define-slot
            else if (name.equals("define-slot")) {
                expressions.defineSlot = attribute.getValue();
            }

            // metal:define-macro
            // metal:fill-slot
            else if (name.equals("define-macro") || name.equals("fill-slot")) {
                // these are ignored here, as they don't affect processing of current
                // template, but are called from other templates
            }

            // error
            else {
                throw new PageTemplateException("unknown metal attribute: " + name);
            }
        }

        // Pass on all other attributes
        else {
            //String qualifiedName = namespace.getPrefix() + ":" + name;
            attributes.addAttribute(namespace.getURI(), name, attribute.getQualifiedName(), "CDATA",
                    attribute.getValue());
            //attributes.addAttribute( getNamespaceURIFromPrefix(prefix), name, qualifiedName, "CDATA", attribute.getValue() );
        }
    }
    return attributes;
}

From source file:com.cladonia.xml.ExchangerXMLWriter.java

License:Open Source License

protected void writeAttribute(Attribute attribute) throws IOException {
    StringBuffer buffer = new StringBuffer();
    XAttribute a = (XAttribute) attribute;

    buffer.append(attribute.getQualifiedName());
    buffer.append("=");

    String value = attribute.getValue();
    boolean hasQuote = value.indexOf("\"") != -1;

    if (hasQuote) {
        buffer.append("'");
        buffer.append(value);//  www.ja  v  a2 s.c  om
        buffer.append("'");
    } else {
        buffer.append("\"");
        buffer.append(value);
        buffer.append("\"");
    }

    String attr = buffer.toString();

    //      System.out.println( "Wrap ["+isWrapText()+", "+getMaxLineLength()+", "+((PositionedWriter)writer).getColumn()+", "+attr.length()+"]");

    if (getMaxLineLength() != -1
            && (((PositionedWriter) writer).getColumn() + attr.length() + 1) >= getMaxLineLength()) {
        //         System.out.println( "Wrapping ... ["+attr+"]");
        ++indentLevel;

        format.setNewlines(true);
        format.setIndent(indentString);

        writePrintln();
        indent();

        --indentLevel;

        format.setNewlines(false);
        format.setIndent("");
    } else {
        writer.write(" ");
    }

    a.setAttributeStartPosition(((PositionedWriter) writer).getPosition());

    writer.write(attr);

    a.setAttributeEndPosition(((PositionedWriter) writer).getPosition());

    lastOutputNodeType = Node.ATTRIBUTE_NODE;
}

From source file:com.cladonia.xml.viewer.XmlElementNode.java

License:Mozilla Public License

private StyledElement formatAttribute(Attribute a) {
    StyledElement styledAttribute = new StyledElement();

    String name = a.getName();//w  w  w.jav a  2  s.com
    String value = a.getValue();

    if (_viewer.showNamespaces()) {
        String prefix = a.getNamespacePrefix();

        if (prefix != null && prefix.length() > 0) {
            styledAttribute.addString(new AttributePrefix(prefix));
            styledAttribute.addString(ATTRIBUTE_COLON);
        }
    }

    styledAttribute.addString(new AttributeName(name));
    styledAttribute.addString(ATTRIBUTE_ASIGN);

    styledAttribute.addString(new AttributeValue(value));

    return styledAttribute;
}

From source file:com.cladonia.xml.xdiff.XmlElementNode.java

License:Open Source License

private StyledElement formatAttribute(Attribute a) {
    StyledElement styledAttribute = new StyledElement();

    String name = a.getName();//  ww  w  .ja v a 2 s. c o  m
    String qualifiedName = a.getQualifiedName();
    String value = a.getValue();

    boolean localInsertAttribute = false;
    boolean localDeleteAttribute = false;

    if (findAttribute(qualifiedName, insertAttributes) || insideInsertChain(this)) {
        localInsertAttribute = true;
        currentColor = COLOR_GREEN;
    } else if (findAttribute(qualifiedName, deleteAttributes) || insideDeleteChain(this)) {
        localDeleteAttribute = true;
        currentColor = Color.RED;
    } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) {
        currentColor = COLOR_MERGED;
    } else {
        currentColor = Color.BLACK;
    }

    String prefix = a.getNamespacePrefix();

    if (prefix != null && prefix.length() > 0) {
        styledAttribute.addString(new AttributePrefix(prefix));

        if (localInsertAttribute) {
            styledAttribute.addString(INSERT_ATTRIBUTE_COLON);
        } else if (localDeleteAttribute) {
            styledAttribute.addString(DELETE_ATTRIBUTE_COLON);
        } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) {
            styledAttribute.addString(MERGED_ATTRIBUTE_COLON);
        } else {
            styledAttribute.addString(ATTRIBUTE_COLON);
        }
    }

    styledAttribute.addString(new AttributeName(name));

    if (localInsertAttribute) {
        styledAttribute.addString(INSERT_ATTRIBUTE_ASIGN);
        styledAttribute.addString(INSERT_ATTRIBUTE_QUOTE);
    } else if (localDeleteAttribute) {
        styledAttribute.addString(DELETE_ATTRIBUTE_ASIGN);
        styledAttribute.addString(DELETE_ATTRIBUTE_QUOTE);
    } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) {
        styledAttribute.addString(MERGED_ATTRIBUTE_ASIGN);
        styledAttribute.addString(MERGED_ATTRIBUTE_QUOTE);
    } else {
        styledAttribute.addString(ATTRIBUTE_ASIGN);
        styledAttribute.addString(ATTRIBUTE_QUOTE);
    }

    String attrPreviousText = findUpdatedAttribute(qualifiedName, updateAttributes);
    if (attrPreviousText != null) {
        StyledString updatedValue = new AttributePreviousValue(attrPreviousText);
        updatedValue.setStrikeThrough(true);
        styledAttribute.addString(updatedValue);

        currentColor = Color.BLUE;
    }

    styledAttribute.addString(new AttributeValue(value));

    if (localInsertAttribute) {
        styledAttribute.addString(INSERT_ATTRIBUTE_QUOTE);
    } else if (localDeleteAttribute) {
        styledAttribute.addString(DELETE_ATTRIBUTE_QUOTE);
    } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) {
        styledAttribute.addString(MERGED_ATTRIBUTE_QUOTE);
    } else {
        styledAttribute.addString(ATTRIBUTE_QUOTE);
    }

    currentColor = Color.BLACK;
    return styledAttribute;
}

From source file:com.cladonia.xml.XMLFormatter.java

License:Mozilla Public License

protected void writeElement(Element element) throws IOException {
    if (DEBUG)//  w w w.j a  v  a2 s  .c om
        System.out.println("XMLFormatter.writeElement( " + element + ")");
    //      if ( indentMixed) {
    //         super.writeElement( element);
    //      } else {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    boolean hasElement = false;
    boolean hasText = false;

    // first test to see if this element has mixed content, 
    // if whitespace is significant ...
    for (int i = 0; i < size; i++) {
        Node node = element.node(i);

        if (node instanceof Element) {
            hasElement = true;
        } else if (node instanceof Text) {
            String text = node.getText();

            if (text != null && text.trim().length() > 0) {
                hasText = true;
            }
        }
    }

    Attribute space = element.attribute("space");
    boolean preserveSpace = false;

    if (space != null) {
        String prefix = space.getNamespacePrefix();
        String value = space.getValue();
        //         System.out.println( "prefix = "+prefix+" value = "+value);
        if (prefix != null && "xml".equals(prefix) && "preserve".equals(value)) {
            preserveSpace = true;
        }
    }

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    int previouslyDeclaredNamespaces = namespaceStack.size();

    Namespace ns = element.getNamespace();

    if (isNamespaceDeclaration(ns)) {
        namespaceStack.push(ns);
        writeNamespace(ns);
    }

    // Print out additional namespace declarations
    for (int i = 0; i < size; i++) {
        Node node = element.node(i);

        if (node instanceof Namespace) {
            Namespace additional = (Namespace) node;

            if (isNamespaceDeclaration(additional)) {
                namespaceStack.push(additional);
                writeNamespace(additional);
            }
        }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
        writeEmptyElementClose(qualifiedName);
    } else {
        writer.write(">");

        if (!hasElement && !preserveSpace) { // text only
            // we have at least one text node so lets assume
            // that its non-empty
            //            System.out.println( "writeElementContent (Text) ...");
            boolean previousWrapText = wrapText;
            wrapText = true;
            writeElementContent(element);
            wrapText = previousWrapText;
        } else if (preserveMixedContent && hasElement && hasText) { // preserve space
            // Mixed content
            //                System.out.println( "writeMixedElementContent ...");
            Node lastNode = writeMixedElementContent(element);

        } else if (preserveSpace) { // preserve space
            // Mixed content
            //                System.out.println( "writePreserveElementContent ...");
            Node lastNode = writePreservedElementContent(element);

        } else { // hasElement && !hasText
            //               System.out.println( "writeElementContent (Element) ...");

            boolean previousWrapText = wrapText;
            wrapText = true;
            ++indentLevel;
            writeElementContent(element);
            --indentLevel;
            wrapText = previousWrapText;

            writePrintln();
            indent();
        }

        writer.write("</");
        writer.write(qualifiedName);
        writer.write(">");
        //         writePrintln();
    }

    // remove declared namespaceStack from stack
    while (namespaceStack.size() > previouslyDeclaredNamespaces) {
        namespaceStack.pop();
    }

    lastOutputNodeType = Node.ELEMENT_NODE;
    //      }
}