Java Code Examples for org.dom4j.io.XMLWriter#startDocument()

The following examples show how to use org.dom4j.io.XMLWriter#startDocument() . 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: ImportFileUpdater.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Updates the passed import file into the equivalent 1.4 format.
 * 
 * @param source		the source import file
 * @param destination	the destination import file
 */
public void updateImportFile(String source, String destination)
{
	XmlPullParser reader = getReader(source);
	XMLWriter writer = getWriter(destination);
	this.shownWarning = false;
	
	try
	{
		// Start the documentation
		writer.startDocument();
		
		// Start reading the document
		int eventType = reader.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) 
        {
            if (eventType == XmlPullParser.START_TAG) 
			{
            	ImportFileUpdater.this.outputCurrentElement(reader, writer, new OutputChildren());
			} 
			eventType = reader.next();
        }
		
		// End and close the document
		writer.endDocument();
		writer.close();
	}
	catch (Exception exception)
	{
		throw new AlfrescoRuntimeException("Unable to update import file.", exception);
	}
	
}
 
Example 2
Source File: Dom4JXmlWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 1.4
 */
public Dom4JXmlWriter(XMLWriter writer, NameCoder nameCoder) {
    super(nameCoder);
    this.writer = writer;
    this.elementStack = new FastStack(16);
    this.attributes = new AttributesImpl();
    try {
        writer.startDocument();
    } catch (SAXException e) {
        throw new StreamException(e);
    }
}
 
Example 3
Source File: LockMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 4
Source File: PropPatchMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
}