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.CMSPage;
import com.arsdigita.cms.dispatcher.SimpleCache; import com.arsdigita.cms.dispatcher.SimpleCache;
import com.arsdigita.cms.ui.CMSApplicationPage; import com.arsdigita.cms.ui.CMSApplicationPage;
import com.arsdigita.cms.ui.CMSItemSearchPage;
import com.arsdigita.cms.ui.CMSSearchResultRedirector; import com.arsdigita.cms.ui.CMSSearchResultRedirector;
// Old version (dispatcher based) of CMSItemSearchPage
import com.arsdigita.cms.ui.ItemSearchPage; import com.arsdigita.cms.ui.ItemSearchPage;
import com.arsdigita.cms.ui.contentcenter.MainPage; import com.arsdigita.cms.ui.contentcenter.MainPage;
import com.arsdigita.developersupport.DeveloperSupport; import com.arsdigita.developersupport.DeveloperSupport;
@ -37,21 +35,21 @@ import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating; import com.arsdigita.templating.Templating;
import com.arsdigita.ui.login.LoginHelper; import com.arsdigita.ui.login.LoginHelper;
import com.arsdigita.util.Assert; 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 com.arsdigita.xml.Document;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -98,11 +96,11 @@ public class ContentCenterServlet extends BaseApplicationServlet {
} }
// DEPRECATED STUFF for servlet internally process pages, maybe required // DEPRECATED STUFF for servlet internally process pages, maybe required
// for JSP extension. // for JSP extension.
// m_trailingSlashList = new ArrayList(); // m_trailingSlashList = new ArrayList();
// requireTrailingSlash(""); // requireTrailingSlash("");
// NEW STUFF here used to process the pages in this servlet // NEW STUFF here used to process the pages in this servlet
// Addresses previously noted in WEB-INF/resources/content-center-map.xml // Addresses previously noted in WEB-INF/resources/content-center-map.xml
// Obviously not required. // Obviously not required.
addPage("/", new MainPage()); // index page at address ~/cc addPage("/", new MainPage()); // index page at address ~/cc
@ -113,11 +111,11 @@ public class ContentCenterServlet extends BaseApplicationServlet {
addPage("/searchredirect", new CMSSearchResultRedirector()); addPage("/searchredirect", new CMSSearchResultRedirector());
// STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not // STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not
// handled by the this servlet directly. // handled by the this servlet directly.
/** Set Template base path for JSP's */ /** Set Template base path for JSP's */
// ToDo: Make it configurable by an appropriate config registry entry! // ToDo: Make it configurable by an appropriate config registry entry!
// m_templatePath = CMS.getConfig().getTemplateRoot(); // m_templatePath = CMS.getConfig().getTemplateRoot();
m_templatePath = "/templates/ccm-cms/content-center"; m_templatePath = "/templates/ccm-cms/content-center";
Assert.exists(m_templatePath, String.class); Assert.exists(m_templatePath, String.class);
Assert.isTrue(m_templatePath.startsWith("/"), Assert.isTrue(m_templatePath.startsWith("/"),
@ -206,7 +204,7 @@ public class ContentCenterServlet extends BaseApplicationServlet {
cmsPage.dispatch(sreq, sresp, ctx); cmsPage.dispatch(sreq, sresp, ctx);
} else { } else {
final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page; final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page;
cmsAppPage.init(sreq,sresp,app); cmsAppPage.init(sreq, sresp, app);
// Serve the page. // Serve the page.
final Document doc = cmsAppPage.buildDocument(sreq, sresp); final Document doc = cmsAppPage.buildDocument(sreq, sresp);
@ -232,8 +230,7 @@ public class ContentCenterServlet extends BaseApplicationServlet {
rd.forward(sreq, sresp); rd.forward(sreq, sresp);
} else { } else {
// String requestUri = sreq.getRequestURI(); // String requestUri = sreq.getRequestURI();
sresp.sendError(404, sreq.getRequestURI() + sresp.sendError(404, sreq.getRequestURI() + " not found on this server.");
" 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 * - 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
@ -101,15 +100,13 @@ import org.apache.log4j.Logger;
* @author Sören Bernstein <sbernstein@quasiweb.de> * @author Sören Bernstein <sbernstein@quasiweb.de>
* @author Peter Boy <pboy@barkhof.uni-bremen.de> * @author Peter Boy <pboy@barkhof.uni-bremen.de>
*/ */
public class ContentSectionServlet extends BaseApplicationServlet { public class ContentSectionServlet extends BaseApplicationServlet {
/** Creates a s_logging category with name = full name of class */ /** Creates a s_logging category with name = full name of class */
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 */
@ -124,23 +121,17 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public static final String XML_SUFFIX = ".xml"; public static final String XML_SUFFIX = ".xml";
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 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 */ /** cache the content items */
private static Map s_itemURLCacheMap = null; private static Map s_itemURLCacheMap = null;
private static boolean s_cacheItems = true; private static 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 // Probably compatibility stuff, based on dispatcher
@ -178,11 +169,10 @@ public class ContentSectionServlet extends BaseApplicationServlet {
if (resolverName == null) { if (resolverName == null) {
m_resolver = Web.getConfig().getApplicationFileResolver(); m_resolver = Web.getConfig().getApplicationFileResolver();
} else { } else {
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 + s_log.debug("Template path is " + m_templatePath + " with resolver " + m_resolver.getClass().getName());
" with resolver " + m_resolver.getClass().getName());
} }
// NEW STUFF here used to process the pages in this servlet // NEW STUFF here used to process the pages in this servlet
@ -200,7 +190,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
* {@see com.arsdigita.web.BaseApplicationServlet#doService * {@see com.arsdigita.web.BaseApplicationServlet#doService
* (HttpServletRequest, HttpServletResponse, Application)} * (HttpServletRequest, HttpServletResponse, Application)}
*/ */
protected void doService( HttpServletRequest sreq, protected void doService(HttpServletRequest sreq,
HttpServletResponse sresp, HttpServletResponse sresp,
Application app) Application app)
throws ServletException, IOException { throws ServletException, IOException {
@ -223,13 +213,14 @@ public class ContentSectionServlet extends BaseApplicationServlet {
s_log.info("Resolving item URL " + url); s_log.info("Resolving item URL " + url);
} }
final ItemResolver itemResolver = getItemResolver(section); final ItemResolver itemResolver = getItemResolver(section);
final ContentItem item = getItem(section, url, itemResolver);
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// Prepare NEW style servlet based bebpo page service // Prepare NEW style servlet based bebpo page service
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
String pathInfo = sreq.getPathInfo(); String pathInfo = sreq.getPathInfo();
final ContentItem item = getItem(section, pathInfo, itemResolver);
Assert.exists(pathInfo, "String pathInfo"); Assert.exists(pathInfo, "String pathInfo");
if (pathInfo.length() > 1 && pathInfo.endsWith("/")) { if (pathInfo.length() > 1 && pathInfo.endsWith("/")) {
/* NOTE: ServletAPI specifies, pathInfo may be empty or will /* NOTE: ServletAPI specifies, pathInfo may be empty or will
@ -259,7 +250,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
cmsPage.dispatch(sreq, sresp, ctx); cmsPage.dispatch(sreq, sresp, ctx);
} else { } else {
final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page; final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page;
cmsAppPage.init(sreq,sresp,app); cmsAppPage.init(sreq, sresp, app);
// Serve the page. // Serve the page.
final Document doc = cmsAppPage.buildDocument(sreq, sresp); final Document doc = cmsAppPage.buildDocument(sreq, sresp);
@ -281,6 +272,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public void beforeCommit(TransactionContext txn) { public void beforeCommit(TransactionContext txn) {
Assert.fail("uncommittable transaction"); Assert.fail("uncommittable transaction");
} }
}); });
Kernel.getContext().getTransaction().setCommitRequested(false); Kernel.getContext().getTransaction().setCommitRequested(false);
@ -310,7 +302,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
s_log.debug("Got dispatcher " + rd); s_log.debug("Got dispatcher " + rd);
} }
sreq = DispatcherHelper.restoreOriginalRequest(sreq); sreq = DispatcherHelper.restoreOriginalRequest(sreq);
rd.forward(sreq,sresp); rd.forward(sreq, sresp);
} else { } else {
// sresp.sendError(404, packageURL + " not found on this server."); // sresp.sendError(404, packageURL + " not found on this server.");
String requestUri = sreq.getRequestURI(); // same as ctx.getRemainingURLPart() String requestUri = sreq.getRequestURI(); // same as ctx.getRemainingURLPart()
@ -319,7 +311,6 @@ public class ContentSectionServlet extends BaseApplicationServlet {
} }
} // END doService } // END doService
/** /**
* *
* @param sreq * @param sreq
@ -373,8 +364,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
Date endDate = cycle.getEndDate(); Date endDate = cycle.getEndDate();
if (endDate != null) { if (endDate != null) {
int maxAge = (int) ((endDate.getTime() - int maxAge = (int) ((endDate.getTime() - System.currentTimeMillis()) / 1000l);
System.currentTimeMillis()) / 1000l);
if (maxAge < expires) { if (maxAge < expires) {
expires = maxAge; expires = maxAge;
} }
@ -386,8 +376,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
// this page to be publically cached // this page to be publically cached
if (s_cacheItems && item.isLiveVersion()) { if (s_cacheItems && item.isLiveVersion()) {
SecurityManager sm = new SecurityManager(section); SecurityManager sm = new SecurityManager(section);
if (sm.canAccess if (sm.canAccess((User) null, SecurityManager.PUBLIC_PAGES, item)) {
((User) null, SecurityManager.PUBLIC_PAGES, item)) {
DispatcherHelper.cacheForWorld(sresp, expires); DispatcherHelper.cacheForWorld(sresp, expires);
} else { } else {
DispatcherHelper.cacheForUser(sresp, expires); DispatcherHelper.cacheForUser(sresp, expires);
@ -397,7 +386,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
} }
//use ContentItemDispatcher //use ContentItemDispatcher
m_disp.dispatch(sreq,sresp,ctx); m_disp.dispatch(sreq, sresp, ctx);
} }
/** /**
@ -441,7 +430,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
String path = section.getPath(); String path = section.getPath();
ItemResolver ir = (ItemResolver) s_itemResolverCache.get(path); ItemResolver ir = (ItemResolver) s_itemResolverCache.get(path);
if ( ir == null ) { if (ir == null) {
ir = section.getItemResolver(); ir = section.getItemResolver();
s_itemResolverCache.put(path, ir); s_itemResolverCache.put(path, ir);
} }
@ -467,7 +456,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
//first sanitize the url //first sanitize the url
if (url.endsWith(XML_SUFFIX)) { if (url.endsWith(XML_SUFFIX)) {
request.setAttribute(XML_MODE, Boolean.TRUE); request.setAttribute(XML_MODE, Boolean.TRUE);
s_log.debug ("StraightXML Requested"); s_log.debug("StraightXML Requested");
url = "/" + url.substring(0, url.length() - XML_SUFFIX.length()); url = "/" + url.substring(0, url.length() - XML_SUFFIX.length());
} else { } else {
request.setAttribute(XML_MODE, Boolean.FALSE); request.setAttribute(XML_MODE, Boolean.FALSE);
@ -502,8 +491,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
item = itemResolver.getItem(section, url, CMSDispatcher.PREVIEW); item = itemResolver.getItem(section, url, CMSDispatcher.PREVIEW);
if (item != null) { if (item != null) {
hasPermission = sm.canAccess hasPermission = sm.canAccess(request, SecurityManager.PREVIEW_PAGES, item);
(request, SecurityManager.PREVIEW_PAGES, item);
} }
} else { } else {
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
@ -513,8 +501,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
//check if this item is in the cache //check if this item is in the cache
//we only cache live items //we only cache live items
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Trying to get content item for URL " + url + s_log.debug("Trying to get content item for URL " + url + " from cache");
" from cache");
} }
// Get the negotiated locale // Get the negotiated locale
@ -525,9 +512,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
if (item == null) { if (item == null) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug s_log.debug("Did not find content item in cache, so trying " + "to retrieve and cache...");
("Did not find content item in cache, so trying " +
"to retrieve and cache...");
} }
//item not cached, so retreive it and cache it //item not cached, so retreive it and cache it
item = itemResolver.getItem(section, url, ContentItem.LIVE); item = itemResolver.getItem(section, url, ContentItem.LIVE);
@ -537,8 +522,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
} }
if (s_log.isDebugEnabled() && item != null) { if (s_log.isDebugEnabled() && item != null) {
s_log.debug s_log.debug("Sanity check: item.getPath() is " + item.getPath());
("Sanity check: item.getPath() is " + item.getPath());
} }
if (item != null) { if (item != null) {
@ -551,7 +535,6 @@ public class ContentSectionServlet extends BaseApplicationServlet {
item); item);
if (hasPermission) { if (hasPermission) {
} }
} }
} }
@ -577,8 +560,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
} }
} }
if (!hasPermission && if (!hasPermission && !LocalRequestPassword.validLocalRequest(request)) {
!LocalRequestPassword.validLocalRequest(request)) {
// first, check if the user is logged-in // first, check if the user is logged-in
// if he isn't, give him a chance to do so... // 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 // synchronize access to the item-url cache
private static synchronized void itemURLCachePut(ContentSection section, private static synchronized void itemURLCachePut(ContentSection section,
String sURL, String sURL,
String lang, String lang,
@ -659,8 +640,7 @@ public class ContentSectionServlet extends BaseApplicationServlet {
return null; return null;
} else { } else {
try { try {
return (ContentItem) DomainObjectFactory.newInstance return (ContentItem) DomainObjectFactory.newInstance(new OID(ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
(new OID(ContentItem.BASE_DATA_OBJECT_TYPE, itemID));
} catch (DataObjectNotFoundException donfe) { } catch (DataObjectNotFoundException donfe) {
return null; return null;
} }
@ -695,9 +675,9 @@ public class ContentSectionServlet extends BaseApplicationServlet {
public static boolean checkAdminAccess(HttpServletRequest request, public static boolean checkAdminAccess(HttpServletRequest request,
ContentSection section) { ContentSection section) {
User user ; User user;
KernelContext kernelContext = Kernel.getContext(); KernelContext kernelContext = Kernel.getContext();
if ( kernelContext.getParty() instanceof User ) { if (kernelContext.getParty() instanceof User) {
user = (User) kernelContext.getParty(); user = (User) kernelContext.getParty();
} else { } else {
// Should not happen, at this stage the user has to be logged in. // Should not happen, at this stage the user has to be logged in.

View File

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

View File

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

View File

@ -39,6 +39,8 @@ import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.SessionManager;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal; 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 Table resultsTable;
private final Paginator paginator; private final Paginator paginator;
private final StringParameter queryParam; private final StringParameter queryParam;
private final List<String> queryFields = new ArrayList<String>();
private final Submit submit; private final Submit submit;
private final static CMSConfig CMS_CONFIG = CMSConfig.getInstance(); 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)); 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 class ResultsTable extends Table {
private static final String TABLE_COL_TITLE = "title"; private static final String TABLE_COL_TITLE = "title";
@ -181,15 +188,26 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
final ContentType type = new ContentType(typeId); final ContentType type = new ContentType(typeId);
collection.set(state, session.retrieve(type.getClassName())); collection.set(state, session.retrieve(type.getClassName()));
} }
((DataCollection)collection.get(state)).addFilter("version = 'draft'"); ((DataCollection) collection.get(state)).addFilter("version = 'draft'");
((DataCollection)collection.get(state)).addFilter("section is not null"); ((DataCollection) collection.get(state)).addFilter("section is not null");
final String query = (String) state.getValue(queryParam); final String query = (String) state.getValue(queryParam);
if ((query != null) && !query.isEmpty()) { if ((query != null) && !query.isEmpty()) {
((DataCollection) collection.get(state)).addFilter(String.format( final StringBuffer buffer = new StringBuffer(String.format(
"((lower(%s) like lower('%%%s%%')) or (lower(%s) like lower('%%%s%%')))", "((lower(%s) like lower('%%%s%%')) or (lower(%s) like lower('%%%s%%'))",
ContentItem.NAME, query, ContentItem.NAME, query,
ContentPage.TITLE, 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"); ((DataCollection) collection.get(state)).addOrder("title asc, name asc");
@ -306,9 +324,11 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
return link; return link;
} }
} }
protected Submit getSubmit() { protected Submit getSubmit() {
return submit; return submit;
} }
} }

View File

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

View File

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