From fbc7372b644480d51f6dd262d101cfc926c0a9e8 Mon Sep 17 00:00:00 2001 From: pb Date: Sun, 26 Dec 2010 00:37:19 +0000 Subject: [PATCH] Verschiedene kleinere Formatierungen / Kommentierungen. git-svn-id: https://svn.libreccm.org/ccm/trunk@662 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/dispatcher/ItemURLFinder.java | 77 ++++++++++++++----- .../bebop/parameters/ParameterModel.java | 5 +- .../arsdigita/kernel/GenericURLFinder.java | 5 +- .../src/com/arsdigita/kernel/Initializer.java | 5 +- .../src/com/arsdigita/kernel/URLFinder.java | 7 +- .../src/com/arsdigita/kernel/URLService.java | 13 ++-- .../arsdigita/toolbox/ui/OIDParameter.java | 3 +- .../com/arsdigita/web/OIDRedirectServlet.java | 46 ++++++++--- ccm-core/web/WEB-INF/web.ccm-core.xml | 62 ++++++++------- .../SubsiteItemTemplateResolver.java | 8 +- 10 files changed, 151 insertions(+), 80 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/dispatcher/ItemURLFinder.java b/ccm-cms/src/com/arsdigita/cms/dispatcher/ItemURLFinder.java index 44852091c..396bcbf64 100755 --- a/ccm-cms/src/com/arsdigita/cms/dispatcher/ItemURLFinder.java +++ b/ccm-cms/src/com/arsdigita/cms/dispatcher/ItemURLFinder.java @@ -18,8 +18,6 @@ */ package com.arsdigita.cms.dispatcher; -import org.apache.log4j.Logger; - import com.arsdigita.categorization.Category; import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; @@ -39,11 +37,29 @@ import com.arsdigita.web.ParameterMap; import com.arsdigita.web.URL; import com.arsdigita.web.Web; +import org.apache.log4j.Logger; + +/** + * Implementation of {@link com.arsdigita.kernel.URLFinder} for content types, + * necessary for ccm dispatcher to find a concrete content item for an url + * provided by a client request. + * + * Specifically it is a helper class for {@link com.arsdigita.web.OIDRedirectServlet} + * to map an OID to an URL. + * + */ public class ItemURLFinder implements URLFinder { private static final Logger s_log = Logger.getLogger(ItemURLFinder.class); - public String find(OID oid,String context) throws NoValidURLException { + /** + * + * @param oid + * @param context publication status ['live'|'draft'] + * @return + * @throws NoValidURLException + */ + public String find(OID oid, String context) throws NoValidURLException { if (s_log.isDebugEnabled()) { s_log.debug("Locating " + oid + " in " + context); } @@ -78,6 +94,12 @@ public class ItemURLFinder implements URLFinder { return find(item, context); } + /** + * + * @param oid + * @return + * @throws NoValidURLException + */ public String find(OID oid) throws NoValidURLException { if (s_log.isDebugEnabled()) { s_log.debug("Locating " + oid); @@ -98,14 +120,18 @@ public class ItemURLFinder implements URLFinder { s_log.debug("Item version is " + item.getVersion()); } - // Revert to the behavior before change# 41315. Clients relied on the behavior that - // links with no context defaulted to the live version (if one existed). Changing - // that behavior broke a lot of links in static content that couldn't easily be updated. - // This change restores the old behavior. We don't get a regression of bz 116226 - // (which bz 41315 was intended to fix) because the CMS search.xsl has been updated to - // append "&context=draft" to the search results. The CMS DHTML editor has also been - // updated to append generated links with "&context=live". If at some point in the future - // all unqualified links have been removed, then this fix could be removed as well. + // Revert to the behavior before change #41315. + // Clients relied on the behavior that links with no context + // defaulted to the live version (if one existed). Changing + // that behavior broke a lot of links in static content that couldn't + // easily be updated. + // This change restores the old behavior. We don't get a regression of + // bz 116226 (which bz 41315 was intended to fix) because the CMS + // search.xsl has been updated to append "&context=draft" to the search + // results. The CMS DHTML editor has also been updated to append + // generated links with "&context=live". If at some point in the future + // all unqualified links have been removed, then this fix could be + // removed as well. if (item.isLive() && !item.isLiveVersion()) { item = item.getLiveVersion(); if (s_log.isDebugEnabled()) { @@ -116,8 +142,16 @@ public class ItemURLFinder implements URLFinder { return find(item, item.getVersion()); } - private String find(ContentItem item, - String context) throws NoValidURLException { + /** + * + * @param item + * @param context publication status ['live'|'draft'] + * @return + * @throws NoValidURLException + */ + private String find(ContentItem item, String context) + throws NoValidURLException { + ContentSection section = item.getContentSection(); ItemResolver resolver = section.getItemResolver(); @@ -127,7 +161,7 @@ public class ItemURLFinder implements URLFinder { // always send to the admin screen (that's for results of the admin // search) - if (!ContentItem.DRAFT.equals(context)) { + if (!ContentItem.DRAFT.equals(context)) { // LIVE context ACSObject parent = item.getParent(); ContentBundle bundle = null; if (parent instanceof ContentBundle) { @@ -137,14 +171,19 @@ public class ItemURLFinder implements URLFinder { DataAssociationCursor categories = ((DataAssociation) DomainServiceInterfaceExposer. get(bundle, Category.CATEGORIES)).cursor(); + // XXX pb (2010.12.15) ToDO + // solution is currently not subsite aware! + // provides an index url even if the category tree is not part + // of subsite (which results in a resource not found exception) categories.addEqualsFilter("link." + Category.IS_INDEX, Boolean.TRUE); if (categories.next()) { Category indexCat = (Category) DomainObjectFactory. - newInstance(categories.getDataObject()); + newInstance(categories.getDataObject()); categories.close(); try { if (s_log.isDebugEnabled()) { - s_log.debug(item + " is a Category index item. Resolving URL for " + indexCat); + s_log.debug(item + " is a Category index item. " + + "Resolving URL for " + indexCat); } return URLService.locate(indexCat.getOID(), context); } catch (URLFinderNotFoundException ufnfe) { @@ -165,12 +204,14 @@ public class ItemURLFinder implements URLFinder { } else { // DRAFT context // public users get 404 when item gets unpublished // if com.arsdigita.cms.unpublished_not_found=true - if (ContentSection.getConfig().isUnpublishedNotFound() && !Web.getUserContext().isLoggedIn()) { + if (ContentSection.getConfig().isUnpublishedNotFound() + && !Web.getUserContext().isLoggedIn()) { throw new NoValidURLException("user must be logged-in to get draft"); } else { // force the switch to draft version at this point // otherwise resolver below breaks with: - // java.lang.IllegalStateException: Generating draft url: item must be draft version + // java.lang.IllegalStateException: Generating draft url: + // item must be draft version if (!item.isDraftVersion()) { item = item.getDraftVersion(); s_log.debug("switching to draft version"); diff --git a/ccm-core/src/com/arsdigita/bebop/parameters/ParameterModel.java b/ccm-core/src/com/arsdigita/bebop/parameters/ParameterModel.java index ebcc70331..21dd484f5 100755 --- a/ccm-core/src/com/arsdigita/bebop/parameters/ParameterModel.java +++ b/ccm-core/src/com/arsdigita/bebop/parameters/ParameterModel.java @@ -21,13 +21,16 @@ package com.arsdigita.bebop.parameters; import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.event.ParameterEvent; import com.arsdigita.bebop.event.ParameterListener; -import com.arsdigita.util.Assert; import com.arsdigita.globalization.Globalization; +import com.arsdigita.util.Assert; import com.arsdigita.util.Lockable; + import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import javax.servlet.http.HttpServletRequest; + import org.apache.log4j.Logger; /** diff --git a/ccm-core/src/com/arsdigita/kernel/GenericURLFinder.java b/ccm-core/src/com/arsdigita/kernel/GenericURLFinder.java index 837a28643..76fbd6cb3 100755 --- a/ccm-core/src/com/arsdigita/kernel/GenericURLFinder.java +++ b/ccm-core/src/com/arsdigita/kernel/GenericURLFinder.java @@ -31,7 +31,6 @@ import javax.servlet.http.HttpUtils; import java.net.URLEncoder; /** - * * A URLFinder that can be registered for most object types. The * GenericURLFinder is constructed with a specified URL pattern such * as one-ticket?ticket_id=:id. For a given OID, the @@ -102,12 +101,10 @@ import java.net.URLEncoder; * PackageInstance. * * @author Oumi Mehrotra - * + * @version $Id: GenericURLFinder.java 287 2005-02-22 00:29:02Z sskracic $ */ public class GenericURLFinder implements URLFinder { - public static final String versionId = "$Id: GenericURLFinder.java 287 2005-02-22 00:29:02Z sskracic $ by $Author: sskracic $, $DateTime: 2004/08/16 18:10:38 $"; - private String m_base; private Map m_params; diff --git a/ccm-core/src/com/arsdigita/kernel/Initializer.java b/ccm-core/src/com/arsdigita/kernel/Initializer.java index 2cddb842a..3d061a32a 100755 --- a/ccm-core/src/com/arsdigita/kernel/Initializer.java +++ b/ccm-core/src/com/arsdigita/kernel/Initializer.java @@ -35,12 +35,9 @@ import org.apache.log4j.Logger; * Initializes the Kernel and bootstraps the rest of the system. * * @version $Revision: #39 $ $Date: 2004/08/16 $ + * @version $Id: Initializer.java 1169 2006-06-14 13:08:25Z fabrice $ */ public class Initializer extends BaseInitializer { - public static final String versionId = - "$Id: Initializer.java 1169 2006-06-14 13:08:25Z fabrice $" + - "$Author: fabrice $" + - "$DateTime: 2004/08/16 18:10:38 $"; private static final Logger s_log = Logger.getLogger(Initializer.class); diff --git a/ccm-core/src/com/arsdigita/kernel/URLFinder.java b/ccm-core/src/com/arsdigita/kernel/URLFinder.java index 3e1b2b6d9..d1b84d357 100755 --- a/ccm-core/src/com/arsdigita/kernel/URLFinder.java +++ b/ccm-core/src/com/arsdigita/kernel/URLFinder.java @@ -36,12 +36,11 @@ import com.arsdigita.persistence.OID; * is not applicable to some data object type, the developer * should write a new URLFinder that uses application-specific logic. * - * @author Oumi Mehrotra - **/ + * @author Oumi Mehrotra + * @version $Id: URLFinder.java 287 2005-02-22 00:29:02Z sskracic $ + */ public interface URLFinder { - public static final String versionId = "$Id: URLFinder.java 287 2005-02-22 00:29:02Z sskracic $ by $Author: sskracic $, $DateTime: 2004/08/16 18:10:38 $"; - /** * Returns a URL path to a page that displays the object identified by * the given OID. The URL path is relative to the server root. diff --git a/ccm-core/src/com/arsdigita/kernel/URLService.java b/ccm-core/src/com/arsdigita/kernel/URLService.java index 67ada9cb7..0c8dc6a4d 100755 --- a/ccm-core/src/com/arsdigita/kernel/URLService.java +++ b/ccm-core/src/com/arsdigita/kernel/URLService.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; /** * Supports generically locating a domain object on the site. + * * The URLService can produce the path (relative to the root URL) to a page * that displays the domain object identified by a given OID. *

