Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

From source file:com.easyjf.web.config.XMLConfigFactory.java

License:Apache License

public void initModule(Map modules) {
    Element root = findElement("modules", getRootElement());
    if (root == null)
        return;/*from   w w w.  j  a v a  2 s .  co m*/

    // ??modules
    // modulesmodule??
    // FromConfig?forms
    String injectType = "none";
    if (root.attributeValue("inject") != null)
        injectType = root.attributeValue("inject");
    List nodes = root.elements();
    for (int i = 0; i < nodes.size(); i++) {
        Element e = (Element) nodes.get(i);
        Module mc = new Module();
        // ??action
        mc.setAction(e.attributeValue("action"));
        // ?token      
        if (e.attributeValue("autoToken") != null)
            mc.setAutoToken(Boolean.valueOf(e.attributeValue("autoToken")));
        if (e.attributeValue("alias") != null) {
            mc.setAlias(e.attributeValue("alias"));
        }
        // ?
        if (e.attributeValue("defaultPage") != null)
            mc.setDefaultPage(e.attributeValue("defaultPage"));
        // ??         
        mc.setForm(e.attributeValue("form"));
        // ? /hello.ejf /hello
        mc.setPath(e.attributeValue("path"));
        // bean
        // singleton
        if (e.attributeValue("scope") != null)
            mc.setScope(e.attributeValue("scope"));
        if (e.attributeValue("method") != null)
            mc.setMethod(e.attributeValue("method"));
        if (e.attributeValue("inject") != null)
            mc.setInject(e.attributeValue("inject"));
        else
            mc.setInject(injectType);
        if (e.attributeValue("views") != null)
            mc.setViews(e.attributeValue("views"));
        if (e.attributeValue("view") != null)
            mc.setViews(e.attributeValue("view"));
        if (e.attributeValue("validate") != null)
            mc.setValidate(Boolean.parseBoolean(e.attributeValue("validate")));
        if (e.attributeValue("messageResource") != null) {
            mc.setMessageResource(e.attributeValue("messageResource"));
        }
        List lPage = findElements("page", e);
        for (int j = 0; j < lPage.size(); j++) {
            Element p = (Element) lPage.get(j);
            Page page = new Page();
            // Page?? modulePage??
            page.setName(p.attributeValue("name"));
            if (mc.getDefaultPage() == null || mc.getDefaultPage().equals("")) {
                mc.setDefaultPage(page.getName());
            }
            // Page html/template
            // ?,html
            page.setType(p.attributeValue("type"));
            // Pageurl,
            page.setUrl(p.attributeValue("url"));
            if (p.attributeValue("contentType") != null)
                page.setContentType(p.attributeValue("contentType"));
            // pages.put(page.getName(), page);
            mc.getPages().put(page.getName(), page);
        }
        // ,??
        List interceptors = findElements("interceptor", e);
        for (int j = 0; j < interceptors.size(); j++) {
            Element p = (Element) interceptors.get(j);
            String interceptorClazz = p.attributeValue("class");
            try {
                mc.getInterceptors().add(Class.forName(interceptorClazz).newInstance());
            } catch (Exception ex) {
            }
        }
        // ?modulepropertyproperty
        mc.setPropertyValues(BeanConfigReader.parsePropertyValues(findElements("property", e)));
        modules.put(mc.getPath(), mc);

    }
}

From source file:com.easyjf.web.config.XMLConfigFactory.java

License:Apache License

public void initPage(Map pages) {
    Element root = findElement("pages", getRootElement());
    if (root == null)
        return;//from ww w. j  a  va2 s  .  c  o  m
    List nodes = root.elements();
    for (int i = 0; i < nodes.size(); i++) {
        Element e = (Element) nodes.get(i);
        Page page = new Page();
        page.setName(e.attributeValue("name"));
        page.setType(e.attributeValue("type"));
        page.setUrl(e.attributeValue("url"));
        if (e.attributeValue("contentType") != null)
            page.setContentType(e.attributeValue("contentType"));
        pages.put(page.getName(), page);
    }
}

