Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

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

Prototype

List<Element> elements();

Source Link

Document

Returns the elements contained in this element.

Usage

From source file:android.apn.androidpn.server.xmpp.net.StanzaHandler.java

License:Open Source License

private void processIQ(Element doc) {
    log.debug("processIQ()...");
    IQ packet;/*  ww  w  . j a  v  a  2s.co m*/
    try {
        packet = getIQ(doc);
    } catch (IllegalArgumentException e) {
        log.debug("Rejecting packet. JID malformed", e);
        IQ reply = new IQ();
        if (!doc.elements().isEmpty()) {
            reply.setChildElement(((Element) doc.elements().get(0)).createCopy());
        }
        reply.setID(doc.attributeValue("id"));
        reply.setTo(session.getAddress());
        String to = doc.attributeValue("to");
        if (to != null) {
            reply.getElement().addAttribute("from", to);
        }
        reply.setError(PacketError.Condition.jid_malformed);
        session.process(reply);
        return;
    }

    //        if (packet.getID() == null) {
    //            // IQ packets MUST have an 'id' attribute
    //            StreamError error = new StreamError(
    //                    StreamError.Condition.invalid_xml);
    //            session.deliverRawText(error.toXML());
    //            session.close();
    //            return;
    //        }

    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
}

From source file:architecture.common.lifecycle.internal.XmlApplicationPropertiesOld.java

License:Apache License

public Collection getChildrenNames(String parent) {
    String propName[] = parsePropertyName(parent);
    Element element = doc.getRootElement();
    for (int i = 0; i < propName.length; i++) {
        element = element.element(propName[i]);
        if (element == null)
            return Collections.emptyList();
    }/*from   www .  jav  a 2 s.  c  o m*/

    List<Element> children = element.elements();
    int childCount = children.size();
    List<String> childrenNames = new ArrayList<String>(childCount);

    for (Element e : children) {
        childrenNames.add(e.getName());
    }

    return childrenNames;
}

From source file:architecture.common.lifecycle.internal.XmlApplicationPropertiesOld.java

License:Apache License

private void getElementNames(List<String> list, Element e, String name) {
    if (e.elements().isEmpty()) {
        list.add(name);//w ww . j a  v a2 s .com
    } else {
        List<Element> children = e.elements();
        for (Element child : children) {
            getElementNames(list, child,
                    (new StringBuilder()).append(name).append('.').append(child.getName()).toString());
        }
    }
}

From source file:architecture.common.xml.XmlProperties.java

License:Apache License

/**
 * Return all children property names of a parent property as a String
 * array, or an empty array if the if there are no children. For example,
 * given the properties <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, and <tt>X.Y.C</tt>,
 * then the child properties of <tt>X.Y</tt> are <tt>A</tt>, <tt>B</tt>, and
 * <tt>C</tt>./*  ww w .j a  v  a  2 s .c o m*/
 *
 * @param parent
 *            the name of the parent property.
 * @return all child property values for the given parent.
 */
public String[] getChildrenProperties(String parent) {
    String[] propName = parsePropertyName(parent);
    // Search for this property by traversing down the XML heirarchy.
    Element element = document.getRootElement();
    for (String aPropName : propName) {
        element = element.element(aPropName);
        if (element == null) {
            // This node doesn't match this part of the property name which
            // indicates this property doesn't exist so return empty array.
            return new String[] {};
        }
    }
    // We found matching property, return names of children.
    List children = element.elements();
    int childCount = children.size();
    String[] childrenNames = new String[childCount];
    for (int i = 0; i < childCount; i++) {
        childrenNames[i] = ((Element) children.get(i)).getName();
    }
    return childrenNames;
}

From source file:architecture.common.xml.XmlProperties.java

License:Apache License

public Collection<String> getChildrenNames(String parent) {
    String propNames[] = parsePropertyName(parent);
    Element element = document.getRootElement();
    for (String propName : propNames) {
        element = element.element(propName);
        if (element == null)
            return Collections.emptyList();
    }//from   w w  w  . j  ava  2s.c  o  m

    List<Element> children = element.elements();
    int childCount = children.size();
    List<String> childrenNames = new ArrayList<String>(childCount);

    for (Element e : children) {
        childrenNames.add(e.getName());
    }

    return childrenNames;
}

From source file:architecture.common.xml.XmlProperties.java

License:Apache License

