org.apache.catalina.util.XMLWriter Java Examples

The following examples show how to use org.apache.catalina.util.XMLWriter. 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: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Propfind helper method.
 *
 * @param req The servlet request
 * @param generatedXML XML response to the Propfind request
 * @param path Path of the current resource
 * @param type Propfind type
 * @param propertiesVector If the propfind type is find properties by
 * name, then this Vector contains those properties
 */
private void parseProperties(HttpServletRequest req,
                             XMLWriter generatedXML,
                             String path, int type,
                             Vector<String> propertiesVector) {

    // Exclude any resource in the /WEB-INF and /META-INF subdirectories
    if (isSpecialPath(path))
        return;

    WebResource resource = resources.getResource(path);
    if (!resource.exists()) {
        // File is in directory listing but doesn't appear to exist
        // Broken symlink or odd permission settings?
        return;
    }

    String href = req.getContextPath() + req.getServletPath();
    if ((href.endsWith("/")) && (path.startsWith("/")))
        href += path.substring(1);
    else
        href += path;
    if (resource.isDirectory() && (!href.endsWith("/")))
        href += "/";

    String rewrittenUrl = rewriteUrl(href);

    generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector,
            resource.isFile(), false, resource.getCreation(), resource.getLastModified(),
            resource.getContentLength(), getServletContext().getMimeType(resource.getName()),
            resource.getETag());
}
 
Example #2
Source File: DavServlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will append an XML fragment to the given XML writer.
 */
// originally this called toXML( ... false). That causes
// the system to show a dummy lock name. That breaks
// Contribute. It also violates the RFC. Contribute uses
// PROPFIND to find the lock name. Furthermore, the RFC
// specifically prohibits hiding the lock name this way.
// Rather than treating the lock name as secret, it's
// better to check permissions, as I now do.
public void toXML(XMLWriter generatedXML)
{
	toXML(generatedXML, true);
}
 
Example #3
Source File: DavServlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will append an XML fragment to the given XML writer.
 */
// originally this called toXML( ... false). That causes
// the system to show a dummy lock name. That breaks
// Contribute. It also violates the RFC. Contribute uses
// PROPFIND to find the lock name. Furthermore, the RFC
// specifically prohibits hiding the lock name this way.
// Rather than treating the lock name as secret, it's
// better to check permissions, as I now do.
public void toXML(XMLWriter generatedXML)
{
	toXML(generatedXML, true);
}
 
Example #4
Source File: WebdavServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Print the lock discovery information associated with a path.
 *
 * @param path Path
 * @param generatedXML XML data to which the locks info will be appended
 * @return true if at least one lock was displayed
 */
private boolean generateLockDiscovery
    (String path, XMLWriter generatedXML) {

    LockInfo resourceLock = resourceLocks.get(path);
    Enumeration<LockInfo> collectionLocksList = collectionLocks.elements();

    boolean wroteStart = false;

    if (resourceLock != null) {
        wroteStart = true;
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
        resourceLock.toXML(generatedXML);
    }

    while (collectionLocksList.hasMoreElements()) {
        LockInfo currentLock = collectionLocksList.nextElement();
        if (path.startsWith(currentLock.path)) {
            if (!wroteStart) {
                wroteStart = true;
                generatedXML.writeElement("D", "lockdiscovery",
                        XMLWriter.OPENING);
            }
            currentLock.toXML(generatedXML);
        }
    }

    if (wroteStart) {
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
    } else {
        return false;
    }

    return true;

}
 
Example #5
Source File: WebdavServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Print the lock discovery information associated with a path.
 *
 * @param path Path
 * @param generatedXML XML data to which the locks info will be appended
 * @return true if at least one lock was displayed
 */
private boolean generateLockDiscovery
    (String path, XMLWriter generatedXML) {

    LockInfo resourceLock = resourceLocks.get(path);
    Enumeration<LockInfo> collectionLocksList = collectionLocks.elements();

    boolean wroteStart = false;

    if (resourceLock != null) {
        wroteStart = true;
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
        resourceLock.toXML(generatedXML);
    }

    while (collectionLocksList.hasMoreElements()) {
        LockInfo currentLock = collectionLocksList.nextElement();
        if (path.startsWith(currentLock.path)) {
            if (!wroteStart) {
                wroteStart = true;
                generatedXML.writeElement("D", "lockdiscovery",
                        XMLWriter.OPENING);
            }
            currentLock.toXML(generatedXML);
        }
    }

    if (wroteStart) {
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
    } else {
        return false;
    }

    return true;

}
 
