List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineExtensionOperationsImpl.java
/** * The List Resource Extension Versions operation lists the versions of a * resource extension that are available to add to a Virtual Machine. In * Azure, a process can run as a resource extension of a Virtual Machine. * For example, Remote Desktop Access or the Azure Diagnostics Agent can * run as resource extensions to the Virtual Machine. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn495440.aspx for * more information)/*from www . j av a 2 s . c om*/ * * @param publisherName Required. The name of the publisher. * @param extensionName Required. The name of the extension. * @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 Resource Extensions operation response. */ @Override public VirtualMachineExtensionListResponse listVersions(String publisherName, String extensionName) throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate if (publisherName == null) { throw new NullPointerException("publisherName"); } if (extensionName == null) { throw new NullPointerException("extensionName"); } // 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("publisherName", publisherName); tracingParameters.put("extensionName", extensionName); CloudTracing.enter(invocationId, this, "listVersionsAsync", 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/resourceextensions/"; url = url + URLEncoder.encode(publisherName, "UTF-8"); url = url + "/"; url = url + URLEncoder.encode(extensionName, "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", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineExtensionListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineExtensionListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element resourceExtensionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ResourceExtensions"); if (resourceExtensionsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(resourceExtensionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ResourceExtension") .size(); i1 = i1 + 1) { org.w3c.dom.Element resourceExtensionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(resourceExtensionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ResourceExtension") .get(i1)); VirtualMachineExtensionListResponse.ResourceExtension resourceExtensionInstance = new VirtualMachineExtensionListResponse.ResourceExtension(); result.getResourceExtensions().add(resourceExtensionInstance); Element publisherElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Publisher"); if (publisherElement != null) { String publisherInstance; publisherInstance = publisherElement.getTextContent(); resourceExtensionInstance.setPublisher(publisherInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); resourceExtensionInstance.setName(nameInstance); } Element versionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Version"); if (versionElement != null) { String versionInstance; versionInstance = versionElement.getTextContent(); resourceExtensionInstance.setVersion(versionInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent(); resourceExtensionInstance.setLabel(labelInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); resourceExtensionInstance.setDescription(descriptionInstance); } Element publicConfigurationSchemaElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PublicConfigurationSchema"); if (publicConfigurationSchemaElement != null) { String publicConfigurationSchemaInstance; publicConfigurationSchemaInstance = publicConfigurationSchemaElement .getTextContent() != null ? new String( Base64.decode(publicConfigurationSchemaElement.getTextContent())) : null; resourceExtensionInstance .setPublicConfigurationSchema(publicConfigurationSchemaInstance); } Element privateConfigurationSchemaElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PrivateConfigurationSchema"); if (privateConfigurationSchemaElement != null) { String privateConfigurationSchemaInstance; privateConfigurationSchemaInstance = privateConfigurationSchemaElement .getTextContent() != null ? new String( Base64.decode(privateConfigurationSchemaElement.getTextContent())) : null; resourceExtensionInstance .setPrivateConfigurationSchema(privateConfigurationSchemaInstance); } Element sampleConfigElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "SampleConfig"); if (sampleConfigElement != null) { String sampleConfigInstance; sampleConfigInstance = sampleConfigElement.getTextContent() != null ? new String(Base64.decode(sampleConfigElement.getTextContent())) : null; resourceExtensionInstance.setSampleConfig(sampleConfigInstance); } Element replicationCompletedElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "ReplicationCompleted"); if (replicationCompletedElement != null && replicationCompletedElement.getTextContent() != null && !replicationCompletedElement.getTextContent().isEmpty()) { boolean replicationCompletedInstance; replicationCompletedInstance = DatatypeConverter .parseBoolean(replicationCompletedElement.getTextContent().toLowerCase()); resourceExtensionInstance.setReplicationCompleted(replicationCompletedInstance); } Element eulaElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Eula"); if (eulaElement != null) { URI eulaInstance; eulaInstance = new URI(eulaElement.getTextContent()); resourceExtensionInstance.setEula(eulaInstance); } Element privacyUriElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PrivacyUri"); if (privacyUriElement != null) { URI privacyUriInstance; privacyUriInstance = new URI(privacyUriElement.getTextContent()); resourceExtensionInstance.setPrivacyUri(privacyUriInstance); } Element homepageUriElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "HomepageUri"); if (homepageUriElement != null) { URI homepageUriInstance; homepageUriInstance = new URI(homepageUriElement.getTextContent()); resourceExtensionInstance.setHomepageUri(homepageUriInstance); } Element isJsonExtensionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "IsJsonExtension"); if (isJsonExtensionElement != null && isJsonExtensionElement.getTextContent() != null && !isJsonExtensionElement.getTextContent().isEmpty()) { boolean isJsonExtensionInstance; isJsonExtensionInstance = DatatypeConverter .parseBoolean(isJsonExtensionElement.getTextContent().toLowerCase()); resourceExtensionInstance.setIsJsonExtension(isJsonExtensionInstance); } Element isInternalExtensionElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "IsInternalExtension"); if (isInternalExtensionElement != null && isInternalExtensionElement.getTextContent() != null && !isInternalExtensionElement.getTextContent().isEmpty()) { boolean isInternalExtensionInstance; isInternalExtensionInstance = DatatypeConverter .parseBoolean(isInternalExtensionElement.getTextContent().toLowerCase()); resourceExtensionInstance.setIsInternalExtension(isInternalExtensionInstance); } Element disallowMajorVersionUpgradeElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "DisallowMajorVersionUpgrade"); if (disallowMajorVersionUpgradeElement != null && disallowMajorVersionUpgradeElement.getTextContent() != null && !disallowMajorVersionUpgradeElement.getTextContent().isEmpty()) { boolean disallowMajorVersionUpgradeInstance; disallowMajorVersionUpgradeInstance = DatatypeConverter.parseBoolean( disallowMajorVersionUpgradeElement.getTextContent().toLowerCase()); resourceExtensionInstance .setDisallowMajorVersionUpgrade(disallowMajorVersionUpgradeInstance); } Element supportedOSElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "SupportedOS"); if (supportedOSElement != null) { String supportedOSInstance; supportedOSInstance = supportedOSElement.getTextContent(); resourceExtensionInstance.setSupportedOS(supportedOSInstance); } Element companyNameElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "CompanyName"); if (companyNameElement != null) { String companyNameInstance; companyNameInstance = companyNameElement.getTextContent(); resourceExtensionInstance.setCompanyName(companyNameInstance); } Element publishedDateElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PublishedDate"); if (publishedDateElement != null && publishedDateElement.getTextContent() != null && !publishedDateElement.getTextContent().isEmpty()) { Calendar publishedDateInstance; publishedDateInstance = DatatypeConverter .parseDateTime(publishedDateElement.getTextContent()); resourceExtensionInstance.setPublishedDate(publishedDateInstance); } Element regionsElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Regions"); if (regionsElement != null) { String regionsInstance; regionsInstance = regionsElement.getTextContent(); resourceExtensionInstance.setRegions(regionsInstance); } } } } 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.ManagementCertificateOperationsImpl.java
/** * The List Management Certificates operation lists and returns basic * information about all of the management certificates associated with the * specified subscription. Management certificates, which are also known as * subscription certificates, authenticate clients attempting to connect to * resources associated with your Azure subscription. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj154105.aspx for * more information)/*from ww w.j av a 2 s. c o m*/ * * @throws IOException Signals that an I/O exception of some sort has * occurred. This class is the general class of exceptions produced by * failed or interrupted I/O operations. * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The List Management Certificates operation response. */ @Override public ManagementCertificateListResponse 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 + "/certificates"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "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 ManagementCertificateListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ManagementCertificateListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element subscriptionCertificatesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificates"); if (subscriptionCertificatesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subscriptionCertificatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificate") .size(); i1 = i1 + 1) { org.w3c.dom.Element subscriptionCertificatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(subscriptionCertificatesSequenceElement, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificate") .get(i1)); ManagementCertificateListResponse.SubscriptionCertificate subscriptionCertificateInstance = new ManagementCertificateListResponse.SubscriptionCertificate(); result.getSubscriptionCertificates().add(subscriptionCertificateInstance); Element subscriptionCertificatePublicKeyElement = XmlUtility.getElementByTagNameNS( subscriptionCertificatesElement, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificatePublicKey"); if (subscriptionCertificatePublicKeyElement != null) { byte[] subscriptionCertificatePublicKeyInstance; subscriptionCertificatePublicKeyInstance = subscriptionCertificatePublicKeyElement .getTextContent() != null ? Base64.decode( subscriptionCertificatePublicKeyElement.getTextContent()) : null; subscriptionCertificateInstance.setPublicKey(subscriptionCertificatePublicKeyInstance); } Element subscriptionCertificateThumbprintElement = XmlUtility.getElementByTagNameNS( subscriptionCertificatesElement, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificateThumbprint"); if (subscriptionCertificateThumbprintElement != null) { String subscriptionCertificateThumbprintInstance; subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement .getTextContent(); subscriptionCertificateInstance .setThumbprint(subscriptionCertificateThumbprintInstance); } Element subscriptionCertificateDataElement = XmlUtility.getElementByTagNameNS( subscriptionCertificatesElement, "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificateData"); if (subscriptionCertificateDataElement != null) { byte[] subscriptionCertificateDataInstance; subscriptionCertificateDataInstance = subscriptionCertificateDataElement .getTextContent() != null ? Base64.decode(subscriptionCertificateDataElement.getTextContent()) : null; subscriptionCertificateInstance.setData(subscriptionCertificateDataInstance); } Element createdElement = XmlUtility.getElementByTagNameNS(subscriptionCertificatesElement, "http://schemas.microsoft.com/windowsazure", "Created"); if (createdElement != null) { Calendar createdInstance; createdInstance = DatatypeConverter.parseDateTime(createdElement.getTextContent()); subscriptionCertificateInstance.setCreated(createdInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationOperationsImpl.java
/** * Retrieves all of the operations that occured on the Azure SQL Database * Server./*from w ww . j a va2 s. c o m*/ * * @param serverName Required. The name of the Azure SQL Database Server to * be queried. * @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 Represents the response containing the list of database * operations for a given server or database. */ @Override public DatabaseOperationListResponse listByServer(String serverName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); CloudTracing.enter(invocationId, this, "listByServerAsync", tracingParameters); } // Construct URL String url = ""; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databaseoperations"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("contentview=generic"); 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", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseOperationListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseOperationListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); DatabaseOperation serviceResourceInstance = new DatabaseOperation(); result.getDatabaseOperations().add(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); serviceResourceInstance.setId(idInstance); } Element stateIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StateId"); if (stateIdElement != null) { int stateIdInstance; stateIdInstance = DatatypeConverter.parseInt(stateIdElement.getTextContent()); serviceResourceInstance.setStateId(stateIdInstance); } Element sessionActivityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SessionActivityId"); if (sessionActivityIdElement != null) { String sessionActivityIdInstance; sessionActivityIdInstance = sessionActivityIdElement.getTextContent(); serviceResourceInstance.setSessionActivityId(sessionActivityIdInstance); } Element databaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseName"); if (databaseNameElement != null) { String databaseNameInstance; databaseNameInstance = databaseNameElement.getTextContent(); serviceResourceInstance.setDatabaseName(databaseNameInstance); } Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "PercentComplete"); if (percentCompleteElement != null) { int percentCompleteInstance; percentCompleteInstance = DatatypeConverter .parseInt(percentCompleteElement.getTextContent()); serviceResourceInstance.setPercentComplete(percentCompleteInstance); } Element errorCodeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorCode"); if (errorCodeElement != null) { int errorCodeInstance; errorCodeInstance = DatatypeConverter.parseInt(errorCodeElement.getTextContent()); serviceResourceInstance.setErrorCode(errorCodeInstance); } Element errorElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Error"); if (errorElement != null) { String errorInstance; errorInstance = errorElement.getTextContent(); serviceResourceInstance.setError(errorInstance); } Element errorSeverityElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorSeverity"); if (errorSeverityElement != null) { int errorSeverityInstance; errorSeverityInstance = DatatypeConverter .parseInt(errorSeverityElement.getTextContent()); serviceResourceInstance.setErrorSeverity(errorSeverityInstance); } Element errorStateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorState"); if (errorStateElement != null) { int errorStateInstance; errorStateInstance = DatatypeConverter.parseInt(errorStateElement.getTextContent()); serviceResourceInstance.setErrorState(errorStateInstance); } Element startTimeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StartTime"); if (startTimeElement != null) { Calendar startTimeInstance; startTimeInstance = DatatypeConverter.parseDateTime(startTimeElement.getTextContent()); serviceResourceInstance.setStartTime(startTimeInstance); } Element lastModifyTimeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "LastModifyTime"); if (lastModifyTimeElement != null) { Calendar lastModifyTimeInstance; lastModifyTimeInstance = DatatypeConverter .parseDateTime(lastModifyTimeElement.getTextContent()); serviceResourceInstance.setLastModifyTime(lastModifyTimeInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:org.apache.taverna.scufl2.translator.t2flow.T2FlowParser.java
public void parseAnnotations(WorkflowBean annotatedBean, Annotations annotations) throws ReaderException { // logger.fine("Checking annotations for " + annotatedSubject); Map<String, NetSfTavernaT2AnnotationAnnotationAssertionImpl> annotationElems = new HashMap<>(); if (annotations == null || annotations.getAnnotationChainOrAnnotationChain22() == null) return;//from w ww .ja v a 2s. co m for (JAXBElement<AnnotationChain> el : annotations.getAnnotationChainOrAnnotationChain22()) { NetSfTavernaT2AnnotationAnnotationAssertionImpl ann = el.getValue() .getNetSfTavernaT2AnnotationAnnotationChainImpl().getAnnotationAssertions() .getNetSfTavernaT2AnnotationAnnotationAssertionImpl(); String annClass = ann.getAnnotationBean().getClazz(); if (annotationElems.containsKey(annClass) && annotationElems.get(annClass).getDate().compareToIgnoreCase(ann.getDate()) > 0) // ann.getDate() is less than current 'latest' annotation, skip continue; annotationElems.put(annClass, ann); } for (String clazz : annotationElems.keySet()) { NetSfTavernaT2AnnotationAnnotationAssertionImpl ann = annotationElems.get(clazz); Calendar cal = parseDate(ann.getDate()); String value = null; String semanticMediaType = TEXT_TURTLE; for (Object obj : ann.getAnnotationBean().getAny()) { if (!(obj instanceof Element)) continue; Element elem = (Element) obj; if (!(elem.getNamespaceURI() == null)) continue; if (elem.getLocalName().equals("text")) { value = elem.getTextContent().trim(); break; } if (clazz.equals(SEMANTIC_ANNOTATION)) { if (elem.getLocalName().equals("content")) value = elem.getTextContent().trim(); if (elem.getLocalName().equals("mimeType")) semanticMediaType = elem.getTextContent().trim(); } } if (value != null) { // Add the annotation Annotation annotation = new Annotation(); WorkflowBundle workflowBundle = parserState.get().getCurrentWorkflowBundle(); annotation.setParent(workflowBundle); String path = "annotation/" + annotation.getName() + ".ttl"; URI bodyURI = URI.create(path); annotation.setTarget(annotatedBean); annotation.setAnnotatedAt(cal); // annotation.setAnnotator(); annotation.setSerializedBy(t2flowParserURI); annotation.setSerializedAt(new GregorianCalendar()); URI annotatedSubject = uriTools.relativeUriForBean(annotatedBean, annotation); String body; if (clazz.equals(SEMANTIC_ANNOTATION)) { String baseStr = "@base <" + annotatedSubject.toASCIIString() + "> .\n"; body = baseStr + value; } else { // Generate Turtle from 'classic' annotation URI predicate = getPredicatesForClass().get(clazz); if (predicate == null) { if (isStrict()) throw new ReaderException("Unsupported annotation class " + clazz); return; } StringBuilder turtle = new StringBuilder(); turtle.append("<"); turtle.append(annotatedSubject.toASCIIString()); turtle.append("> "); turtle.append("<"); turtle.append(predicate.toASCIIString()); turtle.append("> "); // A potentially multi-line string turtle.append("\"\"\""); // Escape existing \ to \\ String escaped = value.replace("\\", "\\\\"); // Escape existing " to \" (beware Java's escaping of \ and " below) escaped = escaped.replace("\"", "\\\""); turtle.append(escaped); turtle.append("\"\"\""); turtle.append(" ."); body = turtle.toString(); } try { workflowBundle.getResources().addResource(body, path, semanticMediaType); } catch (IOException e) { throw new ReaderException("Could not store annotation body to " + path, e); } annotation.setBody(bodyURI); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationOperationsImpl.java
/** * Retrieves all of the operations that took place on a specific database. * * @param serverName Required. The name of the Azure SQL Database Server * that hosts the database.//from ww w.j a v a2 s.c o m * @param databaseName Required. The name of the database for which the * operations should be retrieved. * @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 Represents the response containing the list of database * operations for a given server or database. */ @Override public DatabaseOperationListResponse listByDatabase(String serverName, String databaseName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); CloudTracing.enter(invocationId, this, "listByDatabaseAsync", tracingParameters); } // Construct URL String url = ""; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databaseoperations"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("databaseName=" + URLEncoder.encode(databaseName, "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", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseOperationListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseOperationListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); DatabaseOperation serviceResourceInstance = new DatabaseOperation(); result.getDatabaseOperations().add(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); serviceResourceInstance.setId(idInstance); } Element stateIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StateId"); if (stateIdElement != null) { int stateIdInstance; stateIdInstance = DatatypeConverter.parseInt(stateIdElement.getTextContent()); serviceResourceInstance.setStateId(stateIdInstance); } Element sessionActivityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SessionActivityId"); if (sessionActivityIdElement != null) { String sessionActivityIdInstance; sessionActivityIdInstance = sessionActivityIdElement.getTextContent(); serviceResourceInstance.setSessionActivityId(sessionActivityIdInstance); } Element databaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DatabaseName"); if (databaseNameElement != null) { String databaseNameInstance; databaseNameInstance = databaseNameElement.getTextContent(); serviceResourceInstance.setDatabaseName(databaseNameInstance); } Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "PercentComplete"); if (percentCompleteElement != null) { int percentCompleteInstance; percentCompleteInstance = DatatypeConverter .parseInt(percentCompleteElement.getTextContent()); serviceResourceInstance.setPercentComplete(percentCompleteInstance); } Element errorCodeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorCode"); if (errorCodeElement != null) { int errorCodeInstance; errorCodeInstance = DatatypeConverter.parseInt(errorCodeElement.getTextContent()); serviceResourceInstance.setErrorCode(errorCodeInstance); } Element errorElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Error"); if (errorElement != null) { String errorInstance; errorInstance = errorElement.getTextContent(); serviceResourceInstance.setError(errorInstance); } Element errorSeverityElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorSeverity"); if (errorSeverityElement != null) { int errorSeverityInstance; errorSeverityInstance = DatatypeConverter .parseInt(errorSeverityElement.getTextContent()); serviceResourceInstance.setErrorSeverity(errorSeverityInstance); } Element errorStateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ErrorState"); if (errorStateElement != null) { int errorStateInstance; errorStateInstance = DatatypeConverter.parseInt(errorStateElement.getTextContent()); serviceResourceInstance.setErrorState(errorStateInstance); } Element startTimeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "StartTime"); if (startTimeElement != null) { Calendar startTimeInstance; startTimeInstance = DatatypeConverter.parseDateTime(startTimeElement.getTextContent()); serviceResourceInstance.setStartTime(startTimeInstance); } Element lastModifyTimeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "LastModifyTime"); if (lastModifyTimeElement != null) { Calendar lastModifyTimeInstance; lastModifyTimeInstance = DatatypeConverter .parseDateTime(lastModifyTimeElement.getTextContent()); serviceResourceInstance.setLastModifyTime(lastModifyTimeInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java
/** * Adds the actions.//from w w w .j a v a 2 s . c o m * * @param actionsDocument * the actions document * @param classes * the classes * @deprecated */ @Deprecated @SuppressWarnings("unused") private void addActions(Document actionsDocument, List<Class<?>> classes) { NodeList actionNodes = actionsDocument.getDocumentElement().getChildNodes(); for (int i = 0; i < actionNodes.getLength(); i++) { Node item = actionNodes.item(i); if (item instanceof Element) { Element action = (Element) item; if (action.getTagName().equals("action")) { String className = null; NodeList childNodes = action.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if (childNode instanceof Element) { Element subElement = (Element) childNode; if (subElement.getTagName().equals("class")) { className = StringUtils.trimToNull(subElement.getTextContent()); } } } if (className != null) { try { Class<?> actionClassName = Class.forName(className); classes.add(actionClassName); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error(e); } } } } } } }
From source file:com.microsoft.windowsazure.management.mediaservices.AccountOperationsImpl.java
/** * The List Media Services Account operation gets information about all * existing media services accounts associated with the current * subscription in Windows Azure. (see//from w w w . j a v a2 s .co m * http://msdn.microsoft.com/en-us/library/windowsazure/dn166989.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 Media Accounts operation response. */ @Override public MediaServicesAccountListResponse 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/mediaservices/Accounts"; 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", "2011-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 MediaServicesAccountListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new MediaServicesAccountListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); MediaServicesAccountListResponse.MediaServiceAccount serviceResourceInstance = new MediaServicesAccountListResponse.MediaServiceAccount(); result.getAccounts().add(serviceResourceInstance); Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); serviceResourceInstance.setUri(selfLinkInstance); } Element parentLinkElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ParentLink"); if (parentLinkElement != null) { URI parentLinkInstance; parentLinkInstance = new URI(parentLinkElement.getTextContent()); serviceResourceInstance.setParentUri(parentLinkInstance); } Element accountIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "AccountId"); if (accountIdElement != null) { String accountIdInstance; accountIdInstance = accountIdElement.getTextContent(); serviceResourceInstance.setAccountId(accountIdInstance); } } } } 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.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //from www . j a v a 2 s . com * @param entity * @return * @throws Exception */ public static final List<Element> createV5EntityFromBusinessObject(final Entity entity) throws Exception { /* Create list of elements */ final List<Element> elementList = new ArrayList<Element>(); /* Set entity id */ elementList.add(createMessageElement("id", entity.getId())); /* Step 2: get all node attributes */ final AttributeCollection attCol = entity.getAttributes(); /* Check if entity is not null */ if (attCol != null) { /* Get all attributes for the CRM field */ final KeyValuePairOfstringanyType[] kvpsatArr = attCol.getKeyValuePairOfstringanyTypeArray(); /* This is to avoid : 'DOM Level 3 Not implemented' error */ final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document document = builder.newDocument(); if (logger.isDebugEnabled()) { logger.debug("----Inside createV5EntityFromBusinessObject: no of crm fields: " + kvpsatArr.length); } /* Iterate over all attributes */ for (final KeyValuePairOfstringanyType kvpsat : kvpsatArr) { /* Get field name */ final String fieldName = kvpsat.getKey(); if (logger.isDebugEnabled()) { logger.debug("----Inside createV5EntityFromBusinessObject: crm field name: " + fieldName); } /* Get field value */ String fieldValue = null; /* Get field value node */ final XmlObject xo = kvpsat.getValue(); /* If object is valid */ if (xo != null) { /* Get DOM node from Xo */ final Node node = xo.getDomNode(); /* Check if node is not null */ if (node != null && node.hasChildNodes()) { /* Get all child nodes */ final NodeList nodeList = node.getChildNodes(); /* Create new map for attributes */ final Map<String, String> attributeMap = new HashMap<String, String>(); /* If more than 1 elements in node list */ if (nodeList.getLength() > 1) { /* Iterate on all child node list */ for (int i = 0; i < nodeList.getLength(); i++) { if (nodeList.item(i) instanceof Element) { final Element childElement = (Element) document.importNode(nodeList.item(i), true); if (childElement.getNodeName() != null && childElement.getNodeName().contains(":")) { /* Get attribute name */ final String attName = childElement.getNodeName().split(":")[1]; /* Get attribute value */ final String attValue = childElement.getTextContent(); if ("id".equalsIgnoreCase(attName)) { fieldValue = attValue; } else { /* Put values in map */ attributeMap.put(attName, attValue); } } } } /* Create node with attributes */ elementList.add(createMessageElement(fieldName, fieldValue, attributeMap)); } else if (nodeList.getLength() == 1) { /* Iterate on all child node list */ if (nodeList.item(0) instanceof Element) { final Element childElement = (Element) document.importNode(nodeList.item(0), true); /* Get attribute value */ fieldValue = childElement.getTextContent(); /* Create node with attributes */ elementList.add(createMessageElement(fieldName, fieldValue)); } else { /* Create node with attributes */ elementList.add(createMessageElement(fieldName, nodeList.item(0).getNodeValue())); } } } else { /* Create node with attributes */ elementList.add(createMessageElement(fieldName, node.getTextContent())); } } } } return elementList; }
From source file:com.evolveum.midpoint.prism.schema.DomToSchemaPostProcessor.java
private void parseItemDefinitionAnnotations(ItemDefinitionImpl itemDef, XSAnnotation annotation) throws SchemaException { if (annotation == null || annotation.getAnnotation() == null) { return;//from w ww. j a va 2 s .co m } // ignore Boolean ignore = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_IGNORE); if (ignore != null) { itemDef.setProcessing(ItemProcessing.IGNORE); } Element processing = SchemaProcessorUtil.getAnnotationElement(annotation, A_PROCESSING); if (processing != null) { itemDef.setProcessing(ItemProcessing.findByValue(processing.getTextContent())); } // deprecated Boolean deprecated = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_DEPRECATED); if (deprecated != null) { itemDef.setDeprecated(deprecated); } // deprecated since Element deprecatedSince = SchemaProcessorUtil.getAnnotationElement(annotation, A_DEPRECATED_SINCE); if (deprecatedSince != null) { itemDef.setDeprecatedSince(deprecatedSince.getTextContent()); } // experimental Boolean experimental = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_EXPERIMENTAL); if (experimental != null) { itemDef.setExperimental(experimental); } // elaborate Boolean elaborate = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_ELABORATE); if (elaborate != null) { itemDef.setElaborate(elaborate); } // operational Boolean operational = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_OPERATIONAL); if (operational != null) { itemDef.setOperational(operational); } // displayName Element attributeDisplayName = SchemaProcessorUtil.getAnnotationElement(annotation, A_DISPLAY_NAME); if (attributeDisplayName != null) { itemDef.setDisplayName(attributeDisplayName.getTextContent()); } // displayOrder Element displayOrderElement = SchemaProcessorUtil.getAnnotationElement(annotation, A_DISPLAY_ORDER); if (displayOrderElement != null) { Integer displayOrder = DOMUtil.getIntegerValue(displayOrderElement); itemDef.setDisplayOrder(displayOrder); } // help Element help = SchemaProcessorUtil.getAnnotationElement(annotation, A_HELP); if (help != null) { itemDef.setHelp(help.getTextContent()); } // emphasized Boolean emphasized = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_EMPHASIZED); if (emphasized != null) { itemDef.setEmphasized(emphasized); } // documentation extractDocumentation(itemDef, annotation); Boolean heterogeneousListItem = SchemaProcessorUtil.getAnnotationBooleanMarker(annotation, A_HETEROGENEOUS_LIST_ITEM); if (heterogeneousListItem != null) { itemDef.setHeterogeneousListItem(heterogeneousListItem); } }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private FileUpdateOperation updateFileNodeWith(Element target, Element update) throws FedoraClientException, IOException, XPathExpressionException { FileUpdateOperation fupo = new FileUpdateOperation(); NodeList updateNodes = update.getChildNodes(); for (int i = 0; i < updateNodes.getLength(); i++) { if (updateNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element updateField = (Element) updateNodes.item(i); String updateFieldLocalName = updateField.getLocalName(); Element targetElement = (Element) target.getElementsByTagName(updateFieldLocalName).item(0); if (targetElement == null) { targetElement = target.getOwnerDocument().createElement(updateFieldLocalName); target.appendChild(targetElement); targetElement.appendChild(target.getOwnerDocument().createTextNode("")); }/* w ww. ja v a2 s. c om*/ String oldVal = targetElement.getTextContent(); String newVal = updateField.getTextContent(); if (!oldVal.equals(newVal)) { switch (updateFieldLocalName) { case "PathName": if (!newVal.isEmpty()) fupo.rename(oldVal, newVal); break; case "Label": fupo.newLabel(updateField.getTextContent()); break; case "FrontdoorVisible": fupo.newState(determineDatastreamState(update)); break; } targetElement.setTextContent(updateField.getTextContent()); } } } return fupo; }