/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.webdav;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Abstract base class for all the WebDAV method handling classes
*
* @author gavinc
*/
public abstract class WebDAVMethod
{
// Log output
protected static Log logger = LogFactory.getLog("org.alfresco.webdav.protocol");
// Output formatted XML in the response
private static final boolean XMLPrettyPrint = true;
// Servlet request/response
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
// WebDAV helper
protected WebDAVHelper m_davHelper;
// Root node
protected NodeRef m_rootNodeRef;
// Repository path
protected String m_strPath = null;
/**
* Default constructor
*/
public WebDAVMethod()
{
}
/**
* Set the request/response details
*
* @param req HttpServletRequest
* @param resp HttpServletResponse
* @param registry ServiceRegistry
* @param rootNode NodeRef
*/
public void setDetails(HttpServletRequest req, HttpServletResponse resp, WebDAVHelper davHelper, NodeRef rootNode)
{
m_request = req;
m_response = resp;
m_davHelper = davHelper;
m_rootNodeRef = rootNode;
m_strPath = WebDAV.getRepositoryPath(req);
}
/**
* Override and return true if the method is a query method only. The default implementation
* returns false.
*
* @return Returns true if the method transaction may be read-only
*/
protected boolean isReadOnly()
{
return false;
}
/**
* Executes the method, wrapping the call to {@link #executeImpl()} in an appropriate transaction
* and handling the error conditions.
*/
public final void execute() throws WebDAVServerException
{
// Parse the HTTP headers
parseRequestHeaders();
// Parse the HTTP body
parseRequestBody();
RetryingTransactionCallback