List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java
License:Open Source License
/** * @param resultNode/*from w w w . j a v a 2 s. com*/ * the actual node * @param insertInto * where to insert elements in xml */ private void getTimestampFromResultNode(TestResultNode resultNode, Element insertInto) { Element timestampEL = insertInto.addElement("timestamp"); //$NON-NLS-1$ Date time = resultNode.getTimeStamp(); if (time != null) { String timestamp = time.toString(); timestampEL.addText(timestamp); } else { timestampEL.addText(StringConstants.EMPTY); } }
From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java
License:Open Source License
/** * @param resultNode/*from w w w. j av a 2 s .c o m*/ * TestResultNode * @param insertInto * Element */ protected void addGeneralElements(TestResultNode resultNode, Element insertInto) { Element name = insertInto.addElement("name"); //$NON-NLS-1$ final INodePO resNode = resultNode.getNode(); name.addText(resNode.getName()); if (resNode.getComment() != null) { Element comment = insertInto.addElement("comment"); //$NON-NLS-1$ comment.addText(resNode.getComment()); } Element status = insertInto.addElement("status"); //$NON-NLS-1$ status.addText(String.valueOf(resultNode.getStatus())); long durationMillis = resultNode.getDuration(getTestResult().getEndTime()); if (durationMillis != -1) { insertInto.addAttribute("duration", //$NON-NLS-1$ DurationFormatUtils.formatDurationHMS(durationMillis)); } if (resNode instanceof ICondStructPO) { Element negated = insertInto.addElement("negated"); //$NON-NLS-1$ negated.addText(Boolean.toString(((ICondStructPO) resNode).isNegate())); } }
From source file:org.ednovo.gooru.application.util.ResourceInstanceFormatter.java
License:Open Source License
private Element getQuestionResource(Question question) { StringBuilder questionXML = new StringBuilder(getQuestionSet(question)); Element resourceElm = DocumentHelper.createElement(RESOURCE); if (question.getGooruOid() != null) { resourceElm.addAttribute(ID, question.getGooruOid()); } else {/* www . ja v a 2s.c o m*/ String resourceId = UUID.randomUUID().toString(); resourceElm.addAttribute(ID, resourceId); question.setGooruOid(resourceId); } resourceElm.addAttribute(TYPE, ResourceType.Type.QUIZ.getType()); Element nativeurl = resourceElm.addElement(NATIVE_URL); if (question.getUrl() != null) { nativeurl.addText(question.getUrl()); } else { nativeurl.addText(""); } Element folder = resourceElm.addElement(RESOURCE_FOLDER); if (question.getFolder() != null) { folder.addText(question.getFolder()); } else { folder.addText(""); } Element questionSet = null; try { questionSet = (Element) DocumentHelper.parseText(questionXML.toString()).getRootElement(); } catch (Exception e) { throw new MethodFailureException("Error while converting to a document"); } resourceElm.add(questionSet); return resourceElm; }
From source file:org.ednovo.gooru.application.util.ResourceInstanceFormatter.java
License:Open Source License
private Element setElementText(Element srcElement, String key, String text, boolean showNull) { Element element = srcElement.addElement(key); if (text == null && showNull) { text = ""; }//from w w w. j av a 2 s . com if (text != null) { element.addText(text); } return element; }
From source file:org.efaps.webdav4vfs.data.DavResource.java
License:Apache License
/** * Add the value for a given property to the result document. If the value * is missing or can not be added for some reason it will return false to * indicate a missing property.//from ww w. ja va 2s . co m * * @param _root root element for the result document fragment * @param _propertyName property name to query * @param _ignoreValue <i>true</i> if values must be ignored * @return true for successful addition and false for missing data */ @Override() protected boolean getPropertyValue(final Element _root, final String _propertyName, final boolean ignoreValue) { LogFactory.getLog(getClass()).debug(String.format("[%s].get('%s')", object.getName(), _propertyName)); if (PROP_CREATION_DATE.equals(_propertyName)) { return addCreationDateProperty(_root, ignoreValue); } else if (PROP_DISPLAY_NAME.equals(_propertyName)) { return addGetDisplayNameProperty(_root, ignoreValue); } else if (PROP_GET_CONTENT_LANGUAGE.equals(_propertyName)) { return addGetContentLanguageProperty(_root, ignoreValue); } else if (PROP_GET_CONTENT_LENGTH.equals(_propertyName)) { return addGetContentLengthProperty(_root, ignoreValue); } else if (PROP_GET_CONTENT_TYPE.equals(_propertyName)) { return addGetContentTypeProperty(_root, ignoreValue); } else if (PROP_GET_ETAG.equals(_propertyName)) { return addGetETagProperty(_root, ignoreValue); } else if (PROP_GET_LAST_MODIFIED.equals(_propertyName)) { return addGetLastModifiedProperty(_root, ignoreValue); } else if (PROP_LOCK_DISCOVERY.equals(_propertyName)) { return addLockDiscoveryProperty(_root, ignoreValue); } else if (PROP_RESOURCETYPE.equals(_propertyName)) { return addResourceTypeProperty(_root, ignoreValue); } else if (PROP_SOURCE.equals(_propertyName)) { return addSourceProperty(_root, ignoreValue); } else if (PROP_SUPPORTED_LOCK.equals(_propertyName)) { return addSupportedLockProperty(_root, ignoreValue); } else { // handle non-standard properties (keep a little separate) if (PROP_QUOTA.equals(_propertyName)) { return addQuotaProperty(_root, ignoreValue); } else if (PROP_QUOTA_USED.equals(_propertyName)) { return addQuotaUsedProperty(_root, ignoreValue); } else if (PROP_QUOTA_AVAILABLE_BYTES.equals(_propertyName)) { return addQuotaAvailableBytesProperty(_root, ignoreValue); } else if (PROP_QUOTA_USED_BYTES.equals(_propertyName)) { return addQuotaUsedBytesProperty(_root, ignoreValue); } else { try { Object propertyValue = object.getContent().getAttribute(_propertyName); if (null != propertyValue) { if (((String) propertyValue).startsWith("<")) { try { Document property = DocumentHelper.parseText((String) propertyValue); if (ignoreValue) { property.clearContent(); } _root.add(property.getRootElement().detach()); return true; } catch (DocumentException e) { LogFactory.getLog(getClass()).error("property value unparsable", e); return false; } } else { Element el = _root.addElement(_propertyName); if (!ignoreValue) { el.addText((String) propertyValue); } return true; } } } catch (FileSystemException e) { LogFactory.getLog(this.getClass()) .error(String.format("property '%s' is not supported", _propertyName), e); } } } return false; }
From source file:org.efaps.webdav4vfs.data.DavResource.java
License:Apache License
protected boolean addGetContentLengthProperty(final Element _root, final boolean _ignoreValue) { try {//w ww . j av a2s .com final Element el = _root.addElement(PROP_GET_CONTENT_LENGTH); if (!_ignoreValue) { el.addText("" + object.getContent().getSize()); } return true; } catch (FileSystemException e) { e.printStackTrace(); return false; } }
From source file:org.efaps.webdav4vfs.data.DavResource.java
License:Apache License
protected boolean addGetContentTypeProperty(final Element root, final boolean ignoreValue) { boolean ret = false; try {//from w ww .j a v a 2s. c o m String contentType = object.getContent().getContentInfo().getContentType(); if ((null != contentType) && !contentType.isEmpty()) { final Element el = root.addElement(PROP_GET_CONTENT_TYPE); if (!ignoreValue) { el.addText(contentType); } ret = true; } } catch (FileSystemException e) { e.printStackTrace(); } return ret; }
From source file:org.efaps.webdav4vfs.data.DavResource.java
License:Apache License
protected boolean addGetLastModifiedProperty(final Element _root, final boolean _ignoreValue) { try {//from w w w . ja v a 2s .com Element el = _root.addElement(PROP_GET_LAST_MODIFIED); if (!_ignoreValue) { el.addText(Util.getDateString(object.getContent().getLastModifiedTime())); } return true; } catch (FileSystemException e) { e.printStackTrace(); return false; } }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
License:Open Source License
@Override public void setValue(Object value) { if (value == null) value = "";//null?? if ((node instanceof org.dom4j.CharacterData || node instanceof Attribute || node instanceof DocumentType || node instanceof Entity || node instanceof ProcessingInstruction)) { String string = (String) TypeUtils.convert(value, String.class); if (string != null && !string.equals("")) { ((Node) node).setText(string); } else {//from ww w .j a va 2 s . c o m ((Node) node).getParent().remove((Node) node); } } else if (node instanceof Document) { Document theOriginalDoc = (Document) node; Element theOrigialRoot = theOriginalDoc.getRootElement(); if (value instanceof Document) {//?document Document valueDoc = (Document) value; Element valueRoot = valueDoc.getRootElement(); if (theOrigialRoot == null || valueRoot == null || theOrigialRoot.getQName().equals(valueRoot.getQName())) { theOriginalDoc.clearContent(); List content = valueDoc.content(); if (content != null) { for (int i = 0; i < content.size(); i++) { Node dom4jNode = (Node) content.get(i); Node newDom4jNode = (Node) dom4jNode.clone(); theOriginalDoc.add(newDom4jNode); } } } else { throw new RuntimeException( "Can NOT assign " + valueRoot.getQName() + " to " + theOrigialRoot.getQName()); } } else if (value instanceof Element) { Element valueElem = (Element) value; if (valueElem.getQName().equals(theOrigialRoot.getQName())) { theOriginalDoc.clearContent(); Element newValueElem = (Element) valueElem.clone(); theOriginalDoc.setRootElement(newValueElem); } else { throw new RuntimeException( "Can NOT assign " + valueElem.getQName() + " to " + theOrigialRoot.getQName()); } } else { throw new RuntimeException("Can NOT assign " + value + " to " + theOrigialRoot.getQName()); } // else if (value instanceof Comment){ // Comment cmmt = (Comment)((Comment)value).clone(); // theOriginalDoc.add(cmmt); // // }else if (value instanceof ProcessingInstruction){ // ProcessingInstruction instru = (ProcessingInstruction)((ProcessingInstruction)value).clone(); // theOriginalDoc.add(instru); // } } else if (node instanceof Element) { Element originalElem = ((Element) node); if (value != null && value instanceof Element) { Element valueElm = (Element) value; if (originalElem.getQName().equals(valueElm.getQName())) { originalElem.clearContent(); List content = valueElm.content(); if (content != null) { for (int i = 0; i < content.size(); i++) { Node dom4jNode = (Node) content.get(i); Node newDom4jNode = (Node) dom4jNode.clone(); originalElem.add(newDom4jNode); } } } else { throw new RuntimeException( "Can NOT assign " + valueElm.getQName() + " to " + originalElem.getQName()); } } else if (value != null && value instanceof Text) { originalElem.clearContent(); Text txt = (Text) ((Text) value).clone(); originalElem.add(txt); } else if (value != null && value instanceof CDATA) { originalElem.clearContent(); CDATA cdata = (CDATA) ((CDATA) value).clone(); originalElem.add(cdata); } else if (value != null && value instanceof java.util.Date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = format.format((java.util.Date) value); originalElem.clearContent(); originalElem.addText(dateStr); } else { String string = (String) TypeUtils.convert(value, String.class); originalElem.clearContent(); originalElem.addText(string); } } }
From source file:org.frogx.service.core.DefaultMUGRoom.java
License:Open Source License
protected Presence getPresence() { Presence presence = new Presence(); presence.setFrom(getJID());/*from w w w .ja va 2 s .c o m*/ Element game = presence.addChildElement("game", MUGService.mugNS); Element statusElement = game.addElement("status"); statusElement.addText(match.getStatus().name()); if (match == null || match.getState() == null) { if (match == null) log.warn("[MUG] No match in room " + getJID() + "!"); if (match.getState() == null) log.debug("[MUG] No game state available in room " + getJID()); } else game.add(match.getState().createCopy()); return presence; }