Example usage for org.w3c.dom Element getTextContent

List of usage examples for org.w3c.dom Element getTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element getTextContent.

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:com.microsoft.windowsazure.management.SubscriptionOperationsImpl.java

/**
* The Get Subscription operation returns account and resource allocation
* information for the specified subscription.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/hh403995.aspx for
* more information)//from  www . java 2  s . c o  m
*
* @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.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Get Subscription operation response.
*/
@Override
public SubscriptionGetResponse get()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

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

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    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
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2014-10-01");

    // 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_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element subscriptionElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Subscription");
            if (subscriptionElement != null) {
                Element subscriptionIDElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionID");
                if (subscriptionIDElement != null) {
                    String subscriptionIDInstance;
                    subscriptionIDInstance = subscriptionIDElement.getTextContent();
                    result.setSubscriptionID(subscriptionIDInstance);
                }

                Element subscriptionNameElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionName");
                if (subscriptionNameElement != null) {
                    String subscriptionNameInstance;
                    subscriptionNameInstance = subscriptionNameElement.getTextContent();
                    result.setSubscriptionName(subscriptionNameInstance);
                }

                Element subscriptionStatusElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "SubscriptionStatus");
                if (subscriptionStatusElement != null && subscriptionStatusElement.getTextContent() != null
                        && !subscriptionStatusElement.getTextContent().isEmpty()) {
                    SubscriptionStatus subscriptionStatusInstance;
                    subscriptionStatusInstance = SubscriptionStatus
                            .valueOf(subscriptionStatusElement.getTextContent());
                    result.setSubscriptionStatus(subscriptionStatusInstance);
                }

                Element accountAdminLiveEmailIdElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "AccountAdminLiveEmailId");
                if (accountAdminLiveEmailIdElement != null) {
                    String accountAdminLiveEmailIdInstance;
                    accountAdminLiveEmailIdInstance = accountAdminLiveEmailIdElement.getTextContent();
                    result.setAccountAdminLiveEmailId(accountAdminLiveEmailIdInstance);
                }

                Element serviceAdminLiveEmailIdElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "ServiceAdminLiveEmailId");
                if (serviceAdminLiveEmailIdElement != null) {
                    String serviceAdminLiveEmailIdInstance;
                    serviceAdminLiveEmailIdInstance = serviceAdminLiveEmailIdElement.getTextContent();
                    result.setServiceAdminLiveEmailId(serviceAdminLiveEmailIdInstance);
                }

                Element maxCoreCountElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxCoreCount");
                if (maxCoreCountElement != null) {
                    int maxCoreCountInstance;
                    maxCoreCountInstance = DatatypeConverter.parseInt(maxCoreCountElement.getTextContent());
                    result.setMaximumCoreCount(maxCoreCountInstance);
                }

                Element maxStorageAccountsElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxStorageAccounts");
                if (maxStorageAccountsElement != null) {
                    int maxStorageAccountsInstance;
                    maxStorageAccountsInstance = DatatypeConverter
                            .parseInt(maxStorageAccountsElement.getTextContent());
                    result.setMaximumStorageAccounts(maxStorageAccountsInstance);
                }

                Element maxHostedServicesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxHostedServices");
                if (maxHostedServicesElement != null) {
                    int maxHostedServicesInstance;
                    maxHostedServicesInstance = DatatypeConverter
                            .parseInt(maxHostedServicesElement.getTextContent());
                    result.setMaximumHostedServices(maxHostedServicesInstance);
                }

                Element currentCoreCountElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentCoreCount");
                if (currentCoreCountElement != null) {
                    int currentCoreCountInstance;
                    currentCoreCountInstance = DatatypeConverter
                            .parseInt(currentCoreCountElement.getTextContent());
                    result.setCurrentCoreCount(currentCoreCountInstance);
                }

                Element currentStorageAccountsElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentStorageAccounts");
                if (currentStorageAccountsElement != null) {
                    int currentStorageAccountsInstance;
                    currentStorageAccountsInstance = DatatypeConverter
                            .parseInt(currentStorageAccountsElement.getTextContent());
                    result.setCurrentStorageAccounts(currentStorageAccountsInstance);
                }

                Element currentHostedServicesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentHostedServices");
                if (currentHostedServicesElement != null) {
                    int currentHostedServicesInstance;
                    currentHostedServicesInstance = DatatypeConverter
                            .parseInt(currentHostedServicesElement.getTextContent());
                    result.setCurrentHostedServices(currentHostedServicesInstance);
                }

                Element maxVirtualNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxVirtualNetworkSites");
                if (maxVirtualNetworkSitesElement != null) {
                    int maxVirtualNetworkSitesInstance;
                    maxVirtualNetworkSitesInstance = DatatypeConverter
                            .parseInt(maxVirtualNetworkSitesElement.getTextContent());
                    result.setMaximumVirtualNetworkSites(maxVirtualNetworkSitesInstance);
                }

                Element currentVirtualNetworkSitesElement = XmlUtility.getElementByTagNameNS(
                        subscriptionElement, "http://schemas.microsoft.com/windowsazure",
                        "CurrentVirtualNetworkSites");
                if (currentVirtualNetworkSitesElement != null) {
                    int currentVirtualNetworkSitesInstance;
                    currentVirtualNetworkSitesInstance = DatatypeConverter
                            .parseInt(currentVirtualNetworkSitesElement.getTextContent());
                    result.setCurrentVirtualNetworkSites(currentVirtualNetworkSitesInstance);
                }

                Element maxLocalNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxLocalNetworkSites");
                if (maxLocalNetworkSitesElement != null) {
                    int maxLocalNetworkSitesInstance;
                    maxLocalNetworkSitesInstance = DatatypeConverter
                            .parseInt(maxLocalNetworkSitesElement.getTextContent());
                    result.setMaximumLocalNetworkSites(maxLocalNetworkSitesInstance);
                }

                Element maxDnsServersElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "MaxDnsServers");
                if (maxDnsServersElement != null) {
                    int maxDnsServersInstance;
                    maxDnsServersInstance = DatatypeConverter.parseInt(maxDnsServersElement.getTextContent());
                    result.setMaximumDnsServers(maxDnsServersInstance);
                }

                Element currentLocalNetworkSitesElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentLocalNetworkSites");
                if (currentLocalNetworkSitesElement != null) {
                    int currentLocalNetworkSitesInstance;
                    currentLocalNetworkSitesInstance = DatatypeConverter
                            .parseInt(currentLocalNetworkSitesElement.getTextContent());
                    result.setCurrentLocalNetworkSites(currentLocalNetworkSitesInstance);
                }

                Element currentDnsServersElement = XmlUtility.getElementByTagNameNS(subscriptionElement,
                        "http://schemas.microsoft.com/windowsazure", "CurrentDnsServers");
                if (currentDnsServersElement != null) {
                    int currentDnsServersInstance;
                    currentDnsServersInstance = DatatypeConverter
                            .parseInt(currentDnsServersElement.getTextContent());
                    result.setCurrentDnsServers(currentDnsServersInstance);
                }
            }

        }
        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.clican.pluto.dataprocess.spring.parser.DplExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    this.setBeanDefinitionStringProperty("resultName", beanDef, element);

    String dplStatement = element.getAttribute("dplStatement");
    if (StringUtils.isEmpty(dplStatement)) {
        dplStatement = "dplStatement";
    }//from   ww w  . java 2s  .co m
    String clazz = element.getAttribute("clazz");
    if (StringUtils.isNotEmpty(clazz)) {
        try {
            Class c = Class.forName(clazz);
            beanDef.getPropertyValues().addPropertyValue("clazz", c);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    String singleRow = element.getAttribute("singleRow");
    if (StringUtils.isNotEmpty(singleRow)) {
        beanDef.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
    }
    String traces = element.getAttribute("traces");
    if (StringUtils.isNotEmpty(traces)) {
        List<String> traceList = new ArrayList<String>();
        for (String trace : traces.split(",")) {
            traceList.add(trace.trim());
        }
        beanDef.getPropertyValues().addPropertyValue("traces", traceList);
    }
    beanDef.getPropertyValues().addPropertyValue("dplStatement", new RuntimeBeanReference(dplStatement));
    beanDef.getPropertyValues().addPropertyValue("dpl", element.getTextContent().trim());
}

From source file:com.cloud.test.stress.TestClientWithAPI.java

public static Element queryAsyncJobResult(String host, InputStream inputStream) {
    Element returnBody = null;/*from w w w . j a  v a 2s  . c om*/

    Map<String, String> values = getSingleValueFromXML(inputStream, new String[] { "jobid" });
    String jobId = values.get("jobid");

    if (jobId == null) {
        s_logger.error("Unable to get a jobId");
        return null;
    }

    // s_logger.info("Job id is " + jobId);
    String resultUrl = host + "?command=queryAsyncJobResult&jobid=" + jobId;
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(resultUrl);
    while (true) {
        try {
            client.executeMethod(method);
            // s_logger.info("Method is executed successfully. Following url was sent " + resultUrl);
            InputStream is = method.getResponseBodyAsStream();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(is);
            returnBody = doc.getDocumentElement();
            doc.getDocumentElement().normalize();
            Element jobStatusTag = (Element) returnBody.getElementsByTagName("jobstatus").item(0);
            String jobStatus = jobStatusTag.getTextContent();
            if (jobStatus.equals("0")) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            } else {
                break;
            }

        } catch (Exception ex) {
            s_logger.error(ex);
        }
    }
    return returnBody;
}

