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(QName qName);

Source Link

Document

Returns the elements contained in this element with the given fully qualified name.

Usage

From source file:com.poka.util.XmlSax.java

/**
 * ???dddddd/* www.j av  a2  s. c  o m*/
 *
 * @return
 */
public void getHibernateXmlVal() {
    Document doc = load(f, true);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("session-factory");
    List nodes = root1Elm.elements("property");
    for (Iterator it = nodes.iterator(); it.hasNext();) {
        Element elm = (Element) it.next();
        String name = elm.attributeValue("name");
        if (name.equals("connection.url")) {
            String url = elm.getText();
            if (this.dbTyep.equals("mysql")) {
                if (url.contains("mysql")) {
                    int begingan = url.indexOf("//");
                    ip = url.substring(begingan + 2, url.lastIndexOf(":"));
                    port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf("/"));
                    names = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("?"));
                } else {
                    ip = "";
                    port = "";
                    names = "";
                }
            } else {
                if (url.contains("sqlserver")) {
                    int begingan = url.indexOf("//");
                    ip = url.substring(begingan + 2, url.lastIndexOf(":"));
                    port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf(";"));
                    names = url.substring(url.lastIndexOf("=") + 1);
                } else {
                    ip = "";
                    port = "";
                    names = "";
                }
            }
        }
        if (name.equals("connection.username")) {
            user = elm.getText();
        }

        if (name.equals("connection.password")) {
            pwd = elm.getText();
        }
    }
}

From source file:com.poka.util.XmlSax.java

public void getSoftTitle() {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("bankInfos");
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("bankInfos");
    }/*from   w  w w.jav a 2  s.c  om*/
    List nodes = root1Elm.elements("bankInfo");
    for (Iterator it = nodes.iterator(); it.hasNext();) {
        Element elm = (Element) it.next();
        String attr = elm.attributeValue("id");
        if (attr.equals("2")) {
            StaticVar.showSoftName = elm.attributeValue("myname");
        }
    }
}

From source file:com.poka.util.XmlSax.java

public void setSoftTitle(String title) {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("bankInfos");
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("bankInfos");
    }//from   ww w .  ja  va  2  s .c o m
    boolean flag = false;
    List nodes = root1Elm.elements("bankInfo");
    for (Iterator it = nodes.iterator(); it.hasNext();) {
        Element elm = (Element) it.next();
        String attr = elm.attributeValue("id");
        if (attr.equals("2")) {
            flag = true;
            elm.setAttributeValue("myname", title);
        }
    }
    if (!flag) {
        Element elm = root1Elm.addElement("bankInfo");
        elm.setAttributeValue("myname", title);
        elm.setAttributeValue("id", "2");
    }
    writeToXml(doc, bankFile);
}

From source file:com.pureinfo.ark.auth2.model.AllowDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *//*from w  ww  .j a  va  2s.c o  m*/
public void fromXML(Element _element) throws PureException {
    this.setActions(XMLUtil.getAttributeValueTrim(_element, "action"));

    List list = _element.elements("rule");
    if (list == null || list.isEmpty()) {
        m_rules = null;
    } else {
        try {
            m_rules = new RuleDef[list.size()];
            RuleDef ruleDef;
            for (int i = 0; i < list.size(); i++) {
                ruleDef = new RuleDef(m_resourceMetadata);
                ruleDef.fromXML((Element) list.get(i));
                m_rules[i] = ruleDef;
            }
        } finally {
            list.clear();
        }
    } //endif
}

