Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java

License:Open Source License

/**
 * Extracts the content of the supplied element
 * //from w  w w  .j a  va 2  s.  c  o m
 * @param element
 *            XML element
 * @return Content of the element encoded as String
 */
private static String getValue(Element element) {
    return removeInvalidXmlCharacters(element.getText());
}

From source file:com.compliance.webapp.filter.LicenseFilter.java

public Boolean resolve(HttpServletRequest hRequest) {
    Boolean fileIsExist = false;/* ww  w  . j ava 2s.  co  m*/
    try {
        String path = hRequest.getSession().getServletContext().getRealPath("/");
        File file = new File(path + "compliance.licence");
        if (file.exists()) {
            fileIsExist = true;
            FileInputStream in = null;

            in = new FileInputStream(file);
            byte[] buf = new byte[4096];
            int len = in.read(buf, 0, 4096);
            in.close();

            byte[] buffer = new byte[len];
            for (int i = 0; i < len; i++) {
                buffer[i] = buf[i];
            }

            char[] key1 = { 0x3F, 0xEE, 0x3F, 0x5A, 0xAE, 0xFA, 0x1F, 0x0A };
            char[] key2 = { 0x3D, 0xAE, 0x3A, 0x5B, 0x3F, 0x6A, 0x11, 0xAA };
            char[] key3 = { 0x0B, 0x9E, 0xDF, 0x2A, 0xAA, 0xF0, 0x7D, 0x6E };

            buffer = EncodeUtil.xorDecode(buffer, key3);

            buffer = EncodeUtil.xorDecode(buffer, key2);

            buffer = EncodeUtil.xorDecode(buffer, key1);

            // ?XML
            Document document = DocumentHelper.parseText(new String(buffer));
            Element root = document.getRootElement();
            if (root.getName().equals("reginfo")) {
                List<Element> elementsList = root.elements();
                Iterator<Element> iterator = elementsList.iterator();
                while (iterator.hasNext()) {
                    Element element = (Element) iterator.next();
                    if (element.getName().equals("name")) {
                        Serial.SERIAL_NAME = element.getText();
                    } else if (element.getName().equals("versions")) {
                        Serial.SERIAL_VERSIONS = element.getText();
                    } else if (element.getName().equals("auth_day")) {
                        Serial.SERIAL_AUTH_DAY = Integer.parseInt(element.getText());
                    } else if (element.getName().equals("gen_time")) {
                        Serial.SERIAL_GEN_TIME = Long.parseLong(element.getText());
                    } else if (element.getName().equals("resource_num")) {
                        Serial.SERIAL_RESOURCE_NUM = Integer.parseInt(element.getText());
                    } else if (element.getName().equals("sign")) {
                        Serial.SERIAL_SIGN = element.getText();
                    }
                }
            }
        }
    } catch (Exception e) {
        fileIsExist = false;
        e.printStackTrace();

    }
    return fileIsExist;
}

From source file:com.creativity.controller.CepWebService.java

