Fixed bug in findResource and Dispatcher.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2577 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2014-03-21 00:15:30 +00:00
parent 65b48943e4
commit 9c63398588
11 changed files with 209 additions and 89 deletions

View File

@ -55,7 +55,7 @@ import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.apache.log4j.Level; // import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -126,15 +126,7 @@ public class ContentSection extends Application {
private final static String SECTION_ID = "sectionId"; private final static String SECTION_ID = "sectionId";
private static final CMSConfig s_config = CMSConfig.getInstanceOf(); private static final CMSConfig s_config = CMSConfig.getInstanceOf();
/* DO NOT use CMSConfig constructor to instantiate !
private static final CMSConfig s_config = new CMSConfig();
static {
s_log.debug("Static initializer starting...");
s_config.load();
s_log.debug("Static initializer finished...");
}
*/
// Cached properties // Cached properties
PageResolver m_pageResolver = null; PageResolver m_pageResolver = null;
ItemResolver m_itemResolver = null; ItemResolver m_itemResolver = null;
@ -159,7 +151,7 @@ public class ContentSection extends Application {
/** /**
* Constructor re-creating a content section object from its data object. * Constructor re-creating a content section object from its data object.
* *
* @param oid * @param obj
* @throws DataObjectNotFoundException * @throws DataObjectNotFoundException
*/ */
public ContentSection(DataObject obj) { public ContentSection(DataObject obj) {
@ -170,7 +162,7 @@ public class ContentSection extends Application {
* Constructor re-creating a content section object by retrieving its data * Constructor re-creating a content section object by retrieving its data
* Object by ID * Object by ID
* *
* @param oid * @param id
* @throws DataObjectNotFoundException * @throws DataObjectNotFoundException
*/ */
public ContentSection(BigDecimal id) throws DataObjectNotFoundException { public ContentSection(BigDecimal id) throws DataObjectNotFoundException {
@ -264,8 +256,8 @@ public class ContentSection extends Application {
* This URL includes the webapp context path. * This URL includes the webapp context path.
*/ */
public String getURL() { public String getURL() {
String sURL = null;
String sURL;
//see if there is a request //see if there is a request
final HttpServletRequest sreq = Web.getRequest(); final HttpServletRequest sreq = Web.getRequest();
if (sreq != null) { if (sreq != null) {
@ -1092,9 +1084,11 @@ public class ContentSection extends Application {
* returns it. * returns it.
* *
* @param name Name of the content section * @param name Name of the content section
* @param rootCategory
* @return ContentSection * @return ContentSection
*/ */
public static ContentSection create(final String name, final Category rootCategory) { public static ContentSection create(final String name,
final Category rootCategory) {
Folder folder = createRootFolder(name); Folder folder = createRootFolder(name);
//Category category = createRootCategory(name); //Category category = createRootCategory(name);

View File

@ -88,6 +88,7 @@ import org.apache.log4j.Logger;
* - Refactor content item UI bebop ApplicationPage or PageFactory instead of * - Refactor content item UI bebop ApplicationPage or PageFactory instead of
* legacy infected sitenode / package dispatchers. * legacy infected sitenode / package dispatchers.
*/ */
/** /**
* Content Section's Application Servlet according CCM core web application * Content Section's Application Servlet according CCM core web application
* structure {@see com.arsdigita.web.Application} implements the content * structure {@see com.arsdigita.web.Application} implements the content
@ -106,9 +107,9 @@ public class ContentSectionServlet extends BaseApplicationServlet {
private static final Logger s_log = private static final Logger s_log =
Logger.getLogger(ContentSectionServlet.class); Logger.getLogger(ContentSectionServlet.class);
/** Stringarray of file name patterns for index files. */ /** Stringarray of file name patterns for index files. */
private static final String[] WELCOME_FILES = new String[]{ // private static final String[] WELCOME_FILES = new String[]{
"index.jsp", "index.html" // "index.jsp", "index.html"
}; // };
/** The context (in url) for previewing items */ /** The context (in url) for previewing items */
public static final String PREVIEW = "/preview"; public static final String PREVIEW = "/preview";
/** Template files */ /** Template files */
@ -122,34 +123,40 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public static final String XML_MODE = "xmlMode"; public static final String XML_MODE = "xmlMode";
public static final String MEDIA_TYPE = "templateContext"; public static final String MEDIA_TYPE = "templateContext";
private static final String CACHE_KEY_DELIMITER = "%"; private static final String CACHE_KEY_DELIMITER = "%";
private ContentItemDispatcher m_disp = new ContentItemDispatcher();
private final ContentItemDispatcher m_disp = new ContentItemDispatcher();
public static Map s_itemResolverCache = Collections public static Map s_itemResolverCache = Collections
.synchronizedMap(new HashMap()); .synchronizedMap(new HashMap());
/** cache the content items */
private static Map s_itemURLCacheMap = null; private static Map s_itemURLCacheMap = null;
private static boolean s_cacheItems = true; /** Whether to cache the content items */
private static final boolean s_cacheItems = true;
// NEW STUFF here used to process the pages in this servlet // NEW STUFF here used to process the pages in this servlet
/** URL (pathinfo) -> Page object mapping. Based on it (and the http /** URL (pathinfo) -> Page object mapping. Based on it (and the http
* request url) the doService method selects a page to display */ * request url) the doService method selects a page to display */
private final Map m_pages = new HashMap(); private final Map m_pages = new HashMap();
/** Path to directory containg ccm-cms template (jsp) files */ /** Path to directory containg ccm-cms template (jsp) files */
private String m_templatePath; private String m_templatePath;
// Probably compatibility stuff, based on dispatcher
/** Resolvers to find templages (JSP) and other stuff stored in file system.*/ /** Resolver to actually use to find templates (JSP). JSP may be stored in
* file system or otherwise, depends on resolver. Resolver is retrieved
* from configuration.
* (probably used for other stuff as JSP's as well) */
private ApplicationFileResolver m_resolver; private ApplicationFileResolver m_resolver;
/** /**
* Init method overwrites parents init to pass in optional parameters * Init method overwrites parents init to pass in optional parameters
* {@link com.arsdigita.web.BaseServlet}. * {@link com.arsdigita.web.BaseServlet}.
* If not specified system wide defaults are used. * If not specified system wide defaults are used.
* @param config
* @throws javax.servlet.ServletException
*/ */
@Override @Override
public void init(ServletConfig config) throws ServletException { public void init(ServletConfig config) throws ServletException {
super.init(config); super.init(config);
// optional init-param named template-path from ~/WEB-INF/web.xml // optional init-param named template-path from ~/WEB-INF/web.xml
// may overwrite configuration parameters
String templatePath = config.getInitParameter("template-path"); String templatePath = config.getInitParameter("template-path");
if (templatePath == null) { if (templatePath == null) {
m_templatePath = ContentSection.getConfig().getTemplateRoot(); m_templatePath = ContentSection.getConfig().getTemplateRoot();
@ -172,11 +179,13 @@ public class ContentSectionServlet extends BaseApplicationServlet {
m_resolver = (ApplicationFileResolver) Classes.newInstance(resolverName); m_resolver = (ApplicationFileResolver) Classes.newInstance(resolverName);
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Template path is " + m_templatePath + " with resolver " + m_resolver. s_log.debug("Template path is " + m_templatePath +
" with resolver " + m_resolver.
getClass().getName()); getClass().getName());
} }
// NEW STUFF here used to process the pages in this servlet // NEW STUFF here will be used to process the pages in this servlet
// Currently NOT working
// addPage("/admin", new MainPage()); // index page at address ~/cs // addPage("/admin", new MainPage()); // index page at address ~/cs
// addPage("/admin/index.jsp", new MainPage()); // addPage("/admin/index.jsp", new MainPage());
// addPage("/admin/item.jsp", new MainPage()); // addPage("/admin/item.jsp", new MainPage());
@ -187,14 +196,20 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* Implementation of parent's (abstract) doService method checks HTTP request * Implementation of parent's (abstract) doService method checks HTTP request
* to determine whether to handle a content item or other stuff which is * to determine whether to handle a content item or other stuff which is
* delegated to jsp templates. * delegated to jsp templates.
*
* {@see com.arsdigita.web.BaseApplicationServlet#doService * {@see com.arsdigita.web.BaseApplicationServlet#doService
* (HttpServletRequest, HttpServletResponse, Application)} * (HttpServletRequest, HttpServletResponse, Application)}
*
* @param sreq
* @param sresp
* @param app
* @throws javax.servlet.ServletException
* @throws java.io.IOException
*/ */
@Override
protected void doService(HttpServletRequest sreq, protected void doService(HttpServletRequest sreq,
HttpServletResponse sresp, HttpServletResponse sresp,
Application app) Application app)
throws ServletException, IOException { throws ServletException, IOException {
ContentSection section = (ContentSection) app; ContentSection section = (ContentSection) app;
@ -203,20 +218,20 @@ public class ContentSectionServlet extends BaseApplicationServlet {
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
/* /*
* NOTE: * NOTE:
* Resolves currently to SiteNodeRequestContext which will be removed. * Used to resolve to SiteNodeRequestContext (old style applications)
* NOTE 2: * which has been removed.
* SiteNodeRequestContext removed, resolves currently to * Resolves currently to
* KernelRequestContext which will be removed as well. * KernelRequestContext which will be removed as well.
*/ */
RequestContext ctx = DispatcherHelper.getRequestContext(); RequestContext ctx = DispatcherHelper.getRequestContext();
String url = ctx.getRemainingURLPart(); // here KernelRequestContext now String url = ctx.getRemainingURLPart(); // here KernelRequestContext now
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Resolving item URL " + url); s_log.info("Resolving URL " + url + " and trying as item first.");
} }
final ItemResolver itemResolver = getItemResolver(section); final ItemResolver itemResolver = getItemResolver(section);
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// Prepare NEW style servlet based bebpo page service // Prepare NEW style servlet based bebob page service
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
String pathInfo = sreq.getPathInfo(); String pathInfo = sreq.getPathInfo();
@ -259,7 +274,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
pm.servePage(doc, sreq, sresp); pm.servePage(doc, sreq, sresp);
} }
/* SECONDLY try if we have to serve an item (old style dispatcher based */ /* SECONDLY try if we have to serve an item (old style dispatcher based */
} else if (item != null) { } else if (item != null) {
/* We have to serve an item here */ /* We have to serve an item here */
@ -284,16 +299,16 @@ public class ContentSectionServlet extends BaseApplicationServlet {
serveItem(sreq, sresp, section, item); serveItem(sreq, sresp, section, item);
/* OTHERWISE delegate to a JSP in file system */ /* OTHERWISE delegate to a JSP in file system */
} else { } else {
/* We have to deal with a content-section, folder or an other bit*/ /* We have to deal with a content-section, folder or another bit */
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("NOT serving content item"); s_log.info("NOT serving content item");
} }
/* Store content section in http request to make it available /* Store content section in http request to make it available
* for admin index,jsp */ * for admin/index.jsp */
sreq.setAttribute(CONTENT_SECTION, section); sreq.setAttribute(CONTENT_SECTION, section);
RequestDispatcher rd = m_resolver.resolve(m_templatePath, RequestDispatcher rd = m_resolver.resolve(m_templatePath,
@ -447,6 +462,10 @@ public class ContentSectionServlet extends BaseApplicationServlet {
/** /**
* *
* @param section
* @param url
* @param itemResolver
* @return
*/ */
public ContentItem getItem(ContentSection section, String url, public ContentItem getItem(ContentSection section, String url,
ItemResolver itemResolver) { ItemResolver itemResolver) {
@ -510,6 +529,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
// Get the negotiated locale // Get the negotiated locale
String lang = GlobalizationHelper.getNegotiatedLocale().getLanguage(); String lang = GlobalizationHelper.getNegotiatedLocale().getLanguage();
// XXX why assign a value and afterwards null??
item = itemURLCacheGet(section, url, lang); item = itemURLCacheGet(section, url, lang);
item = null; item = null;
@ -598,6 +618,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* Maps the content item to the URL in a cache * Maps the content item to the URL in a cache
* @param section the content section in which the content item is published * @param section the content section in which the content item is published
* @param sURL the URL at which the content item s published * @param sURL the URL at which the content item s published
* @param lang
* @param item the content item at the URL * @param item the content item at the URL
*/ */
public static synchronized void itemURLCachePut(ContentSection section, public static synchronized void itemURLCachePut(ContentSection section,
@ -608,7 +629,8 @@ public class ContentSectionServlet extends BaseApplicationServlet {
return; return;
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("adding cached entry for url " + sURL + " and language " + lang); s_log.debug("adding cached entry for url " + sURL +
" and language " + lang);
} }
itemURLCachePut(section, sURL, lang, item.getID()); itemURLCachePut(section, sURL, lang, item.getID());
@ -618,20 +640,24 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* Removes the cache entry for the URL, sURL * Removes the cache entry for the URL, sURL
* @param section the content section in which to remove the key * @param section the content section in which to remove the key
* @param sURL the cache entry key to remove * @param sURL the cache entry key to remove
* @param lang
*/ */
public static synchronized void itemURLCacheRemove(ContentSection section, public static synchronized void itemURLCacheRemove(ContentSection section,
String sURL, String sURL,
String lang) { String lang) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("removing cached entry for url " + sURL + "and language " + lang); s_log.debug("removing cached entry for url " + sURL +
"and language " + lang);
} }
getItemURLCache(section).remove(sURL + CACHE_KEY_DELIMITER + lang); getItemURLCache(section).remove(sURL + CACHE_KEY_DELIMITER + lang);
} }
/** /**
* Fetches the ContentItem published at that URL from the cache * Fetches the ContentItem published at that URL from the cache.
*
* @param section the content section in which the content item is published * @param section the content section in which the content item is published
* @param sURL the URL for the item to fetch * @param sURL the URL for the item to fetch
* @param lang
* @return the ContentItem in the cache, or null * @return the ContentItem in the cache, or null
*/ */
public static ContentItem itemURLCacheGet(ContentSection section, public static ContentItem itemURLCacheGet(ContentSection section,
@ -683,6 +709,9 @@ public class ContentSectionServlet extends BaseApplicationServlet {
/** /**
* Checks that the current user has permission to access the admin pages. * Checks that the current user has permission to access the admin pages.
* @param request
* @param section
* @return
**/ **/
public static boolean checkAdminAccess(HttpServletRequest request, public static boolean checkAdminAccess(HttpServletRequest request,
ContentSection section) { ContentSection section) {

View File

@ -470,6 +470,7 @@ public final class LoaderConfig extends AbstractConfig {
/** /**
* Retrieve whether the content-section is publicly viewable (i.e. without * Retrieve whether the content-section is publicly viewable (i.e. without
* registration and login) * registration and login)
* @return
*/ */
public Boolean isPubliclyViewable() { public Boolean isPubliclyViewable() {
return ((Boolean) get(m_isPublic)).booleanValue(); return ((Boolean) get(m_isPublic)).booleanValue();
@ -477,6 +478,7 @@ public final class LoaderConfig extends AbstractConfig {
/** /**
* Retrieve the item resolver class * Retrieve the item resolver class
* @return
*/ */
public String getItemResolverClass() { public String getItemResolverClass() {
return (String) get(m_itemResolverClass); return (String) get(m_itemResolverClass);
@ -484,6 +486,7 @@ public final class LoaderConfig extends AbstractConfig {
/** /**
* Retrieve the template resolver class * Retrieve the template resolver class
* @return
*/ */
public String getTemplateResolverClass() { public String getTemplateResolverClass() {
return (String) get(m_templateResolverClass); return (String) get(m_templateResolverClass);
@ -506,6 +509,7 @@ public final class LoaderConfig extends AbstractConfig {
* Retrieve the list of files containing categories to load. In old * Retrieve the list of files containing categories to load. In old
* Initialiser: Parameter name: CATEGORIES Deskr. "XML file containing the * Initialiser: Parameter name: CATEGORIES Deskr. "XML file containing the
* category tree" * category tree"
* @return
*/ */
public List getCategoryFileList() { public List getCategoryFileList() {
String[] catFiles = (String[]) get(m_categoryFileList); String[] catFiles = (String[]) get(m_categoryFileList);

View File

@ -310,7 +310,9 @@ public final class ContentSectionConfig extends AbstractConfig {
// ////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////
/** /**
* Retrieve the list of workflow tasks and events for each tasks which should receive overdue * Retrieve the list of workflow tasks and events for each tasks which should receive overdue
* notification alerts * notification alerts.
*
* @return
*/ */
public final String[] getTaskAlerts() { public final String[] getTaskAlerts() {
return (String[]) get(m_taskAlerts); return (String[]) get(m_taskAlerts);
@ -318,28 +320,38 @@ public final class ContentSectionConfig extends AbstractConfig {
/** /**
* Retrieve whether to send overdue information for unfinished tasks. * Retrieve whether to send overdue information for unfinished tasks.
*
* @return
*/ */
public Boolean getSendOverdueAlerts() { public Boolean getSendOverdueAlerts() {
return ((Boolean) get(m_sendOverdueAlerts)).booleanValue(); return ((Boolean) get(m_sendOverdueAlerts)).booleanValue();
} }
/** /**
* Retrieve time between when a task is enabled and when it is considered overdue. * Retrieve time between when a task is enabled and when it is considered
* overdue.
*
* @return
*/ */
public Integer getTaskDuration() { public Integer getTaskDuration() {
return ((Integer) get(m_taskDuration)).intValue(); return ((Integer) get(m_taskDuration)).intValue();
} }
/** /**
* Retrieve the time to wait between sending successive alerts on the same overdue task (in * Retrieve the time to wait between sending successive alerts on the
* HOURS). * same overdue task (in HOURS).
*
* @return
*/ */
public Integer getAlertInterval() { public Integer getAlertInterval() {
return (Integer) get(m_alertInterval); return (Integer) get(m_alertInterval);
} }
/** /**
* Retrieve the maximum number of alerts to send that a single task is overdue * Retrieve the maximum number of alerts to send that a single task is
* overdue.
*
* @return
*/ */
public Integer getMaxAlerts() { public Integer getMaxAlerts() {
return (Integer) get(m_maxAlerts); return (Integer) get(m_maxAlerts);
@ -381,8 +393,9 @@ public final class ContentSectionConfig extends AbstractConfig {
* solution. * solution.
*/ */
/** /**
* Changed: The forth field is not used anymore * Changed: The forth field is not used anymore.
* *
* @return
*/ */
public List getDefaultRoles() { public List getDefaultRoles() {
@ -651,6 +664,7 @@ public final class ContentSectionConfig extends AbstractConfig {
/** /**
* Retrieve whether the content-section is publicly viewable (i.e. without registration and * Retrieve whether the content-section is publicly viewable (i.e. without registration and
* login) * login)
* @return
*/ */
public Boolean isPubliclyViewable() { public Boolean isPubliclyViewable() {
return ((Boolean) get(m_isPublic)).booleanValue(); return ((Boolean) get(m_isPublic)).booleanValue();
@ -658,13 +672,15 @@ public final class ContentSectionConfig extends AbstractConfig {
/** /**
* Retrieve the item resolver class * Retrieve the item resolver class
* @return
*/ */
public String getItemResolverClass() { public String getItemResolverClass() {
return (String) get(m_itemResolverClass); return (String) get(m_itemResolverClass);
} }
/** /**
* Retrieve the template resolver class * Retrieve the template resolver class.
* @return
*/ */
public String getTemplateResolverClass() { public String getTemplateResolverClass() {
return (String) get(m_templateResolverClass); return (String) get(m_templateResolverClass);
@ -684,8 +700,10 @@ public final class ContentSectionConfig extends AbstractConfig {
} }
/** /**
* Retrieve the list of files containing categories to load. In old Initialiser: Parameter name: * Retrieve the list of files containing categories to load.
* In old Initialiser: Parameter name:
* CATEGORIES Deskr. "XML file containing the category tree" * CATEGORIES Deskr. "XML file containing the category tree"
* @return
*/ */
public List getCategoryFileList() { public List getCategoryFileList() {
String[] catFiles = (String[]) get(m_categoryFileList); String[] catFiles = (String[]) get(m_categoryFileList);
@ -693,7 +711,8 @@ public final class ContentSectionConfig extends AbstractConfig {
} }
/** /**
* Retrieve the * Retrieve the.
* @return
*/ */
public List getContentSectionsContentTypes() { public List getContentSectionsContentTypes() {
String[] taskAlerts = (String[]) get(m_contentTypeList); String[] taskAlerts = (String[]) get(m_contentTypeList);

View File

@ -21,7 +21,7 @@ import com.arsdigita.kernel.NoValidURLException;
import com.arsdigita.kernel.URLFinder; import com.arsdigita.kernel.URLFinder;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
import com.arsdigita.web.Web; import com.arsdigita.web.Web;
import com.arsdigita.web.WebConfig; //import com.arsdigita.web.WebConfig;
/** /**
* Implementation of URLFinder for Assets. * Implementation of URLFinder for Assets.
@ -37,6 +37,7 @@ public class AssetURLFinder implements URLFinder {
* @param context the context of the lookup (live/draft) * @param context the context of the lookup (live/draft)
* @return * @return
*/ */
@Override
public String find(OID oid, String context) throws NoValidURLException { public String find(OID oid, String context) throws NoValidURLException {
if( !"live".equals( context ) ) if( !"live".equals( context ) )
throw new NoValidURLException("No draft URL for assets"); throw new NoValidURLException("No draft URL for assets");
@ -57,6 +58,7 @@ public class AssetURLFinder implements URLFinder {
* @param oid the OID of the asset * @param oid the OID of the asset
* @return * @return
*/ */
@Override
public String find(OID oid) throws NoValidURLException { public String find(OID oid) throws NoValidURLException {
return find(oid, "live"); return find(oid, "live");
} }

View File

@ -60,6 +60,10 @@ import org.apache.log4j.Logger;
*/ */
public final class DispatcherHelper implements DispatcherConstants { public final class DispatcherHelper implements DispatcherConstants {
/** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.dispatcher.DispatcherHelper=DEBUG
* by uncommenting or adding the line. */
private static final Logger s_log = Logger.getLogger(DispatcherHelper.class); private static final Logger s_log = Logger.getLogger(DispatcherHelper.class);
private static String s_webappCtx; private static String s_webappCtx;
private static String s_staticURL; private static String s_staticURL;
@ -89,7 +93,7 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* The current HttpServletRequest. * The current HttpServletRequest.
*/ */
private static ThreadLocal s_request = new ThreadLocal(); private static final ThreadLocal s_request = new ThreadLocal();
/** null constructor, private so no one can instantiate! */ /** null constructor, private so no one can instantiate! */
private DispatcherHelper() { private DispatcherHelper() {
@ -128,8 +132,9 @@ public final class DispatcherHelper implements DispatcherConstants {
* if servlet A includes servlet B, calling getRequestURI() in B * if servlet A includes servlet B, calling getRequestURI() in B
* returns "A" and not "B". * returns "A" and not "B".
* *
* @param req
* @return the URL path (relative to the webapp root) for the currently * @return the URL path (relative to the webapp root) for the currently
* executing resource. * executing resource.
*/ */
public static String getCurrentResourcePath(HttpServletRequest req) { public static String getCurrentResourcePath(HttpServletRequest req) {
String attr = (String) req.getAttribute(INCLUDE_URI); String attr = (String) req.getAttribute(INCLUDE_URI);
@ -153,6 +158,7 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* Gets the application context from the request attributes. * Gets the application context from the request attributes.
* @param req
* @return the application context from the request attributes. * @return the application context from the request attributes.
*/ */
public static RequestContext getRequestContext(HttpServletRequest req) { public static RequestContext getRequestContext(HttpServletRequest req) {
@ -242,11 +248,16 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* Equivalent to <code>forwardRequestByPath(path, req, resp, * Equivalent to <code>forwardRequestByPath(path, req, resp,
* DispatcherHelper.getRequestContext(req).getServletContext())</code>. * DispatcherHelper.getRequestContext(req).getServletContext())</code>.
* @param path
* @param req
* @param resp
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/ */
public static void forwardRequestByPath(String path, public static void forwardRequestByPath(String path,
HttpServletRequest req, HttpServletRequest req,
HttpServletResponse resp) HttpServletResponse resp)
throws IOException, ServletException { throws IOException, ServletException {
ServletContext sctx = ServletContext sctx =
DispatcherHelper.getRequestContext(req).getServletContext(); DispatcherHelper.getRequestContext(req).getServletContext();
forwardRequestByPath(path, req, resp, sctx); forwardRequestByPath(path, req, resp, sctx);
@ -316,6 +327,12 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* Equivalent to <code>forwardRequestByName(name, req, resp, * Equivalent to <code>forwardRequestByName(name, req, resp,
* DispatcherHelper.getRequestContext(req).getServletContext())</code>. * DispatcherHelper.getRequestContext(req).getServletContext())</code>.
*
* @param name
* @param req
* @param resp
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/ */
public static void forwardRequestByName(String name, public static void forwardRequestByName(String name,
HttpServletRequest req, HttpServletRequest req,
@ -345,6 +362,7 @@ public final class DispatcherHelper implements DispatcherConstants {
* not end with a trailing slash. * not end with a trailing slash.
* @exception java.io.FileNotFoundException if no matching * @exception java.io.FileNotFoundException if no matching
* file exists. * file exists.
* @throws com.arsdigita.dispatcher.DirectoryListingException
* @deprecated abstract URLs are no longer supported. Use * @deprecated abstract URLs are no longer supported. Use
* extensions when your file on disk has an extension. * extensions when your file on disk has an extension.
*/ */
@ -382,17 +400,13 @@ public final class DispatcherHelper implements DispatcherConstants {
final String extensionSearchList[] = {".jsp"}; final String extensionSearchList[] = {".jsp"};
if (filesInDir != null) { if (filesInDir != null) {
// look for .jsp files first for (String searchExtension : extensionSearchList) { //1.5 enhanced loop
for (int j = 0; j < extensionSearchList.length; j++) { File possibleFile = new File(dirToSearch,
filenameStub + searchExtension);
File possibleFile =
new File(dirToSearch,
filenameStub + extensionSearchList[j]);
for (int i = 0; i < filesInDir.length; i++) { for (int i = 0; i < filesInDir.length; i++) {
if (filesInDir[i].equals(possibleFile)) { if (filesInDir[i].equals(possibleFile)) {
return (indexPage ? File.separator + "index" : "") return (indexPage ? File.separator + "index" : "")
+ extensionSearchList[j]; + searchExtension;
} }
} }
} }
@ -474,6 +488,11 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* This method will optionally wrap the request if it is a multipart POST, * This method will optionally wrap the request if it is a multipart POST,
* or restore the original wrapper if it was already wrapped. * or restore the original wrapper if it was already wrapped.
*
* @param sreq
* @return
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/ */
public static HttpServletRequest maybeWrapRequest(HttpServletRequest sreq) public static HttpServletRequest maybeWrapRequest(HttpServletRequest sreq)
throws IOException, ServletException { throws IOException, ServletException {
@ -533,6 +552,7 @@ public final class DispatcherHelper implements DispatcherConstants {
* Redirects the client to the given URL without rewriting it. Delegates * Redirects the client to the given URL without rewriting it. Delegates
* to the sendExternalRedirect method. * to the sendExternalRedirect method.
* *
* @throws java.io.IOException
* @deprecated This method does not rewrite URLs. Use * @deprecated This method does not rewrite URLs. Use
* sendRedirect(HttpServletRequest, HttpServletResponse, String) for * sendRedirect(HttpServletRequest, HttpServletResponse, String) for
* redirects within this ACS or * redirects within this ACS or
@ -544,7 +564,7 @@ public final class DispatcherHelper implements DispatcherConstants {
**/ **/
public static void sendRedirect(HttpServletResponse resp, public static void sendRedirect(HttpServletResponse resp,
String url) String url)
throws IOException { throws IOException {
sendExternalRedirect(resp, url); sendExternalRedirect(resp, url);
} }
@ -556,11 +576,12 @@ public final class DispatcherHelper implements DispatcherConstants {
* for URL rewriting * for URL rewriting
* @param resp the current response * @param resp the current response
* @param url the destination URL for redirect * @param url the destination URL for redirect
* @throws java.io.IOException
**/ **/
public static void sendRedirect(HttpServletRequest req, public static void sendRedirect(HttpServletRequest req,
HttpServletResponse resp, HttpServletResponse resp,
String url) String url)
throws IOException { throws IOException {
sendExternalRedirect(resp, url); sendExternalRedirect(resp, url);
} }
@ -570,10 +591,11 @@ public final class DispatcherHelper implements DispatcherConstants {
* *
* @param resp the current response * @param resp the current response
* @param url the destination URL for redirect * @param url the destination URL for redirect
* @throws java.io.IOException
**/ **/
public static void sendExternalRedirect(HttpServletResponse resp, public static void sendExternalRedirect(HttpServletResponse resp,
String url) String url)
throws IOException { throws IOException {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Redirecting to URL '" + url + "'", new Throwable()); s_log.debug("Redirecting to URL '" + url + "'", new Throwable());
} }
@ -782,6 +804,8 @@ public final class DispatcherHelper implements DispatcherConstants {
* 3. If there is no request or previous request, use the value * 3. If there is no request or previous request, use the value
* specified by the enterprise.init webappContext parameter. * specified by the enterprise.init webappContext parameter.
* 4. Lastly, return null. * 4. Lastly, return null.
*
* @return
*/ */
public static String getWebappContext() { public static String getWebappContext() {
init(); init();
@ -832,6 +856,8 @@ public final class DispatcherHelper implements DispatcherConstants {
/** /**
* Stores the HttpServletRequest in a ThreadLocal so that it can be * Stores the HttpServletRequest in a ThreadLocal so that it can be
* accessed globally. * accessed globally.
*
* @param r
*/ */
public static void setRequest(HttpServletRequest r) { public static void setRequest(HttpServletRequest r) {
init(); init();
@ -1069,7 +1095,8 @@ public final class DispatcherHelper implements DispatcherConstants {
} }
/** /**
* This returns a reference to the dispatcher configuration file * This returns a reference to the dispatcher configuration file
* @return
*/ */
public static DispatcherConfig getConfig() { public static DispatcherConfig getConfig() {
if (s_config == null) { if (s_config == null) {
@ -1080,9 +1107,9 @@ public final class DispatcherHelper implements DispatcherConstants {
} }
/** /**
* This method returns the best matching locate for the request. In contrast to * This method returns the best matching locale for the request. In contrast
* the other methods available this one will also respect the supported_languages * to the other methods available this one will also respect the
* config entry. * supported_languages config entry.
* *
* @return The negotiated locale * @return The negotiated locale
*/ */
@ -1113,8 +1140,8 @@ public final class DispatcherHelper implements DispatcherConstants {
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
// Don't have to do anything because I want to fall back to default language anyway // Don't have to do anything because I want to fall back to default
// This case should only appear during setup // language anyway. This case should only appear during setup
} finally { } finally {
return preferedLocale; return preferedLocale;

View File

@ -149,6 +149,7 @@ public abstract class BaseServlet extends HttpServlet {
final IOException[] ioException = { null }; final IOException[] ioException = { null };
new KernelExcursion() { new KernelExcursion() {
@Override
protected final void excurse() { protected final void excurse() {
setLocale(sreq.getLocale()); setLocale(sreq.getLocale());
setSessionID(sreq.getSession().getId()); setSessionID(sreq.getSession().getId());
@ -266,6 +267,10 @@ public abstract class BaseServlet extends HttpServlet {
/** /**
* <p>Processes HTTP GET requests.</p> * <p>Processes HTTP GET requests.</p>
* *
* @param sreq
* @param sresp
* @throws javax.servlet.ServletException
* @throws java.io.IOException
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest,HttpServletResponse) * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest,HttpServletResponse)
*/ */
@Override @Override
@ -283,6 +288,11 @@ public abstract class BaseServlet extends HttpServlet {
/** /**
* <p>Processes HTTP POST requests.</p> * <p>Processes HTTP POST requests.</p>
*
* @param sreq
* @param sresp
* @throws javax.servlet.ServletException
* @throws java.io.IOException
* *
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest,HttpServletResponse) * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest,HttpServletResponse)
*/ */

View File

@ -318,6 +318,9 @@ public class CCMDispatcherServlet extends BaseServlet {
s_log.debug("Checking if this request needs to be forwarded or " + s_log.debug("Checking if this request needs to be forwarded or " +
"included " + sreq); "included " + sreq);
// Just in case sreq is wrapped in one of our own classes (spec.
// MultipartHttpServletRequest), return unwrapped request, otherwise
// do nothing (doesn't modify anything). Mostly does nothing!
sreq = DispatcherHelper.restoreOriginalRequest(sreq); sreq = DispatcherHelper.restoreOriginalRequest(sreq);
if (sreq.getAttribute("javax.servlet.include.request_uri") == null) { if (sreq.getAttribute("javax.servlet.include.request_uri") == null) {
@ -499,7 +502,7 @@ public class CCMDispatcherServlet extends BaseServlet {
@Override @Override
public String toString() { public String toString() {
final String sep = ", "; final String sep = ", ";
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");
sb.append("appID=").append(m_id).append(sep); sb.append("appID=").append(m_id).append(sep);
sb.append("instanceURI=").append(m_instanceURI).append(sep); sb.append("instanceURI=").append(m_instanceURI).append(sep);
@ -516,6 +519,7 @@ public class CCMDispatcherServlet extends BaseServlet {
*/ */
private static class Cache extends PathMapCache { private static class Cache extends PathMapCache {
/** */
private static final ThreadLocal s_handleHere = new ThreadLocal() { private static final ThreadLocal s_handleHere = new ThreadLocal() {
@Override @Override
protected Object initialValue() { protected Object initialValue() {
@ -523,6 +527,9 @@ public class CCMDispatcherServlet extends BaseServlet {
} }
}; };
/**
* Constructor, just delegates to Super class
*/
public Cache() { public Cache() {
super("BaseDispatcherCache"); super("BaseDispatcherCache");
} }

View File

@ -31,14 +31,16 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
* 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.DefaultApplicationFileResolver=DEBUG by * and set com.arsdigita.web.DefaultApplicationFileResolver=DEBUG by
* uncommenting or adding the line. */ * uncommenting or adding the line. */
private static Logger s_log = private static final Logger s_log = Logger.getLogger
Logger.getLogger(DefaultApplicationFileResolver.class); (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"
}; };
/** /**
* Determines from the passsed in information a suitable RequestDispatcher.
* Implementation of the interface' single method.
* *
* @param templatePath * @param templatePath
* @param sreq * @param sreq
@ -52,7 +54,7 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
HttpServletResponse sresp, HttpServletResponse sresp,
Application app) { Application app) {
String contextPath = app.getContextPath(); String contextPath = app.getContextPath(); // constant from Application!
String pathInfo = sreq.getPathInfo(); String pathInfo = sreq.getPathInfo();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
@ -65,15 +67,13 @@ public class DefaultApplicationFileResolver implements ApplicationFileResolver {
if (path.endsWith("/")) { if (path.endsWith("/")) {
for (int i = 0 ; i < WELCOME_FILES.length ; i++) { for (String welcomeFile : WELCOME_FILES) { //1.5 enhanced for-loop
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Trying welcome resource " + s_log.debug("Trying welcome resource " +
path + WELCOME_FILES[i]); path + welcomeFile);
} }
RequestDispatcher rd = Web.findResourceDispatcher( RequestDispatcher rd = Web.findResourceDispatcher(
contextPath + path contextPath + path + welcomeFile);
+ 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);

View File

@ -22,13 +22,14 @@ package com.arsdigita.web;
import com.arsdigita.kernel.security.UserContext; import com.arsdigita.kernel.security.UserContext;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.StringUtils; import com.arsdigita.util.StringUtils;
import com.arsdigita.util.UncheckedWrapperException; //import com.arsdigita.util.UncheckedWrapperException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.HashMap; //import java.util.HashMap;
import java.util.Map; //import java.util.Map;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -51,7 +52,7 @@ public class Web {
* by uncommenting or adding the line. */ * by uncommenting or adding the line. */
private static final Logger s_log = Logger.getLogger(Web.class); private static final Logger s_log = Logger.getLogger(Web.class);
private static WebConfig s_config = WebConfig.getInstanceOf(); private static final WebConfig s_config = WebConfig.getInstanceOf();
private static final ThreadLocal s_request = private static final ThreadLocal s_request =
new InternalRequestLocal(); new InternalRequestLocal();
@ -237,7 +238,7 @@ public class Web {
} }
return url; // Return adjusted resourcePath url return url; // Return adjusted resourcePath url
} }
} catch (IOException ex) { } catch (MalformedURLException ex) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Cannot get resource for " + resourcePath); s_log.debug("Cannot get resource for " + resourcePath);
} }
@ -272,7 +273,7 @@ public class Web {
s_log.debug("No URL present for " + path); s_log.debug("No URL present for " + path);
} }
} }
} catch(IOException exc) { } catch(MalformedURLException exc) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("cannot get resource for " + path); s_log.debug("cannot get resource for " + path);
} }
@ -324,7 +325,7 @@ public class Web {
s_log.debug("No URL present for " + path); s_log.debug("No URL present for " + path);
} }
} }
} catch(IOException ex) { } catch(MalformedURLException ex) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("cannot get resource for " + path); s_log.debug("cannot get resource for " + path);
} }
@ -404,15 +405,36 @@ public class Web {
return null; return null;
} }
ServletContext ctx = getServletContext(); ServletContext ctx = getServletContext();
URL url = null;
// Check for old style resource format including a comma seoarated list // Check for old style resource format including a comma seoarated list
// of webapps // of webapps
if(resourcePath.indexOf(",") <= 0 ) { if(resourcePath.indexOf(",") <= 0 ) {
// no comma separated list found, process as normal // no comma separated list found, process as normal
return ctx == null ? null : ctx.getRequestDispatcher(resourcePath);
try {
url = ctx.getResource(resourcePath);
} catch (MalformedURLException ex) {
if (s_log.isDebugEnabled()) {
s_log.debug("Resource for " + resourcePath + " not found.");
}
// throw new UncheckedWrapperException(
// "No resource at " + resourcePath, ex);
return null;
}
if (url == null) {
return null;
} else {
RequestDispatcher rd = (ctx == null) ?
null : ctx.getRequestDispatcher(resourcePath);
return rd;
}
} else { } else {
// old style format not implemented yet here // old style format not implemented yet here
return null; return null;
} }
} }

View File

@ -248,6 +248,7 @@ public final class WebConfig extends AbstractConfig {
* per-user caching, <code>world</code> for globally enabled * per-user caching, <code>world</code> for globally enabled
* caching, <code>disable</code> to prevent HTTP header caching, and * caching, <code>disable</code> to prevent HTTP header caching, and
* <code>none</code>to always prevent caching in any case. * <code>none</code>to always prevent caching in any case.
* @return
*/ */
public final CachePolicy getCachePolicy() { public final CachePolicy getCachePolicy() {
return (CachePolicy) get(m_policy); return (CachePolicy) get(m_policy);
@ -259,6 +260,7 @@ public final class WebConfig extends AbstractConfig {
super(name); super(name);
} }
@Override
protected void doValidate(final Object value, final ErrorList errors) { protected void doValidate(final Object value, final ErrorList errors) {
final String string = (String) value; final String string = (String) value;
@ -322,6 +324,7 @@ public final class WebConfig extends AbstractConfig {
// //
/** /**
* @return
* @deprecated Use <code>getServer().getName()</code> instead. * @deprecated Use <code>getServer().getName()</code> instead.
*/ */
public final String getServerName() { public final String getServerName() {
@ -329,6 +332,7 @@ public final class WebConfig extends AbstractConfig {
} }
/** /**
* @return
* @deprecated Use <code>getServer().getPort()</code> instead. * @deprecated Use <code>getServer().getPort()</code> instead.
*/ */
public final int getServerPort() { public final int getServerPort() {
@ -336,6 +340,7 @@ public final class WebConfig extends AbstractConfig {
} }
/** /**
* @return
* @deprecated Use * @deprecated Use
* <code>Host.retrieve(Web.getConfig().getHost())</code> instead. * <code>Host.retrieve(Web.getConfig().getHost())</code> instead.
*/ */
@ -344,6 +349,7 @@ public final class WebConfig extends AbstractConfig {
} }
/** /**
* @return
* @deprecated Use <code>Host.retrieveAll()</code> instead. * @deprecated Use <code>Host.retrieveAll()</code> instead.
*/ */
public final Host[] getHosts() { public final Host[] getHosts() {