Überprüfung von allen Aufrufen von getPrimaryInstance() außer in Navigation abgeschlossen. Sollte jetzt, soweit ich das erkennen konnte, korrekt sein.

git-svn-id: https://svn.libreccm.org/ccm/trunk@269 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2009-09-29 07:00:18 +00:00
parent c559db1ad7
commit 36e5dd7b66
6 changed files with 1009 additions and 1005 deletions

View File

@ -57,29 +57,29 @@ import org.apache.log4j.Logger;
*/ */
public class ContentBundle extends ContentItem { public class ContentBundle extends ContentItem {
public static final String versionId = public static final String versionId =
"$Id: ContentBundle.java 967 2005-10-28 18:08:42Z sskracic $" + "$Id: ContentBundle.java 967 2005-10-28 18:08:42Z sskracic $" +
"$Author: sskracic $" + "$Author: sskracic $" +
"$DateTime: $"; "$DateTime: $";
private static final Logger s_log = Logger.getLogger(ContentBundle.class); private static final Logger s_log = Logger.getLogger(ContentBundle.class);
private static DomainObjectObserver s_instancesObserver = private static DomainObjectObserver s_instancesObserver =
new AbstractDomainObjectObserver() { new AbstractDomainObjectObserver() {
public void add(DomainObject dom, String name, public void add(DomainObject dom, String name,
DataObject dobj) { DataObject dobj) {
if (INSTANCES.equals(name)) { if (INSTANCES.equals(name)) {
if (dobj != null) { if (dobj != null) {
PermissionService.setContext(dobj.getOID(), dom.getOID()); PermissionService.setContext(dobj.getOID(), dom.getOID());
}
} }
} }
}; }
};
/** /**
* The base data object type of a bundle * The base data object type of a bundle
*/ */
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.ContentBundle"; "com.arsdigita.cms.ContentBundle";
/** /**
* The primary instances association * The primary instances association
@ -138,7 +138,7 @@ public class ContentBundle extends ContentItem {
* retrieve * retrieve
*/ */
public ContentBundle(final BigDecimal id) public ContentBundle(final BigDecimal id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
@ -168,7 +168,7 @@ public class ContentBundle extends ContentItem {
final ContentBundle newItem = (ContentBundle) super.makeCopy(); final ContentBundle newItem = (ContentBundle) super.makeCopy();
final WorkflowTemplate template = final WorkflowTemplate template =
ContentTypeWorkflowTemplate.getWorkflowTemplate ContentTypeWorkflowTemplate.getWorkflowTemplate
(newItem.getContentSection(), newItem.getContentType()); (newItem.getContentSection(), newItem.getContentType());
if (template != null) { if (template != null) {
@ -202,7 +202,7 @@ public class ContentBundle extends ContentItem {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(language, String.class); Assert.exists(language, String.class);
Assert.truth(language.length() == 2, Assert.truth(language.length() == 2,
language + " is not an ISO639 language code"); language + " is not an ISO639 language code");
} }
set(DEFAULT_LANGUAGE, language); set(DEFAULT_LANGUAGE, language);
@ -229,8 +229,8 @@ public class ContentBundle extends ContentItem {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(instance, ContentItem.class); Assert.exists(instance, ContentItem.class);
Assert.falsity(hasInstance(instance.getLanguage()), Assert.falsity(hasInstance(instance.getLanguage()),
"The bundle already contains an instance " + "The bundle already contains an instance " +
"for the language " + instance.getLanguage()); "for the language " + instance.getLanguage());
} }
instance.setParent(this); instance.setParent(this);
@ -306,8 +306,8 @@ public class ContentBundle extends ContentItem {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(language, String.class); Assert.exists(language, String.class);
Assert.truth(language.length() == 2, Assert.truth(language.length() == 2,
language + " does not look like a valid language " + language + " does not look like a valid language " +
"code"); "code");
} }
final DataAssociationCursor instances = instances(); final DataAssociationCursor instances = instances();
@ -362,7 +362,7 @@ public class ContentBundle extends ContentItem {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(language, String.class); Assert.exists(language, String.class);
Assert.truth(language.length() == 2, Assert.truth(language.length() == 2,
language + " is not an ISO639 language code"); language + " is not an ISO639 language code");
} }
final DataAssociationCursor instances = instances(); final DataAssociationCursor instances = instances();
@ -433,8 +433,8 @@ public class ContentBundle extends ContentItem {
matchingInstance = dataObject; matchingInstance = dataObject;
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("negotiate: " s_log.debug("negotiate: "
+ "bestMatch= " + i + "bestMatch= " + i
+ ", language= " + language); + ", language= " + language);
} }
} // else other match with less preferred language found } // else other match with less preferred language found
} }
@ -448,7 +448,7 @@ public class ContentBundle extends ContentItem {
instancesCursor.close(); instancesCursor.close();
if (matchingInstance != null) { if (matchingInstance != null) {
return (ContentItem) DomainObjectFactory.newInstance return (ContentItem) DomainObjectFactory.newInstance
(matchingInstance); (matchingInstance);
} else { } else {
s_log.info("negotiate: no match found!"); s_log.info("negotiate: no match found!");
return null; return null;
@ -503,8 +503,8 @@ public class ContentBundle extends ContentItem {
match = dataObject; match = dataObject;
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("negotiate: " s_log.debug("negotiate: "
+ "bestMatch= " + i + "bestMatch= " + i
+ ", language= " + language); + ", language= " + language);
} }
} // else other match with less preferred language found } // else other match with less preferred language found
} }
@ -545,7 +545,7 @@ public class ContentBundle extends ContentItem {
} }
public ContentItem publish(final LifecycleDefinition definition, public ContentItem publish(final LifecycleDefinition definition,
final Date start) { final Date start) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -575,14 +575,14 @@ public class ContentBundle extends ContentItem {
* to copy the property. * to copy the property.
*/ */
public boolean copyProperty(final CustomCopy source, public boolean copyProperty(final CustomCopy source,
final Property property, final Property property,
final ItemCopier copier) { final ItemCopier copier) {
if (copier.getCopyType() == ItemCopier.VERSION_COPY) { if (copier.getCopyType() == ItemCopier.VERSION_COPY) {
if (INSTANCES.equals(property.getName())) { if (INSTANCES.equals(property.getName())) {
return true; return true;
} else if (ATOZ_ALIASING_PROVIDERS.equals(property.getName())) { } else if (ATOZ_ALIASING_PROVIDERS.equals(property.getName())) {
return true; return true;
} }
} }
return super.copyProperty(source, property, copier); return super.copyProperty(source, property, copier);
@ -591,7 +591,7 @@ public class ContentBundle extends ContentItem {
public boolean copyServices(final ContentItem source) { public boolean copyServices(final ContentItem source) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Copying services on bundle " + getName() + " " + s_log.debug("Copying services on bundle " + getName() + " " +
getID() + " using source " + source.getID()); getID() + " using source " + source.getID());
} }
// Copy categories // Copy categories
@ -625,7 +625,7 @@ public class ContentBundle extends ContentItem {
private DataAssociationCursor instances() { private DataAssociationCursor instances() {
final DataAssociationCursor cursor = final DataAssociationCursor cursor =
((DataAssociation) super.get(INSTANCES)).cursor(); ((DataAssociation) super.get(INSTANCES)).cursor();
return cursor; return cursor;
} }

View File

@ -52,12 +52,12 @@ import java.util.StringTokenizer;
*/ */
public class MultilingualItemResolver extends AbstractItemResolver implements ItemResolver { public class MultilingualItemResolver extends AbstractItemResolver implements ItemResolver {
public static final String versionId = public static final String versionId =
"$Id: MultilingualItemResolver.java 1795 2009-02-07 10:47:32Z pboy $" + "$Id: MultilingualItemResolver.java 1795 2009-02-07 10:47:32Z pboy $" +
"$Author: pboy $" + "$Author: pboy $" +
"$DateTime: 2004/08/17 23:15:09 $"; "$DateTime: 2004/08/17 23:15:09 $";
private static final Logger s_log = Logger.getLogger private static final Logger s_log = Logger.getLogger
(MultilingualItemResolver.class); (MultilingualItemResolver.class);
private static MasterPage s_masterP = null; private static MasterPage s_masterP = null;
private static final String ADMIN_PREFIX = "admin"; private static final String ADMIN_PREFIX = "admin";
@ -74,7 +74,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
*/ */
protected static final String SEPARATOR = "&"; protected static final String SEPARATOR = "&";
public MultilingualItemResolver () { public MultilingualItemResolver() {
s_log.debug("Undergoing creation"); s_log.debug("Undergoing creation");
} }
@ -90,124 +90,124 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* #getCurrentContext}. * #getCurrentContext}.
* @return The content item, or null if no such item exists * @return The content item, or null if no such item exists
*/ */
public ContentItem getItem(final ContentSection section, public ContentItem getItem(final ContentSection section,
String url, String url,
final String context) { final String context) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolving the item in content section " + section + s_log.debug("Resolving the item in content section " + section +
" at URL '" + url + "' for context " + context); " at URL '" + url + "' for context " + context);
} }
Assert.exists(section, "ContentSection section"); Assert.exists(section, "ContentSection section");
Assert.exists(url, "String url"); Assert.exists(url, "String url");
Assert.exists(context, "String context"); Assert.exists(context, "String context");
Folder rootFolder = section.getRootFolder(); Folder rootFolder = section.getRootFolder();
url = stripTemplateFromURL(url); url = stripTemplateFromURL(url);
// nothing to do, if root folder is null // nothing to do, if root folder is null
if (rootFolder == null) { if (rootFolder == null) {
s_log.debug("The root folder is null; returning no item"); s_log.debug("The root folder is null; returning no item");
} else { } else {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Using root folder " + rootFolder); s_log.debug("Using root folder " + rootFolder);
} }
if (ContentItem.LIVE.equals(context)) { if (ContentItem.LIVE.equals(context)) {
s_log.debug("The use context is 'live'"); s_log.debug("The use context is 'live'");
// We allow for returning null, so the root folder may // We allow for returning null, so the root folder may
// not be live. // not be live.
//Assert.assertTrue(rootFolder.isLive(), //Assert.assertTrue(rootFolder.isLive(),
// "live context - root folder of secion must be live"); // "live context - root folder of secion must be live");
// If the context is 'live', we need the live item. // If the context is 'live', we need the live item.
rootFolder = (Folder) rootFolder.getLiveVersion(); rootFolder = (Folder) rootFolder.getLiveVersion();
if (rootFolder == null) { if (rootFolder == null) {
s_log.debug("The live version of the root folder is " + s_log.debug("The live version of the root folder is " +
"null; returning no item"); "null; returning no item");
} else { } else {
s_log.debug("The root folder has a live version; " + s_log.debug("The root folder has a live version; " +
"recursing"); "recursing");
final String prefix = final String prefix =
section.getURL() + rootFolder.getPath(); section.getURL() + rootFolder.getPath();
if (url.startsWith(prefix)) { if (url.startsWith(prefix)) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The URL starts with prefix '" + s_log.debug("The URL starts with prefix '" +
prefix + "'; removing it"); prefix + "'; removing it");
} }
url = url.substring(prefix.length()); url = url.substring(prefix.length());
} }
final ContentItem item = getItemFromLiveURL(url, rootFolder); final ContentItem item = getItemFromLiveURL(url, rootFolder);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolved URL '" + url + "' to item " + s_log.debug("Resolved URL '" + url + "' to item " +
item); item);
} }
return item; return item;
} }
} else if (ContentItem.DRAFT.equals(context)) { } else if (ContentItem.DRAFT.equals(context)) {
s_log.debug("The use context is 'draft'"); s_log.debug("The use context is 'draft'");
// For 'draft' items, 'generateUrl()' method returns // For 'draft' items, 'generateUrl()' method returns
// URL like this // URL like this
// '/acs/wcms/admin/item.jsp?item_id=10201&set_tab=1' // '/acs/wcms/admin/item.jsp?item_id=10201&set_tab=1'
// Check if URL contains any match of string // Check if URL contains any match of string
// 'item_id', then try to instanciate item_id value // 'item_id', then try to instanciate item_id value
// and return FIXME: Please hack this if there is // and return FIXME: Please hack this if there is
// more graceful solution. [aavetyan] // more graceful solution. [aavetyan]
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.isTrue Assert.isTrue
(url.indexOf(ITEM_ID) >= 0, (url.indexOf(ITEM_ID) >= 0,
"url must contain parameter " + ITEM_ID); "url must contain parameter " + ITEM_ID);
} }
final ContentItem item = getItemFromDraftURL(url); final ContentItem item = getItemFromDraftURL(url);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolved URL '" + url + "' to item " + item); s_log.debug("Resolved URL '" + url + "' to item " + item);
} }
return item; return item;
} else if (CMSDispatcher.PREVIEW.equals(context)) { } else if (CMSDispatcher.PREVIEW.equals(context)) {
s_log.debug("The use context is 'preview'"); s_log.debug("The use context is 'preview'");
final String prefix = CMSDispatcher.PREVIEW + "/"; final String prefix = CMSDispatcher.PREVIEW + "/";
if (url.startsWith(prefix)) { if (url.startsWith(prefix)) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The URL starts with prefix '" + s_log.debug("The URL starts with prefix '" +
prefix + "'; removing it"); prefix + "'; removing it");
} }
url = url.substring(prefix.length()); url = url.substring(prefix.length());
} }
final ContentItem item = getItemFromLiveURL(url, rootFolder); final ContentItem item = getItemFromLiveURL(url, rootFolder);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolved URL '" + url + "' to item " + item); s_log.debug("Resolved URL '" + url + "' to item " + item);
} }
return item; return item;
} else { } else {
throw new IllegalArgumentException throw new IllegalArgumentException
("Invalid item resolver context " + context); ("Invalid item resolver context " + context);
} }
} }
s_log.debug("No item resolved; returning null"); s_log.debug("No item resolved; returning null");
return null; return null;
} }
/** /**
* Fetches the current context based on the page state. * Fetches the current context based on the page state.
@ -225,7 +225,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
String url = state.getRequest().getRequestURI(); String url = state.getRequest().getRequestURI();
final ContentSection section = final ContentSection section =
CMS.getContext().getContentSection(); CMS.getContext().getContentSection();
// If this page is associated with a content section, // If this page is associated with a content section,
// transform the URL so that it is relative to the content // transform the URL so that it is relative to the content
@ -267,10 +267,10 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @see #getCurrentContext * @see #getCurrentContext
*/ */
public String generateItemURL(final PageState state, public String generateItemURL(final PageState state,
final BigDecimal itemId, final BigDecimal itemId,
final String name, final String name,
final ContentSection section, final ContentSection section,
final String context) { final String context) {
return generateItemURL(state, itemId, name, section, context, null); return generateItemURL(state, itemId, name, section, context, null);
} }
@ -289,15 +289,15 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @see #getCurrentContext * @see #getCurrentContext
*/ */
public String generateItemURL(final PageState state, public String generateItemURL(final PageState state,
final BigDecimal itemId, final BigDecimal itemId,
final String name, final String name,
final ContentSection section, final ContentSection section,
final String context, final String context,
final String templateContext) { final String templateContext) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Generating an item URL for item id " + itemId + s_log.debug("Generating an item URL for item id " + itemId +
", section " + section + ", and context '" + ", section " + section + ", and context '" +
context + "' with name '" + name + "'"); context + "' with name '" + name + "'");
} }
Assert.exists(itemId, "BigDecimal itemId"); Assert.exists(itemId, "BigDecimal itemId");
@ -317,14 +317,14 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(item, "item"); Assert.exists(item, "item");
Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()), Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()),
"Generating " + ContentItem.LIVE + " " + "Generating " + ContentItem.LIVE + " " +
"URL; this item must be the live version"); "URL; this item must be the live version");
} }
return generateLiveURL(section, item, templateContext); return generateLiveURL(section, item, templateContext);
} else { } else {
throw new IllegalArgumentException throw new IllegalArgumentException
("Unknown context '" + context + "'"); ("Unknown context '" + context + "'");
} }
} }
@ -340,9 +340,9 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @see #getCurrentContext * @see #getCurrentContext
*/ */
public String generateItemURL(final PageState state, public String generateItemURL(final PageState state,
final ContentItem item, final ContentItem item,
final ContentSection section, final ContentSection section,
final String context) { final String context) {
return generateItemURL(state, item, section, context, null); return generateItemURL(state, item, section, context, null);
} }
@ -360,14 +360,14 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @see #getCurrentContext * @see #getCurrentContext
*/ */
public String generateItemURL(final PageState state, public String generateItemURL(final PageState state,
final ContentItem item, final ContentItem item,
ContentSection section, ContentSection section,
final String context, final String context,
final String templateContext) { final String templateContext) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Generating an item URL for item " + item + s_log.debug("Generating an item URL for item " + item +
", section " + section + ", and context " + ", section " + section + ", and context " +
context); context);
} }
Assert.exists(item, "ContentItem item"); Assert.exists(item, "ContentItem item");
@ -380,8 +380,8 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (ContentItem.DRAFT.equals(context)) { if (ContentItem.DRAFT.equals(context)) {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.isTrue(ContentItem.DRAFT.equals(item.getVersion()), Assert.isTrue(ContentItem.DRAFT.equals(item.getVersion()),
"Generating " + ContentItem.DRAFT + "Generating " + ContentItem.DRAFT +
" url: item must be draft version"); " url: item must be draft version");
} }
return generateDraftURL(section, item.getID()); return generateDraftURL(section, item.getID());
@ -390,8 +390,8 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
} else if (ContentItem.LIVE.equals(context)) { } else if (ContentItem.LIVE.equals(context)) {
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()), Assert.isTrue(ContentItem.LIVE.equals(item.getVersion()),
"Generating " + ContentItem.LIVE + "Generating " + ContentItem.LIVE +
" url: item must be live version"); " url: item must be live version");
} }
return generateLiveURL(section, item, templateContext); return generateLiveURL(section, item, templateContext);
@ -408,25 +408,25 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @param request The HTTP request * @param request The HTTP request
* @return The master page * @return The master page
*/ */
public CMSPage getMasterPage(final ContentItem item, public CMSPage getMasterPage(final ContentItem item,
final HttpServletRequest request) final HttpServletRequest request)
throws ServletException { throws ServletException {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Getting the master page for item " + item); s_log.debug("Getting the master page for item " + item);
} }
// taken from SimpleItemResolver // taken from SimpleItemResolver
if (s_masterP == null) { if (s_masterP == null) {
s_masterP = new MasterPage(); s_masterP = new MasterPage();
s_masterP.init(); s_masterP.init();
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Returning master page " + s_masterP); s_log.debug("Returning master page " + s_masterP);
} }
return s_masterP; return s_masterP;
} }
/** /**
* Returns content item's draft version URL * Returns content item's draft version URL
@ -436,20 +436,20 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @return generated URL string * @return generated URL string
*/ */
protected String generateDraftURL(final ContentSection section, protected String generateDraftURL(final ContentSection section,
final BigDecimal itemId) { final BigDecimal itemId) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Generating draft URL for item ID " + itemId + s_log.debug("Generating draft URL for item ID " + itemId +
" and section " + section); " and section " + section);
} }
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.isTrue(section != null && itemId != null, Assert.isTrue(section != null && itemId != null,
"get draft url: neither secion nor item " + "get draft url: neither secion nor item " +
"can be null"); "can be null");
} }
final String url = ContentItemPage.getItemURL final String url = ContentItemPage.getItemURL
(section.getPath() + "/", itemId, ContentItemPage.AUTHORING_TAB); (section.getPath() + "/", itemId, ContentItemPage.AUTHORING_TAB);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Generated draft URL " + url); s_log.debug("Generated draft URL " + url);
@ -476,11 +476,11 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* be presented within the given <code>templateContext</code> * be presented within the given <code>templateContext</code>
*/ */
protected String generateLiveURL(final ContentSection section, protected String generateLiveURL(final ContentSection section,
final ContentItem item, final ContentItem item,
final String templateContext) { final String templateContext) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Generating live URL for item " + item + " in " + s_log.debug("Generating live URL for item " + item + " in " +
"section " + section); "section " + section);
} }
/* /*
@ -495,7 +495,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* add template context, if one is given * add template context, if one is given
*/ */
// This is breaking URL's...not sure why it's here. XXX // 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)) { if (!(templateContext == null || templateContext.length() == 0)) {
url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/"); url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/");
} }
@ -518,7 +518,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Appending the bundle's file name '" + s_log.debug("Appending the bundle's file name '" +
fname + "'"); fname + "'");
} }
url.append(fname); url.append(fname);
@ -533,10 +533,10 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (language == null) { if (language == null) {
s_log.debug("The item has no language; omitting the " + s_log.debug("The item has no language; omitting the " +
"language encoding"); "language encoding");
} else { } else {
s_log.debug("Encoding the language of the item passed in, '" + s_log.debug("Encoding the language of the item passed in, '" +
language + "'"); language + "'");
url.append("." + language); url.append("." + language);
} }
@ -567,8 +567,8 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* <code>item</code> * <code>item</code>
*/ */
protected String generatePreviewURL(ContentSection section, protected String generatePreviewURL(ContentSection section,
ContentItem item, ContentItem item,
String templateContext) { String templateContext) {
Assert.exists(section, "ContentSection section"); Assert.exists(section, "ContentSection section");
Assert.exists(item, "ContentItem item"); Assert.exists(item, "ContentItem item");
@ -581,7 +581,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* add template context, if one is given * add template context, if one is given
*/ */
// This is breaking URL's...not sure why it's here. XXX // 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)) { if (!(templateContext == null || templateContext.length() == 0)) {
url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/"); url.append(TEMPLATE_CONTEXT_PREFIX + templateContext + "/");
} }
@ -610,10 +610,10 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (language == null) { if (language == null) {
s_log.debug("The item has no language; omitting the " + s_log.debug("The item has no language; omitting the " +
"language encoding"); "language encoding");
} else { } else {
s_log.debug("Encoding the language of the item passed in, '" + s_log.debug("Encoding the language of the item passed in, '" +
language + "'"); language + "'");
url.append("." + language); url.append("." + language);
} }
@ -646,7 +646,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
// parameter; below we return null. // parameter; below we return null.
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.isTrue(pos >= 0, 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=.... ? String item_id = url.substring(pos); // item_id == ITEM_ID=.... ?
@ -673,7 +673,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, new BigDecimal(item_id)); OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, new BigDecimal(item_id));
final ContentItem item = (ContentItem) DomainObjectFactory.newInstance final ContentItem item = (ContentItem) DomainObjectFactory.newInstance
(oid); (oid);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Returning item " + item); s_log.debug("Returning item " + item);
@ -692,17 +692,17 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* or Folder objects, depending on URL and file language extension * or Folder objects, depending on URL and file language extension
*/ */
protected ContentItem getItemFromLiveURL(String url, protected ContentItem getItemFromLiveURL(String url,
Folder parentFolder) { Folder parentFolder) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Resolving the item for live URL " + url + 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 (parentFolder == null || url == null || url.equals("")) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The url is null or parent folder was null " + s_log.debug("The url is null or parent folder was null " +
"or something else is wrong, so just return " + "or something else is wrong, so just return " +
"the parent folder"); "the parent folder");
} }
return parentFolder; return parentFolder;
@ -713,7 +713,7 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
if (index >= 0) { if (index >= 0) {
s_log.debug("The URL starts with a slash; paring off the first " + 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 // If we got first slash (index == 0), ignore it and go
// on, sample '/foo/bar/item.html.en', in next recursion // on, sample '/foo/bar/item.html.en', in next recursion
@ -721,23 +721,23 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
String name = index > 0 ? url.substring(0, index) : ""; String name = index > 0 ? url.substring(0, index) : "";
parentFolder = parentFolder =
// really object identity? Don't think so // really object identity? Don't think so
// name != "" ? (Folder) parentFolder.getItem(URLEncoder.encode(name), true) // name != "" ? (Folder) parentFolder.getItem(URLEncoder.encode(name), true)
// : parentFolder; // : parentFolder;
name.isEmpty() ? parentFolder name.isEmpty() ? parentFolder
: (Folder) parentFolder.getItem(URLEncoder.encode(name), true); : (Folder) parentFolder.getItem(URLEncoder.encode(name), true);
url = index + 1 < len ? url.substring(index + 1) : ""; url = index + 1 < len ? url.substring(index + 1) : "";
return getItemFromLiveURL(url, parentFolder); return getItemFromLiveURL(url, parentFolder);
} else { } else {
s_log.debug("Found a file element in the URL"); s_log.debug("Found a file element in the URL");
String[] nameAndLang = getNameAndLangFromURLFrag(url); String[] nameAndLang = getNameAndLangFromURLFrag(url);
String name = nameAndLang[0]; String name = nameAndLang[0];
String lang = nameAndLang[1]; String lang = nameAndLang[1];
ContentItem item = parentFolder.getItem(URLEncoder.encode(name), false); ContentItem item = parentFolder.getItem(URLEncoder.encode(name), false);
return getItemFromLangAndBundle(lang, item); return getItemFromLangAndBundle(lang, item);
} }
} }
@ -750,107 +750,107 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* the lang string * the lang string
*/ */
protected String[] getNameAndLangFromURLFrag(String url) { protected String[] getNameAndLangFromURLFrag(String url) {
String name = null; String name = null;
String lang = null; String lang = null;
/* /*
* Try to find out if there's an extension with the language code * 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 * 1 Get a list of all "extensions", i.e. parts of the url
* which are separated by colons * which are separated by colons
* 2 If one or more extensions have been found, compare them against * 2 If one or more extensions have been found, compare them against
* the list of known language codes * the list of known language codes
* 2a if a match is found, this language is used to retrieve an instance * 2a if a match is found, this language is used to retrieve an instance
* from a bundle * from a bundle
* 2b if no match is found * 2b if no match is found
*/ */
final ArrayList exts = new ArrayList(5); final ArrayList exts = new ArrayList(5);
final StringTokenizer tok = new StringTokenizer(url, "."); final StringTokenizer tok = new StringTokenizer(url, ".");
while (tok.hasMoreTokens()) { while (tok.hasMoreTokens()) {
exts.add(tok.nextToken()); exts.add(tok.nextToken());
} }
if (exts.size() > 0) { if (exts.size() > 0) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Found some file extensions to look at; they " + s_log.debug("Found some file extensions to look at; they " +
"are " + exts); "are " + exts);
} }
/* /*
* We have found at least one extension, so we can * We have found at least one extension, so we can
* proceed. Now try to find out if one of the * proceed. Now try to find out if one of the
* extensions looks like a language code (we only * extensions looks like a language code (we only
* support 2-letter language codes!). * support 2-letter language codes!).
* If so, use this as the language to look for. * If so, use this as the language to look for.
*/ */
/* /*
* First element is the NAME of the item, not an extension! * First element is the NAME of the item, not an extension!
*/ */
name = (String) exts.get(0); name = (String) exts.get(0);
String ext = null; String ext = null;
Collection supportedLangs = Collection supportedLangs =
LanguageUtil.getSupportedLanguages2LA(); LanguageUtil.getSupportedLanguages2LA();
Iterator supportedLangIt = null; Iterator supportedLangIt = null;
for (int i = 1; i < exts.size(); i++) { for (int i = 1; i < exts.size(); i++) {
ext = (String) exts.get(i); ext = (String) exts.get(i);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Examining extension " + ext); s_log.debug("Examining extension " + ext);
} }
/* /*
* Loop through all extensions, but discard the * Loop through all extensions, but discard the
* first one, which is the name of the item. * first one, which is the name of the item.
*/ */
if (ext != null && ext.length() == 2) { if (ext != null && ext.length() == 2) {
/* Only check extensions consisting of 2 /* Only check extensions consisting of 2
* characters. * characters.
* *
* Compare current extension with known * Compare current extension with known
* languages; if it matches, we've found the * languages; if it matches, we've found the
* language we should use! * language we should use!
*/ */
supportedLangIt = supportedLangs.iterator(); supportedLangIt = supportedLangs.iterator();
while (supportedLangIt.hasNext()) { while (supportedLangIt.hasNext()) {
if (ext.equals(supportedLangIt.next())) { if (ext.equals(supportedLangIt.next())) {
lang = ext; lang = ext;
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Found a match; using " + s_log.debug("Found a match; using " +
"language " + lang); "language " + lang);
} }
break; break;
} }
} }
} else { } else {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Discarding extension " + ext + "; " + s_log.debug("Discarding extension " + ext + "; " +
"it is too short"); "it is too short");
} }
} }
} }
} else { } else {
s_log.debug("The file has no extensions; no language was " + s_log.debug("The file has no extensions; no language was " +
"encoded"); "encoded");
name = url; // no extension, so we just have a name here name = url; // no extension, so we just have a name here
lang = null; // no extension, so we cannot guess the language lang = null; // no extension, so we cannot guess the language
} }
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.exists(name, "String name"); Assert.exists(name, "String name");
Assert.exists(lang == null || lang.length() == 2); Assert.exists(lang == null || lang.length() == 2);
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("File name resolved to " + name); s_log.debug("File name resolved to " + name);
s_log.debug("File language resolved to " + lang); s_log.debug("File language resolved to " + lang);
} }
String[] returnArray = new String[2]; String[] returnArray = new String[2];
returnArray[0] = name; returnArray[0] = name;
returnArray[1] = lang; returnArray[1] = lang;
return returnArray; return returnArray;
} }
@ -864,74 +864,73 @@ public class MultilingualItemResolver extends AbstractItemResolver implements It
* @return The negotiated lang instance for the current request. * @return The negotiated lang instance for the current request.
*/ */
protected ContentItem getItemFromLangAndBundle(String lang, ContentItem item) { protected ContentItem getItemFromLangAndBundle(String lang, ContentItem item) {
if (item != null && item instanceof ContentBundle) { if (item != null && item instanceof ContentBundle) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Found content bundle " + item); s_log.debug("Found content bundle " + item);
} }
if (lang == null) { if (lang == null) {
s_log.debug("The URL has no language encoded in it; " + s_log.debug("The URL has no language encoded in it; " +
"negotiating the language"); "negotiating the language");
/* /*
* Either there were no extensions at all, or * Either there were no extensions at all, or
* neither one of them matched one of the * neither one of them matched one of the
* supported languages. So the ContentBundle has * supported languages. So the ContentBundle has
* to decide which language it will show; this * to decide which language it will show; this
* decision is based on the preferred languages as * decision is based on the preferred languages as
* defined in the client's request. * defined in the client's request.
*/ */
// TODO: do something about this UCI (Unknown Content Item)... // TODO: do something about this UCI (Unknown Content Item)...
// XXX sketchy getRequest // XXX sketchy getRequest
HttpServletRequest req = Web.getRequest(); HttpServletRequest req = Web.getRequest();
final ContentItem resolved; final ContentItem resolved;
if (req != null) { if (req != null) {
resolved = ((ContentBundle) item) resolved = ((ContentBundle) item).negotiate(req.getLocales());
.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 { } else {
// fallback to the primary instance when request is not available if (s_log.isDebugEnabled()) {
resolved = ((ContentBundle) item).getPrimaryInstance(); 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
}
} }
} }

View File

@ -80,22 +80,22 @@ import javax.servlet.ServletException;
*/ */
public class FolderBrowser extends Table { public class FolderBrowser extends Table {
public static final String versionId = public static final String versionId =
"$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" + "$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" +
"$Author: apevec $" + "$Author: apevec $" +
"$DateTime: 2004/08/17 23:15:09 $"; "$DateTime: 2004/08/17 23:15:09 $";
private static final Logger s_log = Logger.getLogger(FolderBrowser.class); private static final Logger s_log = Logger.getLogger(FolderBrowser.class);
private static GlobalizedMessage[] s_headers = { private static GlobalizedMessage[] s_headers = {
globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"), 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.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") }; globalize("cms.ui.folder.index") };
private static GlobalizedMessage[] s_noIndexHeaders = { private static GlobalizedMessage[] s_noIndexHeaders = {
globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"), 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.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_UP = "sortActionUp";
private static final String SORT_ACTION_DOWN = "sortActionDown"; private static final String SORT_ACTION_DOWN = "sortActionDown";
@ -123,12 +123,12 @@ public class FolderBrowser extends Table {
public FolderBrowser(FolderSelectionModel currentFolder) { public FolderBrowser(FolderSelectionModel currentFolder) {
//super(new FolderTableModelBuilder(), s_headers); //super(new FolderTableModelBuilder(), s_headers);
super(); super();
m_sortType.setDefaultValue(SORT_KEY_NAME); m_sortType.setDefaultValue(SORT_KEY_NAME);
m_sortDirection.setDefaultValue(SORT_ACTION_UP); m_sortDirection.setDefaultValue(SORT_ACTION_UP);
setModelBuilder(new FolderTableModelBuilder(currentFolder)); setModelBuilder(new FolderTableModelBuilder(currentFolder));
setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers)); setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers));
setHeader(new TableHeader(getColumnModel())); setHeader(new TableHeader(getColumnModel()));
// DEE 1/18/02: the folder table model builder needs to know about // DEE 1/18/02: the folder table model builder needs to know about
// 'this' in order to set visibility, but 'this' isn't available // 'this' in order to set visibility, but 'this' isn't available
// until after the super class' constructor has run, so we can't // until after the super class' constructor has run, so we can't
@ -153,13 +153,13 @@ public class FolderBrowser extends Table {
m_currentFolder.addChangeListener(new ChangeListener() { m_currentFolder.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
state.setValue(m_sortType, m_sortType.getDefaultValue()); state.setValue(m_sortType, m_sortType.getDefaultValue());
state.setValue(m_sortDirection, m_sortDirection.getDefaultValue()); state.setValue(m_sortDirection, m_sortDirection.getDefaultValue());
}}); }});
*/ */
setClassAttr("dataTable"); setClassAttr("dataTable");
getHeader().setDefaultRenderer(new com.arsdigita.cms.ui.util.DefaultTableCellRenderer()); getHeader().setDefaultRenderer(new com.arsdigita.cms.ui.util.DefaultTableCellRenderer());
@ -200,14 +200,14 @@ public class FolderBrowser extends Table {
p.addComponentStateParam(this, m_sortType); p.addComponentStateParam(this, m_sortType);
p.addComponentStateParam(this, m_sortDirection); p.addComponentStateParam(this, m_sortDirection);
p.addActionListener(new ActionListener() { p.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
if (state.isVisibleOnPage(FolderBrowser.this)) { if (state.isVisibleOnPage(FolderBrowser.this)) {
showHideFolderActions(state); showHideFolderActions(state);
}
} }
}); }
});
} }
private void showHideFolderActions(PageState state) { private void showHideFolderActions(PageState state) {
@ -216,7 +216,7 @@ public class FolderBrowser extends Table {
Assert.assertNotNull(folder); Assert.assertNotNull(folder);
boolean canDelete = boolean canDelete =
sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder); sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder);
m_deleteColumn.setVisible(state, canDelete); m_deleteColumn.setVisible(state, canDelete);
} }
@ -228,7 +228,7 @@ public class FolderBrowser extends Table {
state.setValue(m_sortType, value); state.setValue(m_sortType, value);
state.setValue(m_sortDirection, SORT_ACTION_UP); state.setValue(m_sortDirection, SORT_ACTION_UP);
} else if ( SORT_ACTION_DOWN.equals(key) ) { } else if ( SORT_ACTION_DOWN.equals(key) ) {
state.setValue(m_sortType, value); state.setValue(m_sortType, value);
state.setValue(m_sortDirection, SORT_ACTION_DOWN); state.setValue(m_sortDirection, SORT_ACTION_DOWN);
} else { } else {
super.respond(state); super.respond(state);
@ -241,7 +241,7 @@ public class FolderBrowser extends Table {
} }
private class FolderTableModelBuilder private class FolderTableModelBuilder
extends AbstractTableModelBuilder implements PaginationModelBuilder { extends AbstractTableModelBuilder implements PaginationModelBuilder {
private FolderSelectionModel m_folder; private FolderSelectionModel m_folder;
private RequestLocal m_size; private RequestLocal m_size;
@ -268,7 +268,7 @@ public class FolderBrowser extends Table {
} else { } else {
t.getRowSelectionModel().clearSelection(s); t.getRowSelectionModel().clearSelection(s);
return new FolderTableModel return new FolderTableModel
((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s)); ((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s));
} }
} }
@ -287,16 +287,16 @@ public class FolderBrowser extends Table {
} }
PermissionService.filterQuery( PermissionService.filterQuery(
itemColl, itemColl,
"id", "id",
PrivilegeDescriptor.READ, PrivilegeDescriptor.READ,
Kernel.getContext().getParty().getOID() Kernel.getContext().getParty().getOID()
); );
size = new Integer( (int) f.getPrimaryInstances().size()); size = new Integer( (int) f.getPrimaryInstances().size());
itemColl.setRange(new Integer(paginator.getFirst(state)), 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 sortKey = (String)state.getValue(m_sortType);
String direction = "asc"; String direction = "asc";
@ -306,17 +306,17 @@ public class FolderBrowser extends Table {
if ( sortKey.equals(SORT_KEY_TITLE) ) { if ( sortKey.equals(SORT_KEY_TITLE) ) {
itemColl.setOrder("lower(item." + itemColl.setOrder("lower(item." +
ContentItem.DISPLAY_NAME + ") " + ContentItem.DISPLAY_NAME + ") " +
direction); direction);
} else if ( sortKey.equals(SORT_KEY_NAME) ) { } else if ( sortKey.equals(SORT_KEY_NAME) ) {
itemColl.setOrder("lower(item." + itemColl.setOrder("lower(item." +
ContentItem.NAME + ") " + direction); ContentItem.NAME + ") " + direction);
} else if ( sortKey.equals(SORT_KEY_LAST_MODIFIED_DATE)) { } else if ( sortKey.equals(SORT_KEY_LAST_MODIFIED_DATE)) {
itemColl.setOrder("item.auditing.lastModifiedDate " + itemColl.setOrder("item.auditing.lastModifiedDate " +
direction); direction);
} else if ( sortKey.equals(SORT_KEY_CREATION_DATE)) { } else if ( sortKey.equals(SORT_KEY_CREATION_DATE)) {
itemColl.setOrder("item.auditing.creationDate " + itemColl.setOrder("item.auditing.creationDate " +
direction); direction);
} }
m_size.set(state, size); m_size.set(state, size);
@ -344,7 +344,7 @@ public class FolderBrowser extends Table {
private class HeaderCellRenderer private class HeaderCellRenderer
extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer { extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer {
private String m_key; private String m_key;
@ -354,9 +354,9 @@ public class FolderBrowser extends Table {
} }
public Component getComponent(final Table table, final PageState state, public Component getComponent(final Table table, final PageState state,
Object value, Object value,
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
String headerName = (String)((GlobalizedMessage)value).localize(); String headerName = (String)((GlobalizedMessage)value).localize();
String sortKey = (String)state.getValue(m_sortType); String sortKey = (String)state.getValue(m_sortType);
final boolean isCurrentKey = sortKey.equals(m_key); final boolean isCurrentKey = sortKey.equals(m_key);
@ -370,21 +370,21 @@ public class FolderBrowser extends Table {
} }
ControlLink cl = new ControlLink(headerName) { ControlLink cl = new ControlLink(headerName) {
public void setControlEvent(PageState ps) { public void setControlEvent(PageState ps) {
String sortDirectionAction = null; String sortDirectionAction = null;
// by default, everything sorts "up" unless it // by default, everything sorts "up" unless it
// is the current key and it is already pointing up // is the current key and it is already pointing up
if (SORT_ACTION_UP.equals(currentSortDirection) && if (SORT_ACTION_UP.equals(currentSortDirection) &&
isCurrentKey) { isCurrentKey) {
sortDirectionAction = SORT_ACTION_DOWN; sortDirectionAction = SORT_ACTION_DOWN;
} else { } else {
sortDirectionAction = SORT_ACTION_UP; sortDirectionAction = SORT_ACTION_UP;
}
ps.setControlEvent(table,
sortDirectionAction,
m_key);
} }
}; ps.setControlEvent(table,
sortDirectionAction,
m_key);
}
};
Label l = new Label(); Label l = new Label();
l.setLabel("<font color=\"blue\">" + headerName + "</font>"); l.setLabel("<font color=\"blue\">" + headerName + "</font>");
l.setOutputEscaping(false); l.setOutputEscaping(false);
@ -412,14 +412,14 @@ public class FolderBrowser extends Table {
} }
public Component getComponent(Table table, PageState state, Object value, public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
Folder.ItemCollection coll = (Folder.ItemCollection) value; Folder.ItemCollection coll = (Folder.ItemCollection) value;
String name = coll.getName(); String name = coll.getName();
if ( coll.isFolder() ) { if ( coll.isFolder() ) {
return super.getComponent(table, state, name, return super.getComponent(table, state, name,
isSelected, key, row, column); isSelected, key, row, column);
} else { } else {
ContentSection section = CMS.getContext().getContentSection(); ContentSection section = CMS.getContext().getContentSection();
BigDecimal id = coll.getID(); BigDecimal id = coll.getID();
@ -429,7 +429,7 @@ public class FolderBrowser extends Table {
} else { } else {
ItemResolver resolver = section.getItemResolver(); ItemResolver resolver = section.getItemResolver();
return new Link(name, resolver.generateItemURL return new Link(name, resolver.generateItemURL
(state, id, name, section, coll.getVersion())); (state, id, name, section, coll.getVersion()));
} }
} }
} }
@ -451,8 +451,8 @@ public class FolderBrowser extends Table {
} }
public Component getComponent(Table table, PageState state, Object value, public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
if ( ((Boolean) value).booleanValue() ) { if ( ((Boolean) value).booleanValue() ) {
return s_link; return s_link;
} else { } else {
@ -535,7 +535,7 @@ public class FolderBrowser extends Table {
//} //}
public FolderTableModel public FolderTableModel
(FolderBrowser table, PageState state, Folder.ItemCollection itemColl) { (FolderBrowser table, PageState state, Folder.ItemCollection itemColl) {
m_state = state; m_state = state;
m_table = table; m_table = table;
m_itemColl = itemColl; m_itemColl = itemColl;
@ -561,45 +561,45 @@ public class FolderBrowser extends Table {
public Object getElementAt(int columnIndex) { public Object getElementAt(int columnIndex) {
switch (columnIndex) { switch (columnIndex) {
case NAME: case NAME:
return m_itemColl; return m_itemColl;
case TITLE: case TITLE:
return m_itemColl.getDisplayName(); return m_itemColl.getDisplayName();
case TYPE: case TYPE:
return m_itemColl.getTypeLabel(); return m_itemColl.getTypeLabel();
case CREATION_DATE: { case CREATION_DATE: {
java.util.Date creationDate = m_itemColl.getCreationDate(); java.util.Date creationDate = m_itemColl.getCreationDate();
if ( creationDate == null ) { if ( creationDate == null ) {
return "--"; return "--";
}
return FormatStandards.formatDate(creationDate);
} }
return FormatStandards.formatDate(creationDate); case LAST_MODIFIED: {
} java.util.Date lastModified = m_itemColl.getLastModifiedDate();
case LAST_MODIFIED: { if ( lastModified == null ) {
java.util.Date lastModified = m_itemColl.getLastModifiedDate(); return "--";
if ( lastModified == null ) { }
return "--"; return FormatStandards.formatDate(lastModified);
} }
return FormatStandards.formatDate(lastModified); case DELETABLE:
} return new Boolean(isDeletable());
case DELETABLE: case IS_INDEX: {
return new Boolean(isDeletable()); if (hideIndexColumn()) {
case IS_INDEX: { throw new IndexOutOfBoundsException("Column index " + columnIndex +
if (hideIndexColumn()) { " 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 + throw new IndexOutOfBoundsException("Column index " + columnIndex +
" not in table model."); " 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.");
} }
} }
@ -620,13 +620,13 @@ public class FolderBrowser extends Table {
if (!m_itemColl.hasChildren()) { if (!m_itemColl.hasChildren()) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The item is an empty folder; it may be " + s_log.debug("The item is an empty folder; it may be " +
"deleted"); "deleted");
} }
return true; return true;
} else { } else {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The folder is not empty; it cannot be " + s_log.debug("The folder is not empty; it cannot be " +
"deleted"); "deleted");
} }
return false; return false;
} }
@ -642,7 +642,7 @@ public class FolderBrowser extends Table {
public Object getKeyAt(int columnIndex) { public Object getKeyAt(int columnIndex) {
// Mark folders by using their negative ID (dirty, dirty) // Mark folders by using their negative ID (dirty, dirty)
return ( m_itemColl.isFolder() ) ? m_itemColl.getID().negate() return ( m_itemColl.isFolder() ) ? m_itemColl.getID().negate()
: m_itemColl.getBundleID(); : m_itemColl.getBundleID();
} }
} }

View File

@ -67,7 +67,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
/** Data object type for this domain object */ /** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = 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) */ /** Data object type for this domain object (for CMS compatibility) */
public static final String TYPE = BASE_DATA_OBJECT_TYPE; public static final String TYPE = BASE_DATA_OBJECT_TYPE;
@ -80,14 +80,14 @@ public class DocLink extends ContentPage implements Resource, Searchable {
public DocLink() { public DocLink() {
this(BASE_DATA_OBJECT_TYPE); this(BASE_DATA_OBJECT_TYPE);
try { try {
setContentType( setContentType(
ContentType.findByAssociatedObjectType(BASE_DATA_OBJECT_TYPE)); ContentType.findByAssociatedObjectType(BASE_DATA_OBJECT_TYPE));
} catch (DataObjectNotFoundException e) { } catch (DataObjectNotFoundException e) {
throw new UncheckedWrapperException( throw new UncheckedWrapperException(
(String) GlobalizationUtil (String) GlobalizationUtil
.globalize("cms.contenttypes.event_type_not_registered") .globalize("cms.contenttypes.event_type_not_registered")
.localize(), .localize(),
e); e);
} }
} }
@ -200,7 +200,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
*/ */
public Resource getParentResource() { public Resource getParentResource() {
DocFolder parent = DocFolder parent =
(DocFolder) ((ContentBundle) getParent()).getParent(); (DocFolder) ((ContentBundle) getParent()).getParent();
return parent; return parent;
} }
@ -241,13 +241,13 @@ public class DocLink extends ContentPage implements Resource, Searchable {
*/ */
public Resource copyTo(String name, final Resource parent) throws ResourceExistsException { public Resource copyTo(String name, final Resource parent) throws ResourceExistsException {
Folder.ItemCollection ic = Folder.ItemCollection ic =
((Folder) parent).getItems(); ((Folder) parent).getItems();
ic.addEqualsFilter("name",URLEncoder.encode(name)); ic.addEqualsFilter("name",URLEncoder.encode(name));
boolean resourceExists = ic.next(); boolean resourceExists = ic.next();
ic.close(); ic.close();
if(resourceExists) { if(resourceExists) {
throw new ResourceExistsException throw new ResourceExistsException
("Copying document would result in duplicate: "+name); ("Copying document would result in duplicate: "+name);
} }
ContentItem item = this; ContentItem item = this;
@ -271,7 +271,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
PermissionService.setContext(newItem,(ACSObject) parent); PermissionService.setContext(newItem,(ACSObject) parent);
}}.run(); }}.run();
return (Resource) ((ContentBundle) newItem).getPrimaryInstance(); return (Resource) ((ContentBundle) newItem).getPrimaryInstance();
} }
/** /**
@ -308,7 +308,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
PermissionService.setContext(cb, (ACSObject) parent); PermissionService.setContext(cb, (ACSObject) parent);
} }
} }
.run(); .run();
} }
/** /**
@ -352,11 +352,11 @@ public class DocLink extends ContentPage implements Resource, Searchable {
} }
} }
CategoryCollection cats = getCategoryCollection(); CategoryCollection cats = getCategoryCollection();
Category cat; Category cat;
if (cats.next()) { if (cats.next()) {
cat = cats.getCategory(); cat = cats.getCategory();
String catID = cat.getID().toString(); String catID = cat.getID().toString();
if (newCategories.contains(catID)) { if (newCategories.contains(catID)) {
newCategories.remove(catID); newCategories.remove(catID);
} else { } else {
@ -366,13 +366,13 @@ public class DocLink extends ContentPage implements Resource, Searchable {
Iterator additions = newCategories.iterator(); Iterator additions = newCategories.iterator();
while (additions.hasNext()) { while (additions.hasNext()) {
addCategory(new Category(new BigDecimal addCategory(new Category(new BigDecimal
((String) additions.next()))); ((String) additions.next())));
} }
} }
protected void beforeSave() { protected void beforeSave() {
super.beforeSave(); super.beforeSave();
setLastModifiedLocal(new Date()); setLastModifiedLocal(new Date());
} }
public String getSearchLanguage() { public String getSearchLanguage() {
@ -386,7 +386,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
} }
public String getSearchUrlStub() { public String getSearchUrlStub() {
return ""; return "";
} }
} }

View File

@ -21,6 +21,7 @@ package com.arsdigita.london.atoz;
import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.persistence.DataQuery; import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
@ -58,7 +59,11 @@ public class AtoZItemGenerator extends AbstractAtoZGenerator {
bundle = new ContentBundle(new BigDecimal(entries.get("id") bundle = new ContentBundle(new BigDecimal(entries.get("id")
.toString())); .toString()));
if (bundle != null) { 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) { if (item != null) {
// this is necessary because aliases refer to the non-live // this is necessary because aliases refer to the non-live
// version, // version,

View File

@ -64,7 +64,7 @@ import com.arsdigita.kernel.User;
*/ */
public class RSSService { public class RSSService {
private static org.apache.log4j.Logger s_log = 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(); private static final RSSConfig s_config = new RSSConfig();
@ -80,10 +80,10 @@ public class RSSService {
* Generates an RSS channel for a specified category and and all of its Articles. * Generates an RSS channel for a specified category and and all of its Articles.
*/ */
public static void generateChannel( public static void generateChannel(
BigDecimal categoryId, BigDecimal categoryId,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response)
throws Exception { throws Exception {
Category cat = new Category(categoryId); Category cat = new Category(categoryId);
boolean useLAWs = "laws-1.0".equals(request.getParameter("extension")); boolean useLAWs = "laws-1.0".equals(request.getParameter("extension"));
@ -95,7 +95,7 @@ public class RSSService {
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS =
Namespace.getNamespace( Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
@ -103,21 +103,21 @@ public class RSSService {
// The following namespaces are declared for the possible // The following namespaces are declared for the possible
// use of the LAWS extension // use of the LAWS extension
Namespace dcNS = 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; Namespace egmsNS = null;
if (useESD) { if (useESD) {
egmsNS = egmsNS =
Namespace.getNamespace( Namespace.getNamespace(
"esd", "esd",
"http://www.esd.org.uk/standards/esd/3.0/esd.rdfs"); "http://www.esd.org.uk/standards/esd/3.0/esd.rdfs");
} else { } else {
egmsNS = egmsNS =
Namespace.getNamespace( Namespace.getNamespace(
"egms", "egms",
"http://www.esd.org.uk/standards/egms/3.0/egms.rdfs"); "http://www.esd.org.uk/standards/egms/3.0/egms.rdfs");
} }
Namespace lgclNS = Namespace lgclNS =
Namespace.getNamespace( Namespace.getNamespace(
"lgcl", "lgcl",
"http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs"); "http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs");
@ -133,9 +133,9 @@ public class RSSService {
// Channel info // Channel info
Element channel = new Element("channel", rssNS); Element channel = new Element("channel", rssNS);
channel.setAttribute( channel.setAttribute(
"about", "about",
URL.here(request, "/rss/").getURL(), URL.here(request, "/rss/").getURL(),
rdfNS); rdfNS);
rdf.addContent(channel); rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS); Element channelTitle = new Element("title", rssNS);
@ -167,7 +167,7 @@ public class RSSService {
// (below rdf) // (below rdf)
SortedSet items = new TreeSet(); SortedSet items = new TreeSet();
CategorizedCollection objects = CategorizedCollection objects =
cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE); cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
while (objects.next()) { while (objects.next()) {
ContentItem item = (ContentItem) objects.getACSObject(); ContentItem item = (ContentItem) objects.getACSObject();
@ -229,11 +229,11 @@ public class RSSService {
if (description != null) { if (description != null) {
Element descEl = new Element("description", rssNS); Element descEl = new Element("description", rssNS);
descEl.setText( descEl.setText(
com.arsdigita.util.StringUtils.truncateString( com.arsdigita.util.StringUtils.truncateString(
description, description,
100, 100,
true) true)
+ "..."); + "...");
itemEl.addContent(descEl); itemEl.addContent(descEl);
} }
@ -264,7 +264,7 @@ public class RSSService {
itemEl.addContent(dcDateEl); itemEl.addContent(dcDateEl);
Element subjectCategoryEl = Element subjectCategoryEl =
new Element("subjectCategory", egmsNS); new Element("subjectCategory", egmsNS);
itemEl.addContent(subjectCategoryEl); itemEl.addContent(subjectCategoryEl);
Element subjectBagEl = new Element("Bag", rdfNS); Element subjectBagEl = new Element("Bag", rdfNS);
@ -284,7 +284,7 @@ public class RSSService {
if (terms != null) { if (terms != null) {
DomainCollectionIterator it = DomainCollectionIterator it =
new DomainCollectionIterator(terms); new DomainCollectionIterator(terms);
while (it.hasNext()) { while (it.hasNext()) {
@ -344,7 +344,7 @@ public class RSSService {
public int compareTo(Object o) { public int compareTo(Object o) {
if ((o instanceof NewestFirstItem)) { if ((o instanceof NewestFirstItem)) {
return return
- 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID())); - 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
} else { } else {
throw new ClassCastException("Must compare to NewestFirstItem"); throw new ClassCastException("Must compare to NewestFirstItem");
} }
@ -363,15 +363,15 @@ public class RSSService {
* Generates an RSS channel for a specified category purpose * Generates an RSS channel for a specified category purpose
*/ */
public static void generateChannelList( public static void generateChannelList(
Category root, Category root,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response)
throws Exception { throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS =
Namespace.getNamespace( Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
@ -383,9 +383,9 @@ public class RSSService {
// Channel info // Channel info
Element channel = new Element("channel", rssNS); Element channel = new Element("channel", rssNS);
channel.setAttribute( channel.setAttribute(
"about", "about",
URL.here(request, "/rss/").getURL(), URL.here(request, "/rss/").getURL(),
rdfNS); rdfNS);
rdf.addContent(channel); rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS); Element channelTitle = new Element("title", rssNS);
@ -464,14 +464,14 @@ public class RSSService {
* Generates an RSS channel for a specified category and and all of its Articles. * Generates an RSS channel for a specified category and and all of its Articles.
*/ */
public static void generateFeedList( public static void generateFeedList(
boolean acsj, boolean acsj,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response)
throws Exception { throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS =
Namespace.getNamespace( Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
@ -483,9 +483,9 @@ public class RSSService {
// Channel info // Channel info
Element channel = new Element("channel", rssNS); Element channel = new Element("channel", rssNS);
channel.setAttribute( channel.setAttribute(
"about", "about",
URL.here(request, "/rss/").getURL(), URL.here(request, "/rss/").getURL(),
rdfNS); rdfNS);
rdf.addContent(channel); rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS); Element channelTitle = new Element("title", rssNS);
@ -564,7 +564,7 @@ public class RSSService {
upperCamel += word.toUpperCase(); upperCamel += word.toUpperCase();
} else { } else {
upperCamel += word.substring(0, 1).toUpperCase() upperCamel += word.substring(0, 1).toUpperCase()
+ word.substring(1, word.length()); + word.substring(1, word.length());
} }
} }