"Another part of cleaning up dispatcher code and enable installation of CCM into any arbitrary application context."

git-svn-id: https://svn.libreccm.org/ccm/trunk@2560 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2014-03-07 08:20:15 +00:00
parent b396010920
commit cfc3064fc6
10 changed files with 310 additions and 234 deletions

View File

@ -31,6 +31,7 @@ import com.arsdigita.categorization.Category;
*/ */
public class DublinCoreRelatedItemsQueryFactoryImpl extends RelatedItemsQueryFactory { public class DublinCoreRelatedItemsQueryFactoryImpl extends RelatedItemsQueryFactory {
@Override
public RelatedItemsQuery getRelatedItems(ContentPage page, public RelatedItemsQuery getRelatedItems(ContentPage page,
Category current) { Category current) {

View File

@ -66,7 +66,10 @@ import org.apache.log4j.Logger;
*/ */
public class Application extends Resource { public class Application extends Resource {
/** Logger instance for debugging. */ /** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.web.Application=DEBUG by uncommenting
* or adding the line. */
private static final Logger s_log = Logger.getLogger(Application.class); private static final Logger s_log = Logger.getLogger(Application.class);
/** PDL property, basic object type for all applications of this type */ /** PDL property, basic object type for all applications of this type */
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
@ -488,8 +491,8 @@ public class Application extends Resource {
* @return Path string including w/o static prefix (if configured) * @return Path string including w/o static prefix (if configured)
*/ */
public final String getPath() { public final String getPath() {
final String path = (String) get(PRIMARY_URL);
final String path = (String) get(PRIMARY_URL);
Assert.exists(path, String.class); Assert.exists(path, String.class);
if (path.endsWith(SLASH)) { if (path.endsWith(SLASH)) {

View File

@ -91,8 +91,9 @@ public class CCMDispatcherServlet extends BaseServlet {
/** Internal logger instance to faciliate debugging. Enable logging output /** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment * by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.web.CCMDispatcherServlet=DEBUG by uncommenting * and set com.arsdigita.web.CCMDispatcherServlet=DEBUG by uncommenting
* or adding the line. */ * or adding the line. */
private static final Logger s_log = Logger.getLogger(CCMDispatcherServlet.class); private static final Logger s_log = Logger.getLogger(
CCMDispatcherServlet.class);
static final String DISPATCHED_ATTRIBUTE = static final String DISPATCHED_ATTRIBUTE =
CCMDispatcherServlet.class.getName() + ".dispatched"; CCMDispatcherServlet.class.getName() + ".dispatched";
@ -123,8 +124,8 @@ public class CCMDispatcherServlet extends BaseServlet {
s_contextPath = servletContext.getContextPath(); s_contextPath = servletContext.getContextPath();
// For backwords compatibility reasons register the web application // For backwords compatibility reasons register the web application
// context of the Core (root) application als "/" // context of the Core (root) application als "/"
Web.registerServletContext("/", // Web.registerServletContext("/",
servletContext); // servletContext);
} }
@ -279,14 +280,16 @@ public class CCMDispatcherServlet extends BaseServlet {
s_log.debug("Forwarding by path to target '" + target + "'"); s_log.debug("Forwarding by path to target '" + target + "'");
} }
s_log.debug("The context path is: " + contextPath); s_log.debug("The context path is: " + contextPath);
if (StringUtils.emptyString(contextPath)) { if (StringUtils.emptyString(contextPath)) { // not compliant with JEE
contextPath = "/"; contextPath = "/"; // Empty context has to be
} } // "" !
if (!contextPath.endsWith("/")) { if (!contextPath.endsWith("/")) { // No trailing slash
contextPath = contextPath + "/"; contextPath = contextPath + "/"; // according to JEE
} }
// XXX We should pass servlet context down // XXX We should pass servlet context down
final ServletContext context = Web.getServletContext(contextPath); // final ServletContext context = Web.getServletContext(contextPath);
final ServletContext context = Web.getServletContext()
.getContext(contextPath);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("From context " + Web.getServletContext() + s_log.debug("From context " + Web.getServletContext() +

View File

@ -24,6 +24,14 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
// This class uses a non-standard way to construct a kind of repository of
// webapp contexts various applications of CCM used to be installed up to
// version 1.0.4
// With version 2.0 all modules of CCM are installed into one directory
// (context) and this servlet is nolonger used (and will be removed soon).
/** /**
* <p> * <p>
Every application running in its own webapp should Every application running in its own webapp should
@ -77,12 +85,12 @@ public class ContextRegistrationServlet extends HttpServlet {
* getServletContext is retrieved by the ContextRegistrationServlet * getServletContext is retrieved by the ContextRegistrationServlet
* loaded first it is not affected by the bug. * loaded first it is not affected by the bug.
*/ */
Web.registerServletContext(m_uri, // Web.registerServletContext(m_uri,
sconfig.getServletContext()); // sconfig.getServletContext());
} }
@Override @Override
public void destroy() { public void destroy() {
Web.unregisterServletContext(m_uri); // Web.unregisterServletContext(m_uri);
} }
} }

View File

@ -27,13 +27,17 @@ import org.apache.log4j.Logger;
public class DefaultApplicationFileResolver implements ApplicationFileResolver { public class DefaultApplicationFileResolver implements ApplicationFileResolver {
/** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.web.DefaultApplicationFileResolver=DEBUG by
* uncommenting or adding the line. */
private static Logger s_log =
Logger.getLogger(DefaultApplicationFileResolver.class);
private static final String[] WELCOME_FILES = new String[] { private static final String[] WELCOME_FILES = new String[] {
"index.jsp", "index.html" "index.jsp", "index.html"
}; };
private static Logger s_log =
Logger.getLogger(DefaultApplicationFileResolver.class);
/** /**
* *
* @param templatePath * @param templatePath
@ -47,10 +51,8 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
HttpServletRequest sreq, HttpServletRequest sreq,
HttpServletResponse sresp, HttpServletResponse sresp,
Application app) { Application app) {
// XXX proper list of dependent & customization webapps to search
String[] webapps = new String[] { String contextPath = app.getContextPath();
app.getContextPath(), "ROOT"
};
String pathInfo = sreq.getPathInfo(); String pathInfo = sreq.getPathInfo();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
@ -70,8 +72,8 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
} }
RequestDispatcher rd = Web.findResourceDispatcher( RequestDispatcher rd = Web.findResourceDispatcher(
webapps, contextPath + path
path + WELCOME_FILES[i]); + WELCOME_FILES[i]);
if (rd != null) { if (rd != null) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Got dispatcher " + rd); s_log.debug("Got dispatcher " + rd);
@ -85,8 +87,7 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
} }
RequestDispatcher rd = Web.findResourceDispatcher( RequestDispatcher rd = Web.findResourceDispatcher(
webapps, contextPath + path);
path);
if (rd != null) { if (rd != null) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Got dispatcher " + rd); s_log.debug("Got dispatcher " + rd);

View File

@ -63,13 +63,20 @@ public class Web {
static final WebContext s_initialContext = new WebContext(); static final WebContext s_initialContext = new WebContext();
/** Internal service property to temporarly save the ServletContext as
* determined by findResource(resource) method to make it available to
* those methods of this class which use findResource to lookup a
* resource as a base for determining additional information, e.g.
* provide a dispatcher (findResourceDispatcher) */
static private ServletContext s_urlContext;
/** String containing the webapp context path portion of the WEB application /** String containing the webapp context path portion of the WEB application
* where this CCM instance is executed. (I.e. where the WEB-INF directory * where this CCM instance is executed. (I.e. where the WEB-INF directory
* is located in the servlet container webapps directory. */ * is located in the servlet container webapps directory). */
private static String s_contextPath; private static String s_contextPath;
/** /**
* * Static Initializer block.
*/ */
static void init(final HttpServletRequest sreq, static void init(final HttpServletRequest sreq,
final ServletContext sc, final ServletContext sc,
@ -160,7 +167,7 @@ public class Web {
* @return The current <code>UserContext</code> object; it can be * @return The current <code>UserContext</code> object; it can be
* null * null
*/ */
public static final UserContext getUserContext() { public static UserContext getUserContext() {
return (UserContext) s_userContext.get(); return (UserContext) s_userContext.get();
} }
@ -174,7 +181,7 @@ public class Web {
* @param resource Path to the resource as String. It may include the * @param resource Path to the resource as String. It may include the
* web context in its first part or may be relative to the * web context in its first part or may be relative to the
* current webapp document root (i.e. its context). * current webapp document root (i.e. its context).
* Additionally, it the web application component (if any) * Additionally, the web application component (if any)
* may be a comma separate list of webapps to search for the * may be a comma separate list of webapps to search for the
* rest of the path String. * rest of the path String.
* So, if the 'resource' is: * So, if the 'resource' is:
@ -230,6 +237,8 @@ public class Web {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Cannot get resource for " + resource); s_log.debug("Cannot get resource for " + resource);
} }
// Try the first part of resource as a webapp context path and
// check far a resource there
int offset = resource.indexOf("/", 1); // search for second "/" int offset = resource.indexOf("/", 1); // search for second "/"
String testPath = resource.substring(1, offset); String testPath = resource.substring(1, offset);
String path = resource.substring(offset); String path = resource.substring(offset);
@ -237,12 +246,15 @@ public class Web {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Try to find a context at " + testPath); s_log.debug("Try to find a context at " + testPath);
} }
// Try to achieve a context
ServletContext ctx = myctx.getContext(testPath); ServletContext ctx = myctx.getContext(testPath);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Servlet context for " + testPath + s_log.debug("Servlet context for " + testPath +
" is " + ctx); " is " + ctx);
} }
if (ctx != null) { if (ctx != null) {
// successs, try to finf a resource for the remaining
// string as path
try { try {
URL url = ctx.getResource(path); URL url = ctx.getResource(path);
if (url != null) { if (url != null) {
@ -351,22 +363,53 @@ public class Web {
} }
/** /**
* Follows the same rules as findResource(String), but * Follows the same rules as findResource(String), but instead returns a
* instead returns a request dispatcher for serving * request dispatcher for serving the resource
* the resource *
* @param resource Path to the resource as String. It may include the
* web context in its first part or may be relative to the
* current webapp document root (i.e. its context).
* Additionally, it the web application component (if any)
* may be a comma separate list of webapps to search for the
* rest of the path String.
* So, if the 'resource' is:
* <pre>
* /myproj,ccm-cms/themes/heirloom/admin/index.xsl
* </pre>
* then this method will look for resources at
* <pre>
* /myproj/themes/heirloom/admin/index.xsl
* /ccm-cms/themes/heirloom/admin/index.xsl
* </pre>
* *
* @param resource the resource name
* @return the request dispatcher for the resource, or null * @return the request dispatcher for the resource, or null
*/ */
public static RequestDispatcher findResourceDispatcher(String resource) { public static RequestDispatcher findResourceDispatcher(String resource) {
ResourceSpec spec = parseResource(resource); URL url = findResource(resource);
ServletContext ctx = s_urlContext;
String path = url.toString();
return findResourceDispatcher(spec.getWebapps(), return ctx == null ? null : ctx.getRequestDispatcher(path);
spec.getPath());
} }
/**
*
*/
private static class WebContextLocal extends InternalRequestLocal {
@Override
protected Object initialValue() {
return Web.s_initialContext.copy();
}
@Override
protected void clearValue() {
((WebContext) get()).clear();
}
}
// /////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////
// //
@ -392,7 +435,7 @@ public class Web {
* *
* @deprecated without direct replacement. See above * @deprecated without direct replacement. See above
*/ */
private static final String ROOT_WEBAPP = "ROOT"; // private static final String ROOT_WEBAPP = "ROOT";
/** Map containing a list of registered ccm webapps and corresponding /** Map containing a list of registered ccm webapps and corresponding
@ -400,7 +443,7 @@ public class Web {
* *
* @deprecated without direct replacement, see above. * @deprecated without direct replacement, see above.
*/ */
private static final Map s_contexts = new HashMap(); // private static final Map s_contexts = new HashMap();
/** /**
@ -428,36 +471,36 @@ public class Web {
* web application context. * web application context.
* *
*/ */
public static ServletContext getServletContext(String uri) { // public static ServletContext getServletContext(String uri) {
Assert.isTrue(uri.startsWith("/"), "uri must start with /"); // Assert.isTrue(uri.startsWith("/"), "uri must start with /");
Assert.isTrue(uri.endsWith("/"), "uri must end with /"); // Assert.isTrue(uri.endsWith("/"), "uri must end with /");
return (ServletContext)s_contexts.get(uri); // return (ServletContext)s_contexts.get(uri);
} // }
/** /**
* Registers a servlet context against a URI. Only intended * Registers a servlet context against a URI. Only intended
* to be used by ContextRegistrationServlet * to be used by ContextRegistrationServlet
* @deprecated without direct replacement. See getServletContext * @deprecated without direct replacement. See getServletContext
*/ */
static final void registerServletContext(String uri, // static final void registerServletContext(String uri,
ServletContext ctx) { // ServletContext ctx) {
s_log.debug("Mapping " + ctx + " to " + uri); // s_log.debug("Mapping " + ctx + " to " + uri);
Assert.isTrue(s_contexts.get(uri) == null, // Assert.isTrue(s_contexts.get(uri) == null,
"a context mapping exists at " + uri); // "a context mapping exists at " + uri);
// Save the web context as manually configured in web.xml // // Save the web context as manually configured in web.xml
// along with the context as provided by ServletContext. // // along with the context as provided by ServletContext.
s_contexts.put(uri, ctx); // s_contexts.put(uri, ctx);
} // }
/** /**
* Unregisters the servlet context against a URI. Only intended * Unregisters the servlet context against a URI. Only intended
* to be used by ContextRegistrationServlet * to be used by ContextRegistrationServlet
* @deprecated without direct replacement. See getServletContext * @deprecated without direct replacement. See getServletContext
*/ */
static final void unregisterServletContext(String uri) { // static final void unregisterServletContext(String uri) {
s_log.debug("Unmapping " + uri); // s_log.debug("Unmapping " + uri);
s_contexts.remove(uri); // s_contexts.remove(uri);
} // }
/** /**
@ -476,24 +519,24 @@ public class Web {
* @return the URL for the resource, or null * @return the URL for the resource, or null
* @deprecated without direct replacement at the moment. * @deprecated without direct replacement at the moment.
*/ */
public static URL findResource(String[] webapps, // public static URL findResource(String[] webapps,
String path) { // String path) {
//
ServletContext ctx = findResourceContext(webapps, // ServletContext ctx = findResourceContext(webapps,
path); // path);
//
URL url = null; // URL url = null;
try { // try {
url = (ctx == null ? null : // url = (ctx == null ? null :
ctx.getResource(path)); // ctx.getResource(path));
} catch (IOException ex) { // } catch (IOException ex) {
throw new UncheckedWrapperException("cannot get URL for " + path, ex); // throw new UncheckedWrapperException("cannot get URL for " + path, ex);
} // }
if (s_log.isDebugEnabled()) { // if (s_log.isDebugEnabled()) {
s_log.debug("URL for " + path + " is " + url); // s_log.debug("URL for " + path + " is " + url);
} // }
return url; // return url;
} // }
/** /**
@ -548,23 +591,23 @@ public class Web {
// spec.getPath()); // spec.getPath());
// } // }
/** // /**
* Follows the same rules as findResource(String[], String), but // * Follows the same rules as findResource(String[], String), but
* instead returns a request dispatcher for serving // * instead returns a request dispatcher for serving
* the resource // * the resource
* // *
* @param webapps the list of webapps // * @param webapps the list of webapps
* @param path the resource path // * @param path the resource path
* @return the request dispatcher for the resource, or null // * @return the request dispatcher for the resource, or null
* @deprecated without direct replacement at the moment. // * @deprecated without direct replacement at the moment.
*/ // */
public static RequestDispatcher findResourceDispatcher(String[] webapps, // public static RequestDispatcher findResourceDispatcher(String[] webapps,
String path) { // String path) {
ServletContext ctx = findResourceContext(webapps, // ServletContext ctx = findResourceContext(webapps,
path); // path);
//
return ctx == null ? null : ctx.getRequestDispatcher(path); // return ctx == null ? null : ctx.getRequestDispatcher(path);
} // }
/** /**
@ -577,50 +620,49 @@ public class Web {
* @return * @return
* @deprecated without direct replacement at the moment. * @deprecated without direct replacement at the moment.
*/ */
private static ServletContext findResourceContext(String[] webapps, // private static ServletContext findResourceContext(String[] webapps,
String path) { // String path) {
for (int i = (webapps.length - 1) ; i >= 0 ; i--) { // for (int i = (webapps.length - 1) ; i >= 0 ; i--) {
// // trash here, depends of a kind of "home made" list of
// trash here, depends of a kind of "home made" list of // // webapps/webcontexts (or ServletContexts) which are part of CCM
// webapps/webcontexts (or ServletContexts) which are part of CCM // // but installed in its own context (it is the structure of APLAWS
// but installed in its own context (it is the structure of APLAWS // // until 1.0.4.
// until 1.0.4. // String ctxPath = ROOT_WEBAPP.equals(webapps[i]) ?
String ctxPath = ROOT_WEBAPP.equals(webapps[i]) ? // "" : webapps[i];
"" : webapps[i]; //
// if (!ctxPath.startsWith("/")) {
if (!ctxPath.startsWith("/")) { // ctxPath = "/" + ctxPath;
ctxPath = "/" + ctxPath; // }
} // if (!ctxPath.endsWith("/")) {
if (!ctxPath.endsWith("/")) { // ctxPath = ctxPath + "/";
ctxPath = ctxPath + "/"; // }
} //
// ServletContext ctx = getServletContext(ctxPath);
ServletContext ctx = getServletContext(ctxPath); // if (s_log.isDebugEnabled()) {
if (s_log.isDebugEnabled()) { // s_log.debug("Servlet context for " + ctxPath + " is " + ctx);
s_log.debug("Servlet context for " + ctxPath + " is " + ctx); // }
} //
// if (ctx != null) {
if (ctx != null) { // try {
try { // URL url = ctx.getResource(path);
URL url = ctx.getResource(path); // if (url != null) {
if (url != null) { // if (s_log.isDebugEnabled()) {
if (s_log.isDebugEnabled()) { // s_log.debug("Got URL " + url + " for " + path);
s_log.debug("Got URL " + url + " for " + path); // }
} // return ctx;
return ctx; // } else {
} else { // if (s_log.isDebugEnabled()) {
if (s_log.isDebugEnabled()) { // s_log.debug("No URL present for " + path);
s_log.debug("No URL present for " + path); // }
} // }
} // } catch (IOException ex) {
} catch (IOException ex) { // throw new UncheckedWrapperException(
throw new UncheckedWrapperException( // "cannot get resource " + path, ex);
"cannot get resource " + path, ex); // }
} // }
} // }
} // return null;
return null; // }
}
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
@ -648,76 +690,59 @@ public class Web {
* @return * @return
* @deprecated without direct replacement. * @deprecated without direct replacement.
*/ */
private static ResourceSpec parseResource(String resource) { // private static ResourceSpec parseResource(String resource) {
// if (resource == null || resource.length() < 2) {
if (resource == null || resource.length() < 2) { // throw new IllegalArgumentException(
throw new IllegalArgumentException( // "Resource spec is too short: " + resource);
"Resource spec is too short: " + resource); // }
} //
// int offset = resource.indexOf("/", 1);
int offset = resource.indexOf("/", 1); // if (offset == -1) {
if (offset == -1) { // throw new IllegalArgumentException(
throw new IllegalArgumentException( // "Cannot find second '/' in resource spec : " + resource);
"Cannot find second '/' in resource spec : " + resource); // }
} //
// String webappList = resource.substring(1, offset);
String webappList = resource.substring(1, offset); // String path = resource.substring(offset);
String path = resource.substring(offset); //
// String[] webapps = StringUtils.split(webappList, ',');
String[] webapps = StringUtils.split(webappList, ','); //
// if (s_log.isInfoEnabled()) {
if (s_log.isInfoEnabled()) { // s_log.info("Web app list " + webappList + " path " + path);
s_log.info("Web app list " + webappList + " path " + path); // }
} //
// return new ResourceSpec(webapps, path);
return new ResourceSpec(webapps, path); // }
} //
//
// /**
/** // * Container to hold a pointer to a resource. The pointer specifically
* Container to hold a pointer to a resource. The pointer specifically // * consists of an array of webapps probably containing the requested
* consists of an array of webapps probably containing the requested // * resource and a path to that resource that has to be equal for each
* resource and a path to that resource that has to be equal for each // * webapp.
* webapp. // * @deprecated without direct replacement at the moment.
* @deprecated without direct replacement at the moment. // */
*/ // private static class ResourceSpec {
private static class ResourceSpec { // private final String[] m_webapps;
private final String[] m_webapps; // private final String m_path;
private final String m_path; //
// /**
/** // * Constructor.
* Constructor. // * @param webapps
* @param webapps // * @param path
* @param path // */
*/ // public ResourceSpec(String[] webapps,
public ResourceSpec(String[] webapps, // String path) {
String path) { // m_webapps = webapps;
m_webapps = webapps; // m_path = path;
m_path = path; // }
} //
// public String[] getWebapps() {
public String[] getWebapps() { // return m_webapps;
return m_webapps; // }
} //
// public String getPath() {
public String getPath() { // return m_path;
return m_path; // }
} // }
}
/**
*
*/
private static class WebContextLocal extends InternalRequestLocal {
@Override
protected Object initialValue() {
return Web.s_initialContext.copy();
}
@Override
protected void clearValue() {
((WebContext) get()).clear();
}
}
} }

View File

@ -122,10 +122,11 @@ public class Navigation extends Application {
}); });
/* Create Instance beyond root (4. parameter null) */ /* Create Instance beyond root (4. parameter null) */
final Application application = Application.createApplication(Navigation.BASE_DATA_OBJECT_TYPE, final Application application = Application.createApplication(
navUrl, Navigation.BASE_DATA_OBJECT_TYPE,
navTitle, navUrl,
null); navTitle,
null);
application.setDescription(description); application.setDescription(description);
application.save(); application.save();
final Domain termDomain = Domain.retrieve(defaultDomain); final Domain termDomain = Domain.retrieve(defaultDomain);
@ -134,7 +135,8 @@ public class Navigation extends Application {
} }
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.navigation.Navigation"; public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.navigation.Navigation";
public Navigation(final DataObject obj) { public Navigation(final DataObject obj) {
super(obj); super(obj);
@ -144,6 +146,9 @@ public class Navigation extends Application {
super(oid); super(oid);
} }
// All modules are now installed into one context (may be ROOT or any other
// one
/* /*
public String getContextPath() { public String getContextPath() {
return "ccm-navigation"; return "ccm-navigation";

View File

@ -65,6 +65,7 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
HttpServletRequest sreq, HttpServletRequest sreq,
HttpServletResponse sresp, HttpServletResponse sresp,
Application app) { Application app) {
String path = sreq.getPathInfo(); String path = sreq.getPathInfo();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolving " + path); s_log.debug("Resolving " + path);
@ -194,17 +195,20 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
*/ */
private void setPathCookie(HttpServletResponse resp, Category[] catsArray) { private void setPathCookie(HttpServletResponse resp, Category[] catsArray) {
// 1st part of cookie value is website - if cookie domain covers several Aplaws sites, // 1st part of cookie value is website - if cookie domain covers several
// and the navigation model retains the cookie for more than one request, // Aplaws sites, and the navigation model retains the cookie for more
// we could potentially link to one site with a path relating to another site. A check on this part // than one request, we could potentially link to one site with a path
// of the cookie will prevent problems // relating to another site. A check on this part of the cookie will
// prevent problems
StringBuffer path = new StringBuffer(Web.getConfig().getSiteName()); StringBuffer path = new StringBuffer(Web.getConfig().getSiteName());
// 2nd part of cookie value is the application that set it. Again may be used if a navigation model // 2nd part of cookie value is the application that set it. Again may
// retains the cookie. If we link to another application, it's navigation model may // be used if a navigation model retains the cookie. If we link to
// use this when deciding whether to trust the given path // another application, it's navigation model may use this when
// deciding whether to trust the given path.
path.append(PATH_COOKIE_SEPARATOR + Kernel.getContext().getResource().getID().toString()); path.append(PATH_COOKIE_SEPARATOR +
Kernel.getContext().getResource().getID().toString());
for (int i = 0; i < catsArray.length; i++) { for (int i = 0; i < catsArray.length; i++) {
Category cat = catsArray[i]; Category cat = catsArray[i];
path.append(PATH_COOKIE_SEPARATOR + cat.getID().toString()); path.append(PATH_COOKIE_SEPARATOR + cat.getID().toString());
@ -235,6 +239,12 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
} }
} }
/**
*
* @param cat
* @param useContext
* @return
*/
private RequestDispatcher resolveTemplate(Category cat, String useContext) { private RequestDispatcher resolveTemplate(Category cat, String useContext) {
Template template = null; Template template = null;
if (Navigation.getConfig().inheritTemplates()) { if (Navigation.getConfig().inheritTemplates()) {
@ -248,7 +258,8 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
} }
// If there's an explicit use context which doesn't exist, give a 404 // If there's an explicit use context which doesn't exist, give a 404
if (!Template.DEFAULT_USE_CONTEXT.equals(useContext) && null == template) { if (!Template.DEFAULT_USE_CONTEXT.equals(useContext) && null == template) {
s_log.debug("No template found in context " + getTemplateContext() + " for category " + cat.getID() s_log.debug("No template found in context " + getTemplateContext() +
" for category " + cat.getID()
+ " with use context " + useContext); + " with use context " + useContext);
return null; return null;
} }
@ -262,9 +273,14 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
} else { } else {
path = template.getURL(); path = template.getURL();
} }
RequestDispatcher rd = Web.findResourceDispatcher( // Old style, no longer valid. App may be installed into any arbitrary
new String[]{"ROOT"}, // context and by default all modules are installed into one context.
path); // RequestDispatcher rd = Web.findResourceDispatcher(
// new String[]{"ROOT"},
// path);
// new style, will lookup path in the current context (formerly used to
// be ROOT)
RequestDispatcher rd = Web.findResourceDispatcher(path);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Got dispatcher " + rd); s_log.debug("Got dispatcher " + rd);
@ -300,8 +316,9 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
/** /**
* *
* category resolution retained as an instance method to allow it to be overridden. Default functionality contained * category resolution retained as an instance method to allow it to be
* in static resolveCategory method * overridden. Default functionality contained in static resolveCategory
* method.
* *
* @param root * @param root
* @param path * @param path
@ -312,11 +329,13 @@ public class NavigationFileResolver extends DefaultApplicationFileResolver {
} }
/** /**
* Match a URL with the category tree and return the requested category if exists. * Match a URL with the category tree and return the requested category
* if exists.
* *
* Quasimodo: Originally addEqualsFilter has been used to filter the appropriate category directly inside the SQL * Quasimodo: Originally addEqualsFilter has been used to filter the
* query. This is possible anymore due to the localised URLs of the new localised categories (or at least: not found * appropriate category directly inside the SQL query. This isn't possible
* it). Therefore we do the filtering in Java now. * anymore due to the localised URLs of the new localised categories
* (or at least: not found it). Therefore we do the filtering in Java now.
* *
*/ */
public static Category[] resolveCategory(Category root, public static Category[] resolveCategory(Category root,

View File

@ -81,6 +81,7 @@ public class Template extends DomainObject {
/** /**
* *
*/ */
@Override
public void initialize() { public void initialize() {
super.initialize(); super.initialize();

View File

@ -33,6 +33,10 @@ import org.apache.log4j.Logger;
public class RSSFileResolver extends DefaultApplicationFileResolver { public class RSSFileResolver extends DefaultApplicationFileResolver {
/** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.rssfeed.RSSFileResolver=DEBUG by
* uncommenting or adding the line. */
private static final Logger s_log = Logger.getLogger(RSSFileResolver.class); private static final Logger s_log = Logger.getLogger(RSSFileResolver.class);
/** /**
@ -71,9 +75,15 @@ public class RSSFileResolver extends DefaultApplicationFileResolver {
s_log.debug("Trying resource " + path); s_log.debug("Trying resource " + path);
} }
RequestDispatcher rd = Web.findResourceDispatcher( // Old style, no longer valid. All CCM modules are nox installed
webapps, // into one context, treating CCM as one web application in a
path); // servlet conainer
//RequestDispatcher rd = Web.findResourceDispatcher(
// webapps,
// path);
// Looks now for a esource at path in the current context
RequestDispatcher rd = Web.findResourceDispatcher(path);
if (rd != null) { if (rd != null) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Got dispatcher " + rd); s_log.debug("Got dispatcher " + rd);