From source file:com.microsoft.windowsazure.management.servicebus.NotificationHubOperationsImpl.java

/**
* Lists the notification hubs associated with a namespace.
*
* @param namespaceName Required. The namespace name.
* @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.//from ww w  .  ja  v  a  2  s .  com
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public ServiceBusNotificationHubsResponse list(String namespaceName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

    // 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("namespaceName", namespaceName);
        CloudTracing.enter(invocationId, this, "listAsync", 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/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/NotificationHubs";
    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
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2013-08-01");

    // 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_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element feedElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "feed");
            if (feedElement != null) {
                if (feedElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element entriesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(feedElement, "http://www.w3.org/2005/Atom", "entry")
                                .get(i1));
                        ServiceBusNotificationHub entryInstance = new ServiceBusNotificationHub();
                        result.getNotificationHubs().add(entryInstance);

                        Element titleElement = XmlUtility.getElementByTagNameNS(entriesElement,
                                "http://www.w3.org/2005/Atom", "title");
                        if (titleElement != null) {
                            String titleInstance;
                            titleInstance = titleElement.getTextContent();
                            entryInstance.setName(titleInstance);
                        }

                        Element contentElement = XmlUtility.getElementByTagNameNS(entriesElement,
                                "http://www.w3.org/2005/Atom", "content");
                        if (contentElement != null) {
                            Element notificationHubDescriptionElement = XmlUtility.getElementByTagNameNS(
                                    contentElement,
                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                    "NotificationHubDescription");
                            if (notificationHubDescriptionElement != null) {
                                Element registrationTtlElement = XmlUtility.getElementByTagNameNS(
                                        notificationHubDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "RegistrationTtl");
                                if (registrationTtlElement != null) {
                                    String registrationTtlInstance;
                                    registrationTtlInstance = registrationTtlElement.getTextContent();
                                    entryInstance.setRegistrationTtl(registrationTtlInstance);
                                }

                                Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                                        notificationHubDescriptionElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "AuthorizationRules");
                                if (authorizationRulesSequenceElement != null) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                    "AuthorizationRule")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                        "AuthorizationRule")
                                                .get(i2));
                                        ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule();
                                        entryInstance.getAuthorizationRules().add(authorizationRuleInstance);

                                        Element claimTypeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ClaimType");
                                        if (claimTypeElement != null) {
                                            String claimTypeInstance;
                                            claimTypeInstance = claimTypeElement.getTextContent();
                                            authorizationRuleInstance.setClaimType(claimTypeInstance);
                                        }

                                        Element claimValueElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ClaimValue");
                                        if (claimValueElement != null) {
                                            String claimValueInstance;
                                            claimValueInstance = claimValueElement.getTextContent();
                                            authorizationRuleInstance.setClaimValue(claimValueInstance);
                                        }

                                        Element rightsSequenceElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "Rights");
                                        if (rightsSequenceElement != null) {
                                            for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                                                    .getElementsByTagNameNS(rightsSequenceElement,
                                                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                            "AccessRights")
                                                    .size(); i3 = i3 + 1) {
                                                org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                        .getElementsByTagNameNS(rightsSequenceElement,
                                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                                "AccessRights")
                                                        .get(i3));
                                                authorizationRuleInstance.getRights().add(
                                                        AccessRight.valueOf(rightsElement.getTextContent()));
                                            }
                                        }

                                        Element createdTimeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "CreatedTime");
                                        if (createdTimeElement != null) {
                                            Calendar createdTimeInstance;
                                            createdTimeInstance = DatatypeConverter
                                                    .parseDateTime(createdTimeElement.getTextContent());
                                            authorizationRuleInstance.setCreatedTime(createdTimeInstance);
                                        }

                                        Element keyNameElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "KeyName");
                                        if (keyNameElement != null) {
                                            String keyNameInstance;
                                            keyNameInstance = keyNameElement.getTextContent();
                                            authorizationRuleInstance.setKeyName(keyNameInstance);
                                        }

                                        Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "ModifiedTime");
                                        if (modifiedTimeElement != null) {
                                            Calendar modifiedTimeInstance;
                                            modifiedTimeInstance = DatatypeConverter
                                                    .parseDateTime(modifiedTimeElement.getTextContent());
                                            authorizationRuleInstance.setModifiedTime(modifiedTimeInstance);
                                        }

                                        Element primaryKeyElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "PrimaryKey");
                                        if (primaryKeyElement != null) {
                                            String primaryKeyInstance;
                                            primaryKeyInstance = primaryKeyElement.getTextContent();
                                            authorizationRuleInstance.setPrimaryKey(primaryKeyInstance);
                                        }

                                        Element secondaryKeyElement = XmlUtility.getElementByTagNameNS(
                                                authorizationRulesElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "SecondaryKey");
                                        if (secondaryKeyElement != null) {
                                            String secondaryKeyInstance;
                                            secondaryKeyInstance = secondaryKeyElement.getTextContent();
                                            authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

        }
        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.microsoft.windowsazure.management.compute.ServiceCertificateOperationsImpl.java

/**
* The List Service Certificates operation lists all of the service
* certificates associated with the specified hosted service.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154105.aspx for
* more information)//from   w  w w  . j a v a 2s.c o m
*
* @param serviceName Required. The DNS prefix name of your hosted service.
* @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.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Service Certificates operation response.
*/
@Override
public ServiceCertificateListResponse list(String serviceName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (serviceName == null) {
        throw new NullPointerException("serviceName");
    }
    // TODO: Validate serviceName is a valid DNS name.

    // 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("serviceName", serviceName);
        CloudTracing.enter(invocationId, this, "listAsync", 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/hostedservices/";
    url = url + URLEncoder.encode(serviceName, "UTF-8");
    url = url + "/certificates";
    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
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2015-04-01");

    // 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_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element certificatesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Certificates");
            if (certificatesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(certificatesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "Certificate")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element certificatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(certificatesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Certificate")
                            .get(i1));
                    ServiceCertificateListResponse.Certificate certificateInstance = new ServiceCertificateListResponse.Certificate();
                    result.getCertificates().add(certificateInstance);

                    Element certificateUrlElement = XmlUtility.getElementByTagNameNS(certificatesElement,
                            "http://schemas.microsoft.com/windowsazure", "CertificateUrl");
                    if (certificateUrlElement != null) {
                        URI certificateUrlInstance;
                        certificateUrlInstance = new URI(certificateUrlElement.getTextContent());
                        certificateInstance.setCertificateUri(certificateUrlInstance);
                    }

                    Element thumbprintElement = XmlUtility.getElementByTagNameNS(certificatesElement,
                            "http://schemas.microsoft.com/windowsazure", "Thumbprint");
                    if (thumbprintElement != null) {
                        String thumbprintInstance;
                        thumbprintInstance = thumbprintElement.getTextContent();
                        certificateInstance.setThumbprint(thumbprintInstance);
                    }

                    Element thumbprintAlgorithmElement = XmlUtility.getElementByTagNameNS(certificatesElement,
                            "http://schemas.microsoft.com/windowsazure", "ThumbprintAlgorithm");
                    if (thumbprintAlgorithmElement != null) {
                        String thumbprintAlgorithmInstance;
                        thumbprintAlgorithmInstance = thumbprintAlgorithmElement.getTextContent();
                        certificateInstance.setThumbprintAlgorithm(thumbprintAlgorithmInstance);
                    }

                    Element dataElement = XmlUtility.getElementByTagNameNS(certificatesElement,
                            "http://schemas.microsoft.com/windowsazure", "Data");
                    if (dataElement != null) {
                        byte[] dataInstance;
                        dataInstance = dataElement.getTextContent() != null
                                ? Base64.decode(dataElement.getTextContent())
                                : null;
                        certificateInstance.setData(dataInstance);
                    }
                }
            }

        }
        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.microsoft.windowsazure.management.sql.ServerOperationsImpl.java