Example #6
Source File: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Print the lock discovery information associated with a path.
 *
 * @param path Path
 * @param generatedXML XML data to which the locks info will be appended
 * @return <code>true</code> if at least one lock was displayed
 */
private boolean generateLockDiscovery
    (String path, XMLWriter generatedXML) {

    LockInfo resourceLock = resourceLocks.get(path);
    Enumeration<LockInfo> collectionLocksList = collectionLocks.elements();

    boolean wroteStart = false;

    if (resourceLock != null) {
        wroteStart = true;
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
        resourceLock.toXML(generatedXML);
    }

    while (collectionLocksList.hasMoreElements()) {
        LockInfo currentLock = collectionLocksList.nextElement();
        if (path.startsWith(currentLock.path)) {
            if (!wroteStart) {
                wroteStart = true;
                generatedXML.writeElement("D", "lockdiscovery",
                        XMLWriter.OPENING);
            }
            currentLock.toXML(generatedXML);
        }
    }

    if (wroteStart) {
        generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
    } else {
        return false;
    }

    return true;

}
 
Example #7
Source File: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Propfind helper method. Displays the properties of a lock-null resource.
 *
 * @param req The servlet request
 * @param generatedXML XML response to the Propfind request
 * @param path Path of the current resource
 * @param type Propfind type
 * @param propertiesVector If the propfind type is find properties by
 * name, then this Vector contains those properties
 */
private void parseLockNullProperties(HttpServletRequest req,
                                     XMLWriter generatedXML,
                                     String path, int type,
                                     Vector<String> propertiesVector) {

    // Exclude any resource in the /WEB-INF and /META-INF subdirectories
    if (isSpecialPath(path))
        return;

    // Retrieving the lock associated with the lock-null resource
    LockInfo lock = resourceLocks.get(path);

    if (lock == null)
        return;

    String absoluteUri = req.getRequestURI();
    String relativePath = getRelativePath(req);
    String toAppend = path.substring(relativePath.length());
    if (!toAppend.startsWith("/"))
        toAppend = "/" + toAppend;

    String rewrittenUrl = rewriteUrl(RequestUtil.normalize(
            absoluteUri + toAppend));

    generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector,
            true, true, lock.creationDate.getTime(), lock.creationDate.getTime(),
            0, "", "");
}
 
Example #8
Source File: WebdavServlet.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Send a multistatus element containing a complete error report to the
 * client.
 *
 * @param req Servlet request
 * @param resp Servlet response
 * @param errorList List of error to be displayed
 */
private void sendReport(HttpServletRequest req, HttpServletResponse resp,
                        Hashtable<String,Integer> errorList)
        throws IOException {

    resp.setStatus(WebdavStatus.SC_MULTI_STATUS);

    String absoluteUri = req.getRequestURI();
    String relativePath = getRelativePath(req);

    XMLWriter generatedXML = new XMLWriter();
    generatedXML.writeXMLHeader();

    generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus",
            XMLWriter.OPENING);

    Enumeration<String> pathList = errorList.keys();
    while (pathList.hasMoreElements()) {

        String errorPath = pathList.nextElement();
        int errorCode = errorList.get(errorPath).intValue();

        generatedXML.writeElement("D", "response", XMLWriter.OPENING);

        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        String toAppend = errorPath.substring(relativePath.length());
        if (!toAppend.startsWith("/"))
            toAppend = "/" + toAppend;
        generatedXML.writeText(absoluteUri + toAppend);
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
        generatedXML.writeElement("D", "status", XMLWriter.OPENING);
        generatedXML.writeText("HTTP/1.1 " + errorCode + " "
                + WebdavStatus.getStatusText(errorCode));
        generatedXML.writeElement("D", "status", XMLWriter.CLOSING);

        generatedXML.writeElement("D", "response", XMLWriter.CLOSING);

    }

    generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);

    Writer writer = resp.getWriter();
    writer.write(generatedXML.toString());
    writer.close();

}
 