From source file:com.pureinfo.ark.auth2.model.ResourceDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///from w w w  . j a  v  a2  s. co m
public void fromXML(Element _element) throws PureException {
    this.setType(XMLUtil.getAttributeValueAsInt(_element, "type"));

    EntityMetadata metadata = m_type.getContentMetadata(true);

    // to read the base
    Element ele = _element.element("base");
    if (ele == null) {
        m_base = null;
    } else {
        m_base = new BaseDef(metadata);
        m_base.fromXML(ele);
    }

    //to read rights
    List list = _element.elements("right");
    if (list == null || list.isEmpty()) {
        m_rights = null;
    } else {
        try {
            m_rights = new RightDef[list.size()];
            RightDef rightDef;
            for (int i = 0; i < list.size(); i++) {
                rightDef = new RightDef(metadata);
                rightDef.fromXML((Element) list.get(i));
                m_rights[i] = rightDef;
            }
        } finally {
            list.clear();
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.RightDefBase.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *//* w  w  w .  j a  v a 2s .c  om*/
public void fromXML(Element _element) throws PureException {
    //to read allows
    List list = _element.elements("allow");
    if (list == null || list.isEmpty()) {
        m_allows = null;
    } else {
        try {
            m_allows = new AllowDef[list.size()];
            AllowDef allowDef;
            for (int i = 0; i < list.size(); i++) {
                allowDef = new AllowDef(m_resourceMetadata);
                allowDef.fromXML((Element) list.get(i));
                m_allows[i] = allowDef;
            }
        } finally {
            list.clear();
        }
    }

    //to read switch
    Element ele = _element.element("switch");
    if (ele == null) {
        m_switch = null;
    } else {
        m_switch = new SwitchDef(m_resourceMetadata);
        m_switch.fromXML(ele);
    }
}

From source file:com.pureinfo.ark.auth2.model.RightsConfig.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 */// w  w  w  .  j  av  a 2s  .c  o m
public void fromXML(Element _element) throws PureException {
    Element ele = _element.element("roles");
    if (ele == null) {
        m_roles = null;
    } else {
        List list = ele.elements("role");
        if (list == null || list.isEmpty()) {
            m_roles = null;
        } else {
            try {
                m_roles = new RoleDef[list.size()];
                RoleDef roleDef;
                for (int i = 0; i < list.size(); i++) {
                    roleDef = new RoleDef();
                    roleDef.fromXML((Element) list.get(i));
                    m_roles[i] = roleDef;
                }
            } finally {
                list.clear();
            }
        }
    } //endif

    //to read action-base
    ele = _element.element("actions");
    if (ele == null) {
        m_actions = null;
    } else {
        List list = ele.elements("action");
        if (list == null || list.isEmpty()) {
            m_actions = null;
        } else {
            try {
                m_actions = new ActionDef[list.size()];
                ActionDef actionDef;
                for (int i = 0; i < list.size(); i++) {
                    actionDef = new ActionDef();
                    actionDef.fromXML((Element) list.get(i));
                    m_actions[i] = actionDef;
                }
            } finally {
                list.clear();
            }
        }
    } //endif

    //to read resources
    List list = _element.elements("resource");
    if (list == null || list.isEmpty()) {
        m_resources = null;
    } else {
        try {
            m_resources = new ResourceDef[list.size()];
            ResourceDef resourceDef;
            for (int i = 0; i < list.size(); i++) {
                resourceDef = new ResourceDef();
                resourceDef.fromXML((Element) list.get(i));
                m_resources[i] = resourceDef;
            }
        } finally {
            list.clear();
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.RuleDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///  w  ww.  j  a  va 2 s. co m
public void fromXML(Element _element) throws PureException {
    this.setResProperty(XMLUtil.getAttributeValueTrim(_element, "res-property"));
    this.setUserProperty(XMLUtil.getAttributeValueTrim(_element, "user-property"));
    this.setResProperty4sql(XMLUtil.getAttributeValueTrim(_element, "res-property4sql"));

    //read value type
    String sTypeName = XMLUtil.getAttributeValueTrim(_element, "type");
    if (sTypeName != null) {
        this.setValueType(PropertyType.lookupByName(sTypeName).getDataType());
    } else {
        this.setValueType(m_resourceMetadata.getProperty(m_sResProperty, true).getDataType());
    }

    this.setValue(XMLUtil.getAttributeValueTrim(_element, "value"), m_nValueType);
    this.setTestOp(ScriptOperator.getType(XMLUtil.getAttributeValueTrim(_element, "test")));

    //to import children
    List list = _element.elements("rule");
    if (list == null || list.isEmpty()) {
        m_children = null;
    } else {
        try {
            m_children = new RuleDef[list.size()];
            RuleDef ruleDef;
            for (int i = 0; i < list.size(); i++) {
                ruleDef = new RuleDef(m_resourceMetadata);
                ruleDef.fromXML((Element) list.get(i));
                m_children[i] = ruleDef;
            }
        } finally {
            list.clear();
        }
    } //endif
}

From source file:com.pureinfo.ark.auth2.model.SwitchDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///from   w w  w  . ja v a2s.co m
public void fromXML(Element _element) throws PureException {
    this.setProperty(XMLUtil.getAttributeValueTrim(_element, "property"));
    this.setProperty4sql(XMLUtil.getAttributeValueTrim(_element, "property4sql"));

    //read value type
    String sTypeName = XMLUtil.getAttributeValueTrim(_element, "type");
    if (sTypeName != null) {
        this.setValueType(PropertyType.lookupByName(sTypeName).getDataType());
    } else {
        this.setValueType(m_resourceMetadata.getProperty(m_sProperty, true).getDataType());
    }

    //to read cases
    List list = _element.elements("case");
    if (list == null || list.isEmpty()) {
        m_cases = null;
    } else {
        try {
            CaseDef caseDef;
            m_cases = new CaseDef[list.size()];
            for (int i = 0; i < list.size(); i++) {
                caseDef = new CaseDef(m_resourceMetadata, m_nValueType);
                caseDef.fromXML((Element) list.get(i));
                m_cases[i] = caseDef;
            }
        } finally {
            list.clear();
        }
    }
}

From source file:com.pureinfo.ark.content.domain.impl.ContentTypeMgrImpl.java

License:Open Source License

/**
 * Loads the content types mapping from the resource path and initiates the
 * index mapping.// www.j  a v a 2 s  .com
 */
private void init() {
    logger.debug("to load content types from " + RESOURCE_PATH);
    try {
        ContentType aType;
        Element root, element;
        List children;
        int nFileIndex, i;

        String[] names = ClassResourceUtil.listFileNames(RESOURCE_PATH, true, true);
        Arrays.sort(names, 0, names.length);

        String sFileName;
        File file;
        for (nFileIndex = 0; nFileIndex < names.length; nFileIndex++) {
            sFileName = names[nFileIndex];
            if (!sFileName.endsWith(".xml"))
                continue;

            // else
            file = new File(sFileName);
            if (logger.isDebugEnabled()) {
                logger.debug("to load content types from " + sFileName);
            }
            root = XMLUtil.fileToElement(file);
            children = root.elements(XML_CONTENT);
            for (i = 0; i < children.size(); i++) {
                element = (Element) children.get(i);
                aType = new ContentType();
                aType.fromXML(element);
                this.put(aType);
            } // endfor
        }
        logger.debug("content types loaded successfully!");
    } catch (Exception ex) {
        throw new RuntimeException("failed to load content type configuration from " + RESOURCE_PATH, ex);
    }
}