/**
* Provisions a new SQL Database server in a subscription.
*
* @param parameters Required. The parameters needed to provision a server.
* @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./* w w  w  . j  a v a  2s  . c om*/
* @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 The response returned from the Create Server operation.  This
* contains all the information returned from the service when a server is
* created.
*/
@Override
public ServerCreateResponse create(ServerCreateParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getAdministratorPassword() == null) {
        throw new NullPointerException("parameters.AdministratorPassword");
    }
    if (parameters.getAdministratorUserName() == null) {
        throw new NullPointerException("parameters.AdministratorUserName");
    }
    if (parameters.getLocation() == null) {
        throw new NullPointerException("parameters.Location");
    }

    // 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("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";
    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 serverElement = requestDoc.createElementNS("http://schemas.microsoft.com/sqlazure/2010/12/",
            "Server");
    requestDoc.appendChild(serverElement);

    Element administratorLoginElement = requestDoc
            .createElementNS("http://schemas.microsoft.com/sqlazure/2010/12/", "AdministratorLogin");
    administratorLoginElement.appendChild(requestDoc.createTextNode(parameters.getAdministratorUserName()));
    serverElement.appendChild(administratorLoginElement);

    Element administratorLoginPasswordElement = requestDoc
            .createElementNS("http://schemas.microsoft.com/sqlazure/2010/12/", "AdministratorLoginPassword");
    administratorLoginPasswordElement
            .appendChild(requestDoc.createTextNode(parameters.getAdministratorPassword()));
    serverElement.appendChild(administratorLoginPasswordElement);

    Element locationElement = requestDoc.createElementNS("http://schemas.microsoft.com/sqlazure/2010/12/",
            "Location");
    locationElement.appendChild(requestDoc.createTextNode(parameters.getLocation()));
    serverElement.appendChild(locationElement);

    if (parameters.getVersion() != null) {
        Element versionElement = requestDoc.createElementNS("http://schemas.microsoft.com/sqlazure/2010/12/",
                "Version");
        versionElement.appendChild(requestDoc.createTextNode(parameters.getVersion()));
        serverElement.appendChild(versionElement);
    }

    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
        ServerCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_CREATED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServerCreateResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element serverNameElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/sqlazure/2010/12/", "ServerName");
            if (serverNameElement != null) {
                Attr fullyQualifiedDomainNameAttribute = serverNameElement.getAttributeNodeNS(
                        "http://schemas.microsoft.com/sqlazure/2010/12/", "FullyQualifiedDomainName");
                if (fullyQualifiedDomainNameAttribute != null) {
                    result.setFullyQualifiedDomainName(fullyQualifiedDomainNameAttribute.getValue());
                }

                result.setServerName(serverNameElement.getTextContent());
            }

        }
        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.testing.model.client.sample.AbstractTestForExchangeConnector.java

