Java Code Examples for org.dom4j.io.XMLWriter#startElement()
The following examples show how to use
org.dom4j.io.XMLWriter#startElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Output the supported lock types XML element * * @param xml XMLWriter */ protected void writeLockTypes(XMLWriter xml) { try { AttributesImpl nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK, nullAttr); // Output exclusive lock // Shared locks are not supported, as they cannot be supported by the LockService (relevant to ALF-16449). writeLock(xml, WebDAV.XML_NS_EXCLUSIVE); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK); } catch (Exception ex) { throw new AlfrescoRuntimeException("XML write error", ex); } }
Example 2
Source File: PropPatchMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Generates the error tag * * @param xml XMLWriter */ protected void generateError(XMLWriter xml) { try { // Output the start of the error element Attributes nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR, nullAttr); // Output error xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CANNOT_MODIFY_PROTECTED_PROPERTY)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR); } catch (Exception ex) { // Convert to a runtime exception throw new AlfrescoRuntimeException("XML processing error", ex); } }
Example 3
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates the required response XML for the current node * * @param xml XMLWriter * @param nodeInfo FileInfo * @param path String */ protected void generateResponseForNode(XMLWriter xml, FileInfo nodeInfo, String path) throws Exception { boolean isFolder = nodeInfo.isFolder(); // Output the response block for the current node xml.startElement( WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE, getDAVHelper().getNullAttributes()); // Build the href string for the current node String strHRef = getURLForPath(m_request, path, isFolder); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(strHRef); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); switch (m_mode) { case GET_NAMED_PROPS: generateNamedPropertiesResponse(xml, nodeInfo, isFolder); break; case GET_ALL_PROPS: generateAllPropertiesResponse(xml, nodeInfo, isFolder); break; case FIND_PROPS: generateFindPropertiesResponse(xml, nodeInfo, isFolder); break; } // Close off the response element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); }
Example 4
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Output the lockentry element of the specified type * @param xml XMLWriter * @param lockType lock type containing namespace. Can be WebDAV.XML_NS_EXCLUSIVE or WebDAV.XML_NS_SHARED * @throws SAXException * @throws IOException */ private void writeLock(XMLWriter xml, String lockType) throws SAXException, IOException { AttributesImpl nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_ENTRY, WebDAV.XML_NS_LOCK_ENTRY, nullAttr); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE, nullAttr); xml.write(DocumentHelper.createElement(lockType)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE, nullAttr); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_WRITE)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_ENTRY, WebDAV.XML_NS_LOCK_ENTRY); }
Example 5
Source File: PropPatchMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates the XML response for a PROPFIND request that asks for a list of * all known properties * * @param xml XMLWriter * @param property WebDAVProperty * @param status int * @param description String */ protected void generatePropertyResponse(XMLWriter xml, WebDAVProperty property, int status, String description) { try { // Output the start of the properties element Attributes nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr); // Output property name xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr); if (property.hasNamespaceName()) { xml.write(DocumentHelper.createElement(property.getNamespaceName() + WebDAV.NAMESPACE_SEPARATOR + property.getName())); } else { xml.write(DocumentHelper.createElement(property.getName())); } xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); // Output action result status xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr); xml.write(WebDAV.HTTP1_1 + " " + status + " " + description); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT); } catch (Exception ex) { // Convert to a runtime exception throw new AlfrescoRuntimeException("XML processing error", ex); } }
Example 6
Source File: LockMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generates the XML lock discovery response body */ protected void generateResponse(FileInfo lockNodeInfo, String userName) throws Exception { String scope; String lt; String owner; Date expiry; if (lockToken != null) { // In case of lock creation take the scope from request header scope = this.createExclusive ? WebDAV.XML_EXCLUSIVE : WebDAV.XML_SHARED; // Output created lock lt = lockToken; } else { // In case of lock refreshing take the scope from previously stored lock scope = this.lockInfo.getScope(); // Output refreshed lock lt = this.lockInfo.getExclusiveLockToken(); } owner = lockInfo.getOwner(); expiry = lockInfo.getExpires(); XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(null); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP + nsdec, WebDAV.XML_NS_PROP + nsdec, getDAVHelper().getNullAttributes()); // Output the lock details generateLockDiscoveryXML(xml, lockNodeInfo, false, scope, WebDAV.getDepthName(m_depth), lt, owner, expiry); // Close off the XML xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); // Send remaining data flushXML(xml); }
Example 7
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generates the XML response for a PROPFIND request that asks for a list of * all known properties * * @param xml XMLWriter * @param nodeInfo FileInfo * @param isDir boolean */ protected void generateFindPropertiesResponse(XMLWriter xml, FileInfo nodeInfo, boolean isDir) { try { // 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); // Output the well-known properties xml.write(DocumentHelper.createElement(WebDAV.XML_NS_LOCK_DISCOVERY)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SUPPORTED_LOCK)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_RESOURCE_TYPE)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_DISPLAYNAME)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_LAST_MODIFIED)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LENGTH)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CREATION_DATE)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_ETAG)); if (isDir) { xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LANGUAGE)); xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_TYPE)); } // Output the custom properties xml.write(DocumentHelper.createElement(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); } catch (Exception ex) { // Convert to a runtime exception throw new AlfrescoRuntimeException("XML processing error", ex); } }
Example 8
Source File: PropPatchMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void generateResponseImpl() throws Exception { m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); // Set the response content type m_response.setContentType(WebDAV.XML_CONTENT_TYPE); // Create multistatus response XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(m_namespaces); xml.startElement( WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); // Output the response block for the current node xml.startElement( WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE, getDAVHelper().getNullAttributes()); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(strHRef); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); if (failedProperty != null) { generateError(xml); } for (PropertyAction propertyAction : m_propertyActions) { WebDAVProperty property = propertyAction.getProperty(); int statusCode = propertyAction.getStatusCode(); String statusCodeDescription = propertyAction.getStatusCodeDescription(); generatePropertyResponse(xml, property, statusCode, statusCodeDescription); } // Close off the response element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data flushXML(xml); }
Example 9
Source File: WebDAVMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generates the lock discovery XML response * * @param xml XMLWriter * @param lockNodeInfo FileInfo * @param emptyNamespace boolean True if namespace should be empty. Used to avoid bugs in WebDAV clients. * @param scope String lock scope * @param depth String lock depth * @param lToken String locktoken * @param owner String lock owner * @param expiryDate the date/time the lock should expire */ protected void generateLockDiscoveryXML(XMLWriter xml, FileInfo lockNodeInfo, boolean emptyNamespace, String scope, String depth, String lToken, String owner, Date expiryDate) throws Exception { Attributes nullAttr= getDAVHelper().getNullAttributes(); String ns = emptyNamespace ? "" : WebDAV.DAV_NS; if (lockNodeInfo != null) { // Output the XML response xml.startElement(ns, WebDAV.XML_LOCK_DISCOVERY, emptyNamespace ? WebDAV.XML_LOCK_DISCOVERY : WebDAV.XML_NS_LOCK_DISCOVERY, nullAttr); xml.startElement(ns, WebDAV.XML_ACTIVE_LOCK, emptyNamespace ? WebDAV.XML_ACTIVE_LOCK : WebDAV.XML_NS_ACTIVE_LOCK, nullAttr); xml.startElement(ns, WebDAV.XML_LOCK_TYPE, emptyNamespace ? WebDAV.XML_LOCK_TYPE : WebDAV.XML_NS_LOCK_TYPE, nullAttr); xml.write(DocumentHelper.createElement(emptyNamespace ? WebDAV.XML_WRITE : WebDAV.XML_NS_WRITE)); xml.endElement(ns, WebDAV.XML_LOCK_TYPE, emptyNamespace ? WebDAV.XML_LOCK_TYPE : WebDAV.XML_NS_LOCK_TYPE); xml.startElement(ns, WebDAV.XML_LOCK_SCOPE, emptyNamespace ? WebDAV.XML_LOCK_SCOPE : WebDAV.XML_NS_LOCK_SCOPE, nullAttr); xml.write(DocumentHelper.createElement(emptyNamespace ? scope : WebDAV.DAV_NS_PREFIX + scope)); xml.endElement(ns, WebDAV.XML_LOCK_SCOPE, emptyNamespace ? WebDAV.XML_LOCK_SCOPE : WebDAV.XML_NS_LOCK_SCOPE); // NOTE: We only support one level of lock at the moment xml.startElement(ns, WebDAV.XML_DEPTH, emptyNamespace ? WebDAV.XML_DEPTH : WebDAV.XML_NS_DEPTH, nullAttr); xml.write(depth); xml.endElement(ns, WebDAV.XML_DEPTH, emptyNamespace ? WebDAV.XML_DEPTH : WebDAV.XML_NS_DEPTH); xml.startElement(ns, WebDAV.XML_OWNER, emptyNamespace ? WebDAV.XML_OWNER : WebDAV.XML_NS_OWNER, nullAttr); xml.write(owner); xml.endElement(ns, WebDAV.XML_OWNER, emptyNamespace ? WebDAV.XML_OWNER : WebDAV.XML_NS_OWNER); xml.startElement(ns, WebDAV.XML_TIMEOUT, emptyNamespace ? WebDAV.XML_TIMEOUT : WebDAV.XML_NS_TIMEOUT, nullAttr); // Output the expiry time String strTimeout = WebDAV.INFINITE; if (expiryDate != null) { long timeoutRemaining = (expiryDate.getTime() - System.currentTimeMillis())/1000L; strTimeout = WebDAV.SECOND + timeoutRemaining; } xml.write(strTimeout); xml.endElement(ns, WebDAV.XML_TIMEOUT, emptyNamespace ? WebDAV.XML_TIMEOUT : WebDAV.XML_NS_TIMEOUT); xml.startElement(ns, WebDAV.XML_LOCK_TOKEN, emptyNamespace ? WebDAV.XML_LOCK_TOKEN : WebDAV.XML_NS_LOCK_TOKEN, nullAttr); xml.startElement(ns, WebDAV.XML_HREF, emptyNamespace ? WebDAV.XML_HREF : WebDAV.XML_NS_HREF, nullAttr); xml.write(lToken); xml.endElement(ns, WebDAV.XML_HREF, emptyNamespace ? WebDAV.XML_HREF : WebDAV.XML_NS_HREF); xml.endElement(ns, WebDAV.XML_LOCK_TOKEN, emptyNamespace ? WebDAV.XML_LOCK_TOKEN : WebDAV.XML_NS_LOCK_TOKEN); xml.endElement(ns, WebDAV.XML_ACTIVE_LOCK, emptyNamespace ? WebDAV.XML_ACTIVE_LOCK : WebDAV.XML_NS_ACTIVE_LOCK); xml.endElement(ns, WebDAV.XML_LOCK_DISCOVERY, emptyNamespace ? WebDAV.XML_LOCK_DISCOVERY : WebDAV.XML_NS_LOCK_DISCOVERY); } }