Example #9
Source File: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Get an XML representation of this lock token.
 *
 * @param generatedXML The XML write to which the fragment will be
 *                     appended
 */
public void toXML(XMLWriter generatedXML) {

    generatedXML.writeElement("D", "activelock", XMLWriter.OPENING);

    generatedXML.writeElement("D", "locktype", XMLWriter.OPENING);
    generatedXML.writeElement("D", type, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "locktype", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "lockscope", XMLWriter.OPENING);
    generatedXML.writeElement("D", scope, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "lockscope", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "depth", XMLWriter.OPENING);
    if (depth == maxDepth) {
        generatedXML.writeText("Infinity");
    } else {
        generatedXML.writeText("0");
    }
    generatedXML.writeElement("D", "depth", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "owner", XMLWriter.OPENING);
    generatedXML.writeText(owner);
    generatedXML.writeElement("D", "owner", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "timeout", XMLWriter.OPENING);
    long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
    generatedXML.writeText("Second-" + timeout);
    generatedXML.writeElement("D", "timeout", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "locktoken", XMLWriter.OPENING);
    Enumeration<String> tokensList = tokens.elements();
    while (tokensList.hasMoreElements()) {
        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        generatedXML.writeText("opaquelocktoken:"
                               + tokensList.nextElement());
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
    }
    generatedXML.writeElement("D", "locktoken", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "activelock", XMLWriter.CLOSING);
}
 
Example #10
Source File: WebdavServlet.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will
 * append an XML fragment to the given XML writer.
 */
public void toXML(XMLWriter generatedXML) {

    generatedXML.writeElement("D", "activelock", XMLWriter.OPENING);

    generatedXML.writeElement("D", "locktype", XMLWriter.OPENING);
    generatedXML.writeElement("D", type, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "locktype", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "lockscope", XMLWriter.OPENING);
    generatedXML.writeElement("D", scope, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "lockscope", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "depth", XMLWriter.OPENING);
    if (depth == maxDepth) {
        generatedXML.writeText("Infinity");
    } else {
        generatedXML.writeText("0");
    }
    generatedXML.writeElement("D", "depth", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "owner", XMLWriter.OPENING);
    generatedXML.writeText(owner);
    generatedXML.writeElement("D", "owner", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "timeout", XMLWriter.OPENING);
    long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
    generatedXML.writeText("Second-" + timeout);
    generatedXML.writeElement("D", "timeout", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "locktoken", XMLWriter.OPENING);
    Enumeration<String> tokensList = tokens.elements();
    while (tokensList.hasMoreElements()) {
        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        generatedXML.writeText("opaquelocktoken:"
                               + tokensList.nextElement());
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
    }
    generatedXML.writeElement("D", "locktoken", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "activelock", XMLWriter.CLOSING);

}
 
Example #11
Source File: WebdavServlet.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Send a multistatus element containing a complete error report to the
 * client.
 *
 * @param req Servlet request
 * @param resp Servlet response
 * @param errorList List of error to be displayed
 */
private void sendReport(HttpServletRequest req, HttpServletResponse resp,
                        Hashtable<String,Integer> errorList)
        throws IOException {

    resp.setStatus(WebdavStatus.SC_MULTI_STATUS);

    String absoluteUri = req.getRequestURI();
    String relativePath = getRelativePath(req);

    XMLWriter generatedXML = new XMLWriter();
    generatedXML.writeXMLHeader();

    generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus",
            XMLWriter.OPENING);

    Enumeration<String> pathList = errorList.keys();
    while (pathList.hasMoreElements()) {

        String errorPath = pathList.nextElement();
        int errorCode = errorList.get(errorPath).intValue();

        generatedXML.writeElement("D", "response", XMLWriter.OPENING);

        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        String toAppend = errorPath.substring(relativePath.length());
        if (!toAppend.startsWith("/"))
            toAppend = "/" + toAppend;
        generatedXML.writeText(absoluteUri + toAppend);
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
        generatedXML.writeElement("D", "status", XMLWriter.OPENING);
        generatedXML.writeText("HTTP/1.1 " + errorCode + " "
                + WebdavStatus.getStatusText(errorCode));
        generatedXML.writeElement("D", "status", XMLWriter.CLOSING);

        generatedXML.writeElement("D", "response", XMLWriter.CLOSING);

    }

    generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);

    Writer writer = resp.getWriter();
    writer.write(generatedXML.toString());
    writer.close();

}
 
