List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:com.microsoft.windowsazure.management.websites.WebSpaceOperationsImpl.java
/** * You can retrieve details for a specified web space name by issuing an * HTTP GET request. (see// w w w. j a v a2 s . c o m * http://msdn.microsoft.com/en-us/library/windowsazure/dn167017.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @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 Web Space Details operation response. */ @Override public WebSpacesGetResponse get(String webSpaceName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } // 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("webSpaceName", webSpaceName); 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/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "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-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 WebSpacesGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element webSpaceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { Element availabilityStateElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); result.setAvailabilityState(availabilityStateInstance); } Element currentNumberOfWorkersElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement != null && currentNumberOfWorkersElement.getTextContent() != null && !currentNumberOfWorkersElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = currentNumberOfWorkersElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement.getTextContent()); result.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } } Element currentWorkerSizeElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement != null && currentWorkerSizeElement.getTextContent() != null && !currentWorkerSizeElement.getTextContent().isEmpty()) { boolean isNil2 = false; Attr nilAttribute2 = currentWorkerSizeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { WorkerSizeOptions currentWorkerSizeInstance; currentWorkerSizeInstance = WorkerSizeOptions .valueOf(currentWorkerSizeElement.getTextContent()); result.setCurrentWorkerSize(currentWorkerSizeInstance); } } Element geoLocationElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "GeoLocation"); if (geoLocationElement != null) { String geoLocationInstance; geoLocationInstance = geoLocationElement.getTextContent(); result.setGeoLocation(geoLocationInstance); } Element geoRegionElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion"); if (geoRegionElement != null) { String geoRegionInstance; geoRegionInstance = geoRegionElement.getTextContent(); result.setGeoRegion(geoRegionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } Element planElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null) { String planInstance; planInstance = planElement.getTextContent(); result.setPlan(planInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSpaceStatus statusInstance; statusInstance = WebSpaceStatus.valueOf(statusElement.getTextContent()); result.setStatus(statusInstance); } Element subscriptionElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "Subscription"); if (subscriptionElement != null) { String subscriptionInstance; subscriptionInstance = subscriptionElement.getTextContent(); result.setSubscription(subscriptionInstance); } Element workerSizeElement = XmlUtility.getElementByTagNameNS(webSpaceElement, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement != null && workerSizeElement.getTextContent() != null && !workerSizeElement.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement.getTextContent()); result.setWorkerSize(workerSizeInstance); } } } 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.websites.WebSpaceOperationsImpl.java
/** * You can list the web spaces under the current subscription by issuing a * GET request. (see/*from w w w .j av a2 s .com*/ * http://msdn.microsoft.com/en-us/library/windowsazure/dn166961.aspx for * more information) * * @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 List Web Spaces operation response. */ @Override public WebSpacesListResponse 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/WebSpaces"; 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-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 WebSpacesListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element webSpacesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "WebSpaces"); if (webSpacesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webSpacesSequenceElement, "http://schemas.microsoft.com/windowsazure", "WebSpace") .size(); i1 = i1 + 1) { org.w3c.dom.Element webSpacesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(webSpacesSequenceElement, "http://schemas.microsoft.com/windowsazure", "WebSpace") .get(i1)); WebSpacesListResponse.WebSpace webSpaceInstance = new WebSpacesListResponse.WebSpace(); result.getWebSpaces().add(webSpaceInstance); Element availabilityStateElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSpaceInstance.setAvailabilityState(availabilityStateInstance); } Element currentNumberOfWorkersElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "CurrentNumberOfWorkers"); if (currentNumberOfWorkersElement != null && currentNumberOfWorkersElement.getTextContent() != null && !currentNumberOfWorkersElement.getTextContent().isEmpty()) { boolean isNil = false; Attr nilAttribute = currentNumberOfWorkersElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { int currentNumberOfWorkersInstance; currentNumberOfWorkersInstance = DatatypeConverter .parseInt(currentNumberOfWorkersElement.getTextContent()); webSpaceInstance.setCurrentNumberOfWorkers(currentNumberOfWorkersInstance); } } Element currentWorkerSizeElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "CurrentWorkerSize"); if (currentWorkerSizeElement != null && currentWorkerSizeElement.getTextContent() != null && !currentWorkerSizeElement.getTextContent().isEmpty()) { boolean isNil2 = false; Attr nilAttribute2 = currentWorkerSizeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { WorkerSizeOptions currentWorkerSizeInstance; currentWorkerSizeInstance = WorkerSizeOptions .valueOf(currentWorkerSizeElement.getTextContent()); webSpaceInstance.setCurrentWorkerSize(currentWorkerSizeInstance); } } Element geoLocationElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "GeoLocation"); if (geoLocationElement != null) { String geoLocationInstance; geoLocationInstance = geoLocationElement.getTextContent(); webSpaceInstance.setGeoLocation(geoLocationInstance); } Element geoRegionElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "GeoRegion"); if (geoRegionElement != null) { String geoRegionInstance; geoRegionInstance = geoRegionElement.getTextContent(); webSpaceInstance.setGeoRegion(geoRegionInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); webSpaceInstance.setName(nameInstance); } Element planElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Plan"); if (planElement != null) { String planInstance; planInstance = planElement.getTextContent(); webSpaceInstance.setPlan(planInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSpaceStatus statusInstance; statusInstance = WebSpaceStatus.valueOf(statusElement.getTextContent()); webSpaceInstance.setStatus(statusInstance); } Element subscriptionElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "Subscription"); if (subscriptionElement != null) { String subscriptionInstance; subscriptionInstance = subscriptionElement.getTextContent(); webSpaceInstance.setSubscription(subscriptionInstance); } Element workerSizeElement = XmlUtility.getElementByTagNameNS(webSpacesElement, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement != null && workerSizeElement.getTextContent() != null && !workerSizeElement.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement.getTextContent()); webSpaceInstance.setWorkerSize(workerSizeInstance); } } } } 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.gargoylesoftware.htmlunit.html.HtmlElement.java
/** * Sets the specified attribute. This method may be overridden by subclasses * which are interested in specific attribute value changes, but such methods <b>must</b> * invoke <tt>super.setAttributeNode()</tt>, and <b>should</b> consider the value of the * <tt>cloning</tt> parameter when deciding whether or not to execute custom logic. * * @param attribute the attribute to set * @return {@inheritDoc}//from w ww . j ava2s . c om */ @Override public Attr setAttributeNode(final Attr attribute) { final String qualifiedName = attribute.getName(); final String oldAttributeValue = getAttribute(qualifiedName); final HtmlPage htmlPage = (HtmlPage) getPage(); final boolean mappedElement = isDirectlyAttachedToPage() && HtmlPage.isMappedElement(htmlPage, qualifiedName); if (mappedElement) { // cast is save here because isMappedElement checks for HtmlPage htmlPage.removeMappedElement(this); } final Attr result = super.setAttributeNode(attribute); if (mappedElement) { htmlPage.addMappedElement(this); } final HtmlAttributeChangeEvent htmlEvent; if (oldAttributeValue == ATTRIBUTE_NOT_DEFINED) { htmlEvent = new HtmlAttributeChangeEvent(this, qualifiedName, attribute.getValue()); fireHtmlAttributeAdded(htmlEvent); htmlPage.fireHtmlAttributeAdded(htmlEvent); } else { htmlEvent = new HtmlAttributeChangeEvent(this, qualifiedName, oldAttributeValue); fireHtmlAttributeReplaced(htmlEvent); htmlPage.fireHtmlAttributeReplaced(htmlEvent); } return result; }
From source file:com.microsoft.windowsazure.management.storage.StorageAccountOperationsImpl.java
/** * The Check Name Availability operation checks if a storage account name is * available for use in Azure. (see//from w w w. ja v a 2s . c o m * http://msdn.microsoft.com/en-us/library/windowsazure/jj154125.aspx for * more information) * * @param accountName Required. The desired storage account name to check * for availability. * @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 to a storage account check name availability request. */ @Override public CheckNameAvailabilityResponse checkNameAvailability(String accountName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (accountName == null) { throw new NullPointerException("accountName"); } // 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("accountName", accountName); CloudTracing.enter(invocationId, this, "checkNameAvailabilityAsync", 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/storageservices/operations/isavailable/"; url = url + URLEncoder.encode(accountName, "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 CheckNameAvailabilityResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new CheckNameAvailabilityResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element availabilityResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "AvailabilityResponse"); if (availabilityResponseElement != null) { Element resultElement = XmlUtility.getElementByTagNameNS(availabilityResponseElement, "http://schemas.microsoft.com/windowsazure", "Result"); if (resultElement != null) { boolean resultInstance; resultInstance = DatatypeConverter .parseBoolean(resultElement.getTextContent().toLowerCase()); result.setIsAvailable(resultInstance); } Element reasonElement = XmlUtility.getElementByTagNameNS(availabilityResponseElement, "http://schemas.microsoft.com/windowsazure", "Reason"); if (reasonElement != null) { boolean isNil = false; Attr nilAttribute = reasonElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String reasonInstance; reasonInstance = reasonElement.getTextContent(); result.setReason(reasonInstance); } } } } 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.websites.WebSpaceOperationsImpl.java
/** * You can retrieve a list of all web sites in a web space by issuing an * HTTP GET request. (see//from w w w . j a v a2 s .c o m * http://msdn.microsoft.com/en-us/library/windowsazure/dn236429.aspx for * more information) * * @param webSpaceName Required. The name of the web space. * @param parameters Optional. Additional parameters. * @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 Web Sites operation response. */ @Override public WebSpacesListWebSitesResponse listWebSites(String webSpaceName, WebSiteListParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } // 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("webSpaceName", webSpaceName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "listWebSitesAsync", 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/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites"; ArrayList<String> queryParameters = new ArrayList<String>(); if (parameters != null && parameters.getPropertiesToInclude() != null && parameters.getPropertiesToInclude().size() > 0) { queryParameters.add("propertiesToInclude=" + URLEncoder .encode(CollectionStringBuilder.join(parameters.getPropertiesToInclude(), ","), "UTF-8")); } if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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-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 WebSpacesListWebSitesResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSpacesListWebSitesResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element sitesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Sites"); if (sitesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(sitesSequenceElement, "http://schemas.microsoft.com/windowsazure", "Site") .size(); i1 = i1 + 1) { org.w3c.dom.Element sitesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(sitesSequenceElement, "http://schemas.microsoft.com/windowsazure", "Site") .get(i1)); WebSite siteInstance = new WebSite(); result.getWebSites().add(siteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); siteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); siteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); siteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); siteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i2 = i2 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i2)); siteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i3)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); siteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement != null && sslStateElement.getTextContent() != null && !sslStateElement.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement = XmlUtility.getElementByTagNameNS( hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement != null) { boolean isNil = false; Attr nilAttribute = thumbprintElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS( hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute2 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress .getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i4 = i4 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i4)); siteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); siteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); siteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); siteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); siteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); siteInstance.setUri(selfLinkInstance); } Element serverFarmElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement.getTextContent(); siteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); siteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS( sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i7 = 0; i7 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i7 = i7 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i7)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); siteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); siteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(sitesElement, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); siteInstance.setWebSpace(webSpaceInstance); } } } } 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:lucee.runtime.img.Image.java
private void addMetaddata(Struct parent, String name, Node node) { // attributes NamedNodeMap attrs = node.getAttributes(); Attr attr; int len = attrs.getLength(); if (len == 1 && "value".equals(attrs.item(0).getNodeName())) { parent.setEL(name, attrs.item(0).getNodeValue()); } else {/*ww w.ja va 2 s . c om*/ Struct sct = metaGetChild(parent, name); for (int i = attrs.getLength() - 1; i >= 0; i--) { attr = (Attr) attrs.item(i); sct.setEL(attr.getName(), attr.getValue()); } } // child nodes NodeList children = XMLUtil.getChildNodes(node, Node.ELEMENT_NODE); Element el; for (int i = children.getLength() - 1; i >= 0; i--) { el = (Element) children.item(i); Struct sct = metaGetChild(parent, name); addMetaddata(sct, el.getNodeName(), children.item(i)); } }
From source file:loci.formats.in.LIFReader.java
private void populateOriginalMetadata(Element root, Deque<String> nameStack) { String name = root.getNodeName(); if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment") && !name.equals("LMSDataContainerHeader")) { nameStack.push(name);/* w ww. jav a 2s. c om*/ String suffix = root.getAttribute("Identifier"); String value = root.getAttribute("Variant"); if (suffix == null || suffix.trim().length() == 0) { suffix = root.getAttribute("Description"); } StringBuffer key = new StringBuffer(); final Iterator<String> nameStackIterator = nameStack.descendingIterator(); while (nameStackIterator.hasNext()) { final String k = nameStackIterator.next(); key.append(k); key.append("|"); } if (suffix != null && value != null && suffix.length() > 0 && value.length() > 0 && !suffix.equals("HighInteger") && !suffix.equals("LowInteger")) { addSeriesMetaList(key.toString() + suffix, value); } else { NamedNodeMap attributes = root.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (!attr.getName().equals("HighInteger") && !attr.getName().equals("LowInteger")) { addSeriesMeta(key.toString() + attr.getName(), attr.getValue()); } } } } NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Object child = children.item(i); if (child instanceof Element) { populateOriginalMetadata((Element) child, nameStack); } } if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment") && !name.equals("LMSDataContainerHeader")) { nameStack.pop(); } }
From source file:com.microsoft.windowsazure.management.storage.StorageAccountOperationsImpl.java
/** * The Get Storage Account Properties operation returns system properties * for the specified storage account. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460802.aspx for * more information)// w w w . j a v a 2 s . c om * * @param accountName Required. Name of the storage account to get * properties for. * @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 Storage Account Properties operation response. */ @Override public StorageAccountGetResponse get(String accountName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (accountName == null) { throw new NullPointerException("accountName"); } // 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("accountName", accountName); 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/storageservices/"; url = url + URLEncoder.encode(accountName, "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 StorageAccountGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new StorageAccountGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element storageServiceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "StorageService"); if (storageServiceElement != null) { StorageAccount storageServiceInstance = new StorageAccount(); result.setStorageAccount(storageServiceInstance); Element urlElement = XmlUtility.getElementByTagNameNS(storageServiceElement, "http://schemas.microsoft.com/windowsazure", "Url"); if (urlElement != null) { URI urlInstance; urlInstance = new URI(urlElement.getTextContent()); storageServiceInstance.setUri(urlInstance); } Element serviceNameElement = XmlUtility.getElementByTagNameNS(storageServiceElement, "http://schemas.microsoft.com/windowsazure", "ServiceName"); if (serviceNameElement != null) { String serviceNameInstance; serviceNameInstance = serviceNameElement.getTextContent(); storageServiceInstance.setName(serviceNameInstance); } Element storageServicePropertiesElement = XmlUtility.getElementByTagNameNS( storageServiceElement, "http://schemas.microsoft.com/windowsazure", "StorageServiceProperties"); if (storageServicePropertiesElement != null) { StorageAccountProperties storageServicePropertiesInstance = new StorageAccountProperties(); storageServiceInstance.setProperties(storageServicePropertiesInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { boolean isNil = false; Attr nilAttribute = descriptionElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); storageServicePropertiesInstance.setDescription(descriptionInstance); } } Element affinityGroupElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); storageServicePropertiesInstance.setAffinityGroup(affinityGroupInstance); } Element locationElement = XmlUtility.getElementByTagNameNS(storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); storageServicePropertiesInstance.setLocation(locationInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent() != null ? new String(Base64.decode(labelElement.getTextContent())) : null; storageServicePropertiesInstance.setLabel(labelInstance); } Element statusElement = XmlUtility.getElementByTagNameNS(storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { StorageAccountStatus statusInstance; statusInstance = StorageAccountStatus.valueOf(statusElement.getTextContent()); storageServicePropertiesInstance.setStatus(statusInstance); } Element endpointsSequenceElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Endpoints"); if (endpointsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(endpointsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Endpoint") .size(); i1 = i1 + 1) { org.w3c.dom.Element endpointsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(endpointsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Endpoint") .get(i1)); storageServicePropertiesInstance.getEndpoints() .add(new URI(endpointsElement.getTextContent())); } } Element geoPrimaryRegionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "GeoPrimaryRegion"); if (geoPrimaryRegionElement != null) { String geoPrimaryRegionInstance; geoPrimaryRegionInstance = geoPrimaryRegionElement.getTextContent(); storageServicePropertiesInstance.setGeoPrimaryRegion(geoPrimaryRegionInstance); } Element statusOfPrimaryElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "StatusOfPrimary"); if (statusOfPrimaryElement != null && statusOfPrimaryElement.getTextContent() != null && !statusOfPrimaryElement.getTextContent().isEmpty()) { GeoRegionStatus statusOfPrimaryInstance; statusOfPrimaryInstance = GeoRegionStatus .valueOf(statusOfPrimaryElement.getTextContent()); storageServicePropertiesInstance.setStatusOfGeoPrimaryRegion(statusOfPrimaryInstance); } Element lastGeoFailoverTimeElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "LastGeoFailoverTime"); if (lastGeoFailoverTimeElement != null && lastGeoFailoverTimeElement.getTextContent() != null && !lastGeoFailoverTimeElement.getTextContent().isEmpty()) { Calendar lastGeoFailoverTimeInstance; lastGeoFailoverTimeInstance = DatatypeConverter .parseDateTime(lastGeoFailoverTimeElement.getTextContent()); storageServicePropertiesInstance.setLastGeoFailoverTime(lastGeoFailoverTimeInstance); } Element geoSecondaryRegionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "GeoSecondaryRegion"); if (geoSecondaryRegionElement != null) { String geoSecondaryRegionInstance; geoSecondaryRegionInstance = geoSecondaryRegionElement.getTextContent(); storageServicePropertiesInstance.setGeoSecondaryRegion(geoSecondaryRegionInstance); } Element statusOfSecondaryElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "StatusOfSecondary"); if (statusOfSecondaryElement != null && statusOfSecondaryElement.getTextContent() != null && !statusOfSecondaryElement.getTextContent().isEmpty()) { GeoRegionStatus statusOfSecondaryInstance; statusOfSecondaryInstance = GeoRegionStatus .valueOf(statusOfSecondaryElement.getTextContent()); storageServicePropertiesInstance .setStatusOfGeoSecondaryRegion(statusOfSecondaryInstance); } Element accountTypeElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AccountType"); if (accountTypeElement != null) { String accountTypeInstance; accountTypeInstance = accountTypeElement.getTextContent(); storageServicePropertiesInstance.setAccountType(accountTypeInstance); } } Element extendedPropertiesSequenceElement = XmlUtility.getElementByTagNameNS( storageServiceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperties"); if (extendedPropertiesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .size(); i2 = i2 + 1) { org.w3c.dom.Element extendedPropertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .get(i2)); String extendedPropertiesKey = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String extendedPropertiesValue = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); storageServiceInstance.getExtendedProperties().put(extendedPropertiesKey, extendedPropertiesValue); } } } } 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.storage.StorageAccountOperationsImpl.java
/** * The List Storage Accounts operation lists the storage accounts available * under the current subscription. (see//from www .j ava 2 s . c om * http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx for * more information) * * @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 Storage Accounts operation response. */ @Override public StorageAccountListResponse list() 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, "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/storageservices"; 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 StorageAccountListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new StorageAccountListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element storageServicesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "StorageServices"); if (storageServicesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(storageServicesSequenceElement, "http://schemas.microsoft.com/windowsazure", "StorageService") .size(); i1 = i1 + 1) { org.w3c.dom.Element storageServicesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(storageServicesSequenceElement, "http://schemas.microsoft.com/windowsazure", "StorageService") .get(i1)); StorageAccount storageServiceInstance = new StorageAccount(); result.getStorageAccounts().add(storageServiceInstance); Element urlElement = XmlUtility.getElementByTagNameNS(storageServicesElement, "http://schemas.microsoft.com/windowsazure", "Url"); if (urlElement != null) { URI urlInstance; urlInstance = new URI(urlElement.getTextContent()); storageServiceInstance.setUri(urlInstance); } Element serviceNameElement = XmlUtility.getElementByTagNameNS(storageServicesElement, "http://schemas.microsoft.com/windowsazure", "ServiceName"); if (serviceNameElement != null) { String serviceNameInstance; serviceNameInstance = serviceNameElement.getTextContent(); storageServiceInstance.setName(serviceNameInstance); } Element storageServicePropertiesElement = XmlUtility.getElementByTagNameNS( storageServicesElement, "http://schemas.microsoft.com/windowsazure", "StorageServiceProperties"); if (storageServicePropertiesElement != null) { StorageAccountProperties storageServicePropertiesInstance = new StorageAccountProperties(); storageServiceInstance.setProperties(storageServicePropertiesInstance); Element descriptionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { boolean isNil = false; Attr nilAttribute = descriptionElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); storageServicePropertiesInstance.setDescription(descriptionInstance); } } Element affinityGroupElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AffinityGroup"); if (affinityGroupElement != null) { String affinityGroupInstance; affinityGroupInstance = affinityGroupElement.getTextContent(); storageServicePropertiesInstance.setAffinityGroup(affinityGroupInstance); } Element locationElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); storageServicePropertiesInstance.setLocation(locationInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent() != null ? new String(Base64.decode(labelElement.getTextContent())) : null; storageServicePropertiesInstance.setLabel(labelInstance); } Element statusElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { StorageAccountStatus statusInstance; statusInstance = StorageAccountStatus.valueOf(statusElement.getTextContent()); storageServicePropertiesInstance.setStatus(statusInstance); } Element endpointsSequenceElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Endpoints"); if (endpointsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(endpointsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Endpoint") .size(); i2 = i2 + 1) { org.w3c.dom.Element endpointsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(endpointsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Endpoint") .get(i2)); storageServicePropertiesInstance.getEndpoints() .add(new URI(endpointsElement.getTextContent())); } } Element geoPrimaryRegionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "GeoPrimaryRegion"); if (geoPrimaryRegionElement != null) { String geoPrimaryRegionInstance; geoPrimaryRegionInstance = geoPrimaryRegionElement.getTextContent(); storageServicePropertiesInstance.setGeoPrimaryRegion(geoPrimaryRegionInstance); } Element statusOfPrimaryElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "StatusOfPrimary"); if (statusOfPrimaryElement != null && statusOfPrimaryElement.getTextContent() != null && !statusOfPrimaryElement.getTextContent().isEmpty()) { GeoRegionStatus statusOfPrimaryInstance; statusOfPrimaryInstance = GeoRegionStatus .valueOf(statusOfPrimaryElement.getTextContent()); storageServicePropertiesInstance .setStatusOfGeoPrimaryRegion(statusOfPrimaryInstance); } Element lastGeoFailoverTimeElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "LastGeoFailoverTime"); if (lastGeoFailoverTimeElement != null && lastGeoFailoverTimeElement.getTextContent() != null && !lastGeoFailoverTimeElement.getTextContent().isEmpty()) { Calendar lastGeoFailoverTimeInstance; lastGeoFailoverTimeInstance = DatatypeConverter .parseDateTime(lastGeoFailoverTimeElement.getTextContent()); storageServicePropertiesInstance .setLastGeoFailoverTime(lastGeoFailoverTimeInstance); } Element geoSecondaryRegionElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "GeoSecondaryRegion"); if (geoSecondaryRegionElement != null) { String geoSecondaryRegionInstance; geoSecondaryRegionInstance = geoSecondaryRegionElement.getTextContent(); storageServicePropertiesInstance.setGeoSecondaryRegion(geoSecondaryRegionInstance); } Element statusOfSecondaryElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "StatusOfSecondary"); if (statusOfSecondaryElement != null && statusOfSecondaryElement.getTextContent() != null && !statusOfSecondaryElement.getTextContent().isEmpty()) { GeoRegionStatus statusOfSecondaryInstance; statusOfSecondaryInstance = GeoRegionStatus .valueOf(statusOfSecondaryElement.getTextContent()); storageServicePropertiesInstance .setStatusOfGeoSecondaryRegion(statusOfSecondaryInstance); } Element accountTypeElement = XmlUtility.getElementByTagNameNS( storageServicePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AccountType"); if (accountTypeElement != null) { String accountTypeInstance; accountTypeInstance = accountTypeElement.getTextContent(); storageServicePropertiesInstance.setAccountType(accountTypeInstance); } } Element extendedPropertiesSequenceElement = XmlUtility.getElementByTagNameNS( storageServicesElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperties"); if (extendedPropertiesSequenceElement != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .size(); i3 = i3 + 1) { org.w3c.dom.Element extendedPropertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(extendedPropertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ExtendedProperty") .get(i3)); String extendedPropertiesKey = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String extendedPropertiesValue = XmlUtility .getElementByTagNameNS(extendedPropertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); storageServiceInstance.getExtendedProperties().put(extendedPropertiesKey, extendedPropertiesValue); } } } } } 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.gargoylesoftware.htmlunit.html.HtmlPage.java
/** * <p>Returns all namespaces defined in the root element of this page.</p> * <p>The default namespace has a key of an empty string.</p> * @return all namespaces defined in the root element of this page */// w w w .ja v a 2 s . co m public Map<String, String> getNamespaces() { final org.w3c.dom.NamedNodeMap attributes = getDocumentElement().getAttributes(); final Map<String, String> namespaces = new HashMap<>(); for (int i = 0; i < attributes.getLength(); i++) { final Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (name.startsWith("xmlns")) { int startPos = 5; if ((name.length() > 5) && (name.charAt(5) == ':')) { startPos = 6; } name = name.substring(startPos); namespaces.put(name, attr.getValue()); } } return namespaces; }