protected Map<String, Object> getAttributesAsMap(ShadowType shadowType) {
    Map<String, Object> rv = new HashMap<>();

    ShadowAttributesType attributes = shadowType.getAttributes();
    for (Object item : attributes.getAny()) {
        if (item instanceof Element) {
            Element e = (Element) item;
            put(rv, e.getLocalName(), e.getTextContent());
        } else if (item instanceof JAXBElement) {
            JAXBElement je = (JAXBElement) item;
            put(rv, je.getName().getLocalPart(), je.getValue());
        } else {//from   w  w w .  j  ava 2  s  .c  om
            // nothing to do here
        }
    }
    return rv;
}

From source file:com.canappi.connector.yp.yhere.CouponView.java

public void fetchDataFromypCoupons(Object orows) {

    HashMap<String, String> map = new HashMap<String, String>();
    map.put("couponDescription", "coupons.couponDescription");
    map.put("businessName", "businessName");
    map.put("couponId", "couponId");
    map.put("phoneNumber", "phone");
    map.put("street", "street");
    map.put("city", "city");
    map.put("call", "call");

    ArrayList<Element> rows = (ArrayList<Element>) orows;
    if (rows != null) {
        if (rows.size() > 0) {
            String key = "";
            String subkey = "";

            //Init from Web API Data
            // couponsLayout 
            //Initializing results
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@6dc57a92 (name: businessName, text: name, font: Helvetica-Bold, size: 14, alignment: Left, lines: null)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("businessName");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }/*w w w .  j  a  v a2 s  .c  o  m*/
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    businessNameArray.add((String) object);
                } else {
                    businessNameArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@7d206f0 (name: couponDescription, text: coupon, font: null, size: null, alignment: Left, lines: 3)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("couponDescription");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    couponDescriptionArray.add((String) object);
                } else {
                    couponDescriptionArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@51d92803 (name: couponId, text: id, font: null, size: null, alignment: Left, lines: null)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("couponId");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    couponIdArray.add((String) object);
                } else {
                    couponIdArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.TextImpl@744957c7 (name: phoneNumber, defaultText: null, font: null, size: null, alignment: Left, readOnly: false, hasClearButton: false, clearButtonMode: Never, isSecure: false, textEntry: textEntry, isAutocomplete: false, lines: null, placeHolder: null, orientation: right, buttonMode: Never, border: none)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("phoneNumber");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    phoneNumberArray.add((String) object);
                } else {
                    phoneNumberArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.ButtonImpl@24065c4 (name: call, title: , titleSelected: null, style: Bordered, gradientStyle: Alert, image: phone.png, selectedImage: null, font: null, size: null, isStandard: None)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("call");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    callArray.add((String) object);
                } else {
                    callArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@30c3bb57 (name: street, text: id, font: null, size: null, alignment: Left, lines: null)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("street");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    streetArray.add((String) object);
                } else {
                    streetArray.add("");
                }

            }
            //Processing com.canappi.metamodels.mdsl.mDsl.impl.LabelImpl@40f186b8 (name: city, text: id, font: Helvetica-Oblique, size: 10, alignment: Left, lines: null)
            //if (rows.size()>0) {

            for (int i = 0; i < rows.size(); i++) {
                Element row = (Element) rows.get(i);
                Object object = null;

                key = map.get("city");
                int r = key.indexOf(".");
                if (r < 0) {
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element e = (Element) nodes.item(0);
                        object = e.getTextContent();
                    } else {
                        object = "";
                    }
                } else {

                    String[] elementNames;
                    elementNames = key.split("\\.");
                    key = elementNames[0];
                    subkey = elementNames[elementNames.length - 1];
                    NodeList nodes = row.getElementsByTagName(key);
                    if (nodes.getLength() > 0) {
                        Element rootElement = (Element) nodes.item(0);
                        NodeList subnodes = rootElement.getElementsByTagName(subkey);
                        if (subnodes.getLength() > 0) {
                            Element e = (Element) subnodes.item(0);
                            object = e.getTextContent();
                        } else {
                            //We need to look one level deeper (but not more)
                            subnodes = rootElement.getChildNodes();
                            object = "";
                            for (int k = 0; k < subnodes.getLength(); k++) {
                                Element e = (Element) subnodes.item(k);
                                NodeList otherNodes = e.getElementsByTagName(subkey);
                                if (otherNodes.getLength() > 0) {
                                    Element sube = (Element) otherNodes.item(0);
                                    object = sube.getTextContent();
                                }
                            }
                        }
                    } else {
                        object = "";
                    }

                }
                if (object != null) {
                    cityArray.add((String) object);
                } else {
                    cityArray.add("");
                }

            }
        }
    }

}