Example #12
Source File: WebdavServlet.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will
 * append an XML fragment to the given XML writer.
 */
public void toXML(XMLWriter generatedXML) {

    generatedXML.writeElement("D", "activelock", XMLWriter.OPENING);

    generatedXML.writeElement("D", "locktype", XMLWriter.OPENING);
    generatedXML.writeElement("D", type, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "locktype", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "lockscope", XMLWriter.OPENING);
    generatedXML.writeElement("D", scope, XMLWriter.NO_CONTENT);
    generatedXML.writeElement("D", "lockscope", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "depth", XMLWriter.OPENING);
    if (depth == maxDepth) {
        generatedXML.writeText("Infinity");
    } else {
        generatedXML.writeText("0");
    }
    generatedXML.writeElement("D", "depth", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "owner", XMLWriter.OPENING);
    generatedXML.writeText(owner);
    generatedXML.writeElement("D", "owner", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "timeout", XMLWriter.OPENING);
    long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
    generatedXML.writeText("Second-" + timeout);
    generatedXML.writeElement("D", "timeout", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "locktoken", XMLWriter.OPENING);
    Enumeration<String> tokensList = tokens.elements();
    while (tokensList.hasMoreElements()) {
        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        generatedXML.writeText("opaquelocktoken:"
                               + tokensList.nextElement());
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
    }
    generatedXML.writeElement("D", "locktoken", XMLWriter.CLOSING);

    generatedXML.writeElement("D", "activelock", XMLWriter.CLOSING);

}
 
Example #13
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Send a multistatus element containing a complete error report to the client.
 * 
 * @param req
 *        Servlet request
 * @param resp
 *        Servlet response
 * @param errorList
 *        List of error to be displayed
 */
private void sendReport(HttpServletRequest req, HttpServletResponse resp, Hashtable<String,Integer> errorList) throws ServletException,
		IOException
{

	resp.setStatus(SakaidavStatus.SC_MULTI_STATUS);

	String absoluteUri = req.getRequestURI();
	String relativePath = getRelativePath(req);
	
	XMLWriter generatedXML = new XMLWriter();
	generatedXML.writeXMLHeader();

	generatedXML.writeElement("D", "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING);

	Enumeration<String> pathList = errorList.keys();
	while (pathList.hasMoreElements())
	{

		String errorPath = pathList.nextElement();
		int errorCode = ((Integer) errorList.get(errorPath)).intValue();

		generatedXML.writeElement("D", "response", XMLWriter.OPENING);

		generatedXML.writeElement("D", "href", XMLWriter.OPENING);
		String toAppend = errorPath.substring(relativePath.length());
		if (!toAppend.startsWith("/")) toAppend = "/" + toAppend;
		generatedXML.writeText(absoluteUri + toAppend);
		generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
		generatedXML.writeElement("D", "status", XMLWriter.OPENING);
		generatedXML.writeText("HTTP/1.1 " + errorCode + " " + SakaidavStatus.getStatusText(errorCode));
		generatedXML.writeElement("D", "status", XMLWriter.CLOSING);

		generatedXML.writeElement("D", "response", XMLWriter.CLOSING);

	}

	generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);

	Writer writer = resp.getWriter();
	writer.write(generatedXML.toString());
	writer.close();

}
 
Example #14
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Print the lock discovery information associated with a path.
 * 
 * @param path
 *        Path
 * @param generatedXML
 *        XML data to which the locks info will be appended
 * @return true if at least one lock was displayed
 */
private boolean generateLockDiscovery(String path, XMLWriter generatedXML)
{

	LockInfo resourceLock = (LockInfo) resourceLocks.get(path);
	Enumeration<LockInfo> collectionLocksList = collectionLocks.elements();

	boolean wroteStart = false;

	if (resourceLock != null)
	{
		wroteStart = true;
		generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
		resourceLock.toXML(generatedXML);
	}

	while (collectionLocksList.hasMoreElements())
	{
		LockInfo currentLock = (LockInfo) collectionLocksList.nextElement();
		if (path.startsWith(currentLock.path))
		{
			if (!wroteStart)
			{
				wroteStart = true;
				generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
			}
			currentLock.toXML(generatedXML);
		}
	}

	if (wroteStart)
	{
		generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
	}
	else
	{
		return false;
	}

	return true;

}
 
