Ü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,54 +57,54 @@ 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
*/ */
public static final String INSTANCES = "instances"; public static final String INSTANCES = "instances";
/** /**
* The association to AtoZ aliases * The association to AtoZ aliases
*/ */
public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders"; public static final String ATOZ_ALIASING_PROVIDERS = "atozAliasingProviders";
/** /**
* The default language property * The default language property
*/ */
public static final String DEFAULT_LANGUAGE = "defaultLanguage"; public static final String DEFAULT_LANGUAGE = "defaultLanguage";
private boolean m_wasNew = false; private boolean m_wasNew = false;
/** /**
* Returns the data object type for this bundle. * Returns the data object type for this bundle.
*/ */
public String getBaseDataObjectType() { public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE; return BASE_DATA_OBJECT_TYPE;
} }
/** /**
* Creates a new bundle. * Creates a new bundle.
* *
@ -112,16 +112,16 @@ public class ContentBundle extends ContentItem {
*/ */
public ContentBundle(final ContentItem primary) { public ContentBundle(final ContentItem primary) {
super(BASE_DATA_OBJECT_TYPE); super(BASE_DATA_OBJECT_TYPE);
Assert.exists(primary, ContentItem.class); Assert.exists(primary, ContentItem.class);
setDefaultLanguage(primary.getLanguage()); setDefaultLanguage(primary.getLanguage());
setContentType(primary.getContentType()); setContentType(primary.getContentType());
addInstance(primary); addInstance(primary);
super.setName(primary.getName()); super.setName(primary.getName());
} }
/** /**
* Retrieves a bundle. * Retrieves a bundle.
* *
@ -130,7 +130,7 @@ public class ContentBundle extends ContentItem {
public ContentBundle(final OID oid) throws DataObjectNotFoundException { public ContentBundle(final OID oid) throws DataObjectNotFoundException {
super(oid); super(oid);
} }
/** /**
* Retrieves a bundle. * Retrieves a bundle.
* *
@ -138,10 +138,10 @@ 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));
} }
/** /**
* Retrieves or creates a bundle using the <code>DataObject</code> * Retrieves or creates a bundle using the <code>DataObject</code>
* argument. * argument.
@ -152,7 +152,7 @@ public class ContentBundle extends ContentItem {
public ContentBundle(final DataObject object) { public ContentBundle(final DataObject object) {
super(object); super(object);
} }
/** /**
* Creates a bundle. * Creates a bundle.
* *
@ -162,15 +162,15 @@ public class ContentBundle extends ContentItem {
public ContentBundle(final String type) { public ContentBundle(final String type) {
super(type); super(type);
} }
protected ContentItem makeCopy() { protected ContentItem makeCopy() {
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) {
s_log.debug("Setting up new workflow template"); s_log.debug("Setting up new workflow template");
ItemCollection instances = getInstances(); ItemCollection instances = getInstances();
@ -181,20 +181,20 @@ public class ContentBundle extends ContentItem {
workflow.setObjectID(instance.getID()); workflow.setObjectID(instance.getID());
workflow.start(Web.getContext().getUser()); workflow.start(Web.getContext().getUser());
workflow.save(); workflow.save();
} }
} }
return newItem; return newItem;
} }
/** /**
* Gets the default language of the bundle. * Gets the default language of the bundle.
*/ */
public final String getDefaultLanguage() { public final String getDefaultLanguage() {
return (String) get(DEFAULT_LANGUAGE); return (String) get(DEFAULT_LANGUAGE);
} }
/** /**
* Sets the default language of the bundle. * Sets the default language of the bundle.
*/ */
@ -202,12 +202,12 @@ 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);
} }
/** /**
* Adds a language instance to this bundle. This method will fail * Adds a language instance to this bundle. This method will fail
* if the bundle already contains a different instance for the * if the bundle already contains a different instance for the
@ -225,22 +225,22 @@ public class ContentBundle extends ContentItem {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Adding " + instance + " to bundle " + this); s_log.debug("Adding " + instance + " to bundle " + this);
} }
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);
instance.setContentSection(getContentSection()); instance.setContentSection(getContentSection());
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.equal(this, instance.getParent()); Assert.equal(this, instance.getParent());
} }
} }
/** /**
* Removes a language instance from the bundle. This method will * Removes a language instance from the bundle. This method will
* fail if <code>instance</code> is the primary instance. * fail if <code>instance</code> is the primary instance.
@ -259,14 +259,14 @@ public class ContentBundle extends ContentItem {
Assert.equal(this, instance.getParent()); Assert.equal(this, instance.getParent());
Assert.unequal(instance, getPrimaryInstance()); Assert.unequal(instance, getPrimaryInstance());
} }
instance.setParent(null); instance.setParent(null);
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.truth(instance.getParent() == null); Assert.truth(instance.getParent() == null);
} }
} }
/** /**
* Gets the primary instance of this bundle. * Gets the primary instance of this bundle.
* *
@ -277,7 +277,7 @@ public class ContentBundle extends ContentItem {
public final ContentItem getPrimaryInstance() { public final ContentItem getPrimaryInstance() {
return getInstance(getDefaultLanguage()); return getInstance(getDefaultLanguage());
} }
/** /**
* Produces a collection containing all language instances in this * Produces a collection containing all language instances in this
* bundle. * bundle.
@ -287,7 +287,7 @@ public class ContentBundle extends ContentItem {
public final ItemCollection getInstances() { public final ItemCollection getInstances() {
return new ItemCollection(instances()); return new ItemCollection(instances());
} }
/** /**
* Returns a language instance for <code>language</code> or * Returns a language instance for <code>language</code> or
* <code>null</code> if no such instance exists. * <code>null</code> if no such instance exists.
@ -306,34 +306,34 @@ 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();
instances.addEqualsFilter(LANGUAGE, language); instances.addEqualsFilter(LANGUAGE, language);
DataObject dataObject = null; DataObject dataObject = null;
if (instances.next()) { if (instances.next()) {
final DataObject data = instances.getDataObject(); final DataObject data = instances.getDataObject();
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
//Assert.falsity(instances.next(), //Assert.falsity(instances.next(),
// "There is more than one instance with the " + // "There is more than one instance with the " +
// "same language"); // "same language");
} }
instances.close(); instances.close();
return (ContentItem) DomainObjectFactory.newInstance(data); return (ContentItem) DomainObjectFactory.newInstance(data);
} else { } else {
instances.close(); instances.close();
return null; return null;
} }
} }
/** /**
* Tells whether <code>instance</code> is present in the bundle. * Tells whether <code>instance</code> is present in the bundle.
* *
@ -342,13 +342,13 @@ public class ContentBundle extends ContentItem {
*/ */
public final boolean hasInstance(final ContentItem instance) { public final boolean hasInstance(final ContentItem instance) {
Assert.exists(instance, ContentItem.class); Assert.exists(instance, ContentItem.class);
final DataAssociationCursor instances = instances(); final DataAssociationCursor instances = instances();
instances.addEqualsFilter(ID, instance.getID()); instances.addEqualsFilter(ID, instance.getID());
return !instances.isEmpty(); return !instances.isEmpty();
} }
/** /**
* Utility method to check if this bundle already contains an * Utility method to check if this bundle already contains an
* instance for the given <code>language</code>. * instance for the given <code>language</code>.
@ -362,15 +362,15 @@ 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();
instances.addEqualsFilter(LANGUAGE, language); instances.addEqualsFilter(LANGUAGE, language);
return !instances.isEmpty(); return !instances.isEmpty();
} }
/** /**
* List all languages in which this item is available, i.e. the * List all languages in which this item is available, i.e. the
* language codes of all instances in this bundle. * 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 // XXX For LIVE bundles, there might be several PENDING
// instances with the same language. Maybe we should filter // instances with the same language. Maybe we should filter
// these out and return only one? // these out and return only one?
final ItemCollection items = getInstances(); final ItemCollection items = getInstances();
final Collection list = new ArrayList(); final Collection list = new ArrayList();
while (items.next()) { while (items.next()) {
list.add(items.getLanguage()); list.add(items.getLanguage());
} }
items.close(); items.close();
if (Assert.isEnabled()) { if (Assert.isEnabled()) {
Assert.truth(!list.isEmpty() || getInstances().isEmpty()); Assert.truth(!list.isEmpty() || getInstances().isEmpty());
} }
return list; return list;
} }
/** /**
* Negotiate the right language instance for this bundle and return it. * Negotiate the right language instance for this bundle and return it.
* *
@ -420,11 +420,11 @@ public class ContentBundle extends ContentItem {
while (instancesCursor.next()) { while (instancesCursor.next()) {
dataObject = instancesCursor.getDataObject(); dataObject = instancesCursor.getDataObject();
language = (String) dataObject.get(LANGUAGE); language = (String) dataObject.get(LANGUAGE);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("negotiate: language= " + language); s_log.debug("negotiate: language= " + language);
} }
if (language != null) { if (language != null) {
for (int i=0; i < locales.length; i++) { for (int i=0; i < locales.length; i++) {
if (language.equals(locales[i].getLanguage())) { if (language.equals(locales[i].getLanguage())) {
@ -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,13 +448,13 @@ 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;
} }
} }
/** /**
* Negotiate the right language instance for this bundle and return it. * 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()); s_log.debug("negotiate: pref " + i + ": "+ loc.getLanguage());
} }
} }
final DataAssociationCursor instances = instances(); final DataAssociationCursor instances = instances();
DataObject dataObject = null; DataObject dataObject = null;
int bestMatch = 0; int bestMatch = 0;
DataObject match = null; DataObject match = null;
String language = null; String language = null;
while (instances.next()) { while (instances.next()) {
dataObject = instances.getDataObject(); dataObject = instances.getDataObject();
language = (String) dataObject.get(LANGUAGE); language = (String) dataObject.get(LANGUAGE);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("negotiate: language= " + language); s_log.debug("negotiate: language= " + language);
} }
if (language != null) { if (language != null) {
for (int i=0; i < languageCodes.size(); i++) { for (int i=0; i < languageCodes.size(); i++) {
if (language.equals( (String)languageCodes.get(i) )) { if (language.equals( (String)languageCodes.get(i) )) {
@ -503,67 +503,67 @@ 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
} }
} // end for } // end for
} // end if } // end if
if (bestMatch == 0 && match != null) { if (bestMatch == 0 && match != null) {
s_log.debug("negotiate: best possible match found, exiting"); s_log.debug("negotiate: best possible match found, exiting");
break; // exit loop when best match is found break; // exit loop when best match is found
} }
} }
instances.close(); instances.close();
return (ContentItem) DomainObjectFactory.newInstance(match); return (ContentItem) DomainObjectFactory.newInstance(match);
} }
// Methods from item that bundle overrides // Methods from item that bundle overrides
protected void beforeSave() { protected void beforeSave() {
super.beforeSave(); super.beforeSave();
final ContentItem primary = getPrimaryInstance(); final ContentItem primary = getPrimaryInstance();
Assert.exists(getContentType(), ContentType.class); Assert.exists(getContentType(), ContentType.class);
if (primary != null) { if (primary != null) {
primary.setContentSection(getContentSection()); primary.setContentSection(getContentSection());
} }
} }
protected boolean canPublishToFS() { protected boolean canPublishToFS() {
return false; return false;
} }
protected void publishToFS() { protected void publishToFS() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public ContentItem publish(final LifecycleDefinition definition, public ContentItem publish(final LifecycleDefinition definition,
final Date start) { final Date start) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public Lifecycle getLifecycle() { public Lifecycle getLifecycle() {
// Bundles do not have lifecycles. // Bundles do not have lifecycles.
return null; return null;
} }
public void setLifecycle(final Lifecycle lifecycle) { public void setLifecycle(final Lifecycle lifecycle) {
// I'd like to do the following, but VersionCopier calls // I'd like to do the following, but VersionCopier calls
// setLifecycle. // setLifecycle.
//throw new UnsupportedOperationException(); //throw new UnsupportedOperationException();
} }
/** /**
* Ignore the <code>INSTANCES</code> property for * Ignore the <code>INSTANCES</code> property for
* <code>ItemCopier.VERSION_COPY</code>. * <code>ItemCopier.VERSION_COPY</code>.
* *
* @param source the source CustomCopy item * @param source the source CustomCopy item
@ -575,25 +575,25 @@ 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);
} }
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
CategoryCollection categories = source.getCategoryCollection(); CategoryCollection categories = source.getCategoryCollection();
while (categories.next() ) { while (categories.next() ) {
@ -602,39 +602,39 @@ public class ContentBundle extends ContentItem {
category.save(); // XXX remove me category.save(); // XXX remove me
} }
categories.close(); categories.close();
return true; return true;
} }
protected void initialize() { protected void initialize() {
super.initialize(); super.initialize();
addObserver(s_instancesObserver); addObserver(s_instancesObserver);
m_wasNew = isNew(); m_wasNew = isNew();
} }
protected void afterSave() { protected void afterSave() {
if (m_wasNew) { if (m_wasNew) {
getPrimaryInstance().setContentSection(getContentSection()); getPrimaryInstance().setContentSection(getContentSection());
} }
super.afterSave(); super.afterSave();
} }
// Utility methods // Utility methods
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;
} }
private DataAssociationCursor instances(final String version) { private DataAssociationCursor instances(final String version) {
final DataAssociationCursor cursor = instances(); final DataAssociationCursor cursor = instances();
cursor.addEqualsFilter(VERSION, version); cursor.addEqualsFilter(VERSION, version);
return cursor; return cursor;
} }
} }

View File

@ -80,55 +80,55 @@ 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";
private FolderSelectionModel m_currentFolder; private FolderSelectionModel m_currentFolder;
private TableActionListener m_folderChanger; private TableActionListener m_folderChanger;
private TableActionListener m_deleter; private TableActionListener m_deleter;
private TableActionListener m_indexChanger; private TableActionListener m_indexChanger;
private TableColumn m_nameColumn; private TableColumn m_nameColumn;
private TableColumn m_deleteColumn; private TableColumn m_deleteColumn;
private TableColumn m_indexColumn; private TableColumn m_indexColumn;
private final static String SORT_KEY_NAME = "name"; private final static String SORT_KEY_NAME = "name";
private final static String SORT_KEY_TITLE = "title"; private final static String SORT_KEY_TITLE = "title";
private final static String SORT_KEY_LAST_MODIFIED_DATE = "lastModified"; private final static String SORT_KEY_LAST_MODIFIED_DATE = "lastModified";
private final static String SORT_KEY_CREATION_DATE = "creationDate"; private final static String SORT_KEY_CREATION_DATE = "creationDate";
private StringParameter m_sortType = new StringParameter("sortType"); private StringParameter m_sortType = new StringParameter("sortType");
private StringParameter m_sortDirection = new StringParameter("sortDirn"); private StringParameter m_sortDirection = new StringParameter("sortDirn");
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
@ -139,31 +139,31 @@ public class FolderBrowser extends Table {
// and pull the foldertablemodelbuilder back with the super class' // and pull the foldertablemodelbuilder back with the super class'
// accessor. // accessor.
((FolderTableModelBuilder)getModelBuilder()).setFolderBrowser(this); ((FolderTableModelBuilder)getModelBuilder()).setFolderBrowser(this);
m_currentFolder = currentFolder; m_currentFolder = currentFolder;
/* /*
This code should be uncommented if the desired behaviour is for a change 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 (by name ascending). Our feeling is that the user selected ordering
should be retained for the duration of the folder browsing session. If 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. the control of a config parameter.
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());
m_nameColumn = getColumn(0); m_nameColumn = getColumn(0);
m_nameColumn.setCellRenderer(new NameCellRenderer()); m_nameColumn.setCellRenderer(new NameCellRenderer());
m_nameColumn.setHeaderRenderer(new HeaderCellRenderer(SORT_KEY_NAME)); m_nameColumn.setHeaderRenderer(new HeaderCellRenderer(SORT_KEY_NAME));
@ -177,50 +177,50 @@ public class FolderBrowser extends Table {
m_indexColumn = getColumn(6); m_indexColumn = getColumn(6);
m_indexColumn.setCellRenderer(new IndexToggleRenderer()); m_indexColumn.setCellRenderer(new IndexToggleRenderer());
m_indexColumn.setAlign("center"); m_indexColumn.setAlign("center");
m_indexChanger = new IndexChanger(m_currentFolder); m_indexChanger = new IndexChanger(m_currentFolder);
addTableActionListener(m_indexChanger); addTableActionListener(m_indexChanger);
} }
m_folderChanger = new FolderChanger(); m_folderChanger = new FolderChanger();
addTableActionListener(m_folderChanger); addTableActionListener(m_folderChanger);
m_deleter = new ItemDeleter(); m_deleter = new ItemDeleter();
addTableActionListener(m_deleter); addTableActionListener(m_deleter);
setEmptyView(new Label(globalize("cms.ui.folder.no_items"))); setEmptyView(new Label(globalize("cms.ui.folder.no_items")));
Assert.assertNotNull( m_currentFolder.getStateParameter() ); Assert.assertNotNull( m_currentFolder.getStateParameter() );
} }
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
p.addComponentStateParam(this, m_currentFolder.getStateParameter()); p.addComponentStateParam(this, m_currentFolder.getStateParameter());
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) {
SecurityManager sm = Utilities.getSecurityManager(state); SecurityManager sm = Utilities.getSecurityManager(state);
Folder folder = (Folder) m_currentFolder.getSelectedObject(state); Folder folder = (Folder) m_currentFolder.getSelectedObject(state);
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);
} }
public void respond(PageState state) throws ServletException { public void respond(PageState state) throws ServletException {
String key = state.getControlEventName(); String key = state.getControlEventName();
String value = state.getControlEventValue(); String value = state.getControlEventValue();
@ -228,30 +228,30 @@ 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);
//throw new ServletException("Unknown control event: " + key); //throw new ServletException("Unknown control event: " + key);
} }
} }
public FolderSelectionModel getFolderSelectionModel() { public FolderSelectionModel getFolderSelectionModel() {
return m_currentFolder; return m_currentFolder;
} }
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;
private RequestLocal m_itemColl; private RequestLocal m_itemColl;
private FolderBrowser m_fb; private FolderBrowser m_fb;
public FolderTableModelBuilder(FolderSelectionModel sel) { public FolderTableModelBuilder(FolderSelectionModel sel) {
this(sel, null); this(sel, null);
} }
public FolderTableModelBuilder(FolderSelectionModel sel, FolderBrowser fb) { public FolderTableModelBuilder(FolderSelectionModel sel, FolderBrowser fb) {
super(); super();
m_folder = sel; m_folder = sel;
@ -259,7 +259,7 @@ public class FolderBrowser extends Table {
m_itemColl = new RequestLocal(); m_itemColl = new RequestLocal();
m_fb = fb; m_fb = fb;
} }
public TableModel makeModel(Table t, PageState s) { public TableModel makeModel(Table t, PageState s) {
FolderSelectionModel sel = ((FolderBrowser) t).getFolderSelectionModel(); FolderSelectionModel sel = ((FolderBrowser) t).getFolderSelectionModel();
Folder f = (Folder) sel.getSelectedObject(s); Folder f = (Folder) sel.getSelectedObject(s);
@ -268,68 +268,68 @@ 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));
} }
} }
public int getTotalSize(Paginator paginator, PageState state) { public int getTotalSize(Paginator paginator, PageState state) {
Integer size = (Integer) m_size.get(state); Integer size = (Integer) m_size.get(state);
if (size == null) { if (size == null) {
Folder f = (Folder) m_folder.getSelectedObject(state); Folder f = (Folder) m_folder.getSelectedObject(state);
Folder.ItemCollection itemColl = f.getPrimaryInstances(); Folder.ItemCollection itemColl = f.getPrimaryInstances();
if (itemColl == null) { if (itemColl == null) {
return 0; return 0;
} }
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";
if (SORT_ACTION_DOWN.equals((String)state.getValue(m_sortDirection))) { if (SORT_ACTION_DOWN.equals((String)state.getValue(m_sortDirection))) {
direction = "desc"; direction = "desc";
} }
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);
m_itemColl.set(state, itemColl); m_itemColl.set(state, itemColl);
} }
return size.intValue(); return size.intValue();
} }
public void setFolderBrowser(FolderBrowser fb) { public void setFolderBrowser(FolderBrowser fb) {
m_fb = fb; m_fb = fb;
} }
/** /**
* Indicates whether the paginator should be visible, * Indicates whether the paginator should be visible,
* based on the visibility of the folder browser itself. * 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; return (m_fb != null)?m_fb.isVisible(state):true;
} }
} }
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;
public HeaderCellRenderer(String key) { public HeaderCellRenderer(String key) {
super(true); super(true);
m_key = key; m_key = key;
} }
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);
final String currentSortDirection = (String)state.getValue(m_sortDirection); final String currentSortDirection = (String)state.getValue(m_sortDirection);
String imageURLStub = null; String imageURLStub = null;
if (SORT_ACTION_UP.equals(currentSortDirection)) { if (SORT_ACTION_UP.equals(currentSortDirection)) {
imageURLStub = "gray-triangle-up.gif"; imageURLStub = "gray-triangle-up.gif";
} else { } else {
imageURLStub = "gray-triangle-down.gif"; imageURLStub = "gray-triangle-down.gif";
} }
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);
l.setFontWeight(Label.BOLD); l.setFontWeight(Label.BOLD);
SimpleContainer container = new SimpleContainer(); SimpleContainer container = new SimpleContainer();
container.add(l); container.add(l);
if ( isCurrentKey ) { if ( isCurrentKey ) {
@ -401,7 +401,7 @@ public class FolderBrowser extends Table {
return cl; return cl;
} }
} }
/** /**
* Produce links to view an item or control links for folders * Produce links to view an item or control links for folders
* to change into the folder. * to change into the folder.
@ -410,49 +410,49 @@ public class FolderBrowser extends Table {
public NameCellRenderer() { public NameCellRenderer() {
super(true); super(true);
} }
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();
if (section == null) { if (section == null) {
return new Label(name); return new Label(name);
} 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()));
} }
} }
} }
} }
/** /**
* Produce delete links for items and non-empty folders. * Produce delete links for items and non-empty folders.
*/ */
private static class ActionCellRenderer implements TableCellRenderer { private static class ActionCellRenderer implements TableCellRenderer {
private static Label s_noAction; private static Label s_noAction;
private static ControlLink s_link; private static ControlLink s_link;
static { static {
s_noAction = new Label("&nbsp;", false); s_noAction = new Label("&nbsp;", false);
s_noAction.lock(); s_noAction.lock();
s_link = new ControlLink(new Label(globalize("cms.ui.folder.delete"))); s_link = new ControlLink(new Label(globalize("cms.ui.folder.delete")));
s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ? s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ?
} }
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 {
@ -460,42 +460,42 @@ public class FolderBrowser extends Table {
} }
} }
} }
private final class IndexToggleRenderer implements TableCellRenderer { private final class IndexToggleRenderer implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) {
if ( value == null ) { if ( value == null ) {
return new Label(GlobalizationUtil.globalize("cms.ui.folder.na")); return new Label(GlobalizationUtil.globalize("cms.ui.folder.na"));
} }
ControlLink link = new ControlLink(""); ControlLink link = new ControlLink("");
if (((Boolean) value).booleanValue()) { if (((Boolean) value).booleanValue()) {
link.setClassAttr("checkBoxChecked"); link.setClassAttr("checkBoxChecked");
} else { } else {
link.setClassAttr("checkBoxUnchecked"); link.setClassAttr("checkBoxUnchecked");
} }
return link; return link;
} }
} }
// Deletes an item // Deletes an item
private class ItemDeleter extends TableActionAdapter { private class ItemDeleter extends TableActionAdapter {
public void cellSelected(TableActionEvent e) { public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue(); int col = e.getColumn().intValue();
if ( m_deleteColumn != getColumn(col) ) { if ( m_deleteColumn != getColumn(col) ) {
return; return;
} }
PageState s = e.getPageState(); PageState s = e.getPageState();
BigDecimal id = new BigDecimal(e.getRowKey().toString()); BigDecimal id = new BigDecimal(e.getRowKey().toString());
OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, id.abs()); OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, id.abs());
final DomainObject item = DomainObjectFactory.newInstance(oid); final DomainObject item = DomainObjectFactory.newInstance(oid);
if (item != null) { if (item != null) {
if (item instanceof ContentBundle) { if (item instanceof ContentBundle) {
ContentBundle bundle = (ContentBundle) item; ContentBundle bundle = (ContentBundle) item;
@ -506,11 +506,11 @@ public class FolderBrowser extends Table {
} }
item.delete(); item.delete();
} }
((Table) e.getSource()).clearSelection(s); ((Table) e.getSource()).clearSelection(s);
} }
} }
/** /**
* Table model around ItemCollection * Table model around ItemCollection
*/ */
@ -522,24 +522,24 @@ public class FolderBrowser extends Table {
private static final int LAST_MODIFIED = 4; private static final int LAST_MODIFIED = 4;
private static final int DELETABLE = 5; private static final int DELETABLE = 5;
private static final int IS_INDEX = 6; private static final int IS_INDEX = 6;
private PageState m_state; private PageState m_state;
private FolderBrowser m_table; private FolderBrowser m_table;
private Folder.ItemCollection m_itemColl; private Folder.ItemCollection m_itemColl;
private Folder m_fol; private Folder m_fol;
private BigDecimal m_folIndexID; private BigDecimal m_folIndexID;
//old constructor before using paginator //old constructor before using paginator
//public FolderTableModel(Folder folder) { //public FolderTableModel(Folder folder) {
//m_itemColl = folder.getItems(); //m_itemColl = folder.getItems();
//} //}
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;
m_fol = (Folder) table.getFolderSelectionModel().getSelectedObject(state); m_fol = (Folder) table.getFolderSelectionModel().getSelectedObject(state);
if (!hideIndexColumn()) { if (!hideIndexColumn()) {
ContentBundle indexItem = m_fol.getIndexItem(); ContentBundle indexItem = m_fol.getIndexItem();
@ -550,83 +550,83 @@ public class FolderBrowser extends Table {
} }
} }
} }
public int getColumnCount() { public int getColumnCount() {
return hideIndexColumn() ? 6 : 7; return hideIndexColumn() ? 6 : 7;
} }
public boolean nextRow() { public boolean nextRow() {
return m_itemColl.next(); return m_itemColl.next();
} }
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.");
} }
} }
public boolean isDeletable() { public boolean isDeletable() {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Checking to see if " + this + " is deletable"); s_log.debug("Checking to see if " + this + " is deletable");
} }
if (m_itemColl.isLive()) { if (m_itemColl.isLive()) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The item is live; it cannot be deleted"); s_log.debug("The item is live; it cannot be deleted");
} }
return false; return false;
} }
if (m_itemColl.isFolder()) { if (m_itemColl.isFolder()) {
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;
} }
@ -634,23 +634,23 @@ public class FolderBrowser extends Table {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("The item is not a folder; it may be deleted"); s_log.debug("The item is not a folder; it may be deleted");
} }
return true; return true;
} }
} }
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();
} }
} }
private class FolderChanger extends TableActionAdapter { private class FolderChanger extends TableActionAdapter {
public void cellSelected(TableActionEvent e) { public void cellSelected(TableActionEvent e) {
PageState s = e.getPageState(); PageState s = e.getPageState();
int col = e.getColumn().intValue(); int col = e.getColumn().intValue();
if ( m_nameColumn != getColumn(col) ) { if ( m_nameColumn != getColumn(col) ) {
return; return;
} }
@ -661,29 +661,29 @@ public class FolderBrowser extends Table {
} }
} }
} }
private class IndexChanger extends TableActionAdapter { private class IndexChanger extends TableActionAdapter {
private FolderSelectionModel m_fol; private FolderSelectionModel m_fol;
public IndexChanger(FolderSelectionModel fol) { public IndexChanger(FolderSelectionModel fol) {
super(); super();
m_fol = fol; m_fol = fol;
} }
public void cellSelected(TableActionEvent e) { public void cellSelected(TableActionEvent e) {
PageState state = e.getPageState(); PageState state = e.getPageState();
BigDecimal rowkey = new BigDecimal((String)e.getRowKey()); BigDecimal rowkey = new BigDecimal((String)e.getRowKey());
if (rowkey == null){ if (rowkey == null){
return; return;
} }
try { try {
ContentBundle contentItem = new ContentBundle(rowkey); ContentBundle contentItem = new ContentBundle(rowkey);
Folder folder = (Folder) m_fol.getSelectedObject(state); Folder folder = (Folder) m_fol.getSelectedObject(state);
ContentBundle currentIndexItem = (ContentBundle) folder.getIndexItem(); ContentBundle currentIndexItem = (ContentBundle) folder.getIndexItem();
if ( currentIndexItem == null || (currentIndexItem.getID().compareTo(contentItem.getID()) != 0)) { if ( currentIndexItem == null || (currentIndexItem.getID().compareTo(contentItem.getID()) != 0)) {
folder.setIndexItem(contentItem); folder.setIndexItem(contentItem);
@ -696,7 +696,7 @@ public class FolderBrowser extends Table {
} }
} }
} }
/** /**
* Getting the GlobalizedMessage using a CMS Class targetBundle. * Getting the GlobalizedMessage using a CMS Class targetBundle.
* *
@ -706,7 +706,7 @@ public class FolderBrowser extends Table {
private static GlobalizedMessage globalize(String key) { private static GlobalizedMessage globalize(String key) {
return FolderManipulator.globalize(key); return FolderManipulator.globalize(key);
} }
private static boolean hideIndexColumn() { private static boolean hideIndexColumn() {
return ContentSection.getConfig().getHideFolderIndexCheckbox(); return ContentSection.getConfig().getHideFolderIndexCheckbox();
} }

View File

@ -48,26 +48,26 @@ import org.apache.log4j.Logger;
/** /**
* DomainObject class which represents <code>DocLink<code> ContentType objects. * DomainObject class which represents <code>DocLink<code> ContentType objects.
* *
* A DocLink will either have an internal reference to another Document * A DocLink will either have an internal reference to another Document
* _or_ contain an external (http) URL. * _or_ contain an external (http) URL.
* *
* @author <a href="mailto:sshinde@redhat.com">Shashin Shinde</a> * @author <a href="mailto:sshinde@redhat.com">Shashin Shinde</a>
* @author Crag Wolfe * @author Crag Wolfe
* *
* $Id: DocLink.java,v 1.1 2004/12/15 16:06:37 pkopunec Exp $ * $Id: DocLink.java,v 1.1 2004/12/15 16:06:37 pkopunec Exp $
* *
*/ */
public class DocLink extends ContentPage implements Resource, Searchable { 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"; private static final String NAME_SUFFIX = "-LinkTo";
/** 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,73 +80,73 @@ 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);
} }
} }
public DocLink(BigDecimal id) throws DataObjectNotFoundException { public DocLink(BigDecimal id) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
public DocLink(OID id) throws DataObjectNotFoundException { public DocLink(OID id) throws DataObjectNotFoundException {
super(id); super(id);
} }
public DocLink(DataObject obj) { public DocLink(DataObject obj) {
super(obj); super(obj);
} }
public DocLink(String type) { public DocLink(String type) {
super(type); super(type);
} }
public void setTitle(String title) { public void setTitle(String title) {
setName(URLEncoder.encode(title)); setName(URLEncoder.encode(title));
super.setTitle(title); super.setTitle(title);
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#getDescription() * @see com.arsdigita.cms.docmgr.Resource#getDescription()
*/ */
public String getDescription() { public String getDescription() {
return (String) get(DESCRIPTION); return (String) get(DESCRIPTION);
} }
public void setDescription(String desc){ public void setDescription(String desc){
set(DESCRIPTION,desc); set(DESCRIPTION,desc);
} }
public boolean isExternal() { public boolean isExternal() {
String s = getExternalURL(); String s = getExternalURL();
return s != null && s.length() > 0; return s != null && s.length() > 0;
} }
public String getExternalURL() { public String getExternalURL() {
return (String) get(EXTERNAL_URL); return (String) get(EXTERNAL_URL);
} }
public void setExternalURL(String externalURL){ public void setExternalURL(String externalURL){
set(EXTERNAL_URL,externalURL); set(EXTERNAL_URL,externalURL);
} }
public Repository getRepository() { public Repository getRepository() {
if (get(REPOSITORY) == null) { if (get(REPOSITORY) == null) {
return null; return null;
} }
return new Repository((DataObject) get(REPOSITORY)); return new Repository((DataObject) get(REPOSITORY));
} }
public void setRepository(Repository repository) { public void setRepository(Repository repository) {
set(REPOSITORY, repository); set(REPOSITORY, repository);
} }
/* redundant to versioning, only for performance */ /* redundant to versioning, only for performance */
public Date getLastModifiedLocal() { public Date getLastModifiedLocal() {
return (Date) get(LAST_MOD_LOCAL); return (Date) get(LAST_MOD_LOCAL);
@ -156,8 +156,8 @@ public class DocLink extends ContentPage implements Resource, Searchable {
public void setLastModifiedLocal(Date last) { public void setLastModifiedLocal(Date last) {
set(LAST_MOD_LOCAL, last); set(LAST_MOD_LOCAL, last);
} }
/** /**
* Set Target Document of this Link.Also set's the name of the Link. * Set Target Document of this Link.Also set's the name of the Link.
* i.e. target.getName()-LinkToxxxx * 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. * NAME_SUFFIX,target Document id,and target document name.
* Also truncates the name if it exceeds 200 characters. * Also truncates the name if it exceeds 200 characters.
*/ */
@ -186,24 +186,24 @@ public class DocLink extends ContentPage implements Resource, Searchable {
return buf.toString(); return buf.toString();
} }
} }
public Document getTarget() { public Document getTarget() {
if (get(TARGET) == null) { if (get(TARGET) == null) {
return null; return null;
} }
return new Document((DataObject) get(TARGET)); return new Document((DataObject) get(TARGET));
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#getParentResource(). * @see com.arsdigita.cms.docmgr.Resource#getParentResource().
* Returns the parent <code>DocFolder</code> * Returns the parent <code>DocFolder</code>
*/ */
public Resource getParentResource() { public Resource getParentResource() {
DocFolder parent = DocFolder parent =
(DocFolder) ((ContentBundle) getParent()).getParent(); (DocFolder) ((ContentBundle) getParent()).getParent();
return parent; return parent;
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#isFolder(). * @see com.arsdigita.cms.docmgr.Resource#isFolder().
* returns false to indicate that it's not a folder. * 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() { public boolean isFolder() {
return false; return false;
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#isFile(). * @see com.arsdigita.cms.docmgr.Resource#isFile().
* returns true to indicate that it's a file. * returns true to indicate that it's a file.
@ -219,7 +219,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
public boolean isFile() { public boolean isFile() {
return true; return true;
} }
/** /**
* Copies the resource into another location. Preserves the * Copies the resource into another location. Preserves the
* original name of the resource but places the copy inside a new * 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 { public Resource copyTo(Resource parent) throws ResourceExistsException {
return copyTo(getTitle(), parent); return copyTo(getTitle(), parent);
} }
/** /**
* Copies the resource into another location with a new name. * 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. * @return a copy of the original resource.
*/ */
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;
if (item.getParent() instanceof ContentBundle) { if (item.getParent() instanceof ContentBundle) {
item = (ContentBundle) item.getParent(); item = (ContentBundle) item.getParent();
@ -258,22 +258,22 @@ public class DocLink extends ContentPage implements Resource, Searchable {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Copying item " + item); s_log.debug("Copying item " + item);
} }
final ContentItem newItem = item.copy(); final ContentItem newItem = item.copy();
newItem.copyServicesFrom(item); newItem.copyServicesFrom(item);
newItem.setParent((Folder) parent); newItem.setParent((Folder) parent);
newItem.setContentSection(item.getContentSection()); newItem.setContentSection(item.getContentSection());
newItem.save(); newItem.save();
new KernelExcursion() { new KernelExcursion() {
protected void excurse() { protected void excurse() {
setParty(Kernel.getSystemParty()); setParty(Kernel.getSystemParty());
PermissionService.setContext(newItem,(ACSObject) parent); PermissionService.setContext(newItem,(ACSObject) parent);
}}.run(); }}.run();
return (Resource) ((ContentBundle) newItem).getPrimaryInstance(); return (Resource) ((ContentBundle) newItem).getPrimaryInstance();
} }
/** /**
* Copies the resource into the same location (same parent) with passed * Copies the resource into the same location (same parent) with passed
* in name as new name. * in name as new name.
@ -285,7 +285,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
final ACSObject parent = getParent(); final ACSObject parent = getParent();
return copyTo(name , (Resource) parent); return copyTo(name , (Resource) parent);
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#toURL(). * @see com.arsdigita.cms.docmgr.Resource#toURL().
* Not Supported.throws <code>UnsupportedOperationException</code> * Not Supported.throws <code>UnsupportedOperationException</code>
@ -293,7 +293,7 @@ public class DocLink extends ContentPage implements Resource, Searchable {
public URL toURL() { public URL toURL() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#setParentResource(com.arsdigita.cms.docmgr.Resource) * @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(); final ContentBundle cb = (ContentBundle) getParent();
cb.setParent((ACSObject) parent); cb.setParent((ACSObject) parent);
cb.save(); cb.save();
new KernelExcursion() { new KernelExcursion() {
protected void excurse() { protected void excurse() {
setParty(Kernel.getSystemParty()); setParty(Kernel.getSystemParty());
PermissionService.setContext(cb, (ACSObject) parent); PermissionService.setContext(cb, (ACSObject) parent);
} }
} }
.run(); .run();
} }
/** /**
* @see com.arsdigita.cms.docmgr.Resource#isRoot() * @see com.arsdigita.cms.docmgr.Resource#isRoot()
* returns false to indicate that it's not the root. * 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() { public boolean isRoot() {
return false; return false;
} }
/** /**
* Delete this Link along with it's parent ContentBundle * Delete this Link along with it's parent ContentBundle
* @see com.arsdigita.domain.DomainObject#delete() * @see com.arsdigita.domain.DomainObject#delete()
@ -327,22 +327,22 @@ public class DocLink extends ContentPage implements Resource, Searchable {
((ContentBundle) getParent()).delete(); ((ContentBundle) getParent()).delete();
} }
/** /**
* Over-ride to avoid any indexing of data for this ContentType. * Over-ride to avoid any indexing of data for this ContentType.
* returns empty string; * returns empty string;
*/ */
public String getSearchXMLContent() { public String getSearchXMLContent() {
return ""; return "";
} }
/** /**
* Over-ride to avoid any indexing of data for this ContentType. * Over-ride to avoid any indexing of data for this ContentType.
* returns empty byte array; * returns empty byte array;
*/ */
public byte[] getSearchRawContent() { public byte[] getSearchRawContent() {
return new byte[0]; return new byte[0];
} }
public void setCategories(String[] catIDs) { public void setCategories(String[] catIDs) {
HashSet newCategories = new HashSet(); HashSet newCategories = new HashSet();
if (catIDs != null) { if (catIDs != null) {
@ -351,12 +351,12 @@ public class DocLink extends ContentPage implements Resource, Searchable {
s_log.debug("newCategories: "+catIDs[i]); s_log.debug("newCategories: "+catIDs[i]);
} }
} }
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,27 +366,27 @@ 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() {
// Returns language type of document. "eng" is english, (ISO 639-2) // Returns language type of document. "eng" is english, (ISO 639-2)
// If not English, should be overridden. // If not English, should be overridden.
return "eng"; return "eng";
} }
public String getSearchLinkText() { public String getSearchLinkText() {
return generateLinkName(getTarget()); return generateLinkName(getTarget());
} }
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

@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of * as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -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();
@ -75,19 +75,19 @@ public class RSSService {
public static RSSConfig getConfig() { public static RSSConfig getConfig() {
return s_config; return s_config;
} }
/** /**
* 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"));
boolean useESD = "laws-esd".equals(request.getParameter("extension")); boolean useESD = "laws-esd".equals(request.getParameter("extension"));
if (useESD) { if (useESD) {
useLAWs = true; useLAWs = true;
@ -95,36 +95,36 @@ 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/");
// 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");
// rdf is the root element // rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS); rdf.addNamespaceDeclaration(rssNS);
if (useLAWs) { if (useLAWs) {
rdf.addNamespaceDeclaration(dcNS); rdf.addNamespaceDeclaration(dcNS);
rdf.addNamespaceDeclaration(egmsNS); rdf.addNamespaceDeclaration(egmsNS);
@ -133,50 +133,50 @@ 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);
channelTitle.setText(cat.getName()); channelTitle.setText(cat.getName());
channel.addContent(channelTitle); channel.addContent(channelTitle);
if (useLAWs) { if (useLAWs) {
Element channelDCTitle = new Element("title", dcNS); Element channelDCTitle = new Element("title", dcNS);
channelDCTitle.setText(cat.getName()); channelDCTitle.setText(cat.getName());
channel.addContent(channelDCTitle); channel.addContent(channelDCTitle);
} }
Element channelLink = new Element("link", rssNS); Element channelLink = new Element("link", rssNS);
channelLink.setText((URL.there(request,null).getServerURI()).concat(URLService.locate(cat.getOID()))); channelLink.setText((URL.there(request,null).getServerURI()).concat(URLService.locate(cat.getOID())));
channel.addContent(channelLink); channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS); Element channelDescription = new Element("description", rssNS);
channelDescription.setText(cat.getDescription()); channelDescription.setText(cat.getDescription());
channel.addContent(channelDescription); channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS); Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems); channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS); Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq); channelItems.addContent(itemsSeq);
// Get and store a list of items. Items urls are added to the list in // 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 // the channel info, and a complete entry is added at the top level
// (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();
s_log.debug("item: " + item.getDisplayName()); s_log.debug("item: " + item.getDisplayName());
if (ContentItem.LIVE.equals(item.getVersion())) { if (ContentItem.LIVE.equals(item.getVersion())) {
items.add(new NewestFirstItem(item)); items.add(new NewestFirstItem(item));
} }
} }
Iterator iter = items.iterator(); Iterator iter = items.iterator();
int max = 10; int max = 10;
int current = 0; int current = 0;
@ -187,7 +187,7 @@ public class RSSService {
} }
NewestFirstItem itemWrapper = (NewestFirstItem) iter.next(); NewestFirstItem itemWrapper = (NewestFirstItem) iter.next();
ContentItem item = itemWrapper.getContentItem(); ContentItem item = itemWrapper.getContentItem();
String title; String title;
String description = ""; String description = "";
try { try {
@ -203,46 +203,46 @@ public class RSSService {
} catch (ClassCastException e) { } catch (ClassCastException e) {
title = item.getDisplayName(); title = item.getDisplayName();
} }
String itemURL = (URL.there(request,null).getServerURI()).concat(URLService.locate(item.getOID())); String itemURL = (URL.there(request,null).getServerURI()).concat(URLService.locate(item.getOID()));
s_log.debug("item is live"); s_log.debug("item is live");
// Add the element to the channel list // Add the element to the channel list
Element seqEl = new Element("li", rdfNS); Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", itemURL, rdfNS); seqEl.setAttribute("resource", itemURL, rdfNS);
itemsSeq.addContent(seqEl); itemsSeq.addContent(seqEl);
// Add the element to the top level // Add the element to the top level
Element itemEl = new Element("item", rssNS); Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", itemURL, rdfNS); itemEl.setAttribute("about", itemURL, rdfNS);
rdf.addContent(itemEl); rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS); Element titleEl = new Element("title", rssNS);
titleEl.setText(title); titleEl.setText(title);
itemEl.addContent(titleEl); itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS); Element linkEl = new Element("link", rssNS);
linkEl.setText(itemURL); linkEl.setText(itemURL);
itemEl.addContent(linkEl); itemEl.addContent(linkEl);
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);
} }
if (useLAWs) { if (useLAWs) {
Element dcTitleEl = new Element("title", dcNS); Element dcTitleEl = new Element("title", dcNS);
dcTitleEl.setText(title); dcTitleEl.setText(title);
itemEl.addContent(dcTitleEl); itemEl.addContent(dcTitleEl);
User creatorUser = item.getCreationUser(); User creatorUser = item.getCreationUser();
String creator = "Not specified"; String creator = "Not specified";
if (creatorUser != null) { if (creatorUser != null) {
@ -251,105 +251,105 @@ public class RSSService {
Element dcCreatorEl = new Element("creator", dcNS); Element dcCreatorEl = new Element("creator", dcNS);
dcCreatorEl.setText(creator); dcCreatorEl.setText(creator);
itemEl.addContent(dcCreatorEl); itemEl.addContent(dcCreatorEl);
Date dcDate = item.getCreationDate(); Date dcDate = item.getCreationDate();
String dcDateString = "Not specified"; String dcDateString = "Not specified";
if (dcDate != null) { if (dcDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dcDateString = sdf.format(dcDate); dcDateString = sdf.format(dcDate);
} }
Element dcDateEl = new Element("date", dcNS); Element dcDateEl = new Element("date", dcNS);
dcDateEl.setText(dcDateString); dcDateEl.setText(dcDateString);
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);
subjectCategoryEl.addContent(subjectBagEl); subjectCategoryEl.addContent(subjectBagEl);
Element liEl; Element liEl;
Element categoryEl; Element categoryEl;
Element rdfValueEl; 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: // LGCL categories for this item:
Domain lgclDomain = Domain.retrieve("LGCL"); Domain lgclDomain = Domain.retrieve("LGCL");
DomainCollection terms = lgclDomain.getTerms(); DomainCollection terms = lgclDomain.getTerms();
terms.addEqualsFilter("model.childObjects.id", item.getID()); terms.addEqualsFilter("model.childObjects.id", item.getID());
if (terms != null) { if (terms != null) {
DomainCollectionIterator it = DomainCollectionIterator it =
new DomainCollectionIterator(terms); new DomainCollectionIterator(terms);
while (it.hasNext()) { while (it.hasNext()) {
Term term = (Term) it.next(); Term term = (Term) it.next();
String name = term.getName(); String name = term.getName();
String urlName = toUpperCamel(name); String urlName = toUpperCamel(name);
liEl = new Element("li", rdfNS); liEl = new Element("li", rdfNS);
subjectBagEl.addContent(liEl); subjectBagEl.addContent(liEl);
categoryEl = new Element(urlName, lgclNS); categoryEl = new Element(urlName, lgclNS);
liEl.addContent(categoryEl); liEl.addContent(categoryEl);
rdfValueEl = new Element("value", rdfNS); rdfValueEl = new Element("value", rdfNS);
rdfValueEl.setText(name); rdfValueEl.setText(name);
categoryEl.addContent(rdfValueEl); categoryEl.addContent(rdfValueEl);
} }
} }
} }
} }
// Write XML to the output stream // Write XML to the output stream
Document doc = new Document(); Document doc = new Document();
if (getConfig().getPIxslt()!= null) { if (getConfig().getPIxslt()!= null) {
doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\"")); doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\""));
} }
doc.setRootElement(rdf); doc.setRootElement(rdf);
response.setContentType("text/xml; charset=UTF-8"); response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true); xmlOutput.setNewlines(true);
xmlOutput.setIndent(true); xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter()); xmlOutput.output(doc, response.getWriter());
} }
private static class NewestFirstItem implements Comparable { private static class NewestFirstItem implements Comparable {
private ContentItem m_item; private ContentItem m_item;
private BigDecimal m_liveID; private BigDecimal m_liveID;
public NewestFirstItem(ContentItem item) { public NewestFirstItem(ContentItem item) {
m_item = item; m_item = item;
m_liveID = item.getID(); m_liveID = item.getID();
} }
public ContentItem getContentItem() { public ContentItem getContentItem() {
return m_item; return m_item;
} }
public BigDecimal getLiveID() { public BigDecimal getLiveID() {
return m_liveID; return m_liveID;
} }
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");
} }
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if ((o instanceof NewestFirstItem)) { if ((o instanceof NewestFirstItem)) {
return m_item.equals(((NewestFirstItem) o).getContentItem()); return m_item.equals(((NewestFirstItem) o).getContentItem());
@ -358,54 +358,54 @@ 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/");
// rdf is the root element // rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS); rdf.addNamespaceDeclaration(rssNS);
// 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);
channelTitle.setText("Channel Index"); channelTitle.setText("Channel Index");
channel.addContent(channelTitle); channel.addContent(channelTitle);
Element channelLink = new Element("link", rssNS); Element channelLink = new Element("link", rssNS);
channelLink.setText(URL.here(request, "/rss/").getURL()); channelLink.setText(URL.here(request, "/rss/").getURL());
channel.addContent(channelLink); channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS); Element channelDescription = new Element("description", rssNS);
channelDescription.setText("The list of content feeds"); channelDescription.setText("The list of content feeds");
channel.addContent(channelDescription); channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS); Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems); channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS); Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq); channelItems.addContent(itemsSeq);
Map cats = Categorization.categorySubtreePath(root); Map cats = Categorization.categorySubtreePath(root);
s_log.debug("Get categories"); s_log.debug("Get categories");
Iterator i = cats.keySet().iterator(); Iterator i = cats.keySet().iterator();
@ -413,34 +413,34 @@ public class RSSService {
while (i.hasNext()) { while (i.hasNext()) {
String path = (String) i.next(); String path = (String) i.next();
Category cat = (Category) cats.get(path); Category cat = (Category) cats.get(path);
if (cat.getID().equals(root.getID())) { if (cat.getID().equals(root.getID())) {
continue; continue;
} }
s_log.debug("GOt sub cat " + path + " id " + cat.getID()); s_log.debug("GOt sub cat " + path + " id " + cat.getID());
ParameterMap params = new ParameterMap(); ParameterMap params = new ParameterMap();
params.setParameter("id", cat.getID()); params.setParameter("id", cat.getID());
URL url = URL.here(request, "/rss/channel.rss", params); URL url = URL.here(request, "/rss/channel.rss", params);
// Add the element to the channel list // Add the element to the channel list
Element seqEl = new Element("li", rdfNS); Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", url.getURL(), rdfNS); seqEl.setAttribute("resource", url.getURL(), rdfNS);
itemsSeq.addContent(seqEl); itemsSeq.addContent(seqEl);
// Add the element to the top level // Add the element to the top level
Element itemEl = new Element("item", rssNS); Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", url.getURL(), rdfNS); itemEl.setAttribute("about", url.getURL(), rdfNS);
rdf.addContent(itemEl); rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS); Element titleEl = new Element("title", rssNS);
titleEl.setText(path); titleEl.setText(path);
itemEl.addContent(titleEl); itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS); Element linkEl = new Element("link", rssNS);
linkEl.setText(url.getURL()); linkEl.setText(url.getURL());
itemEl.addContent(linkEl); itemEl.addContent(linkEl);
if (cat.getDescription() != null) { if (cat.getDescription() != null) {
Element descEl = new Element("description", rssNS); Element descEl = new Element("description", rssNS);
descEl.setText(cat.getDescription()); descEl.setText(cat.getDescription());
@ -448,128 +448,128 @@ public class RSSService {
} }
} }
s_log.debug("All done"); s_log.debug("All done");
// Write XML to the output stream // Write XML to the output stream
Document doc = new Document(rdf); Document doc = new Document(rdf);
response.setContentType("text/xml; charset=UTF-8"); response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true); xmlOutput.setNewlines(true);
xmlOutput.setIndent(true); xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter()); xmlOutput.output(doc, response.getWriter());
} }
/** /**
* 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/");
// rdf is the root element // rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI()); Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS); rdf.addNamespaceDeclaration(rssNS);
// 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);
channelTitle.setText("Channel Index"); channelTitle.setText("Channel Index");
channel.addContent(channelTitle); channel.addContent(channelTitle);
Element channelLink = new Element("link", rssNS); Element channelLink = new Element("link", rssNS);
channelLink.setText(URL.here(request, "/rss/").getURL()); channelLink.setText(URL.here(request, "/rss/").getURL());
channel.addContent(channelLink); channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS); Element channelDescription = new Element("description", rssNS);
channelDescription.setText("The list of server feeds"); channelDescription.setText("The list of server feeds");
channel.addContent(channelDescription); channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS); Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems); channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS); Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq); channelItems.addContent(itemsSeq);
FeedCollection feeds = Feed.retrieveAll(); FeedCollection feeds = Feed.retrieveAll();
feeds.filterACSJFeeds(acsj); feeds.filterACSJFeeds(acsj);
while (feeds.next()) { while (feeds.next()) {
Feed feed = feeds.getFeed(); Feed feed = feeds.getFeed();
// Add the element to the channel list // Add the element to the channel list
Element seqEl = new Element("li", rdfNS); Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", feed.getURL(), rdfNS); seqEl.setAttribute("resource", feed.getURL(), rdfNS);
itemsSeq.addContent(seqEl); itemsSeq.addContent(seqEl);
// Add the element to the top level // Add the element to the top level
Element itemEl = new Element("item", rssNS); Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", feed.getURL(), rdfNS); itemEl.setAttribute("about", feed.getURL(), rdfNS);
rdf.addContent(itemEl); rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS); Element titleEl = new Element("title", rssNS);
titleEl.setText(feed.getTitle()); titleEl.setText(feed.getTitle());
itemEl.addContent(titleEl); itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS); Element linkEl = new Element("link", rssNS);
linkEl.setText(feed.getURL()); linkEl.setText(feed.getURL());
itemEl.addContent(linkEl); itemEl.addContent(linkEl);
String desc = feed.getDescription(); String desc = feed.getDescription();
if (desc != null) { if (desc != null) {
Element descEl = new Element("description", rssNS); Element descEl = new Element("description", rssNS);
descEl.setText(desc); descEl.setText(desc);
itemEl.addContent(descEl); itemEl.addContent(descEl);
} }
} }
// Write XML to the output stream // Write XML to the output stream
Document doc = new Document(rdf); Document doc = new Document(rdf);
response.setContentType("text/xml; charset=UTF-8"); response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8"); XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true); xmlOutput.setNewlines(true);
xmlOutput.setIndent(true); xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter()); xmlOutput.output(doc, response.getWriter());
} }
public static String toUpperCamel(String termName) { public static String toUpperCamel(String termName) {
String upperCamel = ""; String upperCamel = "";
if (termName != null) { if (termName != null) {
StringTokenizer tokens = new StringTokenizer(termName); StringTokenizer tokens = new StringTokenizer(termName);
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
String word = tokens.nextToken(); String word = tokens.nextToken();
if (word.length() <= 1) { if (word.length() <= 1) {
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());
} }
} }
} }
return upperCamel; return upperCamel;
} }
} }