Example usage for org.dom4j DocumentHelper parseText

List of usage examples for org.dom4j DocumentHelper parseText

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper parseText.

Prototype

public static Document parseText(String text) throws DocumentException 

Source Link

Document

parseText parses the given text as an XML document and returns the newly created Document.

Usage

From source file:com.daoke.mobileserver.carinsurance.controller.CarInsuranceController.java

/**
 * /* ww  w  . j  av  a2 s.  c om*/
 * 
 * @param car
 * @return
 */
@ResponseBody
@RequestMapping("/queryCarType")
public String queryCarType(Car car) {
    String result = null;
    Document doc = null;
    try {
        String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>" + "<PackageList>" + "<Package>" + "<Header>"
                + "<version>2</version>" + "<ordertype>3</ordertype>" + "<username>" + car.getUsername()
                + "</username>" + "<password>" + car.getPassword() + "</password>" + "</Header>" + "<Request>"
                + "<AreaInfo>" + "<companyno>" + car.getCompanyno() + "</companyno>" + "<citycode>"
                + car.getCitycode() + "</citycode>" + "</AreaInfo>" + "<CarmoduleInfo>" + "<callback>"
                + car.getCallback() + "</callback>" + "</CarmoduleInfo>" + "<VehicleInfo>" + "<licenseno>"
                + car.getLicenseno() + "</licenseno>" + "<nolicenseflag>" + car.isNolicenseflag()
                + "</nolicenseflag>" + "<ownername>" + car.getOwnername() + "</ownername>" + "</VehicleInfo>"
                + "</Request>" + "</Package>" + "</PackageList>";
        result = carInsuranceService.queryCarType(xml, carApi);
        doc = DocumentHelper.parseText(result);
        Element rootElement = doc.getRootElement();
        Element element = rootElement.element("Package");
        Element header = element.element("Header");
        String statuscode = header.elementTextTrim("statuscode");
        if (("0").equals(statuscode)) {
            Element response = element.element("Response");
            Element carmoduleInfo = response.element("CarmoduleInfo");
            String page = carmoduleInfo.elementTextTrim("page");
        } else {
            String message = header.elementTextTrim("message");
        }
        logger.info(result);
    } catch (Exception e) {
        result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                ConstantsUtil.RESULT_SERVICE_ERROR);
        logger.error(JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
    }
    return result;
}

From source file:com.daoke.mobileserver.carinsurance.controller.CarInsuranceController.java

/**
 * ?????//from  w w  w .j a  v a  2s  . c o m
 * 
 * @param elementInsurance
 * @return
 */
