List of usage examples for org.w3c.dom Node getFirstChild
public Node getFirstChild();
From source file:org.dasein.cloud.aws.platform.SimpleDB.java
@Override public Map<String, Set<KeyValuePair>> query(String queryString, boolean consistentRead) throws CloudException, InternalException { APITrace.begin(provider, "KVDB.query"); try {/*from w ww . ja va2s .com*/ Map<String, Set<KeyValuePair>> pairs = new HashMap<String, Set<KeyValuePair>>(); String marker = null; do { Map<String, String> parameters = provider.getStandardSimpleDBParameters(provider.getContext(), SELECT); NodeList blocks; EC2Method method; Document doc; if (marker != null) { parameters.put("NextToken", marker); } parameters.put("SelectExpression", queryString); parameters.put("ConsistentRead", String.valueOf(consistentRead)); method = new EC2Method(SERVICE_ID, provider, parameters); try { doc = method.invoke(); } catch (EC2Exception e) { String code = e.getCode(); if (code != null && code.equals("NoSuchDomain")) { return null; } throw new CloudException(e); } marker = null; blocks = doc.getElementsByTagName("NextToken"); if (blocks.getLength() > 0) { for (int i = 0; i < blocks.getLength(); i++) { Node item = blocks.item(i); if (item.hasChildNodes()) { marker = item.getFirstChild().getNodeValue().trim(); } } if (marker != null) { break; } } blocks = doc.getElementsByTagName("Item"); for (int i = 0; i < blocks.getLength(); i++) { Node item = blocks.item(i); if (item.hasChildNodes()) { TreeSet<KeyValuePair> itemPairs = new TreeSet<KeyValuePair>(); NodeList children = item.getChildNodes(); String itemId = null; for (int j = 0; j < children.getLength(); j++) { Node child = children.item(j); if (child.hasChildNodes()) { String nn = child.getNodeName(); if (nn.equals("Name")) { itemId = child.getFirstChild().getNodeValue(); } else if (nn.equals("Attribute")) { NodeList parts = child.getChildNodes(); String key = null, value = null; for (int k = 0; k < parts.getLength(); k++) { Node part = parts.item(k); if (part.hasChildNodes()) { String nv = part.getFirstChild().getNodeValue(); if (part.getNodeName().equals("Name")) { key = nv; } else if (part.getNodeName().equals("Value")) { value = nv; } } } if (key != null) { itemPairs.add(new KeyValuePair(key, value)); } } } } if (itemId != null) { pairs.put(itemId, itemPairs); } } } } while (marker != null); return pairs; } finally { APITrace.end(); } }
From source file:be.fedict.eid.applet.service.signer.facets.XAdESSignatureFacet.java
private Node marshallQualifyingProperties(Document document, ObjectFactory xadesObjectFactory, QualifyingPropertiesType qualifyingProperties) { Node marshallNode = document.createElement("marshall-node"); try {/*from www. ja va 2s. c o m*/ this.marshaller.marshal(xadesObjectFactory.createQualifyingProperties(qualifyingProperties), marshallNode); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } Element qualifyingPropertiesElement = (Element) marshallNode.getFirstChild(); Element signedPropertiesElement = (Element) qualifyingPropertiesElement .getElementsByTagNameNS("http://uri.etsi.org/01903/v1.3.2#", "SignedProperties").item(0); signedPropertiesElement.setIdAttribute("Id", true); return qualifyingPropertiesElement; }
From source file:com.test.movierecordsjsf.controller.MovieRecordsController.java
public void uploadXML() { if (file != null) { try {// ww w. jav a 2s . c o m InputStream is = file.getInputstream(); byte[] contents = IOUtils.toByteArray(is); is.close(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(contents)); NodeList nlist = doc.getElementsByTagName("Movie"); for (int i = 0; i < nlist.getLength(); i++) { Node nod = nlist.item(i); MovieRecords movieRecord = new MovieRecords(); NodeList dataMovie = nod.getChildNodes(); for (int j = 0; j < dataMovie.getLength(); j++) { Node data = dataMovie.item(j); if (data.getNodeType() == Node.ELEMENT_NODE) { if (null != data.getNodeName()) //Show data type { switch (data.getNodeName()) { case "title": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setTitle(dataContect.getNodeValue()); } break; } case "description": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setDescription(dataContect.getNodeValue()); } break; } case "size": { System.out.print(data.getNodeName() + ": "); //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setSize(Integer.parseInt(dataContect.getNodeValue())); } break; } case "rating": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setRating(Integer.parseInt(dataContect.getNodeValue())); } break; } case "checksum": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setChecksum(dataContect.getNodeValue()); } break; } case "staring": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setStaring(dataContect.getNodeValue()); } break; } default: break; } } } } movieRecordFacade.create(movieRecord); } listMovie(); } catch (Exception ex) { Logger.getLogger(MovieRecordsController.class.getName()).log(Level.SEVERE, null, ex); } JsfUtil.msgInfo(file.getFileName() + " successfully uploaded."); } }
From source file:org.dasein.cloud.aws.platform.SNS.java
private Subscription toSubscription(Node fromAws) throws InternalException, CloudException { Subscription subscription = new Subscription(); NodeList attrs = fromAws.getChildNodes(); subscription.setProviderRegionId(provider.getContext().getRegionId()); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); String name;//w ww . j a v a 2 s. c o m name = attr.getNodeName(); if (name.equals("TopicArn")) { String id = attr.getFirstChild().getNodeValue().trim(); subscription.setProviderTopicId(id); } else if (name.equals("SubscriptionArn")) { String id = attr.getFirstChild().getNodeValue().trim(); subscription.setProviderSubscriptionId(id); subscription.setDescription(id); subscription.setName(id); } else if (name.equals("Owner")) { String id = attr.getFirstChild().getNodeValue().trim(); subscription.setProviderOwnerId(id); } else if (name.equals("Endpoint")) { String endpoint = attr.getFirstChild().getNodeValue().trim(); subscription.setEndpoint(endpoint); } else if (name.equals("Protocol")) { String proto = attr.getFirstChild().getNodeValue().trim(); if (proto != null) { if (proto.equals("email")) { subscription.setEndpointType(EndpointType.EMAIL); subscription.setDataFormat(DataFormat.PLAINTEXT); } else if (proto.equals("email-json")) { subscription.setEndpointType(EndpointType.EMAIL); subscription.setDataFormat(DataFormat.JSON); } else if (proto.equals("http")) { subscription.setEndpointType(EndpointType.HTTP); subscription.setDataFormat(DataFormat.JSON); } else if (proto.equals("https")) { subscription.setEndpointType(EndpointType.HTTPS); subscription.setDataFormat(DataFormat.JSON); } else if (proto.equals("sqs")) { subscription.setEndpointType(EndpointType.AWS_SQS); subscription.setDataFormat(DataFormat.JSON); } else if (proto.equals("sms")) { subscription.setEndpointType(EndpointType.SMS); subscription.setDataFormat(DataFormat.PLAINTEXT); } } } } if (subscription.getProviderSubscriptionId() == null) { return null; } return subscription; }
From source file:de.bps.course.nodes.vc.provider.adobe.AdobeConnectProvider.java
protected List<String> findClassrooms(String name) { List<String> results = new ArrayList<String>(); if (!loginAdmin()) return results; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("action", "sco-search-by-field"); parameters.put("field", "name"); parameters.put("query", name); parameters.put("filter-type", "meeting"); Document responseDoc = getResponseDocument(sendRequest(parameters)); if (!evaluateOk(responseDoc)) { logError("Invalid response when searching for classrooms with the name \"" + name + "\"", null); return results; }/*from w w w . j a v a 2 s .c om*/ Object result = evaluate(responseDoc, "descendant-or-self::sco-search-by-field-info/child::sco/child::name", XPathConstants.NODESET); logout(); if (result == null) if (isLogDebugEnabled()) logDebug("Search for Adobe Connect classrooms with name \"" + name + "\" with no results"); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); String roomId = node.getFirstChild().getNodeValue(); results.add(roomId); } return results; }
From source file:com.google.enterprise.connector.salesforce.BaseTraversalManager.java
/** * Converts the <document></document> xml into a BaseSimpleDocument object * that we can send into a documentList object that ultimately gets returned * to the connector-manager/*w w w . j av a 2 s . c om*/ * * @param inxml * the xml form of and individual <document></document> object */ private BaseSimpleDocument convertXMLtoBaseDocument(Document doc) { try { HashMap hm_spi = new HashMap(); HashMap hm_meta_tags = new HashMap(); Map props = new HashMap(); String content_value = ""; TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // TODO: figure out why the initial doc passed in to the method // doesn't have the stylesheet 'fully' applied // this is why we do the conversion back and forth below // because for some reason the doc->string->doc has the stylesheet // applied. String sdoc = Util.XMLDoctoString(doc); logger.log(Level.FINEST, "About to convert STORE XML to BaseDocument " + sdoc); doc = Util.XMLStringtoDoc(sdoc); NodeList nl_document = doc.getElementsByTagName("document"); Node ndoc = nl_document.item(0); NodeList nl_doc_child = ndoc.getChildNodes(); for (int j = 0; j < nl_doc_child.getLength(); j++) { Node cnode = nl_doc_child.item(j); String doc_child_node_name = cnode.getNodeName(); if (doc_child_node_name.equalsIgnoreCase("spiheaders")) { NodeList nl_spi = cnode.getChildNodes(); for (int k = 0; k < nl_spi.getLength(); k++) { Node n_spi = nl_spi.item(k); if (n_spi.getNodeType() == Node.ELEMENT_NODE) { String spi_name = n_spi.getAttributes().getNamedItem("name").getNodeValue(); String spi_value = ""; if (n_spi.getFirstChild() != null) { spi_value = n_spi.getFirstChild().getNodeValue(); logger.log(Level.FINEST, "Adding SPI " + spi_name + " " + spi_value); } hm_spi.put(spi_name, spi_value); } } } if (doc_child_node_name.equalsIgnoreCase("metadata")) { NodeList nl_meta = cnode.getChildNodes(); for (int k = 0; k < nl_meta.getLength(); k++) { Node n_meta = nl_meta.item(k); if (n_meta.getNodeType() == Node.ELEMENT_NODE) { String meta_name = n_meta.getAttributes().getNamedItem("name").getNodeValue(); String meta_value = ""; if (n_meta.getFirstChild() != null) { meta_value = n_meta.getFirstChild().getNodeValue(); logger.log(Level.FINEST, "Adding METATAG " + meta_name + " " + meta_value); } hm_meta_tags.put(meta_name, meta_value); } } } if (doc_child_node_name.equalsIgnoreCase("content")) { content_value = cnode.getChildNodes().item(0).getNodeValue(); String encoding_type = ""; NamedNodeMap attribs = cnode.getAttributes(); if (attribs.getLength() > 0) { Node attrib = attribs.getNamedItem("encoding"); if (attrib != null) encoding_type = attrib.getNodeValue(); if (encoding_type.equalsIgnoreCase("base64") || encoding_type.equalsIgnoreCase("base64binary")) { byte[] b = org.apache.commons.codec.binary.Base64 .decodeBase64(content_value.getBytes()); ByteArrayInputStream input1 = new ByteArrayInputStream(b); logger.log(Level.FINEST, "Adding base64 encoded CONTENT " + content_value); props.put(SpiConstants.PROPNAME_CONTENT, input1); } else { logger.log(Level.FINEST, "Adding Text/HTML CONTENT " + content_value); props.put(SpiConstants.PROPNAME_CONTENT, content_value); } } else { logger.log(Level.FINEST, "Adding default Text/HTML CONTENT " + content_value); props.put(SpiConstants.PROPNAME_CONTENT, content_value); } } } // the hashmap holding the spi headers Iterator itr_spi = hm_spi.keySet().iterator(); while (itr_spi.hasNext()) { String key = (String) itr_spi.next(); String value = (String) hm_spi.get(key); if (key.equals("DEFAULT_MIMETYPE")) props.put(SpiConstants.DEFAULT_MIMETYPE, value); if (key.equals("PROPNAME_ACTION")) props.put(SpiConstants.PROPNAME_ACTION, value); if (key.equals("PROPNAME_CONTENTURL")) props.put(SpiConstants.PROPNAME_CONTENTURL, value); if (key.equals("PROPNAME_DISPLAYURL")) props.put(SpiConstants.PROPNAME_DISPLAYURL, value); if (key.equals("PROPNAME_DOCID")) props.put(SpiConstants.PROPNAME_DOCID, value); if (key.equals("PROPNAME_ISPUBLIC")) props.put(SpiConstants.PROPNAME_ISPUBLIC, value); if (key.equals("PROPNAME_LASTMODIFIED")) props.put(SpiConstants.PROPNAME_LASTMODIFIED, value); if (key.equals("PROPNAME_MIMETYPE")) props.put(SpiConstants.PROPNAME_MIMETYPE, value); // if (key.equals("PROPNAME_SEARCHURL")) // props.put(SpiConstants.PROPNAME_SEARCHURL, value); // if (key.equals("PROPNAME_SECURITYTOKEN")) // props.put(SpiConstants.PROPNAME_SECURITYTOKEN, value); } // hashmap holding the custom metatags Iterator itr_meta = hm_meta_tags.keySet().iterator(); while (itr_meta.hasNext()) { String key = (String) itr_meta.next(); String value = (String) hm_meta_tags.get(key); props.put(key, value); } BaseSimpleDocument bsd = createSimpleDocument(new Date(), props); return bsd; } catch (Exception ex) { logger.log(Level.SEVERE, "Error " + ex); } return null; }
From source file:com.library.essay.tinymce.spellchecker.GoogleSpellChekerServlet.java
private JSONObject receiveData(String method, String textToCheck) throws IOException, ParserConfigurationException, SAXException, JSONException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(uc.getInputStream()); JSONArray wordArray = new JSONArray(); if (method.equalsIgnoreCase("checkWords")) { NodeList cList = doc.getElementsByTagName("c"); for (int i = 0; i < cList.getLength(); i++) { Node cNode = cList.item(i); NamedNodeMap attrs = cNode.getAttributes(); int offset = Integer.parseInt(attrs.getNamedItem("o").getNodeValue());//offset int length = Integer.parseInt(attrs.getNamedItem("l").getNodeValue());//length wordArray.put(textToCheck.substring(offset, offset + length)); }/* w w w . j a v a 2s . com*/ } else if (method.equalsIgnoreCase("getSuggestions")) { NodeList cList = doc.getElementsByTagName("c"); if (cList.getLength() < 1) { return null;//Catch and response with an error } Node cNode = cList.item(0);//Should be only one if (cNode.getFirstChild() == null) { return null; } String[] suggestions = cNode.getFirstChild().getNodeValue().split("\t"); for (String suggestion : suggestions) { wordArray.put(suggestion); } } JSONObject returnObject = new JSONObject(); returnObject.put("result", wordArray); return returnObject; }
From source file:edu.wpi.margrave.MCommunicator.java
private static MExploreCondition exploreHelper(Node n, List<String> bound) throws MUserException, MGEManagerException, MGEUnknownIdentifier { assert (n != null); List<Node> childNodes = getElementChildren(n); String name = n.getNodeName(); //writeToLog("\nIn exploreHelper. Node Name: " + name + "\n"); //if(childNodes.getLength() == 0) // writeToLog("\nNo child nodes.\n"); //else/*from w w w . j av a 2s.c o m*/ // writeToLog("First child node's name: " + childNodes.item(0).getNodeName() + "\n"); if (name.equalsIgnoreCase("AND")) { assert (getElementChildren(n).size() == 2); return exploreHelper(childNodes.get(0), bound).and(exploreHelper(childNodes.get(1), bound)); } else if (name.equalsIgnoreCase("OR")) { assert (getElementChildren(n).size() == 2); return exploreHelper(childNodes.get(0), bound).or(exploreHelper(childNodes.get(1), bound)); } else if (name.equalsIgnoreCase("IMPLIES")) { // cannot trust XML to preserve node order Node antecedent = getChildNode(n, "ANTE"); Node consequent = getChildNode(n, "CONS"); // The children of these nodes are the formulas in ante/cons position. MExploreCondition antecedentFmla = exploreHelper(antecedent.getFirstChild(), bound); MExploreCondition consequentFmla = exploreHelper(consequent.getFirstChild(), bound); return antecedentFmla.implies(consequentFmla); } else if (name.equalsIgnoreCase("ISA")) { String typename = getAttributeOfChildNodeOrNode(n, "ISA", "sort"); Relation theRel = MFormulaManager.makeRelation(typename, 1); // These may be null Node internalFmlaWrapNode = getChildNode(n, "FORMULA"); Node internalTermWrapNode = getChildNode(n, "TERM"); MExploreCondition internalFmlaC; MExploreCondition newFmlaC; // If no fmla passed, this is a sort-as-predicate. Just checking whether the var is in the sort. if (internalFmlaWrapNode == null) internalFmlaC = new MExploreCondition(true); else internalFmlaC = exploreHelper(internalFmlaWrapNode.getFirstChild(), bound); MTerm theTerm = termHelper(internalTermWrapNode.getFirstChild(), bound); newFmlaC = internalFmlaC.isaSubstitution(theTerm.expr, theRel); writeToLog("\nFormula helper (ISA) got " + theTerm + " : " + theRel + " | " + internalFmlaC); writeToLog("\n Substituted to: " + newFmlaC); // The term in the ISA _must_ be added to the context, since it isn't necessarily // part of the formula condition. (For instance, TRUE isas) newFmlaC.termMap.put(theTerm.expr, theTerm); return newFmlaC; } else if (name.equalsIgnoreCase("EQUALS")) { return handleEqualsFormula(n, bound); } else if (name.equalsIgnoreCase("IFF")) { assert (getElementChildren(n).size() == 2); return exploreHelper(n.getFirstChild(), bound).iff(exploreHelper(n.getChildNodes().item(1), bound)); } else if (name.equalsIgnoreCase("NOT")) { return exploreHelper(n.getFirstChild(), bound).not(); } else if (name.equalsIgnoreCase("EXISTS")) { String theVarName = getAttributeOfChildNodeOrNode(n, "EXISTS", "var"); String theSortName = getAttributeOfChildNodeOrNode(n, "EXISTS", "sort"); Variable theVar = MFormulaManager.makeVariable(theVarName); Relation theSort = MFormulaManager.makeRelation(theSortName, 1); List<String> newbound = new ArrayList<String>(bound); newbound.add(theVarName); return exploreHelper(n.getFirstChild(), newbound).exists(theVar, theSort); } else if (name.equalsIgnoreCase("FORALL")) { String theVarName = getAttributeOfChildNodeOrNode(n, "FORALL", "var"); String theSortName = getAttributeOfChildNodeOrNode(n, "FORALL", "sort"); Variable theVar = MFormulaManager.makeVariable(theVarName); Relation theSort = MFormulaManager.makeRelation(theSortName, 1); List<String> newbound = new ArrayList<String>(bound); newbound.add(theVarName); return exploreHelper(n.getFirstChild(), newbound).forall(theVar, theSort); } else if (name.equalsIgnoreCase("ATOMIC-FORMULA")) { return handleAtomicFormula(n, bound); } else if (name.equalsIgnoreCase("TRUE")) { return new MExploreCondition(true); } else if (name.equalsIgnoreCase("FALSE")) { return new MExploreCondition(false); } throw new MUserException("exploreHelper was unable to match node type: " + name); }
From source file:org.dasein.cloud.aws.platform.SNS.java
@Override public String publish(String providerTopicId, String subject, String message) throws CloudException, InternalException { APITrace.begin(provider, "Notifications.publish"); try {/*ww w . j a v a 2s.c o m*/ Map<String, String> parameters = provider.getStandardSnsParameters(provider.getContext(), PUBLISH); EC2Method method; NodeList blocks; Document doc; parameters.put("TopicArn", providerTopicId); parameters.put("Subject", subject); parameters.put("Message", message); method = new EC2Method(SERVICE_ID, provider, parameters); try { doc = method.invoke(); } catch (EC2Exception e) { throw new CloudException(e); } blocks = doc.getElementsByTagName("PublishResult"); for (int i = 0; i < blocks.getLength(); i++) { Node item = blocks.item(i); for (int j = 0; j < item.getChildNodes().getLength(); j++) { Node attr = item.getChildNodes().item(j); String name; name = attr.getNodeName(); if (name.equals("MessageId")) { return attr.getFirstChild().getNodeValue().trim(); } } } return null; } finally { APITrace.end(); } }
From source file:DomPrintUtil.java
private Node getVisibleFirstChild(Node target) { if (!entitiyReferenceExpansion && Node.ENTITY_REFERENCE_NODE == target.getNodeType()) { return null; }/*from w ww . j av a2 s . c o m*/ Node tmpN = target.getFirstChild(); if (null == tmpN) { return null; } switch (eval(tmpN)) { case NodeFilter.FILTER_ACCEPT: return tmpN; case NodeFilter.FILTER_SKIP: Node tmpN2 = getVisibleFirstChild(tmpN); if (null != tmpN2) { return tmpN2; } // case NodeFilter.FILTER_REJECT: default: return getVisibleNextSibling(tmpN, target); } }