Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

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

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java

License:Mozilla Public License

private SurveyObjective constructObjective(Element objectiveElement) {
    SurveyObjective objective = new SurveyObjective();
    objective.setDescription(objectiveElement.elementText("description"));
    objective.setLevelNumber(Integer.parseInt(objectiveElement.attributeValue("level")));

    for (Object questionElement : objectiveElement.elements("question")) {
        objective.getSurveyQuestions().add(constructQuestion((Element) questionElement));
    }/*from w  ww  . ja v a 2  s. com*/

    for (SurveyQuestion question : objective.getSurveyQuestions()) {
        question.setSurveyObjective(objective);
    }

    return objective;
}

From source file:com.digiaplus.modules.scorm.ScormCPManifestTreeModel.java

License:Apache License

private GenericTreeNode buildNode(Element item) {
    GenericTreeNode treeNode = new GenericTreeNode();

    // extract title
    String title = item.elementText("title");
    if (title == null)
        title = item.attributeValue("identifier");
    treeNode.setAltText(title);//  w  w w.  j a  v a 2s  . com
    treeNode.setTitle(title);

    if (item.getName().equals("organization")) {
        treeNode.setIconCssClass("o_scorm_org");
        treeNode.setAccessible(false);
    } else if (item.getName().equals("item")) {
        scormIdToNode.put(new Integer(nodeId).toString(), treeNode);
        nodeToId.put(treeNode, new Integer(nodeId));

        //set node images according to scorm sco status
        String itemStatusDesc = (String) itemStatus.get(Integer.toString(nodeId));
        treeNode.setIconCssClass("o_scorm_item");
        if (itemStatusDesc != null) {
            // add icon decorator for current status
            treeNode.setIconDecorator1CssClass("o_scorm_" + itemStatusDesc);
        }

        nodeId++;
        //set resolved file path directly
        String identifierref = item.attributeValue("identifierref");
        XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']");
        meta.setNamespaceURIs(nsuris);
        String href = (String) resources.get(identifierref);
        if (href != null) {
            treeNode.setUserObject(href);
            // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text
            hrefToTreeNode.put(href, treeNode);
        } else
            treeNode.setAccessible(false);
    }

    List chds = item.elements("item");
    int childcnt = chds.size();
    for (int i = 0; i < childcnt; i++) {
        Element childitem = (Element) chds.get(i);
        GenericTreeNode gtnchild = buildNode(childitem);
        treeNode.addChild(gtnchild);
    }
    return treeNode;
}

From source file:com.doculibre.constellio.opensearch.OpenSearchSolrServer.java

License:Open Source License

@SuppressWarnings("unchecked")
private static SolrDocumentList parse(Element rootElement) throws IOException {
    SolrDocumentList solrDocumentList = new SolrDocumentList();
    Element channelElement = rootElement.element("channel");
    String totalResultsStr = channelElement.elementText(new QName("totalResults", NS_OPENSEARCH));
    String startIndexStr = channelElement.elementText(new QName("startIndex", NS_OPENSEARCH));
    long numFound = Long.parseLong(totalResultsStr);
    long start = Long.parseLong(startIndexStr);
    solrDocumentList.setNumFound(numFound);
    solrDocumentList.setStart(start);/*  ww  w .  j a  va  2 s . c o m*/

    for (Iterator<Element> it = channelElement.elementIterator("item"); it.hasNext();) {
        Element itemElement = it.next();
        String title = itemElement.elementText("title");
        String description = itemElement.elementText("description");
        String link = itemElement.elementText("link");

        title = CharSetUtils.convert(title, CharSetUtils.UTF_8, CharSetUtils.ISO_8859_1);
        description = CharSetUtils.convert(description, CharSetUtils.UTF_8, CharSetUtils.ISO_8859_1);
        link = CharSetUtils.convert(link, CharSetUtils.UTF_8, CharSetUtils.ISO_8859_1);

        SolrDocument solrDocument = new SolrDocument();
        solrDocument.addField("title", title);
        solrDocument.addField("description", description);
        solrDocument.addField("link", link);
        solrDocumentList.add(solrDocument);
    }
    return solrDocumentList;
}

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  ww.ja va  2s  .com*/
        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.feilong.framework.netpay.advance.adaptor.alipay.AlipayAdvanceAdaptor.java

License:Apache License

/**
 * ??xml?.//  ww  w  .ja v  a 2 s . c om
 *
 * @author xialong
 * @param alipayResult
 *            the alipay result
 * @return the map
 * @throws DocumentException
 *             the document exception
 */
private static Map<String, String> convertResultToMap(String alipayResult) throws DocumentException {
    log.info("alipayResult :\n {}", alipayResult);

    Map<String, String> map = new HashMap<String, String>();
    SAXReader reader = new SAXReader();
    Document document = reader.read(new InputSource(new StringReader(alipayResult)));
    Element root = document.getRootElement();

    String is_success = root.elementText("is_success");
    String error = root.elementText("error");
    log.info("is_success : {}", is_success);
    log.info("error : {}", error);

    map.put("is_success", is_success);
    map.put("error", error);

    return map;
}