public Collection<String> getPropertyNames() {
    List<String> propNames = new LinkedList<String>();

    Element element = document.getRootElement();
    List<Element> elements = element.elements();
    if (elements.size() == 0)
        return Collections.emptyList();
    for (Element child : elements) {
        getElementNames(propNames, child, child.getName());
    }/*  w ww.j a  v a  2 s  .  com*/
    return propNames;
}

From source file:br.mdarte.exemplo.academico.cd.EstudanteDAO.java

public int xmlImportEntity(org.dom4j.Element raiz) throws DAOException {
    Session session = currentSession();/*from   w  ww.j  a va  2 s  . c  o m*/
    org.hibernate.Criteria critBusca_Entidade = session.createCriteria(EstudanteImpl.class);

    java.util.List listaRes = critBusca_Entidade.setMaxResults(2).list();
    if (listaRes.size() > 1)
        throw new DAOException("error.default.exportid.notunique.exception" + "," + listaRes.get(0).toString()
                + "," + listaRes.get(1).toString());

    EstudanteImpl entidade;

    if (listaRes.size() == 0)
        entidade = new EstudanteImpl();
    else
        entidade = (EstudanteImpl) listaRes.get(0);

    if (raiz.selectNodes("./matricula").size() != 0) {
        java.lang.String valormatricula = java.lang.String.valueOf(raiz.valueOf("./matricula"));
        entidade.setMatricula(valormatricula);
    }

    if (raiz.selectNodes("./nome").size() != 0) {
        java.lang.String valornome = java.lang.String.valueOf(raiz.valueOf("./nome"));
        entidade.setNome(valornome);
    }

    Element raiz_curso = (Element) raiz.selectSingleNode("./curso");
    if (raiz_curso.elements().size() != 0) {

        org.hibernate.Criteria critBusca_curso = session
                .createCriteria(br.mdarte.exemplo.academico.cd.CursoImpl.class);

        java.util.List listaResAss_curso = critBusca_curso.setMaxResults(2).list();
        if (listaResAss_curso.size() > 1) // Encontrou mais de uma entidade para o mesmo cdigo
            throw new DAOException("error.default.exportid.notunique.exception" + ","
                    + listaResAss_curso.get(0).toString() + "," + listaResAss_curso.get(1).toString());
        if (listaResAss_curso.size() == 0) // Nao encontrou entidade associada
            return 1;
        if (listaResAss_curso.size() == 1) {
            br.mdarte.exemplo.academico.cd.CursoImpl entidade_ass_curso;
            entidade_ass_curso = (br.mdarte.exemplo.academico.cd.CursoImpl) listaResAss_curso.get(0);
            entidade.setCurso(entidade_ass_curso);
        }

    } else {
        entidade.setCurso(null);
    }
    insertOrUpdate(entidade);

    return 0;
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

@Override
protected void parseChild(Element child) {
    if (child.getName().equals("highlight")) {
        IWarlockStyle style = null;//from   w  ww  . j  a va2  s .c om
        if (child.elements().size() > 0 && child.element("style") != null) {
            Element sElement = child.element("style");
            style = createStyle(sElement);
        }

        try {
            HighlightString string = new HighlightString(this, null, style);
            fillSetting(string, child);
            highlights.add(string);
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
        }
    } else if (child.getName().equals("style")) {
        IWarlockStyle style = createStyle(child);

        namedStyles.put(style.getName(), style);
    }
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

protected IWarlockStyle createStyle(Element sElement) {
    WarlockStyle style = new WarlockStyle();
    style.setBackgroundColor(colorValue(sElement, "background"));
    style.setForegroundColor(colorValue(sElement, "foreground"));

    if (sElement.attributeValue("name") != null) {
        style.setName(stringValue(sElement, "name"));
    }/*from   w ww  . ja v a2s  .  c  om*/

    for (Element typeElement : (List<Element>) sElement.elements()) {
        String text = typeElement.getTextTrim();
        style.addStyleType(IWarlockStyle.StyleType.valueOf(text));
    }

    style.setFullLine(booleanValue(sElement, "full-line"));
    //System.out.println("Setting style sound to " + sElement.attributeValue("sound"));
    style.setSound(sElement.attributeValue("sound"));

    return style;
}

From source file:cc.warlock.core.configuration.TreeConfigurationProvider.java

License:Open Source License

public void parseElement(Element element) {
    this.element = element;

    parseData();/*w w w.ja  v  a2  s.co  m*/

    for (Element subElement : (List<Element>) element.elements()) {
        if (handleChildren) {
            unhandledElements.add(subElement);

            parseUnhandledElements();
        } else {
            parseChild(subElement);
        }
    }
}