List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java
@Override public Date getSigningTime() { try {//from w ww .jav a 2 s .c o m Element signingTimeEl = XMLUtils.getElement(signatureElement, "ds:Object/xades:QualifyingProperties/xades:SignedProperties/xades:SignedSignatureProperties/" + "./xades:SigningTime"); if (signingTimeEl == null) { return null; } String text = signingTimeEl.getTextContent(); DatatypeFactory factory = DatatypeFactory.newInstance(); XMLGregorianCalendar cal = factory.newXMLGregorianCalendar(text); return cal.toGregorianCalendar().getTime(); } catch (DOMException e) { throw new RuntimeException(e); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } catch (XPathExpressionException e) { throw new EncodingException(MSG.SIGNING_TIME_ENCODING); } }
From source file:org.apache.servicemix.http.ConsumerEndpointTest.java
public void testHttpSoap11UnkownOp() throws Exception { initSoapEndpoints(true);// w w w. j a v a 2 s .c o m PostMethod post = new PostMethod("http://localhost:8192/ep1/"); post.setRequestEntity( new StringRequestEntity("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" + "<s:Body><hello>world</hello></s:Body>" + "</s:Envelope>")); new HttpClient().executeMethod(post); String res = post.getResponseBodyAsString(); log.info(res); Element elem = transformer.toDOMElement(new StringSource(res)); assertEquals(Soap11.getInstance().getEnvelope(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(Soap11.getInstance().getBody(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(Soap11.getInstance().getFault(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(SoapConstants.SOAP_11_FAULTCODE, DomUtil.getQName(elem)); assertEquals(SoapConstants.SOAP_11_CODE_CLIENT, DomUtil.createQName(elem, elem.getTextContent())); assertEquals(500, post.getStatusCode()); }
From source file:com.microsoft.windowsazure.management.sql.ServiceObjectiveOperationsImpl.java
/** * Returns information about a certain Service Objective with a specific Id. * * @param serverName Required. The name of the Azure SQL Database Server to * be queried./*from ww w . j a va 2s. c o m*/ * @param serviceObjectiveId Required. The Id of the Service Objective to be * obtained. * @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 Response containing the service objective for a given Azure SQL * Database Server with matching service objective Id. */ @Override public ServiceObjectiveGetResponse get(String serverName, String serviceObjectiveId) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (serviceObjectiveId == null) { throw new NullPointerException("serviceObjectiveId"); } // 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("serviceObjectiveId", serviceObjectiveId); CloudTracing.enter(invocationId, this, "getAsync", 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 + "/serviceobjectives/"; url = url + URLEncoder.encode(serviceObjectiveId, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServiceObjectiveGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceObjectiveGetResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement != null) { ServiceObjective serviceResourceInstance = new ServiceObjective(); result.setServiceObjective(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { String idInstance; idInstance = idElement.getTextContent(); serviceResourceInstance.setId(idInstance); } Element isDefaultElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "IsDefault"); if (isDefaultElement != null) { boolean isDefaultInstance; isDefaultInstance = DatatypeConverter .parseBoolean(isDefaultElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsDefault(isDefaultInstance); } Element isSystemElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "IsSystem"); if (isSystemElement != null) { boolean isSystemInstance; isSystemInstance = DatatypeConverter .parseBoolean(isSystemElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystem(isSystemInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); serviceResourceInstance.setDescription(descriptionInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); serviceResourceInstance.setEnabled(enabledInstance); } Element dimensionSettingsSequenceElement = XmlUtility.getElementByTagNameNS( serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "DimensionSettings"); if (dimensionSettingsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dimensionSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element dimensionSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dimensionSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); ServiceObjective.DimensionSettingResponse serviceResourceInstance2 = new ServiceObjective.DimensionSettingResponse(); serviceResourceInstance.getDimensionSettings().add(serviceResourceInstance2); Element idElement2 = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement2 != null) { String idInstance2; idInstance2 = idElement2.getTextContent(); serviceResourceInstance2.setId(idInstance2); } Element descriptionElement2 = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement2 != null) { String descriptionInstance2; descriptionInstance2 = descriptionElement2.getTextContent(); serviceResourceInstance2.setDescription(descriptionInstance2); } Element ordinalElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Ordinal"); if (ordinalElement != null) { byte ordinalInstance; ordinalInstance = DatatypeConverter.parseByte(ordinalElement.getTextContent()); serviceResourceInstance2.setOrdinal(ordinalInstance); } Element isDefaultElement2 = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "IsDefault"); if (isDefaultElement2 != null) { boolean isDefaultInstance2; isDefaultInstance2 = DatatypeConverter .parseBoolean(isDefaultElement2.getTextContent().toLowerCase()); serviceResourceInstance2.setIsDefault(isDefaultInstance2); } Element nameElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance2.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance2.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance2.setState(stateInstance); } } } Element nameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); serviceResourceInstance.setName(nameInstance2); } Element typeElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement2 != null) { String typeInstance2; typeInstance2 = typeElement2.getTextContent(); serviceResourceInstance.setType(typeInstance2); } Element stateElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement2 != null) { String stateInstance2; stateInstance2 = stateElement2.getTextContent(); serviceResourceInstance.setState(stateInstance2); } } } 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.servicemix.http.ConsumerEndpointTest.java
public void testHttpSoap11FaultOnEnvelope() throws Exception { initSoapEndpoints(true);//from ww w . j a v a2 s . c o m PostMethod post = new PostMethod("http://localhost:8192/ep1/"); post.setRequestEntity(new StringRequestEntity("<hello>world</hello>")); new HttpClient().executeMethod(post); String res = post.getResponseBodyAsString(); log.info(res); Element elem = transformer.toDOMElement(new StringSource(res)); assertEquals(Soap11.getInstance().getEnvelope(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(Soap11.getInstance().getBody(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(Soap11.getInstance().getFault(), DomUtil.getQName(elem)); elem = DomUtil.getFirstChildElement(elem); assertEquals(SoapConstants.SOAP_11_FAULTCODE, DomUtil.getQName(elem)); assertEquals(SoapConstants.SOAP_11_CODE_VERSIONMISMATCH, DomUtil.createQName(elem, elem.getTextContent())); assertEquals(500, post.getStatusCode()); }
From source file:com.mirth.connect.model.util.ImportConverter.java
private static void updateTransformerFor1_4(Document document, Element transformerRoot, String incoming, String outgoing) {/*from w ww . j a v a 2 s . c o m*/ String template = ""; Element transformerTemplate = null; if (transformerRoot.getElementsByTagName("template").getLength() > 0) { transformerTemplate = (Element) transformerRoot.getElementsByTagName("template").item(0); if (transformerTemplate != null) template = transformerTemplate.getTextContent(); } Element inboundTemplateElement = null, outboundTemplateElement = null, inboundProtocolElement = null, outboundProtocolElement = null; if (transformerRoot.getElementsByTagName("inboundTemplate").getLength() == 0) inboundTemplateElement = document.createElement("inboundTemplate"); if (transformerRoot.getElementsByTagName("outboundTemplate").getLength() == 0) outboundTemplateElement = document.createElement("outboundTemplate"); if (transformerRoot.getElementsByTagName("inboundProtocol").getLength() == 0) { inboundProtocolElement = document.createElement("inboundProtocol"); inboundProtocolElement.setTextContent(incoming.toString()); } if (transformerRoot.getElementsByTagName("outboundProtocol").getLength() == 0) { outboundProtocolElement = document.createElement("outboundProtocol"); outboundProtocolElement.setTextContent(outgoing.toString()); } if (transformerTemplate != null) { if (incoming.equals(HL7V2) && outgoing.equals(HL7V2)) { inboundTemplateElement.setTextContent(template); } else if (outgoing.equals(HL7V2)) { outboundTemplateElement.setTextContent(template); } } if (transformerRoot.getElementsByTagName("inboundTemplate").getLength() == 0) transformerRoot.appendChild(inboundTemplateElement); if (transformerRoot.getElementsByTagName("outboundTemplate").getLength() == 0) transformerRoot.appendChild(outboundTemplateElement); if (transformerRoot.getElementsByTagName("inboundProtocol").getLength() == 0) transformerRoot.appendChild(inboundProtocolElement); if (transformerRoot.getElementsByTagName("outboundProtocol").getLength() == 0) transformerRoot.appendChild(outboundProtocolElement); // replace HL7 Message builder with Message Builder NodeList steps = getElements(transformerRoot, "step", "com.mirth.connect.model.Step"); for (int i = 0; i < steps.getLength(); i++) { Element step = (Element) steps.item(i); NodeList stepTypesList = step.getElementsByTagName("type"); if (stepTypesList.getLength() > 0) { Element stepType = (Element) stepTypesList.item(0); if (stepType.getTextContent().equals("HL7 Message Builder")) { stepType.setTextContent("Message Builder"); } if (stepType.getTextContent().equals("Message Builder") || stepType.getTextContent().equals("Mapper")) { boolean foundRegex = false, foundDefaultValue = false; Element data = (Element) step.getElementsByTagName("data").item(0); NodeList entries = data.getElementsByTagName("entry"); for (int j = 0; j < entries.getLength(); j++) { NodeList strings = ((Element) entries.item(j)).getElementsByTagName("string"); if (strings.getLength() > 0) { if (strings.item(0).getTextContent().equals("RegularExpressions")) foundRegex = true; else if (strings.item(0).getTextContent().equals("DefaultValue")) foundDefaultValue = true; if (strings.item(0).getTextContent().equals("isGlobal")) { if (strings.item(1).getTextContent().equals("0")) strings.item(1).setTextContent("channel"); else if (strings.item(1).getTextContent().equals("1")) strings.item(1).setTextContent("global"); } } } if (!foundRegex) data.appendChild(createRegexElement(document)); if (!foundDefaultValue) data.appendChild(createDefaultValueElement(document)); } } } if (transformerTemplate != null) transformerRoot.removeChild(transformerTemplate); }
From source file:com.evolveum.midpoint.prism.schema.DomToSchemaProcessor.java
/** * Creates appropriate instance of PropertyDefinition. * It creates either PropertyDefinition itself or one of its subclasses (ResourceObjectAttributeDefinition). The behavior * depends of the "mode" of the schema. This method is also processing annotations and other fancy property-relates stuff. *///from w w w . j a va 2 s. co m private <T> PrismPropertyDefinition<T> createPropertyDefinition(XSType xsType, QName elementName, QName typeName, ComplexTypeDefinition ctd, XSAnnotation annotation, XSParticle elementParticle) throws SchemaException { PrismPropertyDefinition<T> propDef; SchemaDefinitionFactory definitionFactory = getDefinitionFactory(); Collection<? extends DisplayableValue<T>> allowedValues = parseEnumAllowedValues(xsType); Object defaultValue = parseDefaultValue(elementParticle, typeName); propDef = definitionFactory.createPropertyDefinition(elementName, typeName, ctd, prismContext, annotation, elementParticle, allowedValues, null); setMultiplicity(propDef, elementParticle, annotation, ctd == null); // Process generic annotations parseItemDefinitionAnnotations(propDef, annotation); List<Element> accessElements = SchemaProcessorUtil.getAnnotationElements(annotation, A_ACCESS); if (accessElements == null || accessElements.isEmpty()) { // Default access is read-write-create propDef.setCanAdd(true); propDef.setCanModify(true); propDef.setCanRead(true); } else { propDef.setCanAdd(false); propDef.setCanModify(false); propDef.setCanRead(false); for (Element e : accessElements) { String access = e.getTextContent(); if (access.equals(A_ACCESS_CREATE)) { propDef.setCanAdd(true); } if (access.equals(A_ACCESS_UPDATE)) { propDef.setCanModify(true); } if (access.equals(A_ACCESS_READ)) { propDef.setCanRead(true); } } } markRuntime(propDef); Element indexableElement = SchemaProcessorUtil.getAnnotationElement(annotation, A_INDEXED); if (indexableElement != null) { Boolean indexable = XmlTypeConverter.toJavaValue(indexableElement, Boolean.class); propDef.setIndexed(indexable); } return propDef; }
From source file:com.googlecode.jdeltasync.DeltaSyncClient.java
private void checkStatus(Document doc) throws DeltaSyncException { Element status = XmlUtil.getElement(doc.getDocumentElement(), "*:Status"); if (status == null) { // All responses should have a <Status> element throw new DeltaSyncException("No <Status> element found in response: " + XmlUtil.toString(doc, true)); }/*from ww w . ja va 2 s . com*/ int code = Integer.parseInt(status.getTextContent().trim()); if (code != 1) { String message = XmlUtil.getTextContent(doc.getDocumentElement(), "*:Fault/*:Faultstring"); if (message == null) { message = "No Faultstring provided in response. Response was: " + XmlUtil.toString(doc, true); } switch (code) { case 3204: // Authentication failure. We assume this means that the session has expired. throw new SessionExpiredException(message); case 4102: // The server failed to understand the request due to a syntax error or an error in the parameters. throw new BadRequestException(message); case 4104: // Invalid sync key. throw new InvalidSyncKeyException(message); case 4402: throw new NoSuchFolderException(message); default: throw new UnrecognizedErrorCodeException(code, message); } } }
From source file:com.microsoft.windowsazure.management.sql.ServerOperationsImpl.java
/** * Returns all SQL Database Servers that are provisioned for a subscription. * * @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.//w w w . j a v a 2 s . com * @throws ServiceException Thrown if an unexpected response is found. * @throws ParserConfigurationException Thrown if there was a serious * configuration error with the document parser. * @throws SAXException Thrown if there was an error parsing the XML * response. * @return The response structure for the Server List operation. Contains a * list of all the servers in a subscription. */ @Override public ServerListResponse list() throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); CloudTracing.enter(invocationId, this, "listAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/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 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 ServerListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServerListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serversSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/sqlazure/2010/12/", "Servers"); if (serversSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serversSequenceElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "Server") .size(); i1 = i1 + 1) { org.w3c.dom.Element serversElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serversSequenceElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "Server") .get(i1)); Server serverInstance = new Server(); result.getServers().add(serverInstance); Element nameElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serverInstance.setName(nameInstance); } Element administratorLoginElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "AdministratorLogin"); if (administratorLoginElement != null) { String administratorLoginInstance; administratorLoginInstance = administratorLoginElement.getTextContent(); serverInstance.setAdministratorUserName(administratorLoginInstance); } Element locationElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "Location"); if (locationElement != null) { String locationInstance; locationInstance = locationElement.getTextContent(); serverInstance.setLocation(locationInstance); } Element fullyQualifiedDomainNameElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "FullyQualifiedDomainName"); if (fullyQualifiedDomainNameElement != null) { String fullyQualifiedDomainNameInstance; fullyQualifiedDomainNameInstance = fullyQualifiedDomainNameElement.getTextContent(); serverInstance.setFullyQualifiedDomainName(fullyQualifiedDomainNameInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serverInstance.setState(stateInstance); } Element versionElement = XmlUtility.getElementByTagNameNS(serversElement, "http://schemas.microsoft.com/sqlazure/2010/12/", "Version"); if (versionElement != null) { String versionInstance; versionInstance = versionElement.getTextContent(); serverInstance.setVersion(versionInstance); } } } } 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.ServiceObjectiveOperationsImpl.java
/** * Returns information about all Service Objectives on an Azure SQL Database * Server.// www . j av a2s. 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 Response containing the list of service objective for a given * server. This is returnedfrom a call to List Service Objectives. */ @Override public ServiceObjectiveListResponse list(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, "listAsync", 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 + "/serviceobjectives"; 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 ServiceObjectiveListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceObjectiveListResponse(); 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)); ServiceObjective serviceResourceInstance = new ServiceObjective(); result.getServiceObjectives().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 isDefaultElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsDefault"); if (isDefaultElement != null) { boolean isDefaultInstance; isDefaultInstance = DatatypeConverter .parseBoolean(isDefaultElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsDefault(isDefaultInstance); } Element isSystemElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "IsSystem"); if (isSystemElement != null) { boolean isSystemInstance; isSystemInstance = DatatypeConverter .parseBoolean(isSystemElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystem(isSystemInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); serviceResourceInstance.setDescription(descriptionInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); serviceResourceInstance.setEnabled(enabledInstance); } Element dimensionSettingsSequenceElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "DimensionSettings"); if (dimensionSettingsSequenceElement != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dimensionSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i2 = i2 + 1) { org.w3c.dom.Element dimensionSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(dimensionSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i2)); ServiceObjective.DimensionSettingResponse serviceResourceInstance2 = new ServiceObjective.DimensionSettingResponse(); serviceResourceInstance.getDimensionSettings().add(serviceResourceInstance2); Element idElement2 = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement2 != null) { String idInstance2; idInstance2 = idElement2.getTextContent(); serviceResourceInstance2.setId(idInstance2); } Element descriptionElement2 = XmlUtility.getElementByTagNameNS( dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement2 != null) { String descriptionInstance2; descriptionInstance2 = descriptionElement2.getTextContent(); serviceResourceInstance2.setDescription(descriptionInstance2); } Element ordinalElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Ordinal"); if (ordinalElement != null) { byte ordinalInstance; ordinalInstance = DatatypeConverter.parseByte(ordinalElement.getTextContent()); serviceResourceInstance2.setOrdinal(ordinalInstance); } Element isDefaultElement2 = XmlUtility.getElementByTagNameNS( dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "IsDefault"); if (isDefaultElement2 != null) { boolean isDefaultInstance2; isDefaultInstance2 = DatatypeConverter .parseBoolean(isDefaultElement2.getTextContent().toLowerCase()); serviceResourceInstance2.setIsDefault(isDefaultInstance2); } Element nameElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance2.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance2.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(dimensionSettingsElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance2.setState(stateInstance); } } } Element nameElement2 = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance2; nameInstance2 = nameElement2.getTextContent(); serviceResourceInstance.setName(nameInstance2); } Element typeElement2 = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement2 != null) { String typeInstance2; typeInstance2 = typeElement2.getTextContent(); serviceResourceInstance.setType(typeInstance2); } Element stateElement2 = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement2 != null) { String stateInstance2; stateInstance2 = stateElement2.getTextContent(); serviceResourceInstance.setState(stateInstance2); } } } } 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:net.pms.util.CoverArtArchiveUtil.java
private ArrayList<ReleaseRecord> parseRelease(final Document document, final CoverArtArchiveTagInfo tagInfo) { NodeList nodeList = document.getDocumentElement().getElementsByTagName("release-list"); if (nodeList.getLength() < 1) { return null; }//from w w w .j a v a 2 s.co m Element listElement = (Element) nodeList.item(0); // release-list nodeList = listElement.getElementsByTagName("release"); if (nodeList.getLength() < 1) { return null; } Pattern pattern = Pattern.compile("\\d{4}"); ArrayList<ReleaseRecord> releaseList = new ArrayList<>(nodeList.getLength()); for (int i = 0; i < nodeList.getLength(); i++) { if (nodeList.item(i) instanceof Element) { Element releaseElement = (Element) nodeList.item(i); ReleaseRecord release = new ReleaseRecord(); release.id = releaseElement.getAttribute("id"); try { release.score = Integer.parseInt(releaseElement.getAttribute("ext:score")); } catch (NumberFormatException e) { release.score = 0; } try { release.title = getChildElement(releaseElement, "title").getTextContent(); } catch (NullPointerException e) { release.title = null; } Element releaseGroup = getChildElement(releaseElement, "release-group"); if (releaseGroup != null) { try { release.type = ReleaseType .valueOf(getChildElement(releaseGroup, "primary-type").getTextContent()); } catch (IllegalArgumentException | NullPointerException e) { release.type = null; } } Element releaseYear = getChildElement(releaseElement, "date"); if (releaseYear != null) { release.year = releaseYear.getTextContent(); Matcher matcher = pattern.matcher(release.year); if (matcher.find()) { release.year = matcher.group(); } else { release.year = null; } } else { release.year = null; } Element artists = getChildElement(releaseElement, "artist-credit"); if (artists != null && artists.getChildNodes().getLength() > 0) { NodeList artistList = artists.getChildNodes(); for (int j = 0; j < artistList.getLength(); j++) { Node node = artistList.item(j); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("name-credit") && node instanceof Element) { Element artistElement = getChildElement((Element) node, "artist"); if (artistElement != null) { Element artistNameElement = getChildElement(artistElement, "name"); if (artistNameElement != null) { release.artists.add(artistNameElement.getTextContent()); } } } } } if (StringUtil.hasValue(release.id)) { releaseList.add(release); } } } return releaseList; }