List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:be.e_contract.mycarenet.xkms2.ProofOfPossessionSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { if (null == this.sessionKey) { return true; }//from w w w . j a v a2 s. c o m if (null == this.prototypeKeyBindingId) { return true; } Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; } LOG.debug("adding proof of possession signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "RegisterRequest"); Element registerRequestElement = (Element) registerRequestNodeList.item(0); Document xkmsDocument; try { xkmsDocument = copyDocument(registerRequestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList proofOfPossessionNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(proofOfPossessionElement); } catch (Exception e) { LOG.error("error adding proof signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true); proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession"); proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0); proofOfPossessionElement.appendChild(signatureNode); return true; }
From source file:ca.inverse.sogo.engine.source.SOGoPropertyConverter.java
protected Property _convertIsRecurring(Element e) { Text textNode = (Text) e.getFirstChild(); String isRecurringValue = textNode.getNodeValue(); if (!Boolean.valueOf(isRecurringValue).booleanValue() && Integer.valueOf(isRecurringValue).intValue() < 1) return null; Element rootElement = e.getOwnerDocument().getDocumentElement(); StringBuffer propertyValue = new StringBuffer(); String sifRecurrenceType = getSifValue(rootElement, "RecurrenceType"); if (sifRecurrenceType != null) { String iCalRecurrenceType = (String) this.sif2ICalDirectMappings .get("rrule.RecurrenceType." + sifRecurrenceType); propertyValue.append("FREQ=").append(iCalRecurrenceType); String patternEndDate = getSifValue(rootElement, "PatternEndDate"); if (patternEndDate == null) { String occurences = getSifValue(rootElement, "Occurrences"); if (occurences != null && (Integer.valueOf(occurences).intValue() > 0)) propertyValue.append(";COUNT=").append(occurences); } else {/*w w w . ja v a 2 s . co m*/ // if ( patternEndDate != null ) propertyValue.append(";UNTIL=").append(patternEndDate); } // boolean noEndDate = "1".equals ( getSifValue ( rootElement, "NoEndDate" ) ); int interval = 0, dayOfWeekMask = 0, dayOfMonth = 0, instance = 0, monthOfYear = 0; switch (Integer.valueOf(sifRecurrenceType).intValue()) { // olRecursDaily case 0: interval = Integer.valueOf(getSifValue(rootElement, "Interval")).intValue(); break; // olRecursWeekly case 1: interval = Integer.valueOf(getSifValue(rootElement, "Interval")).intValue(); dayOfWeekMask = Integer.valueOf(getSifValue(rootElement, "DayOfWeekMask")).intValue(); break; // olRecursMonthly case 2: interval = Integer.valueOf(getSifValue(rootElement, "Interval")).intValue(); dayOfWeekMask = Integer.valueOf(getSifValue(rootElement, "DayOfWeekMask")).intValue(); dayOfMonth = Integer.valueOf(getSifValue(rootElement, "DayOfMonth")).intValue(); break; // olRecursMonthNth case 3: interval = Integer.valueOf(getSifValue(rootElement, "Interval")).intValue(); instance = Integer.valueOf(getSifValue(rootElement, "Instance")).intValue(); dayOfWeekMask = Integer.valueOf(getSifValue(rootElement, "DayOfWeekMask")).intValue(); break; // olRecursYearly case 5: monthOfYear = Integer.valueOf(getSifValue(rootElement, "MonthOfYear")).intValue(); dayOfMonth = Integer.valueOf(getSifValue(rootElement, "DayOfMonth")).intValue(); break; // olRecursYearNth case 6: instance = Integer.valueOf(getSifValue(rootElement, "Instance")).intValue(); dayOfWeekMask = Integer.valueOf(getSifValue(rootElement, "DayOfWeekMask")).intValue(); monthOfYear = Integer.valueOf(getSifValue(rootElement, "MonthOfYear")).intValue(); break; } if (interval > 1) propertyValue.append(";INTERVAL=").append(interval); if (instance > 0) propertyValue.append(";BYSETPOS=").append(instance > 4 ? -1 : instance); if (dayOfWeekMask > 0) { StringBuffer byDayBuffer = new StringBuffer(); for (int i = 1; i <= 64; i <<= 1) { if ((dayOfWeekMask & i) == i) { String iCalWkDay = (String) this.sif2ICalDirectMappings.get("rrule.DayOfWeekMask." + i); if (byDayBuffer.length() > 0) byDayBuffer.append(','); byDayBuffer.append(iCalWkDay); } } if (byDayBuffer.length() > 0) propertyValue.append(";BYDAY=").append(byDayBuffer); } if (monthOfYear > 0) propertyValue.append(";BYMONTH=").append(monthOfYear); if (dayOfMonth > 0) propertyValue.append(";BYMONTHDAY=").append(dayOfMonth); } else { /* no recurrence type specified - won't create RRULE */ return null; } return new Property("RRULE", propertyValue.toString()); }
From source file:com.ibm.bi.dml.conf.DMLConfig.java
/** * //from w w w.j a v a2 s. c o m * @throws IOException */ @SuppressWarnings("deprecation") public void makeQualifiedScratchSpacePath() throws IOException { NodeList list2 = xml_root.getElementsByTagName(SCRATCH_SPACE); if (list2 != null && list2.getLength() > 0) { Element elem = (Element) list2.item(0); FileSystem fs = FileSystem.get(ConfigurationManager.getCachedJobConf()); String fname = elem.getFirstChild().getNodeValue(); Path path = new Path(fname).makeQualified(fs); elem.getFirstChild().setNodeValue(path.toString()); } }
From source file:edu.lternet.pasta.client.ReservationsManager.java
/** * Composes HTML table rows to render the list of active reservations for * this user.//from w w w .j a v a 2 s . c o m * * @return an HTML snippet of table row (<tr>) elements, one per * active data package identifier reservation for this user. * @throws Exception */ public String reservationsTableHTML() throws Exception { String html; StringBuilder sb = new StringBuilder(""); if (this.uid != null && !this.uid.equals("public")) { String xmlString = listActiveReservations(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); InputStream inputStream = IOUtils.toInputStream(xmlString, "UTF-8"); Document document = documentBuilder.parse(inputStream); Element documentElement = document.getDocumentElement(); NodeList reservations = documentElement.getElementsByTagName("reservation"); int nReservations = reservations.getLength(); for (int i = 0; i < nReservations; i++) { Node reservationNode = reservations.item(i); NodeList reservationChildren = reservationNode.getChildNodes(); String docid = ""; String principal = ""; String dateReserved = ""; boolean include = false; for (int j = 0; j < reservationChildren.getLength(); j++) { Node childNode = reservationChildren.item(j); if (childNode instanceof Element) { Element reservationElement = (Element) childNode; if (reservationElement.getTagName().equals("principal")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { principal = text.getData().trim(); if (principal.startsWith(this.uid)) { include = true; } } } else if (reservationElement.getTagName().equals("docid")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { docid = text.getData().trim(); } } else if (reservationElement.getTagName().equals("dateReserved")) { Text text = (Text) reservationElement.getFirstChild(); if (text != null) { dateReserved = text.getData().trim(); } } } } if (include) { sb.append("<tr>\n"); sb.append(" <td class='nis' align='center'>"); sb.append(docid); sb.append("</td>\n"); sb.append(" <td class='nis' align='center'>"); sb.append(principal); sb.append("</td>\n"); sb.append(" <td class='nis'>"); sb.append(dateReserved); sb.append("</td>\n"); sb.append("</tr>\n"); } } } catch (Exception e) { logger.error("Exception:\n" + e.getMessage()); e.printStackTrace(); throw new PastaEventException(e.getMessage()); } } html = sb.toString(); return html; }
From source file:org.coronastreet.gpxconverter.GarminForm.java
private void setDistanceAndTime() { NodeList nl = outDoc.getElementsByTagName("Activity"); NodeList nl1 = ((Element) nl.item(0)).getElementsByTagName("Lap"); NodeList nl2 = ((Element) nl1.item(0)).getElementsByTagName("TotalTimeSeconds"); if (nl2 != null && nl2.getLength() > 0) { Element el = (Element) nl2.item(0); el.getFirstChild().setNodeValue(totalTimeInSeconds); }/* w ww .j av a2 s .co m*/ NodeList nl3 = ((Element) nl.item(0)).getElementsByTagName("DistanceMeters"); if (nl3 != null && nl3.getLength() > 0) { Element el = (Element) nl3.item(0); el.getFirstChild().setNodeValue(distanceMeters); } }
From source file:com.zia.freshdocs.cmis.CMISParser06.java
@Override public NodeRef[] parseChildren(InputStream is) { NodeRef[] refs = new NodeRef[0]; DocumentBuilder docBuilder = null; try {//from w w w . j a v a2 s .c o m Pattern pattern = Pattern.compile("&(?![a-zA-Z0-9]+;)"); Matcher matcher = pattern.matcher(IOUtils.toString(is)); String sanitized = matcher.replaceAll("&"); docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(sanitized.getBytes())); // Iterate over all the entry nodes and build NodeRefs NodeList nodes = doc.getElementsByTagName("entry"); NodeList children = null; Element node = null; NodeRef nodeRef = null; int n = nodes.getLength(); for (int i = 0; i < n; i++) { if (refs.length == 0) { refs = new NodeRef[n]; } node = (Element) nodes.item(i); children = node.getElementsByTagName("content"); if (children.getLength() > 0) { Element contentNode = (Element) children.item(0); String content = null; nodeRef = new NodeRef(); if (contentNode.hasAttribute("type")) { nodeRef.setContentType(contentNode.getAttribute("type")); content = contentNode.getAttribute("src"); } else { content = contentNode.getFirstChild().getNodeValue(); } nodeRef.setContent(content); children = node.getElementsByTagName("title"); if (children.getLength() > 0) { nodeRef.setName(children.item(0).getFirstChild().getNodeValue()); } children = node.getElementsByTagName("updated"); if (children.getLength() > 0) { nodeRef.setLastModificationDate(children.item(0).getFirstChild().getNodeValue()); } children = node.getElementsByTagName("cmis:propertyString"); int nChildren = children.getLength(); if (nChildren > 0) { for (int j = 0; j < nChildren; j++) { Element child = (Element) children.item(j); if (child.getAttribute("cmis:name").equals("BaseType")) { NodeList valueNode = child.getElementsByTagName("cmis:value"); String baseType = valueNode.item(0).getFirstChild().getNodeValue(); nodeRef.setFolder(baseType.equals("folder")); } else if (child.getAttribute("cmis:name").equals("LastModifiedBy")) { NodeList valueNode = child.getElementsByTagName("cmis:value"); nodeRef.setLastModifiedBy(valueNode.item(0).getFirstChild().getNodeValue()); } else if (child.getAttribute("cmis:name").equals("VersionLabel")) { NodeList valueNode = child.getElementsByTagName("cmis:value"); if (valueNode.getLength() > 0) { nodeRef.setVersion(valueNode.item(0).getFirstChild().getNodeValue()); } } } } children = node.getElementsByTagName("cmis:propertyInteger"); nChildren = children.getLength(); if (nChildren > 0) { for (int j = 0; j < nChildren; j++) { Element child = (Element) children.item(j); if (child.getAttribute("cmis:name").equals("ContentStreamLength")) { NodeList valueNode = child.getElementsByTagName("cmis:value"); nodeRef.setContentLength( Long.valueOf(valueNode.item(0).getFirstChild().getNodeValue())); break; } } } refs[i] = nodeRef; } } } catch (Exception e) { Log.e(CMIS.class.getSimpleName(), "Error getting children", e); } return refs; }
From source file:com.github.dozermapper.core.loader.xml.XMLParser.java
private void debugElement(Element element) { log.debug("config name: {}", element.getNodeName()); log.debug(" value: {}", element.getFirstChild().getNodeValue()); }
From source file:com.draagon.meta.manager.xml.ObjectManagerXML.java
private List<Object> parseObjects(ObjectConnection c, MetaObject mc, Element element) throws MetaException, SAXException { String nameRef = getNameRef(mc); NodeList objectList = element.getElementsByTagName(nameRef); List<Object> objects = new ArrayList<Object>(); for (int i = 0; i < objectList.getLength(); i++) { Element e = (Element) objectList.item(i); Object o = getNewObject(mc); for (MetaField mf : getReadableFields(mc)) { String fieldRef = getFieldRef(mf); NodeList list = e.getElementsByTagName(fieldRef); if (list.getLength() > 0) { Element fe = (Element) list.item(0); String value = ""; Node nv = fe.getFirstChild(); if (nv != null) value = nv.getNodeValue(); mf.setString(o, value);/*from w w w .j av a 2s .com*/ } else mf.setString(o, null); } if (mc instanceof StateAwareMetaObject) { // It was pulled from the database, so it doesn't need to be flagged as modified ((StateAwareMetaObject) mc).setModified(o, false); // It is also no longer a new item ((StateAwareMetaObject) mc).setNew(o, false); } // Add the object to the returned vector objects.add(o); } return objects; }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
private boolean isValid(final Element element) { boolean value = false; if (element != null) { if (element.hasAttribute(VALUE_NIL) && VALUE_TRUE.equals(element.getAttributeNode(VALUE_NIL).getNodeValue())) { value = false;/* w w w.j a va 2 s.c om*/ } else { final Node child = element.getFirstChild(); value = child != null; } } return value; }
From source file:be.e_contract.mycarenet.xkms2.KeyBindingAuthenticationSignatureSOAPHandler.java
@Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (false == outboundProperty) { return true; }// w w w.j a v a2 s.co m LOG.debug("adding key binding authentication signature"); SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String requestElementName; if (null != this.prototypeKeyBindingId) { requestElementName = "RegisterRequest"; this.referenceUri = "#" + this.prototypeKeyBindingId; } else if (null != this.revokeKeyBindingId) { requestElementName = "RevokeRequest"; this.referenceUri = "#" + this.revokeKeyBindingId; } else { LOG.error("missing key binding id"); return false; } NodeList requestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, requestElementName); Element requestElement = (Element) requestNodeList.item(0); if (null == requestElement) { LOG.error("request element not present"); return false; } Document xkmsDocument; try { xkmsDocument = copyDocument(requestElement); } catch (ParserConfigurationException e) { LOG.error("error copying XKMS request: " + e.getMessage(), e); return false; } NodeList keyBindingAuthenticationNodeList = xkmsDocument .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); Element keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); try { prepareDocument(xkmsDocument); addSignature(keyBindingAuthenticationElement); } catch (Exception e) { LOG.error("error adding authn signature: " + e.getMessage(), e); return false; } Node signatureNode = soapPart.importNode(keyBindingAuthenticationElement.getFirstChild(), true); keyBindingAuthenticationNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication"); keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0); keyBindingAuthenticationElement.appendChild(signatureNode); return true; }