List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.alfresco.repo.webdav.PropFindMethod.java
License:Open Source License
/** * Generates the XML response for a PROPFIND request that asks for all known * properties/*from ww w.j a v a2 s .com*/ * * @param xml XMLWriter * @param nodeInfo FileInfo * @param isDir boolean */ protected void generateAllPropertiesResponse(XMLWriter xml, FileInfo nodeInfo, boolean isDir) throws Exception { // Get the properties for the node Map<QName, Serializable> props = nodeInfo.getProperties(); // Output the start of the properties element Attributes nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); // Generate a lock status report, if locked generateLockDiscoveryResponse(xml, nodeInfo, isDir); // Output the supported lock types writeLockTypes(xml); // If the node is a folder then return as a collection type xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE, nullAttr); if (isDir) xml.write(DocumentHelper.createElement(WebDAV.XML_NS_COLLECTION)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE); // Get the node name Object davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_DISPLAYNAME); TypeConverter typeConv = DefaultTypeConverter.INSTANCE; // Output the node name xml.startElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME, nullAttr); if (davValue != null) { String name = typeConv.convert(String.class, davValue); if (name == null || name.length() == 0) { logger.error("WebDAV name is null, value=" + davValue.getClass().getName() + ", node=" + nodeInfo.getNodeRef()); } xml.write(name); } xml.endElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME); // Output the source // // NOTE: source is always a no content element in our implementation xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SOURCE)); // Get the creation date davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_CREATION_DATE); // Output the creation date xml.startElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE, nullAttr); if (davValue != null) xml.write(WebDAV.formatCreationDate(typeConv.convert(Date.class, davValue))); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE); // Get the modifed date/time davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_LAST_MODIFIED); // Output the last modified date of the node xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED, nullAttr); if (davValue != null) xml.write(WebDAV.formatModifiedDate(typeConv.convert(Date.class, davValue))); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED); // For a file node output the content language and content type if (isDir == false) { // Get the content language // TODO: // Output the content language xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, WebDAV.XML_NS_GET_CONTENT_LANGUAGE, nullAttr); // TODO: xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LANGUAGE, WebDAV.XML_NS_GET_CONTENT_LANGUAGE); // Get the content type davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_CONTENT_TYPE); // Output the content type xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, WebDAV.XML_NS_GET_CONTENT_TYPE, nullAttr); if (davValue != null) xml.write(typeConv.convert(String.class, davValue)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_TYPE, WebDAV.XML_NS_GET_CONTENT_TYPE); // Output the etag xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG, nullAttr); xml.write(getDAVHelper().makeETag(nodeInfo)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG); } // Get the content length, if it's not a folder long len = 0; if (isDir == false) { ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT); if (contentData != null) len = contentData.getSize(); } // Output the content length xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH, nullAttr); xml.write("" + len); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH); // Print out all the custom properties SessionUser davUser = (SessionUser) m_request.getSession() .getAttribute(AuthenticationFilter.AUTHENTICATION_USER); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_ALF_AUTHTICKET, WebDAV.XML_NS_ALF_AUTHTICKET, nullAttr); if (davUser != null) xml.write(davUser.getTicket()); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_ALF_AUTHTICKET, WebDAV.XML_NS_ALF_AUTHTICKET); // Close off the response xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); }
From source file:org.androidpn.server.xmpp.session.SessionManager.java
License:Open Source License
/** * Creates a new notification IQ and returns it. *//*from w w w . j a v a 2 s. c o m*/ private IQ createNotificationIQ(String apiKey, String title, String message, String uri) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper .createElement(QName.get("notification", NotificationManager.NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
From source file:org.apache.archiva.repository.metadata.RepositoryMetadataWriter.java
License:Apache License
public static void write(ArchivaRepositoryMetadata metadata, Writer writer) throws RepositoryMetadataException { Document doc = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("metadata"); doc.setRootElement(root);//from w w w .j av a 2 s .co m addOptionalElementText(root, "groupId", metadata.getGroupId()); addOptionalElementText(root, "artifactId", metadata.getArtifactId()); addOptionalElementText(root, "version", metadata.getVersion()); if (CollectionUtils.isNotEmpty(metadata.getPlugins())) { Element plugins = root.addElement("plugins"); List<Plugin> pluginList = metadata.getPlugins(); Collections.sort(pluginList, PluginComparator.INSTANCE); for (Plugin plugin : metadata.getPlugins()) { Element p = plugins.addElement("plugin"); p.addElement("prefix").setText(plugin.getPrefix()); p.addElement("artifactId").setText(plugin.getArtifactId()); addOptionalElementText(p, "name", plugin.getName()); } } if (CollectionUtils.isNotEmpty(metadata.getAvailableVersions()) // || StringUtils.isNotBlank(metadata.getReleasedVersion()) // || StringUtils.isNotBlank(metadata.getLatestVersion()) // || StringUtils.isNotBlank(metadata.getLastUpdated()) // || (metadata.getSnapshotVersion() != null)) { Element versioning = root.addElement("versioning"); addOptionalElementText(versioning, "latest", metadata.getLatestVersion()); addOptionalElementText(versioning, "release", metadata.getReleasedVersion()); if (metadata.getSnapshotVersion() != null) { Element snapshot = versioning.addElement("snapshot"); String bnum = String.valueOf(metadata.getSnapshotVersion().getBuildNumber()); addOptionalElementText(snapshot, "buildNumber", bnum); addOptionalElementText(snapshot, "timestamp", metadata.getSnapshotVersion().getTimestamp()); } if (CollectionUtils.isNotEmpty(metadata.getAvailableVersions())) { Element versions = versioning.addElement("versions"); Iterator<String> it = metadata.getAvailableVersions().iterator(); while (it.hasNext()) { String version = it.next(); versions.addElement("version").setText(version); } } addOptionalElementText(versioning, "lastUpdated", metadata.getLastUpdated()); } try { XMLWriter.write(doc, writer); } catch (XMLException e) { throw new RepositoryMetadataException("Unable to write xml contents to writer: " + e.getMessage(), e); } }
From source file:org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl.java
License:Apache License
@Override public void toElement(org.dom4j.Element parent) { if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }/*from w w w .ja v a 2s . co m*/ parent.addElement("name").addText(this.getName()); parent.addElement("description").addText(this.getDescription()); if (!members.isEmpty()) { org.dom4j.Element elementMembers = DocumentHelper.createElement(new QName("members")); for (IPersonAttributesGroupDefinition member : members) { elementMembers.addElement("member-name").addText(member.getName()); } parent.add(elementMembers); } if (!testGroups.isEmpty()) { org.dom4j.Element elementSelectionTest = DocumentHelper.createElement(new QName("selection-test")); for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) { testGroup.toElement(elementSelectionTest); } parent.add(elementSelectionTest); } }
From source file:org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupTestDefinitionImpl.java
License:Apache License
@Override public void toElement(org.dom4j.Element parent) { if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from www .jav a2 s. c om org.dom4j.Element elementTest = DocumentHelper.createElement(new QName("test")); elementTest.addElement("attribute-name").addText(this.getAttributeName()); elementTest.addElement("tester-class").addText(this.getTesterClassName()); elementTest.addElement("test-value").addText(this.getTestValue()); parent.add(elementTest); }
From source file:org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupTestGroupDefinitionImpl.java
License:Apache License
@Override public void toElement(org.dom4j.Element parent) { if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from www.j av a 2 s.c om org.dom4j.Element elementTestGroup = DocumentHelper.createElement(new QName("test-group")); for (IPersonAttributesGroupTestDefinition test : tests) { test.toElement(elementTestGroup); } parent.add(elementTestGroup); }
From source file:org.apereo.portal.layout.dlm.FragmentDefinition.java
License:Apache License
@Override public void toElement(org.dom4j.Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from ww w . j a va 2 s . c om QName q = new QName("fragment", FragmentDefinition.NAMESPACE); org.dom4j.Element rslt = DocumentHelper.createElement(q); rslt.addAttribute("name", this.getName()); rslt.addAttribute("ownerID", this.getOwnerId()); rslt.addAttribute("precedence", Double.toString(this.getPrecedence())); rslt.addAttribute("description", this.getDescription()); // Serialize our children... for (Evaluator v : this.evaluators) { v.toElement(rslt); } parent.add(rslt); }
From source file:org.apereo.portal.layout.dlm.providers.AllUsersEvaluatorFactory.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }// w w w . jav a2 s . com Element rslt = null; QName q = new QName("audience", FragmentDefinition.NAMESPACE); rslt = DocumentHelper.createElement(q); rslt.addAttribute("evaluatorFactory", this.getFactoryClass().getName()); parent.add(rslt); }
From source file:org.apereo.portal.layout.dlm.providers.AttributeEvaluator.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }//from w w w .j a va 2s . c om String mde = null; switch (this.mode) { case AttributeEvaluator.CONTAINS: mde = "contains"; break; case AttributeEvaluator.EQUALS: mde = "equals"; break; case AttributeEvaluator.STARTS_WITH: mde = "startsWith"; break; case AttributeEvaluator.ENDS_WITH: mde = "endsWith"; break; case AttributeEvaluator.EXISTS: mde = "exists"; break; default: throw new IllegalStateException("Unrecognized mode constant: " + this.mode); } Element rslt = DocumentHelper.createElement("attribute"); rslt.addAttribute("name", this.name); rslt.addAttribute("mode", mde); rslt.addAttribute("value", this.value); parent.add(rslt); }
From source file:org.apereo.portal.layout.dlm.providers.GroupMembershipEvaluator.java
License:Apache License
@Override public void toElement(Element parent) { // Assertions. if (parent == null) { String msg = "Argument 'parent' cannot be null."; throw new IllegalArgumentException(msg); }/*from w w w.ja v a 2s . c om*/ String mde = null; switch (this.evaluatorMode) { case MEMBER_OF_MODE: mde = "memberOf"; break; case DEEP_MEMBER_OF_MODE: mde = "deepMemberOf"; break; default: throw new IllegalStateException("Unrecognized evaluatorMode constant: " + this.evaluatorMode); } Element rslt = DocumentHelper.createElement("attribute"); rslt.addAttribute("mode", mde); rslt.addAttribute("name", this.groupName); parent.add(rslt); }