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.enernoc.rnd.openfire.cluster.task.PacketTask.java

License:Apache License

/**
 * Get a packet instance given a generic type.  Clients who already know the
 * type of packet they are manipulating can skip this since they can directly
 * instantiate the packet subclass they are working with.
 * @param <P>//w w  w  . java 2  s  .co  m
 * @param packetType
 * @param in
 * @return
 * @throws IOException
 */
protected P deserializePacket(Class<P> packetType, DataInput in) throws IOException {
    ExternalizableUtil ext = ExternalizableUtil.getInstance();
    try {
        String xmlPacket = ext.readSafeUTF(in);
        Constructor<P> ctr = packetType.getConstructor(new Class[] { Element.class });
        Element e = DocumentHelper.parseText(xmlPacket).getRootElement();
        return ctr.newInstance(e);
    } catch (NoSuchMethodException ex) {
        throw new IOException(ex);
    } catch (InvocationTargetException ex) {
        throw new IOException(ex);
    } catch (IllegalAccessException ex) {
        throw new IOException(ex);
    } catch (IllegalArgumentException ex) {
        throw new IOException(ex);
    } catch (InstantiationException ex) {
        throw new IOException(ex);
    } catch (DocumentException ex) {
        throw new IOException(ex);
    }
}

From source file:com.ethercis.vehr.response.XmlHttpResponse.java

License:Apache License

public void respond(Object data, String path) {

    if (data instanceof String) {
        writer.println((String) data);
        writer.close();//w  w  w  .  ja  v  a  2s  .  c  o  m
    } else if (data instanceof Document) {
        Document document = (Document) data;
        String xml = document.asXML().replaceAll(Constants.URI_TAG, path);
        //massaging...
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();
        StringWriter stringWriter = new StringWriter();
        XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat);
        try {
            Document document1 = DocumentHelper.parseText(xml);
            xmlWriter.write(document1);
        } catch (Exception e) {
            throw new IllegalArgumentException("Could not encode content:" + e);
        }
        writer.println(stringWriter.toString());
        writer.close();
    }
}

From source file:com.eufar.asmm.server.DownloadFunction.java

License:EUPL

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("DownloadFunction - the function started");
    ServletContext context = getServletConfig().getServletContext();
    request.setCharacterEncoding("UTF-8");
    String dir = context.getRealPath("/tmp");
    ;//ww  w .  j  ava 2s  .com
    String filename = "";
    File fileDir = new File(dir);
    try {
        System.out.println("DownloadFunction - create the file on server");
        filename = request.getParameterValues("filename")[0];
        String xmltree = request.getParameterValues("xmltree")[0];

        // format xml code to pretty xml code
        Document doc = DocumentHelper.parseText(xmltree);
        StringWriter sw = new StringWriter();
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setIndent(true);
        format.setIndentSize(4);
        XMLWriter xw = new XMLWriter(sw, format);
        xw.write(doc);

        Writer out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8"));
        out.append(sw.toString());
        out.flush();
        out.close();
    } catch (Exception ex) {
        System.out.println("ERROR during rendering: " + ex);
    }
    try {
        System.out.println("DownloadFunction - send file to user");
        ServletOutputStream out = response.getOutputStream();
        File file = new File(dir + "/" + filename);
        String mimetype = context.getMimeType(filename);
        response.setContentType((mimetype != null) ? mimetype : "application/octet-stream");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        response.setHeader("Pragma", "private");
        response.setHeader("Cache-Control", "private, must-revalidate");
        DataInputStream in = new DataInputStream(new FileInputStream(file));
        int length;
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            out.write(bbuf, 0, length);
        }
        in.close();
        out.flush();
        out.close();
        FileUtils.cleanDirectory(fileDir);
    } catch (Exception ex) {
        System.out.println("ERROR during downloading: " + ex);
    }
    System.out.println("DownloadFunction - file ready to be donwloaded");
}

From source file:com.feilong.tools.dom4j.Dom4jUtil.java

License:Apache License

