List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //ww w . jav a 2s .c o m * @param account * @param accountId * @param cADbject * @return * @throws Exception */ public static final Lead createCRMObjectTypeLead(final ScribeObject cADbject, final String crmFieldIntraSeparator) throws Exception { /* Create xml beans object */ final Lead lead = Lead.Factory.newInstance(); /* Create new cursor */ XmlCursor cursor = null; try { cursor = lead.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_Lead: 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_Lead: 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 lead; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //from ww w .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
/** * //from www . j ava 2s. c o m * @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.twinsoft.convertigo.engine.util.WsReference.java
private static void extractSoapVariables(XmlSchema xmlSchema, List<RequestableHttpVariable> variables, Node node, String longName, boolean isMulti, QName variableType) throws EngineException { if (node == null) return;/*from w w w .ja v a 2 s. c om*/ int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { Element element = (Element) node; if (element != null) { String elementName = element.getLocalName(); if (longName != null) elementName = longName + "_" + elementName; if (!element.getAttribute("soapenc:arrayType").equals("") && !element.hasChildNodes()) { String avalue = element.getAttribute("soapenc:arrayType"); element.setAttribute("soapenc:arrayType", avalue.replaceAll("\\[\\]", "[1]")); Element child = element.getOwnerDocument().createElement("item"); String atype = avalue.replaceAll("\\[\\]", ""); child.setAttribute("xsi:type", atype); if (atype.startsWith("xsd:")) { String variableName = elementName + "_item"; child.appendChild( element.getOwnerDocument().createTextNode("$(" + variableName.toUpperCase() + ")")); RequestableHttpVariable httpVariable = createHttpVariable(true, variableName, new QName(Constants.URI_2001_SCHEMA_XSD, atype.split(":")[1])); variables.add(httpVariable); } element.appendChild(child); } // extract from attributes NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node child = map.item(i); if (child.getNodeName().equals("soapenc:arrayType")) continue; if (child.getNodeName().equals("xsi:type")) continue; if (child.getNodeName().equals("soapenv:encodingStyle")) continue; String variableName = getVariableName(variables, elementName + "_" + child.getLocalName()); child.setNodeValue("$(" + variableName.toUpperCase() + ")"); RequestableHttpVariable httpVariable = createHttpVariable(false, variableName, Constants.XSD_STRING); variables.add(httpVariable); } // extract from children nodes boolean multi = false; QName qname = Constants.XSD_STRING; NodeList children = element.getChildNodes(); if (children.getLength() > 0) { Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.COMMENT_NODE) { String value = child.getNodeValue(); if (value.startsWith("type:")) { String schemaType = child.getNodeValue().substring("type:".length()).trim(); qname = getVariableSchemaType(xmlSchema, schemaType); } if (value.indexOf("repetitions:") != -1) { multi = true; } } else if (child.getNodeType() == Node.TEXT_NODE) { String value = child.getNodeValue().trim(); if (value.equals("?") || !value.equals("")) { String variableName = getVariableName(variables, elementName); child.setNodeValue("$(" + variableName.toUpperCase() + ")"); RequestableHttpVariable httpVariable = createHttpVariable(isMulti, variableName, variableType); variables.add(httpVariable); } } else if (child.getNodeType() == Node.ELEMENT_NODE) { extractSoapVariables(xmlSchema, variables, child, elementName, multi, qname); multi = false; qname = Constants.XSD_STRING; } child = child.getNextSibling(); } } } } }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
/** * //from ww w .j a v a 2 s. c om * @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. j a v a 2 s . c om * @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 w w. j a v a 2s . 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.fujitsu.dc.test.jersey.box.CollectionTest.java
/** * PROPPATCH????.// w w w . j a va 2s . co m * @param doc ??XML * @param resorce PROPPATCH?? * @param lapName prop?????? * @param map ???KeyValue Key?Value???????? Valuenull???Key??????remove???? */ private void proppatchClassResponseTest(Element doc, String resorce, String lapName, ArrayList<String> list) { NodeList response = doc.getElementsByTagName("response"); assertEquals(1, response.getLength()); Element node = (Element) response.item(0); assertEquals(resorce, node.getElementsByTagName("href").item(0).getFirstChild().getNodeValue()); assertEquals("HTTP/1.1 200 OK", node.getElementsByTagName("status").item(0).getFirstChild().getNodeValue()); String lapNameFlg = null; NodeList tmp = node.getElementsByTagName("prop").item(0).getChildNodes(); for (int i = 0; i < tmp.getLength(); i++) { Node child = tmp.item(i); if (child instanceof Element) { // ????? Element childElement = (Element) child; if (childElement.getLocalName().equals(lapName)) { lapNameFlg = "true"; // Path?? NodeList pTmp = childElement.getChildNodes(); for (int ii = 0; ii < pTmp.getLength(); ii++) { Node pChild = pTmp.item(ii); if (pChild instanceof Element) { Element pChildElement = (Element) pChild; NamedNodeMap attrs = pChildElement.getAttributes(); if (attrs != null) { String falg = null; for (Iterator<String> it = list.listIterator(); it.hasNext();) { Object key = it.next(); Object value = it.next(); Node attr = (Node) attrs.getNamedItem((String) key); if (attr != null && attr.getNodeValue().equals(value)) { falg = "true"; } } assertNotNull(falg); } } } } } } // ????? assertNotNull(lapNameFlg); }
From source file:de.escidoc.core.test.EscidocAbstractTest.java
/** * Creates a new element node for the provided document. The created element is an element that that has xlink * attributes, but does not have an objid attribute. * /*from www . ja v a2s . c o m*/ * @param doc * The document for that the node shall be created. * @param namespaceUri * The name space uri of the node to create. This may be null. * @param prefix * The prefix to use. * @param tagName * The tag name of the node. * @param xlinkPrefix * The prefix to use for the xlink attributes. * @param title * The title of the referencing element (=xlink:title) * @param href * The href of the referencing element (=xlink:href). * @param withRestReadOnly * Flag indicating if the parent-ous element shall contain the REST specific read only attributes (type * and title). * @return Returns the created node. * @throws Exception * Thrown if anything fails. */ public static Element createElementNodeWithXlink(final Document doc, final String namespaceUri, final String prefix, final String tagName, final String xlinkPrefix, final String title, final String href, final boolean withRestReadOnly) throws Exception { Element newElement = createElementNode(doc, namespaceUri, prefix, tagName, null); if (withRestReadOnly) { Attr xlinkTypeAttr = createAttributeNode(doc, XLINK_NS_URI, xlinkPrefix, NAME_TYPE, "simple"); Attr xlinkTitleAttr = createAttributeNode(doc, XLINK_NS_URI, xlinkPrefix, NAME_TITLE, title); newElement.getAttributes().setNamedItemNS(xlinkTypeAttr); newElement.getAttributes().setNamedItemNS(xlinkTitleAttr); } Attr xlinkHrefAttr = createAttributeNode(doc, XLINK_NS_URI, xlinkPrefix, NAME_HREF, href); newElement.getAttributes().setNamedItemNS(xlinkHrefAttr); return newElement; }
From source file:com.espertech.esper.client.ConfigurationParser.java
private static void handleDatabaseRefs(Configuration configuration, Element element) { String name = getRequiredAttribute(element, "name"); ConfigurationDBRef configDBRef = new ConfigurationDBRef(); configuration.addDatabaseReference(name, configDBRef); DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes()); while (nodeIterator.hasNext()) { Element subElement = nodeIterator.next(); if (subElement.getNodeName().equals("datasource-connection")) { String lookup = getRequiredAttribute(subElement, "context-lookup-name"); Properties properties = handleProperties(subElement, "env-property"); configDBRef.setDataSourceConnection(lookup, properties); }//from ww w.j a va 2 s. co m if (subElement.getNodeName().equals("datasourcefactory-connection")) { String className = getRequiredAttribute(subElement, "class-name"); Properties properties = handleProperties(subElement, "env-property"); configDBRef.setDataSourceFactory(properties, className); } else if (subElement.getNodeName().equals("drivermanager-connection")) { String className = getRequiredAttribute(subElement, "class-name"); String url = getRequiredAttribute(subElement, "url"); String userName = getRequiredAttribute(subElement, "user"); String password = getRequiredAttribute(subElement, "password"); Properties properties = handleProperties(subElement, "connection-arg"); configDBRef.setDriverManagerConnection(className, url, userName, password, properties); } else if (subElement.getNodeName().equals("connection-lifecycle")) { String value = getRequiredAttribute(subElement, "value"); configDBRef.setConnectionLifecycleEnum( ConfigurationDBRef.ConnectionLifecycleEnum.valueOf(value.toUpperCase())); } else if (subElement.getNodeName().equals("connection-settings")) { if (subElement.getAttributes().getNamedItem("auto-commit") != null) { String autoCommit = subElement.getAttributes().getNamedItem("auto-commit").getTextContent(); configDBRef.setConnectionAutoCommit(Boolean.parseBoolean(autoCommit)); } if (subElement.getAttributes().getNamedItem("transaction-isolation") != null) { String transactionIsolation = subElement.getAttributes().getNamedItem("transaction-isolation") .getTextContent(); configDBRef.setConnectionTransactionIsolation(Integer.parseInt(transactionIsolation)); } if (subElement.getAttributes().getNamedItem("catalog") != null) { String catalog = subElement.getAttributes().getNamedItem("catalog").getTextContent(); configDBRef.setConnectionCatalog(catalog); } if (subElement.getAttributes().getNamedItem("read-only") != null) { String readOnly = subElement.getAttributes().getNamedItem("read-only").getTextContent(); configDBRef.setConnectionReadOnly(Boolean.parseBoolean(readOnly)); } } else if (subElement.getNodeName().equals("column-change-case")) { String value = getRequiredAttribute(subElement, "value"); ConfigurationDBRef.ColumnChangeCaseEnum parsed = ConfigurationDBRef.ColumnChangeCaseEnum .valueOf(value.toUpperCase()); configDBRef.setColumnChangeCase(parsed); } else if (subElement.getNodeName().equals("metadata-origin")) { String value = getRequiredAttribute(subElement, "value"); ConfigurationDBRef.MetadataOriginEnum parsed = ConfigurationDBRef.MetadataOriginEnum .valueOf(value.toUpperCase()); configDBRef.setMetadataOrigin(parsed); } else if (subElement.getNodeName().equals("sql-types-mapping")) { String sqlType = getRequiredAttribute(subElement, "sql-type"); String javaType = getRequiredAttribute(subElement, "java-type"); Integer sqlTypeInt; try { sqlTypeInt = Integer.parseInt(sqlType); } catch (NumberFormatException ex) { throw new ConfigurationException( "Error converting sql type '" + sqlType + "' to integer java.sql.Types constant"); } configDBRef.addSqlTypesBinding(sqlTypeInt, javaType); } else if (subElement.getNodeName().equals("expiry-time-cache")) { String maxAge = getRequiredAttribute(subElement, "max-age-seconds"); String purgeInterval = getRequiredAttribute(subElement, "purge-interval-seconds"); ConfigurationCacheReferenceType refTypeEnum = ConfigurationCacheReferenceType.getDefault(); if (subElement.getAttributes().getNamedItem("ref-type") != null) { String refType = subElement.getAttributes().getNamedItem("ref-type").getTextContent(); refTypeEnum = ConfigurationCacheReferenceType.valueOf(refType.toUpperCase()); } configDBRef.setExpiryTimeCache(Double.parseDouble(maxAge), Double.parseDouble(purgeInterval), refTypeEnum); } else if (subElement.getNodeName().equals("lru-cache")) { String size = getRequiredAttribute(subElement, "size"); configDBRef.setLRUCache(Integer.parseInt(size)); } } }