/* * Copyright (C) 2005 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. */ package org.alfresco.repo.webdav; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; import org.alfresco.model.ContentModel; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileNotFoundException; import org.alfresco.service.cmr.repository.CopyService; 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.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.util.EqualsHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.helpers.AttributesImpl; /** * WebDAV Protocol Helper Class * *
Provides helper methods for repository access using the WebDAV protocol.
*
* @author GKSpencer
*/
public class WebDAVHelper
{
// Constants
// Path seperator
public static final String PathSeperator = "/";
public static final char PathSeperatorChar = '/';
// Logging
private static Log logger = LogFactory.getLog("org.alfresco.protocol.webdav");
// Service registry
private ServiceRegistry m_serviceRegistry;
// Services
private NodeService m_nodeService;
private FileFolderService m_fileFolderService;
private SearchService m_searchService;
private NamespaceService m_namespaceService;
private DictionaryService m_dictionaryService;
private MimetypeService m_mimetypeService;
private LockService m_lockService;
private AuthenticationService m_authService;
// Empty XML attribute list
private AttributesImpl m_nullAttribs = new AttributesImpl();
/**
* Class constructor
*
* @param serviceRegistry ServiceRegistry
* @param authService AuthenticationService
*/
protected WebDAVHelper(ServiceRegistry serviceRegistry, AuthenticationService authService)
{
m_serviceRegistry = serviceRegistry;
m_nodeService = m_serviceRegistry.getNodeService();
m_fileFolderService = m_serviceRegistry.getFileFolderService();
m_searchService = m_serviceRegistry.getSearchService();
m_namespaceService = m_serviceRegistry.getNamespaceService();
m_dictionaryService = m_serviceRegistry.getDictionaryService();
m_mimetypeService = m_serviceRegistry.getMimetypeService();
m_lockService = m_serviceRegistry.getLockService();
m_authService = authService;
}
/**
* Return the authentication service
*
* @return AuthenticationService
*/
public final AuthenticationService getAuthenticationService()
{
return m_authService;
}
/**
* Return the service registry
*
* @return ServiceRegistry
*/
public final ServiceRegistry getServiceRegistry()
{
return m_serviceRegistry;
}
/**
* Return the node service
*
* @return NodeService
*/
public final NodeService getNodeService()
{
return m_nodeService;
}
public FileFolderService getFileFolderService()
{
return m_fileFolderService;
}
/**
* Return the search service
*
* @return SearchService
*/
public final SearchService getSearchService()
{
return m_searchService;
}
/**
* Return the namespace service
*
* @return NamespaceService
*/
public final NamespaceService getNamespaceService()
{
return m_namespaceService;
}
/**
* Return the dictionary service
*
* @return DictionaryService
*/
public final DictionaryService getDictionaryService()
{
return m_dictionaryService;
}
/**
* Return the mimetype service
*
* @return MimetypeService
*/
public final MimetypeService getMimetypeService()
{
return m_mimetypeService;
}
/**
* Return the lock service
*
* @return LockService
*/
public final LockService getLockService()
{
return m_lockService;
}
/**
* Return the copy service
*
* @return CopyService
*/
public final CopyService getCopyService()
{
return getServiceRegistry().getCopyService();
}
/**
* Split the path into seperate directory path and file name strings.
* If the path is not empty, then there will always be an entry for the filename
*
* @param path Full path string.
* @return Returns a String[2] with the folder path and file path.
*/
public final String[] splitPath(String path)
{
if (path == null)
throw new IllegalArgumentException("path may not be null");
// Create an array of strings to hold the path and file name strings
String[] pathStr = new String[] {"", ""};
// Check if the path has a trailing seperator, if so then there is no file name.
int pos = path.lastIndexOf(PathSeperatorChar);
if (pos == -1 || pos == (path.length() - 1))
{
// Set the path string in the returned string array
pathStr[1] = path;
}
else
{
pathStr[0] = path.substring(0, pos);
pathStr[1] = path.substring(pos + 1);
}
// Return the path strings
return pathStr;
}
/**
* Split the path into all the component directories and filename
*
* @param path String
* @return String[]
*/
public final List