/**
 * Document./*ww  w .j  a  v a2  s . c  o  m*/
 *
 * @param xmlString
 *            xml?
 * @return the document
 * @throws Dom4jException
 *             the dom4j exception
 */
public static Document string2Document(String xmlString) throws Dom4jException {
    try {
        Document document = DocumentHelper.parseText(xmlString);
        return document;
    } catch (DocumentException e) {
        throw new Dom4jException(e);
    }
}

From source file:com.founder.fix.fixflow.core.impl.util.XmlUtil.java

License:Apache License

public static Document parseText(String text) throws DocumentException {
    return DocumentHelper.parseText(text);
}

From source file:com.glaf.jbpm.tag.JbpmProcessImageTag.java

License:Apache License

private void writeTable() throws IOException, DocumentException {
    int borderWidth = 4;
    Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
    int[] boxConstraint;
    int[] imageDimension = extractImageDimension(rootDiagramElement);
    String imagePath = contextPath + "/mx/jbpm/image";
    if (conf.get("jbpm.processImageUrl") != null) {
        imagePath = contextPath + conf.get("jbpm.processImageUrl");
    }/* w  ww .j a va  2s .  co  m*/
    String imageLink = imagePath + "?processDefinitionId=" + processDefinition.getId();
    JspWriter jspOut = pageContext.getOut();

    if (tokenInstanceId > 0) {
        List<Token> allTokens = new java.util.ArrayList<Token>();
        walkTokens(currentToken, allTokens);
        jspOut.println("<div style='position:relative; background-image:url(" + imageLink
                + ");background-repeat:no-repeat; width: " + imageDimension[0] + "px; height: "
                + imageDimension[1] + "px;'>");

        for (int i = 0; i < allTokens.size(); i++) {
            Token token = allTokens.get(i);
            if (!token.getProcessInstance().hasEnded()) {
                if (!token.isAbleToReactivateParent()) {
                    continue;
                }
            }
            // check how many tokens are on teh same level (= having the
            // same parent)
            int offset = i;
            if (i > 0) {
                while (offset > 0 && (allTokens.get(offset - 1)).getParent().equals(token.getParent())) {
                    offset--;
                }
            }
            boxConstraint = extractBoxConstraint(rootDiagramElement, token);

            // Adjust for borders
            // boxConstraint[2] -= borderWidth * 2;
            // boxConstraint[3] -= borderWidth * 2;

            jspOut.println("<div style='position:absolute; left: " + boxConstraint[0] + "px; top: "
                    + boxConstraint[1] + "px; ");

            if (i == (allTokens.size() - 1)) {
                jspOut.println("border: " + currentTokenColor);
            } else {
                if (StringUtils.isNotEmpty(childTokenColor)) {
                    jspOut.println("border: " + childTokenColor);
                }
            }

            jspOut.println(" " + borderWidth + "px groove; " + "width: " + (boxConstraint[2] - 2)
                    + "px; height: " + (boxConstraint[3] - 2) + "px;'>");

            jspOut.println("</div>");
        }
        jspOut.println("</div>");
    } else {
        boxConstraint = extractBoxConstraint(rootDiagramElement);

        jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height="
                + imageDimension[1] + ">");
        jspOut.println("  <tr>");
        jspOut.println("    <td width=" + imageDimension[0] + " height=" + imageDimension[1]
                + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
        jspOut.println("      <table border=0 cellspacing=0 cellpadding=0>");
        jspOut.println("        <tr>");
        jspOut.println("          <td width=" + (boxConstraint[0] - borderWidth) + " height="
                + (boxConstraint[1] - borderWidth) + " style=\"background-color:transparent;\"></td>");
        jspOut.println("        </tr>");
        jspOut.println("        <tr>");
        jspOut.println("          <td style=\"background-color:transparent;\"></td>");
        jspOut.println("          <td style=\"border-color:" + currentTokenColor + "; border-width:"
                + borderWidth + "px; border-style:groove; background-color:transparent;\" width="
                + boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + ">&nbsp;</td>");
        jspOut.println("        </tr>");
        jspOut.println("      </table>");
        jspOut.println("    </td>");
        jspOut.println("  </tr>");
        jspOut.println("</table>");
    }
}

