Example usage for org.w3c.dom Document createElementNS

List of usage examples for org.w3c.dom Document createElementNS

Introduction

In this page you can find the example usage for org.w3c.dom Document createElementNS.

Prototype

public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;

Source Link

Document

Creates an element of the given qualified name and namespace URI.

Usage

From source file:de.topobyte.livecg.core.painting.backend.svg.SvgPainter.java

public SvgPainter(Document doc, Element root) {
    this.doc = doc;
    this.root = root;

    defs = doc.createElementNS(svgNS, "defs");
    root.appendChild(defs);/*from w  w  w  .  ja  va  2  s . com*/
}

From source file:com.microsoft.windowsazure.management.sql.RecoverDatabaseOperationsImpl.java

/**
* Issues a recovery request for an Azure SQL Database.
*
* @param sourceServerName Required. The name of the Azure SQL Database
* Server on which the database was hosted.
* @param parameters Required. Additional parameters for the Create Recover
* Database Operation request./*www. ja va 2 s .  co m*/
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Contains the response to the Create Recover Database Operation
* request.
*/
@Override
public RecoverDatabaseOperationCreateResponse create(String sourceServerName,
        RecoverDatabaseOperationCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (sourceServerName == null) {
        throw new NullPointerException("sourceServerName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getSourceDatabaseName() == null) {
        throw new NullPointerException("parameters.SourceDatabaseName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("sourceServerName", sourceServerName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/sqlservers/servers/";
    url = url + URLEncoder.encode(sourceServerName, "UTF-8");
    url = url + "/recoverdatabaseoperations";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2012-03-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ServiceResource");
    requestDoc.appendChild(serviceResourceElement);

    Element sourceDatabaseNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "SourceDatabaseName");
    sourceDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getSourceDatabaseName()));
    serviceResourceElement.appendChild(sourceDatabaseNameElement);

    if (parameters.getTargetServerName() != null) {
        Element targetServerNameElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetServerName");
        targetServerNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetServerName()));
        serviceResourceElement.appendChild(targetServerNameElement);
    }

    if (parameters.getTargetDatabaseName() != null) {
        Element targetDatabaseNameElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetDatabaseName");
        targetDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetDatabaseName()));
        serviceResourceElement.appendChild(targetDatabaseNameElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_CREATED) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        RecoverDatabaseOperationCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new RecoverDatabaseOperationCreateResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResource");
            if (serviceResourceElement2 != null) {
                RecoverDatabaseOperation serviceResourceInstance = new RecoverDatabaseOperation();
                result.setOperation(serviceResourceInstance);

                Element requestIDElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "RequestID");
                if (requestIDElement != null) {
                    String requestIDInstance;
                    requestIDInstance = requestIDElement.getTextContent();
                    serviceResourceInstance.setId(requestIDInstance);
                }

                Element sourceDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName");
                if (sourceDatabaseNameElement2 != null) {
                    String sourceDatabaseNameInstance;
                    sourceDatabaseNameInstance = sourceDatabaseNameElement2.getTextContent();
                    serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance);
                }

                Element targetServerNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "TargetServerName");
                if (targetServerNameElement2 != null) {
                    String targetServerNameInstance;
                    targetServerNameInstance = targetServerNameElement2.getTextContent();
                    serviceResourceInstance.setTargetServerName(targetServerNameInstance);
                }

                Element targetDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "TargetDatabaseName");
                if (targetDatabaseNameElement2 != null) {
                    String targetDatabaseNameInstance;
                    targetDatabaseNameInstance = targetDatabaseNameElement2.getTextContent();
                    serviceResourceInstance.setTargetDatabaseName(targetDatabaseNameInstance);
                }

                Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    serviceResourceInstance.setName(nameInstance);
                }

                Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "Type");
                if (typeElement != null) {
                    String typeInstance;
                    typeInstance = typeElement.getTextContent();
                    serviceResourceInstance.setType(typeInstance);
                }

                Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "State");
                if (stateElement != null) {
                    String stateInstance;
                    stateInstance = stateElement.getTextContent();
                    serviceResourceInstance.setState(stateInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.idega.slide.util.WebdavLocalResource.java

private Element getEmptyElement() {
    if (emptyElement == null) {
        Document doc = XmlUtil.getXMLBuilder().newDocument();
        emptyElement = doc.createElementNS("DAV:", "resourcetype");
        emptyElement.appendChild(doc.createTextNode(CoreConstants.EMPTY));
    }/*from w  w  w .  j  a  v a2  s. c  o m*/
    return emptyElement;
}

From source file:org.openremote.beehive.configuration.www.UsersAPI.java

private void writeSensors(Document document, Element rootElement, Account account, Long offset) {
    Element sensorsElement = document.createElementNS(OPENREMOTE_NAMESPACE, "sensors");
    rootElement.appendChild(sensorsElement);

    Collection<Device> devices = account.getDevices();

    for (Device device : devices) {
        Collection<Sensor> sensors = device.getSensors();
        for (Sensor sensor : sensors) {
            Element sensorElement = document.createElementNS(OPENREMOTE_NAMESPACE, "sensor");
            sensorsElement.appendChild(sensorElement);
            sensorElement.setAttribute("id", Long.toString(sensor.getId() + offset));
            sensorElement.setAttribute("name", sensor.getName());
            sensorElement.setAttribute("type", sensor.getSensorType().toString().toLowerCase());

            Element includeElement = document.createElementNS(OPENREMOTE_NAMESPACE, "include");
            sensorElement.appendChild(includeElement);
            includeElement.setAttribute("type", "command");
            includeElement.setAttribute("ref",
                    Long.toString(sensor.getSensorCommandReference().getCommand().getId()));

            switch (sensor.getSensorType()) {
            case RANGE: {
                Element minElement = document.createElementNS(OPENREMOTE_NAMESPACE, "min");
                sensorElement.appendChild(minElement);
                minElement.setAttribute("value", Integer.toString(((RangeSensor) sensor).getMinValue()));

                Element maxElement = document.createElementNS(OPENREMOTE_NAMESPACE, "max");
                sensorElement.appendChild(maxElement);
                maxElement.setAttribute("value", Integer.toString(((RangeSensor) sensor).getMaxValue()));
                break;
            }/*from   w w w . j a  v  a 2s  . c  o m*/
            case SWITCH: {
                Element stateElement = document.createElementNS(OPENREMOTE_NAMESPACE, "state");
                sensorElement.appendChild(stateElement);
                stateElement.setAttribute("name", "on");

                stateElement = document.createElementNS(OPENREMOTE_NAMESPACE, "state");
                sensorElement.appendChild(stateElement);
                stateElement.setAttribute("name", "off");
                break;
            }
            case CUSTOM: {
                Collection<SensorState> states = sensor.getStates();
                for (SensorState state : states) {
                    Element stateElement = document.createElementNS(OPENREMOTE_NAMESPACE, "state");
                    sensorElement.appendChild(stateElement);
                    stateElement.setAttribute("name", state.getName());
                    stateElement.setAttribute("value", state.getValue());
                }
                break;
            }
            }
        }
    }
}

From source file:com.idega.slide.util.WebdavLocalResource.java

private Element getCollectionElement() {
    if (collectionElement == null) {
        Document doc = XmlUtil.getXMLBuilder().newDocument();
        collectionElement = doc.createElementNS("DAV:", "resourcetype");
        collectionElement.appendChild(doc.createElementNS("DAV:", "collection"));
    }/*from  w  ww. jav a 2 s. co m*/
    return collectionElement;
}

From source file:com.microsoft.windowsazure.management.sql.RestoreDatabaseOperationsImpl.java

/**
* Issues a restore request for an Azure SQL Database.
*
* @param sourceServerName Required. The name of the Azure SQL Database
* Server where the source database is, or was, hosted.
* @param parameters Required. Additional parameters for the Create Restore
* Database Operation request.// w ww. j  av a 2  s  .c o m
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Contains the response to the Create Restore Database Operation
* request.
*/
@Override
public RestoreDatabaseOperationCreateResponse create(String sourceServerName,
        RestoreDatabaseOperationCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (sourceServerName == null) {
        throw new NullPointerException("sourceServerName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getSourceDatabaseName() == null) {
        throw new NullPointerException("parameters.SourceDatabaseName");
    }
    if (parameters.getTargetDatabaseName() == null) {
        throw new NullPointerException("parameters.TargetDatabaseName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("sourceServerName", sourceServerName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/sqlservers/servers/";
    url = url + URLEncoder.encode(sourceServerName, "UTF-8");
    url = url + "/restoredatabaseoperations";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2012-03-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ServiceResource");
    requestDoc.appendChild(serviceResourceElement);

    Element sourceDatabaseNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "SourceDatabaseName");
    sourceDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getSourceDatabaseName()));
    serviceResourceElement.appendChild(sourceDatabaseNameElement);

    if (parameters.getSourceDatabaseDeletionDate() != null) {
        Element sourceDatabaseDeletionDateElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceDatabaseDeletionDate");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        sourceDatabaseDeletionDateElement.appendChild(requestDoc
                .createTextNode(simpleDateFormat.format(parameters.getSourceDatabaseDeletionDate().getTime())));
        serviceResourceElement.appendChild(sourceDatabaseDeletionDateElement);
    }

    if (parameters.getTargetServerName() != null) {
        Element targetServerNameElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetServerName");
        targetServerNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetServerName()));
        serviceResourceElement.appendChild(targetServerNameElement);
    }

    Element targetDatabaseNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "TargetDatabaseName");
    targetDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetDatabaseName()));
    serviceResourceElement.appendChild(targetDatabaseNameElement);

    if (parameters.getPointInTime() != null) {
        Element targetUtcPointInTimeElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetUtcPointInTime");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
        simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
        targetUtcPointInTimeElement.appendChild(
                requestDoc.createTextNode(simpleDateFormat2.format(parameters.getPointInTime().getTime())));
        serviceResourceElement.appendChild(targetUtcPointInTimeElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_CREATED) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        RestoreDatabaseOperationCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new RestoreDatabaseOperationCreateResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResource");
            if (serviceResourceElement2 != null) {
                RestoreDatabaseOperation serviceResourceInstance = new RestoreDatabaseOperation();
                result.setOperation(serviceResourceInstance);

                Element requestIDElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "RequestID");
                if (requestIDElement != null) {
                    String requestIDInstance;
                    requestIDInstance = requestIDElement.getTextContent();
                    serviceResourceInstance.setId(requestIDInstance);
                }

                Element sourceDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName");
                if (sourceDatabaseNameElement2 != null) {
                    String sourceDatabaseNameInstance;
                    sourceDatabaseNameInstance = sourceDatabaseNameElement2.getTextContent();
                    serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance);
                }

                Element sourceDatabaseDeletionDateElement2 = XmlUtility.getElementByTagNameNS(
                        serviceResourceElement2, "http://schemas.microsoft.com/windowsazure",
                        "SourceDatabaseDeletionDate");
                if (sourceDatabaseDeletionDateElement2 != null
                        && sourceDatabaseDeletionDateElement2.getTextContent() != null
                        && !sourceDatabaseDeletionDateElement2.getTextContent().isEmpty()) {
                    Calendar sourceDatabaseDeletionDateInstance;
                    sourceDatabaseDeletionDateInstance = DatatypeConverter
                            .parseDateTime(sourceDatabaseDeletionDateElement2.getTextContent());
                    serviceResourceInstance.setSourceDatabaseDeletionDate(sourceDatabaseDeletionDateInstance);
                }

                Element targetServerNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "TargetServerName");
                if (targetServerNameElement2 != null) {
                    String targetServerNameInstance;
                    targetServerNameInstance = targetServerNameElement2.getTextContent();
                    serviceResourceInstance.setTargetServerName(targetServerNameInstance);
                }

                Element targetDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "TargetDatabaseName");
                if (targetDatabaseNameElement2 != null) {
                    String targetDatabaseNameInstance;
                    targetDatabaseNameInstance = targetDatabaseNameElement2.getTextContent();
                    serviceResourceInstance.setTargetDatabaseName(targetDatabaseNameInstance);
                }

                Element targetUtcPointInTimeElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2,
                        "http://schemas.microsoft.com/windowsazure", "TargetUtcPointInTime");
                if (targetUtcPointInTimeElement2 != null) {
                    Calendar targetUtcPointInTimeInstance;
                    targetUtcPointInTimeInstance = DatatypeConverter
                            .parseDateTime(targetUtcPointInTimeElement2.getTextContent());
                    serviceResourceInstance.setPointInTime(targetUtcPointInTimeInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static Element createElement(Document document, QName qname) {
    Element element;/*  ww w .jav a 2 s  .c o  m*/
    //      String namespaceURI = qname.getNamespaceURI();
    //      if (StringUtils.isBlank(namespaceURI)) {
    //         element = document.createElement(qname.getLocalPart());
    //      } else {
    element = document.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
    //      }
    if (StringUtils.isNotEmpty(qname.getPrefix()) && StringUtils.isNotEmpty(qname.getNamespaceURI())) { // second part of the condition is because of wrong data in tests (undeclared prefixes in XPath expressions)
        element.setPrefix(qname.getPrefix());
    }
    return element;
}

From source file:net.bpelunit.util.XMLUtilTest.java

@Test
public void testGetQName() throws Exception {
    Document doc = XMLUtil.parseXML(getClass().getResourceAsStream("simple.xml"));
    Element root = doc.getDocumentElement();

    assertEquals(new QName("", "simple"), XMLUtil.getQName(root));
    assertEquals(new QName("", "b"), XMLUtil.getQName(doc.createElement("b")));
    assertEquals(new QName("a", "b"), XMLUtil.getQName(doc.createElementNS("a", "b")));
}

From source file:com.urbancode.x2o.xml.XmlWrite.java

public void makeXml(Object object, Document doc, Element parent) throws IllegalArgumentException,
        IllegalAccessException, InvocationTargetException, ClassNotFoundException {
    String className = object.getClass().getCanonicalName();
    String nameSpace = persistConf.getNameSpaceForClassName(className);

    String prefix = persistConf.getPrefixForNameSpace(nameSpace);

    String elemName = persistConf.getElementForClassName(className);
    Element element = doc.createElementNS(nameSpace, prefix + ":" + elemName);

    if (parent == null) {
        doc.appendChild(element);/*from w w w. j a va2 s  .c  o m*/
    } else {
        parent.appendChild(element);
    }

    List<Method> methods = findMethodsForClass("get", object.getClass());
    for (Method method : methods) {
        Object methodResult = method.invoke(object);

        // if the result is a list of Tasks,
        // then iterate through each one and write it out as a sub-element
        if (methodResult instanceof List<?>) {
            for (Task nextTask : (List<Task>) methodResult) {
                makeXml(nextTask, doc, element);
            }
        }
        // if the result is a Task,
        // then write it out as a sub-element
        else if (methodResult instanceof Task) {
            makeXml(methodResult, doc, element);
        }
        // if the result is not any of the above,
        // then write it out as an attribute
        else {
            String attrName = method.getName();
            attrName = attrName.replaceFirst("get", "");
            attrName = convertFromCamelCase(attrName);
            if (methodResult == null || "null".equals(methodResult)) {
                methodResult = "";
            }
            String resultString = methodResult.toString();
            element.setAttribute(attrName, resultString);
        }
    }
}

From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandlerTest.java

private Node makeEntityResolutionConfigurationNode(String limit) throws Exception {
    try {/* w ww  . j  a  va2  s . c  o  m*/
        if (Integer.parseInt(limit) == Integer.MAX_VALUE) {
            return null;
        }
    } catch (NumberFormatException nfe) {
        return null;
    }
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document d = db.newDocument();
    Element ret = d.createElementNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE,
            "EntityResolutionConfiguration");
    d.appendChild(ret);
    Element e = d.createElementNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE, "RecordLimit");
    ret.appendChild(e);
    e.setTextContent(limit);
    return ret;
}