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.pureinfo.srm.auth.domain.impl.AuthMgrSRMImpl.java

License:Open Source License

/**
 * Loads user rights configuration.//from w w w .ja v a 2  s  .  co  m
 * 
 * @throws PureException
 *             if failed to load from resource file.
 */
private void loadConfig() throws PureException {
    logger.debug("to load user rights configuration from " + RESOURCE + "...");
    try {
        int nContentType, nUserLevel, nRights;

        String sFile = ClassResourceUtil.mapFullPath(RESOURCE, true);
        Element xmlRoot = XMLUtil.fileToElement(sFile);

        Element element;
        List elements = xmlRoot.elements("content");
        for (int i = 0; i < elements.size(); i++) {
            element = (Element) elements.get(i);
            nContentType = XMLUtil.getAttributeValueAsInt(element, "type");

            List children = element.elements("user");
            Map map = new HashMap(children.size());
            for (int j = 0; j < children.size(); j++) {
                element = (Element) children.get(j);
                nUserLevel = XMLUtil.getAttributeValueAsInt(element, "level");
                nRights = XMLUtil.getAttributeValueAsInt(element, "rights");
                map.put(new Integer(nUserLevel), new BitsValue(nRights));
            }
            m_hRights.put(new Integer(nContentType), map);
            children.clear();
        } //endfor
        elements.clear();
        logger.debug("user rights configuration loaded successfully");
    } catch (Exception ex) {
        throw new PureException(SRMExceptionTypes.RIGHTS_CONFIG_LOAD, RESOURCE, ex);
    }
}

From source file:com.pureinfo.srm.config.ModulesConfig.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///from   ww w.j  a  v  a 2  s  . c  om
public void fromXML(Element _element) throws PureException {
    // 1. to clear the old
    this.clear();

    // 2. to read the modules
    if (_element == null)
        return; // skip
    List list = _element.elements("module");
    if (list != null) {
        try {
            for (int i = 0; i < list.size(); i++) {
                Module module = new Module(m_sUnivCode);
                module.fromXML((Element) list.get(i));
                m_hMoudules.put(module.getName(), module);
            }
        } finally {
            list.clear();
        }
    }
}

From source file:com.pureinfo.srm.config.workflow.domain.WorkflowMgrImpl.java

License:Open Source License

/**
 * @see com.pureinfo.srm.config.workflow.domain.IWorkflowMgr#loadRolesFromXML(org.dom4j.Element)
 *//*  w w  w  .  ja  v a2s . c  o  m*/
public void loadRolesFromXML(Element _element) throws PureException {
    m_roles = new HashMap();

    List roleEles = _element.elements(ELEMENT_ROLE);
    for (Iterator iter = roleEles.iterator(); iter.hasNext();) {
        Element roleEle = (Element) iter.next();
        WfRole role = new WfRole();
        role.fromXML(roleEle);
        m_roles.put(role.getName(), role);
    }
}

From source file:com.pureinfo.srm.config.workflow.domain.WorkflowMgrImpl.java

License:Open Source License

public void loadProcessesFromXML(Element _element) throws PureException {
    m_processes = new HashMap();
    List processEles = _element.elements(ELEMENT_PROCESS);
    for (Iterator iter = processEles.iterator(); iter.hasNext();) {
        Element processEle = (Element) iter.next();
        WfProcess process = new WfProcess();
        process.fromXML(processEle);/*from  w  w w. j a va2s  .c o  m*/
        m_processes.put(process.getName(), process);
    }
}

From source file:com.pureinfo.srm.config.workflow.model.WfActivity.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///w  w w.  ja v a2s  .c  o m
public void fromXML(Element _element) throws PureException {
    m_sName = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_NAME);

    List roleIdEles = _element.elements(ELEMENT_ROLEREF);
    m_roles = new HashMap();
    IWorkflowMgr wfMgr = (IWorkflowMgr) PureFactory.getBean("IWorkflowMgr");

    for (Iterator iter = roleIdEles.iterator(); iter.hasNext();) {
        Element roleIdEle = (Element) iter.next();
        String sId = XMLUtil.getRequiredAttributeValue(roleIdEle, ATTRIBUTE_ID);
        WfRole role = wfMgr.getRole(sId);
        m_roles.put(sId, role);
    }
}

From source file:com.pureinfo.srm.config.workflow.model.WfProcess.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *///w w  w  .  j  a  v a2  s.  c  o m
public void fromXML(Element _element) throws PureException {
    m_sName = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_NAME);
    m_sType = XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_TYPE);
    List actEles = _element.elements(ELEMENT_ACTIVITY);
    m_actities = new LinkedHashMap();
    for (Iterator iter = actEles.iterator(); iter.hasNext();) {
        Element actEle = (Element) iter.next();
        WfActivity act = new WfActivity();
        act.fromXML(actEle);
        m_actities.put(act.getName(), act);
    }
}