From source file:com.glaf.jbpm.web.rest.MxJbpmProcessViewResource.java

License:Apache License

private Writer writeTable() throws IOException, DocumentException {
    int borderWidth = 4;
    Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
    int[] boxConstraint;
    int[] imageDimension = extractImageDimension(rootDiagramElement);
    String imageLink = contextPath + "/rs/jbpm/view/image/" + processDefinition.getId();
    Writer writer = new StringWriter();

    if (tokenInstanceId > 0) {
        List<Token> allTokens = new java.util.ArrayList<Token>();
        walkTokens(currentToken, allTokens);
        writer.write("<div style='position:relative; background-image:url(" + imageLink
                + ");background-repeat:no-repeat; width: " + imageDimension[0] + "px; height: "
                + imageDimension[1] + "px;'>");

        for (int i = 0; i < allTokens.size(); i++) {
            Token token = allTokens.get(i);
            if (!token.getProcessInstance().hasEnded()) {
                if (!token.isAbleToReactivateParent()) {
                    continue;
                }//from  w  ww.  j  a  v a2 s  . c om
            }
            // check how many tokens are on teh same level (= having the
            // same parent)
            int offset = i;
            if (i > 0) {
                while (offset > 0 && (allTokens.get(offset - 1)).getParent().equals(token.getParent())) {
                    offset--;
                }
            }
            boxConstraint = extractBoxConstraint(rootDiagramElement, token);

            // Adjust for borders
            // boxConstraint[2] -= borderWidth * 2;
            // boxConstraint[3] -= borderWidth * 2;

            writer.write("<div style='position:absolute; left: " + boxConstraint[0] + "px; top: "
                    + boxConstraint[1] + "px; ");

            if (i == (allTokens.size() - 1)) {
                writer.write("border: " + currentTokenColor);
            } else {
                if (StringUtils.isNotEmpty(childTokenColor)) {
                    writer.write("border: " + childTokenColor);
                }
            }

            writer.write(" " + borderWidth + "px groove; " + "width: " + boxConstraint[2] + "px; height: "
                    + boxConstraint[3] + "px;'>");

            /**
             * if (token.getName() != null) { jspOut
             * .println("<span style='color:" + tokenNameColor +
             * ";font-size:12px;font-weight:bold;font-style:italic;position:absolute;left:"
             * + (boxConstraint[2] + 10) + "px;top:" + ((i - offset) * 20) +
             * ";'>&nbsp;" + token.getName() + "</span>"); }
             */

            writer.write("</div>");
        }
        writer.write("</div>");
    } else {
        boxConstraint = extractBoxConstraint(rootDiagramElement);

        writer.write("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height="
                + imageDimension[1] + ">");
        writer.write("  <tr>");
        writer.write("    <td width=" + imageDimension[0] + " height=" + imageDimension[1]
                + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
        writer.write("      <table border=0 cellspacing=0 cellpadding=0>");
        writer.write("        <tr>");
        writer.write("          <td width=" + (boxConstraint[0] - borderWidth) + " height="
                + (boxConstraint[1] - borderWidth) + " style=\"background-color:transparent;\"></td>");
        writer.write("        </tr>");
        writer.write("        <tr>");
        writer.write("          <td style=\"background-color:transparent;\"></td>");
        writer.write("          <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth
                + "px; border-style:groove; background-color:transparent;\" width=" + boxConstraint[2]
                + " height=" + (boxConstraint[3] + (2 * borderWidth)) + ">&nbsp;</td>");
        writer.write("        </tr>");
        writer.write("      </table>");
        writer.write("    </td>");
        writer.write("  </tr>");
        writer.write("</table>");
    }
    return writer;
}

From source file:com.globalsight.everest.webapp.pagehandler.tm.management.TmExportPageHandler.java

License:Apache License

/**
 * Invoke this PageHandler./* w  ww.  jav  a2 s. c  o m*/
 *
 * @param p_pageDescriptor the page desciptor
 * @param p_request the original request sent from the browser
 * @param p_response the original response object
 * @param p_context context the Servlet context
 */
public void invokePageHandler(WebPageDescriptor p_pageDescriptor, HttpServletRequest p_request,
        HttpServletResponse p_response, ServletContext p_context)
        throws ServletException, IOException, EnvoyServletException {
    HttpSession session = p_request.getSession();
    SessionManager sessionMgr = (SessionManager) session.getAttribute(SESSION_MANAGER);

    Locale uiLocale = (Locale) session.getAttribute(UILOCALE);
    ResourceBundle bundle = getBundle(session);

    String action = (String) p_request.getParameter(TM_ACTION);
    String options = (String) p_request.getParameter(TM_EXPORT_OPTIONS);
    String tmid = (String) p_request.getParameter(RADIO_TM_ID);
    String name = null;
    String definition = null;
    String tmtype = "TM2";
    String jobAttribute = "";
    Tm tm = null;

    IExportManager exporter = (IExportManager) sessionMgr.getAttribute(TM_EXPORTER);

    ProcessStatus status = (ProcessStatus) sessionMgr.getAttribute(TM_TM_STATUS);

    try {
        if (tmid != null) {
            // tm = s_manager.getTmById(Long.parseLong(tmid));
            tm = s_manager.getProjectTMById(Long.parseLong(tmid), false);
            name = tm.getName();

            // JSP needs the language names, so get the statistics
            // and pass that as long as a TM has no proper definition.
            // Note that the JSP uses both the languages and whether or 
            // not the TM is empty.
            StatisticsInfo tmStatistics = LingServerProxy.getTmCoreManager().getTmExportInformation(tm,
                    uiLocale);
            definition = tmStatistics.asXML(true);

            Long tm3id = tm.getTm3Id();
            tmtype = tm3id == null ? "TM2" : "TM3";
            jobAttribute = getAttributes(tm.getId(), tm.getTm3Id(), tm.getCompanyId());
        }

        if (options != null) {
            // options are posted as UTF-8 string
            options = EditUtil.utf8ToUnicode(options);
            int index = options.indexOf("</exportOptions>");
            if (index > 0) {
                options = options.substring(0, index + "</exportOptions>".length());
            }
        }

        if (action.equals(TM_ACTION_EXPORT)) {
            if (tmid == null || p_request.getMethod().equalsIgnoreCase(REQUEST_METHOD_GET)) {
                p_response.sendRedirect("/globalsight/ControlServlet?activityName=tm");
                return;
            }
            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("initializing export");
            }

            //exporter = s_manager.getExporter(name);
            exporter = TmManagerLocal.getProjectTmExporter(name);

            options = exporter.getExportOptions();

            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("initial options = " + options);
            }

            sessionMgr.setAttribute(TM_TM_NAME, name);
            sessionMgr.setAttribute(TM_TM_ID, tmid);
            sessionMgr.setAttribute(TM_DEFINITION, definition);
            sessionMgr.setAttribute(TM_PROJECT, definition);
            sessionMgr.setAttribute(TM_EXPORT_OPTIONS, options);
            sessionMgr.setAttribute(TM_EXPORTER, exporter);
            sessionMgr.setAttribute(TM_TYPE, tmtype);
            sessionMgr.setAttribute(TM_ATTRIBUTE, jobAttribute);
        } else if (action.equals(TM_ACTION_ANALYZE_TM)) {
            if (p_request.getMethod().equalsIgnoreCase(REQUEST_METHOD_GET)) {
                p_response.sendRedirect("/globalsight/ControlServlet?activityName=tm");
                return;
            }
            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("options from client= " + options);
            }

            // pass down new options from client (won't reanalyze files)
            exporter.setExportOptions(options);

            // then retrieve new options
            options = exporter.analyze();

            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("analysis options = " + options);
            }

            sessionMgr.setAttribute(TM_EXPORT_OPTIONS, options);
        } else if (action.equals(TM_ACTION_SET_EXPORT_OPTIONS)) {
            if (p_request.getMethod().equalsIgnoreCase(REQUEST_METHOD_GET)) {
                p_response.sendRedirect("/globalsight/ControlServlet?activityName=tm");
                return;
            }
            // pass down new options from client (won't reanalyze files)

            // testrun may come here without setting options
            if (options != null) {
                if (CATEGORY.isDebugEnabled()) {
                    CATEGORY.debug("options from client = " + options);
                }

                exporter.setExportOptions(options);
            } else {
                options = exporter.getExportOptions();
            }

            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("options = " + options);
            }
            Document dom = DocumentHelper.parseText(options);
            Element root = dom.getRootElement();
            Element elem = (Element) root.selectSingleNode("//filterOptions/stringId");
            String sid = elem.getText();
            if (StringUtils.isNotBlank(sid) && sid.indexOf("\\") != -1) {
                sid = sid.replace("\\", "\\\\");
            }
            elem.setText(sid);
            options = dom.asXML().substring(dom.asXML().indexOf("<exportOptions>"));
            sessionMgr.setAttribute(TM_EXPORT_OPTIONS, options);
        } else if (action.equals(TM_ACTION_START_EXPORT)) {
            if (p_request.getMethod().equalsIgnoreCase(REQUEST_METHOD_GET)) {
                p_response.sendRedirect("/globalsight/ControlServlet?activityName=tm");
                return;
            }
            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("running export with options = " + options);
            }

            // pass down new options from client
            exporter.setExportOptions(options);

            // Let the jsp page show progress of export
            sessionMgr.setAttribute(TM_EXPORT_OPTIONS, options);

            // Start export in a separate thread.
            try {
                status = new ProcessStatus();
                status.setResourceBundle(bundle);
                sessionMgr.setAttribute(TM_TM_STATUS, status);

                exporter.attachListener(status);
                exporter.doExport();
            } catch (Throwable ex) {
                CATEGORY.error("Export error occured ", ex);
            }
        } else if (action.equals(TM_ACTION_CANCEL_EXPORT)) {
            status.interrupt();
        } else if (action.equals(TM_ACTION_CANCEL) || action.equals(TM_ACTION_DONE)) {
            // we don't come here, do we??
            sessionMgr.removeElement(TM_EXPORTER);
            sessionMgr.removeElement(TM_EXPORT_OPTIONS);
            sessionMgr.removeElement(TM_TM_STATUS);
        }
    } catch (Throwable ex) {
        CATEGORY.error("export error", ex);
        // JSP needs to clear this.
        sessionMgr.setAttribute(TM_ERROR, ex.getMessage());
    }

    super.invokePageHandler(p_pageDescriptor, p_request, p_response, p_context);
}

