List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:org.alfresco.module.vti.web.ws.VtiSoapResponse.java
License:Open Source License
/** * Constructor/* w w w.j a va 2 s . co m*/ * * @param response HttpServletResponse */ public VtiSoapResponse(HttpServletResponse response) { super(response); document = DocumentHelper.createDocument(); Element envelope = document.addElement(QName.get("Envelope", "s", VtiSoapResponse.NAMESPACE)); envelope.addElement(QName.get("Body", "s", VtiSoapResponse.NAMESPACE)); }
From source file:org.alfresco.web.bean.dashboard.PageConfig.java
License:Open Source License
/** * Convert this config to an XML definition which can be serialized. * Example:// w ww .j av a2s . c o m * <code> * <?xml version="1.0"?> * <dashboard> * <page id="main" layout-id="narrow-left-2column"> * <column> * <dashlet idref="clock" /> * <dashlet idref="random-joke" /> * </column> * <column> * <dashlet idref="getting-started" /> * <dashlet idref="task-list" /> * <dashlet idref="my-checkedout-docs" /> * <dashlet idref="my-documents" /> * </column> * </page> * </dashboard> * </code> * * @return XML for this config */ public String toXML() { try { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement(ELEMENT_DASHBOARD); for (Page page : pages) { Element pageElement = root.addElement(ELEMENT_PAGE); pageElement.addAttribute(ATTR_ID, page.getId()); pageElement.addAttribute(ATTR_LAYOUTID, page.getLayoutDefinition().Id); for (Column column : page.getColumns()) { Element columnElement = pageElement.addElement(ELEMENT_COLUMN); for (DashletDefinition dashletDef : column.getDashlets()) { columnElement.addElement(ELEMENT_DASHLET).addAttribute(ATTR_REFID, dashletDef.Id); } } } StringWriter out = new StringWriter(512); XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); writer.setWriter(out); writer.write(doc); return out.toString(); } catch (Throwable err) { throw new AlfrescoRuntimeException( "Unable to serialize Dashboard PageConfig to XML: " + err.getMessage(), err); } }
From source file:org.alfresco.web.bean.search.SearchContext.java
License:Open Source License
/** * @return this SearchContext as XML/* ww w.j a v a 2s.c o m*/ * * Example: * <code> * <?xml version="1.0" encoding="UTF-8"?> * <search> * <text>CDATA</text> * <mode>int</mode> * <location>XPath</location> * <categories> * <category>XPath</category> * </categories> * <content-type>String</content-type> * <folder-type>String</folder-type> * <mimetype>String</mimetype> * <attributes> * <attribute name="String">String</attribute> * </attributes> * <ranges> * <range name="String"> * <lower>String</lower> * <upper>String</upper> * <inclusive>boolean</inclusive> * </range> * </ranges> * <fixed-values> * <value name="String">String</value> * </fixed-values> * <query>CDATA</query> * </search> * </code> */ public String toXML() { try { NamespaceService ns = Repository.getServiceRegistry(FacesContext.getCurrentInstance()) .getNamespaceService(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement(ELEMENT_SEARCH); root.addElement(ELEMENT_TEXT).addCDATA(this.text); root.addElement(ELEMENT_MODE).addText(Integer.toString(this.mode)); if (this.location != null) { root.addElement(ELEMENT_LOCATION).addText(this.location); } Element categories = root.addElement(ELEMENT_CATEGORIES); for (String path : this.categories) { categories.addElement(ELEMENT_CATEGORY).addText(path); } if (this.contentType != null) { root.addElement(ELEMENT_CONTENT_TYPE).addText(this.contentType); } if (this.folderType != null) { root.addElement(ELEMENT_FOLDER_TYPE).addText(this.folderType); } if (this.mimeType != null && this.mimeType.length() != 0) { root.addElement(ELEMENT_MIMETYPE).addText(this.mimeType); } Element attributes = root.addElement(ELEMENT_ATTRIBUTES); for (QName attrName : this.queryAttributes.keySet()) { attributes.addElement(ELEMENT_ATTRIBUTE).addAttribute(ELEMENT_NAME, attrName.toPrefixString(ns)) .addCDATA(this.queryAttributes.get(attrName)); } Element ranges = root.addElement(ELEMENT_RANGES); for (QName rangeName : this.rangeAttributes.keySet()) { RangeProperties rangeProps = this.rangeAttributes.get(rangeName); Element range = ranges.addElement(ELEMENT_RANGE); range.addAttribute(ELEMENT_NAME, rangeName.toPrefixString(ns)); range.addElement(ELEMENT_LOWER).addText(rangeProps.lower); range.addElement(ELEMENT_UPPER).addText(rangeProps.upper); range.addElement(ELEMENT_INCLUSIVE).addText(Boolean.toString(rangeProps.inclusive)); } Element values = root.addElement(ELEMENT_FIXED_VALUES); for (QName valueName : this.queryFixedValues.keySet()) { values.addElement(ELEMENT_VALUE).addAttribute(ELEMENT_NAME, valueName.toPrefixString(ns)) .addCDATA(this.queryFixedValues.get(valueName)); } // outputing the full lucene query may be useful for some situations Element query = root.addElement(ELEMENT_QUERY); String queryString = buildQuery(0); if (queryString != null) { query.addCDATA(queryString); } StringWriter out = new StringWriter(1024); XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); writer.setWriter(out); writer.write(doc); return out.toString(); } catch (Throwable err) { throw new AlfrescoRuntimeException("Failed to export SearchContext to XML.", err); } }
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 ww . ja v a 2 s . com 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.apache.directory.studio.connection.core.io.ConnectionIO.java
License:Apache License
/** * Saves the connections using the writer. * * @param connections the connections/*from w w w . jav a 2 s . c o m*/ * @param stream the OutputStream * @throws IOException if an I/O error occurs */ public static void save(Set<ConnectionParameter> connections, OutputStream stream) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); // Creating the root element Element root = document.addElement(CONNECTIONS_TAG); if (connections != null) { for (ConnectionParameter connection : connections) { addConnection(root, connection); } } // Writing the file to disk OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); //$NON-NLS-1$ XMLWriter writer = new XMLWriter(stream, outformat); writer.write(document); writer.flush(); }
From source file:org.apache.directory.studio.connection.core.io.ConnectionIO.java
License:Apache License
/** * Saves the connection folders using the writer. * * @param connectionFolders the connection folders * @param stream the OutputStream/*from w w w .j a va 2 s .c o m*/ * @throws IOException if an I/O error occurs */ public static void saveConnectionFolders(Set<ConnectionFolder> connectionFolders, OutputStream stream) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); // Creating the root element Element root = document.addElement(CONNECTION_FOLDERS_TAG); if (connectionFolders != null) { for (ConnectionFolder connectionFolder : connectionFolders) { addFolderConnection(root, connectionFolder); } } // Writing the file to disk OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); //$NON-NLS-1$ XMLWriter writer = new XMLWriter(stream, outformat); writer.write(document); writer.flush(); }
From source file:org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO.java
License:Apache License
/** * Saves the browser connections using the output stream. * * @param stream/*from ww w . j av a2 s .co m*/ * the OutputStream * @param browserConnectionMap * the map of browser connections * @throws IOException * if an I/O error occurs */ public static void save(OutputStream stream, Map<String, IBrowserConnection> browserConnectionMap) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); // Creating the root element Element root = document.addElement(BROWSER_CONNECTIONS_TAG); if (browserConnectionMap != null) { for (IBrowserConnection browserConnection : browserConnectionMap.values()) { writeBrowserConnection(root, browserConnection); } } // Writing the file to disk OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); //$NON-NLS-1$ XMLWriter writer = new XMLWriter(stream, outformat); writer.write(document); writer.flush(); }
From source file:org.apache.directory.studio.ldapservers.LdapServersManagerIO.java
License:Apache License
/** * Writes the list of servers to the given stream. * * @param servers// w w w. j a v a 2 s . co m * the servers * @param outputStream * the output stream * @throws IOException * if an error occurs when writing to the stream */ public static void write(List<LdapServer> servers, OutputStream outputStream) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); // Creating the root element Element root = document.addElement(LDAP_SERVERS_TAG); if (servers != null) { for (LdapServer server : servers) { addLdapServer(server, root); } } // Writing the file to the stream OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); //$NON-NLS-1$ XMLWriter writer = new XMLWriter(outputStream, outformat); writer.write(document); writer.flush(); }
From source file:org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter.java
License:Apache License
/** * Converts the given project to its representation * in Dom4J Document.//from w w w. java 2 s . c o m * * @param project * the project to convert * @return * the corresponding Dom4j Document representation */ public static Document toDocument(Project project) { // Creating the Document Document document = DocumentHelper.createDocument(); // Adding the project addProject(project, document); return document; }
From source file:org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter.java
License:Apache License
/** * Converts the given projects to their representation * in Dom4J Document./*from w ww . j av a2s.c o m*/ * * @param projects * the projects to convert * @return * the corresponding Dom4j Document representation */ public static Document toDocument(Project[] projects) { // Creating the Document Document document = DocumentHelper.createDocument(); Element projectsElement = document.addElement(PROJECTS_TAG); if (projects != null) { for (Project project : projects) { addProject(project, projectsElement); } } return document; }