@ResponseBody
@RequestMapping("/getElementAndInsurance")
public String getElementAndInsurance(ElementInsurance elementInsurance) {
    String result = null;
    Document doc = null;
    try {
        String type = elementInsurance.getSubType();
        if (StringUtils.isNotEmpty(type)) {
            type = "<TagsCarSubjList>" + "<Tag>" + "<Definition name=\"type\">" + elementInsurance.getSubType()
                    + "</ Definition>" + "<Definition name=\"key\">" + elementInsurance.getSubKey()
                    + "</ Definition>" + "<Definition name=\"label\">" + elementInsurance.getSubLabel()
                    + "</Definition>" + "<Definition name=\"value\"/>" + "<Definition name=\"premium\"/>"
                    + "<Definition name=\"disable\"/>"
                    + "<Definition name=\"data\"> <![CDATA:1;?: 0]]> </ Definition>" + "</Tag>"
                    + "</TagsCarSubjList>" + "<TagsCarRiskList>" + "<Tag>" + "<Definition name=\"type\">"
                    + elementInsurance.getRiskType() + "</Definition>" + "<Definition name=\"key\">"
                    + elementInsurance.getRiskKey() + "</Definition>" + "<Definition name=\"label\">"
                    + elementInsurance.getRiskLabel() + "</Definition>" + "<Definition name=\"value\">"
                    + elementInsurance.getRiskValue() + "</Definition>" + "<Definition name=\"premium\">"
                    + elementInsurance.getRiskPremium() + "</Definition>" + "<Definition name=\"disable\"/>"
                    + "<Definition name=\"data\"><![CDATA[?:1]]></Definition>" + "</Tag>"
                    + "</TagsCarRiskList>";
        } else {
            type = "";
        }
        String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>" + "<PackageList>" + "<Package>" + "<Header>"
                + "<version>2</version>" + "<ordertype>3</ordertype>" + "<username>"
                + elementInsurance.getUsername() + "</username>" + "<password>" + elementInsurance.getPassword()
                + "</password>" + "</Header>" + "<Request>" + "<AreaInfo>" + "<companyno>"
                + elementInsurance.getCompanyno() + "</companyno>" + "<citycode>"
                + elementInsurance.getCitycode() + "</citycode>" + "</AreaInfo>" + "<PlcInfo>"
                + "<plcstartdate>" + elementInsurance.getPlcstartdate() + "</plcstartdate>" + "<plcenddate>"
                + elementInsurance.getPlcenddate() + "</plcenddate>" + "</PlcInfo>" + "<VehicleInfo>"
                + "<licenseno>" + elementInsurance.getLicenseno() + "</licenseno>" + "<nolicenseflag>"
                + elementInsurance.isNolicenseflag() + "</nolicenseflag>" + "<ownername>"
                + elementInsurance.getOwnername() + "</ownername>" + "<ownercerttype>"
                + elementInsurance.getOwnercerttype() + "</ownercerttype>" + "<ownercertno>"
                + elementInsurance.getOwnercertno() + "</ownercertno>" + "</VehicleInfo>" + "<InsurInfo>"
                + "<name>" + elementInsurance.getName() + "</name>" + "</InsurInfo>" + type + "</Request>"
                + "</Package>" + "</PackageList>";
        result = carInsuranceService.getElementAndInsurance(xml, carApi);
        doc = DocumentHelper.parseText(result);
        Element rootElement = doc.getRootElement();
        Element element = rootElement.element("Package");
        Element header = element.element("Header");
        String statuscode = header.elementTextTrim("statuscode");
        if (("2").equals(statuscode)) {
            //?
        }
    } catch (Exception e) {
        result = JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR,
                ConstantsUtil.RESULT_SERVICE_ERROR);
        logger.error(JsonPuserUtil.jsonToString(ConstantsUtil.ERRORCODE_SERVICE_ERROR, e.toString()));
    }
    return result;
}

From source file:com.davis.bluefolder.BlueUtils.java

public String formatXML(String input) {
    try {/*from   w  ww.ja va2 s .  c  o  m*/
        org.dom4j.Document doc = DocumentHelper.parseText(input);
        StringWriter sw = new StringWriter();
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setIndent(true);
        format.setIndentSize(3);
        XMLWriter xw = new XMLWriter(sw, format);
        xw.write(doc);

        return sw.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return input;
    }
}

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

License:Open Source License

