diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreES.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreES.java new file mode 100755 index 000000000..3250654eb --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreES.java @@ -0,0 +1,412 @@ +/* + * 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; + +import com.arsdigita.cms.ContentItem; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.kernel.ACSObject; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.util.Assert; + +import java.util.Date; + +import org.apache.log4j.Logger; + +/** + * Domain class represents a Dublin Core Element Set (DCES) version 1.1 of core + * meta data items. For detailend information and a description of each item + * see http://dublincore.org/documents/dces/ (version 2012). + * + * It manages the persistence of the items by providing the getter/setter methods + * for each. The UI classes, specifically DublinCoreFormSection and + * DublinCoreSummary, use it to retrieve and save the information. + * + * There are a bunch of scalar fields. The only non-scalar field is "Subject", + * which we handle as if it were a category. + * + * Here is a database of all the fields handled + *
+ *
Contributor
+ * An entity responsible for making contributions to the resource. + * Examples include a person, an organization, or a service.
+ *
Coverage
+ * The spatial or temporal topic of the resource, the spatial applicability + * of the resource, or the jurisdiction under which the resource is relevant. + * Recommended best practice is to use a controlled vocabulary such + * as the Thesaurus of Geographic Names [TGN].
+ *
Creator
+ * An entity primarily responsible for making the resource.Examples of a + * Creator include a person, an organization, or a service. Typically, the + * name of a Creator should be used to indicate the entity.
+ *
Date
+ * A point or period of time associated with an event in the lifecycle of + * the resource. Date may be used to express temporal information at any + * level of granularity. Recommended best practice is to use an encoding + * scheme, such as the W3CDTF profile of ISO 8601 [W3CDTF].
+ * Used here as date of creation, or of (last) (re-)publication.
+ *
Description
+ * An account of the resource. Description may include but is not limited + * to: an abstract, a table of contents, a graphical representation, or a + * free-text account of the resource.
+ * Automatically pulled from the associated content item and may be + * configured as editible or read only.
+ *
Format
+ * The file format, physical medium, or dimensions of the resource. Examples + * of dimensions include size and duration. Recommended best practice is to + * use a controlled vocabulary, e.g. list of Internet Media Types [MIME].
+ * Automatically pulled in from the type of associated content item.
+ *
Identifier
+ * An unambiguous reference to the resource within a given context. + * Recommended best practice is to identify the resource by means of a + * string conforming to a formal identification system.
+ *
Language
+ * The language of the resource. Recommended best practice is to use a + * controlled vocabulary such as RFC 4646 [RFC4646].
+ * Automatically pulled in from the associated content type.
+ *
Publisher
+ * An entity responsible for making the resource available. Examples of a + * Publisher include a person, an organization, or a service. Typically, the + * name of a Publisher should be used to indicate the entity.
+ *
Relation
+ * A related resource. Recommended best practice is to identify the related + * resource by means of a string conforming to a formal identification + * system.
+ *
Rights
+ * Information about rights held in and over the resource. Typically, rights + * information includes a statement about various property rights associated + * with the resource, including intellectual property rights.
+ *
Source
+ * A related resource from which the described resource is derived. The + * described resource may be derived from the related resource in whole or + * in part. Recommended best practice is to identify the related resource + * by means of a string conforming to a formal identification system.
+ *
Subject
+ * The topic of the resource. Typically, the subject will be represented + * using keywords, key phrases, or classification codes. Recommended + * best practice is to use a controlled vocabulary.
+ *
Title
+ * A name given to the resource. Typically, a Title will be a name by which + * the resource is formally known.
+ * NOT PERSISTED in database but retrieved as title (display name) from + * content item.
+ *
Type
+ * The nature or genre of the resource. Recommended best practice is to use + * a controlled vocabulary such as the DCMI Type Vocabulary [DCMITYPE]. To + * describe the file format, physical medium, or dimensions of the resource, + * use the Format element.
+ *
+ * It may serve as a base for a more complex and larger set of "DCMI Metadata + * Terms" whereas all those sets include the base element set items. + * + * @author slater@arsdigita.com + * @author Peter Boy + * @version $Id: DublinCoreES.java 1111 2006-04-18 13:57:35Z apevec $ + */ +public class DublinCoreES extends ContentItem { + + /** A logger instance to assist debugging. */ + private static final Logger logger = Logger.getLogger(DublinCoreES.class); + /** PDL Stuff - Base object */ + public static final String BASE_DATA_OBJECT_TYPE = + "com.arsdigita.cms.contentassets.DublinCoreES"; + + /** Config object containing various parameter */ + private static final DublinCoreConfig s_config = DublinCoreConfig.instanceOf(); + + /** Provide other classes with the config object */ + public static final DublinCoreConfig getConfig() { + return s_config; + } + + // /////////////////////////////////////////////////////////////////////// + // + // DataObject constants + + /* Constant for Assoziation betweem DCES and content item */ + public static final String DCES_OWNER = "dcesOwner"; + + /* Constant for Contributor dc item data field */ + public static final String DC_CONTRIBUTOR = "dcContributor"; + /* Constant for Coverage dc item data field */ + public static final String DC_COVERAGE = "dcCoverage"; + /* Constant for Creator dc item data field */ + public static final String DC_CREATOR = "dcCreator"; + public static final String DC_DATE = "dcDate"; + public static final String DC_DESCRIPTION = "dcDescription"; + public static final String DC_FORMAT = "dcFormat"; + public static final String DC_IDENTIFIER = "dcIdentifier"; + public static final String DC_LANGUAGE = "dcLanguage"; + public static final String DC_PUBLISHER = "dcPublisher"; + public static final String DC_RELATION = "dcRelation"; + public static final String DC_RIGHTS = "dcRights"; + public static final String DC_SOURCE = "dcSource"; + public static final String DC_SUBJECT = "dcSubject"; + /* DCES element item title automatically retrieved from associated + * content item title (display name), not persisted here! + public static final String DC_TITLE = ""; */ + public static final String DC_TYPE = "dcType"; + + + // /////////////////////////////////////////////////////////////////////// + // + // Constructors section + + /** + * Default constructor. This creates a new content page. + **/ + protected DublinCoreES() { + super(BASE_DATA_OBJECT_TYPE); + } + + /** + * Constructor. The contained DataObject is retrieved + * from the persistent storage mechanism with an OID + * specified by oid. + * + * @param oid The OID for the retrieved + * DataObject. + **/ + public DublinCoreES(OID oid) { + super(oid); + } + + public DublinCoreES(DataObject obj) { + super(obj); + } + + public DublinCoreES(String type) { + super(type); + } + + + /** + * Create a new empty DCES object and associate it with the given content + * item. + * + * @param ownerItem content item object to associate the new DCES object with + * @return the new DCES object, associated with the given content item + * object but otherwise empty. + */ + public static DublinCoreES create(ContentItem ownerItem) { + DublinCoreES dces = new DublinCoreES(); + dces.setOwner(ownerItem); + dces.setName(ownerItem.getName() + "-dublin-metadata"); + return dces; + } + + + /** + * Retrieve a DCES by its owner (a content item) from the database and + * instantiate a new DCES object. + * + * @param ownerItem the content item object for which we look for meta data + * @return a DCES object + */ + public static DublinCoreES findByOwner(ContentItem ownerItem) { + DataCollection items = SessionManager.getSession() + .retrieve(BASE_DATA_OBJECT_TYPE); + items.addEqualsFilter(DCES_OWNER + "." + ACSObject.ID, + ownerItem.getID()); + + if (items.next()) { + DataObject obj = items.getDataObject(); + items.close(); + return (DublinCoreES)DomainObjectFactory.newInstance(obj); + } + return null; + } + + + // /////////////////////////////////////////////////////////////////////// + // + // The getters / setters section + + /** + * Associate this DCES with the content item it provides Dublin Core meta + * data for. + * @param owner + */ + protected void setOwner(ContentItem ownerItem) { + setAssociation(DCES_OWNER, ownerItem); + } + + /** + * Retrieve the content item this DCES provides meta data for. + * + * @return The contentItem this DCES provides meta data for. + */ + public ContentItem getOwner() { + DataObject dobj = (DataObject)get(DCES_OWNER); + Assert.exists(dobj, DataObject.class); + return (ContentItem)DomainObjectFactory.newInstance(dobj); + } + + + /** + * Retrieve the Contributor metadata item. A contriburor is an entity + * responsible for making contributions to the resource. Examples include + * a person, an organization, or a service. + */ + public String getContributor() { + return (String)get(DC_CONTRIBUTOR); + } + + /** + * Set and store the Contributor metadata item. A contriburor is an entity + * responsible for making contributions to the resource. Examples include + * a person, an organization, or a service. + * + * @param contributor + */ + public void setContributor(String contributor) { + set(DC_CONTRIBUTOR, contributor); + } + + /** + * Retrieve the Coverage metadata item. + * It is the spatial or temporal topic of the resource, the spatial applicability + * of the resource, or the jurisdiction under which the resource is relevant. + * Spatial topic and spatial applicability may be a named place or a location + * specified by its geographic coordinates. Temporal topic may be a named + * period, date, or date range. A jurisdiction may be a named administrative + * entity or a geographic place to which the resource applies. Recommended + * best practice is to use a controlled vocabulary such as the Thesaurus of + * Geographic Names [TGN]. + */ + public String getCoverage() { + return (String)get(DC_COVERAGE); + } + + /** + * Set and store the Coverage metadata item. + * It is the spatial or temporal topic of the resource, the spatial applicability + * of the resource, or the jurisdiction under which the resource is relevant. + * For more details @see getCoverage() + * + * @param coverage + */ + public void setCoverage(String coverage) { + set(DC_COVERAGE, coverage); + } + + + /*Creator*/ + public String getCreator() { + return (String)get(DC_CREATOR); + } + + public void setCreator(String creator) { + set(DC_CREATOR, creator); + } + + + + + /*Date*/ + public String getDate() { + return (String)get(DC_DATE); + } + + public void setDate(String date) { + set(DC_DATE, date); + } + + /*Language*/ + @Override + public String getLanguage() { + return getOwner().getLanguage(); + } + + @Override + public void setLanguage(String language) { + throw new UnsupportedOperationException( + "Metadata language is no longer set explicitly. " + + "Language is pulled from underlying ContentItem"); + //set(DC_LANGUAGE, language); + } + + + /*Description*/ + public String getDescription() { + return (String)get(DC_DESCRIPTION); + } + + public void setDescription(String description) { + set(DC_DESCRIPTION, description); + } + + + /*Identifier*/ + public String getIdentifier() { + return (String)get(DC_IDENTIFIER); + } + + public void setIdentifier(String identifier) { + set(DC_IDENTIFIER, identifier); + } + + /*Publisher*/ + public String getPublisher() { + return (String)get(DC_PUBLISHER); + } + + public void setPublisher(String publisher) { + set(DC_PUBLISHER, publisher); + } + + /*Relation*/ + public String getRelation() { + return (String)get(DC_RELATION); + } + + public void setRelation(String relation) { + set(DC_RELATION, relation); + } + + + /*Rights*/ + public String getRights() { + return (String)get(DC_RIGHTS); + } + + public void setRights(String rights) { + set(DC_RIGHTS, rights); + } + + /*Source*/ + public String getSource() { + return (String)get(DC_SOURCE); + } + + public void setSource(String source) { + set(DC_SOURCE, source); + } + + + /** + * + */ + @Override + public void beforeSave() { + super.beforeSave(); + if (get(DC_LANGUAGE) == null) { + set(DC_LANGUAGE, getOwner().getLanguage() ); + } + } +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreRelatedItemsQueryFactoryImpl.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreRelatedItemsQueryFactoryImpl.java new file mode 100755 index 000000000..82dd2b63d --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreRelatedItemsQueryFactoryImpl.java @@ -0,0 +1,65 @@ +/* + * 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.navigation.RelatedItemsQuery; +import com.arsdigita.navigation.RelatedItemsQueryFactory; +import com.arsdigita.cms.ContentBundle; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.util.StringUtils; +import com.arsdigita.categorization.Category; + +/** + * + * + */ +public class DublinCoreRelatedItemsQueryFactoryImpl extends RelatedItemsQueryFactory { + + public RelatedItemsQuery getRelatedItems(ContentPage page, + Category current) { + + ContentBundle bundle = (ContentBundle)page.getParent(); + DublinCoreES metadata = DublinCoreES.findByOwner(page); + + if (metadata == null) { + return null; + } + + String keywordStr = metadata.getKeywords(); + + String[] keywords = ("".equals(keywordStr) || keywordStr == null) ? + new String[] {} : + StringUtils.split(metadata.getKeywords(), ','); + + if (keywords.length == 0) { + return null; + } + + String first = keywords[0].trim(); + if (first == null || + "".equals(first)) { + return null; + } + + return new RelatedItemsQueryImpl(bundle, + page, + first, + current); + } +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_de.properties b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_de.properties new file mode 100755 index 000000000..df02a499c --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_de.properties @@ -0,0 +1,2 @@ +com.arsdigita.cms.contentassets.dublin_core_label=Metadaten +com.arsdigita.cms.contentassets.dublin_core_description=Bitte die Dublin Core Metadaten eingeben diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_en.properties b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_en.properties new file mode 100755 index 000000000..8cc03a291 --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/DublinCoreResources_en.properties @@ -0,0 +1,2 @@ +com.arsdigita.cms.contentassets.dublin_core_label=Metadata +com.arsdigita.cms.contentassets.dublin_core_description=Enter the Dublin Core metadata diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreControlledList.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreControlledList.java new file mode 100755 index 000000000..5e2737861 --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreControlledList.java @@ -0,0 +1,84 @@ +/* + * 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.ui; + +import com.arsdigita.bebop.form.SingleSelect; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.kernel.ACSObject; +import com.arsdigita.london.terms.Domain; +import com.arsdigita.london.terms.Term; +import com.arsdigita.util.UncheckedWrapperException; + +import java.util.TooManyListenersException; + +/** + * + * + */ +public class DublinCoreControlledList extends SingleSelect { + + private Domain m_domain; + + /** + * + * @param name + * @param domain + */ + public DublinCoreControlledList(String name, + Domain domain) { + super(name); + + m_domain = domain; + m_domain.disconnect(); + + try { + addPrintListener(new PrintListener() { + public void prepare(PrintEvent e) { + DublinCoreControlledList target = + (DublinCoreControlledList)e.getTarget(); + target.populate(); + } + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException("Cannot happen", ex); + } + } + + /** + * + */ + private void populate() { + DomainCollection terms = m_domain.getTerms(); + terms.addPath(Term.MODEL + "." + ACSObject.ID); + terms.addPath(Term.MODEL + "." + ACSObject.OBJECT_TYPE); + terms.addPath(Term.MODEL + "." + ACSObject.DEFAULT_DOMAIN_CLASS); + terms.addOrder(Term.NAME); + + addOption(new Option(null, "--Select Term--")); + while (terms.next()) { + Term term = (Term)terms.getDomainObject(); + + addOption(new Option(term.getName(), + term.getName())); + } + } +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreKeywordsValidationListener.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreKeywordsValidationListener.java new file mode 100755 index 000000000..14af41c6e --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/ui/DublinCoreKeywordsValidationListener.java @@ -0,0 +1,78 @@ +/* + * 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.event.ParameterListener; +import com.arsdigita.bebop.event.ParameterEvent; +import com.arsdigita.bebop.parameters.ParameterData; + +import java.util.StringTokenizer; + +/** + * Verifies that the parameter contains only comma separated + * alpha-numeric words (allowing hypens and underscores). + * + * Note: An empty string will pass the validation tests. + * + * @author Dave Turner + * @version $Id: DublinCoreKeywordsValidationListener.java 652 2005-07-22 13:15:41Z sskracic $ + **/ +public class DublinCoreKeywordsValidationListener implements ParameterListener { + + private String m_label; + + // allow tokens to contain only alpha-numerics, hyphens and underscores + // TODO: configuration parameter maybe? + private static String TOKEN_PATTERN = "(\\w|-)*"; + private static String TOKEN_DELIMITERS = ", \t\n\r\f"; + + /** + * + * @param label + */ + public DublinCoreKeywordsValidationListener(String label) { + m_label = label; + } + + /** + * + */ + public DublinCoreKeywordsValidationListener() { + this("This parameter"); + } + + /** + * + * @param event + */ + public void validate(ParameterEvent event) { + ParameterData data = event.getParameterData(); + String value = data.getValue().toString(); + + StringTokenizer st = new StringTokenizer(value, TOKEN_DELIMITERS); + while (st.hasMoreTokens()) { + String token = st.nextToken(); + if (!token.matches(TOKEN_PATTERN)) { + // The error message + StringBuilder msg = new StringBuilder(128); + msg.append(m_label) + .append(" must contain only comma separated keywords"); + data.addError(msg.toString()); + return; + } + } + } +} diff --git a/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/util/DublinCoreGlobalizationUtil.java b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/util/DublinCoreGlobalizationUtil.java new file mode 100644 index 000000000..650a4cc1b --- /dev/null +++ b/ccm-cms-assets-dublincore/src/com/arsdigita/cms/contentassets/util/DublinCoreGlobalizationUtil.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 Peter Boy, University of Bremen. 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.util; + +import com.arsdigita.globalization.Globalized; +import com.arsdigita.globalization.GlobalizedMessage; + +/** + * Compilation of methods to simplify the handling of globalizing keys. + * Basically it adds the name of package's resource bundle files to the + * globalize methods and forwards to GlobalizedMessage, shortening the + * method invocation in the various application classes. + * + * @author Peter Boy + * @version $Id: $ + */ +public class DublinCoreGlobalizationUtil implements Globalized { + + /** Name of Java resource files to handle DC's globalisation. */ + private static final String BUNDLE_NAME = + "com.arsdigita.cms.contentassets.DublinCoreResources"; + + /** + * Returns a globalized message using the package specific bundle, + * provided by BUNDLE_NAME. + */ + public static GlobalizedMessage globalize(String key) { + return new GlobalizedMessage(key, BUNDLE_NAME); + } + + /** + * Returns a globalized message object, using the package specific bundle, + * as specified by BUNDLE_NAME. Also takes in an Object[] of arguments to + * interpolate into the retrieved message using the MessageFormat class. + */ + public static GlobalizedMessage globalize(String key, Object[] args) { + return new GlobalizedMessage(key, BUNDLE_NAME, args); + } + + public static GlobalizedMessage AuthoringStepLabel() { + return new GlobalizedMessage( + "com.arsdigita.cms.contentassets.dublin_core_label", + BUNDLE_NAME); + } + + public static GlobalizedMessage AuthoringStepDescription() { + return new GlobalizedMessage( + "com.arsdigita.cms.contentassets.dublin_core_description", + BUNDLE_NAME); + } + +}