/*
 * C5Connector.Java - The Java backend for the filemanager of corefive.
 * It's a bridge between the filemanager and a storage backend and 
 * works like a transparent VFS or proxy.
 * Copyright (C) Thilo Schwarz
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.thischwa.c5c.requestcycle.impl;

import javax.servlet.ServletContext;

import de.thischwa.c5c.Constants;
import de.thischwa.c5c.requestcycle.Context;
import de.thischwa.c5c.requestcycle.BackendPathBuilder;

/**
 * An implementation of the {@link BackendPathBuilder} that returns the {@link ServletContext#getRealPath(String)}.
 */
public class ServerPathBuilder implements BackendPathBuilder {

	@Override
	public String getBackendPath(String urlPath, Context context, ServletContext servletContext) {
		String storagePath = servletContext.getRealPath(urlPath);
		if(urlPath.endsWith(Constants.defaultSeparator) && !storagePath.endsWith(Constants.defaultSeparator))
			storagePath += Constants.defaultSeparator;
		return storagePath;
	}

}

@@ -635,16 +635,57 @@
 Builder;
+%0Aimport de.thischwa.c5c.util.StringUtils;
 %0A%0A/**%0A *
@@ -798,16 +798,113 @@
 ring)%7D.%0A
+ * But it will be respected, if the servlet is running in a context other than the root context.%0A
  */%0Apubl
@@ -1070,16 +1070,355 @@
 text) %7B%0A
+%09%09String requestedPath = urlPath;%0A%09%09%0A%09%09// check if the servlet runs in not in the root-context and adjust the url-path%0A%09%09String ctxPath = servletContext.getContextPath();%0A%09%09if(!StringUtils.isNullOrEmpty(ctxPath) && requestedPath.startsWith(ctxPath))%0A%09%09%09requestedPath = requestedPath.substring(ctxPath.length(), requestedPath.length());%0A%09%09%0A
 %09%09String
@@ -1459,19 +1459,25 @@
 ealPath(
-url
+requested
 Path);%0A%09
@@ -1480,19 +1480,25 @@
 );%0A%09%09if(
-url
+requested
 Path.end

fix for contexts other than the root one