@SuppressWarnings("rawtypes")
public CepWebService(String cep) {

    try {//from w ww.  j a  v a 2 s.co m
        URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml");

        Document document = getDocumento(url);

        Element root = document.getRootElement();

        for (Iterator i = root.elementIterator(); i.hasNext();) {
            Element element = (Element) i.next();

            if (element.getQualifiedName().equals("uf")) {
                setEstado(element.getText());
            }

            if (element.getQualifiedName().equals("cidade")) {
                setCidade(element.getText());
            }

            if (element.getQualifiedName().equals("bairro")) {
                setBairro(element.getText());
            }

            if (element.getQualifiedName().equals("tipo_logradouro")) {
                setTipoLogradouro(element.getText());
            }

            if (element.getQualifiedName().equals("logradouro")) {
                setLogradouro(element.getText());
            }

            if (element.getQualifiedName().equals("resultado")) {
                setResultado(Integer.parseInt(element.getText()));
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.delmar.station.service.impl.WFDetailServiceImpl.java

public String updateDcmsFcrDate(EDIResponseInfo edirInfo, String trustFileCode) {

    String resultMessage = "success";
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    String currentDate = sf.format(date);
    try {//w w  w . j  av  a2s.c o m
        date = sf.parse(edirInfo.getInDate());
        currentDate = sf.format(date);
    } catch (ParseException e1) {
        e1.printStackTrace();
    }

    try {

        EDIResponseInfo resultEDIResponseInfo = ediResponseInfoService.getEDIRByTrustFileCode(trustFileCode);

        // Booking IDCargoProDcms????bookingID
        if (StringUtil.isNotEmpty(resultEDIResponseInfo.getCsReferenceNo())) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("id", resultEDIResponseInfo.getCsReferenceNo());
            params.put("fcrDate", currentDate);
            params.put("remark", edirInfo.getResponseDesc());
            HttpClient httpClient = null;
            httpClient.getParams().setAuthenticationPreemptive(true);

            // ?
            Credentials credentials = new UsernamePasswordCredentials("wsuserchina", "ws1sGreat");
            httpClient.getState().setCredentials(AuthScope.ANY, credentials);

            HttpMethod method = buildPostMethod(
                    "https://www.delmarcargo.com/cms/api/bookingservice/updateBookingFcrDate", params);
            int statusCode = httpClient.executeMethod(method);
            if (statusCode != HttpStatus.SC_OK) {
                throw new HttpException(method.getStatusText());
            }
            String xmlResult = method.getResponseBodyAsString();
            method.releaseConnection();

            //   
            StringReader xmlReader = new StringReader(xmlResult);
            // ?SAX ? InputSource ?? XML   
            InputSource xmlSource = new InputSource(xmlReader);
            // SAXBuilder  
            SAXReader builder = new SAXReader();
            // ?SAXDocument
            Document doc = builder.read(xmlSource);
            // 
            Element root = doc.getRootElement();
            // BODY 
            Element resultStatusCode = root.element("ServiceResponse").element("statusCode");

            // ????
            if ("200".equals(resultStatusCode.getText())) {
                // add
                edirInfo.setEdiType("DCMS_FCRDATE");
                edirInfo.setEdiStatus("1");
                edirInfo.setCsReferenceNo(resultEDIResponseInfo.getCsReferenceNo());// set Booking Id
                edirInfo.setEdiAction("NEW");
                edirInfo.setEdiStatus("1");
                edirInfo.setBatchNo("0");
                edirInfo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                edirInfo.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                edirInfo.setBeUse(0);
                ediResponseInfoService.saveOrUpdate(edirInfo);

                ediResponseInfoService.updateTrustFileInfoFCRDate(currentDate, edirInfo.getTrustFileCode());
            } else if ("405".equals(resultStatusCode.getText())) {
                Element resultText = root.element("ServiceResponse").element("description");
                resultMessage = resultText.getText();

                // add
                edirInfo.setEdiType("DCMS_FCRDATE");
                edirInfo.setEdiStatus("11");
                edirInfo.setCsReferenceNo(resultEDIResponseInfo.getCsReferenceNo());// set Booking Id
                edirInfo.setEdiAction("NEW");
                edirInfo.setEdiStatus("1");
                edirInfo.setBatchNo("0");
                edirInfo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                edirInfo.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                edirInfo.setBeUse(0);
                ediResponseInfoService.saveOrUpdate(edirInfo);
            } else {
                Element resultText = root.element("ServiceResponse").element("description");
                resultMessage = resultText.getText();
            }
        } else {
            resultMessage = "Booking IDCargoProDcms?";
        }
    } catch (Exception e) {
        e.printStackTrace();
        resultMessage = "Modify Dcms Fcr Date have Exception";
        return resultMessage;
    }

    return resultMessage;
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleCounter(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKey = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<counter>", statKey, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("increase")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, value);
            }//  w  w w. ja  v  a2s.  c om
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =+", value);
        } else if (actionElementName.equals("decrease")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, -value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, -value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =-", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleFlow(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKey = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<flow>", statKey, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("increase")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, value);
            }//  ww w . j  a va 2 s. c o  m
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =+", value);
        } else if (actionElementName.equals("decrease")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKey, -value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKey, -value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count =-", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleValue(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");

    // create the corresponding template 
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    StatKey statKeyCount = new StatKey(StatPool.PREFIX_USER, "value", name, "_count");
    CounterReportTemplate template = new CounterReportTemplate("<value>", statKeyValue, statKeyCount, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("newValue")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }//  w w  w. j a v a2 s  .c o  m
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_total +=", value);
            StatPool.getInstance().addValue(statKeyCount, 1);
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_count +=", 1);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handlePercent(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    StatKey statKeyTotal = new StatKey(StatPool.PREFIX_USER, "value", name, "_total");

    // create the corresponding template
    CounterReportTemplate template = new CounterReportTemplate("<percent>", statKeyValue, statKeyTotal, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("incValue")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }/*from   www .  j av  a2 s  .co m*/
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_value =+", value);
        } else if (actionElementName.equals("incTotal")) {
            double value = Double.parseDouble(
                    (null != actionElement.attributeValue("value") ? actionElement.attributeValue("value")
                            : actionElement.getText()));
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyTotal, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyTotal, value);
            }
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_total =+", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.operations.basic.OperationStats.java