From source file:com.easyjf.web.config.XMLConfigFactory.java

License:Apache License

public Map initOther() {
    if (doc == null)
        return null;
    Map result = new HashMap();
    Element root = findElement("framework-setting", getRootElement());
    if (root == null) {
        root = findElement("frame-setting", getRootElement());
    }//from   w ww  . ja va  2s.co m
    if (root != null) {
        // 
        Element node = findElement("template-base", root);
        if (node != null)
            result.put("TemplateBasePath", node.getText());
        // ???
        node = findElement("init-app", root);
        List appList = findElements("app-class", node);
        List applist = new ArrayList();
        for (int i = 0; i < appList.size(); i++) {
            Element e = (Element) appList.get(i);
            Map app = new HashMap();
            app.put("init-method", e.attributeValue("init-method"));
            app.put("destroy-method", e.attributeValue("destroy-method"));
            app.put("class", e.getText());
            applist.add(app);
        }
        result.put("initApp", applist);

        // ?
        node = findElement("interceptors", root);
        List interceptors = findElements("app-class", node);
        List appinterceptorslist = new ArrayList();
        if (interceptors != null) {
            for (int i = 0; i < interceptors.size(); i++) {
                Element e = (Element) interceptors.get(i);
                Map app = new HashMap();
                app.put("name", e.attributeValue("name"));
                app.put("method", e.attributeValue("method"));
                app.put("class", e.getText());
                appinterceptorslist.add(app);
            }
        }
        result.put("interceptors", appinterceptorslist);

        // ???
        node = findElement("error-handler", root);
        List errorHandlers = findElements("app-class", node);
        if (errorHandlers != null) {
            for (int i = 0; i < errorHandlers.size(); i++) {
                Element e = (Element) errorHandlers.get(i);
                Map app = new HashMap();
                app.put("exception", e.attributeValue("exception"));
                app.put("path", e.attributeValue("path"));
                app.put("class", e.getText());
                errorHandlers.set(i, app);
            }
        }
        result.put("errorHandlers", errorHandlers);
        // ????   
        List list = findElements("property", root);
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                Element el = (Element) list.get(i);
                result.put(el.attributeValue("name"), el.getText());
            }
        }
    }
    List importResources = new java.util.ArrayList();
    List list = findElements("import", getRootElement());
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            Element el = (Element) list.get(i);
            String resource = el.attributeValue("resource");
            if (resource != null && !"".equals(resource)) {
                //?/WEB-INFclasspath
                if (resource.toLowerCase().indexOf("web-inf") < 0 && resource.indexOf("classpath") != 0)
                    resource = "/WEB-INF/" + resource;
                importResources.add(resource);
            }
        }
    }
    result.put("importResources", importResources);
    // EasyJWebBean??bean beanDefinitions
    result.put("beanDefinitions", BeanConfigReader.parseBeansFromDocument(doc));
    return result;
}

From source file:com.edo.dolphin.service.impl.DolphinServiceImpl.java

