Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

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

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private String openShell() {
    log.debug("openShell");

    final Element bodyContent = DocumentHelper.createElement(QName.get("Shell", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("InputStreams", Namespaces.NS_WIN_SHELL)).addText("stdin");
    bodyContent.addElement(QName.get("OutputStreams", Namespaces.NS_WIN_SHELL)).addText("stdout stderr");

    final Document requestDocument = getRequestDocument(Action.WS_ACTION, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.OPEN_SHELL, null, bodyContent);
    Document responseDocument = sendMessage(requestDocument, SoapAction.SHELL);

    return getFirstElement(responseDocument, ResponseExtractor.SHELL_ID);

}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java

License:Open Source License

private Element getHeader(Action action, ResourceURI resourceURI, OptionSet optionSet, String shellId) {
    final Element header = DocumentHelper.createElement(QName.get("Header", Namespaces.NS_SOAP_ENV));
    header.addElement(QName.get("To", Namespaces.NS_ADDRESSING)).addText(targetURL.toString());
    final Element replyTo = header.addElement(QName.get("ReplyTo", Namespaces.NS_ADDRESSING));
    replyTo.addElement(QName.get("Address", Namespaces.NS_ADDRESSING)).addAttribute("mustUnderstand", "true")
            .addText("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");
    header.addElement(QName.get("MaxEnvelopeSize", Namespaces.NS_WSMAN_DMTF))
            .addAttribute("mustUnderstand", "true").addText("" + envelopSize);
    header.addElement(QName.get("MessageID", Namespaces.NS_ADDRESSING)).addText(getUUID());
    header.addElement(QName.get("Locale", Namespaces.NS_WSMAN_DMTF)).addAttribute("mustUnderstand", "false")
            .addAttribute("xml:lang", locale);
    header.addElement(QName.get("DataLocale", Namespaces.NS_WSMAN_MSFT)).addAttribute("mustUnderstand", "false")
            .addAttribute("xml:lang", locale);
    header.addElement(QName.get("OperationTimeout", Namespaces.NS_WSMAN_DMTF)).addText(timeout);
    header.add(action.getElement());/*from   www. ja  v  a 2  s.com*/
    if (shellId != null) {
        header.addElement(QName.get("SelectorSet", Namespaces.NS_WSMAN_DMTF))
                .addElement(QName.get("Selector", Namespaces.NS_WSMAN_DMTF)).addAttribute("Name", "ShellId")
                .addText(shellId);
    }
    header.add(resourceURI.getElement());
    if (optionSet != null) {
        header.add(optionSet.getElement());
    }

    return header;
}

From source file:com.xebia.mojo.dashboard.reports.html.JacocoDashboardReport.java

License:Apache License

public static Element createPercentageBar(Node contentNode, int pixelsWide) {
    Element bar = null;/*w w w  .  j  av a2s  .  co m*/

    try {
        String percentageString = (contentNode != null) ? contentNode.getText() : "0.0";

        double fraction = NumberFormat.getPercentInstance().parse(percentageString).doubleValue();
        bar = DocumentHelper.createElement("div");

        int pixWide = pixelsWide;
        int greenPixWide = (int) (pixWide * fraction);

        HtmlUtil.addStyles(bar, "border: 1px solid #808080; padding: 0px; background-color: #F02020; width: "
                + pixWide + "px; border-collapse: collapse;");

        Element greenBar = bar.addElement("div");
        HtmlUtil.addStyles(greenBar,
                "padding: 0px; background-color: #00F000; height: 1.3em; border-collapse: collapse; width: "
                        + greenPixWide + "px;");

        Element text = greenBar.addElement("span");
        HtmlUtil.addStyles(text, "display:block; position:absolute; text-align:center; width:" + pixWide
                + "px; border-collapse:collapse;");
        text.setText(percentageString);

    } catch (ParseException e) {
    }

    return bar;
}

From source file:com.xebialabs.overthere.cifs.winrm.ResourceURI.java

License:Open Source License

public Element getElement() {
    return DocumentHelper.createElement(QName.get("ResourceURI", Namespaces.NS_WSMAN_DMTF))
            .addAttribute("mustUnderstand", "true").addText(uri);
}

From source file:com.xebialabs.overthere.cifs.winrm.WinRmClient.java

License:Open Source License

private void cleanUp() {
    if (commandId == null)
        return;/*w  w  w .  j  a va  2 s  . com*/
    logger.debug("cleanUp shellId {} commandId {} ", shellId, commandId);
    final Element bodyContent = DocumentHelper.createElement(QName.get("Signal", Namespaces.NS_WIN_SHELL))
            .addAttribute("CommandId", commandId);
    bodyContent.addElement(QName.get("Code", Namespaces.NS_WIN_SHELL))
            .addText("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate");
    final Document requestDocument = getRequestDocument(Action.WS_SIGNAL, ResourceURI.RESOURCE_URI_CMD, null,
            shellId, bodyContent);
    @SuppressWarnings("unused")
    Document responseDocument = sendMessage(requestDocument, SoapAction.SIGNAL);

}

From source file:com.xebialabs.overthere.cifs.winrm.WinRmClient.java

License:Open Source License

private void getCommandOutput(OverthereProcessOutputHandler handler) {
    logger.debug("getCommandOutput shellId {} commandId {} ", shellId, commandId);
    final Element bodyContent = DocumentHelper.createElement(QName.get("Receive", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("DesiredStream", Namespaces.NS_WIN_SHELL))
            .addAttribute("CommandId", commandId).addText("stdout stderr");
    final Document requestDocument = getRequestDocument(Action.WS_RECEIVE, ResourceURI.RESOURCE_URI_CMD, null,
            shellId, bodyContent);/*from   w  ww . ja v  a  2s.  c  o m*/

    for (;;) {
        Document responseDocument = sendMessage(requestDocument, SoapAction.RECEIVE);
        String stdout = handleStream(responseDocument, ResponseExtractor.STDOUT);
        BufferedReader stdoutReader = new BufferedReader(new StringReader(stdout));
        try {
            for (;;) {
                String line = stdoutReader.readLine();
                if (line == null) {
                    break;
                }
                handler.handleOutputLine(line);
            }
        } catch (IOException exc) {
            throw new RuntimeIOException("Unexpected I/O exception while reading stdout", exc);
        }

        String stderr = handleStream(responseDocument, ResponseExtractor.STDERR);
        BufferedReader stderrReader = new BufferedReader(new StringReader(stderr));
        try {
            for (;;) {
                String line = stderrReader.readLine();
                if (line == null) {
                    break;
                }
                handler.handleErrorLine(line);
            }
        } catch (IOException exc) {
            throw new RuntimeIOException("Unexpected I/O exception while reading stderr", exc);
        }

        if (chunk == 0) {
            try {
                exitCode = getFirstElement(responseDocument, ResponseExtractor.EXIT_CODE);
                logger.info("exit code {}", exitCode);
            } catch (Exception e) {
                logger.debug("not found");
            }
        }
        chunk++;

        /* We may need to get additional output if the stream has not finished.
                      The CommandState will change from Running to Done like so:
                      @example
                
                       from...
                       <rsp:CommandState CommandId="..." State="http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Running"/>
                       to...
                       <rsp:CommandState CommandId="..." State="http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done">
                          <rsp:ExitCode>0</rsp:ExitCode>
                       </rsp:CommandState>
                    */
        final List<?> list = ResponseExtractor.STREAM_DONE.getXPath().selectNodes(responseDocument);
        if (!list.isEmpty()) {
            exitCode = getFirstElement(responseDocument, ResponseExtractor.EXIT_CODE);
            logger.info("exit code {}", exitCode);
            break;
        }
    }

    logger.debug("all the command output has been fetched (chunk={})", chunk);

}

From source file:com.xebialabs.overthere.cifs.winrm.WinRmClient.java

License:Open Source License

private String runCommand(String command) {
    logger.debug("runCommand shellId {} command {}", shellId, command);
    final Element bodyContent = DocumentHelper.createElement(QName.get("CommandLine", Namespaces.NS_WIN_SHELL));

    String encoded = command;//from   w  w  w . j av  a2s. com
    encoded = "\"" + encoded + "\"";

    logger.info("Encoded command is {}", encoded);

    bodyContent.addElement(QName.get("Command", Namespaces.NS_WIN_SHELL)).addText(encoded);

    final Document requestDocument = getRequestDocument(Action.WS_COMMAND, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.RUN_COMMAND, shellId, bodyContent);
    Document responseDocument = sendMessage(requestDocument, SoapAction.COMMAND_LINE);

    return getFirstElement(responseDocument, ResponseExtractor.COMMAND_ID);
}

From source file:com.xebialabs.overthere.cifs.winrm.WinRmClient.java

License:Open Source License

private String openShell() {
    logger.debug("openShell");

    final Element bodyContent = DocumentHelper.createElement(QName.get("Shell", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("InputStreams", Namespaces.NS_WIN_SHELL)).addText("stdin");
    bodyContent.addElement(QName.get("OutputStreams", Namespaces.NS_WIN_SHELL)).addText("stdout stderr");

    final Document requestDocument = getRequestDocument(Action.WS_ACTION, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.OPEN_SHELL, null, bodyContent);
    Document responseDocument = sendMessage(requestDocument, SoapAction.SHELL);

    return getFirstElement(responseDocument, ResponseExtractor.SHELL_ID);

}

From source file:com.xebialabs.overthere.winrm.WinRmClient.java

License:Open Source License

public String createShell() {
    logger.debug("Sending WinRM Create Shell request");

    final Element bodyContent = DocumentHelper.createElement(QName.get("Shell", Namespaces.NS_WIN_SHELL));
    bodyContent.addElement(QName.get("InputStreams", Namespaces.NS_WIN_SHELL)).addText("stdin");
    bodyContent.addElement(QName.get("OutputStreams", Namespaces.NS_WIN_SHELL)).addText("stdout stderr");
    final Document requestDocument = getRequestDocument(Action.WS_ACTION, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.OPEN_SHELL, bodyContent);

    Document responseDocument = sendRequest(requestDocument, SoapAction.SHELL);

    shellId = getFirstElement(responseDocument, ResponseExtractor.SHELL_ID);

    logger.debug("Received WinRM Create Shell response: shell with ID {} start created", shellId);

    return shellId;
}

From source file:com.xebialabs.overthere.winrm.WinRmClient.java

License:Open Source License

public String executeCommand(String command) {
    logger.debug("Sending WinRM Execute Command request to shell {}", shellId);

    final Element bodyContent = DocumentHelper.createElement(QName.get("CommandLine", Namespaces.NS_WIN_SHELL));
    String encoded = "\"" + command + "\"";
    bodyContent.addElement(QName.get("Command", Namespaces.NS_WIN_SHELL)).addText(encoded);
    final Document requestDocument = getRequestDocument(Action.WS_COMMAND, ResourceURI.RESOURCE_URI_CMD,
            OptionSet.RUN_COMMAND, bodyContent);

    Document responseDocument = sendRequest(requestDocument, SoapAction.COMMAND_LINE);

    commandId = getFirstElement(responseDocument, ResponseExtractor.COMMAND_ID);

    logger.debug("Received WinRM Execute Command response to shell {}: command with ID {} was started", shellId,
            commandId);//from   w w  w.ja  v a  2  s. com

    return commandId;
}