From 36e5dd7b6673ded1bc939da8121ea8f694b46cdd Mon Sep 17 00:00:00 2001 From: quasi Date: Tue, 29 Sep 2009 07:00:18 +0000 Subject: [PATCH] =?UTF-8?q?=C3=9Cberpr=C3=BCfung=20von=20allen=20Aufrufen?= =?UTF-8?q?=20von=20getPrimaryInstance()=20au=C3=9Fer=20in=20Navigation=20?= =?UTF-8?q?abgeschlossen.=20Sollte=20jetzt,=20soweit=20ich=20das=20erkenne?= =?UTF-8?q?n=20konnte,=20korrekt=20sein.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@269 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/cms/ContentBundle.java | 260 ++--- .../dispatcher/MultilingualItemResolver.java | 915 +++++++++--------- .../cms/ui/folder/FolderBrowser.java | 414 ++++---- .../src/com/arsdigita/cms/docmgr/DocLink.java | 142 +-- .../london/atoz/AtoZItemGenerator.java | 7 +- .../com/arsdigita/london/rss/RSSService.java | 276 +++--- 6 files changed, 1009 insertions(+), 1005 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/ContentBundle.java b/ccm-cms/src/com/arsdigita/cms/ContentBundle.java index b1917ebab..9bfab3910 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentBundle.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentBundle.java @@ -57,54 +57,54 @@ import org.apache.log4j.Logger; */ public class ContentBundle extends ContentItem { public static final String versionId = - "$Id: ContentBundle.java 967 2005-10-28 18:08:42Z sskracic $" + - "$Author: sskracic $" + - "$DateTime: $"; - + "$Id: ContentBundle.java 967 2005-10-28 18:08:42Z sskracic $" + + "$Author: sskracic $" + + "$DateTime: $"; + private static final Logger s_log = Logger.getLogger(ContentBundle.class); - + private static DomainObjectObserver s_instancesObserver = - new AbstractDomainObjectObserver() { - public void add(DomainObject dom, String name, - DataObject dobj) { - if (INSTANCES.equals(name)) { - if (dobj != null) { - PermissionService.setContext(dobj.getOID(), dom.getOID()); - } + new AbstractDomainObjectObserver() { + public void add(DomainObject dom, String name, + DataObject dobj) { + if (INSTANCES.equals(name)) { + if (dobj != null) { + PermissionService.setContext(dobj.getOID(), dom.getOID()); } } - }; - + } + }; + /** * The base data object type of a bundle */ public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.ContentBundle"; - + "com.arsdigita.cms.ContentBundle"; + /** * The primary instances association */ public static final String INSTANCES = "instances"; - + /** * The association to AtoZ aliases */ public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders"; - + /** * The default language property */ public static final String DEFAULT_LANGUAGE = "defaultLanguage"; - + private boolean m_wasNew = false; - + /** * Returns the data object type for this bundle. */ public String getBaseDataObjectType() { return BASE_DATA_OBJECT_TYPE; } - + /** * Creates a new bundle. * @@ -112,16 +112,16 @@ public class ContentBundle extends ContentItem { */ public ContentBundle(final ContentItem primary) { super(BASE_DATA_OBJECT_TYPE); - + Assert.exists(primary, ContentItem.class); - + setDefaultLanguage(primary.getLanguage()); setContentType(primary.getContentType()); addInstance(primary); - + super.setName(primary.getName()); } - + /** * Retrieves a bundle. * @@ -130,7 +130,7 @@ public class ContentBundle extends ContentItem { public ContentBundle(final OID oid) throws DataObjectNotFoundException { super(oid); } - + /** * Retrieves a bundle. * @@ -138,10 +138,10 @@ public class ContentBundle extends ContentItem { * retrieve */ public ContentBundle(final BigDecimal id) - throws DataObjectNotFoundException { + throws DataObjectNotFoundException { this(new OID(BASE_DATA_OBJECT_TYPE, id)); } - + /** * Retrieves or creates a bundle using the DataObject * argument. @@ -152,7 +152,7 @@ public class ContentBundle extends ContentItem { public ContentBundle(final DataObject object) { super(object); } - + /** * Creates a bundle. * @@ -162,15 +162,15 @@ public class ContentBundle extends ContentItem { public ContentBundle(final String type) { super(type); } - - + + protected ContentItem makeCopy() { final ContentBundle newItem = (ContentBundle) super.makeCopy(); - + final WorkflowTemplate template = - ContentTypeWorkflowTemplate.getWorkflowTemplate + ContentTypeWorkflowTemplate.getWorkflowTemplate (newItem.getContentSection(), newItem.getContentType()); - + if (template != null) { s_log.debug("Setting up new workflow template"); ItemCollection instances = getInstances(); @@ -181,20 +181,20 @@ public class ContentBundle extends ContentItem { workflow.setObjectID(instance.getID()); workflow.start(Web.getContext().getUser()); workflow.save(); - + } } - + return newItem; } - + /** * Gets the default language of the bundle. */ public final String getDefaultLanguage() { return (String) get(DEFAULT_LANGUAGE); } - + /** * Sets the default language of the bundle. */ @@ -202,12 +202,12 @@ public class ContentBundle extends ContentItem { if (Assert.isEnabled()) { Assert.exists(language, String.class); Assert.truth(language.length() == 2, - language + " is not an ISO639 language code"); + language + " is not an ISO639 language code"); } - + set(DEFAULT_LANGUAGE, language); } - + /** * Adds a language instance to this bundle. This method will fail * if the bundle already contains a different instance for the @@ -225,22 +225,22 @@ public class ContentBundle extends ContentItem { if (s_log.isDebugEnabled()) { s_log.debug("Adding " + instance + " to bundle " + this); } - + if (Assert.isEnabled()) { Assert.exists(instance, ContentItem.class); Assert.falsity(hasInstance(instance.getLanguage()), - "The bundle already contains an instance " + - "for the language " + instance.getLanguage()); + "The bundle already contains an instance " + + "for the language " + instance.getLanguage()); } - + instance.setParent(this); instance.setContentSection(getContentSection()); - + if (Assert.isEnabled()) { Assert.equal(this, instance.getParent()); } } - + /** * Removes a language instance from the bundle. This method will * fail if instance is the primary instance. @@ -259,14 +259,14 @@ public class ContentBundle extends ContentItem { Assert.equal(this, instance.getParent()); Assert.unequal(instance, getPrimaryInstance()); } - + instance.setParent(null); - + if (Assert.isEnabled()) { Assert.truth(instance.getParent() == null); } } - + /** * Gets the primary instance of this bundle. * @@ -277,7 +277,7 @@ public class ContentBundle extends ContentItem { public final ContentItem getPrimaryInstance() { return getInstance(getDefaultLanguage()); } - + /** * Produces a collection containing all language instances in this * bundle. @@ -287,7 +287,7 @@ public class ContentBundle extends ContentItem { public final ItemCollection getInstances() { return new ItemCollection(instances()); } - + /** * Returns a language instance for language or * null if no such instance exists. @@ -306,34 +306,34 @@ public class ContentBundle extends ContentItem { if (Assert.isEnabled()) { Assert.exists(language, String.class); Assert.truth(language.length() == 2, - language + " does not look like a valid language " + - "code"); + language + " does not look like a valid language " + + "code"); } - + final DataAssociationCursor instances = instances(); instances.addEqualsFilter(LANGUAGE, language); - + DataObject dataObject = null; - + if (instances.next()) { final DataObject data = instances.getDataObject(); - + if (Assert.isEnabled()) { //Assert.falsity(instances.next(), // "There is more than one instance with the " + // "same language"); } - + instances.close(); - + return (ContentItem) DomainObjectFactory.newInstance(data); } else { instances.close(); - + return null; } } - + /** * Tells whether instance is present in the bundle. * @@ -342,13 +342,13 @@ public class ContentBundle extends ContentItem { */ public final boolean hasInstance(final ContentItem instance) { Assert.exists(instance, ContentItem.class); - + final DataAssociationCursor instances = instances(); instances.addEqualsFilter(ID, instance.getID()); - + return !instances.isEmpty(); } - + /** * Utility method to check if this bundle already contains an * instance for the given language. @@ -362,15 +362,15 @@ public class ContentBundle extends ContentItem { if (Assert.isEnabled()) { Assert.exists(language, String.class); Assert.truth(language.length() == 2, - language + " is not an ISO639 language code"); + language + " is not an ISO639 language code"); } - + final DataAssociationCursor instances = instances(); instances.addEqualsFilter(LANGUAGE, language); - + return !instances.isEmpty(); } - + /** * List all languages in which this item is available, i.e. the * language codes of all instances in this bundle. @@ -382,24 +382,24 @@ public class ContentBundle extends ContentItem { // XXX For LIVE bundles, there might be several PENDING // instances with the same language. Maybe we should filter // these out and return only one? - + final ItemCollection items = getInstances(); - + final Collection list = new ArrayList(); - + while (items.next()) { list.add(items.getLanguage()); } - + items.close(); - + if (Assert.isEnabled()) { Assert.truth(!list.isEmpty() || getInstances().isEmpty()); } - + return list; } - + /** * Negotiate the right language instance for this bundle and return it. * @@ -420,11 +420,11 @@ public class ContentBundle extends ContentItem { while (instancesCursor.next()) { dataObject = instancesCursor.getDataObject(); language = (String) dataObject.get(LANGUAGE); - + if (s_log.isDebugEnabled()) { s_log.debug("negotiate: language= " + language); } - + if (language != null) { for (int i=0; i < locales.length; i++) { if (language.equals(locales[i].getLanguage())) { @@ -433,8 +433,8 @@ public class ContentBundle extends ContentItem { matchingInstance = dataObject; if (s_log.isDebugEnabled()) { s_log.debug("negotiate: " - + "bestMatch= " + i - + ", language= " + language); + + "bestMatch= " + i + + ", language= " + language); } } // else other match with less preferred language found } @@ -448,13 +448,13 @@ public class ContentBundle extends ContentItem { instancesCursor.close(); if (matchingInstance != null) { return (ContentItem) DomainObjectFactory.newInstance - (matchingInstance); + (matchingInstance); } else { s_log.info("negotiate: no match found!"); return null; } } - + /** * Negotiate the right language instance for this bundle and return it. * @@ -479,22 +479,22 @@ public class ContentBundle extends ContentItem { s_log.debug("negotiate: pref " + i + ": "+ loc.getLanguage()); } } - + final DataAssociationCursor instances = instances(); - + DataObject dataObject = null; int bestMatch = 0; DataObject match = null; String language = null; - + while (instances.next()) { dataObject = instances.getDataObject(); language = (String) dataObject.get(LANGUAGE); - + if (s_log.isDebugEnabled()) { s_log.debug("negotiate: language= " + language); } - + if (language != null) { for (int i=0; i < languageCodes.size(); i++) { if (language.equals( (String)languageCodes.get(i) )) { @@ -503,67 +503,67 @@ public class ContentBundle extends ContentItem { match = dataObject; if (s_log.isDebugEnabled()) { s_log.debug("negotiate: " - + "bestMatch= " + i - + ", language= " + language); + + "bestMatch= " + i + + ", language= " + language); } } // else other match with less preferred language found } } // end for } // end if - + if (bestMatch == 0 && match != null) { s_log.debug("negotiate: best possible match found, exiting"); break; // exit loop when best match is found } } - + instances.close(); - + return (ContentItem) DomainObjectFactory.newInstance(match); } - + // Methods from item that bundle overrides - + protected void beforeSave() { super.beforeSave(); - + final ContentItem primary = getPrimaryInstance(); - + Assert.exists(getContentType(), ContentType.class); - + if (primary != null) { primary.setContentSection(getContentSection()); } } - + protected boolean canPublishToFS() { return false; } - + protected void publishToFS() { throw new UnsupportedOperationException(); } - + public ContentItem publish(final LifecycleDefinition definition, - final Date start) { + final Date start) { throw new UnsupportedOperationException(); } - + public Lifecycle getLifecycle() { // Bundles do not have lifecycles. - + return null; } - + public void setLifecycle(final Lifecycle lifecycle) { // I'd like to do the following, but VersionCopier calls // setLifecycle. //throw new UnsupportedOperationException(); } - - + + /** - * Ignore the INSTANCES property for + * Ignore the INSTANCES property for * ItemCopier.VERSION_COPY. * * @param source the source CustomCopy item @@ -575,25 +575,25 @@ public class ContentBundle extends ContentItem { * to copy the property. */ public boolean copyProperty(final CustomCopy source, - final Property property, - final ItemCopier copier) { + final Property property, + final ItemCopier copier) { if (copier.getCopyType() == ItemCopier.VERSION_COPY) { - if (INSTANCES.equals(property.getName())) { - return true; - } else if (ATOZ_ALIASING_PROVIDERS.equals(property.getName())) { - return true; - } + if (INSTANCES.equals(property.getName())) { + return true; + } else if (ATOZ_ALIASING_PROVIDERS.equals(property.getName())) { + return true; + } } - + return super.copyProperty(source, property, copier); } - + public boolean copyServices(final ContentItem source) { if (s_log.isDebugEnabled()) { s_log.debug("Copying services on bundle " + getName() + " " + - getID() + " using source " + source.getID()); + getID() + " using source " + source.getID()); } - + // Copy categories CategoryCollection categories = source.getCategoryCollection(); while (categories.next() ) { @@ -602,39 +602,39 @@ public class ContentBundle extends ContentItem { category.save(); // XXX remove me } categories.close(); - + return true; } - + protected void initialize() { super.initialize(); addObserver(s_instancesObserver); - + m_wasNew = isNew(); } - + protected void afterSave() { if (m_wasNew) { getPrimaryInstance().setContentSection(getContentSection()); } - + super.afterSave(); } - + // Utility methods - + private DataAssociationCursor instances() { final DataAssociationCursor cursor = - ((DataAssociation) super.get(INSTANCES)).cursor(); - + ((DataAssociation) super.get(INSTANCES)).cursor(); + return cursor; } - + private DataAssociationCursor instances(final String version) { final DataAssociationCursor cursor = instances(); - + cursor.addEqualsFilter(VERSION, version); - + return cursor; } } diff --git a/ccm-cms/src/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java b/ccm-cms/src/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java index 5aac15497..41f669d8f 100755 --- a/ccm-cms/src/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java +++ b/ccm-cms/src/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java @@ -52,32 +52,32 @@ import java.util.StringTokenizer; */ public class MultilingualItemResolver extends AbstractItemResolver implements ItemResolver { public static final String versionId = - "$Id: MultilingualItemResolver.java 1795 2009-02-07 10:47:32Z pboy $" + - "$Author: pboy $" + - "$DateTime: 2004/08/17 23:15:09 $"; - + "$Id: MultilingualItemResolver.java 1795 2009-02-07 10:47:32Z pboy $" + + "$Author: pboy $" + + "$DateTime: 2004/08/17 23:15:09 $"; + private static final Logger s_log = Logger.getLogger - (MultilingualItemResolver.class); - + (MultilingualItemResolver.class); + private static MasterPage s_masterP = null; private static final String ADMIN_PREFIX = "admin"; - + /** * The string identifying an item's ID in the query string of a * URL. */ protected static final String ITEM_ID = "item_id"; - + /** * The separator used in URL query strings; should be either "&" * or ";". */ protected static final String SEPARATOR = "&"; - - public MultilingualItemResolver () { + + public MultilingualItemResolver() { s_log.debug("Undergoing creation"); } - + /** * Returns a content item based on section, url, and use context. * @@ -90,125 +90,125 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * #getCurrentContext}. * @return The content item, or null if no such item exists */ - public ContentItem getItem(final ContentSection section, - String url, - final String context) { - if (s_log.isDebugEnabled()) { - s_log.debug("Resolving the item in content section " + section + - " at URL '" + url + "' for context " + context); - } - - Assert.exists(section, "ContentSection section"); - Assert.exists(url, "String url"); - Assert.exists(context, "String context"); - - Folder rootFolder = section.getRootFolder(); - url = stripTemplateFromURL(url); - - // nothing to do, if root folder is null - if (rootFolder == null) { - s_log.debug("The root folder is null; returning no item"); - } else { - if (s_log.isDebugEnabled()) { - s_log.debug("Using root folder " + rootFolder); - } - - if (ContentItem.LIVE.equals(context)) { - s_log.debug("The use context is 'live'"); - - // We allow for returning null, so the root folder may - // not be live. - //Assert.assertTrue(rootFolder.isLive(), - // "live context - root folder of secion must be live"); - - // If the context is 'live', we need the live item. - - rootFolder = (Folder) rootFolder.getLiveVersion(); - - if (rootFolder == null) { - s_log.debug("The live version of the root folder is " + - "null; returning no item"); - } else { - s_log.debug("The root folder has a live version; " + - "recursing"); - - final String prefix = - section.getURL() + rootFolder.getPath(); - - if (url.startsWith(prefix)) { - if (s_log.isDebugEnabled()) { - s_log.debug("The URL starts with prefix '" + - prefix + "'; removing it"); - } - - url = url.substring(prefix.length()); - } - - final ContentItem item = getItemFromLiveURL(url, rootFolder); - - if (s_log.isDebugEnabled()) { - s_log.debug("Resolved URL '" + url + "' to item " + - item); - } - - return item; - } - } else if (ContentItem.DRAFT.equals(context)) { - s_log.debug("The use context is 'draft'"); - - // For 'draft' items, 'generateUrl()' method returns - // URL like this - // '/acs/wcms/admin/item.jsp?item_id=10201&set_tab=1' - // Check if URL contains any match of string - // 'item_id', then try to instanciate item_id value - // and return FIXME: Please hack this if there is - // more graceful solution. [aavetyan] - - if (Assert.isEnabled()) { - Assert.isTrue - (url.indexOf(ITEM_ID) >= 0, - "url must contain parameter " + ITEM_ID); - } - - final ContentItem item = getItemFromDraftURL(url); - - if (s_log.isDebugEnabled()) { - s_log.debug("Resolved URL '" + url + "' to item " + item); - } - - return item; - } else if (CMSDispatcher.PREVIEW.equals(context)) { - s_log.debug("The use context is 'preview'"); - - final String prefix = CMSDispatcher.PREVIEW + "/"; - - if (url.startsWith(prefix)) { - if (s_log.isDebugEnabled()) { - s_log.debug("The URL starts with prefix '" + - prefix + "'; removing it"); - } - - url = url.substring(prefix.length()); - } - - final ContentItem item = getItemFromLiveURL(url, rootFolder); - - if (s_log.isDebugEnabled()) { - s_log.debug("Resolved URL '" + url + "' to item " + item); - } - - return item; - } else { - throw new IllegalArgumentException - ("Invalid item resolver context " + context); - } - } - - s_log.debug("No item resolved; returning null"); - - return null; - } - + public ContentItem getItem(final ContentSection section, + String url, + final String context) { + if (s_log.isDebugEnabled()) { + s_log.debug("Resolving the item in content section " + section + + " at URL '" + url + "' for context " + context); + } + + Assert.exists(section, "ContentSection section"); + Assert.exists(url, "String url"); + Assert.exists(context, "String context"); + + Folder rootFolder = section.getRootFolder(); + url = stripTemplateFromURL(url); + + // nothing to do, if root folder is null + if (rootFolder == null) { + s_log.debug("The root folder is null; returning no item"); + } else { + if (s_log.isDebugEnabled()) { + s_log.debug("Using root folder " + rootFolder); + } + + if (ContentItem.LIVE.equals(context)) { + s_log.debug("The use context is 'live'"); + + // We allow for returning null, so the root folder may + // not be live. + //Assert.assertTrue(rootFolder.isLive(), + // "live context - root folder of secion must be live"); + + // If the context is 'live', we need the live item. + + rootFolder = (Folder) rootFolder.getLiveVersion(); + + if (rootFolder == null) { + s_log.debug("The live version of the root folder is " + + "null; returning no item"); + } else { + s_log.debug("The root folder has a live version; " + + "recursing"); + + final String prefix = + section.getURL() + rootFolder.getPath(); + + if (url.startsWith(prefix)) { + if (s_log.isDebugEnabled()) { + s_log.debug("The URL starts with prefix '" + + prefix + "'; removing it"); + } + + url = url.substring(prefix.length()); + } + + final ContentItem item = getItemFromLiveURL(url, rootFolder); + + if (s_log.isDebugEnabled()) { + s_log.debug("Resolved URL '" + url + "' to item " + + item); + } + + return item; + } + } else if (ContentItem.DRAFT.equals(context)) { + s_log.debug("The use context is 'draft'"); + + // For 'draft' items, 'generateUrl()' method returns + // URL like this + // '/acs/wcms/admin/item.jsp?item_id=10201&set_tab=1' + // Check if URL contains any match of string + // 'item_id', then try to instanciate item_id value + // and return FIXME: Please hack this if there is + // more graceful solution. [aavetyan] + + if (Assert.isEnabled()) { + Assert.isTrue + (url.indexOf(ITEM_ID) >= 0, + "url must contain parameter " + ITEM_ID); + } + + final ContentItem item = getItemFromDraftURL(url); + + if (s_log.isDebugEnabled()) { + s_log.debug("Resolved URL '" + url + "' to item " + item); + } + + return item; + } else if (CMSDispatcher.PREVIEW.equals(context)) { + s_log.debug("The use context is 'preview'"); + + final String prefix = CMSDispatcher.PREVIEW + "/"; + + if (url.startsWith(prefix)) { + if (s_log.isDebugEnabled()) { + s_log.debug("The URL starts with prefix '" + + prefix + "'; removing it"); + } + + url = url.substring(prefix.length()); + } + + final ContentItem item = getItemFromLiveURL(url, rootFolder); + + if (s_log.isDebugEnabled()) { + s_log.debug("Resolved URL '" + url + "' to item " + item); + } + + return item; + } else { + throw new IllegalArgumentException + ("Invalid item resolver context " + context); + } + } + + s_log.debug("No item resolved; returning null"); + + return null; + } + /** * Fetches the current context based on the page state. * @@ -220,40 +220,40 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It */ public String getCurrentContext(final PageState state) { s_log.debug("Getting the current context"); - + // XXX need to use Web.getContext().getRequestURL() here. String url = state.getRequest().getRequestURI(); - + final ContentSection section = - CMS.getContext().getContentSection(); - + CMS.getContext().getContentSection(); + // If this page is associated with a content section, // transform the URL so that it is relative to the content // section site node. - + if (section != null) { final String sectionURL = section.getURL(); - + if (url.startsWith(sectionURL)) { url = url.substring(sectionURL.length()); } } - + // Remove any template-specific URL components (will only work // if they're first in the URL at this point; verify). XXX but // we don't actually verify? - + url = stripTemplateFromURL(url); - + // Determine if we are under the admin UI. - + if (url.startsWith(ADMIN_PREFIX) || url.startsWith(Utilities.getWorkspaceURL())) { return ContentItem.DRAFT; } else { return ContentItem.LIVE; } } - + /** * Generates a URL for a content item. * @@ -267,13 +267,13 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @see #getCurrentContext */ public String generateItemURL(final PageState state, - final BigDecimal itemId, - final String name, - final ContentSection section, - final String context) { + final BigDecimal itemId, + final String name, + final ContentSection section, + final String context) { return generateItemURL(state, itemId, name, section, context, null); } - + /** * Generates a URL for a content item. * @@ -289,45 +289,45 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @see #getCurrentContext */ public String generateItemURL(final PageState state, - final BigDecimal itemId, - final String name, - final ContentSection section, - final String context, - final String templateContext) { + final BigDecimal itemId, + final String name, + final ContentSection section, + final String context, + final String templateContext) { if (s_log.isDebugEnabled()) { s_log.debug("Generating an item URL for item id " + itemId + - ", section " + section + ", and context '" + - context + "' with name '" + name + "'"); + ", section " + section + ", and context '" + + context + "' with name '" + name + "'"); } - + Assert.exists(itemId, "BigDecimal itemId"); Assert.exists(context, "String context"); Assert.exists(section, "ContentSection section"); - + if (ContentItem.DRAFT.equals(context)) { // No template context here. return generateDraftURL(section, itemId); } else if (CMSDispatcher.PREVIEW.equals(context)) { ContentItem item = new ContentItem(itemId); - + return generatePreviewURL(section, item, templateContext); } else if (ContentItem.LIVE.equals(context)) { ContentItem item = new ContentItem(itemId); - + if (Assert.isEnabled()) { Assert.exists(item, "item"); Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()), - "Generating " + ContentItem.LIVE + " " + - "URL; this item must be the live version"); + "Generating " + ContentItem.LIVE + " " + + "URL; this item must be the live version"); } - + return generateLiveURL(section, item, templateContext); } else { throw new IllegalArgumentException - ("Unknown context '" + context + "'"); + ("Unknown context '" + context + "'"); } } - + /** * Generates a URL for a content item. * @@ -340,12 +340,12 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @see #getCurrentContext */ public String generateItemURL(final PageState state, - final ContentItem item, - final ContentSection section, - final String context) { + final ContentItem item, + final ContentSection section, + final String context) { return generateItemURL(state, item, section, context, null); } - + /** * Generates a URL for a content item. * @@ -360,46 +360,46 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @see #getCurrentContext */ public String generateItemURL(final PageState state, - final ContentItem item, - ContentSection section, - final String context, - final String templateContext) { + final ContentItem item, + ContentSection section, + final String context, + final String templateContext) { if (s_log.isDebugEnabled()) { s_log.debug("Generating an item URL for item " + item + - ", section " + section + ", and context " + - context); + ", section " + section + ", and context " + + context); } - + Assert.exists(item, "ContentItem item"); Assert.exists(context, "String context"); - + if (section == null) { section = item.getContentSection(); } - + if (ContentItem.DRAFT.equals(context)) { if (Assert.isEnabled()) { Assert.isTrue(ContentItem.DRAFT.equals(item.getVersion()), - "Generating " + ContentItem.DRAFT + - " url: item must be draft version"); + "Generating " + ContentItem.DRAFT + + " url: item must be draft version"); } - + return generateDraftURL(section, item.getID()); } else if (CMSDispatcher.PREVIEW.equals(context)) { return generatePreviewURL(section, item, templateContext); } else if (ContentItem.LIVE.equals(context)) { if (Assert.isEnabled()) { Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()), - "Generating " + ContentItem.LIVE + - " url: item must be live version"); + "Generating " + ContentItem.LIVE + + " url: item must be live version"); } - + return generateLiveURL(section, item, templateContext); } else { throw new RuntimeException("Unknown context " + context); } } - + /** * Returns a master page based on page state (and content * section). @@ -408,26 +408,26 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @param request The HTTP request * @return The master page */ - public CMSPage getMasterPage(final ContentItem item, - final HttpServletRequest request) - throws ServletException { - if (s_log.isDebugEnabled()) { - s_log.debug("Getting the master page for item " + item); - } - - // taken from SimpleItemResolver - if (s_masterP == null) { - s_masterP = new MasterPage(); - s_masterP.init(); - } - - if (s_log.isDebugEnabled()) { - s_log.debug("Returning master page " + s_masterP); - } - - return s_masterP; - } - + public CMSPage getMasterPage(final ContentItem item, + final HttpServletRequest request) + throws ServletException { + if (s_log.isDebugEnabled()) { + s_log.debug("Getting the master page for item " + item); + } + + // taken from SimpleItemResolver + if (s_masterP == null) { + s_masterP = new MasterPage(); + s_masterP.init(); + } + + if (s_log.isDebugEnabled()) { + s_log.debug("Returning master page " + s_masterP); + } + + return s_masterP; + } + /** * Returns content item's draft version URL * @@ -436,28 +436,28 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @return generated URL string */ protected String generateDraftURL(final ContentSection section, - final BigDecimal itemId) { + final BigDecimal itemId) { if (s_log.isDebugEnabled()) { s_log.debug("Generating draft URL for item ID " + itemId + - " and section " + section); + " and section " + section); } - + if (Assert.isEnabled()) { Assert.isTrue(section != null && itemId != null, - "get draft url: neither secion nor item " + - "can be null"); + "get draft url: neither secion nor item " + + "can be null"); } - + final String url = ContentItemPage.getItemURL - (section.getPath() + "/", itemId, ContentItemPage.AUTHORING_TAB); - + (section.getPath() + "/", itemId, ContentItemPage.AUTHORING_TAB); + if (s_log.isDebugEnabled()) { s_log.debug("Generated draft URL " + url); } - + return url; } - + /** * Generate a language-independent URL to the * item in the given section.

When a client @@ -476,13 +476,13 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * be presented within the given templateContext */ protected String generateLiveURL(final ContentSection section, - final ContentItem item, - final String templateContext) { + final ContentItem item, + final String templateContext) { if (s_log.isDebugEnabled()) { s_log.debug("Generating live URL for item " + item + " in " + - "section " + section); + "section " + section); } - + /* * URL = URL of section + templateContext + path to the ContentBundle * which contains the item @@ -490,19 +490,19 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It final StringBuffer url = new StringBuffer(400); //url.append(section.getURL()); url.append(section.getPath() + "/"); - + /* * add template context, if one is given */ // This is breaking URL's...not sure why it's here. XXX - // this should work with the appropriate logic. trying again. + // this should work with the appropriate logic. trying again. if (!(templateContext == null || templateContext.length() == 0)) { url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/"); } - + // Try to retrieve the bundle. final ContentItem bundle = (ContentItem) item.getParent(); - + /* * It would be nice if we had a ContentPage here, which * supports the getContentBundle() method, but unfortunately @@ -513,41 +513,41 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It */ if (bundle != null && bundle instanceof ContentBundle) { s_log.debug("Found a bundle; building its file name"); - + final String fname = bundle.getPath(); - + if (s_log.isDebugEnabled()) { s_log.debug("Appending the bundle's file name '" + - fname + "'"); + fname + "'"); } - + url.append(fname); - + } else { s_log.debug("No bundle found; using the item's path directly"); - + url.append(item.getPath()); } - + final String language = item.getLanguage(); - + if (language == null) { s_log.debug("The item has no language; omitting the " + - "language encoding"); + "language encoding"); } else { s_log.debug("Encoding the language of the item passed in, '" + - language + "'"); - + language + "'"); + url.append("." + language); } - + if (s_log.isDebugEnabled()) { s_log.debug("Generated live URL " + url.toString()); } - + return url.toString(); } - + /** * Generate a URL which can be used to preview the * item, using the given @@ -567,11 +567,11 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * item */ protected String generatePreviewURL(ContentSection section, - ContentItem item, - String templateContext) { + ContentItem item, + String templateContext) { Assert.exists(section, "ContentSection section"); Assert.exists(item, "ContentItem item"); - + final StringBuffer url = new StringBuffer(100); url.append(section.getPath()); url.append("/"); @@ -581,14 +581,14 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * add template context, if one is given */ // This is breaking URL's...not sure why it's here. XXX - // this should work with the appropriate logic. trying again. + // this should work with the appropriate logic. trying again. if (!(templateContext == null || templateContext.length() == 0)) { url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/"); } - + // Try to retrieve the bundle. ContentItem bundle = (ContentItem) item.getParent(); - + /* It would be nice if we had a ContentPage here, which * supports the getContentBundle() method, but unfortunately * the API sucks and there is no real distinction between mere @@ -598,33 +598,33 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It */ if (bundle != null && bundle instanceof ContentBundle) { s_log.debug("Found a bundle; using its path"); - + url.append(bundle.getPath()); } else { s_log.debug("No bundle found; using the item's path directly"); - + url.append(item.getPath()); } - + final String language = item.getLanguage(); - + if (language == null) { s_log.debug("The item has no language; omitting the " + - "language encoding"); + "language encoding"); } else { s_log.debug("Encoding the language of the item passed in, '" + - language + "'"); - + language + "'"); + url.append("." + language); } - + if (s_log.isDebugEnabled()) { s_log.debug("Generated preview URL " + url.toString()); } - + return url.toString(); } - + /** * Retrieves ITEM_ID parameter from URL and * instantiates item according to this ID. @@ -639,49 +639,49 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It if (s_log.isDebugEnabled()) { s_log.debug("Looking up the item from draft URL " + url); } - + int pos = url.indexOf(ITEM_ID); - + // XXX this is wrong: here we abort on not finding the // parameter; below we return null. if (Assert.isEnabled()) { Assert.isTrue(pos >= 0, - "Draft URL must contain parameter " + ITEM_ID); + "Draft URL must contain parameter " + ITEM_ID); } - + String item_id = url.substring(pos); // item_id == ITEM_ID=.... ? - + pos = item_id.indexOf("="); // should be exactly after the ITEM_ID string - + if (pos != ITEM_ID.length()) { // item_id seems to be something like ITEM_IDFOO= - + s_log.debug("No suitable item_id parameter found; returning null"); - + return null; // no ID found } - + pos++; // skip the "=" - + // ID is the string between the equal (at pos) and the next separator int i = item_id.indexOf(SEPARATOR); item_id = item_id.substring(pos, Math.min(i, item_id.length() -1)); - + if (s_log.isDebugEnabled()) { s_log.debug("Looking up item using item ID " + item_id); } - + OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, new BigDecimal(item_id)); final ContentItem item = (ContentItem) DomainObjectFactory.newInstance - (oid); - + (oid); + if (s_log.isDebugEnabled()) { s_log.debug("Returning item " + item); } - + return item; } - + /** * Returns a content item based on URL relative to the root * folder. @@ -692,55 +692,55 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * or Folder objects, depending on URL and file language extension */ protected ContentItem getItemFromLiveURL(String url, - Folder parentFolder) { + Folder parentFolder) { if (s_log.isDebugEnabled()) { s_log.debug("Resolving the item for live URL " + url + - " and parent folder " + parentFolder); + " and parent folder " + parentFolder); } - + if (parentFolder == null || url == null || url.equals("")) { if (s_log.isDebugEnabled()) { s_log.debug("The url is null or parent folder was null " + - "or something else is wrong, so just return " + - "the parent folder"); + "or something else is wrong, so just return " + + "the parent folder"); } - + return parentFolder; } - + int len = url.length(); int index = url.indexOf('/'); - + if (index >= 0) { s_log.debug("The URL starts with a slash; paring off the first " + - "URL element and recursing"); - + "URL element and recursing"); + // If we got first slash (index == 0), ignore it and go // on, sample '/foo/bar/item.html.en', in next recursion // will have deal with 'foo' folder. - + String name = index > 0 ? url.substring(0, index) : ""; parentFolder = - // really object identity? Don't think so - // name != "" ? (Folder) parentFolder.getItem(URLEncoder.encode(name), true) - // : parentFolder; - name.isEmpty() ? parentFolder - : (Folder) parentFolder.getItem(URLEncoder.encode(name), true); + // really object identity? Don't think so + // name != "" ? (Folder) parentFolder.getItem(URLEncoder.encode(name), true) + // : parentFolder; + name.isEmpty() ? parentFolder + : (Folder) parentFolder.getItem(URLEncoder.encode(name), true); url = index + 1 < len ? url.substring(index + 1) : ""; - + return getItemFromLiveURL(url, parentFolder); } else { s_log.debug("Found a file element in the URL"); - - String[] nameAndLang = getNameAndLangFromURLFrag(url); + + String[] nameAndLang = getNameAndLangFromURLFrag(url); String name = nameAndLang[0]; String lang = nameAndLang[1]; - + ContentItem item = parentFolder.getItem(URLEncoder.encode(name), false); - return getItemFromLangAndBundle(lang, item); + return getItemFromLangAndBundle(lang, item); } } - + /** * Returns an array containing the the item's name and lang based * on the URL fragment. @@ -750,110 +750,110 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * the lang string */ protected String[] getNameAndLangFromURLFrag(String url) { - String name = null; - String lang = null; - - /* - * Try to find out if there's an extension with the language code - * 1 Get a list of all "extensions", i.e. parts of the url - * which are separated by colons - * 2 If one or more extensions have been found, compare them against - * the list of known language codes - * 2a if a match is found, this language is used to retrieve an instance - * from a bundle - * 2b if no match is found - */ - - final ArrayList exts = new ArrayList(5); - final StringTokenizer tok = new StringTokenizer(url, "."); - - while (tok.hasMoreTokens()) { - exts.add(tok.nextToken()); - } - - if (exts.size() > 0) { - if (s_log.isDebugEnabled()) { - s_log.debug("Found some file extensions to look at; they " + - "are " + exts); - } - - /* - * We have found at least one extension, so we can - * proceed. Now try to find out if one of the - * extensions looks like a language code (we only - * support 2-letter language codes!). - * If so, use this as the language to look for. - */ - - /* - * First element is the NAME of the item, not an extension! - */ - name = (String) exts.get(0); - String ext = null; - Collection supportedLangs = - LanguageUtil.getSupportedLanguages2LA(); - Iterator supportedLangIt = null; - - for (int i = 1; i < exts.size(); i++) { - ext = (String) exts.get(i); - - if (s_log.isDebugEnabled()) { - s_log.debug("Examining extension " + ext); - } - - /* - * Loop through all extensions, but discard the - * first one, which is the name of the item. - */ - if (ext != null && ext.length() == 2) { - /* Only check extensions consisting of 2 - * characters. - * - * Compare current extension with known - * languages; if it matches, we've found the - * language we should use! - */ - supportedLangIt = supportedLangs.iterator(); - while (supportedLangIt.hasNext()) { - if (ext.equals(supportedLangIt.next())) { - lang = ext; - if (s_log.isDebugEnabled()) { - s_log.debug("Found a match; using " + - "language " + lang); - } - break; - } - } - } else { - if (s_log.isDebugEnabled()) { - s_log.debug("Discarding extension " + ext + "; " + - "it is too short"); - } - } - } - } else { - s_log.debug("The file has no extensions; no language was " + - "encoded"); - name = url; // no extension, so we just have a name here - lang = null; // no extension, so we cannot guess the language - } - - if (Assert.isEnabled()) { - Assert.exists(name, "String name"); - Assert.exists(lang == null || lang.length() == 2); - } - - if (s_log.isDebugEnabled()) { - s_log.debug("File name resolved to " + name); - s_log.debug("File language resolved to " + lang); - } - String[] returnArray = new String[2]; - returnArray[0] = name; - returnArray[1] = lang; - return returnArray; + String name = null; + String lang = null; + + /* + * Try to find out if there's an extension with the language code + * 1 Get a list of all "extensions", i.e. parts of the url + * which are separated by colons + * 2 If one or more extensions have been found, compare them against + * the list of known language codes + * 2a if a match is found, this language is used to retrieve an instance + * from a bundle + * 2b if no match is found + */ + + final ArrayList exts = new ArrayList(5); + final StringTokenizer tok = new StringTokenizer(url, "."); + + while (tok.hasMoreTokens()) { + exts.add(tok.nextToken()); + } + + if (exts.size() > 0) { + if (s_log.isDebugEnabled()) { + s_log.debug("Found some file extensions to look at; they " + + "are " + exts); + } + + /* + * We have found at least one extension, so we can + * proceed. Now try to find out if one of the + * extensions looks like a language code (we only + * support 2-letter language codes!). + * If so, use this as the language to look for. + */ + + /* + * First element is the NAME of the item, not an extension! + */ + name = (String) exts.get(0); + String ext = null; + Collection supportedLangs = + LanguageUtil.getSupportedLanguages2LA(); + Iterator supportedLangIt = null; + + for (int i = 1; i < exts.size(); i++) { + ext = (String) exts.get(i); + + if (s_log.isDebugEnabled()) { + s_log.debug("Examining extension " + ext); + } + + /* + * Loop through all extensions, but discard the + * first one, which is the name of the item. + */ + if (ext != null && ext.length() == 2) { + /* Only check extensions consisting of 2 + * characters. + * + * Compare current extension with known + * languages; if it matches, we've found the + * language we should use! + */ + supportedLangIt = supportedLangs.iterator(); + while (supportedLangIt.hasNext()) { + if (ext.equals(supportedLangIt.next())) { + lang = ext; + if (s_log.isDebugEnabled()) { + s_log.debug("Found a match; using " + + "language " + lang); + } + break; + } + } + } else { + if (s_log.isDebugEnabled()) { + s_log.debug("Discarding extension " + ext + "; " + + "it is too short"); + } + } + } + } else { + s_log.debug("The file has no extensions; no language was " + + "encoded"); + name = url; // no extension, so we just have a name here + lang = null; // no extension, so we cannot guess the language + } + + if (Assert.isEnabled()) { + Assert.exists(name, "String name"); + Assert.exists(lang == null || lang.length() == 2); + } + + if (s_log.isDebugEnabled()) { + s_log.debug("File name resolved to " + name); + s_log.debug("File language resolved to " + lang); + } + String[] returnArray = new String[2]; + returnArray[0] = name; + returnArray[1] = lang; + return returnArray; } - - + + /** * Finds a language instance of a content item given the bundle, * name, and lang string @@ -864,74 +864,73 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It * @return The negotiated lang instance for the current request. */ protected ContentItem getItemFromLangAndBundle(String lang, ContentItem item) { - if (item != null && item instanceof ContentBundle) { - if (s_log.isDebugEnabled()) { - s_log.debug("Found content bundle " + item); - } - if (lang == null) { - s_log.debug("The URL has no language encoded in it; " + - "negotiating the language"); - /* - * Either there were no extensions at all, or - * neither one of them matched one of the - * supported languages. So the ContentBundle has - * to decide which language it will show; this - * decision is based on the preferred languages as - * defined in the client's request. - */ - // TODO: do something about this UCI (Unknown Content Item)... - - // XXX sketchy getRequest - HttpServletRequest req = Web.getRequest(); - final ContentItem resolved; - if (req != null) { - resolved = ((ContentBundle) item) - .negotiate(req.getLocales()); + if (item != null && item instanceof ContentBundle) { + if (s_log.isDebugEnabled()) { + s_log.debug("Found content bundle " + item); + } + if (lang == null) { + s_log.debug("The URL has no language encoded in it; " + + "negotiating the language"); + /* + * Either there were no extensions at all, or + * neither one of them matched one of the + * supported languages. So the ContentBundle has + * to decide which language it will show; this + * decision is based on the preferred languages as + * defined in the client's request. + */ + // TODO: do something about this UCI (Unknown Content Item)... + + // XXX sketchy getRequest + HttpServletRequest req = Web.getRequest(); + final ContentItem resolved; + if (req != null) { + resolved = ((ContentBundle) item).negotiate(req.getLocales()); + } else { + // fallback to the primary instance when request is not available + resolved = ((ContentBundle) item).getPrimaryInstance(); + } + if (s_log.isDebugEnabled()) { + s_log.debug("Resolved URL to item " + resolved); + } + return resolved; + } else { + s_log.debug("The URL is encoded with a langauge; " + + "fetching the appropriate item from " + + "the bundle"); + /* + * So the request contains a language code as an + * extension of the "name" ==>go ahead and try to + * find the item from its ContentBundle. Fail if + * the bundle does not contain an instance for the + * given language. + */ + + final ContentItem resolved = + ((ContentBundle) item).getInstance(lang); + + if (s_log.isDebugEnabled()) { + s_log.debug("Resolved URL to item " + resolved); + } + return resolved; + } } else { - // fallback to the primary instance when request is not available - resolved = ((ContentBundle) item).getPrimaryInstance(); + if (s_log.isDebugEnabled()) { + s_log.debug("I expected to get a content bundle; I got " + + item); + } + + /* + * We expected something like a Bundle, but it seems + * like we got something completely different... just + * return this crap and let other people's code deal + * with it ;-). + * + * NOTE: This should never happen :-) + */ + + return item; // might be null } - if (s_log.isDebugEnabled()) { - s_log.debug("Resolved URL to item " + resolved); - } - return resolved; - } else { - s_log.debug("The URL is encoded with a langauge; " + - "fetching the appropriate item from " + - "the bundle"); - /* - * So the request contains a language code as an - * extension of the "name" ==>go ahead and try to - * find the item from its ContentBundle. Fail if - * the bundle does not contain an instance for the - * given language. - */ - - final ContentItem resolved = - ((ContentBundle) item).getInstance(lang); - - if (s_log.isDebugEnabled()) { - s_log.debug("Resolved URL to item " + resolved); - } - return resolved; - } - } else { - if (s_log.isDebugEnabled()) { - s_log.debug("I expected to get a content bundle; I got " + - item); - } - - /* - * We expected something like a Bundle, but it seems - * like we got something completely different... just - * return this crap and let other people's code deal - * with it ;-). - * - * NOTE: This should never happen :-) - */ - - return item; // might be null - } } - + } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/folder/FolderBrowser.java b/ccm-cms/src/com/arsdigita/cms/ui/folder/FolderBrowser.java index 5d30f6231..1b0a68e3b 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/folder/FolderBrowser.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/folder/FolderBrowser.java @@ -80,55 +80,55 @@ import javax.servlet.ServletException; */ public class FolderBrowser extends Table { public static final String versionId = - "$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" + - "$Author: apevec $" + - "$DateTime: 2004/08/17 23:15:09 $"; - + "$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" + + "$Author: apevec $" + + "$DateTime: 2004/08/17 23:15:09 $"; + private static final Logger s_log = Logger.getLogger(FolderBrowser.class); - + private static GlobalizedMessage[] s_headers = { globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"), globalize("cms.ui.folder.type"), globalize("cms.ui.folder.creation_date"), - globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action"), + globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action"), globalize("cms.ui.folder.index") }; - + private static GlobalizedMessage[] s_noIndexHeaders = { globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"), globalize("cms.ui.folder.type"), globalize("cms.ui.folder.creation_date"), - globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action") }; - + globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action") }; + private static final String SORT_ACTION_UP = "sortActionUp"; private static final String SORT_ACTION_DOWN = "sortActionDown"; - + private FolderSelectionModel m_currentFolder; - + private TableActionListener m_folderChanger; - + private TableActionListener m_deleter; - + private TableActionListener m_indexChanger; - + private TableColumn m_nameColumn; private TableColumn m_deleteColumn; private TableColumn m_indexColumn; - + private final static String SORT_KEY_NAME = "name"; private final static String SORT_KEY_TITLE = "title"; private final static String SORT_KEY_LAST_MODIFIED_DATE = "lastModified"; private final static String SORT_KEY_CREATION_DATE = "creationDate"; - + private StringParameter m_sortType = new StringParameter("sortType"); private StringParameter m_sortDirection = new StringParameter("sortDirn"); public FolderBrowser(FolderSelectionModel currentFolder) { //super(new FolderTableModelBuilder(), s_headers); super(); - m_sortType.setDefaultValue(SORT_KEY_NAME); - m_sortDirection.setDefaultValue(SORT_ACTION_UP); - - setModelBuilder(new FolderTableModelBuilder(currentFolder)); - setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers)); - setHeader(new TableHeader(getColumnModel())); + m_sortType.setDefaultValue(SORT_KEY_NAME); + m_sortDirection.setDefaultValue(SORT_ACTION_UP); + + setModelBuilder(new FolderTableModelBuilder(currentFolder)); + setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers)); + setHeader(new TableHeader(getColumnModel())); // DEE 1/18/02: the folder table model builder needs to know about // 'this' in order to set visibility, but 'this' isn't available // until after the super class' constructor has run, so we can't @@ -139,31 +139,31 @@ public class FolderBrowser extends Table { // and pull the foldertablemodelbuilder back with the super class' // accessor. ((FolderTableModelBuilder)getModelBuilder()).setFolderBrowser(this); - + m_currentFolder = currentFolder; /* This code should be uncommented if the desired behaviour is for a change - of folder to cause reversion to default ordering of contained items + of folder to cause reversion to default ordering of contained items (by name ascending). Our feeling is that the user selected ordering should be retained for the duration of the folder browsing session. If - anyone wants this alternative behaviour it should be brought in under + anyone wants this alternative behaviour it should be brought in under the control of a config parameter. - + m_currentFolder.addChangeListener(new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - PageState state = e.getPageState(); - state.setValue(m_sortType, m_sortType.getDefaultValue()); - state.setValue(m_sortDirection, m_sortDirection.getDefaultValue()); - - }}); - */ + + public void stateChanged(ChangeEvent e) { + PageState state = e.getPageState(); + state.setValue(m_sortType, m_sortType.getDefaultValue()); + state.setValue(m_sortDirection, m_sortDirection.getDefaultValue()); + + }}); + */ setClassAttr("dataTable"); - + getHeader().setDefaultRenderer(new com.arsdigita.cms.ui.util.DefaultTableCellRenderer()); - + m_nameColumn = getColumn(0); m_nameColumn.setCellRenderer(new NameCellRenderer()); m_nameColumn.setHeaderRenderer(new HeaderCellRenderer(SORT_KEY_NAME)); @@ -177,50 +177,50 @@ public class FolderBrowser extends Table { m_indexColumn = getColumn(6); m_indexColumn.setCellRenderer(new IndexToggleRenderer()); m_indexColumn.setAlign("center"); - + m_indexChanger = new IndexChanger(m_currentFolder); addTableActionListener(m_indexChanger); } m_folderChanger = new FolderChanger(); addTableActionListener(m_folderChanger); - + m_deleter = new ItemDeleter(); addTableActionListener(m_deleter); - - + + setEmptyView(new Label(globalize("cms.ui.folder.no_items"))); - + Assert.assertNotNull( m_currentFolder.getStateParameter() ); } - + public void register(Page p) { super.register(p); - + p.addComponentStateParam(this, m_currentFolder.getStateParameter()); p.addComponentStateParam(this, m_sortType); p.addComponentStateParam(this, m_sortDirection); p.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - final PageState state = e.getPageState(); - - if (state.isVisibleOnPage(FolderBrowser.this)) { - showHideFolderActions(state); - } + public void actionPerformed(ActionEvent e) { + final PageState state = e.getPageState(); + + if (state.isVisibleOnPage(FolderBrowser.this)) { + showHideFolderActions(state); } - }); + } + }); } - + private void showHideFolderActions(PageState state) { SecurityManager sm = Utilities.getSecurityManager(state); Folder folder = (Folder) m_currentFolder.getSelectedObject(state); Assert.assertNotNull(folder); - + boolean canDelete = - sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder); - + sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder); + m_deleteColumn.setVisible(state, canDelete); } - + public void respond(PageState state) throws ServletException { String key = state.getControlEventName(); String value = state.getControlEventValue(); @@ -228,30 +228,30 @@ public class FolderBrowser extends Table { state.setValue(m_sortType, value); state.setValue(m_sortDirection, SORT_ACTION_UP); } else if ( SORT_ACTION_DOWN.equals(key) ) { - state.setValue(m_sortType, value); + state.setValue(m_sortType, value); state.setValue(m_sortDirection, SORT_ACTION_DOWN); } else { super.respond(state); //throw new ServletException("Unknown control event: " + key); } } - + public FolderSelectionModel getFolderSelectionModel() { return m_currentFolder; } - + private class FolderTableModelBuilder - extends AbstractTableModelBuilder implements PaginationModelBuilder { - + extends AbstractTableModelBuilder implements PaginationModelBuilder { + private FolderSelectionModel m_folder; private RequestLocal m_size; private RequestLocal m_itemColl; private FolderBrowser m_fb; - + public FolderTableModelBuilder(FolderSelectionModel sel) { this(sel, null); } - + public FolderTableModelBuilder(FolderSelectionModel sel, FolderBrowser fb) { super(); m_folder = sel; @@ -259,7 +259,7 @@ public class FolderBrowser extends Table { m_itemColl = new RequestLocal(); m_fb = fb; } - + public TableModel makeModel(Table t, PageState s) { FolderSelectionModel sel = ((FolderBrowser) t).getFolderSelectionModel(); Folder f = (Folder) sel.getSelectedObject(s); @@ -268,68 +268,68 @@ public class FolderBrowser extends Table { } else { t.getRowSelectionModel().clearSelection(s); return new FolderTableModel - ((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s)); + ((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s)); } } - + public int getTotalSize(Paginator paginator, PageState state) { - + Integer size = (Integer) m_size.get(state); - + if (size == null) { - + Folder f = (Folder) m_folder.getSelectedObject(state); - + Folder.ItemCollection itemColl = f.getPrimaryInstances(); - + if (itemColl == null) { return 0; } - + PermissionService.filterQuery( - itemColl, - "id", - PrivilegeDescriptor.READ, - Kernel.getContext().getParty().getOID() - ); - + itemColl, + "id", + PrivilegeDescriptor.READ, + Kernel.getContext().getParty().getOID() + ); + size = new Integer( (int) f.getPrimaryInstances().size()); - + itemColl.setRange(new Integer(paginator.getFirst(state)), - new Integer(paginator.getLast(state) + 1)); - + new Integer(paginator.getLast(state) + 1)); + String sortKey = (String)state.getValue(m_sortType); String direction = "asc"; if (SORT_ACTION_DOWN.equals((String)state.getValue(m_sortDirection))) { direction = "desc"; } - + if ( sortKey.equals(SORT_KEY_TITLE) ) { itemColl.setOrder("lower(item." + - ContentItem.DISPLAY_NAME + ") " + - direction); + ContentItem.DISPLAY_NAME + ") " + + direction); } else if ( sortKey.equals(SORT_KEY_NAME) ) { itemColl.setOrder("lower(item." + - ContentItem.NAME + ") " + direction); + ContentItem.NAME + ") " + direction); } else if ( sortKey.equals(SORT_KEY_LAST_MODIFIED_DATE)) { itemColl.setOrder("item.auditing.lastModifiedDate " + - direction); + direction); } else if ( sortKey.equals(SORT_KEY_CREATION_DATE)) { itemColl.setOrder("item.auditing.creationDate " + - direction); + direction); } - + m_size.set(state, size); m_itemColl.set(state, itemColl); } - + return size.intValue(); } - + public void setFolderBrowser(FolderBrowser fb) { m_fb = fb; } - + /** * Indicates whether the paginator should be visible, * based on the visibility of the folder browser itself. @@ -341,55 +341,55 @@ public class FolderBrowser extends Table { return (m_fb != null)?m_fb.isVisible(state):true; } } - - + + private class HeaderCellRenderer - extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer { - + extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer { + private String m_key; - + public HeaderCellRenderer(String key) { super(true); m_key = key; } - + public Component getComponent(final Table table, final PageState state, - Object value, - boolean isSelected, Object key, - int row, int column) { + Object value, + boolean isSelected, Object key, + int row, int column) { String headerName = (String)((GlobalizedMessage)value).localize(); String sortKey = (String)state.getValue(m_sortType); final boolean isCurrentKey = sortKey.equals(m_key); final String currentSortDirection = (String)state.getValue(m_sortDirection); String imageURLStub = null; - + if (SORT_ACTION_UP.equals(currentSortDirection)) { imageURLStub = "gray-triangle-up.gif"; } else { imageURLStub = "gray-triangle-down.gif"; } - + ControlLink cl = new ControlLink(headerName) { - public void setControlEvent(PageState ps) { - String sortDirectionAction = null; - // by default, everything sorts "up" unless it - // is the current key and it is already pointing up - if (SORT_ACTION_UP.equals(currentSortDirection) && + public void setControlEvent(PageState ps) { + String sortDirectionAction = null; + // by default, everything sorts "up" unless it + // is the current key and it is already pointing up + if (SORT_ACTION_UP.equals(currentSortDirection) && isCurrentKey) { - sortDirectionAction = SORT_ACTION_DOWN; - } else { - sortDirectionAction = SORT_ACTION_UP; - } - ps.setControlEvent(table, - sortDirectionAction, - m_key); + sortDirectionAction = SORT_ACTION_DOWN; + } else { + sortDirectionAction = SORT_ACTION_UP; } - }; + ps.setControlEvent(table, + sortDirectionAction, + m_key); + } + }; Label l = new Label(); l.setLabel("" + headerName + ""); l.setOutputEscaping(false); l.setFontWeight(Label.BOLD); - + SimpleContainer container = new SimpleContainer(); container.add(l); if ( isCurrentKey ) { @@ -401,7 +401,7 @@ public class FolderBrowser extends Table { return cl; } } - + /** * Produce links to view an item or control links for folders * to change into the folder. @@ -410,49 +410,49 @@ public class FolderBrowser extends Table { public NameCellRenderer() { super(true); } - + public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { - + 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); + isSelected, key, row, column); } else { ContentSection section = CMS.getContext().getContentSection(); BigDecimal id = coll.getID(); - + if (section == null) { return new Label(name); } else { ItemResolver resolver = section.getItemResolver(); return new Link(name, resolver.generateItemURL - (state, id, name, section, coll.getVersion())); + (state, id, name, section, coll.getVersion())); } } } } - - + + /** * Produce delete links for items and non-empty folders. */ private static class ActionCellRenderer implements TableCellRenderer { private static Label s_noAction; private static ControlLink s_link; - + static { s_noAction = new Label(" ", false); s_noAction.lock(); s_link = new ControlLink(new Label(globalize("cms.ui.folder.delete"))); s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ? } - + public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { + boolean isSelected, Object key, + int row, int column) { if ( ((Boolean) value).booleanValue() ) { return s_link; } else { @@ -460,42 +460,42 @@ public class FolderBrowser extends Table { } } } - + private final class IndexToggleRenderer implements TableCellRenderer { - + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { - + if ( value == null ) { return new Label(GlobalizationUtil.globalize("cms.ui.folder.na")); } ControlLink link = new ControlLink(""); - + if (((Boolean) value).booleanValue()) { link.setClassAttr("checkBoxChecked"); } else { link.setClassAttr("checkBoxUnchecked"); } - + return link; } } - + // Deletes an item private class ItemDeleter extends TableActionAdapter { public void cellSelected(TableActionEvent e) { int col = e.getColumn().intValue(); - + if ( m_deleteColumn != getColumn(col) ) { return; } - + PageState s = e.getPageState(); BigDecimal id = new BigDecimal(e.getRowKey().toString()); - + OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, id.abs()); - + final DomainObject item = DomainObjectFactory.newInstance(oid); - + if (item != null) { if (item instanceof ContentBundle) { ContentBundle bundle = (ContentBundle) item; @@ -506,11 +506,11 @@ public class FolderBrowser extends Table { } item.delete(); } - + ((Table) e.getSource()).clearSelection(s); } } - + /** * Table model around ItemCollection */ @@ -522,24 +522,24 @@ public class FolderBrowser extends Table { private static final int LAST_MODIFIED = 4; private static final int DELETABLE = 5; private static final int IS_INDEX = 6; - + private PageState m_state; private FolderBrowser m_table; private Folder.ItemCollection m_itemColl; private Folder m_fol; private BigDecimal m_folIndexID; - + //old constructor before using paginator //public FolderTableModel(Folder folder) { //m_itemColl = folder.getItems(); //} - + public FolderTableModel - (FolderBrowser table, PageState state, Folder.ItemCollection itemColl) { + (FolderBrowser table, PageState state, Folder.ItemCollection itemColl) { m_state = state; m_table = table; m_itemColl = itemColl; - + m_fol = (Folder) table.getFolderSelectionModel().getSelectedObject(state); if (!hideIndexColumn()) { ContentBundle indexItem = m_fol.getIndexItem(); @@ -550,83 +550,83 @@ public class FolderBrowser extends Table { } } } - + public int getColumnCount() { return hideIndexColumn() ? 6 : 7; } - + public boolean nextRow() { return m_itemColl.next(); } - + public Object getElementAt(int columnIndex) { switch (columnIndex) { - case NAME: - return m_itemColl; - case TITLE: - return m_itemColl.getDisplayName(); - case TYPE: - return m_itemColl.getTypeLabel(); - case CREATION_DATE: { - java.util.Date creationDate = m_itemColl.getCreationDate(); - if ( creationDate == null ) { - return "--"; + case NAME: + return m_itemColl; + case TITLE: + return m_itemColl.getDisplayName(); + case TYPE: + return m_itemColl.getTypeLabel(); + case CREATION_DATE: { + java.util.Date creationDate = m_itemColl.getCreationDate(); + if ( creationDate == null ) { + return "--"; + } + return FormatStandards.formatDate(creationDate); } - return FormatStandards.formatDate(creationDate); - } - case LAST_MODIFIED: { - java.util.Date lastModified = m_itemColl.getLastModifiedDate(); - if ( lastModified == null ) { - return "--"; + case LAST_MODIFIED: { + java.util.Date lastModified = m_itemColl.getLastModifiedDate(); + if ( lastModified == null ) { + return "--"; + } + return FormatStandards.formatDate(lastModified); } - return FormatStandards.formatDate(lastModified); - } - case DELETABLE: - return new Boolean(isDeletable()); - case IS_INDEX: { - if (hideIndexColumn()) { + case DELETABLE: + return new Boolean(isDeletable()); + case IS_INDEX: { + if (hideIndexColumn()) { + throw new IndexOutOfBoundsException("Column index " + columnIndex + + " not in table model."); + } + if ( m_itemColl.isFolder() ) { + return null; + } + if ( m_folIndexID == null ) { + return new Boolean(false); + } + return new Boolean(m_folIndexID + .compareTo(m_itemColl.getBundleID()) == 0); + } + default: throw new IndexOutOfBoundsException("Column index " + columnIndex + - " not in table model."); - } - if ( m_itemColl.isFolder() ) { - return null; - } - if ( m_folIndexID == null ) { - return new Boolean(false); - } - return new Boolean(m_folIndexID - .compareTo(m_itemColl.getBundleID()) == 0); - } - default: - throw new IndexOutOfBoundsException("Column index " + columnIndex + - " not in table model."); + " not in table model."); } } - + public boolean isDeletable() { if (s_log.isDebugEnabled()) { s_log.debug("Checking to see if " + this + " is deletable"); } - + if (m_itemColl.isLive()) { if (s_log.isDebugEnabled()) { s_log.debug("The item is live; it cannot be deleted"); } - + return false; } - + if (m_itemColl.isFolder()) { if (!m_itemColl.hasChildren()) { if (s_log.isDebugEnabled()) { s_log.debug("The item is an empty folder; it may be " + - "deleted"); + "deleted"); } return true; } else { if (s_log.isDebugEnabled()) { s_log.debug("The folder is not empty; it cannot be " + - "deleted"); + "deleted"); } return false; } @@ -634,23 +634,23 @@ public class FolderBrowser extends Table { if (s_log.isDebugEnabled()) { s_log.debug("The item is not a folder; it may be deleted"); } - + return true; } } - + public Object getKeyAt(int columnIndex) { // Mark folders by using their negative ID (dirty, dirty) return ( m_itemColl.isFolder() ) ? m_itemColl.getID().negate() - : m_itemColl.getBundleID(); + : m_itemColl.getBundleID(); } } - + private class FolderChanger extends TableActionAdapter { public void cellSelected(TableActionEvent e) { PageState s = e.getPageState(); int col = e.getColumn().intValue(); - + if ( m_nameColumn != getColumn(col) ) { return; } @@ -661,29 +661,29 @@ public class FolderBrowser extends Table { } } } - + private class IndexChanger extends TableActionAdapter { - + private FolderSelectionModel m_fol; - + public IndexChanger(FolderSelectionModel fol) { super(); m_fol = fol; } - + public void cellSelected(TableActionEvent e) { PageState state = e.getPageState(); - + BigDecimal rowkey = new BigDecimal((String)e.getRowKey()); if (rowkey == null){ return; } - + try { ContentBundle contentItem = new ContentBundle(rowkey); - + Folder folder = (Folder) m_fol.getSelectedObject(state); - + ContentBundle currentIndexItem = (ContentBundle) folder.getIndexItem(); if ( currentIndexItem == null || (currentIndexItem.getID().compareTo(contentItem.getID()) != 0)) { folder.setIndexItem(contentItem); @@ -696,7 +696,7 @@ public class FolderBrowser extends Table { } } } - + /** * Getting the GlobalizedMessage using a CMS Class targetBundle. * @@ -706,7 +706,7 @@ public class FolderBrowser extends Table { private static GlobalizedMessage globalize(String key) { return FolderManipulator.globalize(key); } - + private static boolean hideIndexColumn() { return ContentSection.getConfig().getHideFolderIndexCheckbox(); } diff --git a/ccm-docmgr/src/com/arsdigita/cms/docmgr/DocLink.java b/ccm-docmgr/src/com/arsdigita/cms/docmgr/DocLink.java index e72324e76..321f9aa1d 100755 --- a/ccm-docmgr/src/com/arsdigita/cms/docmgr/DocLink.java +++ b/ccm-docmgr/src/com/arsdigita/cms/docmgr/DocLink.java @@ -48,26 +48,26 @@ import org.apache.log4j.Logger; /** * DomainObject class which represents DocLink ContentType objects. - * + * * A DocLink will either have an internal reference to another Document * _or_ contain an external (http) URL. * * @author Shashin Shinde * @author Crag Wolfe - * + * * $Id: DocLink.java,v 1.1 2004/12/15 16:06:37 pkopunec Exp $ * */ public class DocLink extends ContentPage implements Resource, Searchable { - - private static final Logger s_log = Logger.getLogger(DocLink.class.getName()); - + + private static final Logger s_log = Logger.getLogger(DocLink.class.getName()); + private static final String NAME_SUFFIX = "-LinkTo"; /** Data object type for this domain object */ public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.docmgr.DocLink"; + "com.arsdigita.cms.docmgr.DocLink"; /** Data object type for this domain object (for CMS compatibility) */ public static final String TYPE = BASE_DATA_OBJECT_TYPE; @@ -80,73 +80,73 @@ public class DocLink extends ContentPage implements Resource, Searchable { public DocLink() { this(BASE_DATA_OBJECT_TYPE); try { - setContentType( - ContentType.findByAssociatedObjectType(BASE_DATA_OBJECT_TYPE)); + setContentType( + ContentType.findByAssociatedObjectType(BASE_DATA_OBJECT_TYPE)); } catch (DataObjectNotFoundException e) { throw new UncheckedWrapperException( - (String) GlobalizationUtil - .globalize("cms.contenttypes.event_type_not_registered") - .localize(), - e); + (String) GlobalizationUtil + .globalize("cms.contenttypes.event_type_not_registered") + .localize(), + e); } } - + public DocLink(BigDecimal id) throws DataObjectNotFoundException { this(new OID(BASE_DATA_OBJECT_TYPE, id)); } - + public DocLink(OID id) throws DataObjectNotFoundException { super(id); } - + public DocLink(DataObject obj) { super(obj); } - + public DocLink(String type) { super(type); } - + public void setTitle(String title) { setName(URLEncoder.encode(title)); super.setTitle(title); } - + /** * @see com.arsdigita.cms.docmgr.Resource#getDescription() */ public String getDescription() { return (String) get(DESCRIPTION); } - + public void setDescription(String desc){ set(DESCRIPTION,desc); } - + public boolean isExternal() { String s = getExternalURL(); return s != null && s.length() > 0; } - + public String getExternalURL() { return (String) get(EXTERNAL_URL); } - + public void setExternalURL(String externalURL){ set(EXTERNAL_URL,externalURL); } - + public Repository getRepository() { if (get(REPOSITORY) == null) { return null; } return new Repository((DataObject) get(REPOSITORY)); } - + public void setRepository(Repository repository) { set(REPOSITORY, repository); } - + /* redundant to versioning, only for performance */ public Date getLastModifiedLocal() { return (Date) get(LAST_MOD_LOCAL); @@ -156,8 +156,8 @@ public class DocLink extends ContentPage implements Resource, Searchable { public void setLastModifiedLocal(Date last) { set(LAST_MOD_LOCAL, last); } - - /** + + /** * Set Target Document of this Link.Also set's the name of the Link. * i.e. target.getName()-LinkToxxxx */ @@ -167,7 +167,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { } /** - * Helper method to generate the name of the Link using the + * Helper method to generate the name of the Link using the * NAME_SUFFIX,target Document id,and target document name. * Also truncates the name if it exceeds 200 characters. */ @@ -186,24 +186,24 @@ public class DocLink extends ContentPage implements Resource, Searchable { return buf.toString(); } } - + public Document getTarget() { if (get(TARGET) == null) { return null; } return new Document((DataObject) get(TARGET)); } - + /** * @see com.arsdigita.cms.docmgr.Resource#getParentResource(). * Returns the parent DocFolder */ public Resource getParentResource() { DocFolder parent = - (DocFolder) ((ContentBundle) getParent()).getParent(); + (DocFolder) ((ContentBundle) getParent()).getParent(); return parent; } - + /** * @see com.arsdigita.cms.docmgr.Resource#isFolder(). * returns false to indicate that it's not a folder. @@ -211,7 +211,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { public boolean isFolder() { return false; } - + /** * @see com.arsdigita.cms.docmgr.Resource#isFile(). * returns true to indicate that it's a file. @@ -219,7 +219,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { public boolean isFile() { return true; } - + /** * Copies the resource into another location. Preserves the * original name of the resource but places the copy inside a new @@ -231,7 +231,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { public Resource copyTo(Resource parent) throws ResourceExistsException { return copyTo(getTitle(), parent); } - + /** * Copies the resource into another location with a new name. * @@ -240,16 +240,16 @@ public class DocLink extends ContentPage implements Resource, Searchable { * @return a copy of the original resource. */ public Resource copyTo(String name, final Resource parent) throws ResourceExistsException { - Folder.ItemCollection ic = - ((Folder) parent).getItems(); + Folder.ItemCollection ic = + ((Folder) parent).getItems(); ic.addEqualsFilter("name",URLEncoder.encode(name)); boolean resourceExists = ic.next(); ic.close(); if(resourceExists) { throw new ResourceExistsException - ("Copying document would result in duplicate: "+name); + ("Copying document would result in duplicate: "+name); } - + ContentItem item = this; if (item.getParent() instanceof ContentBundle) { item = (ContentBundle) item.getParent(); @@ -258,22 +258,22 @@ public class DocLink extends ContentPage implements Resource, Searchable { if (s_log.isDebugEnabled()) { s_log.debug("Copying item " + item); } - + final ContentItem newItem = item.copy(); newItem.copyServicesFrom(item); newItem.setParent((Folder) parent); newItem.setContentSection(item.getContentSection()); newItem.save(); - + new KernelExcursion() { protected void excurse() { setParty(Kernel.getSystemParty()); PermissionService.setContext(newItem,(ACSObject) parent); }}.run(); - - return (Resource) ((ContentBundle) newItem).getPrimaryInstance(); + + return (Resource) ((ContentBundle) newItem).getPrimaryInstance(); } - + /** * Copies the resource into the same location (same parent) with passed * in name as new name. @@ -285,7 +285,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { final ACSObject parent = getParent(); return copyTo(name , (Resource) parent); } - + /** * @see com.arsdigita.cms.docmgr.Resource#toURL(). * Not Supported.throws UnsupportedOperationException @@ -293,7 +293,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { public URL toURL() { throw new UnsupportedOperationException(); } - + /** * @see com.arsdigita.cms.docmgr.Resource#setParentResource(com.arsdigita.cms.docmgr.Resource) */ @@ -301,16 +301,16 @@ public class DocLink extends ContentPage implements Resource, Searchable { final ContentBundle cb = (ContentBundle) getParent(); cb.setParent((ACSObject) parent); cb.save(); - + new KernelExcursion() { protected void excurse() { setParty(Kernel.getSystemParty()); PermissionService.setContext(cb, (ACSObject) parent); } } - .run(); + .run(); } - + /** * @see com.arsdigita.cms.docmgr.Resource#isRoot() * returns false to indicate that it's not the root. @@ -318,7 +318,7 @@ public class DocLink extends ContentPage implements Resource, Searchable { public boolean isRoot() { return false; } - + /** * Delete this Link along with it's parent ContentBundle * @see com.arsdigita.domain.DomainObject#delete() @@ -327,22 +327,22 @@ public class DocLink extends ContentPage implements Resource, Searchable { ((ContentBundle) getParent()).delete(); } - /** + /** * Over-ride to avoid any indexing of data for this ContentType. - * returns empty string; + * returns empty string; */ public String getSearchXMLContent() { return ""; } - - /** + + /** * Over-ride to avoid any indexing of data for this ContentType. - * returns empty byte array; + * returns empty byte array; */ public byte[] getSearchRawContent() { return new byte[0]; } - + public void setCategories(String[] catIDs) { HashSet newCategories = new HashSet(); if (catIDs != null) { @@ -351,12 +351,12 @@ public class DocLink extends ContentPage implements Resource, Searchable { s_log.debug("newCategories: "+catIDs[i]); } } - - CategoryCollection cats = getCategoryCollection(); - Category cat; - if (cats.next()) { - cat = cats.getCategory(); - String catID = cat.getID().toString(); + + CategoryCollection cats = getCategoryCollection(); + Category cat; + if (cats.next()) { + cat = cats.getCategory(); + String catID = cat.getID().toString(); if (newCategories.contains(catID)) { newCategories.remove(catID); } else { @@ -366,27 +366,27 @@ public class DocLink extends ContentPage implements Resource, Searchable { Iterator additions = newCategories.iterator(); while (additions.hasNext()) { addCategory(new Category(new BigDecimal - ((String) additions.next()))); + ((String) additions.next()))); } } - + protected void beforeSave() { - super.beforeSave(); - setLastModifiedLocal(new Date()); + super.beforeSave(); + setLastModifiedLocal(new Date()); } - + public String getSearchLanguage() { // Returns language type of document. "eng" is english, (ISO 639-2) // If not English, should be overridden. return "eng"; } - + public String getSearchLinkText() { return generateLinkName(getTarget()); } - + public String getSearchUrlStub() { - return ""; + return ""; } - + } diff --git a/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AtoZItemGenerator.java b/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AtoZItemGenerator.java index 4edd961cc..4a5fbd095 100755 --- a/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AtoZItemGenerator.java +++ b/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AtoZItemGenerator.java @@ -21,6 +21,7 @@ package com.arsdigita.london.atoz; import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentPage; +import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.persistence.DataQuery; import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.OID; @@ -58,7 +59,11 @@ public class AtoZItemGenerator extends AbstractAtoZGenerator { bundle = new ContentBundle(new BigDecimal(entries.get("id") .toString())); if (bundle != null) { - item = bundle.getPrimaryInstance(); + /* Fix by Quasimodo*/ + /* getPrimaryInstance doesn't negotiate the language of the content item */ + /* item = bundle.getPrimaryInstance(); */ + item = bundle.negotiate(DispatcherHelper.getRequest().getLocales()); + if (item != null) { // this is necessary because aliases refer to the non-live // version, diff --git a/ccm-ldn-rss/src/com/arsdigita/london/rss/RSSService.java b/ccm-ldn-rss/src/com/arsdigita/london/rss/RSSService.java index dd259f6c0..f7798a6d5 100755 --- a/ccm-ldn-rss/src/com/arsdigita/london/rss/RSSService.java +++ b/ccm-ldn-rss/src/com/arsdigita/london/rss/RSSService.java @@ -5,12 +5,12 @@ * 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 @@ -64,7 +64,7 @@ import com.arsdigita.kernel.User; */ public class RSSService { private static org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(RSSService.class); + org.apache.log4j.Logger.getLogger(RSSService.class); private static final RSSConfig s_config = new RSSConfig(); @@ -75,19 +75,19 @@ public class RSSService { public static RSSConfig getConfig() { return s_config; } - + /** * Generates an RSS channel for a specified category and and all of its Articles. */ public static void generateChannel( - BigDecimal categoryId, - HttpServletRequest request, - HttpServletResponse response) - throws Exception { + BigDecimal categoryId, + HttpServletRequest request, + HttpServletResponse response) + throws Exception { Category cat = new Category(categoryId); - + boolean useLAWs = "laws-1.0".equals(request.getParameter("extension")); - + boolean useESD = "laws-esd".equals(request.getParameter("extension")); if (useESD) { useLAWs = true; @@ -95,36 +95,36 @@ public class RSSService { // The two namespaces used for basic rdf. rssNS is the default namespace // for all elements. Namespace rdfNS = - Namespace.getNamespace( + Namespace.getNamespace( "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); - - // The following namespaces are declared for the possible + + // The following namespaces are declared for the possible // use of the LAWS extension Namespace dcNS = - Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/"); + Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/"); Namespace egmsNS = null; if (useESD) { egmsNS = - Namespace.getNamespace( + Namespace.getNamespace( "esd", "http://www.esd.org.uk/standards/esd/3.0/esd.rdfs"); } else { egmsNS = - Namespace.getNamespace( + Namespace.getNamespace( "egms", "http://www.esd.org.uk/standards/egms/3.0/egms.rdfs"); } Namespace lgclNS = - Namespace.getNamespace( + Namespace.getNamespace( "lgcl", "http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs"); - + // rdf is the root element Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); rdf.addNamespaceDeclaration(rssNS); - + if (useLAWs) { rdf.addNamespaceDeclaration(dcNS); rdf.addNamespaceDeclaration(egmsNS); @@ -133,50 +133,50 @@ public class RSSService { // Channel info Element channel = new Element("channel", rssNS); channel.setAttribute( - "about", - URL.here(request, "/rss/").getURL(), - rdfNS); + "about", + URL.here(request, "/rss/").getURL(), + rdfNS); rdf.addContent(channel); - + Element channelTitle = new Element("title", rssNS); channelTitle.setText(cat.getName()); channel.addContent(channelTitle); - + if (useLAWs) { Element channelDCTitle = new Element("title", dcNS); channelDCTitle.setText(cat.getName()); channel.addContent(channelDCTitle); } - + Element channelLink = new Element("link", rssNS); channelLink.setText((URL.there(request,null).getServerURI()).concat(URLService.locate(cat.getOID()))); channel.addContent(channelLink); - + Element channelDescription = new Element("description", rssNS); channelDescription.setText(cat.getDescription()); channel.addContent(channelDescription); - + Element channelItems = new Element("items", rssNS); channel.addContent(channelItems); - + Element itemsSeq = new Element("Seq", rdfNS); channelItems.addContent(itemsSeq); - + // Get and store a list of items. Items urls are added to the list in // the channel info, and a complete entry is added at the top level // (below rdf) SortedSet items = new TreeSet(); CategorizedCollection objects = - cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE); + cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE); while (objects.next()) { ContentItem item = (ContentItem) objects.getACSObject(); - + s_log.debug("item: " + item.getDisplayName()); if (ContentItem.LIVE.equals(item.getVersion())) { items.add(new NewestFirstItem(item)); } } - + Iterator iter = items.iterator(); int max = 10; int current = 0; @@ -187,7 +187,7 @@ public class RSSService { } NewestFirstItem itemWrapper = (NewestFirstItem) iter.next(); ContentItem item = itemWrapper.getContentItem(); - + String title; String description = ""; try { @@ -203,46 +203,46 @@ public class RSSService { } catch (ClassCastException e) { title = item.getDisplayName(); } - + String itemURL = (URL.there(request,null).getServerURI()).concat(URLService.locate(item.getOID())); - + s_log.debug("item is live"); - + // Add the element to the channel list Element seqEl = new Element("li", rdfNS); seqEl.setAttribute("resource", itemURL, rdfNS); itemsSeq.addContent(seqEl); - + // Add the element to the top level Element itemEl = new Element("item", rssNS); itemEl.setAttribute("about", itemURL, rdfNS); rdf.addContent(itemEl); - + Element titleEl = new Element("title", rssNS); titleEl.setText(title); itemEl.addContent(titleEl); - + Element linkEl = new Element("link", rssNS); linkEl.setText(itemURL); itemEl.addContent(linkEl); - + if (description != null) { Element descEl = new Element("description", rssNS); descEl.setText( - com.arsdigita.util.StringUtils.truncateString( + com.arsdigita.util.StringUtils.truncateString( description, 100, true) - + "..."); + + "..."); itemEl.addContent(descEl); } - + if (useLAWs) { - + Element dcTitleEl = new Element("title", dcNS); dcTitleEl.setText(title); itemEl.addContent(dcTitleEl); - + User creatorUser = item.getCreationUser(); String creator = "Not specified"; if (creatorUser != null) { @@ -251,105 +251,105 @@ public class RSSService { Element dcCreatorEl = new Element("creator", dcNS); dcCreatorEl.setText(creator); itemEl.addContent(dcCreatorEl); - + Date dcDate = item.getCreationDate(); String dcDateString = "Not specified"; if (dcDate != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dcDateString = sdf.format(dcDate); } - + Element dcDateEl = new Element("date", dcNS); dcDateEl.setText(dcDateString); itemEl.addContent(dcDateEl); - + Element subjectCategoryEl = - new Element("subjectCategory", egmsNS); + new Element("subjectCategory", egmsNS); itemEl.addContent(subjectCategoryEl); - + Element subjectBagEl = new Element("Bag", rdfNS); subjectCategoryEl.addContent(subjectBagEl); - + Element liEl; Element categoryEl; Element rdfValueEl; - - // OK now we are going to see if we can find any + + // OK now we are going to see if we can find any // LGCL categories for this item: - + Domain lgclDomain = Domain.retrieve("LGCL"); - + DomainCollection terms = lgclDomain.getTerms(); terms.addEqualsFilter("model.childObjects.id", item.getID()); - + if (terms != null) { DomainCollectionIterator it = - new DomainCollectionIterator(terms); - + new DomainCollectionIterator(terms); + while (it.hasNext()) { - + Term term = (Term) it.next(); String name = term.getName(); String urlName = toUpperCamel(name); - + liEl = new Element("li", rdfNS); subjectBagEl.addContent(liEl); - + categoryEl = new Element(urlName, lgclNS); liEl.addContent(categoryEl); - + rdfValueEl = new Element("value", rdfNS); rdfValueEl.setText(name); categoryEl.addContent(rdfValueEl); } } - + } } - + // Write XML to the output stream Document doc = new Document(); - + if (getConfig().getPIxslt()!= null) { doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\"")); } doc.setRootElement(rdf); - + response.setContentType("text/xml; charset=UTF-8"); - + XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); xmlOutput.setNewlines(true); xmlOutput.setIndent(true); xmlOutput.output(doc, response.getWriter()); } - + private static class NewestFirstItem implements Comparable { private ContentItem m_item; private BigDecimal m_liveID; - + public NewestFirstItem(ContentItem item) { m_item = item; - + m_liveID = item.getID(); } - + public ContentItem getContentItem() { return m_item; } - + public BigDecimal getLiveID() { return m_liveID; } - + public int compareTo(Object o) { if ((o instanceof NewestFirstItem)) { return - - 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID())); + - 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID())); } else { throw new ClassCastException("Must compare to NewestFirstItem"); } } - + public boolean equals(Object o) { if ((o instanceof NewestFirstItem)) { return m_item.equals(((NewestFirstItem) o).getContentItem()); @@ -358,54 +358,54 @@ public class RSSService { } } } - + /** * Generates an RSS channel for a specified category purpose */ public static void generateChannelList( - Category root, - HttpServletRequest request, - HttpServletResponse response) - throws Exception { - + Category root, + HttpServletRequest request, + HttpServletResponse response) + throws Exception { + // The two namespaces used for basic rdf. rssNS is the default namespace // for all elements. Namespace rdfNS = - Namespace.getNamespace( + Namespace.getNamespace( "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); - + // rdf is the root element Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); rdf.addNamespaceDeclaration(rssNS); - + // Channel info Element channel = new Element("channel", rssNS); channel.setAttribute( - "about", - URL.here(request, "/rss/").getURL(), - rdfNS); + "about", + URL.here(request, "/rss/").getURL(), + rdfNS); rdf.addContent(channel); - + Element channelTitle = new Element("title", rssNS); channelTitle.setText("Channel Index"); channel.addContent(channelTitle); - + Element channelLink = new Element("link", rssNS); channelLink.setText(URL.here(request, "/rss/").getURL()); channel.addContent(channelLink); - + Element channelDescription = new Element("description", rssNS); channelDescription.setText("The list of content feeds"); channel.addContent(channelDescription); - + Element channelItems = new Element("items", rssNS); channel.addContent(channelItems); - + Element itemsSeq = new Element("Seq", rdfNS); channelItems.addContent(itemsSeq); - + Map cats = Categorization.categorySubtreePath(root); s_log.debug("Get categories"); Iterator i = cats.keySet().iterator(); @@ -413,34 +413,34 @@ public class RSSService { while (i.hasNext()) { String path = (String) i.next(); Category cat = (Category) cats.get(path); - + if (cat.getID().equals(root.getID())) { continue; } - + s_log.debug("GOt sub cat " + path + " id " + cat.getID()); ParameterMap params = new ParameterMap(); params.setParameter("id", cat.getID()); URL url = URL.here(request, "/rss/channel.rss", params); - + // Add the element to the channel list Element seqEl = new Element("li", rdfNS); seqEl.setAttribute("resource", url.getURL(), rdfNS); itemsSeq.addContent(seqEl); - + // Add the element to the top level Element itemEl = new Element("item", rssNS); itemEl.setAttribute("about", url.getURL(), rdfNS); rdf.addContent(itemEl); - + Element titleEl = new Element("title", rssNS); titleEl.setText(path); itemEl.addContent(titleEl); - + Element linkEl = new Element("link", rssNS); linkEl.setText(url.getURL()); itemEl.addContent(linkEl); - + if (cat.getDescription() != null) { Element descEl = new Element("description", rssNS); descEl.setText(cat.getDescription()); @@ -448,128 +448,128 @@ public class RSSService { } } s_log.debug("All done"); - + // Write XML to the output stream Document doc = new Document(rdf); - + response.setContentType("text/xml; charset=UTF-8"); - + XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); xmlOutput.setNewlines(true); xmlOutput.setIndent(true); xmlOutput.output(doc, response.getWriter()); } - + /** * Generates an RSS channel for a specified category and and all of its Articles. */ public static void generateFeedList( - boolean acsj, - HttpServletRequest request, - HttpServletResponse response) - throws Exception { + boolean acsj, + HttpServletRequest request, + HttpServletResponse response) + throws Exception { // The two namespaces used for basic rdf. rssNS is the default namespace // for all elements. Namespace rdfNS = - Namespace.getNamespace( + Namespace.getNamespace( "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); - + // rdf is the root element Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); rdf.addNamespaceDeclaration(rssNS); - + // Channel info Element channel = new Element("channel", rssNS); channel.setAttribute( - "about", - URL.here(request, "/rss/").getURL(), - rdfNS); + "about", + URL.here(request, "/rss/").getURL(), + rdfNS); rdf.addContent(channel); - + Element channelTitle = new Element("title", rssNS); channelTitle.setText("Channel Index"); channel.addContent(channelTitle); - + Element channelLink = new Element("link", rssNS); channelLink.setText(URL.here(request, "/rss/").getURL()); channel.addContent(channelLink); - + Element channelDescription = new Element("description", rssNS); channelDescription.setText("The list of server feeds"); channel.addContent(channelDescription); - + Element channelItems = new Element("items", rssNS); channel.addContent(channelItems); - + Element itemsSeq = new Element("Seq", rdfNS); channelItems.addContent(itemsSeq); - + FeedCollection feeds = Feed.retrieveAll(); feeds.filterACSJFeeds(acsj); - + while (feeds.next()) { Feed feed = feeds.getFeed(); - + // Add the element to the channel list Element seqEl = new Element("li", rdfNS); seqEl.setAttribute("resource", feed.getURL(), rdfNS); itemsSeq.addContent(seqEl); - + // Add the element to the top level Element itemEl = new Element("item", rssNS); itemEl.setAttribute("about", feed.getURL(), rdfNS); rdf.addContent(itemEl); - + Element titleEl = new Element("title", rssNS); titleEl.setText(feed.getTitle()); itemEl.addContent(titleEl); - + Element linkEl = new Element("link", rssNS); linkEl.setText(feed.getURL()); itemEl.addContent(linkEl); - + String desc = feed.getDescription(); if (desc != null) { Element descEl = new Element("description", rssNS); descEl.setText(desc); itemEl.addContent(descEl); } - + } - + // Write XML to the output stream Document doc = new Document(rdf); - + response.setContentType("text/xml; charset=UTF-8"); - + XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); xmlOutput.setNewlines(true); xmlOutput.setIndent(true); xmlOutput.output(doc, response.getWriter()); } - + public static String toUpperCamel(String termName) { - + String upperCamel = ""; - + if (termName != null) { - + StringTokenizer tokens = new StringTokenizer(termName); while (tokens.hasMoreTokens()) { - + String word = tokens.nextToken(); if (word.length() <= 1) { upperCamel += word.toUpperCase(); } else { upperCamel += word.substring(0, 1).toUpperCase() - + word.substring(1, word.length()); + + word.substring(1, word.length()); } - + } } - + return upperCamel; } }