Example #15
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will append an XML fragment to the given XML writer.
 */
public void toXML(XMLWriter generatedXML, boolean showToken)
{

	generatedXML.writeElement("D", "activelock", XMLWriter.OPENING);

	generatedXML.writeElement("D", "locktype", XMLWriter.OPENING);
	generatedXML.writeElement("D", type, XMLWriter.NO_CONTENT);
	generatedXML.writeElement("D", "locktype", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "lockscope", XMLWriter.OPENING);
	generatedXML.writeElement("D", scope, XMLWriter.NO_CONTENT);
	generatedXML.writeElement("D", "lockscope", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "depth", XMLWriter.OPENING);
	if (depth == INFINITY)
	{
		generatedXML.writeText("Infinity");
	}
	else
	{
		generatedXML.writeText("0");
	}
	generatedXML.writeElement("D", "depth", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "owner", XMLWriter.OPENING);
	generatedXML.writeText(owner);
	generatedXML.writeElement("D", "owner", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "timeout", XMLWriter.OPENING);
	long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
	generatedXML.writeText("Second-" + timeout);
	generatedXML.writeElement("D", "timeout", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "locktoken", XMLWriter.OPENING);
	if (showToken)
	{
		Enumeration<String> tokensList = tokens.elements();
		while (tokensList.hasMoreElements())
		{
			generatedXML.writeElement("D", "href", XMLWriter.OPENING);
			generatedXML.writeText("opaquelocktoken:" + tokensList.nextElement());
			generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
		}
	}
	else
	{
		generatedXML.writeElement("D", "href", XMLWriter.OPENING);
		generatedXML.writeText("opaquelocktoken:dummytoken");
		generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
	}
	generatedXML.writeElement("D", "locktoken", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "activelock", XMLWriter.CLOSING);

}
 
Example #16
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Send a multistatus element containing a complete error report to the client.
 * 
 * @param req
 *        Servlet request
 * @param resp
 *        Servlet response
 * @param errorList
 *        List of error to be displayed
 */
private void sendReport(HttpServletRequest req, HttpServletResponse resp, Hashtable<String,Integer> errorList) throws ServletException,
		IOException
{

	resp.setStatus(SakaidavStatus.SC_MULTI_STATUS);

	String absoluteUri = req.getRequestURI();
	String relativePath = getRelativePath(req);
	
	XMLWriter generatedXML = new XMLWriter();
	generatedXML.writeXMLHeader();

	generatedXML.writeElement("D", "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING);

	Enumeration<String> pathList = errorList.keys();
	while (pathList.hasMoreElements())
	{

		String errorPath = pathList.nextElement();
		int errorCode = ((Integer) errorList.get(errorPath)).intValue();

		generatedXML.writeElement("D", "response", XMLWriter.OPENING);

		generatedXML.writeElement("D", "href", XMLWriter.OPENING);
		String toAppend = errorPath.substring(relativePath.length());
		if (!toAppend.startsWith("/")) toAppend = "/" + toAppend;
		generatedXML.writeText(absoluteUri + toAppend);
		generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
		generatedXML.writeElement("D", "status", XMLWriter.OPENING);
		generatedXML.writeText("HTTP/1.1 " + errorCode + " " + SakaidavStatus.getStatusText(errorCode));
		generatedXML.writeElement("D", "status", XMLWriter.CLOSING);

		generatedXML.writeElement("D", "response", XMLWriter.CLOSING);

	}

	generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);

	Writer writer = resp.getWriter();
	writer.write(generatedXML.toString());
	writer.close();

}
 
Example #17
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Print the lock discovery information associated with a path.
 * 
 * @param path
 *        Path
 * @param generatedXML
 *        XML data to which the locks info will be appended
 * @return true if at least one lock was displayed
 */
