public class WebdavServlet
extends DefaultServlet {
+ private static final long serialVersionUID = 1L;
- // -------------------------------------------------------------- Constants
+ // -------------------------------------------------------------- Constants
private static final String METHOD_PROPFIND = "PROPFIND";
private static final String METHOD_PROPPATCH = "PROPPATCH";
if (type == FIND_BY_PROPERTY) {
properties = new Vector<String>();
+ // propNode must be non-null if type == FIND_BY_PROPERTY
+ @SuppressWarnings("null")
NodeList childList = propNode.getChildNodes();
for (int i=0; i < childList.getLength(); i++) {
/**
* PROPPATCH Method.
*/
- protected void doProppatch(HttpServletRequest req,
- HttpServletResponse resp)
- throws ServletException, IOException {
+ protected void doProppatch(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException {
if (readOnly) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
* COPY Method.
*/
protected void doCopy(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ throws IOException {
if (readOnly) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
* MOVE Method.
*/
protected void doMove(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ throws IOException {
if (readOnly) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
LockInfo toRenew = resourceLocks.get(path);
Enumeration<String> tokenList = null;
- if (lock != null) {
- // At least one of the tokens of the locks must have been given
-
- tokenList = toRenew.tokens.elements();
- while (tokenList.hasMoreElements()) {
- String token = tokenList.nextElement();
- if (ifHeader.indexOf(token) != -1) {
- toRenew.expiresAt = lock.expiresAt;
- lock = toRenew;
- }
+ // At least one of the tokens of the locks must have been given
+ tokenList = toRenew.tokens.elements();
+ while (tokenList.hasMoreElements()) {
+ String token = tokenList.nextElement();
+ if (ifHeader.indexOf(token) != -1) {
+ toRenew.expiresAt = lock.expiresAt;
+ lock = toRenew;
}
-
}
// Checking inheritable collection locks
* UNLOCK Method.
*/
protected void doUnlock(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ throws IOException {
if (readOnly) {
resp.sendError(WebdavStatus.SC_FORBIDDEN);
*/
private boolean copyResource(HttpServletRequest req,
HttpServletResponse resp)
- throws ServletException, IOException {
+ throws IOException {
// Parsing destination header
/**
* Copy a collection.
*
- * @param resources Resources implementation to be used
+ * @param dirContext Resources implementation to be used
* @param errorList Hashtable containing the list of errors which occurred
* during the copy operation
* @param source Path of the resource to be copied
* @param dest Destination path
*/
- private boolean copyResource(DirContext resources,
+ private boolean copyResource(DirContext dirContext,
Hashtable<String,Integer> errorList, String source, String dest) {
if (debug > 1)
Object object = null;
try {
- object = resources.lookup(source);
+ object = dirContext.lookup(source);
} catch (NamingException e) {
// Ignore
}
if (object instanceof DirContext) {
try {
- resources.createSubcontext(dest);
+ dirContext.createSubcontext(dest);
} catch (NamingException e) {
errorList.put
(dest, new Integer(WebdavStatus.SC_CONFLICT));
try {
NamingEnumeration<NameClassPair> enumeration =
- resources.list(source);
+ dirContext.list(source);
while (enumeration.hasMoreElements()) {
NameClassPair ncPair = enumeration.nextElement();
String childDest = dest;
if (!childSrc.equals("/"))
childSrc += "/";
childSrc += ncPair.getName();
- copyResource(resources, errorList, childSrc, childDest);
+ copyResource(dirContext, errorList, childSrc, childDest);
}
} catch (NamingException e) {
errorList.put
if (object instanceof Resource) {
try {
- resources.bind(dest, object);
+ dirContext.bind(dest, object);
} catch (NamingException e) {
if (e.getCause() instanceof FileNotFoundException) {
// We know the source exists so it must be the
*/
private boolean deleteResource(HttpServletRequest req,
HttpServletResponse resp)
- throws ServletException, IOException {
+ throws IOException {
String path = getRelativePath(req);
*/
private boolean deleteResource(String path, HttpServletRequest req,
HttpServletResponse resp, boolean setStatus)
- throws ServletException, IOException {
+ throws IOException {
if ((path.toUpperCase().startsWith("/WEB-INF")) ||
(path.toUpperCase().startsWith("/META-INF"))) {
/**
* Deletes a collection.
*
- * @param resources Resources implementation associated with the context
+ * @param dirContext Resources implementation associated with the context
* @param path Path to the collection to be deleted
* @param errorList Contains the list of the errors which occurred
*/
private void deleteCollection(HttpServletRequest req,
- DirContext resources,
+ DirContext dirContext,
String path,
Hashtable<String,Integer> errorList) {
Enumeration<NameClassPair> enumeration = null;
try {
- enumeration = resources.list(path);
+ enumeration = dirContext.list(path);
} catch (NamingException e) {
errorList.put(path, new Integer
(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
} else {
try {
- Object object = resources.lookup(childName);
+ Object object = dirContext.lookup(childName);
if (object instanceof DirContext) {
- deleteCollection(req, resources, childName, errorList);
+ deleteCollection(req, dirContext, childName, errorList);
}
try {
- resources.unbind(childName);
+ dirContext.unbind(childName);
} catch (NamingException e) {
if (!(object instanceof DirContext)) {
// If it's not a collection, then it's an unknown
*/
private void sendReport(HttpServletRequest req, HttpServletResponse resp,
Hashtable<String,Integer> errorList)
- throws ServletException, IOException {
+ throws IOException {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
* Determines the methods normally allowed for the resource.
*
*/
- private StringBuilder determineMethodsAllowed(DirContext resources,
+ private StringBuilder determineMethodsAllowed(DirContext dirContext,
HttpServletRequest req) {
StringBuilder methodsAllowed = new StringBuilder();
try {
String path = getRelativePath(req);
- object = resources.lookup(path);
+ object = dirContext.lookup(path);
} catch (NamingException e) {
exists = false;
}