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:com.thinkberg.moxo.dav.data.DavResource.java
License:Apache License
@SuppressWarnings({ "WeakerAccess" }) protected boolean addGetLastModifiedProperty(Element root) { try {/*from w ww . j av a 2 s . co m*/ Element el = root.addElement(PROP_GET_LAST_MODIFIED); if (!ignoreValues) { el.addText(Util.getDateString(object.getContent().getLastModifiedTime())); } return true; } catch (FileSystemException e) { e.printStackTrace(); return false; } }
From source file:com.thinkberg.webdav.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 w w w . java 2s . co m * * @param root the root element for the result document fragment * @param propertyName the property name to query * @return true for successful addition and false for missing data */ protected boolean getPropertyValue(Element root, String propertyName, 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:com.thinkberg.webdav.data.DavResource.java
License:Apache License
protected boolean addGetContentLengthProperty(Element root, boolean ignoreValue) { try {/* w w w . ja v a 2 s .co m*/ 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:com.thinkberg.webdav.data.DavResource.java
License:Apache License
protected boolean addGetContentTypeProperty(Element root, boolean ignoreValue) { try {/* www. j a v a 2 s.co m*/ String contentType = object.getContent().getContentInfo().getContentType(); if (null == contentType || "".equals(contentType)) { return false; } Element el = root.addElement(PROP_GET_CONTENT_TYPE); if (!ignoreValue) { el.addText(contentType); } return true; } catch (FileSystemException e) { e.printStackTrace(); return false; } }
From source file:com.thinkberg.webdav.data.DavResource.java
License:Apache License
protected boolean addGetLastModifiedProperty(Element root, boolean ignoreValue) { try {/*from w ww . j a va 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:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void addAdmins(String... users) { Element security = (Element) document.getRootElement().selectSingleNode("//security"); Element admins = (Element) document.getRootElement().selectSingleNode("//admins"); if (admins == null) { admins = new DefaultElement("admins"); security.add(admins);/* w ww. ja va 2 s .c om*/ } for (String user : users) { Element userElement = new DefaultElement("user"); userElement.addText(user); admins.add(userElement); } }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void addRolesToAdmin(String[] roles) { Element security = (Element) document.getRootElement().selectSingleNode("//security"); Element admins = (Element) document.getRootElement().selectSingleNode("//admins"); if (admins == null) { admins = new DefaultElement("admins"); security.add(admins);//from ww w .ja v a 2s .com } for (String role : roles) { Element userElement = new DefaultElement("role"); userElement.addText(role); admins.add(userElement); } }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void addUsersToRole(String roleName, String[] users) { Element security = (Element) document.getRootElement().selectSingleNode("//security"); Element roles = (Element) document.getRootElement().selectSingleNode("//roles"); if (roles == null) { roles = new DefaultElement("roles"); security.add(roles);//from w w w .j a v a2s.c om } Element role = (Element) document.getRootElement().selectSingleNode("//role[name='" + roleName + "']"); if (role == null) { role = new DefaultElement("role"); role.addAttribute("name", roleName); roles.add(role); } for (String user : users) { Element userElement = new DefaultElement("user"); userElement.addText(user); role.add(userElement); } }
From source file:com.thoughtworks.go.server.domain.xml.UsersXmlViewModel.java
License:Apache License
private Element textNode(String name, String value) { Element result = new DOMElement(name); result.addText(value == null ? "" : value); return result; }
From source file:com.thoughtworks.go.server.domain.xml.UsersXmlViewModel.java
License:Apache License
private Element booleanNode(String name, boolean aBool) { final Element result = nodeOfType(name, "boolean"); result.addText(String.valueOf(aBool)); return result; }