From source file:com.feilong.framework.netpay.payment.adaptor.alipay.wap.AlipayWapAdaptor.java

License:Apache License

/**
 * ?keyxml.// w ww. ja v a  2s .  c om
 * 
 * @param xmlData
 *            the xml data
 * @param name
 *            the name
 * @return String
 * @throws DocumentException
 *             the document exception
 * @author 
 * @time 2013-9-16?10:16:39
 */
private String getValueByKeyForXML(String xmlData, String name) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(new InputSource(new StringReader(xmlData)));
    Element root = document.getRootElement();
    String value = root.elementText(name);
    return value;
}

From source file:com.gi.desktop.maptool.dialog.MapServiceConfDialog.java

License:Open Source License

@SuppressWarnings("unchecked")
private void loadAgsSchema() {
    JFileChooser dialog = getJFileChooserAgsSchema();
    int val = dialog.showOpenDialog(this);
    if (val == JFileChooser.APPROVE_OPTION) {
        File agsSchema = dialog.getSelectedFile();
        try {//from w ww .j  a  v a 2s.  c om
            FileInputStream in = new FileInputStream(agsSchema);
            SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(in);
            Element root = document.getRootElement();
            Element eTileCacheInfo = root.element("TileCacheInfo");

            Element eTileOrigin = eTileCacheInfo.element("TileOrigin");
            this.jTextFieldOriginX.setText(eTileOrigin.elementText("X"));
            this.jTextFieldOriginY.setText(eTileOrigin.elementText("Y"));

            this.jTextFieldWidth.setText(eTileCacheInfo.elementText("TileCols"));
            this.jTextFieldHeight.setText(eTileCacheInfo.elementText("TileRows"));

            jListLevelsModel.removeAllElements();
            Element eLODInfos = eTileCacheInfo.element("LODInfos");
            for (Iterator iLODInfos = eLODInfos.elementIterator(); iLODInfos.hasNext();) {
                Element eLODInfo = (Element) iLODInfos.next();
                TileLodInfo tileLodInfo = new TileLodInfo();
                tileLodInfo.setLevel(Integer.valueOf(eLODInfo.elementText("LevelID")));
                tileLodInfo.setScale(Double.valueOf(eLODInfo.elementText("Scale")));
                tileLodInfo.setResolution(Double.valueOf(eLODInfo.elementText("Resolution")));

                LodItem item = new LodItem();
                item.setTileLodInfo(tileLodInfo);
                jListLevelsModel.addElement(item);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Load Error!");
        }
    }
}

From source file:com.glaf.activiti.extension.xml.ExtensionReader.java

License:Apache License

public List<ExtensionEntity> readTasks(java.io.InputStream inputStream) {
    List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>();
    SAXReader xmlReader = new SAXReader();
    try {/*  w w  w. j  a va 2s .  c o m*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String x_type = root.attributeValue("type");
        List<?> rows = root.elements("taskmgr");
        Iterator<?> iterator = rows.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            ExtensionEntity extension = new ExtensionEntity();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setType(x_type);
            if (element.elementTextTrim("taskMgmtType") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("taskMgmtType");
                extensionField.setValue(element.elementTextTrim("taskMgmtType"));
                extension.addField(extensionField);
            }
            Element propertiesE = element.element("properties");
            if (propertiesE != null) {
                List<?> properties = propertiesE.elements("property");
                Iterator<?> iter = properties.iterator();
                while (iter.hasNext()) {
                    Element elem = (Element) iter.next();
                    String propertyName = elem.attributeValue("key");
                    String propertyValue = null;
                    if (elem.attribute("value") != null) {
                        propertyValue = elem.attributeValue("value");
                    } else {
                        propertyValue = elem.getTextTrim();
                    }
                    if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                        ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                        extensionField.setName(propertyName.trim());
                        extensionField.setValue(propertyValue.trim());
                        extension.addField(extensionField);
                    }
                }
            }
            if (element.elementText("handlers") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("handlers");
                extensionField.setValue(element.elementTextTrim("handlers"));
                extension.addField(extensionField);
            }
            extensions.add(extension);
        }

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return extensions;
}

From source file:com.glaf.activiti.extension.xml.ExtensionReader.java

License:Apache License

public List<ExtensionEntity> readActions(java.io.InputStream inputStream) {
    List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>();
    SAXReader xmlReader = new SAXReader();
    try {/*  w w w.  j av  a2s .com*/
        Document doc = xmlReader.read(inputStream);
        Element root = doc.getRootElement();
        String x_type = root.attributeValue("type");
        List<?> actions = root.elements("action");
        Iterator<?> iter = actions.iterator();
        while (iter.hasNext()) {
            Element element = (Element) iter.next();
            ExtensionEntity extension = new ExtensionEntity();
            extension.setProcessName(element.attributeValue("processName"));
            extension.setTaskName(element.attributeValue("taskName"));
            extension.setName(element.attributeValue("name"));
            extension.setType(x_type);
            extension.setDescription(element.elementTextTrim("description"));
            Iterator<?> it99 = element.elementIterator();
            while (it99.hasNext()) {
                Element elem = (Element) it99.next();
                String propertyName = elem.getName();
                String propertyValue = elem.getTextTrim();
                if (StringUtils.isNotEmpty(propertyValue)) {
                    ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                    extensionField.setName(propertyName.trim());
                    extensionField.setValue(propertyValue.trim());
                    extension.addField(extensionField);
                }
            }
            if (element.elementText("sql") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("sql");
                extensionField.setValue(element.elementTextTrim("sql"));
                extension.addField(extensionField);

            }
            if (element.elementText("handlers") != null) {
                ExtensionFieldEntity extensionField = new ExtensionFieldEntity();
                extensionField.setName("handlers");
                extensionField.setValue(element.elementTextTrim("handlers"));
                extension.addField(extensionField);
            }

            Element parametersE = element.element("parameters");
            if (parametersE != null) {
                List<?> parameters = parametersE.elements("parameter");
                Iterator<?> it = parameters.iterator();
                while (it.hasNext()) {
                    Element elem = (Element) it.next();
                    String propertyName = elem.attributeValue("name");
                    String type = elem.attributeValue("type");
                    String propertyValue = null;
                    if (elem.attribute("value") != null) {
                        propertyValue = elem.attributeValue("value");
                    } else {
                        propertyValue = elem.getTextTrim();
                    }
                    if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) {
                        ExtensionParamEntity extensionParam = new ExtensionParamEntity();
                        extensionParam.setName(propertyName.trim());
                        extensionParam.setValue(propertyValue.trim());
                        extensionParam.setType(type);
                        extension.addParam(extensionParam);
                    }
                }
            }

            extensions.add(extension);
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return extensions;
}

From source file:com.glaf.core.xml.XmlBuilder.java

License:Apache License

public void processElement(String systemName, Element root, Map<String, Object> params) {
    /**//from  w  ww.jav  a  2s  . co m
     * ??
     */
    Map<String, DatasetModel> dataSetMap = new HashMap<String, DatasetModel>();
    List<?> elements = root.elements("DataSet");
    Iterator<?> iterator = elements.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        String id = element.attributeValue("id");
        String sql = element.attributeValue("sql");
        String queryId = element.attributeValue("queryId");
        String title = element.attributeValue("title");
        String single = element.attributeValue("single");
        String splits = element.attributeValue("splits");
        String foreachPerRow = element.attributeValue("foreachPerRow");
        if (sql == null) {
            sql = element.elementText("sql");
        }

        DatasetModel dsm = new DatasetModel();
        dsm.setId(id);
        dsm.setSql(sql);
        dsm.setQueryId(queryId);
        dsm.setTitle(title);
        if (StringUtils.equalsIgnoreCase(single, "true")) {
            dsm.setSingle(true);
        }

        if (StringUtils.equalsIgnoreCase(foreachPerRow, "true")) {
            dsm.setForeachPerRow(true);
        }

        if (StringUtils.isNotEmpty(splits)) {
            dsm.setSplitList(StringTools.split(splits));
        }

        List<?> attrs = element.attributes();
        if (attrs != null && !attrs.isEmpty()) {
            Iterator<?> iter = attrs.iterator();
            while (iter.hasNext()) {
                Attribute attr = (Attribute) iter.next();
                dsm.addAttribute(attr.getName(), attr.getStringValue());
            }
        }

        List<?> providers = element.elements("FieldConverter");
        if (providers != null && !providers.isEmpty()) {
            Iterator<?> iter = providers.iterator();
            while (iter.hasNext()) {
                Element elem = (Element) iter.next();
                String fromName = elem.attributeValue("fromName");
                String toName = elem.attributeValue("toName");
                String provider = elem.attributeValue("provider");
                FieldController c = new FieldController();
                c.setFromName(fromName);
                c.setToName(toName);
                c.setProvider(provider);
                dsm.addController(c);
            }
        }
        dataSetMap.put(dsm.getId(), dsm);
    }

    elements = root.elements();
    iterator = elements.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        if (StringUtils.equals(element.getName(), "DataSet")) {
            continue;
        }
        this.processNode(element, dataSetMap, systemName, params);
    }

    elements = root.elements("DataSet");
    iterator = elements.iterator();
    while (iterator.hasNext()) {
        Element element = (Element) iterator.next();
        root.remove(element);
    }
}