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

View File

@ -80,55 +80,55 @@ import javax.servlet.ServletException;
*/
public class FolderBrowser extends Table {
public static final String versionId =
"$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" +
"$Author: apevec $" +
"$DateTime: 2004/08/17 23:15:09 $";
"$Id: FolderBrowser.java 1540 2007-03-26 20:44:49Z apevec $" +
"$Author: apevec $" +
"$DateTime: 2004/08/17 23:15:09 $";
private static final Logger s_log = Logger.getLogger(FolderBrowser.class);
private static GlobalizedMessage[] s_headers = {
globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"),
globalize("cms.ui.folder.type"), globalize("cms.ui.folder.creation_date"),
globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action"),
globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action"),
globalize("cms.ui.folder.index") };
private static GlobalizedMessage[] s_noIndexHeaders = {
globalize("cms.ui.folder.name"), globalize("cms.ui.folder.title"),
globalize("cms.ui.folder.type"), globalize("cms.ui.folder.creation_date"),
globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action") };
globalize("cms.ui.folder.last_modified"), globalize("cms.ui.folder.action") };
private static final String SORT_ACTION_UP = "sortActionUp";
private static final String SORT_ACTION_DOWN = "sortActionDown";
private FolderSelectionModel m_currentFolder;
private TableActionListener m_folderChanger;
private TableActionListener m_deleter;
private TableActionListener m_indexChanger;
private TableColumn m_nameColumn;
private TableColumn m_deleteColumn;
private TableColumn m_indexColumn;
private final static String SORT_KEY_NAME = "name";
private final static String SORT_KEY_TITLE = "title";
private final static String SORT_KEY_LAST_MODIFIED_DATE = "lastModified";
private final static String SORT_KEY_CREATION_DATE = "creationDate";
private StringParameter m_sortType = new StringParameter("sortType");
private StringParameter m_sortDirection = new StringParameter("sortDirn");
public FolderBrowser(FolderSelectionModel currentFolder) {
//super(new FolderTableModelBuilder(), s_headers);
super();
m_sortType.setDefaultValue(SORT_KEY_NAME);
m_sortDirection.setDefaultValue(SORT_ACTION_UP);
setModelBuilder(new FolderTableModelBuilder(currentFolder));
setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers));
setHeader(new TableHeader(getColumnModel()));
m_sortType.setDefaultValue(SORT_KEY_NAME);
m_sortDirection.setDefaultValue(SORT_ACTION_UP);
setModelBuilder(new FolderTableModelBuilder(currentFolder));
setColumnModel(new DefaultTableColumnModel(hideIndexColumn() ? s_noIndexHeaders : s_headers));
setHeader(new TableHeader(getColumnModel()));
// DEE 1/18/02: the folder table model builder needs to know about
// 'this' in order to set visibility, but 'this' isn't available
// until after the super class' constructor has run, so we can't
@ -139,31 +139,31 @@ public class FolderBrowser extends Table {
// and pull the foldertablemodelbuilder back with the super class'
// accessor.
((FolderTableModelBuilder)getModelBuilder()).setFolderBrowser(this);
m_currentFolder = currentFolder;
/*
This code should be uncommented if the desired behaviour is for a change
of folder to cause reversion to default ordering of contained items
of folder to cause reversion to default ordering of contained items
(by name ascending). Our feeling is that the user selected ordering
should be retained for the duration of the folder browsing session. If
anyone wants this alternative behaviour it should be brought in under
anyone wants this alternative behaviour it should be brought in under
the control of a config parameter.
m_currentFolder.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
PageState state = e.getPageState();
state.setValue(m_sortType, m_sortType.getDefaultValue());
state.setValue(m_sortDirection, m_sortDirection.getDefaultValue());
}});
*/
public void stateChanged(ChangeEvent e) {
PageState state = e.getPageState();
state.setValue(m_sortType, m_sortType.getDefaultValue());
state.setValue(m_sortDirection, m_sortDirection.getDefaultValue());
}});
*/
setClassAttr("dataTable");
getHeader().setDefaultRenderer(new com.arsdigita.cms.ui.util.DefaultTableCellRenderer());
m_nameColumn = getColumn(0);
m_nameColumn.setCellRenderer(new NameCellRenderer());
m_nameColumn.setHeaderRenderer(new HeaderCellRenderer(SORT_KEY_NAME));
@ -177,50 +177,50 @@ public class FolderBrowser extends Table {
m_indexColumn = getColumn(6);
m_indexColumn.setCellRenderer(new IndexToggleRenderer());
m_indexColumn.setAlign("center");
m_indexChanger = new IndexChanger(m_currentFolder);
addTableActionListener(m_indexChanger);
}
m_folderChanger = new FolderChanger();
addTableActionListener(m_folderChanger);
m_deleter = new ItemDeleter();
addTableActionListener(m_deleter);
setEmptyView(new Label(globalize("cms.ui.folder.no_items")));
Assert.assertNotNull( m_currentFolder.getStateParameter() );
}
public void register(Page p) {
super.register(p);
p.addComponentStateParam(this, m_currentFolder.getStateParameter());
p.addComponentStateParam(this, m_sortType);
p.addComponentStateParam(this, m_sortDirection);
p.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final PageState state = e.getPageState();
if (state.isVisibleOnPage(FolderBrowser.this)) {
showHideFolderActions(state);
}
public void actionPerformed(ActionEvent e) {
final PageState state = e.getPageState();
if (state.isVisibleOnPage(FolderBrowser.this)) {
showHideFolderActions(state);
}
});
}
});
}
private void showHideFolderActions(PageState state) {
SecurityManager sm = Utilities.getSecurityManager(state);
Folder folder = (Folder) m_currentFolder.getSelectedObject(state);
Assert.assertNotNull(folder);
boolean canDelete =
sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder);
sm.canAccess(state.getRequest(), SecurityManager.DELETE_ITEM, folder);
m_deleteColumn.setVisible(state, canDelete);
}
public void respond(PageState state) throws ServletException {
String key = state.getControlEventName();
String value = state.getControlEventValue();
@ -228,30 +228,30 @@ public class FolderBrowser extends Table {
state.setValue(m_sortType, value);
state.setValue(m_sortDirection, SORT_ACTION_UP);
} else if ( SORT_ACTION_DOWN.equals(key) ) {
state.setValue(m_sortType, value);
state.setValue(m_sortType, value);
state.setValue(m_sortDirection, SORT_ACTION_DOWN);
} else {
super.respond(state);
//throw new ServletException("Unknown control event: " + key);
}
}
public FolderSelectionModel getFolderSelectionModel() {
return m_currentFolder;
}
private class FolderTableModelBuilder
extends AbstractTableModelBuilder implements PaginationModelBuilder {
extends AbstractTableModelBuilder implements PaginationModelBuilder {
private FolderSelectionModel m_folder;
private RequestLocal m_size;
private RequestLocal m_itemColl;
private FolderBrowser m_fb;
public FolderTableModelBuilder(FolderSelectionModel sel) {
this(sel, null);
}
public FolderTableModelBuilder(FolderSelectionModel sel, FolderBrowser fb) {
super();
m_folder = sel;
@ -259,7 +259,7 @@ public class FolderBrowser extends Table {
m_itemColl = new RequestLocal();
m_fb = fb;
}
public TableModel makeModel(Table t, PageState s) {
FolderSelectionModel sel = ((FolderBrowser) t).getFolderSelectionModel();
Folder f = (Folder) sel.getSelectedObject(s);
@ -268,68 +268,68 @@ public class FolderBrowser extends Table {
} else {
t.getRowSelectionModel().clearSelection(s);
return new FolderTableModel
((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s));
((FolderBrowser) t, s, (Folder.ItemCollection) m_itemColl.get(s));
}
}
public int getTotalSize(Paginator paginator, PageState state) {
Integer size = (Integer) m_size.get(state);
if (size == null) {
Folder f = (Folder) m_folder.getSelectedObject(state);
Folder.ItemCollection itemColl = f.getPrimaryInstances();
if (itemColl == null) {
return 0;
}
PermissionService.filterQuery(
itemColl,
"id",
PrivilegeDescriptor.READ,
Kernel.getContext().getParty().getOID()
);
itemColl,
"id",
PrivilegeDescriptor.READ,
Kernel.getContext().getParty().getOID()
);
size = new Integer( (int) f.getPrimaryInstances().size());
itemColl.setRange(new Integer(paginator.getFirst(state)),
new Integer(paginator.getLast(state) + 1));
new Integer(paginator.getLast(state) + 1));
String sortKey = (String)state.getValue(m_sortType);
String direction = "asc";
if (SORT_ACTION_DOWN.equals((String)state.getValue(m_sortDirection))) {
direction = "desc";
}
if ( sortKey.equals(SORT_KEY_TITLE) ) {
itemColl.setOrder("lower(item." +
ContentItem.DISPLAY_NAME + ") " +
direction);
ContentItem.DISPLAY_NAME + ") " +
direction);
} else if ( sortKey.equals(SORT_KEY_NAME) ) {
itemColl.setOrder("lower(item." +
ContentItem.NAME + ") " + direction);
ContentItem.NAME + ") " + direction);
} else if ( sortKey.equals(SORT_KEY_LAST_MODIFIED_DATE)) {
itemColl.setOrder("item.auditing.lastModifiedDate " +
direction);
direction);
} else if ( sortKey.equals(SORT_KEY_CREATION_DATE)) {
itemColl.setOrder("item.auditing.creationDate " +
direction);
direction);
}
m_size.set(state, size);
m_itemColl.set(state, itemColl);
}
return size.intValue();
}
public void setFolderBrowser(FolderBrowser fb) {
m_fb = fb;
}
/**
* Indicates whether the paginator should be visible,
* based on the visibility of the folder browser itself.
@ -341,55 +341,55 @@ public class FolderBrowser extends Table {
return (m_fb != null)?m_fb.isVisible(state):true;
}
}
private class HeaderCellRenderer
extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer {
extends com.arsdigita.cms.ui.util.DefaultTableCellRenderer {
private String m_key;
public HeaderCellRenderer(String key) {
super(true);
m_key = key;
}
public Component getComponent(final Table table, final PageState state,
Object value,
boolean isSelected, Object key,
int row, int column) {
Object value,
boolean isSelected, Object key,
int row, int column) {
String headerName = (String)((GlobalizedMessage)value).localize();
String sortKey = (String)state.getValue(m_sortType);
final boolean isCurrentKey = sortKey.equals(m_key);
final String currentSortDirection = (String)state.getValue(m_sortDirection);
String imageURLStub = null;
if (SORT_ACTION_UP.equals(currentSortDirection)) {
imageURLStub = "gray-triangle-up.gif";
} else {
imageURLStub = "gray-triangle-down.gif";
}
ControlLink cl = new ControlLink(headerName) {
public void setControlEvent(PageState ps) {
String sortDirectionAction = null;
// by default, everything sorts "up" unless it
// is the current key and it is already pointing up
if (SORT_ACTION_UP.equals(currentSortDirection) &&
public void setControlEvent(PageState ps) {
String sortDirectionAction = null;
// by default, everything sorts "up" unless it
// is the current key and it is already pointing up
if (SORT_ACTION_UP.equals(currentSortDirection) &&
isCurrentKey) {
sortDirectionAction = SORT_ACTION_DOWN;
} else {
sortDirectionAction = SORT_ACTION_UP;
}
ps.setControlEvent(table,
sortDirectionAction,
m_key);
sortDirectionAction = SORT_ACTION_DOWN;
} else {
sortDirectionAction = SORT_ACTION_UP;
}
};
ps.setControlEvent(table,
sortDirectionAction,
m_key);
}
};
Label l = new Label();
l.setLabel("<font color=\"blue\">" + headerName + "</font>");
l.setOutputEscaping(false);
l.setFontWeight(Label.BOLD);
SimpleContainer container = new SimpleContainer();
container.add(l);
if ( isCurrentKey ) {
@ -401,7 +401,7 @@ public class FolderBrowser extends Table {
return cl;
}
}
/**
* Produce links to view an item or control links for folders
* to change into the folder.
@ -410,49 +410,49 @@ public class FolderBrowser extends Table {
public NameCellRenderer() {
super(true);
}
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
boolean isSelected, Object key,
int row, int column) {
Folder.ItemCollection coll = (Folder.ItemCollection) value;
String name = coll.getName();
if ( coll.isFolder() ) {
return super.getComponent(table, state, name,
isSelected, key, row, column);
isSelected, key, row, column);
} else {
ContentSection section = CMS.getContext().getContentSection();
BigDecimal id = coll.getID();
if (section == null) {
return new Label(name);
} else {
ItemResolver resolver = section.getItemResolver();
return new Link(name, resolver.generateItemURL
(state, id, name, section, coll.getVersion()));
(state, id, name, section, coll.getVersion()));
}
}
}
}
/**
* Produce delete links for items and non-empty folders.
*/
private static class ActionCellRenderer implements TableCellRenderer {
private static Label s_noAction;
private static ControlLink s_link;
static {
s_noAction = new Label("&nbsp;", false);
s_noAction.lock();
s_link = new ControlLink(new Label(globalize("cms.ui.folder.delete")));
s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ?
}
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
boolean isSelected, Object key,
int row, int column) {
if ( ((Boolean) value).booleanValue() ) {
return s_link;
} else {
@ -460,42 +460,42 @@ public class FolderBrowser extends Table {
}
}
}
private final class IndexToggleRenderer implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) {
if ( value == null ) {
return new Label(GlobalizationUtil.globalize("cms.ui.folder.na"));
}
ControlLink link = new ControlLink("");
if (((Boolean) value).booleanValue()) {
link.setClassAttr("checkBoxChecked");
} else {
link.setClassAttr("checkBoxUnchecked");
}
return link;
}
}
// Deletes an item
private class ItemDeleter extends TableActionAdapter {
public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue();
if ( m_deleteColumn != getColumn(col) ) {
return;
}
PageState s = e.getPageState();
BigDecimal id = new BigDecimal(e.getRowKey().toString());
OID oid = new OID(ContentItem.BASE_DATA_OBJECT_TYPE, id.abs());
final DomainObject item = DomainObjectFactory.newInstance(oid);
if (item != null) {
if (item instanceof ContentBundle) {
ContentBundle bundle = (ContentBundle) item;
@ -506,11 +506,11 @@ public class FolderBrowser extends Table {
}
item.delete();
}
((Table) e.getSource()).clearSelection(s);
}
}
/**
* Table model around ItemCollection
*/
@ -522,24 +522,24 @@ public class FolderBrowser extends Table {
private static final int LAST_MODIFIED = 4;
private static final int DELETABLE = 5;
private static final int IS_INDEX = 6;
private PageState m_state;
private FolderBrowser m_table;
private Folder.ItemCollection m_itemColl;
private Folder m_fol;
private BigDecimal m_folIndexID;
//old constructor before using paginator
//public FolderTableModel(Folder folder) {
//m_itemColl = folder.getItems();
//}
public FolderTableModel
(FolderBrowser table, PageState state, Folder.ItemCollection itemColl) {
(FolderBrowser table, PageState state, Folder.ItemCollection itemColl) {
m_state = state;
m_table = table;
m_itemColl = itemColl;
m_fol = (Folder) table.getFolderSelectionModel().getSelectedObject(state);
if (!hideIndexColumn()) {
ContentBundle indexItem = m_fol.getIndexItem();
@ -550,83 +550,83 @@ public class FolderBrowser extends Table {
}
}
}
public int getColumnCount() {
return hideIndexColumn() ? 6 : 7;
}
public boolean nextRow() {
return m_itemColl.next();
}
public Object getElementAt(int columnIndex) {
switch (columnIndex) {
case NAME:
return m_itemColl;
case TITLE:
return m_itemColl.getDisplayName();
case TYPE:
return m_itemColl.getTypeLabel();
case CREATION_DATE: {
java.util.Date creationDate = m_itemColl.getCreationDate();
if ( creationDate == null ) {
return "--";
case NAME:
return m_itemColl;
case TITLE:
return m_itemColl.getDisplayName();
case TYPE:
return m_itemColl.getTypeLabel();
case CREATION_DATE: {
java.util.Date creationDate = m_itemColl.getCreationDate();
if ( creationDate == null ) {
return "--";
}
return FormatStandards.formatDate(creationDate);
}
return FormatStandards.formatDate(creationDate);
}
case LAST_MODIFIED: {
java.util.Date lastModified = m_itemColl.getLastModifiedDate();
if ( lastModified == null ) {
return "--";
case LAST_MODIFIED: {
java.util.Date lastModified = m_itemColl.getLastModifiedDate();
if ( lastModified == null ) {
return "--";
}
return FormatStandards.formatDate(lastModified);
}
return FormatStandards.formatDate(lastModified);
}
case DELETABLE:
return new Boolean(isDeletable());
case IS_INDEX: {
if (hideIndexColumn()) {
case DELETABLE:
return new Boolean(isDeletable());
case IS_INDEX: {
if (hideIndexColumn()) {
throw new IndexOutOfBoundsException("Column index " + columnIndex +
" not in table model.");
}
if ( m_itemColl.isFolder() ) {
return null;
}
if ( m_folIndexID == null ) {
return new Boolean(false);
}
return new Boolean(m_folIndexID
.compareTo(m_itemColl.getBundleID()) == 0);
}
default:
throw new IndexOutOfBoundsException("Column index " + columnIndex +
" not in table model.");
}
if ( m_itemColl.isFolder() ) {
return null;
}
if ( m_folIndexID == null ) {
return new Boolean(false);
}
return new Boolean(m_folIndexID
.compareTo(m_itemColl.getBundleID()) == 0);
}
default:
throw new IndexOutOfBoundsException("Column index " + columnIndex +
" not in table model.");
" not in table model.");
}
}
public boolean isDeletable() {
if (s_log.isDebugEnabled()) {
s_log.debug("Checking to see if " + this + " is deletable");
}
if (m_itemColl.isLive()) {
if (s_log.isDebugEnabled()) {
s_log.debug("The item is live; it cannot be deleted");
}
return false;
}
if (m_itemColl.isFolder()) {
if (!m_itemColl.hasChildren()) {
if (s_log.isDebugEnabled()) {
s_log.debug("The item is an empty folder; it may be " +
"deleted");
"deleted");
}
return true;
} else {
if (s_log.isDebugEnabled()) {
s_log.debug("The folder is not empty; it cannot be " +
"deleted");
"deleted");
}
return false;
}
@ -634,23 +634,23 @@ public class FolderBrowser extends Table {
if (s_log.isDebugEnabled()) {
s_log.debug("The item is not a folder; it may be deleted");
}
return true;
}
}
public Object getKeyAt(int columnIndex) {
// Mark folders by using their negative ID (dirty, dirty)
return ( m_itemColl.isFolder() ) ? m_itemColl.getID().negate()
: m_itemColl.getBundleID();
: m_itemColl.getBundleID();
}
}
private class FolderChanger extends TableActionAdapter {
public void cellSelected(TableActionEvent e) {
PageState s = e.getPageState();
int col = e.getColumn().intValue();
if ( m_nameColumn != getColumn(col) ) {
return;
}
@ -661,29 +661,29 @@ public class FolderBrowser extends Table {
}
}
}
private class IndexChanger extends TableActionAdapter {
private FolderSelectionModel m_fol;
public IndexChanger(FolderSelectionModel fol) {
super();
m_fol = fol;
}
public void cellSelected(TableActionEvent e) {
PageState state = e.getPageState();
BigDecimal rowkey = new BigDecimal((String)e.getRowKey());
if (rowkey == null){
return;
}
try {
ContentBundle contentItem = new ContentBundle(rowkey);
Folder folder = (Folder) m_fol.getSelectedObject(state);
ContentBundle currentIndexItem = (ContentBundle) folder.getIndexItem();
if ( currentIndexItem == null || (currentIndexItem.getID().compareTo(contentItem.getID()) != 0)) {
folder.setIndexItem(contentItem);
@ -696,7 +696,7 @@ public class FolderBrowser extends Table {
}
}
}
/**
* Getting the GlobalizedMessage using a CMS Class targetBundle.
*
@ -706,7 +706,7 @@ public class FolderBrowser extends Table {
private static GlobalizedMessage globalize(String key) {
return FolderManipulator.globalize(key);
}
private static boolean hideIndexColumn() {
return ContentSection.getConfig().getHideFolderIndexCheckbox();
}

View File

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

View File

@ -21,6 +21,7 @@ package com.arsdigita.london.atoz;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.OID;
@ -58,7 +59,11 @@ public class AtoZItemGenerator extends AbstractAtoZGenerator {
bundle = new ContentBundle(new BigDecimal(entries.get("id")
.toString()));
if (bundle != null) {
item = bundle.getPrimaryInstance();
/* Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* item = bundle.getPrimaryInstance(); */
item = bundle.negotiate(DispatcherHelper.getRequest().getLocales());
if (item != null) {
// this is necessary because aliases refer to the non-live
// version,

View File

@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -64,7 +64,7 @@ import com.arsdigita.kernel.User;
*/
public class RSSService {
private static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(RSSService.class);
org.apache.log4j.Logger.getLogger(RSSService.class);
private static final RSSConfig s_config = new RSSConfig();
@ -75,19 +75,19 @@ public class RSSService {
public static RSSConfig getConfig() {
return s_config;
}
/**
* Generates an RSS channel for a specified category and and all of its Articles.
*/
public static void generateChannel(
BigDecimal categoryId,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
BigDecimal categoryId,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Category cat = new Category(categoryId);
boolean useLAWs = "laws-1.0".equals(request.getParameter("extension"));
boolean useESD = "laws-esd".equals(request.getParameter("extension"));
if (useESD) {
useLAWs = true;
@ -95,36 +95,36 @@ public class RSSService {
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// The following namespaces are declared for the possible
// The following namespaces are declared for the possible
// use of the LAWS extension
Namespace dcNS =
Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace egmsNS = null;
if (useESD) {
egmsNS =
Namespace.getNamespace(
Namespace.getNamespace(
"esd",
"http://www.esd.org.uk/standards/esd/3.0/esd.rdfs");
} else {
egmsNS =
Namespace.getNamespace(
Namespace.getNamespace(
"egms",
"http://www.esd.org.uk/standards/egms/3.0/egms.rdfs");
}
Namespace lgclNS =
Namespace.getNamespace(
Namespace.getNamespace(
"lgcl",
"http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs");
// rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS);
if (useLAWs) {
rdf.addNamespaceDeclaration(dcNS);
rdf.addNamespaceDeclaration(egmsNS);
@ -133,50 +133,50 @@ public class RSSService {
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
channelTitle.setText(cat.getName());
channel.addContent(channelTitle);
if (useLAWs) {
Element channelDCTitle = new Element("title", dcNS);
channelDCTitle.setText(cat.getName());
channel.addContent(channelDCTitle);
}
Element channelLink = new Element("link", rssNS);
channelLink.setText((URL.there(request,null).getServerURI()).concat(URLService.locate(cat.getOID())));
channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS);
channelDescription.setText(cat.getDescription());
channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq);
// Get and store a list of items. Items urls are added to the list in
// the channel info, and a complete entry is added at the top level
// (below rdf)
SortedSet items = new TreeSet();
CategorizedCollection objects =
cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
while (objects.next()) {
ContentItem item = (ContentItem) objects.getACSObject();
s_log.debug("item: " + item.getDisplayName());
if (ContentItem.LIVE.equals(item.getVersion())) {
items.add(new NewestFirstItem(item));
}
}
Iterator iter = items.iterator();
int max = 10;
int current = 0;
@ -187,7 +187,7 @@ public class RSSService {
}
NewestFirstItem itemWrapper = (NewestFirstItem) iter.next();
ContentItem item = itemWrapper.getContentItem();
String title;
String description = "";
try {
@ -203,46 +203,46 @@ public class RSSService {
} catch (ClassCastException e) {
title = item.getDisplayName();
}
String itemURL = (URL.there(request,null).getServerURI()).concat(URLService.locate(item.getOID()));
s_log.debug("item is live");
// Add the element to the channel list
Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", itemURL, rdfNS);
itemsSeq.addContent(seqEl);
// Add the element to the top level
Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", itemURL, rdfNS);
rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS);
titleEl.setText(title);
itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS);
linkEl.setText(itemURL);
itemEl.addContent(linkEl);
if (description != null) {
Element descEl = new Element("description", rssNS);
descEl.setText(
com.arsdigita.util.StringUtils.truncateString(
com.arsdigita.util.StringUtils.truncateString(
description,
100,
true)
+ "...");
+ "...");
itemEl.addContent(descEl);
}
if (useLAWs) {
Element dcTitleEl = new Element("title", dcNS);
dcTitleEl.setText(title);
itemEl.addContent(dcTitleEl);
User creatorUser = item.getCreationUser();
String creator = "Not specified";
if (creatorUser != null) {
@ -251,105 +251,105 @@ public class RSSService {
Element dcCreatorEl = new Element("creator", dcNS);
dcCreatorEl.setText(creator);
itemEl.addContent(dcCreatorEl);
Date dcDate = item.getCreationDate();
String dcDateString = "Not specified";
if (dcDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dcDateString = sdf.format(dcDate);
}
Element dcDateEl = new Element("date", dcNS);
dcDateEl.setText(dcDateString);
itemEl.addContent(dcDateEl);
Element subjectCategoryEl =
new Element("subjectCategory", egmsNS);
new Element("subjectCategory", egmsNS);
itemEl.addContent(subjectCategoryEl);
Element subjectBagEl = new Element("Bag", rdfNS);
subjectCategoryEl.addContent(subjectBagEl);
Element liEl;
Element categoryEl;
Element rdfValueEl;
// OK now we are going to see if we can find any
// OK now we are going to see if we can find any
// LGCL categories for this item:
Domain lgclDomain = Domain.retrieve("LGCL");
DomainCollection terms = lgclDomain.getTerms();
terms.addEqualsFilter("model.childObjects.id", item.getID());
if (terms != null) {
DomainCollectionIterator it =
new DomainCollectionIterator(terms);
new DomainCollectionIterator(terms);
while (it.hasNext()) {
Term term = (Term) it.next();
String name = term.getName();
String urlName = toUpperCamel(name);
liEl = new Element("li", rdfNS);
subjectBagEl.addContent(liEl);
categoryEl = new Element(urlName, lgclNS);
liEl.addContent(categoryEl);
rdfValueEl = new Element("value", rdfNS);
rdfValueEl.setText(name);
categoryEl.addContent(rdfValueEl);
}
}
}
}
// Write XML to the output stream
Document doc = new Document();
if (getConfig().getPIxslt()!= null) {
doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\""));
}
doc.setRootElement(rdf);
response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true);
xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter());
}
private static class NewestFirstItem implements Comparable {
private ContentItem m_item;
private BigDecimal m_liveID;
public NewestFirstItem(ContentItem item) {
m_item = item;
m_liveID = item.getID();
}
public ContentItem getContentItem() {
return m_item;
}
public BigDecimal getLiveID() {
return m_liveID;
}
public int compareTo(Object o) {
if ((o instanceof NewestFirstItem)) {
return
- 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
- 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
} else {
throw new ClassCastException("Must compare to NewestFirstItem");
}
}
public boolean equals(Object o) {
if ((o instanceof NewestFirstItem)) {
return m_item.equals(((NewestFirstItem) o).getContentItem());
@ -358,54 +358,54 @@ public class RSSService {
}
}
}
/**
* Generates an RSS channel for a specified category purpose
*/
public static void generateChannelList(
Category root,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Category root,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS);
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
channelTitle.setText("Channel Index");
channel.addContent(channelTitle);
Element channelLink = new Element("link", rssNS);
channelLink.setText(URL.here(request, "/rss/").getURL());
channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS);
channelDescription.setText("The list of content feeds");
channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq);
Map cats = Categorization.categorySubtreePath(root);
s_log.debug("Get categories");
Iterator i = cats.keySet().iterator();
@ -413,34 +413,34 @@ public class RSSService {
while (i.hasNext()) {
String path = (String) i.next();
Category cat = (Category) cats.get(path);
if (cat.getID().equals(root.getID())) {
continue;
}
s_log.debug("GOt sub cat " + path + " id " + cat.getID());
ParameterMap params = new ParameterMap();
params.setParameter("id", cat.getID());
URL url = URL.here(request, "/rss/channel.rss", params);
// Add the element to the channel list
Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", url.getURL(), rdfNS);
itemsSeq.addContent(seqEl);
// Add the element to the top level
Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", url.getURL(), rdfNS);
rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS);
titleEl.setText(path);
itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS);
linkEl.setText(url.getURL());
itemEl.addContent(linkEl);
if (cat.getDescription() != null) {
Element descEl = new Element("description", rssNS);
descEl.setText(cat.getDescription());
@ -448,128 +448,128 @@ public class RSSService {
}
}
s_log.debug("All done");
// Write XML to the output stream
Document doc = new Document(rdf);
response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true);
xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter());
}
/**
* Generates an RSS channel for a specified category and and all of its Articles.
*/
public static void generateFeedList(
boolean acsj,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
boolean acsj,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
rdf.addNamespaceDeclaration(rssNS);
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
channelTitle.setText("Channel Index");
channel.addContent(channelTitle);
Element channelLink = new Element("link", rssNS);
channelLink.setText(URL.here(request, "/rss/").getURL());
channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS);
channelDescription.setText("The list of server feeds");
channel.addContent(channelDescription);
Element channelItems = new Element("items", rssNS);
channel.addContent(channelItems);
Element itemsSeq = new Element("Seq", rdfNS);
channelItems.addContent(itemsSeq);
FeedCollection feeds = Feed.retrieveAll();
feeds.filterACSJFeeds(acsj);
while (feeds.next()) {
Feed feed = feeds.getFeed();
// Add the element to the channel list
Element seqEl = new Element("li", rdfNS);
seqEl.setAttribute("resource", feed.getURL(), rdfNS);
itemsSeq.addContent(seqEl);
// Add the element to the top level
Element itemEl = new Element("item", rssNS);
itemEl.setAttribute("about", feed.getURL(), rdfNS);
rdf.addContent(itemEl);
Element titleEl = new Element("title", rssNS);
titleEl.setText(feed.getTitle());
itemEl.addContent(titleEl);
Element linkEl = new Element("link", rssNS);
linkEl.setText(feed.getURL());
itemEl.addContent(linkEl);
String desc = feed.getDescription();
if (desc != null) {
Element descEl = new Element("description", rssNS);
descEl.setText(desc);
itemEl.addContent(descEl);
}
}
// Write XML to the output stream
Document doc = new Document(rdf);
response.setContentType("text/xml; charset=UTF-8");
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
xmlOutput.setNewlines(true);
xmlOutput.setIndent(true);
xmlOutput.output(doc, response.getWriter());
}
public static String toUpperCamel(String termName) {
String upperCamel = "";
if (termName != null) {
StringTokenizer tokens = new StringTokenizer(termName);
while (tokens.hasMoreTokens()) {
String word = tokens.nextToken();
if (word.length() <= 1) {
upperCamel += word.toUpperCase();
} else {
upperCamel += word.substring(0, 1).toUpperCase()
+ word.substring(1, word.length());
+ word.substring(1, word.length());
}
}
}
return upperCamel;
}
}