Code Aufräumen nach Umstellung ContentCenter auf Servlet basierte Seiten statt Dispatcher.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2050 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2013-01-26 12:33:20 +00:00
parent 97bdd93d1c
commit 5764020eab
5 changed files with 73 additions and 161 deletions

View File

@ -20,7 +20,7 @@
package com.arsdigita.cms;
import com.arsdigita.bebop.Page;
import com.arsdigita.cms.dispatcher.ResourceHandler;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.SimpleCache;
import com.arsdigita.cms.ui.contentcenter.MainPage;
import com.arsdigita.developersupport.DeveloperSupport;
@ -37,7 +37,6 @@ import com.arsdigita.web.*;
import com.arsdigita.xml.Document;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -69,7 +68,7 @@ public class ContentCenterServlet extends BaseApplicationServlet {
"/WEB-INF/resources/content-center-old-map.xml";
/** Mapping between a relative URL and the class name of a ResourceHandler.*/
private static HashMap s_pageClasses = ContentCenterSetup.getURLToClassMap();
// private static HashMap s_pageClasses = ContentCenterSetup.getURLToClassMap();
private static HashMap s_pageURLs = ContentCenterSetup.getClassToURLMap();
/** Instantiated ResourceHandlers cache. This allows for lazy loading. */
@ -205,7 +204,6 @@ public class ContentCenterServlet extends BaseApplicationServlet {
}
// ResourceHandler page = getResource(url);
final Page page = (Page) m_pages.get(pathInfo);
if ( page != null ) {
@ -271,6 +269,7 @@ public class ContentCenterServlet extends BaseApplicationServlet {
* Service Method returns the URL stub for the class name,
* can return null if not mapped
*/
// Currently still in use by c.ad.cms.ui.ItemSearchWidget
public static String getURLStubForClass(String classname) {
s_log.debug("Getting URL Stub for : " + classname);
Iterator itr = s_pageURLs.keySet().iterator();
@ -283,67 +282,13 @@ public class ContentCenterServlet extends BaseApplicationServlet {
return url;
}
/**
* Fetch a page based on the URL stub.
*
* @param url The URL stub following the site-node URL
* @return A ResourceHandler or null if none exists.
* @pre (url != null)
*/
protected ResourceHandler getResource(String url) throws ServletException {
// First check the pages cache for existing pages.
ResourceHandler page = (ResourceHandler) s_pages.get(url);
if ( page == null ) {
// Next check if the URL maps to a page class.
String pageClassName = (String) s_pageClasses.get(url);
if ( pageClassName != null ) {
Class pageClass;
try {
pageClass = Class.forName(pageClassName);
} catch (ClassNotFoundException e) {
s_log.error("error fetching class for ResourceHandler", e);
throw new ServletException(e);
}
// Try and instantiate the page.
try {
page = (ResourceHandler) pageClass.newInstance();
} catch (InstantiationException e) {
s_log.error("error instantiating a ResourceHandler", e);
throw new ServletException(e);
} catch (IllegalAccessException e) {
s_log.error("error instantiating a ResourceHandler", e);
throw new ServletException(e);
}
page.init();
s_pages.put(url, page);
}
}
return page;
}
/**
* Map a page to a URL.
*
* @param url The URL
* @param className The name of the ResourceHandler class
* @pre (url != null && className != null)
*/
protected void addResource(String url, String className) {
s_pageClasses.put(url, className);
s_pageURLs.put(className, url);
}
/**
* Release the page at the specified URL.
*
* @param url The URL
* @pre (url != null)
*/
// Currently still in use by c.ad.cms.dispatcher.Utilities
public static void releaseResource(String url) {
s_pages.remove(url);
}

View File

@ -18,38 +18,18 @@
*/
package com.arsdigita.cms.ui;
import com.arsdigita.cms.dispatcher.*;
import com.arsdigita.bebop.Bebop;
import com.arsdigita.bebop.Container;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.page.PageTransformer;
import com.arsdigita.cms.CMSExcursion;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ContentSectionServlet;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.developersupport.DeveloperSupport;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.User;
import com.arsdigita.kernel.permissions.PermissionDescriptor;
import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.persistence.OID;
import com.arsdigita.templating.PresentationManager;
import com.arsdigita.util.Assert;
import com.arsdigita.web.Application;
import com.arsdigita.xml.Document;
import com.arsdigita.xml.Element;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
@ -57,19 +37,18 @@ import org.apache.log4j.Logger;
// ////////////////////////////////////////////////////////////////////////////
//
// Currently under development as a replacement for CMSPage without the
// dispatcher mechanism but a new application style "pure" bebop page
// dispatcher mechanism but a new application style "pure" bebop pageElement
// served by an application servlet.
//
// ////////////////////////////////////////////////////////////////////////////
/**
* <p>A <tt>CMSPage</tt> is a Bebop {@link com.arsdigita.bebop.Page}
* implementation of the {@link com.arsdigita.cms.dispatcher.ResourceHandler}
* interface.</p>
* <p>A <tt>CMSApplicationPage</tt> is a Bebop {@link com.arsdigita.bebop.Page}
* implementation serving as a base for any CMS pageElement served by a servlet. </p>
*
* <p>It stores the current {@link com.arsdigita.cms.ContentSection} and, if
* applicable, the {@link com.arsdigita.cms.ContentItem} in the page state as
* applicable, the {@link com.arsdigita.cms.ContentItem} in the pageElement state as
* request local objects. Components that are part of the <tt>CMSPage</tt>
* may access these objects by calling:</p>
* <blockquote><code><pre>
@ -87,7 +66,7 @@ public class CMSApplicationPage extends Page {
/** The global assets URL stub XML parameter name. */
public final static String ASSETS = "ASSETS";
/** The XML page class. */
/** The XML pageElement class. */
public final static String PAGE_CLASS = "CMS";
/** Map of XML parameters */
@ -122,10 +101,11 @@ public class CMSApplicationPage extends Page {
}
/**
* Builds the page.
* Builds the pageElement.
*/
protected void buildPage() {
// Set the class attribute.
private void buildPage() {
// Set the class attribute value (down in SimpleComponent).
setClassAttr(PAGE_CLASS);
// Global XML params.
@ -151,10 +131,10 @@ public class CMSApplicationPage extends Page {
}
/**
* Finishes and locks the page. If the page is already locked, does nothing.
* Finishes and locks the pageElement. If the pageElement is already locked, does nothing.
*
* This method is called by the {@link com.arsdigita.dispatcher.Dispatcher}
* that initializes this page.
* that initializes this pageElement.
*/
public synchronized void init() {
s_log.debug("Initializing the page");
@ -194,7 +174,7 @@ public class CMSApplicationPage extends Page {
* @param request The HTTP request
* @return The current content section
*
* @deprecated use com.arsdigita.cms.CMS.getContext().getContentSection()
* @ deprecated use com.arsdigita.cms.CMS.getContext().getContentSection()
* instead
* Despite of being deprecated it can not be removed because it
* is required by the interface Resourcehandler which is
@ -202,27 +182,27 @@ public class CMSApplicationPage extends Page {
* On the other hand, if deprecated, implementing ResourceHandler
* may not be required
*/
public ContentSection getContentSection(HttpServletRequest request) {
// Resets all content sections associations.
// return ContentSectionDispatcher.getContentSection(request);
return ContentSectionServlet.getContentSection(request);
}
// public ContentSection getContentSection(HttpServletRequest request) {
// // Resets all content sections associations.
// // return ContentSectionDispatcher.getContentSection(request);
// return ContentSectionServlet.getContentSection(request);
// }
/**
* Fetch the request-local content section.
*
* @param state The page state
* @param state The pageElement state
* @return The current content section
*
* @deprecated use com.arsdigita.cms.CMS.getContext().getContentSection()
* @ deprecated use com.arsdigita.cms.CMS.getContext().getContentSection()
* instead
* Despite of being deprecated it can not be removed because it
* is required by ContentItemPage which extends CMSPage and
* uses this method.
*/
public ContentSection getContentSection(PageState state) {
return getContentSection(state.getRequest());
}
// public ContentSection getContentSection(PageState state) {
// return getContentSection(state.getRequest());
// }
/**
* Fetch the request-local content item.
@ -230,7 +210,7 @@ public class CMSApplicationPage extends Page {
* @param request The HTTP request
* @return The current content item
*
* @deprecated use com.arsdigita.cms.CMS.getContext().getContentItem()
* @ deprecated use com.arsdigita.cms.CMS.getContext().getContentItem()
* instead
* Despite of being deprecated it can not be removed because it
* is required by the interface Resourcehandler which is
@ -238,41 +218,41 @@ public class CMSApplicationPage extends Page {
* On the other hand, if deprecated, implementing ResourceHandler
* may not be required
*/
public ContentItem getContentItem(HttpServletRequest request) {
// resets all content item associations
return ContentSectionDispatcher.getContentItem(request);
}
// public ContentItem getContentItem(HttpServletRequest request) {
// // resets all content item associations
// return ContentSectionDispatcher.getContentItem(request);
// }
/**
* Fetch the request-local content item.
*
* @param state The page state
* @param state The pageElement state
* @return The current content item
* @deprecated use com.arsdigita.cms.CMS.getContext().getContentItem()
* @ deprecated use com.arsdigita.cms.CMS.getContext().getContentItem()
* instead.
* Despite of being deprecated it can not be removed because it
* is required by ContentItemPage which extends CMSPage and
* uses this method.
*/
public ContentItem getContentItem(PageState state) {
return getContentItem(state.getRequest());
}
// public ContentItem getContentItem(PageState state) {
// return getContentItem(state.getRequest());
// }
/**
* Services the Bebop page.
* Services the Bebop pageElement.
*
* @param request The servlet request object
* @param response the servlet response object
*
* @pre m_transformer != null
*/
public void dispatch(final HttpServletRequest request,
/* public void dispatch(final HttpServletRequest request,
final HttpServletResponse response // ,
// RequestContext actx
)
throws IOException, ServletException {
DeveloperSupport.startStage("CMSPage.dispatch: serve page");
DeveloperSupport.startStage("CMSPage.dispatch: serve pageElement");
CMSExcursion excursion = new CMSExcursion() {
public void excurse() throws IOException, ServletException {
@ -331,21 +311,35 @@ public class CMSApplicationPage extends Page {
try {
excursion.run();
} finally {
DeveloperSupport.endStage("CMSPage.dispatch: serve page");
DeveloperSupport.endStage("CMSPage.dispatch: serve pageElement");
}
}
} */
/**
* Overwrites bebop.Page#generateXMLHelper to add the name of the user
* logged in to the pageElement (displayed as part of the header).
* @param ps
* @param parent
* @return pageElement for use in generateXML
*/
@Override
protected Element generateXMLHelper(PageState ps, Document parent) {
Element page = super.generateXMLHelper(ps,parent);
/* Retain elements already included. */
Element pageElement = super.generateXMLHelper(ps,parent);
/* Add name of user logged in. */
// Note: There are at least 2 ways in the API to determin the user
// TODO: Check for differences, determin the best / recommended way and
// document it in the classes. Probably remove one ore the other
// way from the API if possible.
User user = (User) Kernel.getContext().getParty();
// User user = Web.getContext().getUser();
if ( user != null ) {
page.addAttribute("name",user.getDisplayName());
pageElement.addAttribute("name",user.getDisplayName());
}
return page;
return pageElement;
}
}

View File

@ -18,12 +18,16 @@
*/
package com.arsdigita.cms.ui;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.bebop.form.DHTMLEditor;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentSection;
/**
*
*
*/
public class CMSDHTMLEditor extends DHTMLEditor {
public CMSDHTMLEditor(String name) {

View File

@ -24,16 +24,14 @@ import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ui.CMSApplicationPage;
import com.arsdigita.cms.ui.GlobalNavigation;
import com.arsdigita.cms.ui.ItemSearch;
import com.arsdigita.cms.ui.WorkspaceContextBar;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.kernel.User;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.ui.DebugPanel;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Document;
import com.arsdigita.xml.Element;
import org.apache.log4j.Logger;
@ -49,7 +47,7 @@ import org.apache.log4j.Logger;
* @author Peter Boy (pboy@barkhof.uni-bremen.de)
* @version $Id: MainPage.java pboy $
*/
public class MainPage extends Page implements ActionListener {
public class MainPage extends CMSApplicationPage implements ActionListener {
private static final Logger s_log = Logger.getLogger(MainPage.class);
@ -109,7 +107,8 @@ public class MainPage extends Page implements ActionListener {
add(new DebugPanel());
/* Page complete, locked now. */
lock();
// lock();
init();
}
/**
@ -168,11 +167,8 @@ public class MainPage extends Page implements ActionListener {
* attribute to "CMS Admin." This implementation also adds tasks,
* content sections, and search panes.
*
*<p>
*
* Developers can override this method to add only the tabs they
* want, or to add additional tabs after the default CMS tabs are
* added.
* Developers can override this method to add only the tabs they want,
* or to add additional tabs after the default CMS tabs are added.
**/
protected TabbedPane createTabbedPane() {
TabbedPane pane = new TabbedPane();
@ -216,31 +212,4 @@ public class MainPage extends Page implements ActionListener {
}
}
/**
* Overwrites bebop.Page#generateXMLHelper to add the name of the user
* logged in to the page (displayed as part of the header).
* @param ps
* @param parent
* @return
*/
// ToDo: This code fragment is used by several pages of CMS package. It
// should be factored out into a kind of CMSBasePage, as it had been in
// the deprecated CMSPage.
// Should be checked when refactoring the content section pages to work
// as bebop pages without dispatcher mechanism and in new style application.
@Override
protected Element generateXMLHelper(PageState ps, Document parent) {
/* Retain elements already included. */
Element page = super.generateXMLHelper(ps,parent);
/* Add name of user logged in. */
User user = Web.getContext().getUser();
if ( user != null ) {
page.addAttribute("name",user.getDisplayName());
}
return page;
}
}