public static Element sendGet(String openSearchServerURLStr, Map<String, String> paramsMap) {
    if (paramsMap == null) {
        paramsMap = new HashMap<String, String>();
    }//  w w  w  .j  a  va2s .  c om

    try {
        HttpParams params = new BasicHttpParams();
        for (Iterator<String> it = paramsMap.keySet().iterator(); it.hasNext();) {
            String paramName = (String) it.next();
            String paramValue = (String) paramsMap.get(paramName);
            params.setParameter(paramName, paramValue);
        }

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, CharSetUtils.UTF_8);
        HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
        HttpProtocolParams.setUseExpectContinue(params, true);

        BasicHttpProcessor httpproc = new BasicHttpProcessor();
        // Required protocol interceptors
        httpproc.addInterceptor(new RequestContent());
        httpproc.addInterceptor(new RequestTargetHost());
        // Recommended protocol interceptors
        httpproc.addInterceptor(new RequestConnControl());
        httpproc.addInterceptor(new RequestUserAgent());
        httpproc.addInterceptor(new RequestExpectContinue());

        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

        HttpContext context = new BasicHttpContext(null);
        URL openSearchServerURL = new URL(openSearchServerURLStr);
        String host = openSearchServerURL.getHost();
        int port = openSearchServerURL.getPort();
        if (port == -1) {
            port = 80;
        }
        HttpHost httpHost = new HttpHost(host, port);

        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, httpHost);

        try {
            boolean firstParam = true;
            for (Iterator<String> it = paramsMap.keySet().iterator(); it.hasNext();) {
                String paramName = (String) it.next();
                String paramValue = (String) paramsMap.get(paramName);
                if (paramValue != null) {
                    try {
                        paramValue = URLEncoder.encode(paramValue, CharSetUtils.ISO_8859_1);
                    } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException(e);
                    }
                }

                if (firstParam) {
                    openSearchServerURLStr += "?";
                    firstParam = false;
                } else {
                    openSearchServerURLStr += "&";
                }
                openSearchServerURLStr += paramName + "=" + paramValue;
            }

            if (!conn.isOpen()) {
                Socket socket = new Socket(host, port);
                conn.bind(socket, params);
            }
            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET",
                    openSearchServerURLStr);
            LOGGER.fine(">> Request URI: " + request.getRequestLine().getUri());

            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            response.setParams(params);
            httpexecutor.postProcess(response, httpproc, context);

            LOGGER.fine("<< Response: " + response.getStatusLine());
            String entityText = EntityUtils.toString(response.getEntity());
            LOGGER.fine(entityText);
            LOGGER.fine("==============");
            if (!connStrategy.keepAlive(response, context)) {
                conn.close();
            } else {
                LOGGER.fine("Connection kept alive...");
            }

            try {
                Document xml = DocumentHelper.parseText(entityText);
                return xml.getRootElement();
            } catch (RuntimeException e) {
                LOGGER.severe("Error caused by text : " + entityText);
                throw e;
            }
        } finally {
            conn.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.doculibre.constellio.utils.ConnectorManagerRequestUtils.java

License:Open Source License

public static Element sendGet(ConnectorManager connectorManager, String servletPath,
        Map<String, String> paramsMap) {
    if (paramsMap == null) {
        paramsMap = new HashMap<String, String>();
    }/*from  w ww . j av a 2 s  .  c om*/

    try {
        HttpParams params = new BasicHttpParams();
        for (Iterator<String> it = paramsMap.keySet().iterator(); it.hasNext();) {
            String paramName = (String) it.next();
            String paramValue = (String) paramsMap.get(paramName);
            params.setParameter(paramName, paramValue);
        }

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
        HttpProtocolParams.setUseExpectContinue(params, true);

        BasicHttpProcessor httpproc = new BasicHttpProcessor();
        // Required protocol interceptors
        httpproc.addInterceptor(new RequestContent());
        httpproc.addInterceptor(new RequestTargetHost());
        // Recommended protocol interceptors
        httpproc.addInterceptor(new RequestConnControl());
        httpproc.addInterceptor(new RequestUserAgent());
        httpproc.addInterceptor(new RequestExpectContinue());

        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

        HttpContext context = new BasicHttpContext(null);
        URL connectorManagerURL = new URL(connectorManager.getUrl());
        HttpHost host = new HttpHost(connectorManagerURL.getHost(), connectorManagerURL.getPort());

        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);

        try {
            String target = connectorManager.getUrl() + servletPath;
            boolean firstParam = true;
            for (Iterator<String> it = paramsMap.keySet().iterator(); it.hasNext();) {
                String paramName = (String) it.next();
                String paramValue = (String) paramsMap.get(paramName);

                if (firstParam) {
                    target += "?";
                    firstParam = false;
                } else {
                    target += "&";
                }
                target += paramName + "=" + paramValue;
            }

            if (!conn.isOpen()) {
                Socket socket = new Socket(host.getHostName(), host.getPort());
                conn.bind(socket, params);
            }
            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET", target);
            LOGGER.fine(">> Request URI: " + request.getRequestLine().getUri());

            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            response.setParams(params);
            httpexecutor.postProcess(response, httpproc, context);

            LOGGER.fine("<< Response: " + response.getStatusLine());
            String entityText = EntityUtils.toString(response.getEntity());
            LOGGER.fine(entityText);
            LOGGER.fine("==============");
            if (!connStrategy.keepAlive(response, context)) {
                conn.close();
            } else {
                LOGGER.fine("Connection kept alive...");
            }

            try {
                Document xml = DocumentHelper.parseText(entityText);
                return xml.getRootElement();
            } catch (Exception e) {
                LOGGER.severe("Error caused by text : " + entityText);
                throw e;
            }
        } finally {
            conn.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.doculibre.constellio.utils.ConnectorManagerRequestUtils.java

License:Open Source License

public static Element sendPost(ConnectorManager connectorManager, String servletPath, Document document) {
    try {/*from  ww w  .  ja  v  a2 s .  c  om*/
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
        HttpProtocolParams.setUseExpectContinue(params, true);

        BasicHttpProcessor httpproc = new BasicHttpProcessor();
        // Required protocol interceptors
        httpproc.addInterceptor(new RequestContent());
        httpproc.addInterceptor(new RequestTargetHost());
        // Recommended protocol interceptors
        httpproc.addInterceptor(new RequestConnControl());
        httpproc.addInterceptor(new RequestUserAgent());
        httpproc.addInterceptor(new RequestExpectContinue());

        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();

        HttpContext context = new BasicHttpContext(null);

        URL connectorManagerURL = new URL(connectorManager.getUrl());
        HttpHost host = new HttpHost(connectorManagerURL.getHost(), connectorManagerURL.getPort());

        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);

        try {
            HttpEntity requestBody;
            if (document != null) {
                //                 OutputFormat format = OutputFormat.createPrettyPrint();
                OutputFormat format = OutputFormat.createCompactFormat();
                StringWriter stringWriter = new StringWriter();
                XMLWriter xmlWriter = new XMLWriter(stringWriter, format);
                xmlWriter.write(document);
                String xmlAsString = stringWriter.toString();
                requestBody = new StringEntity(xmlAsString, "UTF-8");
            } else {
                requestBody = null;
            }
            if (!conn.isOpen()) {
                Socket socket = new Socket(host.getHostName(), host.getPort());
                conn.bind(socket, params);
            }

            String target = connectorManager.getUrl() + servletPath;

            BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", target);
            request.setEntity(requestBody);
            LOGGER.info(">> Request URI: " + request.getRequestLine().getUri());

            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            response.setParams(params);
            httpexecutor.postProcess(response, httpproc, context);

            LOGGER.info("<< Response: " + response.getStatusLine());
            String entityText = EntityUtils.toString(response.getEntity());
            LOGGER.info(entityText);
            LOGGER.info("==============");
            if (!connStrategy.keepAlive(response, context)) {
                conn.close();
            } else {
                LOGGER.info("Connection kept alive...");
            }

            Document xml = DocumentHelper.parseText(entityText);
            return xml.getRootElement();
        } finally {
            conn.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.dotmarketing.viewtools.XmlTool.java

License:Apache License

/**
 * Parses the given XML string and uses the resulting {@link Document} as the root {@link Node}.
 *//*from   ww  w .  j  a  v  a 2  s  .c  o  m*/
protected void parse(String xml) throws Exception {
    setRoot(DocumentHelper.parseText(xml));
}

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 {/* www.ja  v a 2s  .  co m*/
        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.electriccloud.commander.android.app.NetworkActivity.java

License:Apache License

public void parseFindObjectsResponse(InputStream httpResponse) {
    org.dom4j.Document doc = null;

    try {//  w w  w. j  av a  2  s.co  m
        doc = DocumentHelper.parseText(parseResponse(httpResponse));
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    org.dom4j.Node n = doc.selectSingleNode("//response");
    CommanderObjectImpl co = new CommanderObjectImpl((Element) n);
    FindObjectsResponse response = new FindObjectsResponseImpl(ObjectType.job, co);

    m_jobs = response.getJobs();
}

From source file:com.enernoc.rnd.openfire.cluster.task.PacketTask.java

License:Apache License

protected Element readXML(ObjectInput in) throws IOException {
    try {// w w  w .  j  a  v a2  s . c  o m
        return DocumentHelper.parseText(ExternalizableUtil.getInstance().readSafeUTF(in)).getRootElement();
    } catch (DocumentException e) {
        throw new IOException(e);
    }
}