@Override
public DolphinResult queryZrrKxHonest(Integer operatorID, String name, String idNumber, String mobile) {
    DolphinResult result = new DolphinResult();

    try {/*from  w w  w  .ja  v  a2s . c om*/
        String data = DolphinAPIUtil.execute(name, idNumber, mobile);

        Document document = DocumentHelper.parseText(data);
        Element root = document.getRootElement();
        result.setName(root.attributeValue("name"));
        result.setIdNumber(root.attributeValue("zjhm"));
        result.setSearchNo(root.attributeValue("cxbh"));

        Element resultElement = root.element("RESULT");
        result.setResult(resultElement.getText());

        if (!result.getResult().equals("1005")) {
            return result;
        }

        @SuppressWarnings("unchecked")
        List<Element> resourceList = root.elements("RESOURCE");
        for (Element element : resourceList) {
            String resources = element.attributeValue("RESOURCES");
            Resource resource = null;
            switch (resources) {
            case "GRZX130000005":
                // ??:GRZX130000005
                resource = new SocialResource();

                SocialResource socialResource = (SocialResource) resource;

                // ??:SHBXDJM
                socialResource.setRegisterCode(element.elementText("SHBXDJM"));
                // ????:DWMC
                socialResource.setCompanyName(element.elementText("DWMC"));
                // ??:JNSHBXJZTHZ
                socialResource.setSocialPayStatus(element.elementText("JNSHBXJZTHZ"));
                // ???:LQYLJZTHZ
                socialResource.setSocialGetStatus(element.elementText("LQYLJZTHZ"));
                // :JDWRQ
                socialResource.setSocialStartTime(element.elementText("JDWRQ"));
                // :ZXGXSJ
                socialResource.setSocialUpdateTime(element.elementText("ZXGXSJ"));

                processStaffData(socialResource, idNumber, operatorID);
                processStaffExpData(socialResource, idNumber, operatorID);
                break;
            case "XY0700050207030001":
                // ?:XY0700050207030001
                resource = new HouseFundResource();
                HouseFundResource houseFundResource = (HouseFundResource) resource;

                // ??:A3
                houseFundResource.setAccountStatus(element.elementText("A3"));
                // ????:A4
                houseFundResource.setAccountCompanyName(element.elementText("A4"));
                // :A5
                houseFundResource.setAccountCreateTime(element.elementText("A5"));

                break;
            case "GRZX100000007":
            case "GRZX100000008":
                // ?:GRZX100000007
                // ?:GRZX100000008
                resource = new MarryResource();
                resource.setResourceCode(resources);
                MarryResource marryResource = (MarryResource) resource;

                // :DJJG
                marryResource.setRegisterOrg(element.elementText("DJJG"));
                // :DJRQ
                marryResource.setRegisterDate(element.elementText("DJRQ"));
                // ??:ZSBH
                marryResource.setRegisterNumber(element.elementText("ZSBH"));
                // ????:POXM
                marryResource.setMateName(element.elementText("POXM"));

                processRegisterData(marryResource, idNumber, operatorID);
                break;
            case "GRZX080000032":
                // ??:GRZX080000032
                resource = new IllegalResource();
                IllegalResource illegalResource = (IllegalResource) resource;
                // ??
                illegalResource.setHasSwindling(element.elementText("SFYZPLAJWFJL"));
                // ??
                illegalResource.setHasTheft(element.elementText("SFYDQLAJWFJL"));
                // ??
                illegalResource.setHasTrick(element.elementText("SFYZYZPLAJWFJL"));
                // ?????
                illegalResource.setHasCounterfeit(element.elementText("SFYWZBZMMGWZJLAJWFJL"));
                break;
            case "GRZX080000040":
                // ?:GRZX080000040
                resource = new VehicleResource();
                VehicleResource vehicleResource = (VehicleResource) resource;

                // ??:HPZL
                vehicleResource.setLicenseType(element.elementText("HPZL"));
                // ???:HPHM
                vehicleResource.setLicenseNumber(element.elementText("HPHM"));
                // ?:CCDJRQ
                vehicleResource.setRegisterTime(element.elementText("CCDJRQ"));
                // :YXQZ
                vehicleResource.setInspectionValidityDate(element.elementText("YXQZ"));
                // :DJRQ
                vehicleResource.setInspectionDate(element.elementText("DJRQ"));
                // :QZBFQZ
                vehicleResource.setRetirementDate(element.elementText("QZBFQZ"));
                // ?:BXZZRQ
                vehicleResource.setRepairDate(element.elementText("BXZZRQ"));
                // ?:XZQH
                vehicleResource.setRegisterArea(element.elementText("XZQH"));
                // ?:ZTHZ
                vehicleResource.setStatus(element.elementText("ZTHZ"));
                // ?:DYBJHZ
                vehicleResource.setIsMortgage(element.elementText("DYBJHZ"));

                processVehicleData(vehicleResource, idNumber, operatorID);
                break;
            case "GRZX080000039":
            case "GRZX080000038":
                // ?:GRZX080000039
                // ?:GRZX080000038
                resource = new DriverResource();

                DriverResource driverResource = (DriverResource) resource;
                // ??WFMS
                driverResource.setIllegalType(element.elementText("WFMS"));
                // ?:JDSBH
                driverResource.setIllegalNumber(element.elementText("JDSBH"));
                // ?:WFSJ
                driverResource.setIllegalTime(element.elementText("WFSJ"));
                // ??:WFDZ
                driverResource.setIllegalAddress(element.elementText("WFDZ"));
                // ?:CLSJ
                driverResource.setIllegalProcessTime(element.elementText("CLSJ"));
                break;
            }

            if (resource != null) {

                // RESOURCES:??
                resource.setResourceCode(resources);

                // RESOURCENAME:???
                resource.setResourceName(element.attributeValue("RESOURCENAME"));
                // XXSSDWDM:????
                resource.setUnitCode(element.attributeValue("XXSSDWDM"));
                // XXSSDW:???
                resource.setUnitName(element.attributeValue("XXSSDW"));
                // XXLB:?
                resource.setCategory(element.attributeValue("XXLB"));

                result.getResources().add(resource);
            }
        }

    } catch (Exception e) {
        logger.fatal(e);
    }

    return result;
}

