diff --git a/ccm-cms-assets-dublincore/application.xml b/ccm-cms-assets-dublincore/application.xml
new file mode 100755
index 000000000..a0504faef
--- /dev/null
+++ b/ccm-cms-assets-dublincore/application.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+ The DublinCore asset provides meta data functionality according the the + Dublin Dore Metadata Initiative (DCMI). +
++ For a details information see the Dublin Core + User Guide +
++ "Dublin Core" is a set of 15 generic elements for describing resources: + Creator, Contributor, Publisher, Title, Date, Language, Format, Subject, + Description, Identifier, Relation, Source, Type, Coverage, and Rights. + These are name the "Dublin Core Metadata Elemenmt Set (DCES) created in + 1995, currently at version 1.1 (2012) +
++ According to the Dublin Core initiative it is about more than those 15 + elements. It is part of the "Semantic Weg" approach. The initative + developed "DCMI Metadata Terms", which is a larger set that includes the + 15 elements along with several dozen related properties and classes. They + constitute an "application profile" which uses DCMI metadata terms together + with terms from other, more specialized vocabularies to describe a specific + type of information +
++ The CCM DublinCore asset is an implementation of the Dublin Core Metadata + Element Set, version 1.1 (revision 2012). For detailed information see the + element set reference guide. + It is meant to be expandable to serve as a base for a domain or user specific + and more complex set of metadata or an application profile. +
++ DublinCoreItem.java is the main domain class. +
+ + + diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreEdit.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreEdit.java new file mode 100755 index 000000000..9125251ba --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreEdit.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the Open Software License v2.1 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://rhea.redhat.com/licenses/osl2.1.html. + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + */ + +package com.arsdigita.cms.contentassets.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * Dublin Core authoring kit editing step. + * + * Main entry point into authoring functionality as defined in + * DublinCoreInitializer. It just overwrites the constructor to create a page + * to display the current values and a page to edit the modifiable properties. + * + * + * must call setDisplayComponent(); + * must call addComponent() 0 or more times; + * + * @author slater@arsdigita.com + */ +public class DublinCoreEdit extends SimpleEditStep { + + /** + * Constructor, invokes super class and creates two page elements to display + * all properties and another one to edit the modifiable ones. + * + * @param itemModel + * @param parent + */ + public DublinCoreEdit(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + + super(itemModel, parent); + + DublinCoreForm edit = new DublinCoreForm(itemModel); + DublinCoreSummary display = new DublinCoreSummary(itemModel); + + setDisplayComponent(display); + add("edit", + "edit", + new WorkflowLockedComponentAccess(edit, itemModel), + edit.getCancelButton() + ); + } +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreForm.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreForm.java new file mode 100755 index 000000000..299957adb --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreForm.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the Open Software License v2.1 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://rhea.redhat.com/licenses/osl2.1.html. + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + */ + +package com.arsdigita.cms.contentassets.ui; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ItemSelectionModel; + +import org.apache.log4j.Logger; + +/** + * + * + */ +public class DublinCoreForm extends Form { + + /** A logger instance to assist debugging. */ + private static final Logger s_log = + Logger.getLogger(DublinCoreFormSection.class); + + private ItemSelectionModel m_itemModel; + private DublinCoreFormSection m_section; + + + /** + * Constructor + * @param itemModel + */ + public DublinCoreForm(ItemSelectionModel itemModel) { + + super("dublin"); + + m_itemModel = itemModel; + m_section = new DublinCoreFormSection(false) { + @Override + protected String getInitialDescription(ContentItem item) { + return ((ContentPage) item).getSearchSummary(); + } + + protected ContentItem getSelectedItem(PageState state) { + return m_itemModel.getSelectedItem(state); + } + }; + add(m_section, ColumnPanel.FULL_WIDTH); + } + + public Submit getCancelButton() { + return m_section.getCancelButton(); + } + +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreFormSection.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreFormSection.java new file mode 100755 index 000000000..499c19471 --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreFormSection.java @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the Open Software License v2.1 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://rhea.redhat.com/licenses/osl2.1.html. + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + */ + +package com.arsdigita.cms.contentassets.ui; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.FormSection; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SaveCancelSection; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.DateTime; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.SingleSelect; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.form.Widget; +import com.arsdigita.bebop.parameters.DateTimeParameter; +import com.arsdigita.bebop.parameters.StringLengthValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.bebop.parameters.TrimmedStringParameter; +import com.arsdigita.cms.contentassets.DublinCoreES; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.Party; +import com.arsdigita.london.terms.Domain; + +import java.util.Date; + +import org.apache.log4j.Logger; + +/** + * + * + */ +public abstract class DublinCoreFormSection extends FormSection + implements FormInitListener, + FormProcessListener { + + /** A logger instance to assist debugging. */ + private static final Logger s_log = + Logger.getLogger(DublinCoreFormSection.class); + + + // private TextField m_contributor; //nevertheless, contrib is a db field + + // Originally coverage(Spatial) is a controlled list, therefore Widget here + private Widget m_coverage; + + private TextArea m_creator; //default value pulled in frim config, edited + // value persisted in database + + private TextField m_dateValid; + + private TextArea m_description; + + // private TextField m_format; + // private TextField m_identifier; + // private TextField m_language; + private TextArea m_publisher; + + /* Relation: Related resource. Recommended to identify by a string + * conforming to a formal identification system. */ + // private TextField m_relation; + /** Rights: Information about rights held in and over the resource. + * Statement about various property rights. */ + private TextArea m_rights; + + /* Related resource from which the resource is derived. Recommended to + * identify by a string conforming to a formal identification system. */ + // private TextField m_source; + + /** Topic of the resource, typically represented by keywords or + * classiofication codes. */ + // private TextField m_subject; + private TextField m_keywords; + + /* Given name, not persisted, retrieved from associated content item. */ + // private TextField m_title; + + /* * Nature or genre, recommended to use a controlled vocabulary */ + // private TextField m_type; + + /** Flag whether the discription item should be editable after retrieving + * its value from the associated content item description (abstract) */ + private boolean editableDescription; + + private Submit m_cancel; + + + /** + * Constructor creates the form elements. + * + * @param editableDescription whether the discription item should be editable + */ + public DublinCoreFormSection(boolean editableDescription) { + this.editableDescription = editableDescription; + + + m_dateValid = new TextField(new StringParameter("dateValid")); + m_dateValid.addValidationListener(new StringLengthValidationListener( + 100)); + + m_creator = new TextArea(new StringParameter("creatorOwner")); + m_creator.addValidationListener(new + StringLengthValidationListener(300)); + m_creator.setCols(50); + m_creator.setRows(3); + + m_description = new TextArea(new StringParameter("description")); + if (editableDescription) { + m_description.addValidationListener( + new StringLengthValidationListener(4000)); + m_description.setCols(50); + m_description.setRows(10); + + } else { + m_description.setReadOnly(); + } + + m_publisher = new TextArea(new StringParameter("publisher")); + m_publisher.addValidationListener(new + StringLengthValidationListener(4000)); + m_publisher.setCols(50); + m_publisher.setRows(5); + + m_rights = new TextArea(new StringParameter("rights")); + m_rights.addValidationListener(new StringLengthValidationListener(4000)); + m_rights.setCols(50); + m_rights.setRows(10); + + m_keywords = new TextField(new TrimmedStringParameter("keywords")); + m_keywords.addValidationListener(new StringLengthValidationListener( + 4000)); + m_keywords.addValidationListener(new DublinCoreKeywordsValidationListener()); + m_keywords.setHint("Enter a list of keywords, separated with commas"); + m_keywords.setSize(50); + + + + add(new Label("Coverage:", Label.BOLD), ColumnPanel.RIGHT); + add(m_coverage); + + + + add(new Label("Date (valid):", Label.BOLD), ColumnPanel.RIGHT); + add(m_dateValid); + + add(new Label("Creator (owner):", Label.BOLD), ColumnPanel.RIGHT); + add(m_creator); + + add(new Label("Description:", Label.BOLD), ColumnPanel.RIGHT); + add(m_description); + + add(new Label("Publisher:", Label.BOLD), ColumnPanel.RIGHT); + add(m_publisher); + + add(new Label("Rights:", Label.BOLD), ColumnPanel.RIGHT); + add(m_rights); + + add(new Label("Keywords:", Label.BOLD), ColumnPanel.RIGHT); + add(m_keywords); + + + SaveCancelSection saveCancel = new SaveCancelSection(); + m_cancel = saveCancel.getCancelButton(); + add(saveCancel, ColumnPanel.FULL_WIDTH); + + addInitListener(this); + addProcessListener(this); + } + + /** + * + * @return + */ + public Submit getCancelButton() { + return m_cancel; + } + + /** + * + * @param name + * @param key + * @return + */ + protected Widget createControlledList(String name, String key) { + if (s_log.isDebugEnabled()) { + s_log.debug("Creating controlled list with " + name + " key " + + key); + } + Domain domain = null; + if (key != null) { + try { + domain = Domain.retrieve(key); + } catch (DataObjectNotFoundException ex) { + s_log.warn("Cannot find controlled list key " + key + + " for field " + name); + // nada + } + } + + if (domain == null) { + TextField widget = new TextField(name); + widget.setSize(40); + return widget; + } else { + DublinCoreControlledList widget = new DublinCoreControlledList(name, domain); + return widget; + } + } + + /** + * + * @param fse + * @throws FormProcessException + */ + public void init(FormSectionEvent fse) throws FormProcessException { + + PageState state = fse.getPageState(); + ContentItem item = getSelectedItem(state); + if (item == null) { + return; + } + + DublinCoreES dcItem = DublinCoreES.findByOwner(item); + if (dcItem == null) { + m_creator.setValue(state, DublinCoreES.getConfig() + .getOwnerDefault()); + m_publisher.setValue(state, DublinCoreES.getConfig() + .getPublisherDefault()); + m_rights.setValue(state, DublinCoreES.getConfig() + .getRightsDefault()); + m_description.setValue(state, getInitialDescription(item)); + return; + } + + m_coverage.setValue(state, dcItem.getCoverage()); + + m_creator.setValue(state, + dcItem.getCreator() == null ? + DublinCoreES.getConfig().getOwnerDefault() : + dcItem.getCreator() + ); + + m_publisher.setValue(state, + dcItem.getPublisher() == null ? DublinCoreES.getConfig() + .getPublisherDefault() : dcItem.getPublisher()); + m_rights.setValue(state, dcItem.getRights() == null ? DublinCoreES + .getConfig().getRightsDefault() : dcItem.getRights()); + // m_keywords.setValue(state, dcItem.getKeywords()); + if (editableDescription) { + m_description.setValue(state, dcItem.getDescription()); + } else { + m_description.setValue(state, getInitialDescription(item)); + } + // if (DublinCoreES.getConfig().getUseCCNPortalMetadata()) { + // m_ccn_portal_instance + // .setValue(state, dcItem.getCcnPortalInstance()); + // } + } + + /** + * + * @param fse + * @throws FormProcessException + */ + public void process(FormSectionEvent fse) throws FormProcessException { + + PageState state = fse.getPageState(); + ContentItem item = getSelectedItem(state); + if (item == null) { + return; + } + DublinCoreES dcItem = DublinCoreES.findByOwner(item); + if (dcItem == null) { + dcItem = DublinCoreES.create(item); + } + + + dcItem.setCoverage((String) m_coverage.getValue(state)); + dcItem.setDate((String) m_dateValid.getValue(state)); + + dcItem.setCreator((String) m_creator.getValue(state)); + + dcItem.setPublisher((String) m_publisher.getValue(state)); + dcItem.setRights((String) m_rights.getValue(state)); + + // dcItem.setKeywords((String) m_keywords.getValue(state)); + + if (editableDescription) { + saveDescription((String) m_description.getValue(state), item, dcItem); + } + + + dcItem.save(); + } + + /** + * + * @param state + * @return + */ + protected abstract ContentItem getSelectedItem(PageState state); + + /** + * + * @param item + * @return + */ + protected String getInitialDescription(ContentItem item) { + return ""; + } + + /** + * + * @param description + * @param item + * @param dcItem + */ + protected void saveDescription(String description, ContentItem item, DublinCoreES dcItem ) { + dcItem.setDescription(description); + } + +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreSummary.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreSummary.java new file mode 100755 index 000000000..14adacd9c --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreSummary.java @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the Open Software License v2.1 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://rhea.redhat.com/licenses/osl2.1.html. + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + */ + +package com.arsdigita.cms.contentassets.ui; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.List; +import com.arsdigita.bebop.list.ListCellRenderer; +import com.arsdigita.bebop.list.ListModel; +import com.arsdigita.bebop.list.ListModelBuilder; +import com.arsdigita.cms.contentassets.DublinCoreES; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.category.CategoryIteratorListModel; +import com.arsdigita.util.LockableImpl; +import com.arsdigita.xml.Element; + +import java.util.Date; +import java.text.DateFormat; + +import org.apache.log4j.Category; + +/** + * + * + */ +public class DublinCoreSummary extends ColumnPanel { + + private static final Category s_log = + Category.getInstance( DublinCoreSummary.class ); + + private Label m_title; + + private Label m_contributor; + private Label m_coverage; + private Label m_creator; + + private Label m_date_created; + private Label m_date_issued; + private Label m_date_modified; + private Label m_dateValid; + + private Label m_description; + + private Label m_identifier; + private Label m_language; + + private Label m_publisher; + private Label m_relation; + private Label m_rights; + private Label m_source; + private Label m_subject; + private Label m_documentType; + private List m_categories; + + private ItemSelectionModel m_itemModel; + + /** + * Constructor, creates the panel. + * + * @param itemModel + */ + public DublinCoreSummary(ItemSelectionModel itemModel) { + super(2); + + setColumnWidth( 1, "40%" ); + + m_itemModel = itemModel; + + m_title = new Label(); + + + m_date_created = new Label(); + m_date_issued = new Label(); + m_date_modified = new Label(); + + m_dateValid = new Label(); + + m_documentType = new Label(); + + m_creator = new Label(); + + m_description = new Label(); + m_publisher = new Label(); + m_rights = new Label(); + + m_language = new Label(); + + m_subject = new Label(); + + ListCellRenderer simpleCellRenderer = new SimpleCellRenderer(); + m_categories = new List(new CategoryListModelBuilder(itemModel, + "subject")); + m_categories.setCellRenderer(simpleCellRenderer); + + + add(new Label("Title:", Label.BOLD), ColumnPanel.RIGHT); + add(m_title); + + add(new Label("Coverage:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_coverage); + + add(new Label("Creator (owner):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_creator); + + add(new Label("Date (created):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_date_created); + + add(new Label("Date (issued):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_date_issued); + + add(new Label("Date (modified):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_date_modified); + + add(new Label("Date (valid):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_dateValid); + + add(new Label("Description:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_description); + + add(new Label("Publisher:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_publisher); + + add(new Label("Rights:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_rights); + + add(new Label("Type (document type):", Label.BOLD), + ColumnPanel.RIGHT); + add(m_documentType); + + // add(new Label("Disposal (review):", Label.BOLD), + // ColumnPanel.RIGHT); + // add(m_disposalReview); + + add(new Label("Language:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_language); + + add(new Label("Keywords:", Label.BOLD), + ColumnPanel.RIGHT); + add(m_subject); + + add(new Label("Subject Categories:", Label.BOLD), + ColumnPanel.RIGHT | ColumnPanel.TOP); + add(m_categories); + + } + + /** + * + * @param state + * @param parent + */ + @Override + public void generateXML(PageState state, + Element parent) { + + ContentPage item = (ContentPage)m_itemModel.getSelectedObject(state); + DublinCoreES dces = DublinCoreES.findByOwner(item); + + /* Retrieve dc title from associated content items title. Not persisted + * in dces database table. */ + m_title.setLabel(item.getDisplayName(), state); + + if (dces != null) { + m_coverage.setLabel(dces.getCoverage(), state); + } + + DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, + DateFormat.MEDIUM); + + ContentPage latest; + String issueDate; + if (item.isLive()) { + latest = (ContentPage)item.getLiveVersion(); + + Date issued = item.getLifecycle().getStartDate(); + if (issued != null) { + issueDate = dateFormat.format(issued); + } else { + issueDate = ""; + } + } else { + latest = item; + issueDate = ""; + } + + String creationDate = (item.getCreationDate() != null ? + dateFormat.format( item.getCreationDate()) : "" ); + String modifiedDate = (latest.getLastModifiedDate() != null ? + dateFormat.format( latest.getLastModifiedDate()) : ""); + + m_date_created.setLabel( creationDate, state ); + m_date_issued.setLabel( issueDate, state ); + m_date_modified.setLabel( modifiedDate, state ); + + if (dces != null) { + m_creator.setLabel(dces.getCreator(), state); + } + + m_description.setLabel(item.getSearchSummary(), state); + + if (dces != null) { + m_publisher.setLabel(dces.getPublisher(), state); + m_rights.setLabel(dces.getRights(), state); + } + + m_documentType.setLabel(item.getContentType().getLabel(), state); + + m_language.setLabel(item.getLanguage(), state); + + if (dces != null) { + m_dateValid.setLabel(dces.getDate(), state); + + // m_keywords.setLabel(dces.getKeywords(), state); will be Subject! + } + + super.generateXML(state, parent); + } + + /** + * + */ + protected class CategoryListModelBuilder extends LockableImpl + implements ListModelBuilder { + + private ItemSelectionModel m_itemModel; + private String m_context; + + /** + * + * @param itemModel + * @param context + */ + public CategoryListModelBuilder(ItemSelectionModel itemModel, + String context) { + m_itemModel = itemModel; + m_context = context; + } + + /** + * + * @param l + * @param state + * @return + */ + public ListModel makeModel( List l, PageState state ) { + ContentPage item = (ContentPage) m_itemModel.getSelectedObject(state); + return new CategoryIteratorListModel(item.getCategories(m_context)); + } + } + + /** + * + */ + protected class SimpleCellRenderer implements ListCellRenderer { + + /** + * + * @param list + * @param state + * @param value + * @param key + * @param index + * @param isSelected + * @return + */ + public Component getComponent(List list, + PageState state, + Object value, + String key, + int index, + boolean isSelected) { + return new Label(value.toString()); + } + }; +} diff --git a/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinSuite.java b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinSuite.java new file mode 100755 index 000000000..8f706c6a2 --- /dev/null +++ b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinSuite.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2001-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.contentassets; + +import com.arsdigita.tools.junit.extensions.BaseTestSetup; +import com.arsdigita.tools.junit.extensions.CoreTestSetup; +import com.arsdigita.tools.junit.framework.PackageTestSuite; +import junit.framework.Test; + + +public class DublinSuite extends PackageTestSuite { + + public DublinSuite() { + super(); + } + + public DublinSuite(Class theClass) { + super(theClass); + } + + public DublinSuite(String name) { + super(name); + } + + public static Test suite() { + DublinSuite suite = new DublinSuite(); + populateSuite(suite); + BaseTestSetup wrapper = new DublinTestSetup(suite); + return wrapper; + } + + public static void main(String[] args) throws Exception { + junit.textui.TestRunner.run( suite() ); + } +} diff --git a/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinTestSetup.java b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinTestSetup.java new file mode 100755 index 000000000..67c331749 --- /dev/null +++ b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/DublinTestSetup.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2001-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.contentassets; + +import junit.framework.Test; +import junit.framework.TestSuite; +import com.arsdigita.tools.junit.extensions.CoreTestSetup; + + +/** + * DublinTestSetup + * + * Utility extension of BaseTestSetup that automatically adds the core initializer + * + */ +public class DublinTestSetup extends CoreTestSetup { + public DublinTestSetup(Test test, TestSuite suite) { + super(test, suite); + } + + public DublinTestSetup(TestSuite suite) { + super(suite); + } + + protected void setUp() throws Exception { + addRequiredInitializer("com.arsdigita.cms.Initializer"); + addRequiredInitializer("com.arsdigita.london.util.Initializer"); + addRequiredInitializer("com.arsdigita.london.atoz.Initializer"); + addRequiredInitializer("com.arsdigita.london.terms.Initializer"); + addRequiredInitializer("com.arsdigita.navigation.Initializer"); + addRequiredInitializer("com.arsdigita.london.cms.dublin.Initializer"); + super.setUp(); + } +} diff --git a/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/RelatedItemsTest.java b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/RelatedItemsTest.java new file mode 100755 index 000000000..4f2c010f6 --- /dev/null +++ b/ccm-cms-assets-dublincore/test/src/com/arsdigita/cms/contentassets/RelatedItemsTest.java @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2001-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.contentassets; + +import com.arsdigita.london.util.junit.BaseTestCase; + +import com.arsdigita.cms.Article; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ContentBundle; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ui.authoring.PageCreate; +import com.arsdigita.cms.lifecycle.LifecycleDefinition; +import com.arsdigita.categorization.Category; +import com.arsdigita.categorization.CategoryCollection; +import com.arsdigita.london.terms.Term; +import com.arsdigita.london.terms.Domain; +import com.arsdigita.util.UncheckedWrapperException; +import java.util.HashMap; + +import java.util.Date; +import java.net.URL; +import java.net.MalformedURLException; +import java.math.BigDecimal; + +import org.apache.log4j.Logger; + +public class RelatedItemsTest extends BaseTestCase { + + private final static Logger s_log = Logger.getLogger(RelatedItemsTest.class); + + private static final int NITEMS = 9; + + private ContentBundle[] m_bundles; + private ContentPage[] m_items; + private ContentPage[] m_live; + private Category m_mainNavCat; + + public RelatedItemsTest( String name ) { + super( name ); + } + + public void setUp() { + m_items = new ContentPage[NITEMS]; + m_live = new ContentPage[NITEMS]; + m_bundles = new ContentBundle[NITEMS]; + + ContentSection section = createContentSection(); + ContentType type = createContentType(); + for (int i= 0 ; i < NITEMS ; i++) { + m_items[i] = createItem(type, i); + m_bundles[i] = createBundle(section, m_items[i]); + } + + DublinCoreItem.getConfig().setRelatedItemsSubjectDomain("TEST-LGCL"); + + Domain lgcl = createDomain("TEST-LGCL"); + Domain nav = createDomain("TEST-NAV"); + + Term mainNav = createTerm(nav, 1); + Term mainSubNav = createTerm(nav, 2); + Term otherNav = createTerm(nav, 3); + + mainNav.addNarrowerTerm(mainSubNav, true, true); + + Term mainLGCL = createTerm(lgcl, 1); + Term otherLGCL = createTerm(lgcl, 2); + + + // Main item + mainNav.addObject(m_bundles[0]); + CategoryCollection cats = m_bundles[0].getCategoryCollection(); + assertTrue(cats.next()); + m_mainNavCat = cats.getCategory(); + assertTrue(!cats.next()); + + mainLGCL.addObject(m_bundles[0]); + createDublin(m_items[0], "foo"); + + // Negative: Item in same nav cat with matching lgcl & matching 1st keyword + mainNav.addObject(m_bundles[1]); + mainLGCL.addObject(m_bundles[1]); + createDublin(m_items[1], "foo"); + + // Negative: Item in sub nav cat with matching lgcl & matching 1st keyword + mainSubNav.addObject(m_bundles[2]); + mainLGCL.addObject(m_bundles[2]); + createDublin(m_items[2], "foo"); + + // Positive: Item in diff nav cat with matching lgcl & matching 1st keyword + otherNav.addObject(m_bundles[3]); + mainLGCL.addObject(m_bundles[3]); + createDublin(m_items[3], "foo"); + + // Positive: Item in diff nav cat with matching + // lgcl & matching 1st keyword, non-match second + otherNav.addObject(m_bundles[4]); + mainLGCL.addObject(m_bundles[4]); + createDublin(m_items[4], "foo,bar"); + + // Negative: Item in diff nav cat with matching + // lgcl & non-match 1st keyword, matching 2nd + otherNav.addObject(m_bundles[5]); + mainLGCL.addObject(m_bundles[5]); + createDublin(m_items[5], "bar,foo"); + + // Negative: Item in diff nav cat with non-matching + // lgcl & matching 1st keyword + otherNav.addObject(m_bundles[6]); + otherLGCL.addObject(m_bundles[6]); + createDublin(m_items[6], "foo"); + + // Negative: Item in diff nav cat with non-matching + // lgcl & matching 1st keyword, non-match second + otherNav.addObject(m_bundles[7]); + otherLGCL.addObject(m_bundles[7]); + createDublin(m_items[7], "foo,bar"); + + // Negative: Item in diff nav cat with non-matching + // lgcl & non-match 1st keyword, matching 2nd + otherNav.addObject(m_bundles[8]); + otherLGCL.addObject(m_bundles[8]); + createDublin(m_items[8], "bar,foo"); + + LifecycleDefinition def = createLifecycleDefintion(); + + for (int i = 0 ; i < m_items.length ; i++) { + m_live[i] = (ContentPage)m_items[i].publish(def, new Date()); + m_live[i].getLifecycle().start(); + } + + } + + private LifecycleDefinition createLifecycleDefintion() { + LifecycleDefinition def = new LifecycleDefinition(); + def.setLabel("Test infinite"); + + def.addPhaseDefinition("Forever", "A long time", null, null, null); + + return def; + } + + private Domain createDomain(String name) { + try { + Domain domain = Domain.create( + name, + new URL("http://www.example.com/test/" + name), + name, + name, + "1.0", + new Date()); + return domain; + } catch (MalformedURLException ex) { + throw new RuntimeException("Oh no you don't"); + } + } + + private Term createTerm(Domain domain, + int i) { + return Term.create(new Integer(i), + "term" + i, + false, + null, + domain); + } + + public DublinCoreItem createDublin(ContentPage item, + String keywords) { + DublinCoreItem dc = DublinCoreItem.create(item); + dc.setKeywords(keywords); + return dc; + } + + private ContentSection createContentSection() { + return ContentSection.create("test-section"); + } + + private ContentType createContentType() { + ContentType type = new ContentType(); + type.setAssociatedObjectType(Article.BASE_DATA_OBJECT_TYPE); + type.setLabel("Test Article"); + type.setClassName(PageCreate.class.getName()); + return type; + } + + private ContentPage createItem(ContentType type, + int i) { + ContentPage page = new Article(); + page.setLanguage("en"); + page.setName("item-" + i); + page.setTitle("Item " + i); + page.setContentType(type); + return page; + } + + private ContentBundle createBundle(ContentSection section, + ContentPage page) { + ContentBundle bundle = new ContentBundle(page); + bundle.setParent(section.getRootFolder()); + return bundle; + } + + + public void tearDown() { + } + + public void testRelatedItems() { + RelatedItemsQueryFactoryImpl impl = new RelatedItemsQueryFactoryImpl(); + RelatedItemsQueryImpl query = (RelatedItemsQueryImpl) + impl.getRelatedItems(m_items[0], + m_mainNavCat); + + int i = 3; + while (query.next()) { + BigDecimal workingId = query.getWorkingID(); + BigDecimal itemId = query.getItemID(); + System.out.println("WO" + workingId + " " + itemId); + assertTrue(workingId.equals(m_items[i].getID())); + assertTrue(itemId.equals(m_live[i].getID())); + + i++; + } + assertTrue(i == 5); + } + +} diff --git a/ccm-cms-assets-dublincore/web/themes/heirloom/contentassets/dublincore/xsl/metadata.xsl b/ccm-cms-assets-dublincore/web/themes/heirloom/contentassets/dublincore/xsl/metadata.xsl new file mode 100755 index 000000000..02ae55d13 --- /dev/null +++ b/ccm-cms-assets-dublincore/web/themes/heirloom/contentassets/dublincore/xsl/metadata.xsl @@ -0,0 +1,19 @@ + +