Example usage for org.dom4j QName get

List of usage examples for org.dom4j QName get

Introduction

In this page you can find the example usage for org.dom4j QName get.

Prototype

public static QName get(String localName, Namespace namespace, String qualifiedName) 

Source Link

Usage

From source file:com.smartwork.im.StreamError.java

License:Open Source License

/**
 * Sets the text description of the error. Optionally, a language code
 * can be specified to indicate the language of the description.
 *
 * @param text the text description of the error.
 * @param language the language code of the description, or <tt>null</tt> to specify
 *      no language code./*w  w w .  java 2  s .  co m*/
 */
public void setText(String text, String language) {
    Element textElement = element.element("text");
    // If text is null, clear the text.
    if (text == null) {
        if (textElement != null) {
            element.remove(textElement);
        }
        return;
    }

    if (textElement == null) {
        textElement = docFactory.createElement("text", ERROR_NAMESPACE);
        if (language != null) {
            textElement.addAttribute(QName.get("lang", "xml", "http://www.w3.org/XML/1998/namespace"),
                    language);
        }
        element.add(textElement);
    }
    textElement.setText(text);
}

From source file:com.smartwork.im.StreamError.java

License:Open Source License

/**
 * Returns the text description's language code, or <tt>null</tt> if there
 * is no language code associated with the description text.
 *
 * @return the language code of the text description, if it exists.
 *///from   w w  w. jav a2s .  c o m
public String getTextLanguage() {
    Element textElement = element.element("text");
    if (textElement != null) {
        return textElement.attributeValue(QName.get("lang", "xml", "http://www.w3.org/XML/1998/namespace"));
    }
    return null;
}

From source file:com.sun.xml.ws.test.container.invm.InVmContainer.java

License:Open Source License

/**
 * Fix the address in the WSDL. to the local address.
 *//*from w ww  . j a  v  a  2  s  .  c o  m*/
private void patchWsdl(DeployedService service, File wsdl, String id) throws Exception {
    Document doc = new SAXReader().read(wsdl);
    List<Element> ports = doc.getRootElement().element("service").elements("port");

    for (Element port : ports) {
        String portName = port.attributeValue("name");
        Element address = getSoapAddress(port);

        //Looks like invalid wsdl:port, MUST have a soap:address
        //TODO: give some error message
        if (address == null)
            continue;

        if (!"wsdl".equalsIgnoreCase(wsdl.getParentFile().getName())) {
            portName = wsdl.getParentFile().getName() + portName;
        }

        Attribute locationAttr = address.attribute("location");
        String newLocation = "in-vm://" + id + "/?" + portName;
        newLocation = newLocation.replace('\\', '/');
        locationAttr.setValue(newLocation);

        //Patch wsa:Address in wsa:EndpointReference as well
        Element wsaEprEl = port
                .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing"));
        if (wsaEprEl != null) {
            Element wsaAddrEl = wsaEprEl
                    .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing"));
            wsaAddrEl.setText(newLocation);

        }
    }

    // save file
    FileOutputStream os = new FileOutputStream(wsdl);
    new XMLWriter(os).write(doc);
    os.close();
}

From source file:com.sun.xml.ws.test.container.local.LocalApplicationContainer.java

License:Open Source License

/**
 * Fix the address in the WSDL. to the local address.
 *///  w w  w  .  j a  v  a  2  s  .  co  m
private void patchWsdl(DeployedService service, File wsdl) throws Exception {
    Document doc = new SAXReader().read(wsdl);
    List<Element> ports = doc.getRootElement().element("service").elements("port");

    for (Element port : ports) {
        String portName = port.attributeValue("name");

        Element address = (Element) port.elements().get(0);

        Attribute locationAttr = address.attribute("location");
        String newLocation = "local://" + service.warDir.getAbsolutePath() + "?" + portName;
        newLocation = newLocation.replace('\\', '/');
        locationAttr.setValue(newLocation);

        //Patch wsa:Address in wsa:EndpointReference as well
        Element wsaEprEl = port
                .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing"));
        if (wsaEprEl != null) {
            Element wsaAddrEl = wsaEprEl
                    .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing"));
            wsaAddrEl.setText(newLocation);

        }
    }

    // save file
    FileOutputStream os = new FileOutputStream(wsdl);
    new XMLWriter(os).write(doc);
    os.close();
}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.PacketError.java

License:Open Source License

/**
 * Sets the text description of the error. Optionally, a language code
 * can be specified to indicate the language of the description.
 *
 * @param text the text description of the error.
 * @param lang the language code of the description, or <tt>null</tt> to specify
 *      no language code.//  w  ww.j  a va2s.c om
 */
public void setText(String text, String lang) {
    Element textElement = element.element("text");
    // If text is null, clear the text.
    if (text == null) {
        if (textElement != null) {
            element.remove(textElement);
        }
        return;
    }

    if (textElement == null) {
        textElement = docFactory.createElement("text", ERROR_NAMESPACE);
        if (lang != null) {
            textElement.addAttribute(QName.get("lang", "xml", "http://www.w3.org/XML/1998/namespace"), lang);
        }
        element.add(textElement);
    }
    textElement.setText(text);
}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.PacketError.java

License:Open Source License

/**
 * Returns the text description's language code, or <tt>null</tt> if there
 * is no language code associated with the description text.
 *
 * @return the language code of the text description, if it exists.
 */// w w w. j a  va  2s  . c  o m
public String getTextLang() {
    Element textElement = element.element("text");
    if (textElement != null) {
        return textElement.attributeValue(QName.get("lang", "xml", "http://www.w3.org/XML/1998/namespace"));
    }
    return null;
}