private boolean generateLockDiscovery(String path, XMLWriter generatedXML)
{

	LockInfo resourceLock = (LockInfo) resourceLocks.get(path);
	Enumeration<LockInfo> collectionLocksList = collectionLocks.elements();

	boolean wroteStart = false;

	if (resourceLock != null)
	{
		wroteStart = true;
		generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
		resourceLock.toXML(generatedXML);
	}

	while (collectionLocksList.hasMoreElements())
	{
		LockInfo currentLock = (LockInfo) collectionLocksList.nextElement();
		if (path.startsWith(currentLock.path))
		{
			if (!wroteStart)
			{
				wroteStart = true;
				generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
			}
			currentLock.toXML(generatedXML);
		}
	}

	if (wroteStart)
	{
		generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
	}
	else
	{
		return false;
	}

	return true;

}
 
Example #18
Source File: WebdavServlet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Send a multistatus element containing a complete error report to the
 * client.
 *
 * @param req Servlet request
 * @param resp Servlet response
 * @param errorList List of error to be displayed
 * @throws IOException If an IO error occurs
 */
private void sendReport(HttpServletRequest req, HttpServletResponse resp,
                        Hashtable<String,Integer> errorList)
        throws IOException {

    resp.setStatus(WebdavStatus.SC_MULTI_STATUS);

    String absoluteUri = req.getRequestURI();
    String relativePath = getRelativePath(req);

    XMLWriter generatedXML = new XMLWriter();
    generatedXML.writeXMLHeader();

    generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus",
            XMLWriter.OPENING);

    Enumeration<String> pathList = errorList.keys();
    while (pathList.hasMoreElements()) {

        String errorPath = pathList.nextElement();
        int errorCode = errorList.get(errorPath).intValue();

        generatedXML.writeElement("D", "response", XMLWriter.OPENING);

        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
        String toAppend = errorPath.substring(relativePath.length());
        if (!toAppend.startsWith("/"))
            toAppend = "/" + toAppend;
        generatedXML.writeText(absoluteUri + toAppend);
        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
        generatedXML.writeElement("D", "status", XMLWriter.OPENING);
        generatedXML.writeText("HTTP/1.1 " + errorCode + " "
                + WebdavStatus.getStatusText(errorCode));
        generatedXML.writeElement("D", "status", XMLWriter.CLOSING);

        generatedXML.writeElement("D", "response", XMLWriter.CLOSING);

    }

    generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);

    Writer writer = resp.getWriter();
    writer.write(generatedXML.toString());
    writer.close();

}
 
Example #19
Source File: DavServlet.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Get an XML representation of this lock token. This method will append an XML fragment to the given XML writer.
 */
public void toXML(XMLWriter generatedXML, boolean showToken)
{

	generatedXML.writeElement("D", "activelock", XMLWriter.OPENING);

	generatedXML.writeElement("D", "locktype", XMLWriter.OPENING);
	generatedXML.writeElement("D", type, XMLWriter.NO_CONTENT);
	generatedXML.writeElement("D", "locktype", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "lockscope", XMLWriter.OPENING);
	generatedXML.writeElement("D", scope, XMLWriter.NO_CONTENT);
	generatedXML.writeElement("D", "lockscope", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "depth", XMLWriter.OPENING);
	if (depth == INFINITY)
	{
		generatedXML.writeText("Infinity");
	}
	else
	{
		generatedXML.writeText("0");
	}
	generatedXML.writeElement("D", "depth", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "owner", XMLWriter.OPENING);
	generatedXML.writeText(owner);
	generatedXML.writeElement("D", "owner", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "timeout", XMLWriter.OPENING);
	long timeout = (expiresAt - System.currentTimeMillis()) / 1000;
	generatedXML.writeText("Second-" + timeout);
	generatedXML.writeElement("D", "timeout", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "locktoken", XMLWriter.OPENING);
	if (showToken)
	{
		Enumeration<String> tokensList = tokens.elements();
		while (tokensList.hasMoreElements())
		{
			generatedXML.writeElement("D", "href", XMLWriter.OPENING);
			generatedXML.writeText("opaquelocktoken:" + tokensList.nextElement());
			generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
		}
	}
	else
	{
		generatedXML.writeElement("D", "href", XMLWriter.OPENING);
		generatedXML.writeText("opaquelocktoken:dummytoken");
		generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
	}
	generatedXML.writeElement("D", "locktoken", XMLWriter.CLOSING);

	generatedXML.writeElement("D", "activelock", XMLWriter.CLOSING);

}