From source file:com.microsoft.windowsazure.management.network.NetworkOperationsImpl.java

/**
* The List Virtual network sites operation retrieves the virtual networks
* configured for the subscription.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157185.aspx for
* more information)/*from  w w w .  java2  s  . co  m*/
*
* @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.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response structure for the Network Operations List operation.
*/
@Override
public NetworkListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        CloudTracing.enter(invocationId, this, "listAsync", 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/networking/virtualnetwork";
    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
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2015-04-01");

    // 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_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element virtualNetworkSitesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "VirtualNetworkSites");
            if (virtualNetworkSitesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(virtualNetworkSitesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "VirtualNetworkSite")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element virtualNetworkSitesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(virtualNetworkSitesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "VirtualNetworkSite")
                            .get(i1));
                    NetworkListResponse.VirtualNetworkSite virtualNetworkSiteInstance = new NetworkListResponse.VirtualNetworkSite();
                    result.getVirtualNetworkSites().add(virtualNetworkSiteInstance);

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

                    Element labelElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Label");
                    if (labelElement != null) {
                        String labelInstance;
                        labelInstance = labelElement.getTextContent();
                        virtualNetworkSiteInstance.setLabel(labelInstance);
                    }

                    Element idElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Id");
                    if (idElement != null) {
                        String idInstance;
                        idInstance = idElement.getTextContent();
                        virtualNetworkSiteInstance.setId(idInstance);
                    }

                    Element affinityGroupElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                    if (affinityGroupElement != null) {
                        String affinityGroupInstance;
                        affinityGroupInstance = affinityGroupElement.getTextContent();
                        virtualNetworkSiteInstance.setAffinityGroup(affinityGroupInstance);
                    }

                    Element locationElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Location");
                    if (locationElement != null) {
                        String locationInstance;
                        locationInstance = locationElement.getTextContent();
                        virtualNetworkSiteInstance.setLocation(locationInstance);
                    }

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

                    Element addressSpaceElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "AddressSpace");
                    if (addressSpaceElement != null) {
                        NetworkListResponse.AddressSpace addressSpaceInstance = new NetworkListResponse.AddressSpace();
                        virtualNetworkSiteInstance.setAddressSpace(addressSpaceInstance);

                        Element addressPrefixesSequenceElement = XmlUtility.getElementByTagNameNS(
                                addressSpaceElement, "http://schemas.microsoft.com/windowsazure",
                                "AddressPrefixes");
                        if (addressPrefixesSequenceElement != null) {
                            for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(addressPrefixesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "AddressPrefix")
                                    .size(); i2 = i2 + 1) {
                                org.w3c.dom.Element addressPrefixesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(addressPrefixesSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "AddressPrefix")
                                        .get(i2));
                                addressSpaceInstance.getAddressPrefixes()
                                        .add(addressPrefixesElement.getTextContent());
                            }
                        }
                    }

                    Element subnetsSequenceElement = XmlUtility.getElementByTagNameNS(
                            virtualNetworkSitesElement, "http://schemas.microsoft.com/windowsazure", "Subnets");
                    if (subnetsSequenceElement != null) {
                        for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(subnetsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "Subnet")
                                .size(); i3 = i3 + 1) {
                            org.w3c.dom.Element subnetsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(subnetsSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "Subnet")
                                    .get(i3));
                            NetworkListResponse.Subnet subnetInstance = new NetworkListResponse.Subnet();
                            virtualNetworkSiteInstance.getSubnets().add(subnetInstance);

                            Element nameElement2 = XmlUtility.getElementByTagNameNS(subnetsElement,
                                    "http://schemas.microsoft.com/windowsazure", "Name");
                            if (nameElement2 != null) {
                                String nameInstance2;
                                nameInstance2 = nameElement2.getTextContent();
                                subnetInstance.setName(nameInstance2);
                            }

                            Element addressPrefixElement = XmlUtility.getElementByTagNameNS(subnetsElement,
                                    "http://schemas.microsoft.com/windowsazure", "AddressPrefix");
                            if (addressPrefixElement != null) {
                                String addressPrefixInstance;
                                addressPrefixInstance = addressPrefixElement.getTextContent();
                                subnetInstance.setAddressPrefix(addressPrefixInstance);
                            }

                            Element networkSecurityGroupElement = XmlUtility.getElementByTagNameNS(
                                    subnetsElement, "http://schemas.microsoft.com/windowsazure",
                                    "NetworkSecurityGroup");
                            if (networkSecurityGroupElement != null) {
                                String networkSecurityGroupInstance;
                                networkSecurityGroupInstance = networkSecurityGroupElement.getTextContent();
                                subnetInstance.setNetworkSecurityGroup(networkSecurityGroupInstance);
                            }
                        }
                    }

                    Element dnsElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Dns");
                    if (dnsElement != null) {
                        Element dnsServersSequenceElement = XmlUtility.getElementByTagNameNS(dnsElement,
                                "http://schemas.microsoft.com/windowsazure", "DnsServers");
                        if (dnsServersSequenceElement != null) {
                            for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(dnsServersSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "DnsServer")
                                    .size(); i4 = i4 + 1) {
                                org.w3c.dom.Element dnsServersElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(dnsServersSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "DnsServer")
                                        .get(i4));
                                NetworkListResponse.DnsServer dnsServerInstance = new NetworkListResponse.DnsServer();
                                virtualNetworkSiteInstance.getDnsServers().add(dnsServerInstance);

                                Element nameElement3 = XmlUtility.getElementByTagNameNS(dnsServersElement,
                                        "http://schemas.microsoft.com/windowsazure", "Name");
                                if (nameElement3 != null) {
                                    String nameInstance3;
                                    nameInstance3 = nameElement3.getTextContent();
                                    dnsServerInstance.setName(nameInstance3);
                                }

                                Element addressElement = XmlUtility.getElementByTagNameNS(dnsServersElement,
                                        "http://schemas.microsoft.com/windowsazure", "Address");
                                if (addressElement != null) {
                                    InetAddress addressInstance;
                                    addressInstance = InetAddress.getByName(addressElement.getTextContent());
                                    dnsServerInstance.setAddress(addressInstance);
                                }
                            }
                        }
                    }

                    Element gatewayElement = XmlUtility.getElementByTagNameNS(virtualNetworkSitesElement,
                            "http://schemas.microsoft.com/windowsazure", "Gateway");
                    if (gatewayElement != null) {
                        NetworkListResponse.Gateway gatewayInstance = new NetworkListResponse.Gateway();
                        virtualNetworkSiteInstance.setGateway(gatewayInstance);

                        Element profileElement = XmlUtility.getElementByTagNameNS(gatewayElement,
                                "http://schemas.microsoft.com/windowsazure", "Profile");
                        if (profileElement != null) {
                            String profileInstance;
                            profileInstance = profileElement.getTextContent();
                            gatewayInstance.setProfile(profileInstance);
                        }

                        Element sitesSequenceElement = XmlUtility.getElementByTagNameNS(gatewayElement,
                                "http://schemas.microsoft.com/windowsazure", "Sites");
                        if (sitesSequenceElement != null) {
                            for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(sitesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "LocalNetworkSite")
                                    .size(); i5 = i5 + 1) {
                                org.w3c.dom.Element sitesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(sitesSequenceElement,
                                                "http://schemas.microsoft.com/windowsazure", "LocalNetworkSite")
                                        .get(i5));
                                NetworkListResponse.LocalNetworkSite localNetworkSiteInstance = new NetworkListResponse.LocalNetworkSite();
                                gatewayInstance.getSites().add(localNetworkSiteInstance);

                                Element nameElement4 = XmlUtility.getElementByTagNameNS(sitesElement,
                                        "http://schemas.microsoft.com/windowsazure", "Name");
                                if (nameElement4 != null) {
                                    String nameInstance4;
                                    nameInstance4 = nameElement4.getTextContent();
                                    localNetworkSiteInstance.setName(nameInstance4);
                                }

                                Element vpnGatewayAddressElement = XmlUtility.getElementByTagNameNS(
                                        sitesElement, "http://schemas.microsoft.com/windowsazure",
                                        "VpnGatewayAddress");
                                if (vpnGatewayAddressElement != null) {
                                    InetAddress vpnGatewayAddressInstance;
                                    vpnGatewayAddressInstance = InetAddress
                                            .getByName(vpnGatewayAddressElement.getTextContent());
                                    localNetworkSiteInstance.setVpnGatewayAddress(vpnGatewayAddressInstance);
                                }

                                Element addressSpaceElement2 = XmlUtility.getElementByTagNameNS(sitesElement,
                                        "http://schemas.microsoft.com/windowsazure", "AddressSpace");
                                if (addressSpaceElement2 != null) {
                                    NetworkListResponse.AddressSpace addressSpaceInstance2 = new NetworkListResponse.AddressSpace();
                                    localNetworkSiteInstance.setAddressSpace(addressSpaceInstance2);

                                    Element addressPrefixesSequenceElement2 = XmlUtility.getElementByTagNameNS(
                                            addressSpaceElement2, "http://schemas.microsoft.com/windowsazure",
                                            "AddressPrefixes");
                                    if (addressPrefixesSequenceElement2 != null) {
                                        for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(addressPrefixesSequenceElement2,
                                                        "http://schemas.microsoft.com/windowsazure",
                                                        "AddressPrefix")
                                                .size(); i6 = i6 + 1) {
                                            org.w3c.dom.Element addressPrefixesElement2 = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                    .getElementsByTagNameNS(addressPrefixesSequenceElement2,
                                                            "http://schemas.microsoft.com/windowsazure",
                                                            "AddressPrefix")
                                                    .get(i6));
                                            addressSpaceInstance2.getAddressPrefixes()
                                                    .add(addressPrefixesElement2.getTextContent());
                                        }
                                    }
                                }

                                Element connectionsSequenceElement = XmlUtility.getElementByTagNameNS(
                                        sitesElement, "http://schemas.microsoft.com/windowsazure",
                                        "Connections");
                                if (connectionsSequenceElement != null) {
                                    for (int i7 = 0; i7 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(connectionsSequenceElement,
                                                    "http://schemas.microsoft.com/windowsazure", "Connection")
                                            .size(); i7 = i7 + 1) {
                                        org.w3c.dom.Element connectionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(connectionsSequenceElement,
                                                        "http://schemas.microsoft.com/windowsazure",
                                                        "Connection")
                                                .get(i7));
                                        NetworkListResponse.Connection connectionInstance = new NetworkListResponse.Connection();
                                        localNetworkSiteInstance.getConnections().add(connectionInstance);

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

                        Element vPNClientAddressPoolElement = XmlUtility.getElementByTagNameNS(gatewayElement,
                                "http://schemas.microsoft.com/windowsazure", "VPNClientAddressPool");
                        if (vPNClientAddressPoolElement != null) {
                            NetworkListResponse.VPNClientAddressPool vPNClientAddressPoolInstance = new NetworkListResponse.VPNClientAddressPool();
                            gatewayInstance.setVPNClientAddressPool(vPNClientAddressPoolInstance);

                            Element addressPrefixesSequenceElement3 = XmlUtility.getElementByTagNameNS(
                                    vPNClientAddressPoolElement, "http://schemas.microsoft.com/windowsazure",
                                    "AddressPrefixes");
                            if (addressPrefixesSequenceElement3 != null) {
                                for (int i8 = 0; i8 < com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(addressPrefixesSequenceElement3,
                                                "http://schemas.microsoft.com/windowsazure", "AddressPrefix")
                                        .size(); i8 = i8 + 1) {
                                    org.w3c.dom.Element addressPrefixesElement3 = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(addressPrefixesSequenceElement3,
                                                    "http://schemas.microsoft.com/windowsazure",
                                                    "AddressPrefix")
                                            .get(i8));
                                    vPNClientAddressPoolInstance.getAddressPrefixes()
                                            .add(addressPrefixesElement3.getTextContent());
                                }
                            }
                        }
                    }
                }
            }

        }
        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.microsoft.windowsazure.management.sql.FirewallRuleOperationsImpl.java