From source file:fr.gouv.culture.vitam.utils.XmlDom.java

License:Open Source License

private final static void setNamespace(Element elem, Namespace ns) {
    elem.setQName(QName.get(elem.getName(), ns, elem.getQualifiedName()));
}

From source file:net.dontdrinkandroot.lastfm.api.CheckImplementationStatus.java

License:Apache License

/**
 * Sets the namespace of the element to the given namespace
 *///from  w w  w .  ja  v  a 2  s  .co  m
public static void setNamespace(final Element elem, final Namespace ns) {

    elem.setQName(QName.get(elem.getName(), ns, elem.getQualifiedName()));
}

From source file:org.alfresco.module.vti.web.actions.VtiSoapAction.java

License:Open Source License

/**
 * Creates an appropriate SOAP Fault Response, in the appropriate
 *  of the two different formats/*from w  w  w.j a  v a2  s  .com*/
 */
private void createFaultSOAPResponse(VtiSoapRequest request, Element responseElement, Exception e,
        VtiEndpoint vtiEndpoint) {
    // Is it something like
    //  <FooResponse><FooResult><Error ID="123"/></FooResult></FooResponse> ?
    if (e instanceof VtiHandlerException) {
        VtiHandlerException handlerException = (VtiHandlerException) e;
        Element endpointResponseE = responseElement.addElement(vtiEndpoint.getName() + "Response",
                vtiEndpoint.getNamespace());
        Element endpointResultE = endpointResponseE.addElement(vtiEndpoint.getName() + "Result");

        //String errorMessage = handlerException.getMessage();
        String errorCode;
        if (handlerException.getErrorCode() > -1) {
            errorCode = Long.toString(handlerException.getErrorCode());
        } else {
            errorCode = "13";
        }

        // Return it as an ID based error, without the message
        endpointResultE.addElement("Error").addAttribute("ID", errorCode);
    } else if (e instanceof DwsException) {
        // <FooResponse><FooResult><Error>[ID]</Error></FooResult></FooResponse>
        DwsException handlerException = (DwsException) e;
        Element endpointResponseE = responseElement.addElement(vtiEndpoint.getResponseTagName(),
                vtiEndpoint.getNamespace());
        Element endpointResultE = endpointResponseE.addElement(vtiEndpoint.getResultTagName());

        DwsError error = handlerException.getError();
        // Error value, numeric ID
        int errorId = error.toInt();
        // Error code, e.g. "ServerFailure"
        String errorCode = error.toCode();

        // Return it as an Coded ID based error, without the message
        Map<String, Object> errorAttrs = new HashMap<String, Object>(1);
        errorAttrs.put("ID", errorId);
        StringBuilder sb = startTag("Error", errorAttrs);
        sb.append(errorCode);
        sb.append(endTag("Error"));
        String elText = sb.toString();
        endpointResultE.setText(elText);
    } else {
        // We need to return a regular SOAP Fault
        String errorMessage = e.getMessage();
        if (errorMessage == null) {
            errorMessage = "Unknown error";
        }

        // Manually generate the Soap error response
        Element fault = responseElement.addElement(QName.get("Fault", "s", VtiSoapResponse.NAMESPACE));

        if ("1.2".equals(request.getVersion())) {
            // SOAP 1.2 is Code + Reason
            Element faultCode = fault.addElement(QName.get("Code", "s", VtiSoapResponse.NAMESPACE));
            Element faultCodeText = faultCode.addElement(QName.get("Value", "s", VtiSoapResponse.NAMESPACE));
            faultCodeText.addText("s:Server");

            Element faultReason = fault.addElement(QName.get("Reason", "s", VtiSoapResponse.NAMESPACE));
            Element faultReasonText = faultReason.addElement(QName.get("Text", "s", VtiSoapResponse.NAMESPACE));
            faultReasonText.addText("Exception of type '" + e.getClass().getName() + "' was thrown.");
        } else {
            // SOAP 1.1 is Code + String
            Element faultCode = fault.addElement("faultcode");
            faultCode.addText("s:Server");
            Element faultString = fault.addElement("faultstring");
            faultString.addText(e.getClass().getName());
        }

        // Both versions get the detail
        Element detail = fault.addElement("detail");
        Element errorstring = detail
                .addElement(QName.get("errorstring", "", "http://schemas.microsoft.com/sharepoint/soap/"));
        errorstring.addText(errorMessage);

        // Include the code if known
        if (e instanceof VtiSoapException) {
            VtiSoapException soapException = (VtiSoapException) e;
            if (soapException.getErrorCode() > 0) {
                Element errorcode = detail.addElement(
                        QName.get("errorcode", "", "http://schemas.microsoft.com/sharepoint/soap/"));

                // Codes need to be zero padded to 8 characters, eg 0x12345678
                String codeHex = Long.toHexString(soapException.getErrorCode());
                while (codeHex.length() < 8) {
                    codeHex = "0" + codeHex;
                }
                errorcode.addText("0x" + codeHex);
            }
        }
    }
}

From source file:org.alfresco.module.vti.web.ws.VtiSoapResponse.java

License:Open Source License

/**
  * Constructor/*from   w w  w . j av a 2  s.  c  o m*/
  * 
  * @param response HttpServletResponse 
  */
public VtiSoapResponse(HttpServletResponse response) {
    super(response);
    document = DocumentHelper.createDocument();
    Element envelope = document.addElement(QName.get("Envelope", "s", VtiSoapResponse.NAMESPACE));
    envelope.addElement(QName.get("Body", "s", VtiSoapResponse.NAMESPACE));
}