From source file:com.fivepebbles.Backup.java

License:MIT License

public void processBackup() {

    //Retrieve Bucket Names and related files/folders from XML saved locally

    Document myDocument = null;//w  ww  .  j a v  a2s .c o m

    try {
        URL myURL = new File("target", "s3files.xml").toURI().toURL();
        SAXReader myReader = new SAXReader();
        myDocument = myReader.read(myURL);
    } catch (MalformedURLException | DocumentException e) {
        //***TODO*** log Msg
        e.printStackTrace();
    }

    Element root = myDocument.getRootElement();

    for (Iterator<Element> i1 = root.elementIterator(); i1.hasNext();) {
        Element bucketelem = i1.next();

        if (bucketelem.getName() == "bucket") {
            bucketnm = bucketelem.attributeValue("name");

            for (Iterator<Element> i2 = bucketelem.elementIterator(); i2.hasNext();) {
                Element fileelem = i2.next();

                if (fileelem.getName() == "file") {
                    bfile = fileelem.getText();

                    //Get list of files (bfile could be a folder name)
                    ProcessFiles p1 = new ProcessFiles();
                    filelist = p1.getFiles(bfile);

                    //Append files to arraylist
                    if (filelist != null) {
                        totalfilelist.addAll(filelist);
                    }
                }
            }

            //Make the data good for S3
            //Replace "\" with "/" for Windows

            for (int j = 0; j < totalfilelist.size(); j++) {

                if (totalfilelist.get(j).contains("\\")) {
                    newfilelist.add(totalfilelist.get(j).replace("\\", "/"));
                } else {
                    newfilelist.add(totalfilelist.get(j));
                }
            }

            //Remove Driveletter from files/object list if present (Windows)
            for (int k = 0; k < newfilelist.size(); k++) {
                if (newfilelist.get(k).contains("C:")) {
                    newfilelist2.add(newfilelist.get(k).replace("C:", ""));
                } else {
                    newfilelist2.add(newfilelist.get(k));
                }
            }

            //Get S3 key list corresponding to the files 
            //This is obtained by removing the "/" in index 0 from the file list since AWS key should not have a / at position 0

            for (int m = 0; m < newfilelist2.size(); m++) {
                keylist.add(newfilelist2.get(m).substring(1));
            }

            //Backup files in S3 (for this bucket)

            //Get AWS Credentials
            String[] awskeys = new S3Credentials().getCredentials();

            //Set AWS credentials
            ProcessAWS pr1 = new ProcessAWS(awskeys[0], awskeys[1]);

            //Check if Bucket exists in S3
            if (pr1.checkBucket(bucketnm)) {

                //Put Objects in S3
                //keylist contains S3 keys and newfilelist2 contains the files
                for (int l = 0; l < newfilelist2.size(); l++) {
                    boolean r1 = pr1.putAWSObject(keylist.get(l), new File(newfilelist2.get(l)), bucketnm);

                    if (!r1) {
                        //***TODO*** Log message
                    }
                }
            } else {
                //Create Bucket in S3
                boolean r2 = pr1.createBucket(bucketnm);

                if (r2) {
                    //Put Objects in S3
                    //keylist contains S3 keys and newfilelist2 contains the files
                    for (int m = 0; m < newfilelist2.size(); m++) {
                        boolean r3 = pr1.putAWSObject(keylist.get(m), new File(newfilelist2.get(m)), bucketnm);

                        if (!r3) {
                            //***TODO*** Log message
                        }
                    }

                } else {
                    //***TODO*** Log message
                }
            }

        }

        //Clear arrays for the next bucket
        totalfilelist.clear();
        newfilelist.clear();
        newfilelist2.clear();
        keylist.clear();

    }

}