/**
* Returns the Firewall rule for an Azure SQL Database Server with a
* matching name./*from  w  w w  . jav a2 s. co m*/
*
* @param serverName Required. The name of the Azure SQL Database Server to
* query for the Firewall Rule.
* @param ruleName Required. The name of the rule to retrieve.
* @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.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return Contains the response from a request to Get Firewall Rule.
*/
@Override
public FirewallRuleGetResponse get(String serverName, String ruleName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (ruleName == null) {
        throw new NullPointerException("ruleName");
    }

    // 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("serverName", serverName);
        tracingParameters.put("ruleName", ruleName);
        CloudTracing.enter(invocationId, this, "getAsync", 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(serverName, "UTF-8");
    url = url + "/firewallrules/";
    url = url + URLEncoder.encode(ruleName, "UTF-8");
    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
    HttpGet httpRequest = new HttpGet(url);

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

    // 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_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

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

                Element startIPAddressElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "StartIPAddress");
                if (startIPAddressElement != null) {
                    InetAddress startIPAddressInstance;
                    startIPAddressInstance = InetAddress.getByName(startIPAddressElement.getTextContent());
                    serviceResourceInstance.setStartIPAddress(startIPAddressInstance);
                }

                Element endIPAddressElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "http://schemas.microsoft.com/windowsazure", "EndIPAddress");
                if (endIPAddressElement != null) {
                    InetAddress endIPAddressInstance;
                    endIPAddressInstance = InetAddress.getByName(endIPAddressElement.getTextContent());
                    serviceResourceInstance.setEndIPAddress(endIPAddressInstance);
                }

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

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

                Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement,
                        "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();
        }
    }
}