@@ -82,11 +83,12 @@ public class URLService { * @throws NoValidURLException when the * URLFinder registered for the given oid's object type is unable * to produce a valid non-null URL. - **/ + */ public static String locate(OID oid) throws URLFinderNotFoundException, NoValidURLException { return locate(oid,null); } + /** * Returns a URL path to a page that displays the object identified by * the given oid. The URL path is relative to the server root. @@ -100,10 +102,10 @@ public class URLService { * @throws NoValidURLException when the * URLFinder registered for the given oid's object type is unable * to produce a valid non-null URL. - **/ + */ public static String locate(OID oid, String context) - throws URLFinderNotFoundException, NoValidURLException - { + throws URLFinderNotFoundException, NoValidURLException{ + URLFinder f = getFinder(oid.getObjectType()); if (f==null) { throw new URLFinderNotFoundException("There is no URLFinder " + @@ -112,6 +114,7 @@ public class URLService { oid.getObjectType().getQualifiedName()); } + // Determine the URL using the objects URLFinder String url = (context == null) ? f.find(oid) : f.find(oid,context); if (url == null) { @@ -149,7 +152,7 @@ public class URLService { * * @return the previous finder that was * registered with this service for this object type. - **/ + */ public synchronized static URLFinder registerFinder(ObjectType objectType, URLFinder finder) { return (URLFinder) s_finders.put(objectType, finder); diff --git a/ccm-core/src/com/arsdigita/toolbox/ui/OIDParameter.java b/ccm-core/src/com/arsdigita/toolbox/ui/OIDParameter.java index c8bf53dfc..65fcadc81 100755 --- a/ccm-core/src/com/arsdigita/toolbox/ui/OIDParameter.java +++ b/ccm-core/src/com/arsdigita/toolbox/ui/OIDParameter.java @@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletRequest; import com.arsdigita.persistence.OID; import com.arsdigita.bebop.parameters.ParameterModel; -/* +/** * A {@link com.arsdigita.bebop.parameters.ParameterModel} for an * {@link com.arsdigita.persistence.OID} * @@ -31,6 +31,7 @@ import com.arsdigita.bebop.parameters.ParameterModel; * @since Iteration 1 */ public class OIDParameter extends ParameterModel { + public OIDParameter(String name) { super(name); } diff --git a/ccm-core/src/com/arsdigita/web/OIDRedirectServlet.java b/ccm-core/src/com/arsdigita/web/OIDRedirectServlet.java index 2b5125faa..e6b3ff271 100755 --- a/ccm-core/src/com/arsdigita/web/OIDRedirectServlet.java +++ b/ccm-core/src/com/arsdigita/web/OIDRedirectServlet.java @@ -18,22 +18,39 @@ */ package com.arsdigita.web; +import com.arsdigita.kernel.URLService; +import com.arsdigita.kernel.NoValidURLException; +import com.arsdigita.kernel.URLFinderNotFoundException; +import com.arsdigita.persistence.OID; +import com.arsdigita.toolbox.ui.OIDParameter; + +import java.io.IOException; +import java.util.Map; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -import com.arsdigita.kernel.URLService; -import com.arsdigita.kernel.NoValidURLException; -import com.arsdigita.kernel.URLFinderNotFoundException; - -import com.arsdigita.persistence.OID; -import com.arsdigita.toolbox.ui.OIDParameter; -import java.util.Map; - import org.apache.log4j.Logger; +/** + * Servlet to redirect an OID based request to a complete url in an application's + * url tree and is one of the basic servlets required by any ccm-core application + * instance to work correctly. + * + * It has to be declared in an application web.xml, typically: + * + * oid-redirect + * com.arsdigita.web.OIDRedirectServlet + * + * .... + * .... + * + * oid-redirect + * /redirect/* + * + * + */ public class OIDRedirectServlet extends BaseServlet { private static final Logger s_log = @@ -48,6 +65,8 @@ public class OIDRedirectServlet extends BaseServlet { OID oid = null; try { + // extract parameter named OID_PARAM (="oid") from sreq object + // searches for something like oid=Article-id-167013 oid = (OID) param.transformValue(sreq); } catch (Exception e) { // invalid OID value, return 400 Bad Request @@ -65,6 +84,7 @@ public class OIDRedirectServlet extends BaseServlet { sresp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } + if (s_log.isDebugEnabled()) { s_log.debug("Tried to read non encoded OID, result: " + oid); } @@ -82,6 +102,7 @@ public class OIDRedirectServlet extends BaseServlet { String context = sreq.getParameter("context"); String url = URLService.locate(oid, context); + /* Addition by JensP: */ Map parameters = sreq.getParameterMap(); StringBuilder urlParams = new StringBuilder(); for (Map.Entry entry : parameters.entrySet()) { @@ -98,20 +119,21 @@ public class OIDRedirectServlet extends BaseServlet { } } } - url = url.concat(urlParams.toString()); + /* JensP END */ if (s_log.isDebugEnabled()) { s_log.debug("Redirecting oid " + oid + " to " + url); } - throw new RedirectSignal(url, false); + } catch (URLFinderNotFoundException ex) { if (s_log.isDebugEnabled()) { s_log.debug("No URL finder for oid " + oid); } sresp.sendError(HttpServletResponse.SC_NOT_FOUND); return; + } catch (NoValidURLException ex) { if (s_log.isDebugEnabled()) { s_log.debug("No URL for oid " + oid); diff --git a/ccm-core/web/WEB-INF/web.ccm-core.xml b/ccm-core/web/WEB-INF/web.ccm-core.xml index 33f670d73..af8a3ca8b 100644 --- a/ccm-core/web/WEB-INF/web.ccm-core.xml +++ b/ccm-core/web/WEB-INF/web.ccm-core.xml @@ -4,19 +4,20 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> - + CCM Content and Collaboration Management log4j-conf-file @@ -24,20 +25,18 @@ - + com.arsdigita.web.CCMApplicationContextListener - - + reg com.arsdigita.web.ContextRegistrationServlet @@ -95,10 +94,11 @@ - content-section com.arsdigita.cms.ContentSectionServlet @@ -140,8 +140,10 @@ @@ -185,8 +187,10 @@ @@ -220,8 +224,9 @@ @@ -260,8 +265,9 @@ diff --git a/ccm-ldn-subsite/src/com/arsdigita/london/subsite/dispatcher/SubsiteItemTemplateResolver.java b/ccm-ldn-subsite/src/com/arsdigita/london/subsite/dispatcher/SubsiteItemTemplateResolver.java index 4516d9967..a75eb32f8 100755 --- a/ccm-ldn-subsite/src/com/arsdigita/london/subsite/dispatcher/SubsiteItemTemplateResolver.java +++ b/ccm-ldn-subsite/src/com/arsdigita/london/subsite/dispatcher/SubsiteItemTemplateResolver.java @@ -22,14 +22,16 @@ import com.arsdigita.cms.Folder; import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.TemplateManager; -import javax.servlet.http.HttpServletRequest; - import com.arsdigita.cms.dispatcher.DefaultTemplateResolver; import com.arsdigita.util.ResourceManager; -import java.io.File; + import com.arsdigita.london.subsite.Site; import com.arsdigita.london.subsite.Subsite; +import java.io.File; + +import javax.servlet.http.HttpServletRequest; + import org.apache.log4j.Logger;