From source file:com.flaptor.hounder.indexer.CommandsModule.java

License:Apache License

/**
 * @param doc a non null document to process
 *//*w w  w  . j  a  v a 2  s .c o  m*/
public Document[] internalProcess(final Document doc) {
    Element root = doc.getRootElement();
    if (null != root && root.getName().equals("command")) {
        String name = root.attributeValue("name");
        if (null == name) {
            logger.error("Invalid command: no name set. Ignoring it.");
        } else {
            if (name.equals("optimize")) {
                optimize();
            } else if (name.equals("close")) {
                close();
            } else if (name.equals("checkpoint")) {
                checkpoint();
            } else {
                logger.error("Unknown command received. Ignoring it.");
            }
        }
        Document[] docs = {};
        return docs;
    } else {
        Document[] docs = { doc };
        return docs;
    }
}

From source file:com.flaptor.util.DomUtil.java

License:Apache License

/**
 * Returns the first attribute's value of the first ocurrence of an element.
 * @param root the root element of the dom
 * @param elementName the name of the element
 * @param attribName the name of the attribute
 * @return the value of the first element, or null if not found.
 * The first matching element is considered only.
 *//*w  ww  .  j  a v a2s. co m*/
public static String getAttributeValue(final Element root, final String elementName, final String attribName) {
    String value = null;
    Element element;
    Iterator elementIterator = root.elementIterator(elementName);
    while (elementIterator.hasNext()) {
        element = (Element) elementIterator.next();
        value = element.attributeValue(attribName);
    }
    return value;
}

From source file:com.flaptor.util.DomUtil.java

License:Apache License

/**
 * Returns the first attribute's value of the first ocurrence of an element.
 * @param root the root element of the dom
 * @param elementName the name of the element
 * @param attribName the name of the attribute
 * @return the value of the first element, or null if not found.
 * The first matching element is considered only.
 *//*from   w  w w.j  av  a 2s .com*/
public static void replaceElementValueByName(final Element root, final String elementName, final String name,
        final String value) {
    Element element;
    Iterator elementIterator = root.elementIterator(elementName);
    while (elementIterator.hasNext()) {
        element = (Element) elementIterator.next();
        if (name.equals(element.attributeValue("name"))) {
            element.setText(DomUtil.filterXml(value));
            break;
        }
    }
}

From source file:com.footprint.server.common.config.ConfigHelper.java

License:Open Source License

public static Map<String, LogNode> getLogConfigs() {
    List<Element> elements = getDocument().selectNodes("/config//log");
    Map<String, LogNode> logConfigs = new HashMap<String, LogNode>();
    for (Element element : elements) {
        String name = element.attributeValue("name");
        String url = element.attributeValue("url");
        LogNode logConfig = new LogNode();
        logConfig.setUrl(url);/*from  w  w w.ja  va2s.co  m*/
        logConfig.setName(name);
        logConfigs.put(url, logConfig);
    }
    return logConfigs;
}

From source file:com.footprint.server.common.config.ConfigHelper.java

License:Open Source License

public static Set<String> getAllPerms() {
    List<Element> elements = getDocument().selectNodes("/config//perm");
    Set<String> set = new HashSet<String>();
    for (Element element : elements) {
        String url = element.attributeValue("url");
        set.add(url);/*from  ww  w. j av a  2s .co  m*/
    }
    return set;
}