Some fixes for the ongoing refactoring/removal of the old dispatcher code.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2077 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-02-25 13:18:40 +00:00
parent a4a94953c4
commit 6c79fc15a9
7 changed files with 140 additions and 122 deletions

View File

@ -22,9 +22,7 @@ import com.arsdigita.bebop.Page;
import com.arsdigita.cms.dispatcher.CMSPage;
import com.arsdigita.cms.dispatcher.SimpleCache;
import com.arsdigita.cms.ui.CMSApplicationPage;
import com.arsdigita.cms.ui.CMSItemSearchPage;
import com.arsdigita.cms.ui.CMSSearchResultRedirector;
// Old version (dispatcher based) of CMSItemSearchPage
import com.arsdigita.cms.ui.ItemSearchPage;
import com.arsdigita.cms.ui.contentcenter.MainPage;
import com.arsdigita.developersupport.DeveloperSupport;
@ -37,21 +35,21 @@ import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating;
import com.arsdigita.ui.login.LoginHelper;
import com.arsdigita.util.Assert;
import com.arsdigita.web.*;
import com.arsdigita.web.Application;
import com.arsdigita.web.ApplicationFileResolver;
import com.arsdigita.web.BaseApplicationServlet;
import com.arsdigita.web.LoginSignal;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Document;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
/**
@ -232,8 +230,7 @@ public class ContentCenterServlet extends BaseApplicationServlet {
rd.forward(sreq, sresp);
} else {
// String requestUri = sreq.getRequestURI();
sresp.sendError(404, sreq.getRequestURI() +
" not found on this server.");
sresp.sendError(404, sreq.getRequestURI() + " not found on this server.");
}
}

View File

@ -88,7 +88,6 @@ import org.apache.log4j.Logger;
* - Refactor content item UI bebop ApplicationPage or PageFactory instead of
* legacy infected sitenode / package dispatchers.
*/
/**
* Content Section's Application Servlet according CCM core web application
* structure {@see com.arsdigita.web.Application} implements the content
@ -101,13 +100,11 @@ import org.apache.log4j.Logger;
* @author Sören Bernstein <sbernstein@quasiweb.de>
* @author Peter Boy <pboy@barkhof.uni-bremen.de>
*/
public class ContentSectionServlet extends BaseApplicationServlet {
/** Creates a s_logging category with name = full name of class */
private static final Logger s_log =
Logger.getLogger(ContentSectionServlet.class);
/** Stringarray of file name patterns for index files. */
private static final String[] WELCOME_FILES = new String[]{
"index.jsp", "index.html"
@ -124,23 +121,17 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public static final String XML_SUFFIX = ".xml";
public static final String XML_MODE = "xmlMode";
public static final String MEDIA_TYPE = "templateContext";
private static final String CACHE_KEY_DELIMITER = "%";
private ContentItemDispatcher m_disp = new ContentItemDispatcher();
public static Map s_itemResolverCache = Collections
.synchronizedMap(new HashMap());
/** cache the content items */
private static Map s_itemURLCacheMap = null;
private static boolean s_cacheItems = true;
// NEW STUFF here used to process the pages in this servlet
/** URL (pathinfo) -> Page object mapping. Based on it (and the http
* request url) the doService method selects a page to display */
private final Map m_pages = new HashMap();
/** Path to directory containg ccm-cms template (jsp) files */
private String m_templatePath;
// Probably compatibility stuff, based on dispatcher
@ -181,8 +172,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
m_resolver = (ApplicationFileResolver) Classes.newInstance(resolverName);
}
if (s_log.isDebugEnabled()) {
s_log.debug("Template path is " + m_templatePath +
" with resolver " + m_resolver.getClass().getName());
s_log.debug("Template path is " + m_templatePath + " with resolver " + m_resolver.getClass().getName());
}
// NEW STUFF here used to process the pages in this servlet
@ -223,13 +213,14 @@ public class ContentSectionServlet extends BaseApplicationServlet {
s_log.info("Resolving item URL " + url);
}
final ItemResolver itemResolver = getItemResolver(section);
final ContentItem item = getItem(section, url, itemResolver);
// ////////////////////////////////////////////////////////////////////
// Prepare NEW style servlet based bebpo page service
// ////////////////////////////////////////////////////////////////////
String pathInfo = sreq.getPathInfo();
final ContentItem item = getItem(section, pathInfo, itemResolver);
Assert.exists(pathInfo, "String pathInfo");
if (pathInfo.length() > 1 && pathInfo.endsWith("/")) {
/* NOTE: ServletAPI specifies, pathInfo may be empty or will
@ -281,6 +272,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public void beforeCommit(TransactionContext txn) {
Assert.fail("uncommittable transaction");
}
});
Kernel.getContext().getTransaction().setCommitRequested(false);
@ -319,7 +311,6 @@ public class ContentSectionServlet extends BaseApplicationServlet {
}
} // END doService
/**
*
* @param sreq
@ -373,8 +364,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
Date endDate = cycle.getEndDate();
if (endDate != null) {
int maxAge = (int) ((endDate.getTime() -
System.currentTimeMillis()) / 1000l);
int maxAge = (int) ((endDate.getTime() - System.currentTimeMillis()) / 1000l);
if (maxAge < expires) {
expires = maxAge;
}
@ -386,8 +376,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
// this page to be publically cached
if (s_cacheItems && item.isLiveVersion()) {
SecurityManager sm = new SecurityManager(section);
if (sm.canAccess
((User) null, SecurityManager.PUBLIC_PAGES, item)) {
if (sm.canAccess((User) null, SecurityManager.PUBLIC_PAGES, item)) {
DispatcherHelper.cacheForWorld(sresp, expires);
} else {
DispatcherHelper.cacheForUser(sresp, expires);
@ -502,8 +491,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
item = itemResolver.getItem(section, url, CMSDispatcher.PREVIEW);
if (item != null) {
hasPermission = sm.canAccess
(request, SecurityManager.PREVIEW_PAGES, item);
hasPermission = sm.canAccess(request, SecurityManager.PREVIEW_PAGES, item);
}
} else {
if (s_log.isInfoEnabled()) {
@ -513,8 +501,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
//check if this item is in the cache
//we only cache live items
if (s_log.isDebugEnabled()) {
s_log.debug("Trying to get content item for URL " + url +
" from cache");
s_log.debug("Trying to get content item for URL " + url + " from cache");
}
// Get the negotiated locale
@ -525,9 +512,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
if (item == null) {
if (s_log.isDebugEnabled()) {
s_log.debug
("Did not find content item in cache, so trying " +
"to retrieve and cache...");
s_log.debug("Did not find content item in cache, so trying " + "to retrieve and cache...");
}
//item not cached, so retreive it and cache it
item = itemResolver.getItem(section, url, ContentItem.LIVE);
@ -537,8 +522,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
}
if (s_log.isDebugEnabled() && item != null) {
s_log.debug
("Sanity check: item.getPath() is " + item.getPath());
s_log.debug("Sanity check: item.getPath() is " + item.getPath());
}
if (item != null) {
@ -551,7 +535,6 @@ public class ContentSectionServlet extends BaseApplicationServlet {
item);
if (hasPermission) {
}
}
}
@ -577,8 +560,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
}
}
if (!hasPermission &&
!LocalRequestPassword.validLocalRequest(request)) {
if (!hasPermission && !LocalRequestPassword.validLocalRequest(request)) {
// first, check if the user is logged-in
// if he isn't, give him a chance to do so...
@ -600,7 +582,6 @@ public class ContentSectionServlet extends BaseApplicationServlet {
}
// synchronize access to the item-url cache
private static synchronized void itemURLCachePut(ContentSection section,
String sURL,
String lang,
@ -659,8 +640,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
return null;
} else {
try {
return (ContentItem) DomainObjectFactory.newInstance
(new OID(ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
return (ContentItem) DomainObjectFactory.newInstance(new OID(ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
} catch (DataObjectNotFoundException donfe) {
return null;
}

View File

@ -84,6 +84,7 @@ public class CMSItemSearchPage extends CMSApplicationPage {
addGlobalStateParam(new IntegerParameter("lastTab"));
addGlobalStateParam(new BooleanParameter("disableCreatePane"));
addGlobalStateParam(new BooleanParameter("editAfterCreate"));
addGlobalStateParam(new StringParameter("queryField"));
m_sectionId = new BigDecimalParameter(CONTENT_SECTION);
addGlobalStateParam(m_sectionId);
@ -136,6 +137,10 @@ public class CMSItemSearchPage extends CMSApplicationPage {
m_create.setEditAfterCreate((Boolean) state.getValue(new BooleanParameter("editAfterCreate")));
}
if (state.getValue(new StringParameter("queryField")) != null) {
m_flatBrowse.addQueryField((String) state.getValue(new StringParameter("queryField")));
}
// if (m_lastTab != m_tabbedPane.getSelectedIndex(state)) {
// m_lastTab = m_tabbedPane.getSelectedIndex(state);
// return;

View File

@ -115,6 +115,7 @@ class ItemSearchCreateItemPane extends CMSContainer
*/
public ItemSearchCreateItemPane(final ItemSearchPage parent) {
super();
m_model = new ParameterSingleSelectionModel(new BigDecimalParameter(FOLDER_ID));
m_folderSel = new FolderSelectionModel(m_model);
m_typeSel = new ParameterSingleSelectionModel(new BigDecimalParameter(CONTENT_TYPE_ID));
init();
@ -126,6 +127,7 @@ class ItemSearchCreateItemPane extends CMSContainer
*/
public ItemSearchCreateItemPane(final CMSItemSearchPage parent) {
super();
m_model = new ParameterSingleSelectionModel(new BigDecimalParameter(FOLDER_ID));
m_folderSel = new FolderSelectionModel(m_model);
m_typeSel = new ParameterSingleSelectionModel(new BigDecimalParameter(CONTENT_TYPE_ID));
init();
@ -145,7 +147,7 @@ class ItemSearchCreateItemPane extends CMSContainer
// m_newItem = new SectionNewItemForm("newItem");
m_model = new ParameterSingleSelectionModel(new BigDecimalParameter(FOLDER_ID));
//m_model = new ParameterSingleSelectionModel(new BigDecimalParameter(FOLDER_ID));
// m_folderSel = new FolderSelectionModel(m_model);
this.setIdAttr("folder-new-item");

View File

@ -39,6 +39,8 @@ import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
*
@ -54,6 +56,7 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
private final Table resultsTable;
private final Paginator paginator;
private final StringParameter queryParam;
private final List<String> queryFields = new ArrayList<String>();
private final Submit submit;
private final static CMSConfig CMS_CONFIG = CMSConfig.getInstance();
@ -113,6 +116,10 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
state.setValue(new StringParameter(ItemSearchPopup.QUERY), data.get(QUERY_PARAM));
}
public void addQueryField(final String queryField) {
queryFields.add(queryField);
}
private class ResultsTable extends Table {
private static final String TABLE_COL_TITLE = "title";
@ -186,10 +193,21 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
final String query = (String) state.getValue(queryParam);
if ((query != null) && !query.isEmpty()) {
((DataCollection) collection.get(state)).addFilter(String.format(
"((lower(%s) like lower('%%%s%%')) or (lower(%s) like lower('%%%s%%')))",
final StringBuffer buffer = new StringBuffer(String.format(
"((lower(%s) like lower('%%%s%%')) or (lower(%s) like lower('%%%s%%'))",
ContentItem.NAME, query,
ContentPage.TITLE, query));
for (String field : queryFields) {
buffer.append(String.format(" or (lower(%s) like lower('%%%s%%'))", field, query));
}
buffer.append(')');
((DataCollection) collection.get(state)).addFilter(buffer.toString());
// ((DataCollection) collection.get(state)).addFilter(String.format(
// "((lower(%s) like lower('%%%s%%')) or (lower(%s) like lower('%%%s%%')))",
// ContentItem.NAME, query,
// ContentPage.TITLE, query));
}
((DataCollection) collection.get(state)).addOrder("title asc, name asc");
@ -306,9 +324,11 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
return link;
}
}
protected Submit getSubmit() {
return submit;
}
}

View File

@ -84,6 +84,7 @@ public class ItemSearchPage extends CMSPage {
addGlobalStateParam(new IntegerParameter("lastTab"));
addGlobalStateParam(new BooleanParameter("disableCreatePane"));
addGlobalStateParam(new BooleanParameter("editAfterCreate"));
addGlobalStateParam(new StringParameter("queryField"));
m_sectionId = new BigDecimalParameter(CONTENT_SECTION);
addGlobalStateParam(m_sectionId);
@ -136,6 +137,10 @@ public class ItemSearchPage extends CMSPage {
m_create.setEditAfterCreate((Boolean) state.getValue(new BooleanParameter("editAfterCreate")));
}
if (state.getValue(new StringParameter("queryField")) != null) {
m_flatBrowse.addQueryField((String) state.getValue(new StringParameter("queryField")));
}
// if (m_lastTab != m_tabbedPane.getSelectedIndex(state)) {
// m_lastTab = m_tabbedPane.getSelectedIndex(state);
// return;

View File

@ -78,6 +78,7 @@ public class ItemSearchWidget extends FormSection
private String m_searchName;
private String m_clearName;
private Folder m_defaultCreationFolder;
private String m_queryField;
private ParameterModel m_model;
private ParameterModel m_searchModel;
private boolean disableCreatePane = false;
@ -284,6 +285,10 @@ public class ItemSearchWidget extends FormSection
params.setParameter("defaultCreationFolder", m_defaultCreationFolder.getOID().toString());
}
if (m_queryField != null) {
params.setParameter("queryField", m_queryField);
}
String searchURL = ContentCenterServlet.getURLStubForClass(
ItemSearchPage.class.getName());
s_log.debug("Search URL stub is: " + searchURL);
@ -507,6 +512,10 @@ public class ItemSearchWidget extends FormSection
m_defaultCreationFolder = folder;
}
public void setQueryField(final String queryField) {
m_queryField = queryField;
}
public void publishCreatedItem(final FormData data, final ContentItem item) {
final String publishStr = data.getString(ItemSearchWidget.PUBLISH);
final Boolean publish = Boolean.valueOf(publishStr);