items) {
+ this.items = items;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 3;
+ }
+
+ @Override
+ public boolean nextRow() {
+ index++;
+ if (index < items.size()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Object getElementAt(final int columnIndex) {
+ switch (columnIndex) {
+ case NAME:
+ return items.get(index);
+ case TITLE:
+ return items.get(index).getDisplayName();
+ case TYPE:
+ return items.get(index).getContentType().getDisplayName();
+ default:
+ throw new IllegalArgumentException(String.format(
+ "Column index {} not in table model.", columnIndex));
+ }
+ }
+
+ @Override
+ public Object getKeyAt(final int columnIndex) {
+ return items.get(index).getObjectId();
+ }
+
+ }
+
+ private class FolderChanger extends TableActionAdapter {
+
+ @Override
+ public void cellSelected(final TableActionEvent event) {
+ final PageState state = event.getPageState();
+ final int col = event.getColumn();
+
+ if (nameColumn != getColumn(col)) {
+ return;
+ }
+ final String key = (String) event.getRowKey();
+ if (key.startsWith("-")) {
+ clearSelection(state);
+ getFolderSelectionModel().setSelectedKey(
+ state, Long.parseLong(key.substring(1)));
+ paginator.reset(state);
+ }
+ }
+
+ }
+
+ /**
+ * Getting the GlobalizedMessage using a CMS Class targetBundle.
+ *
+ * @param key The resource key
+ *
+ * @pre ( key != null )
+ */
+ private static GlobalizedMessage globalize(final String key) {
+ return new GlobalizedMessage(key, CmsConstants.CMS_FOLDER_BUNDLE);
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchFolderBrowser.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchFolderBrowser.java.todo
deleted file mode 100755
index 948483f55..000000000
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchFolderBrowser.java.todo
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-package com.arsdigita.cms.ui;
-
-import com.arsdigita.bebop.Bebop;
-import com.arsdigita.bebop.Component;
-import com.arsdigita.bebop.Label;
-import com.arsdigita.bebop.Link;
-import com.arsdigita.bebop.Page;
-import com.arsdigita.bebop.RequestLocal;
-import com.arsdigita.bebop.PageState;
-import com.arsdigita.bebop.PaginationModelBuilder;
-import com.arsdigita.bebop.Paginator;
-import com.arsdigita.bebop.SimpleContainer;
-import com.arsdigita.bebop.Table;
-import com.arsdigita.bebop.event.ActionEvent;
-import com.arsdigita.bebop.event.ActionListener;
-import com.arsdigita.bebop.event.TableActionAdapter;
-import com.arsdigita.bebop.event.TableActionEvent;
-import com.arsdigita.bebop.event.TableActionListener;
-import com.arsdigita.bebop.parameters.BigDecimalParameter;
-import com.arsdigita.bebop.parameters.StringParameter;
-import com.arsdigita.bebop.table.AbstractTableModelBuilder;
-import com.arsdigita.bebop.table.DefaultTableCellRenderer;
-import com.arsdigita.bebop.table.TableColumn;
-import com.arsdigita.bebop.table.TableModel;
-import com.arsdigita.bebop.util.BebopConstants;
-import com.arsdigita.cms.CMS;
-import com.arsdigita.cms.ContentItem;
-import com.arsdigita.cms.ContentPage;
-import com.arsdigita.cms.ContentSection;
-import com.arsdigita.cms.ContentType;
-import com.arsdigita.cms.Folder;
-import com.arsdigita.cms.SecurityManager;
-import com.arsdigita.cms.dispatcher.Utilities;
-import com.arsdigita.cms.ui.folder.FolderSelectionModel;
-import com.arsdigita.globalization.GlobalizedMessage;
-import com.arsdigita.persistence.CompoundFilter;
-import com.arsdigita.persistence.FilterFactory;
-import com.arsdigita.toolbox.GlobalisationUtil;
-import com.arsdigita.util.Assert;
-
-import java.math.BigDecimal;
-
-/**
- * Browse folders and items. If the user clicks on a folder, the folder selection model is updated.
- * If the user clicks on any other item, an separate item selection model is updated.
- *
- * @author David Lutterkort
- * @version $Revision: #9 $ $DateTime: 2004/08/17 23:15:09 $
- */
-public class ItemSearchFolderBrowser extends Table {
-
- private static final org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
- ItemSearchFolderBrowser.class);
- private static GlobalizedMessage[] s_headers = {
- globalize("cms.ui.folder.name"),
- globalize("cms.ui.folder.title"),
- globalize("cms.ui.folder.type")};
- private FolderSelectionModel m_currentFolder;
- private TableActionListener m_folderChanger;
- private TableActionListener m_deleter;
- private TableActionListener m_indexChanger;
- private TableColumn m_nameColumn;
- private Paginator m_paginator;
-
- public ItemSearchFolderBrowser(FolderSelectionModel currentFolder) {
- super((FolderTableModelBuilder) null, s_headers);
-
- FolderTableModelBuilder builder = new FolderTableModelBuilder();
- setModelBuilder(builder);
-
- m_paginator = new Paginator(builder, ContentSection.getConfig().
- getFolderBrowseListSize());
-
- m_currentFolder = currentFolder;
-
- setClassAttr("dataTable");
-
- getHeader().setDefaultRenderer(
- new com.arsdigita.cms.ui.util.DefaultTableCellRenderer());
- m_nameColumn = getColumn(0);
- m_nameColumn.setCellRenderer(new NameCellRenderer());
-
- m_folderChanger = new FolderChanger();
- addTableActionListener(m_folderChanger);
-
- setEmptyView(new Label(globalize("cms.ui.folder.no_items")));
-
- Assert.exists(m_currentFolder.getStateParameter());
- }
-
- public Paginator getPaginator() {
- return m_paginator;
- }
-
- @Override
- public void register(Page p) {
- super.register(p);
- p.addComponentStateParam(this, m_currentFolder.getStateParameter());
-
- p.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent event) {
- // MP: This action listener should only be called when the
- // folder browser is visible.
- showHideFolderActions(event.getPageState());
- }
-
- });
- }
-
- private Folder getCurrentFolder(PageState state) {
- return (Folder) m_currentFolder.getSelectedObject(state);
- }
-
- private void showHideFolderActions(PageState state) {
- SecurityManager sm = Utilities.getSecurityManager(state);
- Folder folder = getCurrentFolder(state);
- Assert.exists(folder);
- }
-
- public FolderSelectionModel getFolderSelectionModel() {
- return m_currentFolder;
- }
-
- private class FolderTableModelBuilder
- extends AbstractTableModelBuilder implements PaginationModelBuilder {
-
- private RequestLocal m_size = new RequestLocal() {
-
- @Override
- protected Object initialValue(PageState state) {
- Folder.ItemCollection itemColl = getItemCollection(state);
-
- if (null == itemColl) {
- return new Integer(0);
- }
- return new Integer((int) itemColl.size());
- }
-
- };
- private RequestLocal m_itemColl = new RequestLocal() {
-
- @Override
- protected Object initialValue(PageState state) {
- Folder.ItemCollection itemColl = getItemCollection(state);
-
- itemColl.addOrder("item.name");
- itemColl.setRange(new Integer(m_paginator.getFirst(state)),
- new Integer(m_paginator.getLast(state) + 1));
-
- return itemColl;
- }
-
- };
-
- public TableModel makeModel(Table t, PageState s) {
- FolderSelectionModel sel = ((ItemSearchFolderBrowser) t).
- getFolderSelectionModel();
- Folder f = getCurrentFolder(s);
-
- if (s_log.isDebugEnabled()) {
- if (null == f) {
- s_log.debug("Selected folder is null");
- } else {
- s_log.debug("Selected folder: " + f.getLabel() + " " + f.
- getOID().toString());
- }
- }
-
- if (f == null) {
- return Table.EMPTY_MODEL;
- } else {
- t.getRowSelectionModel().clearSelection(s);
- return new FolderTableModel((Folder.ItemCollection) m_itemColl.
- get(s));
- }
- }
-
- private Folder.ItemCollection getItemCollection(PageState state) {
- Folder f = getCurrentFolder(state);
- Folder.ItemCollection itemColl = f.getPrimaryInstances();
-
- if (null == itemColl) {
- return null;
- }
-
- BigDecimal singleTypeID = (BigDecimal) state.getValue(new BigDecimalParameter(
- ItemSearch.SINGLE_TYPE_PARAM));
-
- if (singleTypeID != null) {
-
- // The Filter Factory
- FilterFactory ff = itemColl.getFilterFactory();
-
- // Create an or-filter
- CompoundFilter or = ff.or();
-
- // The content type must be either of the requested type
- or.addFilter(ff.equals(ContentItem.CONTENT_TYPE + "."
- + ContentType.ID, singleTypeID));
-
- // Or must be a sibling of the requested type
- /*
- * jensp 2011-11-14: The orginal code here was only traversing
- * one level, but ContentType hierarchies may have several
- * levels. Therefore, this code was replaced by method which is
- * called recursivly until the type with no descendents is
- * reached.
- */
- createSiblingFilter(or, ff, singleTypeID);
- /*try {
- ContentType ct = new ContentType(singleTypeID);
-
- StringTokenizer strTok = new StringTokenizer(ct.
- getDescendants(), "/");
- while (strTok.hasMoreElements()) {
- or.addFilter(ff.equals(ContentItem.CONTENT_TYPE + "."
- + ContentType.ID,
- (String) strTok.nextElement()));
- }
- } catch (Exception ex) {
- // WTF? The selected content type does not exist in the table???
- s_log.error(String.format(
- "Something is very wrong here, the ContentType '%s' "
- + "seems not to exist. Ignoring for now, but please "
- + "make your checks.",
- singleTypeID.toString()),
- ex);
- }*/
-
- itemColl.addFilter(or);
-
- }
-
- itemColl.addOrder("isFolder desc");
- itemColl.addOrder("lower(item." + ContentItem.NAME + ") ");
- return itemColl;
- }
-
- private void createSiblingFilter(final CompoundFilter filter,
- final FilterFactory filterFactory,
- final BigDecimal typeId) {
- final ContentType type = new ContentType(typeId);
- if ((type.getDescendants() == null)
- || type.getDescendants().trim().isEmpty()) {
- return;
- } else {
- final String[] descendantsIds = type.getDescendants().split("/");
-
- for (String descendantId : descendantsIds) {
- filter.addFilter(filterFactory.equals(String.format(
- ContentItem.CONTENT_TYPE + "." + ContentType.ID),
- descendantId));
- createSiblingFilter(filter, filterFactory, descendantId);
- }
- }
- }
-
- private void createSiblingFilter(final CompoundFilter filter,
- final FilterFactory filterFactory,
- final String typeId) {
- try {
- final BigDecimal _typeId = new BigDecimal(typeId);
- createSiblingFilter(filter, filterFactory, _typeId);
- } catch (NumberFormatException ex) {
- s_log.error(String.format("Failed to parse typeId '%s'.",
- typeId),
- ex);
- }
- }
-
- public int getTotalSize(Paginator paginator, PageState state) {
-
- Integer size = (Integer) m_size.get(state);
- return size.intValue();
- }
-
- /**
- * Indicates whether the paginator should be visible, based on the visibility of the folder
- * browser itself and how many items are displayed
- *
- * @return true if folder browser is visible and there is more than 1 page of items, false
- * otherwise
- */
- public boolean isVisible(PageState state) {
- int size = ((Integer) m_size.get(state)).intValue();
-
- return ItemSearchFolderBrowser.this.isVisible(state)
- && (size
- > ContentSection.getConfig().getFolderBrowseListSize());
- }
-
- }
-
- /**
- * Produce links to view an item or control links for folders to change into the folder.
- */
- private class NameCellRenderer extends DefaultTableCellRenderer {
-
- public NameCellRenderer() {
- super(true);
- }
-
- @Override
- public Component getComponent(Table table, PageState state,
- Object value, boolean isSelected,
- Object key, int row, int column) {
- Folder.ItemCollection coll = (Folder.ItemCollection) value;
- String name = coll.getName();
- if (coll.isFolder()) {
- return super.getComponent(table, state, name, isSelected, key,
- row, column);
- } else {
- ContentSection section = CMS.getContext().getContentSection();
- BigDecimal id = (BigDecimal) key;
-
- if (section == null) {
- return new Label(name);
- } else {
- //ItemResolver resolver = section.getItemResolver();
-
- //String url =
- //resolver.generateItemURL
- //(state, id, name, section, coll.getVersion()));
- SimpleContainer container = new SimpleContainer();
-
- String widget = (String) state.getValue(new StringParameter(
- ItemSearchPopup.WIDGET_PARAM));
- String searchWidget = (String) state.getValue(
- new StringParameter("searchWidget"));
- boolean useURL = "true".equals(state.getValue(new StringParameter(
- ItemSearchPopup.URL_PARAM)));
-
- String fillString;
- if (useURL) {
- fillString = ItemSearchPopup.getItemURL(state.getRequest(),
- coll.getDomainObject().getOID());
- } else {
- fillString = id.toString();// + " (" + name + ")";
- }
-
- String title = ((ContentPage) coll.getDomainObject()).getTitle();
-
- Label js = new Label(
- generateJSLabel(id, widget, searchWidget, fillString, title),
- false);
- container.add(js);
-
- String url = "#";
-
- Link link = new Link(name, url);
- link.setClassAttr("title");
- link.setOnClick("return fillItem" + id + "()");
-
- container.add(link);
-
- return container;
- }
- }
- }
-
- private String generateJSLabel(BigDecimal id, String widget, String searchWidget,
- String fill, String title) {
- StringBuilder buffer = new StringBuilder();
- buffer.append(" ");
-
- return buffer.toString();
- }
-
- }
-
- /**
- * Table model around ItemCollection
- */
- private static class FolderTableModel implements TableModel {
-
- private static final int NAME = 0;
- private static final int TITLE = 1;
- private static final int TYPE = 2;
- private Folder.ItemCollection m_itemColl;
-
- public FolderTableModel(Folder.ItemCollection itemColl) {
- m_itemColl = itemColl;
- }
-
- public int getColumnCount() {
- return 3;
- }
-
- public boolean nextRow() {
- return m_itemColl != null ? m_itemColl.next() : false;
- }
-
- public Object getElementAt(int columnIndex) {
- switch (columnIndex) {
- case NAME:
- return m_itemColl;
- case TITLE:
- return m_itemColl.getDisplayName();
- case TYPE:
- return m_itemColl.getTypeLabel();
- default:
- throw new IndexOutOfBoundsException("Column index "
- + columnIndex
- + " not in table model.");
- }
- }
-
- public Object getKeyAt(int columnIndex) {
- // Mark folders by using their negative ID (dirty, dirty)
- return (m_itemColl.isFolder()) ? m_itemColl.getID().negate()
- : m_itemColl.getID();
- }
-
- }
-
- private class FolderChanger extends TableActionAdapter {
-
- @Override
- public void cellSelected(TableActionEvent e) {
- PageState s = e.getPageState();
- int col = e.getColumn().intValue();
-
- if (m_nameColumn != getColumn(col)) {
- return;
- }
- String key = (String) e.getRowKey();
- if (key.startsWith("-")) {
- clearSelection(s);
- getFolderSelectionModel().setSelectedKey(s, key.substring(1));
- m_paginator.reset(s);
- }
- }
-
- }
-
- /**
- * Getting the GlobalizedMessage using a CMS Class targetBundle.
- *
- * @param key The resource key
- *
- * @pre ( key != null )
- */
- private static GlobalizedMessage globalize(String key) {
- //return FolderManipulator.globalize(key);
- final GlobalisationUtil util = new GlobalisationUtil(
- "com.arsdigita.cms."
- + "ui.folder.CMSFolderResources");
- return util.globalize(key);
- }
-
-}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java
similarity index 53%
rename from ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java.todo
rename to ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java
index 16469cebb..547c74ddf 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java.todo
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPage.java
@@ -27,25 +27,40 @@ import com.arsdigita.bebop.event.RequestListener;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.BooleanParameter;
import com.arsdigita.bebop.parameters.IntegerParameter;
+import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.dispatcher.CMSPage;
import com.arsdigita.dispatcher.RequestContext;
+import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating;
import com.arsdigita.util.UncheckedWrapperException;
+
import org.libreccm.web.CcmApplication;
+
import com.arsdigita.web.Web;
import com.arsdigita.xml.Document;
+import org.arsdigita.cms.CMSConfig;
+import org.libreccm.cdi.utils.CdiUtil;
+import org.libreccm.security.Shiro;
+import org.librecms.CmsConstants;
+import org.librecms.contentsection.ContentItemVersion;
+import org.librecms.contentsection.ContentSection;
+import org.librecms.contentsection.ContentSectionRepository;
+
import java.io.IOException;
import java.math.BigDecimal;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * The Item Search page.
+ *
+ * The Item Search page.
*
* @author Scott Seago (scott@arsdigita.com)
* @author Sören Bernstein
@@ -53,27 +68,33 @@ import javax.servlet.http.HttpServletResponse;
*/
public class ItemSearchPage extends CMSPage {
- private final static String XSL_CLASS = "CMS Admin";
- private TabbedPane m_tabbedPane;
- private ItemSearchFlatBrowsePane m_flatBrowse;
- private ItemSearchBrowsePane m_browse;
- private ItemSearchPopup m_search;
- private ItemSearchCreateItemPane m_create;
- private BigDecimalParameter m_sectionId;
- private int m_lastTab;
- private static final CMSConfig s_conf = CMSConfig.getInstanceOf();
- private static final boolean LIMIT_TO_CONTENT_SECTION = false;
public static final String CONTENT_SECTION = "section_id";
+ private static final boolean LIMIT_TO_CONTENT_SECTION = false;
+ private final static String XSL_CLASS = "CMS Admin";
+
+ private TabbedPane tabbedPane;
+ private ItemSearchFlatBrowsePane flatBrowsePane;
+ private ItemSearchBrowsePane browsePane;
+ private ItemSearchPopup searchPopup;
+// private ItemSearchCreateItemPane m_create;
+ private final LongParameter sectionId;
+ private int lastTab;
+ private static final CMSConfig CONFIG = CMSConfig.getConfig();
+
/**
* Construct a new ItemSearchPage
*/
public ItemSearchPage() {
- super(GlobalizationUtil.globalize("cms.ui.item_search.page_title").localize().toString(), new SimpleContainer());
+ super(new GlobalizedMessage("cms.ui.item_search.page_title",
+ CmsConstants.CMS_BUNDLE).localize()
+ .toString(),
+ new SimpleContainer());
setClassAttr("cms-admin");
- addGlobalStateParam(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
+ addGlobalStateParam(
+ new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
addGlobalStateParam(new StringParameter(ItemSearchPopup.WIDGET_PARAM));
addGlobalStateParam(new StringParameter("searchWidget"));
addGlobalStateParam(new StringParameter("publishWidget"));
@@ -81,64 +102,71 @@ 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);
+ addGlobalStateParam(new StringParameter("queryField"));
+ sectionId = new LongParameter(CONTENT_SECTION);
+ addGlobalStateParam(sectionId);
- m_flatBrowse = getFlatBrowsePane();
- m_browse = getBrowsePane();
- m_search = getSearchPane();
- m_create = getCreatePane();
+ flatBrowsePane = getFlatBrowsePane();
+ browsePane = getBrowsePane();
+ searchPopup = getSearchPane();
+// m_create = getCreatePane();
- m_tabbedPane = createTabbedPane();
- m_tabbedPane.setIdAttr("page-body");
- add(m_tabbedPane);
+ tabbedPane = createTabbedPane();
+ tabbedPane.setIdAttr("page-body");
+ add(tabbedPane);
addRequestListener(new RequestListener() {
public void pageRequested(final RequestEvent event) {
final PageState state = event.getPageState();
- final String query = (String) state.getValue(new StringParameter(ItemSearchPopup.QUERY));
- final Boolean disableCreatePane = (Boolean) state.getValue(new BooleanParameter("disableCreatePane"));
+ final String query = (String) state.getValue(
+ new StringParameter(ItemSearchPopup.QUERY));
+ final Boolean disableCreatePane = (Boolean) state.getValue(
+ new BooleanParameter("disableCreatePane"));
- BigDecimal typeParam =
- (BigDecimal) state.getValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
+ BigDecimal typeParam = (BigDecimal) state.getValue(
+ new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
if ((typeParam == null) || disableCreatePane) {
- m_tabbedPane.setTabVisible(state, m_create, false);
- m_create.setVisible(state, false);
+// tabbedPane.setTabVisible(state, m_create, false);
+// m_create.setVisible(state, false);
} else {
- m_tabbedPane.setTabVisible(state, m_create, true);
- m_create.setVisible(state, true);
+// tabbedPane.setTabVisible(state, m_create, true);
+// m_create.setVisible(state, true);
}
if (state.getValue(new IntegerParameter("lastTab")) == null) {
if ((query == null) || query.isEmpty()) {
- m_tabbedPane.setSelectedIndex(state, 1);
+ tabbedPane.setSelectedIndex(state, 1);
} else {
- m_tabbedPane.setSelectedIndex(state, 0);
+ tabbedPane.setSelectedIndex(state, 0);
}
// m_tabbedPane.setTabVisible(state, m_create, false);
// m_create.setVisible(state, false);
-
}
- state.setValue(new IntegerParameter("lastTab"), m_tabbedPane.getSelectedIndex(state));
+ state.setValue(new IntegerParameter("lastTab"), tabbedPane
+ .getSelectedIndex(state));
- if (state.getValue(new StringParameter("defaultCreationFolder")) != null) {
- m_create.setDefaultFolder((String) state.getValue(new StringParameter("defaultCreationFolder")));
+ if (state.getValue(new StringParameter("defaultCreationFolder"))
+ != null) {
+// m_create.setDefaultFolder((String) state.getValue(
+// new StringParameter("defaultCreationFolder")));
}
-
- if (state.getValue(new BooleanParameter("editAfterCreate")) != null) {
- m_create.setEditAfterCreate((Boolean) state.getValue(new BooleanParameter("editAfterCreate")));
+
+ if (state.getValue(new BooleanParameter("editAfterCreate"))
+ != null) {
+// m_create.setEditAfterCreate((Boolean) state.getValue(
+// new BooleanParameter("editAfterCreate")));
}
-
+
if (state.getValue(new StringParameter("queryField")) == null) {
//Because of Bebops silly stateful behaviour we have to do this...
- m_flatBrowse.resetQueryFields();
- }else {
- m_flatBrowse.addQueryField((String) state.getValue(new StringParameter("queryField")));
+ flatBrowsePane.resetQueryFields();
+ } else {
+ flatBrowsePane.addQueryField((String) state.getValue(
+ new StringParameter("queryField")));
}
// if (m_lastTab != m_tabbedPane.getSelectedIndex(state)) {
@@ -156,7 +184,6 @@ public class ItemSearchPage extends CMSPage {
// } else {
// m_tabbedPane.setSelectedIndex(state, 1);
// }
-
// if (m_tabbedPane.getCurrentPane(state) == m_create) {
// m_tabbedPane.setTabVisible(state, m_create, false);
// m_create.setVisible(state, false);
@@ -175,7 +202,6 @@ public class ItemSearchPage extends CMSPage {
// }
//
// });
-
// m_flatBrowse.addProcessListener(new FormProcessListener() {
//
// public void process(final FormSectionEvent fse) throws FormProcessException {
@@ -187,157 +213,175 @@ public class ItemSearchPage extends CMSPage {
// });
} // END constructor
-
/**
- * Creates, and then caches, the Browse pane.
- *
+ * Creates, and then caches, the Browse pane.
+ *
* Overriding this method to return null will prevent this tab from
* appearing. Note: not implemented yet.
+ *
+ * @return
*/
protected ItemSearchBrowsePane getBrowsePane() {
- if (m_browse == null) {
- m_browse = new ItemSearchBrowsePane();
+ if (browsePane == null) {
+ browsePane = new ItemSearchBrowsePane();
}
- return m_browse;
+ return browsePane;
}
protected ItemSearchFlatBrowsePane getFlatBrowsePane() {
- if (m_flatBrowse == null) {
+ if (flatBrowsePane == null) {
//m_flatBrowse = new ItemSearchFlatBrowsePane("flatBrowse");
- m_flatBrowse = new ItemSearchFlatBrowsePane();
+ flatBrowsePane = new ItemSearchFlatBrowsePane();
}
- return m_flatBrowse;
+ return flatBrowsePane;
}
/**
- * Creates, and then caches, the Creation pane.
- * Overriding this method to return null will prevent this tab from
- * appearing.
+ * Creates, and then caches, the Creation pane. Overriding this method to
+ * return null will prevent this tab from appearing.
*/
protected ItemSearchPopup getSearchPane() {
- if (m_search == null) {
+ if (searchPopup == null) {
// Always search in every content section
// m_search = new ItemSearchPopup(ContentItem.DRAFT, CMS.getConfig().limitToContentSection());
- m_search = new ItemSearchPopup(ContentItem.DRAFT, LIMIT_TO_CONTENT_SECTION);
+ searchPopup = new ItemSearchPopup(ContentItemVersion.DRAFT
+ .toString(),
+ LIMIT_TO_CONTENT_SECTION);
}
- return m_search;
- }
-
- protected ItemSearchCreateItemPane getCreatePane() {
- if (m_create == null) {
- m_create = new ItemSearchCreateItemPane(this);
- }
-
- return m_create;
+ return searchPopup;
}
+// protected ItemSearchCreateItemPane getCreatePane() {
+// if (m_create == null) {
+// m_create = new ItemSearchCreateItemPane(this);
+// }
+//
+// return m_create;
+// }
/**
- * Created the TabbedPane to use for this page.
- *
- * Sets the class attribute for this tabbed pane. The default implementation
- * uses a {@link com.arsdigita.bebop.TabbedPane} and sets the class
- * attribute to "CMS Admin." This implementation also adds tasks,
- * content sections, and search panes.
+ * Created the TabbedPane to use for this page.
*
- * Developers can override this method to add only the tabs they want,
- * or to add additional tabs after the default CMS tabs are added.
+ * Sets the class attribute for this tabbed pane. The default implementation
+ * uses a {@link com.arsdigita.bebop.TabbedPane} and sets the class
+ * attribute to "CMS Admin." This implementation also adds tasks, content
+ * sections, and search panes.
+ *
+ * Developers can override this method to add only the tabs they want, or to
+ * add additional tabs after the default CMS tabs are added.
+ *
+ * @return
*/
protected TabbedPane createTabbedPane() {
TabbedPane pane = new TabbedPane();
pane.setClassAttr(XSL_CLASS);
-
addToPane(pane, "flatBrowse", getFlatBrowsePane());
addToPane(pane, "browse", getBrowsePane());
addToPane(pane, "search", getSearchPane());
- addToPane(pane, "create", getCreatePane());
+// addToPane(pane, "create", getCreatePane());
- if ("browse".equals(s_conf.getItemSearchDefaultTab())) {
- pane.setDefaultPane(m_browse);
+ if ("browse".equals(CONFIG.getItemSearchDefaultTab())) {
+ pane.setDefaultPane(browsePane);
}
- if ("search".equals(s_conf.getItemSearchDefaultTab())) {
- pane.setDefaultPane(m_search);
+ if ("search".equals(CONFIG.getItemSearchDefaultTab())) {
+ pane.setDefaultPane(searchPopup);
}
//pane.setDefaultPane(m_flatBrowse);
- pane.setDefaultPane(m_browse);
+ pane.setDefaultPane(browsePane);
return pane;
}
/**
- * Adds the specified component, with the specified tab name, to the
- * tabbed pane only if it is not null.
+ * Adds the specified component, with the specified tab name, to the tabbed
+ * pane only if it is not null.
*
* @param pane The pane to which to add the tab
* @param tabName The name of the tab if it's added
* @param comp The component to add to the pane
*/
- protected void addToPane(TabbedPane pane, String tabName, Component comp) {
+ protected void addToPane(final TabbedPane pane,
+ final String tabName,
+ final Component comp) {
if (comp != null) {
-
- pane.addTab(GlobalizationUtil
- .globalize("cms.ui.item_search." + tabName)
- .localize().toString()
- ,comp);
-
+ pane.addTab(new GlobalizedMessage(String.format(
+ "cms.ui.item_search.%s", tabName), CmsConstants.CMS_BUNDLE)
+ .localize().toString(),
+ comp);
}
}
-
/**
* This strange voodoo from Dan. No idea what it does.
+ *
+ * @throws java.io.IOException
+ * @throws javax.servlet.ServletException
*/
@Override
public void dispatch(final HttpServletRequest request,
final HttpServletResponse response,
- RequestContext actx)
- throws IOException, ServletException {
- new CMSExcursion() {
+ final RequestContext actx) {
+
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final Shiro shiro = cdiUtil.findBean(Shiro.class);
+
+ shiro.getSystemUser().execute(new Runnable() {
@Override
- public void excurse()
- throws IOException, ServletException {
- ContentSection section = null;
- Application app = Web.getWebContext().getApplication();
- if (app instanceof ContentSection) {
- section = (ContentSection) app;
- } else {
- try {
- section = new ContentSection((BigDecimal) m_sectionId.transformValue(request));
- } catch (DataObjectNotFoundException ex) {
- throw new UncheckedWrapperException(ex);
- }
- }
- setContentSection(section);
+ public void run() {
- final Document doc = buildDocument(request, response);
- final PresentationManager pm =
- Templating.getPresentationManager();
+ final CcmApplication application = Web.getWebContext()
+ .getApplication();
+
+ final CdiUtil util = CdiUtil.createCdiUtil();
+ final ContentSectionRepository sectionRepo = util.findBean(
+ ContentSectionRepository.class);
+
+ final ContentSection section;
+ if (application instanceof ContentSection) {
+ section = (ContentSection) application;
+ } else {
+ section = sectionRepo.findById(Long.parseLong(
+ (String) sectionId.transformValue(request)));
+ }
+
+// Web.getWebContext().setContentSection(section);
+
+ final Document doc;
+ try {
+ doc = buildDocument(request, response);
+ } catch (ServletException ex) {
+ throw new UncheckedWrapperException(ex);
+ }
+ final PresentationManager pm = Templating
+ .getPresentationManager();
pm.servePage(doc, request, response);
}
- }.run();
+ });
}
- protected void setTabActive(final PageState state, final Component component, final boolean value) {
- m_tabbedPane.setTabVisible(state, component, value);
+ protected void setTabActive(final PageState state, final Component component,
+ final boolean value) {
+ tabbedPane.setTabVisible(state, component, value);
}
- protected void setTabActive(final PageState state, final int index, final boolean value) {
- m_tabbedPane.setTabVisible(state, index, value);
+ protected void setTabActive(final PageState state, final int index,
+ final boolean value) {
+ tabbedPane.setTabVisible(state, index, value);
}
- protected void setDefaultCreationFolder(final Folder folder) {
- m_create.setDefaultFolder(folder.getOID().toString());
- }
-
- protected void setEditAfterCreate(final boolean editAfterCreate) {
- m_create.setEditAfterCreate(editAfterCreate);
- }
+// protected void setDefaultCreationFolder(final Folder folder) {
+// m_create.setDefaultFolder(folder.getOID().toString());
+// }
+//
+// protected void setEditAfterCreate(final boolean editAfterCreate) {
+// m_create.setEditAfterCreate(editAfterCreate);
+// }
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPopup.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPopup.java
new file mode 100755
index 000000000..31f335267
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ItemSearchPopup.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.cms.ui;
+
+import com.arsdigita.bebop.Component;
+import com.arsdigita.bebop.Page;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.parameters.StringParameter;
+import com.arsdigita.globalization.GlobalizedMessage;
+import com.arsdigita.search.SearchConstants;
+
+import org.librecms.contentsection.ContentItem;
+
+import com.arsdigita.xml.Element;
+
+import com.arsdigita.search.ui.QueryGenerator;
+import com.arsdigita.search.ui.ResultsPane;
+import com.arsdigita.web.Web;
+
+import org.libreccm.core.CcmObject;
+import org.librecms.CmsConstants;
+
+import java.math.BigDecimal;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * An extension of {@link ItemSearch} for use in a popup search window. The
+ * display of results is altered so that selecting a result closes the window &
+ * passes the id of the selected item back to the opener.
+ *
+ * @author Stanislav Freidin (sfreidin@arsdigita.com)
+ * @author Jens Pelzetter
+ */
+public class ItemSearchPopup extends ItemSearch {
+
+// private static final org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
+// ItemSearchPopup.class);
+ public static final String WIDGET_PARAM = "widget";
+ public static final String URL_PARAM = "useURL";
+ public static final String QUERY = "query";
+
+ /**
+ * Construct a new ItemSearchPopup component
+ *
+ * @param context the context for the retrieved items. Should
+ * be {@link ContentItem#DRAFT} or
+ * {@link ContentItem#LIVE}
+ * @param limitToContentSection limit the search to the current content
+ * section
+ */
+ public ItemSearchPopup(final String context,
+ final boolean limitToContentSection) {
+ super(context, limitToContentSection);
+ }
+
+ // Hide results by default
+ @Override
+ public void register(final Page page) {
+ super.register(page);
+ page.addGlobalStateParam(new StringParameter(WIDGET_PARAM));
+ page.addGlobalStateParam(new StringParameter(URL_PARAM));
+ page.addGlobalStateParam(new StringParameter(QUERY));
+ }
+
+ @Override
+ protected ItemSearchSection createSearchSection(
+ final String context, final boolean limitToContentSection) {
+ return new ItemSearchSectionPopup(context, limitToContentSection);
+ }
+
+ private static class ItemSearchSectionPopup extends ItemSearchSection {
+
+ public ItemSearchSectionPopup(final String context,
+ final boolean limitToContentSection) {
+ super(context, limitToContentSection);
+ }
+
+ @Override
+ protected Component createResultsPane(final QueryGenerator generator) {
+ return new PopupResultsPane(generator);
+ }
+
+ }
+
+ /**
+ * The default context is Live.No need to append &context=live explicitly.
+ *
+ * @param request
+ * @param objectId
+ *
+ * @return
+ */
+ public static String getItemURL(final HttpServletRequest request,
+ final Long objectId) {
+ // redirect doesn't use /ccm prefix for some reason, so just returning the raw string.
+ //ParameterMap map = new ParameterMap();
+ //map.setParameter("oid", oid.toString());
+ //return URL.there(request, "/redirect/", map).toString();
+ // Always link directly to the live version.
+ if (Web.getWebappContextPath() == null) {
+ return "/redirect/?oid=" + objectId.toString();
+ } else {
+ return Web.getWebappContextPath() + "/redirect/?oid=" + objectId
+ .toString();
+ }
+ }
+
+ private static class PopupResultsPane extends ResultsPane {
+
+ public PopupResultsPane(final QueryGenerator generator) {
+ super(generator);
+ setRelativeURLs(true);
+ setSearchHelpMsg(new GlobalizedMessage("cms.ui.search.help",
+ CmsConstants.CMS_BUNDLE));
+ setNoResultsMsg(new GlobalizedMessage("cms.ui.search.no_results",
+ CmsConstants.CMS_BUNDLE));
+ }
+
+ @Override
+ protected Element generateDocumentXML(final PageState state,
+ final CcmObject doc) {
+ final Element element = super.generateDocumentXML(state, doc);
+
+ element.addAttribute("class", "jsButton");
+
+ final String widget = (String) state.getValue(new StringParameter(
+ WIDGET_PARAM));
+ final String searchWidget = (String) state.getValue(
+ new StringParameter("searchWidget"));
+
+ final boolean useURL = "true".equals(state.getValue(
+ new StringParameter(URL_PARAM)));
+
+ String fillString;
+ if (useURL) {
+ fillString = getItemURL(state.getRequest(), doc.getObjectId());
+ } else {
+ fillString = Long.toString(doc.getObjectId());
+ }
+
+ final String title = doc.getDisplayName();
+
+ final Element jsLabel = new Element(
+ SearchConstants.XML_PREFIX + "jsAction",
+ SearchConstants.XML_NS);
+ jsLabel.addAttribute(
+ "name", "fillItem" + Long.toString(doc.getObjectId()) + "()");
+ jsLabel.setText(generateJSLabel(doc.getObjectId(),
+ widget,
+ searchWidget,
+ fillString,
+ title));
+ jsLabel.addAttribute("action",
+ String.format(
+ "window.opener.document.%s.value = \"%s\"; self.close(); return false;",
+ widget,
+ fillString));
+ element.addContent(jsLabel);
+
+ return element;
+ }
+
+ private String generateJSLabel(final Long docId,
+ final String widget,
+ final String searchWidget,
+ final String fill,
+ final String title) {
+ return " ";
+ }
+
+ }
+
+}
diff --git a/ccm-core/src/main/java/com/arsdigita/search/ui/ResultsPane.java b/ccm-core/src/main/java/com/arsdigita/search/ui/ResultsPane.java
index 797172ee7..41eff76f9 100755
--- a/ccm-core/src/main/java/com/arsdigita/search/ui/ResultsPane.java
+++ b/ccm-core/src/main/java/com/arsdigita/search/ui/ResultsPane.java
@@ -26,28 +26,26 @@ import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.search.SearchConstants;
import com.arsdigita.util.UncheckedWrapperException;
-import org.libreccm.security.Party;
import com.arsdigita.xml.Element;
import com.arsdigita.xml.XML;
import com.arsdigita.web.URL;
import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.Web;
+
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
-import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import java.util.logging.Level;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;