diff --git a/ccm-cms/src/com/arsdigita/cms/ContentType.java b/ccm-cms/src/com/arsdigita/cms/ContentType.java index 05282a455..bc3855e0c 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentType.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentType.java @@ -574,7 +574,7 @@ public class ContentType extends ACSObject { CompoundFilter or = ff.or(); // The content type must be either of the requested type - or.addFilter(ff.equals(ContentType.ID, ct.ID)); + or.addFilter(ff.equals(ContentType.ID, ct.getID().toString())); // Or must be a descendant of the requested type try { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/Paginator.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/Paginator.java index c04ca8917..38c547853 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/Paginator.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/panels/Paginator.java @@ -10,10 +10,10 @@ import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; /** - * Paginator class for the classes implementing + * Paginator class for the classes implementing * {@link com.arsdigita.cms.contenttypes.ui.GenericOrgaUnitTab}. - * - * @author Jens Pelzetter + * + * @author Jens Pelzetter * @version $Id$ */ public class Paginator { @@ -45,7 +45,7 @@ public class Paginator { logger.debug(String.format("pageNumber = %d", pageNumber)); } this.objectCount = objectCount; - + if (request.getParameter(PAGE_SIZE) == null) { this.pageSize = pageSize; } else { @@ -95,8 +95,8 @@ public class Paginator { logger.debug(String.format("Applying limits: %d, %d", getBegin(), - getEnd())); - query.setRange(getBegin(), getEnd() + 1); + getEnd())); + query.setRange(getBegin(), getEnd() + 1); } public int getPageCount() { @@ -135,10 +135,13 @@ public class Paginator { } private int getEnd() { - int paginatorEnd = getBegin() + getCount(); + int paginatorEnd = getBegin() + getCount() - 1; if (paginatorEnd < 0) { paginatorEnd = 0; } + if (paginatorEnd <= getBegin()) { + paginatorEnd = (getBegin() + 1); + } return paginatorEnd; } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java index 3a2b4d7bf..018f8c3a2 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java @@ -18,7 +18,6 @@ */ package com.arsdigita.cms.ui; - import com.arsdigita.bebop.Component; import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.Container; @@ -30,6 +29,7 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ui.search.ItemQueryComponent; import com.arsdigita.search.ui.ResultsPane; @@ -38,49 +38,66 @@ import com.arsdigita.search.QuerySpecification; /** * Contains a form for specifying search parameters, as well as a - * {@link com.arsdigita.search.ui.ResultsPane} which will perform - * the search and display the results + * {@link com.arsdigita.search.ui.ResultsPane} which will perform the search and + * display the results * * @author Stanislav Freidin (sfreidin@arsdigita.com) * @version $Id: ItemSearchSection.java 1940 2009-05-29 07:15:05Z terry $ */ -public class ItemSearchSection extends FormSection - implements Resettable, QueryGenerator { +public class ItemSearchSection extends FormSection + implements Resettable, QueryGenerator { private static final org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(ItemSearchSection.class); - + org.apache.log4j.Logger. + getLogger(ItemSearchSection.class); public static final String SINGLE_TYPE_PARAM = "single_type"; - - private ItemQueryComponent m_query; private Component m_results; /** - * Construct a new ItemSearchSection component + * Construct a new + * ItemSearchSection 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 + * @param limitToContentSection limit the search to the current content + * section */ public ItemSearchSection(String context, boolean limitToContentSection) { this(null, context, limitToContentSection); } + /** - * Construct a new ItemSearchSection component + * Construct a new + * ItemSearchSection component * * @param context the context for the retrieved items. Should be * {@link ContentItem#DRAFT} or {@link ContentItem#LIVE} - * @param name The name of the search parameter for the particular FormSection - * @param limitToContentSection limit the search to the current content section + * @param name The name of the search parameter for the particular + * FormSection + * @param limitToContentSection limit the search to the current content + * section */ - public ItemSearchSection(String name, String context, boolean limitToContentSection) { + public ItemSearchSection(String name, + String context, + boolean limitToContentSection) { + this(name, context, limitToContentSection, null); + } + + public ItemSearchSection(String name, + String context, + boolean limitToContentSection, + ContentType type) { super(new SimpleContainer()); String thisName = (name == null ? "itemSearch" : name); - - m_query = createQueryGenerator(context, limitToContentSection); + + if (type == null) { + m_query = createQueryGenerator(context, limitToContentSection); + } else { + m_query = createQueryGenerator(context, limitToContentSection, type); + } m_results = createResultsPane(m_query); - + addQueryGenerator(this); addResultsPane(this); addFormListener(); @@ -100,9 +117,16 @@ public class ItemSearchSection extends FormSection m_results.setVisible(state, false); } - protected ItemQueryComponent createQueryGenerator(String context, boolean limitToContentSection) { + protected ItemQueryComponent createQueryGenerator(String context, + boolean limitToContentSection) { return new ItemQueryComponent(context, limitToContentSection); } + + protected ItemQueryComponent createQueryGenerator(String context, + boolean limitToContentSection, + ContentType type) { + return new ItemQueryComponent(context, limitToContentSection, type); + } protected Component createResultsPane(QueryGenerator generator) { ResultsPane pane = new ResultsPane(generator); @@ -113,7 +137,7 @@ public class ItemSearchSection extends FormSection protected void addResultsPane(Container container) { container.add(m_results); } - + protected void addQueryGenerator(Container container) { container.add(m_query); } @@ -137,6 +161,7 @@ public class ItemSearchSection extends FormSection * Displays the "keywords" and "content types" widgets */ private class SearchFormProcessListener implements FormProcessListener { + public void process(FormSectionEvent e) throws FormProcessException { PageState s = e.getPageState(); processQuery(s); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSectionInline.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSectionInline.java index ef768a843..03e3db7b4 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSectionInline.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSectionInline.java @@ -26,6 +26,7 @@ import com.arsdigita.bebop.form.Submit; import com.arsdigita.toolbox.ui.OIDParameter; import com.arsdigita.persistence.OID; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentType; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.xml.Element; @@ -62,6 +63,14 @@ public class ItemSearchSectionInline extends ItemSearchSection { m_name = name; m_item = new OIDParameter(name + "_itemOID"); } + + public ItemSearchSectionInline(String name, String context, + boolean limitToContentSection, + ContentType type) { + super(name, context, limitToContentSection, type); + m_name = name; + m_item = new OIDParameter(name + "_itemOID"); + } @Override public void register(Page p) { diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java index a2ddaeb4f..e100fc74f 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java @@ -45,10 +45,10 @@ import com.arsdigita.web.URL; import org.apache.log4j.Logger; /** - * A class representing a content item search field in an HTML form. - * - * @author Scott Seago (sseago@redhat.com) - * @version $Id: ItemSearchWidget.java 1166 2006-06-14 11:45:15Z fabrice $ + * A class representing a content item search field in an HTML form. + * + * @author Scott Seago (sseago@redhat.com) + * @version $Id: ItemSearchWidget.java 1166 2006-06-14 11:45:15Z fabrice $ */ public class ItemSearchWidget extends FormSection implements BebopConstants, FormSubmissionListener, FormInitListener { @@ -88,14 +88,15 @@ public class ItemSearchWidget extends FormSection public SearchFragment(String name, ItemSearchWidget parent) { super(name, "Search"); this.parent = parent; - this.setAttribute("onClick", "return " + parent.m_item.getName().replace('.', '_') + "Popup(this.form)"); + this.setAttribute("onClick", "return " + parent.m_item.getName(). + replace('.', '_') + "Popup(this.form)"); this.setAttribute("value", "Search"); } @Override public boolean isVisible(PageState ps) { return (!(parent.m_search.isSelected(ps) - || parent.m_searchComponent.hasQuery(ps)) + || parent.m_searchComponent.hasQuery(ps)) && super.isVisible(ps)); } } @@ -107,7 +108,8 @@ public class ItemSearchWidget extends FormSection public ClearFragment(String name, ItemSearchWidget parent) { super(name, "Clear"); this.parent = parent; - this.setAttribute("onClick", "this.form." + parent.m_item.getName() + ".value = \"\"; return false;"); + this.setAttribute("onClick", "this.form." + parent.m_item.getName() + + ".value = \"\"; return false;"); this.setAttribute("value", "Clear"); } } @@ -116,7 +118,8 @@ public class ItemSearchWidget extends FormSection private ItemSearchWidget parent; - public LabelFragment(String name, boolean escaping, ItemSearchWidget parent) { + public LabelFragment(String name, boolean escaping, + ItemSearchWidget parent) { super(name, escaping); this.parent = parent; } @@ -126,15 +129,25 @@ public class ItemSearchWidget extends FormSection private ItemSearchWidget parent; - public ItemSearchFragment(String name, String context, ItemSearchWidget parent, boolean limitToContentSection) { + public ItemSearchFragment(String name, String context, + ItemSearchWidget parent, + boolean limitToContentSection) { super(name, context, limitToContentSection); this.parent = parent; } + public ItemSearchFragment(String name, String context, + ItemSearchWidget parent, + boolean limitToContentSection, + ContentType type) { + super(name, context, limitToContentSection, type); + this.parent = parent; + } + @Override public boolean isVisible(PageState ps) { return ((m_search.isSelected(ps) - || hasQuery(ps)) + || hasQuery(ps)) && super.isVisible(ps)); } } @@ -148,20 +161,22 @@ public class ItemSearchWidget extends FormSection @Override public boolean isVisible(PageState ps) { return ((m_search.isSelected(ps) - || m_searchComponent.hasQuery(ps)) + || m_searchComponent.hasQuery(ps)) && super.isVisible(ps)); } } /** - * Construct a new ItemSearchWidget. The model must be an ItemSearchParameter + * Construct a new ItemSearchWidget. The model must be an + * ItemSearchParameter */ public ItemSearchWidget(ParameterModel model) { this(model, null); } /** - * Construct a new ItemSearchWidget. The model must be an ItemSearchParameter + * Construct a new ItemSearchWidget. The model must be an + * ItemSearchParameter */ public ItemSearchWidget(ParameterModel model, ContentType contentType) { super(new BoxPanel(BoxPanel.VERTICAL)); @@ -194,11 +209,13 @@ public class ItemSearchWidget extends FormSection public void prepare(PrintEvent event) { PageState state = event.getPageState(); Label t = (Label) event.getTarget(); - String formName = ((LabelFragment) t).parent.getSearchButton().getForm().getName(); + String formName = ((LabelFragment) t).parent.getSearchButton(). + getForm().getName(); ParameterMap params = new ParameterMap(); params.setParameter("section_id", - CMS.getContext().getContentSection().getID()); - params.setParameter("widget", formName + ".elements['" + m_item.getName() + "']"); + CMS.getContext().getContentSection().getID()); + params.setParameter("widget", formName + ".elements['" + m_item. + getName() + "']"); if (typeURLFrag != null) { params.setParameter("single_type", typeURLFrag); } @@ -208,34 +225,45 @@ public class ItemSearchWidget extends FormSection ItemSearchPage.class.getName()); s_log.debug("Search URL stub is: " + searchURL); - searchURL = com.arsdigita.cms.dispatcher.Utilities.getWorkspaceURL() - + searchURL; + searchURL = com.arsdigita.cms.dispatcher.Utilities. + getWorkspaceURL() + + searchURL; // TODO Not sure what to do when you get a null here URL url = URL.there(state.getRequest(), searchURL, params); t.setLabel(" "); + + " \n" + + " "); } }); m_topHR = new HRLabel(); add(m_topHR); - FormSection searchSection = new FormSection(new BoxPanel(BoxPanel.HORIZONTAL)); + FormSection searchSection = new FormSection(new BoxPanel( + BoxPanel.HORIZONTAL)); searchSection.add(m_item); searchSection.add(m_search); searchSection.add(m_clear); searchSection.add(m_jsLabel); add(searchSection); - m_searchComponent = new ItemSearchFragment(m_name, ContentItem.DRAFT, this, LIMIT_TO_CONTENT_SECTION); + if (m_contentType == null) { + m_searchComponent = new ItemSearchFragment(m_name, ContentItem.DRAFT, + this, + LIMIT_TO_CONTENT_SECTION); + } else { + m_searchComponent = new ItemSearchFragment(m_name, ContentItem.DRAFT, + this, + LIMIT_TO_CONTENT_SECTION, + m_contentType); + } add(m_searchComponent); addSubmissionListener(this); addInitListener(this); @@ -257,11 +285,11 @@ public class ItemSearchWidget extends FormSection } public ItemSearchWidget(String name, - String objectType) + String objectType) throws DataObjectNotFoundException { this(name, (objectType == null || objectType.length() == 0 - ? null - : ContentType.findByAssociatedObjectType(objectType))); + ? null + : ContentType.findByAssociatedObjectType(objectType))); } public ItemSearchWidget(String name, ContentType contentType) { @@ -326,9 +354,11 @@ public class ItemSearchWidget extends FormSection } if (m_contentType != null) { - s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), m_contentType.getID()); + s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), + m_contentType.getID()); } else { - s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), null); + s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), + null); } throw new FormProcessException("item search FormSection submit"); } else if (m_search.isSelected(s)) { @@ -344,9 +374,11 @@ public class ItemSearchWidget extends FormSection } if (m_contentType != null) { - s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), m_contentType.getID()); + s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), + m_contentType.getID()); } else { - s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), null); + s.setValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM), + null); } throw new FormProcessException("item search FormSection submit"); } else if (m_clear.isSelected(s)) { diff --git a/ccm-cms/src/com/arsdigita/cms/ui/search/ContentTypeFilterWidget.java b/ccm-cms/src/com/arsdigita/cms/ui/search/ContentTypeFilterWidget.java index 0f0f7d965..63340ddf9 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/search/ContentTypeFilterWidget.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/search/ContentTypeFilterWidget.java @@ -18,6 +18,10 @@ */ package com.arsdigita.cms.ui.search; +/** + * @author Unknown + * @author Jens Pelzetter (jens@jp-digital.de) + */ import com.arsdigita.search.ui.FilterWidget; import com.arsdigita.search.Search; import com.arsdigita.search.FilterSpecification; @@ -42,7 +46,8 @@ public class ContentTypeFilterWidget extends FilterWidget { private ContentType[] m_types = null; public ContentTypeFilterWidget(ContentTypeCollection types) { - super(new ContentTypeFilterType(), new ArrayParameter(new StringParameter(ContentTypeFilterType.KEY))); + super(new ContentTypeFilterType(), + new ArrayParameter(new StringParameter(ContentTypeFilterType.KEY))); m_types = new ContentType[(int) types.size()]; @@ -55,7 +60,8 @@ public class ContentTypeFilterWidget extends FilterWidget { this(section.getContentTypes()); } - public ContentTypeFilterWidget(ContentSection section, ContentType parentType) { + public ContentTypeFilterWidget(ContentSection section, + ContentType parentType) { this(section.getDescendantsOfContentType(parentType)); m_section = section; m_parentType = parentType; @@ -79,7 +85,8 @@ public class ContentTypeFilterWidget extends FilterWidget { ContentType ct = m_parentType; BigDecimal singleTypeID = - (BigDecimal) state.getValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM)); + (BigDecimal) state.getValue(new BigDecimalParameter( + ItemSearch.SINGLE_TYPE_PARAM)); if (singleTypeID != null) { try { @@ -108,7 +115,8 @@ public class ContentTypeFilterWidget extends FilterWidget { if (parentType == null) { typesCollection = section.getContentTypes(); } else { - typesCollection = section.getDescendantsOfContentType(parentType); + typesCollection = section.getDescendantsOfContentType( + parentType); } } else { @@ -134,7 +142,15 @@ public class ContentTypeFilterWidget extends FilterWidget { String[] types = (String[]) getValue(state); if (types == null) { - types = new String[0]; + if (getParentType(state) == null) { + types = new String[0]; + } else { + final ContentType[] widgetTypes = getContentTypes(state); + types = new String[widgetTypes.length]; + for (int i = 0; i < widgetTypes.length; i++) { + types[i] = widgetTypes[i].getAssociatedObjectType(); + } + } } return new ContentTypeFilterSpecification(types); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/search/ItemQueryComponent.java b/ccm-cms/src/com/arsdigita/cms/ui/search/ItemQueryComponent.java index 5c0883517..1571c2f42 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/search/ItemQueryComponent.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/search/ItemQueryComponent.java @@ -24,6 +24,7 @@ import com.arsdigita.categorization.Category; import com.arsdigita.cms.CMS; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSectionCollection; +import com.arsdigita.cms.ContentType; import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.search.CreationDateFilterType; import com.arsdigita.cms.search.CreationUserFilterType; @@ -42,12 +43,13 @@ import java.util.ArrayList; import java.util.List; /** - * This class provides a basic query form for CMS admin pages - * that automatically adds components for the maximal set of - * filters supported by the current search query engine. + * This class provides a basic query form for CMS admin pages that automatically + * adds components for the maximal set of filters supported by the current + * search query engine. * * @author unknown * @author Sören Bernstein (sbernstein@quasiweb.de) + * @author Jens Pelzetter (jens@jp-digital.de) */ public class ItemQueryComponent extends BaseQueryComponent { @@ -55,6 +57,12 @@ public class ItemQueryComponent extends BaseQueryComponent { public ItemQueryComponent(String context, final boolean limitToContentSection) { + this(context, limitToContentSection, null); + } + + public ItemQueryComponent(String context, + final boolean limitToContentSection, + ContentType type) { m_context = context; if (Search.getConfig().isIntermediaEnabled()) { @@ -94,18 +102,33 @@ public class ItemQueryComponent extends BaseQueryComponent { } }); - add(new ContentTypeFilterWidget() { + if (type == null) { + add(new ContentTypeFilterWidget() { - @Override - protected ContentSection getContentSection() { - if (limitToContentSection == true && CMS.getContext(). - hasContentSection()) { - return CMS.getContext().getContentSection(); - } else { - return super.getContentSection(); + @Override + protected ContentSection getContentSection() { + if (limitToContentSection == true && CMS.getContext(). + hasContentSection()) { + return CMS.getContext().getContentSection(); + } else { + return super.getContentSection(); + } } - } - }); + }); + } else { + add(new ContentTypeFilterWidget(type) { + + @Override + protected ContentSection getContentSection() { + if (limitToContentSection == true && CMS.getContext(). + hasContentSection()) { + return CMS.getContext().getContentSection(); + } else { + return super.getContentSection(); + } + } + }); + } add(new VersionFilterComponent(context)); if (limitToContentSection == true) { diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java index 1ee1d499c..f3a9f56fd 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisBuilder.java @@ -19,8 +19,8 @@ */ package com.arsdigita.cms.scipublications.exporter.ris; -import java.util.EnumMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; /** * Builds an reference in RIS format. @@ -37,8 +37,9 @@ public class RisBuilder { /** * Fields of the reference. */ - private Map fields = new EnumMap( - RisFields.class); + private List fields =new ArrayList(); + //private Map fields = new EnumMap( + // RisFields.class); public RisBuilder() { } @@ -59,7 +60,8 @@ public class RisBuilder { * @param value The value of the field. */ public void addField(final RisFields field, final String value) { - fields.put(field, value); + //fields.put(field, value); + fields.add(new RisFieldValue(field, value)); } /** @@ -73,10 +75,15 @@ public class RisBuilder { builder = new StringBuilder(); appendField("TY", type.name(), builder); - for (Map.Entry field : fields.entrySet()) { + /*for (Map.Entry field : fields.entrySet()) { appendField(field.getKey().name(), field.getValue(), builder); + }*/ + for(RisFieldValue field : fields) { + appendField(field.getName().name(), + field.getValue(), + builder); } appendField("ER", "", builder); @@ -102,5 +109,5 @@ public class RisBuilder { @Override public String toString() { return toRis(); - } + } }