List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static String getNamespaceDeclarationNamespace(Attr attr) { if (!W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) { throw new IllegalStateException( "Attempt to get namespace from a attribute that is not a namespace declaration, it has namespace " + attr.getNamespaceURI()); }//from ww w .j av a 2 s . c om String attrName = attr.getName(); if (!attrName.startsWith("xmlns:") && !"xmlns".equals(attr.getName())) { throw new IllegalStateException( "Attempt to get namespace from a attribute that is not a namespace declaration, it is " + attrName); } return attr.getValue(); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*w w w.ja v a 2 s. c om*/ public void testAddAttributeFromNameWithoutNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); SOAPElement retValue = element.addAttribute(envelope.createName("attr"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS(null, "attr"); assertNull(attr.getNamespaceURI()); String localName = attr.getLocalName(); if (localName != null) { assertEquals("attr", attr.getLocalName()); } assertNull(attr.getPrefix()); assertEquals("value", attr.getValue()); }
From source file:com.microsoft.windowsazure.management.websites.WebSiteOperationsImpl2.java
@Override public WebSiteGetPublishProfileResponse getPublishProfile(String webSpaceName, String webSiteName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate//from ww w . ja v a2s .co m if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } // 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("webSiteName", webSiteName); CloudTracing.enter(invocationId, this, "getPublishProfileAsync", tracingParameters); } // Construct URL String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/WebSpaces/" + webSpaceName.trim() + "/sites/" + webSiteName.trim() + "/publishxml"; 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 WebSiteGetPublishProfileResponse result = null; // Deserialize Response InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteGetPublishProfileResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element publishDataElement = XmlUtility.getElementByTagNameNS(responseDoc, "", "publishData"); if (publishDataElement != null) { if (publishDataElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataElement, "", "publishProfile").size(); i1 = i1 + 1) { org.w3c.dom.Element publishProfilesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(publishDataElement, "", "publishProfile").get(i1)); WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile(); result.getPublishProfiles().add(publishProfileInstance); Attr profileNameAttribute = publishProfilesElement.getAttributeNodeNS(null, "profileName"); if (profileNameAttribute != null) { publishProfileInstance.setProfileName(profileNameAttribute.getValue()); } Attr publishMethodAttribute = publishProfilesElement.getAttributeNodeNS(null, "publishMethod"); if (publishMethodAttribute != null) { publishProfileInstance.setPublishMethod(publishMethodAttribute.getValue()); } Attr publishUrlAttribute = publishProfilesElement.getAttributeNodeNS(null, "publishUrl"); if (publishUrlAttribute != null) { publishProfileInstance.setPublishUrl(publishUrlAttribute.getValue()); } Attr msdeploySiteAttribute = publishProfilesElement.getAttributeNodeNS(null, "msdeploySite"); if (msdeploySiteAttribute != null) { publishProfileInstance.setMSDeploySite(msdeploySiteAttribute.getValue()); } Attr ftpPassiveModeAttribute = publishProfilesElement.getAttributeNodeNS(null, "ftpPassiveMode"); if (ftpPassiveModeAttribute != null) { publishProfileInstance.setFtpPassiveMode(DatatypeConverter .parseBoolean(ftpPassiveModeAttribute.getValue().toLowerCase())); } Attr userNameAttribute = publishProfilesElement.getAttributeNodeNS(null, "userName"); if (userNameAttribute != null) { publishProfileInstance.setUserName(userNameAttribute.getValue()); } Attr userPWDAttribute = publishProfilesElement.getAttributeNodeNS(null, "userPWD"); if (userPWDAttribute != null) { publishProfileInstance.setUserPassword(userPWDAttribute.getValue()); } Attr destinationAppUrlAttribute = publishProfilesElement.getAttributeNodeNS(null, "destinationAppUrl"); if (destinationAppUrlAttribute != null) { publishProfileInstance .setDestinationAppUri(new URI(destinationAppUrlAttribute.getValue())); } Attr sQLServerDBConnectionStringAttribute = publishProfilesElement.getAttributeNodeNS(null, "SQLServerDBConnectionString"); if (sQLServerDBConnectionStringAttribute != null) { publishProfileInstance .setSqlServerConnectionString(sQLServerDBConnectionStringAttribute.getValue()); } Attr mySQLDBConnectionStringAttribute = publishProfilesElement.getAttributeNodeNS(null, "mySQLDBConnectionString"); if (mySQLDBConnectionStringAttribute != null) { publishProfileInstance .setMySqlConnectionString(mySQLDBConnectionStringAttribute.getValue()); } Attr hostingProviderForumLinkAttribute = publishProfilesElement.getAttributeNodeNS(null, "hostingProviderForumLink"); if (hostingProviderForumLinkAttribute != null) { publishProfileInstance.setHostingProviderForumUri( new URI(hostingProviderForumLinkAttribute.getValue())); } Attr controlPanelLinkAttribute = publishProfilesElement.getAttributeNodeNS(null, "controlPanelLink"); if (controlPanelLinkAttribute != null) { publishProfileInstance .setControlPanelUri(new URI(controlPanelLinkAttribute.getValue())); } Element databasesSequenceElement = XmlUtility.getElementByTagNameNS(publishProfilesElement, "", "databases"); if (databasesSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add") .size(); i2 = i2 + 1) { org.w3c.dom.Element databasesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(databasesSequenceElement, "", "add").get(i2)); WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database(); publishProfileInstance.getDatabases().add(addInstance); Attr nameAttribute = databasesElement.getAttributeNodeNS(null, "name"); if (nameAttribute != null) { addInstance.setName(nameAttribute.getValue()); } Attr connectionStringAttribute = databasesElement.getAttributeNodeNS(null, "connectionString"); if (connectionStringAttribute != null) { addInstance.setConnectionString(connectionStringAttribute.getValue()); } Attr providerNameAttribute = databasesElement.getAttributeNodeNS(null, "providerName"); if (providerNameAttribute != null) { addInstance.setProviderName(providerNameAttribute.getValue()); } Attr typeAttribute = databasesElement.getAttributeNodeNS(null, "type"); if (typeAttribute != null) { addInstance.setType(typeAttribute.getValue()); } } } } } } 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.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from w w w. ja v a2 s . c o m public void testAddAttributeFromQNameWithoutNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement retValue = element.addAttribute(new QName("attr"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS(null, "attr"); assertNull(attr.getNamespaceURI()); String localName = attr.getLocalName(); // The RI creates a namespace unaware attribute node in this case; we believe // it's better to create a namespace aware node. if (localName != null) { assertEquals("attr", attr.getLocalName()); } assertNull(attr.getPrefix()); assertEquals("value", attr.getValue()); }
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.//from w w w. j av a 2 s . c o m * @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.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Annotation element/*from w w w .j av a 2 s . c om*/ * * @param element the Annotation element * @return Annotation data object * @throws InkMLException */ protected Annotation getAnnotation(final Element element) throws InkMLException { final Annotation annotation = new Annotation(); final NamedNodeMap attributesMap = element.getAttributes(); final int length = attributesMap.getLength(); for (int index = 0; index < length; index++) { final Attr attribute = (Attr) attributesMap.item(index); final String attributeName = attribute.getName(); if ("type".equals(attributeName)) { annotation.setType(attribute.getValue()); } else if ("encoding".equals(attributeName)) { annotation.setEncoding(attribute.getValue()); } else { annotation.addToOtherAttributesMap(attributeName, attribute.getValue()); } } final Node valueNode = element.getFirstChild(); if (null != valueNode) { annotation.setAnnotationTextValue(valueNode.getNodeValue()); } return annotation; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind AnnotationXML element/*from w w w. j a v a 2 s . c o m*/ * * @param element the AnnotationXML element * @return AnnotationXML data object * @throws InkMLException */ protected AnnotationXML getAnnotationXML(final Element element) throws InkMLException { final AnnotationXML aXml = new AnnotationXML(); final NamedNodeMap attributesMap = element.getAttributes(); final int length = attributesMap.getLength(); for (int index = 0; index < length; index++) { final Attr attribute = (Attr) attributesMap.item(index); final String attributeName = attribute.getName(); if ("type".equals(attributeName)) { aXml.setType(attribute.getValue()); } else if ("encoding".equals(attributeName)) { aXml.setEncoding(attribute.getValue()); } else { aXml.addToOtherAttributesMap(attributeName, attribute.getValue()); } } InkMLDOMParser.LOG.finest("annotationXML received: " + element.toString()); final NodeList list = element.getChildNodes(); final int nChildren = list.getLength(); if (nChildren > 0) { for (int i = 0; i < nChildren; i++) { final Node node = list.item(i); if (!(node instanceof Element)) { continue; } final Element childElement = (Element) node; // get the tagName to use as Key in the valueMap final String tagName = childElement.getLocalName(); // String key = this.parentXPath+"/"+tagName; final String value = childElement.getFirstChild().getNodeValue(); // propertyElementsMap.put(key, childElement); // propertyElementsMap.put(key, value); aXml.addToPropertyElementsMap(tagName, value); InkMLDOMParser.LOG .finer("The property with name = " + tagName + " is added to the propertyElementsMap."); } } return aXml; }
From source file:com.rest4j.generator.Generator.java
public void generate() throws Exception { ApiFactory fac = new ApiFactory(apiXml, null, null); for (String className : preprocessors) { Preprocessor p = (Preprocessor) Class.forName(className).newInstance(); fac.addPreprocessor(p);/*from w w w .j a v a 2 s. c o m*/ } Document xml = fac.getDocument(); preprocess(xml); URL url = getStylesheet(); String filename = "index.html"; for (TemplateParam param : params) { if (param.getName().equals("filename")) { filename = param.getValue(); } } Document doc = transform(xml, url); cleanupBeforePostprocess(doc.getDocumentElement()); if (postprocessingXSLT != null) { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document composed = documentBuilder.newDocument(); org.w3c.dom.Element top = composed.createElementNS("http://rest4j.com/api-description", "top"); composed.appendChild(top); top.appendChild(composed.adoptNode(xml.getDocumentElement())); top.appendChild(composed.adoptNode(doc.getDocumentElement())); xml = null; doc = null; // free some mem doc = transform(composed, postprocessingXSLT); } if ("files".equals(doc.getDocumentElement().getLocalName())) { // break the result into files for (Node child : Util.it(doc.getDocumentElement().getChildNodes())) { if ("file".equals(child.getLocalName())) { if (child.getAttributes().getNamedItem("name") == null) { throw new IllegalArgumentException("Attribute name not found in <file>"); } String name = child.getAttributes().getNamedItem("name").getTextContent(); File file = new File(outputDir, name); file.getParentFile().mkdirs(); System.out.println("Write " + file.getAbsolutePath()); Attr copyFromAttr = (Attr) child.getAttributes().getNamedItem("copy-from"); if (copyFromAttr == null) { cleanupFinal((Element) child); if (child.getAttributes().getNamedItem("text") != null) { // plain-text output FileOutputStream fos = new FileOutputStream(file); try { IOUtils.write(child.getTextContent(), fos, "UTF-8"); } finally { IOUtils.closeQuietly(fos); } } else { output(child, file); } } else { String copyFrom = copyFromAttr.getValue(); URL asset = getClass().getClassLoader().getResource(copyFrom); if (asset == null) { asset = getClass().getResource(copyFrom); } if (asset == null) { File assetFile = new File(copyFrom); if (!assetFile.canRead()) { if (postprocessingXSLT != null) { asset = new URL(postprocessingXSLT, copyFrom); try { asset.openStream().close(); } catch (FileNotFoundException fnfe) { asset = null; } } if (asset == null) { asset = new URL(getStylesheet(), copyFrom); try { asset.openStream().close(); } catch (FileNotFoundException fnfe) { asset = null; } } if (asset == null) throw new IllegalArgumentException("File '" + copyFrom + "' specified by @copy-from not found in the classpath or filesystem"); } else { asset = assetFile.toURI().toURL(); } } InputStream is = asset.openStream(); OutputStream fos = new FileOutputStream(file); try { IOUtils.copy(is, fos); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } } } else if (child.getNodeType() == Node.ELEMENT_NODE) { throw new IllegalArgumentException("Something but <file> found inside <files>"); } } } else { File file = new File(outputDir, filename); System.out.println("Write " + file.getAbsolutePath()); cleanupFinal(doc.getDocumentElement()); DOMSource source = new DOMSource(doc); FileOutputStream fos = new FileOutputStream(file); try { StreamResult result = new StreamResult(fos); Transformer trans = tFactory.newTransformer(); trans.transform(source, result); } finally { IOUtils.closeQuietly(fos); } } }
From source file:com.microsoft.windowsazure.management.websites.WebSiteManagementClientImpl.java
/** * The Get Operation Status operation returns the status of the specified * operation. After calling a long-running operation, you can call Get * Operation Status to determine whether the operation has succeeded, * failed, timed out, or is still in progress. (see * http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx for * more information)// w ww. j a v a 2 s. c o m * * @param webSpaceName Required. The name of the webspace for the website * where the operation was targeted. * @param siteName Required. The name of the site where the operation was * targeted. * @param operationId Required. The operation ID for the operation you wish * to track. The operation ID is returned in the ID field in the body of * the response for long-running operations. * @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 body contains the status of the specified * long-running operation, indicating whether it has succeeded, is * inprogress, has timed out, or has failed. Note that this status is * distinct from the HTTP status code returned for the Get Operation Status * operation itself. If the long-running operation failed, the response * body includes error information regarding the failure. */ @Override public WebSiteOperationStatusResponse getOperationStatus(String webSpaceName, String siteName, String operationId) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (siteName == null) { throw new NullPointerException("siteName"); } if (operationId == null) { throw new NullPointerException("operationId"); } // 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("siteName", siteName); tracingParameters.put("operationId", operationId); CloudTracing.enter(invocationId, this, "getOperationStatusAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/sites/"; url = url + URLEncoder.encode(siteName, "UTF-8"); url = url + "/operations/"; url = url + URLEncoder.encode(operationId, "UTF-8"); String baseUrl = this.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.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 WebSiteOperationStatusResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteOperationStatusResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element operationElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Operation"); if (operationElement != null) { Element createdTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "CreatedTime"); if (createdTimeElement != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeElement.getTextContent()); result.setCreatedTime(createdTimeInstance); } Element errorsSequenceElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Errors"); if (errorsSequenceElement != null) { boolean isNil = false; Attr nilAttribute = errorsSequenceElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute != null) { isNil = "true".equals(nilAttribute.getValue()); } if (isNil == false) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(errorsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Error") .size(); i1 = i1 + 1) { org.w3c.dom.Element errorsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(errorsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Error") .get(i1)); WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error(); result.getErrors().add(errorInstance); Element codeElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Code"); if (codeElement != null) { boolean isNil2 = false; Attr nilAttribute2 = codeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil2 = "true".equals(nilAttribute2.getValue()); } if (isNil2 == false) { String codeInstance; codeInstance = codeElement.getTextContent(); errorInstance.setCode(codeInstance); } } Element messageElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Message"); if (messageElement != null) { boolean isNil3 = false; Attr nilAttribute3 = messageElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute3 != null) { isNil3 = "true".equals(nilAttribute3.getValue()); } if (isNil3 == false) { String messageInstance; messageInstance = messageElement.getTextContent(); errorInstance.setMessage(messageInstance); } } Element extendedCodeElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "ExtendedCode"); if (extendedCodeElement != null) { boolean isNil4 = false; Attr nilAttribute4 = extendedCodeElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute4 != null) { isNil4 = "true".equals(nilAttribute4.getValue()); } if (isNil4 == false) { String extendedCodeInstance; extendedCodeInstance = extendedCodeElement.getTextContent(); errorInstance.setExtendedCode(extendedCodeInstance); } } Element messageTemplateElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "MessageTemplate"); if (messageTemplateElement != null) { boolean isNil5 = false; Attr nilAttribute5 = messageTemplateElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute5 != null) { isNil5 = "true".equals(nilAttribute5.getValue()); } if (isNil5 == false) { String messageTemplateInstance; messageTemplateInstance = messageTemplateElement.getTextContent(); errorInstance.setMessageTemplate(messageTemplateInstance); } } Element parametersSequenceElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "Parameters"); if (parametersSequenceElement != null) { boolean isNil6 = false; Attr nilAttribute6 = parametersSequenceElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute6 != null) { isNil6 = "true".equals(nilAttribute6.getValue()); } if (isNil6 == false) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(parametersSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i2 = i2 + 1) { org.w3c.dom.Element parametersElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(parametersSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i2)); errorInstance.getParameters().add(parametersElement.getTextContent()); } } else { errorInstance.setParameters(null); } } Element innerErrorsElement = XmlUtility.getElementByTagNameNS(errorsElement, "http://schemas.microsoft.com/windowsazure", "InnerErrors"); if (innerErrorsElement != null) { boolean isNil7 = false; Attr nilAttribute7 = innerErrorsElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute7 != null) { isNil7 = "true".equals(nilAttribute7.getValue()); } if (isNil7 == false) { String innerErrorsInstance; innerErrorsInstance = innerErrorsElement.getTextContent(); errorInstance.setInnerErrors(innerErrorsInstance); } } } } else { result.setErrors(null); } } Element expirationTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "ExpirationTime"); if (expirationTimeElement != null) { Calendar expirationTimeInstance; expirationTimeInstance = DatatypeConverter .parseDateTime(expirationTimeElement.getTextContent()); result.setExpirationTime(expirationTimeInstance); } Element geoMasterOperationIdElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "GeoMasterOperationId"); if (geoMasterOperationIdElement != null) { boolean isNil8 = false; Attr nilAttribute8 = geoMasterOperationIdElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute8 != null) { isNil8 = "true".equals(nilAttribute8.getValue()); } if (isNil8 == false) { String geoMasterOperationIdInstance; geoMasterOperationIdInstance = geoMasterOperationIdElement.getTextContent(); result.setGeoMasterOperationId(geoMasterOperationIdInstance); } } Element idElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { boolean isNil9 = false; Attr nilAttribute9 = idElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute9 != null) { isNil9 = "true".equals(nilAttribute9.getValue()); } if (isNil9 == false) { String idInstance; idInstance = idElement.getTextContent(); result.setOperationId(idInstance); } } Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "ModifiedTime"); if (modifiedTimeElement != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement.getTextContent()); result.setModifiedTime(modifiedTimeInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { boolean isNil10 = false; Attr nilAttribute10 = nameElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute10 != null) { isNil10 = "true".equals(nilAttribute10.getValue()); } if (isNil10 == false) { String nameInstance; nameInstance = nameElement.getTextContent(); result.setName(nameInstance); } } Element statusElement = XmlUtility.getElementByTagNameNS(operationElement, "http://schemas.microsoft.com/windowsazure", "Status"); if (statusElement != null && statusElement.getTextContent() != null && !statusElement.getTextContent().isEmpty()) { WebSiteOperationStatus statusInstance; statusInstance = WebSiteOperationStatus.valueOf(statusElement.getTextContent()); result.setStatus(statusInstance); } } } 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:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
/** * Catalogs XMLSchema when submitted as an ExtrinsicObject - RepositoryItem pair. * *//*from ww w . ja va 2s .c o m*/ private void catalogXMLSchemaExtrinsicObject(RegistryObjectType ro, InputSource source) throws CatalogingException { try { registryObjects.add(ro); Document document = parseXML(source); Element schemaElement = document.getDocumentElement(); String documentLocalName = schemaElement.getLocalName(); String documentNamespaceURI = schemaElement.getNamespaceURI(); if (documentLocalName.equalsIgnoreCase("schema") && documentNamespaceURI.endsWith("XMLSchema")) { Attr attribute = schemaElement.getAttributeNode("targetNamespace"); String namespaceURI = attribute.getValue(); // Set the id for the XMLSchema EO updateRegistryObjectId(namespaceURI, ro, false); // Check if this XSD file imports another file (usually XSD) NodeList nodeList = schemaElement.getChildNodes(); int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); String localName = node.getLocalName(); if (localName != null && localName.equalsIgnoreCase("import")) { // This XSD imports another file NamedNodeMap importNamedNodeMap = node.getAttributes(); Node namespaceNode = importNamedNodeMap.getNamedItem("namespace"); String importNamespace = null; if (namespaceNode != null) { importNamespace = namespaceNode.getNodeValue(); } String schemaLocation = null; Node schemaLocationNode = importNamedNodeMap.getNamedItem("schemaLocation"); if (schemaLocationNode != null) { schemaLocation = schemaLocationNode.getNodeValue(); } RegistryObjectType importedObject = catalogImportStatement(ro, importNamespace, schemaLocation); createImportsAssociation(ro, importedObject); } } } } catch (CatalogingException e) { throw e; } catch (Exception e) { log.error(e, e); CatalogingException ce = new CatalogingException(e); throw ce; } }