From 6c79fc15a98abf39f64e7371a61b264bfccb297c Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 25 Feb 2013 13:18:40 +0000 Subject: [PATCH] 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 --- .../arsdigita/cms/ContentCenterServlet.java | 61 ++++---- .../arsdigita/cms/ContentSectionServlet.java | 134 ++++++++---------- .../arsdigita/cms/ui/CMSItemSearchPage.java | 5 + .../cms/ui/ItemSearchCreateItemPane.java | 4 +- .../cms/ui/ItemSearchFlatBrowsePane.java | 44 ++++-- .../com/arsdigita/cms/ui/ItemSearchPage.java | 5 + .../arsdigita/cms/ui/ItemSearchWidget.java | 9 ++ 7 files changed, 140 insertions(+), 122 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/ContentCenterServlet.java b/ccm-cms/src/com/arsdigita/cms/ContentCenterServlet.java index c36796bf6..085ae6d8f 100644 --- a/ccm-cms/src/com/arsdigita/cms/ContentCenterServlet.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentCenterServlet.java @@ -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; /** @@ -97,27 +95,27 @@ public class ContentCenterServlet extends BaseApplicationServlet { s_log.info("starting doInit method"); } - // DEPRECATED STUFF for servlet internally process pages, maybe required -// for JSP extension. - // m_trailingSlashList = new ArrayList(); - // requireTrailingSlash(""); + // DEPRECATED STUFF for servlet internally process pages, maybe required + // for JSP extension. + // m_trailingSlashList = new ArrayList(); + // 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 // Obviously not required. addPage("/", new MainPage()); // index page at address ~/cc - addPage("/index", new MainPage()); + addPage("/index", new MainPage()); // addPage("/item-search", new CMSItemSearchPage()); // Old style addPage("/item-search", new ItemSearchPage()); addPage("/searchredirect", new CMSSearchResultRedirector()); -// STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not -// handled by the this servlet directly. + // STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not + // handled by the this servlet directly. /** Set Template base path for JSP's */ // 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"; Assert.exists(m_templatePath, String.class); Assert.isTrue(m_templatePath.startsWith("/"), @@ -136,16 +134,16 @@ public class ContentCenterServlet extends BaseApplicationServlet { * (HttpServletRequest, HttpServletResponse, Application) */ protected void doService(HttpServletRequest sreq, - HttpServletResponse sresp, - Application app) - throws ServletException, IOException { + HttpServletResponse sresp, + Application app) + throws ServletException, IOException { if (s_log.isDebugEnabled()) { s_log.info("starting doService method"); } DeveloperSupport.startStage("ContentCenterServlet.doService"); - // ContentCenter workspace = (ContentCenter) app; + // ContentCenter workspace = (ContentCenter) app; /* Check user and privilegies */ if (Web.getContext().getUser() == null) { // user not logged in @@ -186,10 +184,10 @@ public class ContentCenterServlet extends BaseApplicationServlet { // probably want to redirect. // Probably DEPRECATED with new access method or only relevant for jsp // extension - // if (m_trailingSlashList.contains(url) && !originalUrl.endsWith("/")) { - // DispatcherHelper.sendRedirect(sresp, originalUrl + "/"); - // return; - // } + // if (m_trailingSlashList.contains(url) && !originalUrl.endsWith("/")) { + // DispatcherHelper.sendRedirect(sresp, originalUrl + "/"); + // return; + // } final Page page = (Page) m_pages.get(pathInfo); @@ -206,7 +204,7 @@ public class ContentCenterServlet extends BaseApplicationServlet { cmsPage.dispatch(sreq, sresp, ctx); } else { final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page; - cmsAppPage.init(sreq,sresp,app); + cmsAppPage.init(sreq, sresp, app); // Serve the page. final Document doc = cmsAppPage.buildDocument(sreq, sresp); @@ -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."); } } @@ -274,8 +271,8 @@ public class ContentCenterServlet extends BaseApplicationServlet { Iterator itr = s_pageURLs.keySet().iterator(); while (itr.hasNext()) { String classname2 = (String) itr.next(); - s_log.debug("key: " + classname + " value: " - + (String) s_pageURLs.get(classname2)); + s_log.debug("key: " + classname + " value: " + + (String) s_pageURLs.get(classname2)); } String url = (String) s_pageURLs.get(classname); return url; @@ -302,7 +299,7 @@ public class ContentCenterServlet extends BaseApplicationServlet { * @param actx The request context **/ protected void checkUserAccess(final HttpServletRequest request, - final HttpServletResponse response //, + final HttpServletResponse response //, /// final RequestContext actx ) throws ServletException { @@ -320,8 +317,8 @@ public class ContentCenterServlet extends BaseApplicationServlet { * trying to redirect, wrap that exception in a ServletException **/ protected void redirectToLoginPage(HttpServletRequest req, - HttpServletResponse resp) - throws ServletException { + HttpServletResponse resp) + throws ServletException { String url = Util.getSecurityHelper() .getLoginURL(req) + "?" + LoginHelper.RETURN_URL_PARAM_NAME diff --git a/ccm-cms/src/com/arsdigita/cms/ContentSectionServlet.java b/ccm-cms/src/com/arsdigita/cms/ContentSectionServlet.java index 87c54fa39..7e0c1a211 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentSectionServlet.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentSectionServlet.java @@ -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,15 +100,13 @@ import org.apache.log4j.Logger; * @author Sören Bernstein * @author Peter Boy */ - 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[] { + private static final String[] WELCOME_FILES = new String[]{ "index.jsp", "index.html" }; /** 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_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()); + .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 @@ -153,7 +144,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { * If not specified system wide defaults are used. */ @Override - public void init(ServletConfig config) throws ServletException { + public void init(ServletConfig config) throws ServletException { super.init(config); @@ -168,27 +159,26 @@ public class ContentSectionServlet extends BaseApplicationServlet { Assert.exists(m_templatePath, String.class); Assert.isTrue(m_templatePath.startsWith("/"), - "template-path must start with '/'"); + "template-path must start with '/'"); Assert.isTrue(!m_templatePath.endsWith("/"), - "template-path must not end with '/'"); + "template-path must not end with '/'"); + - // optional init-param named file-resolver from ~/WEB-INF/web.xml String resolverName = config.getInitParameter("file-resolver"); if (resolverName == null) { m_resolver = Web.getConfig().getApplicationFileResolver(); } else { - m_resolver = (ApplicationFileResolver)Classes.newInstance(resolverName); + 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 - // addPage("/admin", new MainPage()); // index page at address ~/cs - // addPage("/admin/index.jsp", new MainPage()); - // addPage("/admin/item.jsp", new MainPage()); + // addPage("/admin", new MainPage()); // index page at address ~/cs + // addPage("/admin/index.jsp", new MainPage()); + // addPage("/admin/item.jsp", new MainPage()); } @@ -200,13 +190,13 @@ public class ContentSectionServlet extends BaseApplicationServlet { * {@see com.arsdigita.web.BaseApplicationServlet#doService * (HttpServletRequest, HttpServletResponse, Application)} */ - protected void doService( HttpServletRequest sreq, - HttpServletResponse sresp, - Application app) - throws ServletException, IOException { + protected void doService(HttpServletRequest sreq, + HttpServletResponse sresp, + Application app) + throws ServletException, IOException { ContentSection section = (ContentSection) app; - + // //////////////////////////////////////////////////////////////////// // Prepare OLD style dispatcher based page service // //////////////////////////////////////////////////////////////////// @@ -217,19 +207,20 @@ public class ContentSectionServlet extends BaseApplicationServlet { * SiteNodeRequestContext removed, resolves currently to * KernelRequestContext which will be removed as well. */ - RequestContext ctx = DispatcherHelper.getRequestContext(); + RequestContext ctx = DispatcherHelper.getRequestContext(); String url = ctx.getRemainingURLPart(); // here KernelRequestContext now if (s_log.isInfoEnabled()) { 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 @@ -254,12 +245,12 @@ public class ContentSectionServlet extends BaseApplicationServlet { if (page instanceof CMSPage) { // backwards compatibility fix until migration completed final CMSPage cmsPage = (CMSPage) page; - // final RequestContext ctx = DispatcherHelper.getRequestContext(); + // final RequestContext ctx = DispatcherHelper.getRequestContext(); cmsPage.init(); cmsPage.dispatch(sreq, sresp, ctx); } else { final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page; - cmsAppPage.init(sreq,sresp,app); + cmsAppPage.init(sreq, sresp, app); // Serve the page. final Document doc = cmsAppPage.buildDocument(sreq, sresp); @@ -267,9 +258,9 @@ public class ContentSectionServlet extends BaseApplicationServlet { 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) { - + /* We have to serve an item here */ String param = sreq.getParameter("transID"); @@ -281,6 +272,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { public void beforeCommit(TransactionContext txn) { Assert.fail("uncommittable transaction"); } + }); Kernel.getContext().getTransaction().setCommitRequested(false); @@ -290,8 +282,8 @@ public class ContentSectionServlet extends BaseApplicationServlet { } serveItem(sreq, sresp, section, item); - - /* OTHERWISE delegate to a JSP in file system */ + + /* OTHERWISE delegate to a JSP in file system */ } else { /* We have to deal with a content-section, folder or an other bit*/ @@ -310,16 +302,15 @@ public class ContentSectionServlet extends BaseApplicationServlet { s_log.debug("Got dispatcher " + rd); } sreq = DispatcherHelper.restoreOriginalRequest(sreq); - rd.forward(sreq,sresp); + rd.forward(sreq, sresp); } 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() sresp.sendError(404, requestUri + " not found on this server."); } } } // END doService - /** * * @param sreq @@ -333,7 +324,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { HttpServletResponse sresp, ContentSection section, ContentItem item) - throws ServletException, IOException { + throws ServletException, IOException { //this is a content item, so use ContentItemDispatcher if (s_log.isInfoEnabled()) { s_log.info("serving content item"); @@ -350,14 +341,14 @@ public class ContentSectionServlet extends BaseApplicationServlet { //set the template context TemplateResolver templateResolver = - m_disp.getTemplateResolver(section); + m_disp.getTemplateResolver(section); String templateURL = url; if (!templateURL.startsWith("/")) { - templateURL = "/" + templateURL; + templateURL = "/" + templateURL; } if (templateURL.startsWith(PREVIEW)) { templateURL = templateURL.substring(PREVIEW.length()); - } + } String sTemplateContext = itemResolver.getTemplateFromURL(templateURL); if (s_log.isDebugEnabled()) { @@ -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); @@ -397,7 +386,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { } //use ContentItemDispatcher - m_disp.dispatch(sreq,sresp,ctx); + m_disp.dispatch(sreq, sresp, ctx); } /** @@ -418,7 +407,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { m_pages.put(pathInfo, page); } - + /** * Fetches the content section from the request attributes. * @@ -441,7 +430,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { String path = section.getPath(); ItemResolver ir = (ItemResolver) s_itemResolverCache.get(path); - if ( ir == null ) { + if (ir == null) { ir = section.getItemResolver(); s_itemResolverCache.put(path, ir); } @@ -467,7 +456,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { //first sanitize the url if (url.endsWith(XML_SUFFIX)) { 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()); } else { request.setAttribute(XML_MODE, Boolean.FALSE); @@ -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,21 +501,18 @@ 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 String lang = GlobalizationHelper.getNegotiatedLocale().getLanguage(); - + item = itemURLCacheGet(section, url, lang); item = null; 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,12 +582,11 @@ public class ContentSectionServlet extends BaseApplicationServlet { } // synchronize access to the item-url cache - - private static synchronized void itemURLCachePut(ContentSection section, + private static synchronized void itemURLCachePut(ContentSection section, String sURL, String lang, BigDecimal itemID) { - + getItemURLCache(section).put(sURL + CACHE_KEY_DELIMITER + lang, itemID); } @@ -615,7 +596,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { * @param sURL the URL at which the content item s published * @param item the content item at the URL */ - public static synchronized void itemURLCachePut(ContentSection section, + public static synchronized void itemURLCachePut(ContentSection section, String sURL, String lang, ContentItem item) { @@ -634,7 +615,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { * @param section the content section in which to remove the key * @param sURL the cache entry key to remove */ - public static synchronized void itemURLCacheRemove(ContentSection section, + public static synchronized void itemURLCacheRemove(ContentSection section, String sURL, String lang) { if (s_log.isDebugEnabled()) { @@ -649,7 +630,7 @@ public class ContentSectionServlet extends BaseApplicationServlet { * @param sURL the URL for the item to fetch * @return the ContentItem in the cache, or null */ - public static ContentItem itemURLCacheGet(ContentSection section, + public static ContentItem itemURLCacheGet(ContentSection section, final String sURL, final String lang) { final BigDecimal itemID = (BigDecimal) getItemURLCache(section) @@ -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; } @@ -683,9 +663,9 @@ public class ContentSectionServlet extends BaseApplicationServlet { String idStr = section.getID().toString(); String path = section.getPath(); CacheTable itemURLCache = - new CacheTable("ContentSectionServletItemURLCache" + idStr); + new CacheTable("ContentSectionServletItemURLCache" + idStr); s_itemURLCacheMap.put(path, itemURLCache); - + } } @@ -695,15 +675,15 @@ public class ContentSectionServlet extends BaseApplicationServlet { public static boolean checkAdminAccess(HttpServletRequest request, ContentSection section) { - User user ; + User user; KernelContext kernelContext = Kernel.getContext(); - if ( kernelContext.getParty() instanceof User ) { + if (kernelContext.getParty() instanceof User) { user = (User) kernelContext.getParty(); } else { // Should not happen, at this stage the user has to be logged in. return false; } - + SecurityManager sm = new SecurityManager(section); return sm.canAccess(user, SecurityManager.ADMIN_PAGES); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/CMSItemSearchPage.java b/ccm-cms/src/com/arsdigita/cms/ui/CMSItemSearchPage.java index 1733e0c2c..3b84beba4 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/CMSItemSearchPage.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/CMSItemSearchPage.java @@ -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; diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchCreateItemPane.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchCreateItemPane.java index c2728401a..ae1b8eeb4 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchCreateItemPane.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchCreateItemPane.java @@ -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"); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java index 26d975529..20065c158 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java @@ -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 queryFields = new ArrayList(); private final Submit submit; private final static CMSConfig CMS_CONFIG = CMSConfig.getInstance(); @@ -61,14 +64,14 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, super(name); setIdAttr("itemSearchFlatBrowse"); - + final BoxPanel mainPanel = new BoxPanel(BoxPanel.VERTICAL); queryParam = new StringParameter(QUERY_PARAM); - final BoxPanel boxPanel = new BoxPanel(BoxPanel.HORIZONTAL); + final BoxPanel boxPanel = new BoxPanel(BoxPanel.HORIZONTAL); boxPanel.add(new Label(GlobalizationUtil.globalize("cms.ui.item_search.flat.filter"))); - final TextField filter = new TextField(new StringParameter(QUERY_PARAM)); + final TextField filter = new TextField(new StringParameter(QUERY_PARAM)); boxPanel.add(filter); submit = new Submit(FILTER_SUBMIT, GlobalizationUtil.globalize("cms.ui.item_search.flat.filter.submit")); boxPanel.add(submit); @@ -79,8 +82,8 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, CMS_CONFIG.getItemSearchFlatBrowsePanePageSize()); mainPanel.add(paginator); - mainPanel.add(resultsTable); - + mainPanel.add(resultsTable); + add(mainPanel); addInitListener(this); @@ -101,7 +104,7 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, if ((query == null) || query.isEmpty()) { data.setParameter(QUERY_PARAM, new ParameterData(queryParam, state.getValue(new StringParameter(ItemSearchPopup.QUERY)))); - state.setValue(queryParam, data.getParameter(QUERY_PARAM).getValue()); + state.setValue(queryParam, data.getParameter(QUERY_PARAM).getValue()); } } @@ -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"; @@ -181,15 +188,26 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, final ContentType type = new ContentType(typeId); collection.set(state, session.retrieve(type.getClassName())); } - ((DataCollection)collection.get(state)).addFilter("version = 'draft'"); - ((DataCollection)collection.get(state)).addFilter("section is not null"); + ((DataCollection) collection.get(state)).addFilter("version = 'draft'"); + ((DataCollection) collection.get(state)).addFilter("section is not null"); 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)); + 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; } + } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchPage.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchPage.java index 74565acb0..42f4a75b1 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchPage.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchPage.java @@ -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); @@ -135,6 +136,10 @@ public class ItemSearchPage extends CMSPage { if (state.getValue(new BooleanParameter("editAfterCreate")) != null) { 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); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java index 1c0d6d0c2..1e2eab2ca 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java @@ -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; @@ -283,6 +284,10 @@ public class ItemSearchWidget extends FormSection if (m_defaultCreationFolder != null) { params.setParameter("defaultCreationFolder", m_defaultCreationFolder.getOID().toString()); } + + if (m_queryField != null) { + params.setParameter("queryField", m_queryField); + } String searchURL = ContentCenterServlet.getURLStubForClass( ItemSearchPage.class.getName()); @@ -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);