List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //w ww.j a v a 2 s . co m * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Task createCRMObjectTypeTask(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ final Task task = Task.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = task.newCursor(); cursor.toFirstContentToken(); final Node node = cursor.getDomNode(); /* Get main namespace URl */ if (node != null) { final String nsURL = node.getNamespaceURI(); /* Iterate on the Element list and create SOAP object */ for (final Element element : cADbject.getXmlContent()) { if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Task: adding node : " + element.getNodeName() + " with value : " + element.getTextContent()); } /* Get crm field */ final String crmField = element.getNodeName(); String crmFieldName = null; /* If field contains the type information */ if (crmField != null && crmField.contains(crmFieldIntraSeparator)) { /* Split the field and get name */ crmFieldName = crmField.split(crmFieldIntraSeparator)[0]; } else { crmFieldName = crmField; } /* Add all new nodes */ cursor.beginElement(new QName(nsURL, crmFieldName)); /* Set node attributes */ if (element.getAttributes() != null) { /* Get attribute map */ final NamedNodeMap namedNodeMap = element.getAttributes(); /* Interate over map */ for (int i = 0; i < namedNodeMap.getLength(); i++) { /* Get respective item */ final Node namedNode = namedNodeMap.item(i); if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Task: adding attribute name : " + namedNode.getNodeName() + " with value : " + namedNode.getNodeValue()); } /* Set node attribute */ cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue()); } } /* Set node value */ cursor.insertChars(element.getTextContent()); /* Jump to next token */ cursor.toNextToken(); } } } finally { if (cursor != null) { cursor.dispose(); } } return task; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * // w ww . j ava 2 s . com * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Account createCRMObjectTypeAccount(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ final Account account = Account.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = account.newCursor(); cursor.toFirstContentToken(); final Node node = cursor.getDomNode(); /* Get main namespace URl */ if (node != null) { final String nsURL = node.getNamespaceURI(); /* Iterate on the Element list and create SOAP object */ for (final Element element : cADbject.getXmlContent()) { if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Account: adding node: " + element.getNodeName() + " with value : " + element.getTextContent()); } /* Get crm field */ final String crmField = element.getNodeName(); String crmFieldName = null; /* If field contains the type information */ if (crmField != null && crmField.contains(crmFieldIntraSeparator)) { /* Split the field and get name */ crmFieldName = crmField.split(crmFieldIntraSeparator)[0]; } else { crmFieldName = crmField; } /* Add all new nodes */ cursor.beginElement(new QName(nsURL, crmFieldName)); /* Set node attributes */ if (element.getAttributes() != null) { /* Get attribute map */ final NamedNodeMap namedNodeMap = element.getAttributes(); /* Interate over map */ for (int i = 0; i < namedNodeMap.getLength(); i++) { /* Get respective item */ final Node namedNode = namedNodeMap.item(i); if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Account: adding attribute name : " + namedNode.getNodeName() + " with value : " + namedNode.getNodeValue()); } /* Set node attribute */ cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue()); } } /* Set node value */ cursor.insertChars(element.getTextContent()); /* Jump to next token */ cursor.toNextToken(); } } } finally { if (cursor != null) { cursor.dispose(); } } return account; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * /*from ww w .ja v a 2 s.c om*/ * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Contact createCRMObjectTypeContact(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ final Contact contact = Contact.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = contact.newCursor(); cursor.toFirstContentToken(); final Node node = cursor.getDomNode(); /* Get main namespace URl */ if (node != null) { final String nsURL = node.getNamespaceURI(); /* Iterate on the Element list and create SOAP object */ for (final Element element : cADbject.getXmlContent()) { if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Contact: adding node : " + element.getNodeName() + " with value : " + element.getTextContent()); } /* Get crm field */ final String crmField = element.getNodeName(); String crmFieldName = null; /* If field contains the type information */ if (crmField != null && crmField.contains(crmFieldIntraSeparator)) { /* Split the field and get name */ crmFieldName = crmField.split(crmFieldIntraSeparator)[0]; } else { crmFieldName = crmField; } /* Add all new nodes */ cursor.beginElement(new QName(nsURL, crmFieldName)); /* Set node attributes */ if (element.getAttributes() != null) { /* Get attribute map */ final NamedNodeMap namedNodeMap = element.getAttributes(); /* Interate over map */ for (int i = 0; i < namedNodeMap.getLength(); i++) { /* Get respective item */ final Node namedNode = namedNodeMap.item(i); if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Contact: adding attribute name : " + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue()); } /* Set node attribute */ cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue()); } } /* Set node value */ cursor.insertChars(element.getTextContent()); /* Jump to next token */ cursor.toNextToken(); } } } finally { if (cursor != null) { cursor.dispose(); } } return contact; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * // ww w. j a v a 2 s . co m * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Incident createCRMObjectTypeIncident(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ /* In MS CRM 'Incident' is actually a 'Case' */ final Incident caseObject = Incident.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = caseObject.newCursor(); cursor.toFirstContentToken(); final Node node = cursor.getDomNode(); /* Get main namespace URl */ if (node != null) { final String nsURL = node.getNamespaceURI(); /* Iterate on the Element list and create SOAP object */ for (final Element element : cADbject.getXmlContent()) { if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Incident: adding node : " + element.getNodeName() + " with value : " + element.getTextContent()); } /* Get crm field */ final String crmField = element.getNodeName(); String crmFieldName = null; /* If field contains the type information */ if (crmField != null && crmField.contains(crmFieldIntraSeparator)) { /* Split the field and get name */ crmFieldName = crmField.split(crmFieldIntraSeparator)[0]; } else { crmFieldName = crmField; } /* Add all new nodes */ cursor.beginElement(new QName(nsURL, crmFieldName)); /* Set node attributes */ if (element.getAttributes() != null) { /* Get attribute map */ final NamedNodeMap namedNodeMap = element.getAttributes(); /* Interate over map */ for (int i = 0; i < namedNodeMap.getLength(); i++) { /* Get respective item */ final Node namedNode = namedNodeMap.item(i); if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Incident: adding attribute name : " + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue()); } /* Set node attribute */ cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue()); } } /* Set node value */ cursor.insertChars(element.getTextContent()); /* Jump to next token */ cursor.toNextToken(); } } } finally { if (cursor != null) { cursor.dispose(); } } return caseObject; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //w ww .j av a 2s . c o m * @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:de.codesourcery.eve.apiclient.parsers.AbstractResponseParser.java
/** * Parse {@literal <rowset/>} XML. * //w w w. j a v a 2 s .com * @param name the rowset name the returned rowset should get * @param rowSet the rowset node * @return rowset with the given name * @throws UnparseableResponseException if the rowset * does not contain any columns or the XML has an unexpected structure. * @see #getRowSetNode(Node, String) */ protected RowSet parseRowSet(String name, Element rowSet) { // parse columns final Set<String> columns = new HashSet<String>(); final String[] sColumns = getAttributeValue(rowSet, "columns").split(","); if (ArrayUtils.isEmpty(sColumns)) { throw new UnparseableResponseException("Response XML contains rowset without any columns ?"); } for (String col : sColumns) { columns.add(col); } // parse key final String key = getAttributeValue(rowSet, "key", false); final RowSet result = new RowSet(name, key, columns); // parse rows final NodeList children = rowSet.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node n = children.item(i); if (!(n instanceof Element)) { continue; } final Element element = (Element) n; if (!"row".equalsIgnoreCase(element.getNodeName())) { throw new UnparseableResponseException("Invalid response XML ," + " found unexpected node <" + element.getNodeName() + "> in rowset"); } final Map<String, String> data = new HashMap<String, String>(); for (String attribute : result.getColumnNames()) { final String value = getAttributeValue(element, attribute, false); if (value != null) { data.put(attribute, value); } } result.addRow(data); } return result; }
From source file:com.alfaariss.oa.util.configuration.ConfigurationManager.java
/** * Add a new configuration section to the configuration. * @see IConfigurationManager#setSection(org.w3c.dom.Element, org.w3c.dom.Element) *//*from w w w . jav a 2s . c o m*/ public synchronized void setSection(Element eRootSection, Element eNewSection) throws ConfigurationException { if (eNewSection == null) throw new IllegalArgumentException("Suplied section is empty"); //rootSection can be null if the first section is requested if (eRootSection == null) eRootSection = _oDomDocument.getDocumentElement(); try { eRootSection.appendChild(eNewSection); } catch (DOMException e) { _logger.error("Could not add section: " + eNewSection.getNodeName(), e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_WRITE); } }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * /* ww w.j a v a 2 s. c o m*/ * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Opportunity createCRMObjectTypeOpportunity(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ final Opportunity opportunity = Opportunity.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = opportunity.newCursor(); cursor.toFirstContentToken(); final Node node = cursor.getDomNode(); /* Get main namespace URl */ if (node != null) { final String nsURL = node.getNamespaceURI(); /* Iterate on the Element list and create SOAP object */ for (final Element element : cADbject.getXmlContent()) { if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Opportunity: adding node : " + element.getNodeName() + " with value : " + element.getTextContent()); } /* Get crm field */ final String crmField = element.getNodeName(); String crmFieldName = null; /* If field contains the type information */ if (crmField != null && crmField.contains(crmFieldIntraSeparator)) { /* Split the field and get name */ crmFieldName = crmField.split(crmFieldIntraSeparator)[0]; } else { crmFieldName = crmField; } /* Add all new nodes */ cursor.beginElement(new QName(nsURL, crmFieldName)); /* Set node attributes */ if (element.getAttributes() != null) { /* Get attribute map */ final NamedNodeMap namedNodeMap = element.getAttributes(); /* Interate over map */ for (int i = 0; i < namedNodeMap.getLength(); i++) { /* Get respective item */ final Node namedNode = namedNodeMap.item(i); if (logger.isDebugEnabled()) { logger.debug("----Inside createCRMObject_Opportunity: adding attribute name : " + namedNode.getNodeName() + " with value: " + namedNode.getNodeValue()); } /* Set node attribute */ cursor.insertAttributeWithValue(namedNode.getNodeName(), namedNode.getNodeValue()); } } /* Set node value */ cursor.insertChars(element.getTextContent()); /* Jump to next token */ cursor.toNextToken(); } } } finally { if (cursor != null) { cursor.dispose(); } } return opportunity; }
From source file:com.fota.Link.sdpApi.java
public String CheckNumberPortabilityByPhoneNumber(String CTN) throws SAXException, IOException, ParserConfigurationException { String resultStr = null;//from w ww.j a v a2 s . co m try { String endPointUrl = PropUtil.getPropValue("sdp.oif552.url"); String strRequest = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + "xmlns:oas='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" + " xmlns:sdp='http://kt.com/sdp'>" + " <soapenv:Header>" + " <oas:Security>" + " <oas:UsernameToken>" + " <oas:Username>" + PropUtil.getPropValue("sdp.id") + "</oas:Username>" + " <oas:Password>" + PropUtil.getPropValue("sdp.pw") + "</oas:Password>" + " </oas:UsernameToken>" + " </oas:Security>" + " </soapenv:Header>" + " <soapenv:Body>" + " <sdp:checkNumberPortabilityByPhoneNumberRequest>" + " <!--You may enterthe following 6 items in any order-->" + " <sdp:CALL_CTN>" + CTN + "</sdp:CALL_CTN>" + " </sdp:checkNumberPortabilityByPhoneNumberRequest>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; // phone_number + telco_code + party_name + birth_date + [gender + // foreigner](?) // + auth_code + random_no + action_type // connection URL url = new URL(endPointUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-type", "text/xml;charset=utf-8"); // connection.setRequestProperty("Content-Length", // String.valueOf(strRequest.length())); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); // output OutputStream os = connection.getOutputStream(); // os.write(strRequest.getBytes(), 0, strRequest.length()); os.write(strRequest.getBytes("utf-8")); os.flush(); os.close(); // input InputStream is = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8")); String line = null; String resValue = null; String parseStr = null; while ((line = br.readLine()) != null) { System.out.println(line); parseStr = line; //int nIndex = resultStr.indexOf("<sdp:ROUTING_DIGIT>"); //resValue = resultStr.substring(nIndex,nIndex+1); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource temp = new InputSource(); temp.setCharacterStream(new StringReader(parseStr)); Document doc = builder.parse(temp); //xml? NodeList list = doc.getElementsByTagName("*"); int i = 0; Element element; String contents; while (list.item(i) != null) { element = (Element) list.item(i); System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println(element.getNodeName()); if (element.hasChildNodes()) { contents = element.getFirstChild().getNodeValue(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55"); System.out.println(element.getNodeName()); System.out.println(element.getFirstChild().getNodeName()); if (element.getNodeName().equals("sdp:ROUTING_DIGIT")) { //nero17 //resultStr = element.getFirstChild().getNodeName(); resultStr = contents; } System.out.println(contents); } i++; } connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } if (resultStr.length() < 2) { resultStr = ""; } return resultStr; }
From source file:com.photon.phresco.framework.rest.api.ParameterService.java
private static Publication readConfiguration(File path) throws PhrescoException { Publication config = new Publication(); try {/* w ww.j a va 2s . c o m*/ Pattern p = Pattern.compile("%20"); p.matcher(path.getPath()); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = builderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(path.toString()); doc.getDocumentElement().normalize(); List<Map<String, String>> parentList = new ArrayList<Map<String, String>>(); Map<String, String> parentMap = new HashMap<String, String>(); NodeList rootList = doc.getElementsByTagName(PUBLICATIONS); Node rootItem = rootList.item(0); NodeList nodeList = rootItem.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element != null) { String nodeName = element.getNodeName(); if (nodeName.equalsIgnoreCase(PUBLICATION)) { config.setPublicationType( node.getAttributes().getNamedItem(PUBLICATION_TYPE).getNodeValue()); config.setPublicationName( node.getAttributes().getNamedItem(PUBLICATION_NAME).getNodeValue()); } else if (nodeName.equalsIgnoreCase(PUBLICATION_PATH)) { config.setPublicationPath(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(PUBLICATION_URL)) { config.setPublicationUrl(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(IMAGE_URL)) { config.setImageUrl(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(IMAGE_PATH)) { config.setImagePath(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(PUBLICATION_KEY)) { config.setPublicationKey(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(ENVIRONMENT)) { config.setEnvironment(node.getTextContent()); } else if (nodeName.equalsIgnoreCase(PARENT_PUBLICATIONS)) { NodeList childNodes = node.getChildNodes(); if (childNodes != null) { for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if (childNode.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) node; parentMap.put(PARENT_NAME, childNode.getAttributes().getNamedItem(PARENT_NAME).getNodeValue()); parentMap.put(PRIORITY, childNode.getAttributes().getNamedItem(PRIORITY).getNodeValue()); parentList.add(parentMap); } } } config.setParentPublications(parentList); } } } } } catch (ParserConfigurationException e) { throw new PhrescoException(e); } catch (SAXException e) { throw new PhrescoException(e); } catch (IOException e) { throw new PhrescoException(e); } return config; }