From source file:com.globalsight.everest.webapp.servlet.SnippetLibraryServlet.java

License:Apache License

/**
 * Extracts and executes a request for the SnippetLibrary to
 * create, modify, or delete snippets./* www.  ja  v a2  s.  c  o m*/
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {
        String result = null;

        HttpSession session = request.getSession();
        String userId = PageHandler.getUser(session).getUserId();

        SessionManager sessionMgr = (SessionManager) session.getAttribute(WebAppConstants.SESSION_MANAGER);

        EditorState state = (EditorState) sessionMgr.getAttribute(WebAppConstants.EDITORSTATE);

        response.setContentType("text/xml; charset=UTF-8");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);

        Document dom = DocumentHelper.parseText(readBody(request));

        Node commandNode = dom.selectSingleNode("/*/request");
        if (commandNode == null) {
            returnBadRequest(response);
        }

        String command = commandNode.getText();
        if (command == null || command.length() == 0) {
            returnBadRequest(response);
        }

        if (command.equals(SNIPPET_ACTION_GETPAGE)) {
            // retrieve page interpreted in a locale
            result = getPage(dom, state, request.getSession());
        } else if (command.equals(SNIPPET_ACTION_GETSNIPPET)) {
            // retrieve the snippet for a specific position
            // (by name + locale + version)
            result = getSnippet(dom);
        } else if (command.equals(SNIPPET_ACTION_GETSNIPPETS)) {
            // retrieve the snippets for a position (by name + locale)
            result = getSnippets(dom);
        } else if (command.equals(SNIPPET_ACTION_CREATESNIPPET)) {
            result = createSnippet(userId, dom);
        } else if (command.equals(SNIPPET_ACTION_CREATESNIPPETGETSNIPPET)) {
            result = createSnippetGetSnippet(userId, dom);
        } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPET)) {
            result = modifySnippet(userId, dom);
        } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPETGETSNIPPET)) {
            result = modifySnippetGetSnippet(userId, dom);
        } else if (command.equals(SNIPPET_ACTION_REMOVESNIPPET)) {
            // deletes a snippet.
            result = removeSnippet(userId, dom);
        } else if (command.equals(SNIPPET_ACTION_ADDSNIPPETGETPAGE)) {
            // add a snippet and recompute the page
            result = addSnippetGetPage(userId, dom, state, request.getSession());
        } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPETGETPAGE)) {
            // modify a snippet and recompute the page
            result = modifySnippetGetPage(userId, dom, state, request.getSession());
        } else if (command.equals(SNIPPET_ACTION_REMOVESNIPPETGETPAGE)) {
            // remove a snippet and recompute the page
            result = removeSnippetGetPage(userId, dom, state, request.getSession());
        } else if (command.equals(SNIPPET_ACTION_DELETECONTENTGETPAGE)) {
            // delete content and recompute the page
            result = deleteContentGetPage(userId, dom, state, request.getSession());
        } else if (command.equals(SNIPPET_ACTION_UNDELETECONTENTGETPAGE)) {
            // un-delete content and recompute the page
            result = undeleteContentGetPage(userId, dom, state, request.getSession());
        }
        // Mon Jul 11 21:32:17 2005 Amb6.6 source page editing additions
        else if (command.equals(SNIPPET_ACTION_GETGENERICNAMES)) {
            result = getGenericSnippetNames();
        } else if (command.equals(SNIPPET_ACTION_GETSNIPPETSBYLOCALE)) {
            result = getSnippetsByLocale(dom);
        } else if (command.equals(SNIPPET_ACTION_GETGENERICSNIPPET)) {
            result = getGenericSnippet(dom);
        }

        if (CATEGORY.isDebugEnabled()) {
            CATEGORY.debug("action=" + command + " result=\n" + result);
        }

        if (result == null) {
            returnBadRequest(response);
        } else {
            returnXml(response, result);
        }
    } catch (SnippetException ex) {
        CATEGORY.warn(ex.getMessage(), ex);

        returnError(response, ex);
    } catch (Throwable ex) {
        CATEGORY.warn(ex.getMessage(), ex);

        returnError(response, ex);
    }
}

From source file:com.globalsight.smartbox.util.WebClientHelper.java

License:Apache License

/**
 * Get jobStatus from GS Server//from  w w  w . j  a v a 2s .  c om
 * 
 * @param jobInfo
 * @return
 * @throws Exception
 */
public static boolean getJobStatus(JobInfo jobInfo) {
    try {
        String jobStatus = ambassador.getJobStatus(accessToken, jobInfo.getJobName());
        Document profileDoc = DocumentHelper.parseText(jobStatus);
        Node node = profileDoc.selectSingleNode("/job");
        String id = node.selectSingleNode("id").getText();
        String status = node.selectSingleNode("status").getText();
        jobInfo.setId(id);
        jobInfo.setStatus(status);
    } catch (Exception e) {
        String message = "Failed to get job status, Job Name:" + jobInfo.getJobName();
        LogUtil.fail(message, e);
        return false;
    }
    return true;
}