License:Open Source License

private void handleText(Runner runner, Element root) throws Exception {
    // read attributes
    String name = root.attributeValue("name");

    // create the corresponding template 
    StatKey statKeyValue = new StatKey(StatPool.PREFIX_USER, "value", name, "_value");
    CounterReportTemplate template = new CounterReportTemplate("<text>", statKeyValue, null, root);

    // read and check the attributes 
    checkStoreTemplate(new StatKey(StatPool.PREFIX_USER), template);

    // Now execute the action.
    List<Element> actionElements = (List<Element>) root.elements();
    for (Element actionElement : actionElements) {
        String actionElementName = actionElement.getName();
        if (actionElementName.equals("newValue")) {
            String value = (null != actionElement.attributeValue("value")
                    ? actionElement.attributeValue("value")
                    : actionElement.getText());
            long timestamp = getTimestamp(actionElement);
            if (-1 != timestamp) {
                StatPool.getInstance().addValue(statKeyValue, value, timestamp);
            } else {
                StatPool.getInstance().addValue(statKeyValue, value);
            }//from   w ww  . ja va2  s . c  o  m
            GlobalLogger.instance().getSessionLogger().info(runner, TextEvent.Topic.CORE, "Statistic : ", name,
                    "/_value +=", value);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.core.utils.XMLTree.java

License:Open Source License

private void listMatchingElements(Element element, String regex, boolean recurse) {
    ////  w  w w .  java2 s  . c  o m
    // First check attributes
    //
    List<Attribute> namedNodeMap = element.attributes();
    if (null != namedNodeMap) {
        for (Attribute attribute : namedNodeMap) {
            String value = attribute.getValue();
            if (Utils.containsRegex(value, regex)) {
                if (false == elementsMap.containsKey(element)) {
                    elementsMap.put(element, null);
                    elementsOrder.addFirst(element);
                }
            }
        }
    }

    //
    // Then check text
    //
    if (Utils.containsRegex(element.getText(), regex)) {
        if (false == elementsMap.containsKey(element)) {
            elementsMap.put(element, null);
            elementsOrder.addFirst(element);
        }
    }

    //
    // Finally elements
    //
    if (recurse) {
        List<Element> childrens = element.elements();
        for (Element child : childrens) {
            listMatchingElements(child, regex, recurse);
        }
    }
}