From source file:com.pureinfo.srm.report.report.digital.parser.ReportParser.java

License:Open Source License

private static Map parseGroupers(Document _script) {
    List xGroupers = _script.getRootElement().element("groupers").elements("grouper");
    Map groupers = new HashMap(xGroupers.size());
    for (Iterator iter = xGroupers.iterator(); iter.hasNext();) {
        Element xQuery = (Element) iter.next();
        String sId = xQuery.attributeValue("id");

        Grouper grouper = new Grouper();
        String sType = xQuery.attributeValue("type");
        List xParams = xQuery.elements("param");
        Map params = new HashMap(xParams.size());
        for (Iterator iterInner = xGroupers.iterator(); iterInner.hasNext();) {
            Element xParam = (Element) iterInner.next();
            params.put(xParam.attributeValue("name"), xParam.getText().trim());
        }//w w  w.ja  v a2s  . c  o m
        grouper.setType(sType);
        grouper.setPamrams(params);
        groupers.put(sId, grouper);
    }
    return groupers;
}

From source file:com.pureinfo.srm.srm2rpms.SRM2RPMSImporter.java

License:Open Source License

/**
 * Runs to export SRM data to RPMS//from  w ww . ja va 2  s.com
 * 
 * @param _sItemFlags
 *            flags of the data item to export.
 * @throws PureException
 *             if failed.
 */
public static void run(String _sItemFlags) throws PureException {
    Date today = new Date();
    int nYear = DateTimeUtil.get(today, DateTimeUtil.YEAR) - 1
            + DateTimeUtil.get(today, DateTimeUtil.MONTH) / 11;
    logger.debug("Year=" + nYear + ", ItemFlags=" + _sItemFlags);

    String sConfigPath = ClassResourceUtil.mapFullPath("com/pureinfo/srm/srm2rpms/mapping/", true);
    String sIndexFile = sConfigPath + "index.srm.xml";
    Element xml = XMLUtil.fileToElement(sIndexFile);

    List list = xml.elements("exporter");
    Importer importer = null;
    try {
        importer = new Importer("Local", "Export");

        String sConfigFile;
        String sFlag;
        for (int i = 0; i < list.size(); i++) {
            sConfigFile = ((Element) list.get(i)).attributeValue("config");
            if (_sItemFlags != null) {
                sFlag = sConfigFile.substring(0, 2);
                if (_sItemFlags.indexOf(sFlag) < 0)
                    continue; // skip
            }

            // else
            importer.config(sConfigPath + sConfigFile, nYear);
            importer.run();
        }
    } finally {
        list.clear();
        if (importer != null)
            importer.clear();
    }
}

From source file:com.pureinfo.studio.db.export.InsertSQLDumper.java

License:Open Source License

private void executeSQLElement(String _sName) throws Exception {
    Element ele = m_xmlConfig.element(_sName);
    if (ele == null || "false".equals(ele.attributeValue("enabled"))) {
        return;//from ww  w.  j ava 2s  .c  o m
    }

    //else
    List eleSQLs = ele.elements("sql");
    if (eleSQLs.isEmpty())
        return;

    //else, to execute the SQLs
    String strSQL;
    ISession session = this.getSessionTo();
    for (int i = 0; i < eleSQLs.size(); i++) {
        strSQL = ((Element) eleSQLs.get(i)).getTextTrim();
        try {
            System.out.println("to execute: " + strSQL);
            IStatement statement = session.createStatement(strSQL);
            this.registerAlias(statement, ele.elements("alias"));
            statement.executeUpdate();
            statement.clear();
        } catch (Exception ex) {
            throw new PureException(PureException.DATABASE_ACCESS, strSQL, ex);
        }
    }
}

From source file:com.pureinfo.studio.db.rpms2srm.RPMSImporter.java

License:Open Source License

private void executeSQLElement(String _sName) throws Exception {
    Element ele = m_xmlConfig.element(_sName);
    if (ele == null || "false".equals(ele.attributeValue("enabled"))) {
        return;//  www  .  j  a va2s.  co  m
    }

    // else
    List eleSQLs = ele.elements("sql");
    if (eleSQLs.isEmpty())
        return;

    // else, to execute the SQLs
    String strSQL;
    ISession session = this.getSessionTo();
    for (int i = 0; i < eleSQLs.size(); i++) {
        strSQL = ((Element) eleSQLs.get(i)).getTextTrim();
        try {
            System.out.println("to execute: " + strSQL);
            IStatement statement = session.createStatement(strSQL);
            this.registerAlias(statement, ele.elements("alias"));
            statement.executeUpdate();
            statement.clear();
        } catch (Exception ex) {
            throw new PureException(PureException.DATABASE_ACCESS, strSQL, ex);
        }
    }
}