GenericArticleImageAssociation

Dieses Ding scheint der alte Code zu sein, aus einer Zeit bevor es das ReusableImageAsset gab. Da wird nur noch das ReusableImageAsset verwenden wollen, wird der alter Code nicht mehr benötigt.

Dazu gehört eigentlich auch eine Änderung der GenericArticle.pdl, die ich noch nicht eingecheckt habe, damit wir die Änderungen testen können, bevor wir ein Update der DB durchführen.

git-svn-id: https://svn.libreccm.org/ccm/trunk@640 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-12-01 16:16:42 +00:00
parent c88e3819e0
commit 8539b1852b
14 changed files with 63 additions and 2075 deletions

View File

@ -18,16 +18,10 @@
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ImageAssetCollection;
import com.arsdigita.cms.TextPage;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert;
import java.math.BigDecimal;
@ -43,10 +37,6 @@ public class GenericArticle extends TextPage {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.GenericArticle";
protected static final String IMAGES = "imageAssets";
private static final String IMAGE_CAPTIONS = "imageCaptions";
private static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(GenericArticle.class);
@ -98,101 +88,4 @@ public class GenericArticle extends TextPage {
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
/**
* Add an image to this article. If the image is already added
* to the article, the caption will be updated.
*
* @param image the image to add
* @param caption the caption for the image
* @return true if image is added and false if caption is updated
*/
public boolean addImage(ImageAsset image, String caption) {
ImageAssetCollection col = getImages();
col.addEqualsFilter(GenericArticleImageAssociation.IMAGE_ID,image.getID());
boolean toReturn = false;
GenericArticleImageAssociation assn = null;
if (col.next()) {
assn = (GenericArticleImageAssociation)(col.getDomainObject());
col.close();
} else {
assn = new GenericArticleImageAssociation();
String name = this.getName();
Assert.exists(name, String.class);
String imgName = image.getName();
Assert.exists(imgName, String.class);
assn.setName(name + "/" + imgName);
assn.setArticle(this);
assn.setImage(image);
toReturn = true;
assn.setMaster(this);
}
assn.setCaption(caption);
assn.save();
return toReturn;
}
/**
* Get the caption of the image
* @deprecated Do not use this method, it will always return the
* first available caption regardless of what image is in use. Use
* GenericArticleImageAssnCollection.getCaption() or
* GenericArticleImageAssociation.getCaption().
* @return the caption, or null if the image is not associated to this
* article
*/
public String getCaption(ImageAsset image) {
DataCollection col = (DataCollection)get(IMAGE_CAPTIONS);
String caption = null;
if (col.next()) {
caption = (String)col.getDataObject().get("caption");
}
col.close();
return caption;
}
/**
* Remove a image from this article.
* @return true is the image is removed, false otherwise.
*/
public boolean removeImage(ImageAsset image) {
GenericArticleImageAssociation assn = GenericArticleImageAssociation
.retrieveAssociation(getID(), image.getID());
if (assn != null) {
assn.delete();
return true;
} else {
return false;
}
}
/**
* Get the images for this article
*/
public ImageAssetCollection getImages() {
DataAssociationCursor dac = ((DataAssociation) get(IMAGE_CAPTIONS)).cursor();
ImageAssetCollection images = new GenericArticleImageAssnCollection(dac);
return images;
}
/**
* Unassociate all images from this article
*/
public void clearImages() {
ImageAssetCollection images = getImages();
while(images.next()) {
images.getDomainObject().delete();
}
}
@Override
protected void propagateMaster(com.arsdigita.versioning.VersionedACSObject master) {
super.propagateMaster(master);
ImageAssetCollection collection = getImages();
while (collection.next()) {
GenericArticleImageAssociation assn = (GenericArticleImageAssociation)(collection.getDomainObject());
assn.setMaster(master);
assn.save();
}
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ImageAssetCollection;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.Filter;
/**
* This class contains contains a collection of ArticleImageAssociations, each
* of which points to an image, and each of which has a caption. Ideally it
* should be constructed with a DataCollection of ArticleImageAssociations
* which has been filtered on isDeleted=0, or there will be deleted associations
* in the collection. It extends ImageAssetCollection because we need to pass
* it off as an ImageAssetCollection at various places in the UI code.
*
* @see com.arsdigita.domain.DomainCollection
* @see com.arsdigita.persistence.DataCollection
*
*
* @author Hugh Brock .
* @version $Id: GenericArticleImageAssnCollection.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class GenericArticleImageAssnCollection extends ImageAssetCollection {
/**
* Constructor. Should only be called from Article.getImages()
*
**/
protected GenericArticleImageAssnCollection(DataCollection dataCollection) {
super(dataCollection);
}
/**
* Returns a <code>DomainObject</code> (the
* GenericArticleImageAssociation for the current position in the
* collection.
*
**/
public DomainObject getDomainObject() {
return new GenericArticleImageAssociation
(m_dataCollection.getDataObject());
}
/**
* Returns a <code>Image</code> for the current position in
* the collection.
*
**/
public ImageAsset getImage() {
return ((GenericArticleImageAssociation)getDomainObject()).getImage();
}
public String getCaption() {
return ((GenericArticleImageAssociation)getDomainObject()).getCaption();
}
// Exposed methods
public Filter addEqualsFilter(String attribute, Object value) {
return m_dataCollection.addEqualsFilter(attribute, value);
}
}

View File

@ -1,260 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.CustomCopy;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemCollection;
import com.arsdigita.cms.ItemCopier;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.util.Assert;
import com.arsdigita.versioning.VersionedACSObject;
import java.math.BigDecimal;
/**
* This class associates an GenericArticle and an Image with a particular
* caption.
*
* @author Jack Chung (flattop@arsdigita.com)
* @version $Revision: #17 $ $Date: 2004/08/17 $
* @version $Id: GenericArticleImageAssociation.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class GenericArticleImageAssociation extends ContentItem {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.GenericArticleImageAssociation";
protected static final String ARTICLE = "captionArticle";
protected static final String IMAGE = "imageAsset";
protected static final String CAPTION = "caption";
protected static final String ARTICLE_ID = "articleId";
protected static final String IMAGE_ID = "imageId";
/**
* Default constructor.
**/
public GenericArticleImageAssociation() {
super(BASE_DATA_OBJECT_TYPE);
}
/**
* Constructor retrieves the contained <code>DataObject</code> from the
* persistent storage mechanism with an <code>OID</code> specified by
* <i>oid</i>.
*
* @param oid The <code>OID</code> for the retrieved
* <code>DataObject</code>.
**/
public GenericArticleImageAssociation(OID oid) throws DataObjectNotFoundException {
super(oid);
}
public GenericArticleImageAssociation(DataObject obj) {
super(obj);
}
public GenericArticleImageAssociation(String type) {
super(type);
}
/**
* This returns the association object that is specified by
* the passed in IDs or it returns null if no such association exists
*/
public static GenericArticleImageAssociation retrieveAssociation
(BigDecimal articleID, BigDecimal imageID) {
DataCollection collection = SessionManager.getSession().retrieve
(BASE_DATA_OBJECT_TYPE);
collection.addEqualsFilter(ARTICLE_ID, articleID);
collection.addEqualsFilter(IMAGE_ID, imageID);
// no deleted associations, please
collection.addEqualsFilter(VersionedACSObject.IS_DELETED, new BigDecimal(0));
if (collection.next()) {
GenericArticleImageAssociation association =
new GenericArticleImageAssociation(collection.getDataObject());
collection.close();
return association;
}
return null;
}
/**
* This returns true if the image is associated with at least one article.
*/
public static boolean imageHasDirectAssociation
(BigDecimal imageID) {
DataCollection collection = SessionManager.getSession().retrieve
(BASE_DATA_OBJECT_TYPE);
collection.addEqualsFilter(IMAGE_ID, imageID);
// no deleted associations, please
collection.addEqualsFilter(VersionedACSObject.IS_DELETED, new BigDecimal(0));
if (collection.next()) {
collection.close();
return true;
}
return false;
}
/**
* This returns true if the image is associated with at least one article.
*/
public static boolean imageHasAssociation
(BigDecimal imageID) {
try {
ImageAsset asset = (ImageAsset) DomainObjectFactory.newInstance
(new OID(ImageAsset.BASE_DATA_OBJECT_TYPE, imageID));
return asset == null ? false : imageHasAssociation(asset);
} catch (DataObjectNotFoundException e) {
// can't find asset, return false
return false;
}
}
/**
* This returns true if the image is associated with at least one article, checking both liveand draft versions
*/
public static boolean imageHasAssociation
(ImageAsset image) {
Assert.exists(image);
boolean returnValue = imageHasDirectAssociation(image.getID());
if (!returnValue) {
if (!image.getVersion().equals(ContentItem.DRAFT)) {
ContentItem item = image.getWorkingVersion();
if (item != null) {
returnValue = imageHasDirectAssociation(item.getID());
}
}
}
if (!returnValue) {
if (!image.getVersion().equals(ContentItem.PENDING)) {
ItemCollection pendingVersions = image.getPendingVersions();
while(pendingVersions.next()) {
ContentItem item = pendingVersions.getContentItem();
returnValue = returnValue || imageHasDirectAssociation(item.getID());
}
}
}
if (!returnValue) {
if (!image.getVersion().equals(ContentItem.LIVE)) {
ContentItem item = image.getLiveVersion();
if (item != null) {
returnValue = imageHasDirectAssociation(item.getID());
}
}
}
DataCollection collection = SessionManager.getSession().retrieve
(BASE_DATA_OBJECT_TYPE);
collection.addEqualsFilter(IMAGE_ID, image.getID());
// no deleted associations, please
collection.addEqualsFilter(VersionedACSObject.IS_DELETED, new BigDecimal(0));
if (collection.next()) {
collection.close();
return true;
}
return false;
}
public BigDecimal getArticleID() {
return (BigDecimal) get(ARTICLE_ID);
}
public GenericArticle getArticle() {
DataCollection col = SessionManager.getSession().retrieve(ARTICLE);
if (col.next()) {
GenericArticle art = new GenericArticle(col.getDataObject());
col.close();
return art;
}
return null;
}
public void setArticle(GenericArticle article) {
setAssociation(ARTICLE, article);
}
public BigDecimal getImageID() {
return (BigDecimal) get(IMAGE_ID);
}
public ImageAsset getImage() {
return (ImageAsset) DomainObjectFactory.
newInstance((DataObject) get(IMAGE));
}
public void setImage(ImageAsset image) {
setAssociation(IMAGE, image);
}
public String getCaption() {
return (String) get(CAPTION);
}
public void setCaption(String caption) {
set(CAPTION, caption);
}
/**
* Auto-publish the associated ReusableImageAssociation if it is not yet live
*
* @param source the source CustomCopy item
* @param property the property to copy
* @param copier a temporary class that is able to copy a child item
* correctly.
* @return true if the property was copied; false to indicate
* that regular metadata-driven methods should be used
* to copy the property.
*/
@Override
public boolean copyProperty(final CustomCopy source,
final Property property,
final ItemCopier copier) {
String attribute = property.getName();
// don't copy these attributes. they're controlled by explicit associations
if (IMAGE_ID.equals(attribute) || ARTICLE_ID.equals(attribute)) {
return true;
}
if (copier.getCopyType() == ItemCopier.VERSION_COPY
&& IMAGE.equals(attribute)) {
ImageAsset image = ((GenericArticleImageAssociation)source).getImage();
if (image != null) {
ImageAsset liveImage = (ImageAsset) image.getLiveVersion();
if (liveImage == null) {
liveImage = (ImageAsset) image.createLiveVersion();
}
}
// This method only makes sure that the ReusableImageAsset
// is auto-published. It still returns false so that the
// copier can generate PublishedLink objects appropriately.
return false;
}
return super.copyProperty(source, property, copier);
}
}

View File

@ -1,108 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleComponent;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
/**
* Displays a single ImageAsset, showing its image, width, height,
* name and mime-type. If the ImageAsset in the selection model is null,
* be nice about it.
*
* @author Hugh Brock (hbrock@redhat.com)
* @version $Id: ImageDisplay.java 1967 2009-08-29 21:05:51Z pboy $
*/
public class ImageDisplay extends SimpleComponent {
private final ItemSelectionModel m_item;
/**
* Construct a new ImageDisplay
*
* @param m The {@link ItemSelectionModel} which will supply
* this component with the {@link ImageAsset}
*/
public ImageDisplay(ItemSelectionModel m) {
super();
m_item = m;
}
/**
* @return the {@link ItemSelectionModel} which supplies this
* component with the {@link ImageAsset}
*/
public final ItemSelectionModel getImageSelectionModel() {
return m_item;
}
public void generateXML(PageState state, Element parent) {
if ( isVisible(state) ) {
ImageAsset image = getImageAsset(state);
if (image != null) {
Element element = new Element("cms:imageDisplay", CMS.CMS_XML_NS);
generateImagePropertiesXML(image, state, element);
exportAttributes(element);
parent.addContent(element);
}
}
}
protected void generateImagePropertiesXML(ImageAsset image,
PageState state,
Element element) {
element.addAttribute("name", image.getName());
element.addAttribute("src", Utilities.getImageURL(image));
BigDecimal width = image.getWidth();
if ( width != null ) {
element.addAttribute("width", width.toString());
}
BigDecimal height = image.getHeight();
if ( height != null ) {
element.addAttribute("height", height.toString());
}
MimeType mimeType = image.getMimeType();
if ( mimeType != null ) {
element.addAttribute("mime_type", mimeType.getLabel());
}
}
protected ImageAsset getImageAsset(PageState state) {
ImageAsset image = (ImageAsset) m_item.getSelectedObject(state);
return image;
}
}

View File

@ -21,13 +21,10 @@ package com.arsdigita.cms.dispatcher;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ImageAssetCollection;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.dispatcher.RequestContext;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.toolbox.ui.OIDParameter;
import com.arsdigita.versioning.Transaction;
@ -150,19 +147,6 @@ public class StreamImage extends ResourceHandlerImpl {
"no ImageAsset with oid " + oid);
return;
}
} else {
ImageAssetCollection col = article.getImages();
col.addEqualsFilter(ACSObject.ID, imageId);
if (col.next()) {
image = col.getImage();
col.close();
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
"failed to retrieve ImageAsset " + imageId);
return;
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element;
/**
* Extends {@link ImageDisplay} to display the first
* (according to the order attribute) image associated with an {@link GenericArticle}
* The typical usage for this component is
* <blockquote><pre><code>ArticleImageDisplay d = new ArticleImageDisplay(myItemSelectionModel, false);</code></pre></blockquote>
* <p>
*
* @version $Revision: #8 $ $DateTime: 2004/08/17 23:15:09 $
* @author Michael Pih (pihman@arsdigita.com)
* @author Stanislav Freidin (stas@arsdigita.com)
* @version $Id: ArticleImageDisplay.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ArticleImageDisplay extends ImageDisplay {
private final ItemSelectionModel m_article;
/**
* Construct a new <code>ArticleImageDisplay</code>
*
* @param article the {@link ItemSelectionModel} which
* supplies the {@link GenericArticle}
*
* @param assets the {@link ItemSelectionModel} which
* supplies the {@link ImageAsset} for the article; it is
* the parent's responsibility to register any state parameters
* for this model
*/
public ArticleImageDisplay(ItemSelectionModel article,
ItemSelectionModel assets) {
super(assets);
m_article = article;
}
/**
* @return The item selection model which supplies the
* current article
*/
public final ItemSelectionModel getArticleSelectionModel() {
return m_article;
}
/**
* @param state The page state
* @return the currently selected article
* @post ( return != null )
*/
protected GenericArticle getArticle(PageState state) {
GenericArticle article = (GenericArticle) m_article.getSelectedObject(state);
Assert.exists(article, "GenericArticle");
return article;
}
/**
* Adds the image caption as an attribute of the DOM element.
*/
protected void generateImagePropertiesXML(ImageAsset image,
PageState state,
Element element) {
super.generateImagePropertiesXML(image, state, element);
GenericArticle article = getArticle(state);
String caption = article.getCaption(image);
if ( caption != null ) {
element.addAttribute("caption", caption);
}
}
}

View File

@ -30,7 +30,6 @@ import com.arsdigita.bebop.table.DefaultTableCellRenderer;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.contenttypes.GenericArticleImageAssociation;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.Utilities;
@ -66,9 +65,7 @@ import org.apache.log4j.Logger;
public class ImageBrowser extends Table {
private ImageBrowserModelBuilder m_builder;
private static final String[] HEADERS =
{"Thumbnail", "Name", "Size", "Type", "Action", ""};
private static final String[] HEADERS = {"Thumbnail", "Name", "Size", "Type", "Action", ""};
private static final int THUMB = 0;
private static final int NAME = 1;
private static final int SIZE = 2;
@ -76,9 +73,7 @@ public class ImageBrowser extends Table {
private static final int LINK = 4;
private static final int DELETE = 5;
private static final int NUM_COLUMNS = 6;
private int m_thumbSize;
private static final Logger s_log = Logger.getLogger(ImageBrowser.class);
/**
@ -134,7 +129,7 @@ public class ImageBrowser extends Table {
* request
*/
public ImageBrowserModel getImageBrowserModel(PageState state) {
return ((ImageModelAdapter)getTableModel(state)).getModel();
return ((ImageModelAdapter) getTableModel(state)).getModel();
}
/**
@ -143,18 +138,19 @@ public class ImageBrowser extends Table {
* linkClicked method.
*/
public static abstract class LinkActionListener
extends TableActionAdapter {
extends TableActionAdapter {
public void cellSelected(TableActionEvent e) {
int c = e.getColumn().intValue();
if(c == LINK) {
linkClicked(e.getPageState(), new BigDecimal((String)e.getRowKey()));
} else if (c==DELETE) {
deleteClicked(e.getPageState(), new BigDecimal((String)e.getRowKey()));
if (c == LINK) {
linkClicked(e.getPageState(), new BigDecimal((String) e.getRowKey()));
} else if (c == DELETE) {
deleteClicked(e.getPageState(), new BigDecimal((String) e.getRowKey()));
}
}
public abstract void linkClicked(PageState state, BigDecimal imageId);
public abstract void deleteClicked(PageState state, BigDecimal imageId);
}
@ -162,9 +158,9 @@ public class ImageBrowser extends Table {
private class ThumbnailCellRenderer implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
ImageAsset a = (ImageAsset)value;
boolean isSelected, Object key,
int row, int column) {
ImageAsset a = (ImageAsset) value;
String url = Utilities.getImageURL(a);
Image img = new Image(URL.getDispatcherPath() + url);
@ -178,11 +174,10 @@ public class ImageBrowser extends Table {
w = m_thumbSize;
h = m_thumbSize;
} else {
Dimension d = ImageSizer.getScaledSize (
width.intValue(), height.intValue(), m_thumbSize, m_thumbSize
);
w = (int)d.getWidth();
h = (int)d.getHeight();
Dimension d = ImageSizer.getScaledSize(
width.intValue(), height.intValue(), m_thumbSize, m_thumbSize);
w = (int) d.getWidth();
h = (int) d.getHeight();
}
img.setWidth(Integer.toString(w));
@ -195,22 +190,24 @@ public class ImageBrowser extends Table {
// Renders the delete link if the user has permission to delete
// the asset and it's not used in an article.
private class DeleteCellRenderer extends DefaultTableCellRenderer {
public DeleteCellRenderer() {
super(true);
}
@Override
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) {
boolean canDelete = false;
SecurityManager sm = Utilities.getSecurityManager(state);
if (sm.canAccess(state.getRequest(),SecurityManager.DELETE_IMAGES) ) {
if (sm.canAccess(state.getRequest(), SecurityManager.DELETE_IMAGES)) {
try {
ImageAsset asset = (ImageAsset) DomainObjectFactory.newInstance
(new OID(ImageAsset.BASE_DATA_OBJECT_TYPE,(BigDecimal) key));
if (!GenericArticleImageAssociation.imageHasAssociation(asset)) {
canDelete = true;
}
ImageAsset asset = (ImageAsset) DomainObjectFactory.newInstance(new OID(ImageAsset.BASE_DATA_OBJECT_TYPE, (BigDecimal) key));
//XXX Find a new way to figure out, if this image is used by any CI so we can decide if it can be deleted
// if (!GenericArticleImageAssociation.imageHasAssociation(asset)) {
// canDelete = true;
// }
} catch (DataObjectNotFoundException e) {
// can't find asset, can't delete it
}
@ -223,13 +220,11 @@ public class ImageBrowser extends Table {
return new Label("");
}
}
}
// Converts an ImageBrowserModelBuilder to a TableModelBuilder
private static class BuilderAdapter extends LockableImpl
implements TableModelBuilder {
implements TableModelBuilder {
private ImageBrowserModelBuilder m_builder;
@ -239,10 +234,10 @@ public class ImageBrowser extends Table {
public TableModel makeModel(Table t, PageState s) {
return new ImageModelAdapter(
m_builder.makeModel((ImageBrowser)t, s)
);
m_builder.makeModel((ImageBrowser) t, s));
}
@Override
public void lock() {
m_builder.lock();
super.lock();
@ -269,40 +264,50 @@ public class ImageBrowser extends Table {
public Object getElementAt(int columnIndex) {
ImageAsset a = m_model.getImageAsset();
switch(columnIndex) {
case ImageBrowser.THUMB:
return a;
switch (columnIndex) {
case ImageBrowser.THUMB:
return a;
case ImageBrowser.NAME:
return a.getName();
case ImageBrowser.NAME:
return a.getName();
case ImageBrowser.SIZE:
StringBuffer buf = new StringBuffer();
BigDecimal v;
case ImageBrowser.SIZE:
StringBuilder buf = new StringBuilder();
BigDecimal v;
v = a.getWidth();
if(v == null) buf.append("???"); else buf.append(v.toString());
buf.append(" x ");
v = a.getWidth();
if (v == null) {
buf.append("???");
} else {
buf.append(v.toString());
}
buf.append(" x ");
v = a.getHeight();
if(v == null) buf.append("???"); else buf.append(v.toString());
v = a.getHeight();
if (v == null) {
buf.append("???");
} else {
buf.append(v.toString());
}
return buf.toString();
return buf.toString();
case ImageBrowser.TYPE:
MimeType m = a.getMimeType();
if(m == null) return "???";
case ImageBrowser.TYPE:
MimeType m = a.getMimeType();
if (m == null) {
return "???";
}
return m.getMimeType();
return m.getMimeType();
case ImageBrowser.LINK:
return "select";
case ImageBrowser.LINK:
return "select";
case ImageBrowser.DELETE:
return "delete";
case ImageBrowser.DELETE:
return "delete";
default:
return null;
default:
return null;
}
}
@ -314,5 +319,4 @@ public class ImageBrowser extends Table {
return m_model;
}
}
}

View File

@ -1,161 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ImageAssetCollection;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.domain.DomainObject;
/**
* Selects a single image for an article.
*
* @see com.arsdigita.cms.ui.authoring.ArticleImage
* @see com.arsdigita.cms.ui.ArticleImageDisplay
*
* @version $Id: SingleImageSelectionModel.java 287 2005-02-22 00:29:02Z sskracic $
* @author <a href="mailto:sfreidin@arsdigita.com">Stanislav Freidin</a>
*/
public class SingleImageSelectionModel extends ItemSelectionModel {
private ItemSelectionModel m_articleModel;
/**
* Construct a new <code>SingleImageSelectionModel</code>
*
* @param javaClass the Java class name of the {@link ImageAsset} subclass
* that this model deals with
* @param objetcType the PDL object type of the {@link ImageAsset} subclass
* that this model deals with
* @param param the {@link BigDecimalParameter} where the image ID will
* be stored
* @param articleModel the {@link ItemSelectionModel} which will supply
* the current article
*/
public SingleImageSelectionModel(
String javaClass, String objectType, BigDecimalParameter param,
ItemSelectionModel articleModel
) {
this(javaClass, objectType, new ParameterSingleSelectionModel(param),
articleModel);
}
/**
* Construct a new <code>SingleImageSelectionModel</code>
*
* @param javaClass the Java class name of the {@link ImageAsset} subclass
* that this model deals with
* @param objetcType the PDL object type of the {@link ImageAsset} subclass
* that this model deals with
* @param imageModel the {@link SingleSelectionModel} which will store the
* image ID
* @param articleModel the {@link ItemSelectionModel} which will supply
* the current article
*/
public SingleImageSelectionModel(
String javaClass, String objectType, SingleSelectionModel imageModel,
ItemSelectionModel articleModel
) {
super(javaClass, objectType, imageModel);
m_articleModel = articleModel;
}
/**
* Construct a new <code>SingleImageSelectionModel</code>
*
* @param imageModel the {@link SingleSelectionModel} which will store the
* image ID
* @param articleModel the {@link ItemSelectionModel} which will supply
* the current article
*/
public SingleImageSelectionModel(
SingleSelectionModel imageModel, ItemSelectionModel articleModel
) {
this(ImageAsset.class.getName(), ImageAsset.BASE_DATA_OBJECT_TYPE,
imageModel, articleModel);
}
/**
* Construct a new <code>SingleImageSelectionModel</code>
*
* @param param the {@link BigDecimalParameter} where the image ID will
* be stored
*
* @param articleModel the {@link ItemSelectionModel} which will supply
* the current article
*/
public SingleImageSelectionModel(
BigDecimalParameter param, ItemSelectionModel articleModel
) {
this(ImageAsset.class.getName(), ImageAsset.BASE_DATA_OBJECT_TYPE,
param, articleModel);
}
// Load the first asset for the article, if neccessary.
private void checkAsset(PageState state) {
if ( !isInitialized(state) ) {
// Load the object from the item.
com.arsdigita.cms.ContentItem temp =
(com.arsdigita.cms.ContentItem)m_articleModel.getSelectedObject(state);
GenericArticle item = null;
if ( temp != null ) {
item =
(GenericArticle) com.arsdigita.cms.ACSObjectFactory.castContentItem(temp);
}
if ( item != null ) {
ImageAssetCollection images = item.getImages();
if ( images.next() ) {
setSelectedObject(state, images.getImage());
images.close();
}
}
}
}
/**
* Get the currently selected image. If no image is selected,
* select the first image for the article.
*/
public DomainObject getSelectedObject(PageState state) {
checkAsset(state);
return super.getSelectedObject(state);
}
/**
* Get the id of the currently selected image
*/
public Object getSelectedKey(PageState state) {
checkAsset(state);
return super.getSelectedKey(state);
}
/**
* @return the {@link ItemSelectionModel} which supplies the article
*/
public ItemSelectionModel getArticleSelectionModel() {
return m_articleModel;
}
}

View File

@ -1,432 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ImageAssetCollection;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.ui.ArticleImageDisplay;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.cms.ui.ImageChooser;
import com.arsdigita.cms.ui.SecurityPropertyEditor;
import com.arsdigita.cms.ui.SingleImageSelectionModel;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element;
import org.apache.log4j.Logger;
/**
* Display the image associated with the article (if any),
* and present UI controls for associating a new image.
* This component contains two {@link PropertyEditor}
* instances: one instance that shows up when the article has
* no associated image, and another instance that shows up when
* the article has at least one image.
* <p>
* This class actually contains four inner classes:
* <ul>
* <li>ImageUploadForm: a form for uploading a new image</li>
* <li>ImagePropertiesForm: a form for editing width/height/caption</li>
* <li>ArticleImagePane: an {@link com.arsdigita.cms.ui.ItemPropertySheet}
* which displays the properties of an image</li>
* <li>ArticleImageChooser: a {@link SimpleComponent} that contains
* an {@link ImageChooser} and an <code>ImageSelectionForm</code> (which
* is another inner class). The <code>ArticleImageChooser</code>
* uses the {@link ImageChooser} to select an image, then shows the
* form in order to assign a caption to the image and complete the
* image selection process.
* </li>
* </ul>
*
* @author Stanislav Freidin (sfreidin@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @version $Revision: #20 $ $DateTime: 2004/08/17 23:15:09 $
* @version $Id: ArticleImage.java 754 2005-09-02 13:26:17Z sskracic $
*/
public class ArticleImage extends SimpleContainer implements AuthoringStepComponent {
private static final String IMAGE_ASSET = "image_asset";
private static Logger s_log = Logger.getLogger(ArticleImage.class);
private final ItemSelectionModel m_article;
private final AuthoringKitWizard m_parent;
private SingleImageSelectionModel m_assets;
private BigDecimalParameter m_assetParam;
private ArticleWithoutImage m_noImagePane;
private ArticleImageChooser m_noImageChooser;
private ArticleWithImage m_imagePane;
private ArticleImageChooser m_imageChooser;
private StringParameter m_streamlinedCreationParam;
private static final String STREAMLINED = "_streamlined";
private static final String STREAMLINED_DONE = "1";
public ArticleImage(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
super();
m_parent = parent;
m_article = itemModel;
m_streamlinedCreationParam =
new StringParameter(parent.getContentType().getAssociatedObjectType() + "_image_done");
// Add the asset selection model
m_assetParam = new BigDecimalParameter(IMAGE_ASSET);
m_assets = new SingleImageSelectionModel(m_assetParam, m_article);
// This panel will be shown if there is no image selected.
m_noImagePane = new ArticleWithoutImage(m_article, m_assets);
m_noImageChooser = m_noImagePane.getChooser();
final ImageSelectionForm noImageForm = m_noImageChooser.getImageSelectionForm();
noImageForm.addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent event)
throws FormProcessException {
PageState state = event.getPageState();
m_imagePane.showDisplayPane(state);
maybeForwardToNextStep(state);
}
});
noImageForm.addSubmissionListener(new FormSubmissionListener() {
public void submitted(FormSectionEvent event) throws FormProcessException {
PageState state = event.getPageState();
if (noImageForm.getSaveCancelSection().getCancelButton()
.isSelected( state)) {
cancelStreamlinedCreation(state);
}
}
});
add(m_noImagePane);
m_imagePane = new ArticleWithImage(m_article, m_assets);
m_imageChooser = m_imagePane.getChooser();
final ImageSelectionForm imageForm = m_imageChooser.getImageSelectionForm();
imageForm.addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent event)
throws FormProcessException {
PageState state = event.getPageState();
m_imagePane.showDisplayPane(state);
maybeForwardToNextStep(state);
}
});
// Reset state of all sub-components
m_imagePane.getList().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PageState state = e.getPageState();
m_imageChooser.deselectImage(state);
m_imageChooser.getImageChooser().clearKeyword(state);
m_noImageChooser.deselectImage(state);
m_noImageChooser.getImageChooser().clearKeyword(state);
}
});
imageForm.addSubmissionListener(new FormSubmissionListener() {
public void submitted(FormSectionEvent event) throws FormProcessException {
PageState state = event.getPageState();
if (imageForm.getSaveCancelSection().getCancelButton()
.isSelected( state)) {
cancelStreamlinedCreation(state);
}
}
});
add(m_imagePane);
// Reset the editing when this component becomes visible
parent.getList().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
PageState state = event.getPageState();
// get the image fresh from the db each time this component displays;
// otherwise rollback doesn't appear to work on this pane
GenericArticle art = (GenericArticle)(m_article.getSelectedObject(state));
ImageAssetCollection col = art.getImages();
ImageAsset img = null;
if (col.next()) {
img = col.getImage();
}
col.close();
m_assets.setSelectedObject(state, img);
m_imagePane.showDisplayPane(state);
m_imageChooser.deselectImage(state);
m_noImageChooser.deselectImage(state);
}
});
}
// Create the image chooser
private ArticleImageChooser addChooser(SecurityPropertyEditor e) {
ArticleImageChooser c = new ArticleImageChooser(m_article, m_assets);
c.getImageSelectionForm().addProcessListener(
new FormProcessListener() {
public void process(FormSectionEvent param_e) throws FormProcessException {
m_imagePane.showDisplayPane(param_e.getPageState());
}
});
ImageChooser ch = c.getImageChooser();
e.addCancelListener(ch.getForm(), ch.getFormCancelButton());
e.addComponent("browse", "Select existing image",
new WorkflowLockedComponentAccess(c,m_article));
return c;
}
// Register the image id
public void register(Page p) {
p.addComponentStateParam(this, m_assetParam);
p.addGlobalStateParam(m_streamlinedCreationParam);
}
// Generate XML: Show either the image pane or the no image pane
public void generateXML(PageState state, Element parent) {
if(m_assets.getSelectedObject(state) == null) {
m_noImagePane.generateXML(state, parent);
} else {
m_imagePane.generateXML(state, parent);
}
}
/**
* @return the parent wizard
*/
public AuthoringKitWizard getParentWizard() {
return m_parent;
}
/**
* @return The item selection model
*/
public ItemSelectionModel getItemSelectionModel() {
return m_article;
}
/**
* Forward to the next step if the streamlined creation parameter
* is turned on _and_ the streamlined_creation global state param
* is set to 'active'
*
* @param state the PageState
*/
public void maybeForwardToNextStep(PageState state) {
if (ContentItemPage.isStreamlinedCreationActive(state) &&
!STREAMLINED_DONE.equals(state.getValue(m_streamlinedCreationParam))) {
state.setValue(m_streamlinedCreationParam, STREAMLINED_DONE);
fireCompletionEvent(state);
}
}
/**
* Cancel streamlined creation for this step if the streamlined
* creation parameter is turned on _and_ the streamlined_creation
* global state param is set to 'active'
*
* @param state the PageState
*/
public void cancelStreamlinedCreation(PageState state) {
if (ContentItemPage.isStreamlinedCreationActive(state)) {
state.setValue(m_streamlinedCreationParam, STREAMLINED_DONE);
}
}
private class ArticleWithoutImage extends SecurityPropertyEditor {
private final ItemSelectionModel m_articleWithoutImage;
private final ItemSelectionModel m_assetsWithoutImage;
private ImageUploadForm m_uploadFormWithoutImage;
private ArticleImageChooser m_chooserWithoutImage;
public ArticleWithoutImage(ItemSelectionModel article,
ItemSelectionModel assets) {
super();
m_articleWithoutImage = article;
m_assetsWithoutImage = assets;
Label l = new Label(GlobalizationUtil.globalize("cms.ui.authoring.this_article_does_not_have_an_image"));
l.setFontWeight(Label.ITALIC);
setDisplayComponent(l);
m_uploadFormWithoutImage = new ImageUploadForm(m_articleWithoutImage,
m_assetsWithoutImage,
ArticleImage.this);
add("upload", "Upload a new image",
new WorkflowLockedComponentAccess(m_uploadFormWithoutImage, m_articleWithoutImage),
m_uploadFormWithoutImage.getSaveCancelSection().getCancelButton());
m_chooserWithoutImage = new ArticleImageChooser(m_articleWithoutImage, m_assetsWithoutImage);
ImageChooser imgChooser = m_chooserWithoutImage.getImageChooser();
addCancelListener(imgChooser.getForm(),
imgChooser.getFormCancelButton());
addComponent("browse", "Select existing image",
new WorkflowLockedComponentAccess(m_chooserWithoutImage, m_articleWithoutImage));
}
public ArticleImageChooser getChooser() {
return m_chooserWithoutImage;
}
}
private class ArticleWithImage extends SecurityPropertyEditor {
private final ItemSelectionModel m_articleWithImage;
private final ItemSelectionModel m_assetsWithImage;
private CMSContainer m_display;
private ActionLink m_editLink;
private ActionLink m_uploadLink;
private ActionLink m_selectLink;
private ActionLink m_removeLink;
private ImageUploadForm m_uploadFormWithImage;
private ImagePropertiesForm m_editFormWithImage;
private ArticleImageChooser m_chooserWithImage;
public ArticleWithImage(ItemSelectionModel article,
ItemSelectionModel assets) {
super();
m_articleWithImage = article;
m_assetsWithImage = assets;
// This panel will be shown if there is an image.
m_display = new CMSContainer();
m_display.add(new ArticleImageDisplay(m_articleWithImage, m_assetsWithImage));
// The "edit caption" link.
m_editLink = new ActionLink( (String) GlobalizationUtil.globalize("cms.ui.authoring.edit_caption").localize());
m_editLink.setClassAttr("actionLink");
m_editLink.setIdAttr("edit_link");
m_display.add(new WorkflowLockedContainer(m_editLink, m_articleWithImage));
// The "upload image" link.
m_uploadLink = new ActionLink( (String) GlobalizationUtil.globalize("cms.ui.authoring.upload_a_new_image").localize());
m_uploadLink.setClassAttr("actionLink");
m_uploadLink.setIdAttr("upload_link");
m_display.add(new WorkflowLockedContainer(m_uploadLink, m_articleWithImage));
// The "select a new image" link.
m_selectLink = new ActionLink( (String) GlobalizationUtil.globalize("cms.ui.authoring.select_an_existing_image").localize());
m_selectLink.setClassAttr("actionLink");
m_selectLink.setIdAttr("select_link");
m_display.add(new WorkflowLockedContainer(m_selectLink, m_articleWithImage));
// The "remove image" link.
m_removeLink = new ActionLink( (String) GlobalizationUtil.globalize("cms.ui.authoring.remove_image").localize());
m_removeLink.setClassAttr("actionLink");
m_removeLink.setIdAttr("remove_image_link");
m_removeLink.setConfirmation("Are you sure you wish to " +
"remove this image from the article?");
m_removeLink.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
PageState state = event.getPageState();
ImageAsset img = getImageAsset(state);
GenericArticle articleTarget = getArticle(state);
articleTarget.removeImage(img);
articleTarget.save();
m_assetsWithImage.setSelectedObject(state, null);
m_imageChooser.deselectImage(state);
m_imageChooser.getImageChooser().clearKeyword(state);
m_noImageChooser.deselectImage(state);
m_noImageChooser.getImageChooser().clearKeyword(state);
m_noImagePane.showDisplayPane(event.getPageState());
Utilities.disableBrowserCache(state.getResponse());
}
});
m_display.add(new WorkflowLockedContainer(m_removeLink, m_articleWithImage));
setDisplayComponent(m_display);
// The edit form.
m_editFormWithImage = new ImagePropertiesForm(m_articleWithImage, m_assetsWithImage);
addComponent("edit",
new WorkflowLockedComponentAccess(m_editFormWithImage, m_articleWithImage));
addListeners(m_editFormWithImage,
m_editFormWithImage.getSaveCancelSection().getCancelButton());
addVisibilityListener(m_editLink, "edit");
// The upload form.
m_uploadFormWithImage = new ImageUploadForm(m_articleWithImage,
m_assetsWithImage,
ArticleImage.this);
addComponent("upload",
new WorkflowLockedComponentAccess(m_uploadFormWithImage, m_articleWithImage));
addListeners(m_uploadFormWithImage,
m_uploadFormWithImage.getSaveCancelSection().getCancelButton());
addVisibilityListener(m_uploadLink, "upload");
// The select form.
m_chooserWithImage = new ArticleImageChooser(m_articleWithImage, m_assetsWithImage);
ImageChooser imgChooser = m_chooserWithImage.getImageChooser();
addCancelListener(imgChooser.getForm(),
imgChooser.getFormCancelButton());
addComponent("browse",
new WorkflowLockedComponentAccess(m_chooserWithImage, m_articleWithImage));
addVisibilityListener(m_selectLink, "browse");
}
public ArticleImageChooser getChooser() {
return m_chooserWithImage;
}
private ImageAsset getImageAsset(PageState state) {
ImageAsset image = (ImageAsset) m_assetsWithImage.getSelectedObject(state);
Assert.exists(image, "Image asset");
return image;
}
private GenericArticle getArticle(PageState state) {
GenericArticle article = (GenericArticle) m_articleWithImage.getSelectedObject(state);
Assert.exists(article, "GenericArticle");
return article;
}
}
}

View File

@ -1,202 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.contenttypes.GenericArticleImageAssociation;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemCollection;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.ui.ImageBrowser;
import com.arsdigita.cms.ui.ImageChooser;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.OID;
import org.apache.log4j.Logger;
import java.math.BigDecimal;
/**
* A component that can assign an existing image to an article.
* Consists of an ImageChooser and an ImageSelectionForm
*
* @author Stanislav Freidin
* @author Michael Pih
* @version $Revision: #12 $ $DateTime: 2004/08/17 23:15:09 $
* @version $Id: ArticleImageChooser.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ArticleImageChooser extends SimpleContainer {
public static final String CHOSEN_IMAGE = "chim";
private static Logger s_log =
Logger.getLogger(ArticleImageChooser.class);
private final ItemSelectionModel m_assets;
private final ItemSelectionModel m_choiceModel;
private ImageChooser m_chooser;
private ImageSelectionForm m_form;
private BigDecimalParameter m_chosenImage;
/**
* Construct a new ArticleImageChooser
*/
public ArticleImageChooser(ItemSelectionModel itemModel,
ItemSelectionModel assetModel) {
super();
m_assets = assetModel;
m_chooser = new ImageChooser();
add(m_chooser);
// Show the form when an image is clicked
m_chooser.addImageActionListener(new ImageBrowser.LinkActionListener() {
public void linkClicked(PageState state, BigDecimal imageId) {
s_log.debug("SELECTING: " + imageId);
selectImage(state, imageId);
}
public void deleteClicked(PageState state, BigDecimal imageId) {
s_log.debug("DELETING: " + imageId);
deleteImage(state, imageId);
}
});
// Clone the asset model, since we don't want to contaminate
// the original data in case the user decides to cancel the
// form submission
m_chosenImage = new BigDecimalParameter(CHOSEN_IMAGE);
ContentType t = assetModel.getContentType();
if ( t == null ) {
m_choiceModel =
new ItemSelectionModel(assetModel.getJavaClass().getName(),
assetModel.getObjectType(),
m_chosenImage);
} else {
m_choiceModel =
new ItemSelectionModel(assetModel.getContentType(), m_chosenImage);
}
m_form = new ImageSelectionForm(itemModel, m_choiceModel);
// Hide the form again when the user clicks Cancel
m_form.addSubmissionListener(new FormSubmissionListener() {
public void submitted(FormSectionEvent e) throws FormProcessException {
PageState state = e.getPageState();
if(m_form.getSaveCancelSection().getCancelButton().isSelected(state)) {
deselectImage(state);
throw new FormProcessException( (String) GlobalizationUtil.globalize("cms.ui.authoring.submission_cancelled").localize());
}
}
});
// Propagate the image selection on success
m_form.addProcessListener(new FormProcessListener() {
public void process(FormSectionEvent e) throws FormProcessException {
PageState state = e.getPageState();
m_assets.setSelectedObject(state,
m_choiceModel.getSelectedObject(state));
}
});
add(m_form);
}
// Hide the form by default, register the "chosen image" parameter
public void register(Page p) {
p.addComponentStateParam(this, m_chosenImage);
p.setVisibleDefault(m_form, false);
}
/**
* @return the image selection form
*/
public ImageSelectionForm getImageSelectionForm() {
return m_form;
}
/**
* @return the image chooser
*/
public ImageChooser getImageChooser() {
return m_chooser;
}
/**
* Select the specified image and show the form
*/
public void selectImage(PageState s, BigDecimal imageId) {
s.setVisible(m_form, true);
s.setVisible(m_chooser, false);
m_choiceModel.setSelectedKey(s, imageId);
}
/**
* Select the specified image and show the form
*/
public void deleteImage(PageState s, BigDecimal imageId) {
SecurityManager sm = Utilities.getSecurityManager(s);
if (sm.canAccess(s.getRequest(),SecurityManager.DELETE_IMAGES) ) {
try {
ImageAsset asset = (ImageAsset) DomainObjectFactory.newInstance
(new OID(ImageAsset.BASE_DATA_OBJECT_TYPE,imageId));
if (!GenericArticleImageAssociation.imageHasAssociation(asset)) {
asset.setLive(null);
ItemCollection pendingVersions = asset.getPendingVersions();
while(pendingVersions.next()) {
ContentItem item = pendingVersions.getContentItem();
asset.removePendingVersion(item);
}
asset.delete();
}
} catch (DataObjectNotFoundException e) {
// can't find asset, don't delete
}
}
}
/**
* Deselect the image and hide the form
*/
public void deselectImage(PageState s) {
s.setVisible(m_form, false);
s.setVisible(m_chooser, true);
m_choiceModel.clearSelection(s);
m_chooser.clearSelection(s);
}
}

View File

@ -1,206 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.util.GlobalizationUtil;
/**
* A form for modifying a single image asset attached to the article.
* This is just a convenience class; children should override
* the addWidgets, init and process methods.
*
* @version $Id: BasicImageForm.java 287 2005-02-22 00:29:02Z sskracic $
*/
public abstract class BasicImageForm extends Form
implements FormInitListener, FormProcessListener {
private ItemSelectionModel m_itemModel, m_assetModel;
private SaveCancelSection m_saveCancelSection;
public static final String CAPTION = "caption";
/**
* Construct a new BasicImageForm
*
* @param formName The name for this form
*
* @param itemModel The {@link ItemSelectionModel} which will
* be responsible for loading the current item
*
* @param assetModel The {@link ItemSelectionModel} which will
* be responsible for loading the current image asset
*/
public BasicImageForm(String formName,
ItemSelectionModel itemModel, ItemSelectionModel assetModel
) {
super(formName, new ColumnPanel(2));
m_itemModel = itemModel;
m_assetModel = assetModel;
ColumnPanel panel = (ColumnPanel)getPanel();
panel.setBorder(false);
panel.setPadColor("#FFFFFF");
panel.setColumnWidth(1, "20%");
panel.setColumnWidth(2, "80%");
panel.setWidth("2%");
addWidgets();
m_saveCancelSection = new SaveCancelSection();
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
addInitListener(this);
addProcessListener(this);
}
/**
* Add various widgets to the form. Child classes should override
* this method to perform all their widget-adding needs
*/
protected void addWidgets() {
add(new Label(GlobalizationUtil.globalize("cms.ui.authoring.caption")));
// WAI requires all images to maintain ALT attribute
// aplaws ticket 14026
StringParameter captionParam = new StringParameter(CAPTION);
captionParam.addParameterListener(new NotNullValidationListener());
TextField captionWidget = new TextField(captionParam);
add(captionWidget);
}
/**
* Perform form initialization. Children should override this
* this method to pre-fill the widgets with data, instantiate
* the content item, etc.
*/
public abstract void init(FormSectionEvent e) throws FormProcessException;
/**
* Process the form. Children should override this method to save
* the user's changes to the database.
*/
public abstract void process(FormSectionEvent e) throws FormProcessException;
/**
* Helper method to pre-fill the "Caption" textbox. Should be called from
* the init listener
*
* @param e The FormSectionEvent
*/
public void initCaption(FormSectionEvent e) {
FormData data = e.getFormData();
PageState state = e.getPageState();
GenericArticle item = getArticle(state);
ImageAsset asset = getImageAsset(state);
if(item != null && asset != null) {
String caption = item.getCaption(asset);
if(caption != null)
data.put(CAPTION, caption);
}
}
/**
* Helper method to process "Caption" textbox. Should be called from
* the process listener
*
* @param e The FormSectionEvent
*/
public void processCaption(FormSectionEvent e) {
FormData data = e.getFormData();
PageState state = e.getPageState();
GenericArticle item = getArticle(state);
ImageAsset asset = getImageAsset(state);
if(item != null && asset != null) {
item.addImage(asset, (String)data.get(CAPTION));
}
}
/**
* @return the item selection model used in this form
*/
public ItemSelectionModel getItemSelectionModel() {
return m_itemModel;
}
/**
* @return the asset selection model used in this form
*/
public ItemSelectionModel getAssetSelectionModel() {
return m_assetModel;
}
/**
* @return the save/cancel section for this form
*/
public SaveCancelSection getSaveCancelSection() {
return m_saveCancelSection;
}
/**
* @param state The page state
* @return the currently selected item
*/
public GenericArticle getArticle(PageState state) {
return (GenericArticle)m_itemModel.getSelectedObject(state);
}
/**
* @param state The page state
* @return the currently selected image asset
*/
public ImageAsset getImageAsset(PageState state) {
return (ImageAsset)m_assetModel.getSelectedObject(state);
}
/**
* Set the image asset. This will probably be done in the process
* listener
*
* @param state The page state
* @param asset The image asset
*/
public void setImageAsset(PageState state, ImageAsset asset) {
m_assetModel.setSelectedObject(state, asset);
// Force the item to reload, since the assets query is cached ?
// ?
}
}

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.util.GlobalizationUtil;
/**
* A form which edits the width/height/caption of the image.
* Displays appropriate textboxes.
*
* @author Stanislav Freidin (stas@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @version $Revision: #8 $ $DateTime: 2004/08/17 23:15:09 $
*/
public class ImagePropertiesForm extends BasicImageForm {
public static final String WIDTH = "width";
public static final String HEIGHT = "height";
public static final String CAPTION = "caption";
public ImagePropertiesForm(ItemSelectionModel itemModel,
ItemSelectionModel assetModel) {
super("ImagePropertiesForm", itemModel, assetModel);
}
// Add the basic widgeys
public void addWidgets() {
super.addWidgets();
}
// Init: load the asset and preset fields
public void init(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
PageState state = e.getPageState();
GenericArticle item = this.getArticle(state);
ImageAsset asset = this.getImageAsset(state);
if ( asset == null ) {
throw new FormProcessException( (String) GlobalizationUtil.globalize("cms.ui.authoring.no_asset").localize());
}
initCaption(e);
}
// Process: save the data
public void process(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
PageState state = e.getPageState();
GenericArticle item = this.getArticle(state);
ImageAsset asset = this.getImageAsset(state);
if ( asset == null ) {
throw new FormProcessException( (String) GlobalizationUtil.globalize("cms.ui.authoring.no_asset").localize());
}
processCaption(e);
item.save();
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.ImageDisplay;
import org.apache.log4j.Logger;
/**
* A form which displays the newly selected image and prompts
* for image caption.
*
* @author Stanislav Freidin (stas@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @version $Revision: #9 $ $DateTime: 2004/08/17 23:15:09 $
* @version $Id: ImageSelectionForm.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ImageSelectionForm extends BasicImageForm {
private static Logger s_log =
Logger.getLogger(ImageSelectionForm.class);
private ImageDisplay m_display;
/**
* Construct a new ImageSelectionForm
*
* @param itemModel The {@link ItemSelectionModel} which will
* be responsible for loading the current item
*
* @param assetModel The {@link ItemSelectionModel} which will
* be responsible for loading the current image asset
*/
public ImageSelectionForm(ItemSelectionModel itemModel,
ItemSelectionModel assetModel) {
super("ImageSelectionForm", itemModel, assetModel);
m_display = new ImageDisplay(getAssetSelectionModel());
add(m_display, ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH);
}
public void init(FormSectionEvent e) throws FormProcessException {
// Do nothing.
}
// process: update image association
public void process(FormSectionEvent e) throws FormProcessException {
s_log.debug("Selecting Image");
FormData data = e.getFormData();
PageState state = e.getPageState();
GenericArticle item = this.getArticle(state);
ImageAsset a = this.getImageAsset(state);
if(a != null) {
item.clearImages();
item.addImage(a, (String)data.get(CAPTION));
item.save();
this.setImageAsset(state, a);
s_log.debug("Image Selected");
}
}
/**
* @return the image display component
*/
public ImageDisplay getImageDisplay() {
return m_display;
}
}

View File

@ -1,164 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.authoring;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.contenttypes.GenericArticle;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ReusableImageAsset;
import com.arsdigita.cms.ui.FileUploadSection;
import com.arsdigita.mimetypes.ImageMimeType;
import java.io.File;
import org.apache.log4j.Logger;
/**
* A form for uploading images. Displays a mime-type selection
* box and a Caption field.
*
* @author Stanislav Freidin (stas@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @version $Revision: #16 $ $DateTime: 2004/08/17 23:15:09 $
* @version $Id: ImageUploadForm.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ImageUploadForm extends BasicImageForm implements FormSubmissionListener {
private static Logger s_log = Logger.getLogger(ImageUploadForm.class);
private FileUploadSection m_fileUploadSection;
private ArticleImage m_step;
/**
* Construct a new ImageUploadForm
*
* @param itemModel The {@link ItemSelectionModel} which will
* be responsible for loading the current item
*
* @param assetModel The {@link ItemSelectionModel} which will
* be responsible for loading the current image asset
*/
public ImageUploadForm(ItemSelectionModel itemModel,
ItemSelectionModel assetModel) {
this(itemModel, assetModel, null);
}
/**
* Construct a new ImageUploadForm
*
* @param itemModel The {@link ItemSelectionModel} which will
* be responsible for loading the current item
*
* @param assetModel The {@link ItemSelectionModel} which will
* be responsible for loading the current image asset
*
* @param articleImage The {@link ArticleImage} step which this form belongs to
*/
public ImageUploadForm(ItemSelectionModel itemModel,
ItemSelectionModel assetModel,
ArticleImage articleImage) {
super("ImageUploadForm", itemModel, assetModel);
setMethod(Form.POST);
setEncType("multipart/form-data");
m_step = articleImage;
}
// Add the widgets
public void addWidgets() {
m_fileUploadSection =
new FileUploadSection("Image&nbsp;Type:", "image",
ImageMimeType.MIME_IMAGE_JPEG);
m_fileUploadSection.getFileUploadWidget()
.addValidationListener(new NotNullValidationListener());
add(m_fileUploadSection, ColumnPanel.INSERT);
super.addWidgets();
}
public void init(FormSectionEvent event) throws FormProcessException {
// Do nothing.
}
/** Cancels streamlined editing. */
public void submitted( FormSectionEvent fse ) {
if (m_step != null &&
getSaveCancelSection().getCancelButton()
.isSelected( fse.getPageState())) {
m_step.cancelStreamlinedCreation(fse.getPageState());
}
}
// process: update the mime type and content
public void process(FormSectionEvent event) throws FormProcessException {
s_log.debug("Uploading Image");
FormData data = event.getFormData();
PageState state = event.getPageState();
GenericArticle item = this.getArticle(state);
ImageAsset a = null;
try {
// Upload a new image asset
String fileName = m_fileUploadSection.getFileName(event);
String caption = (String)data.get(CAPTION);
File file = m_fileUploadSection.getFile(event);
// Even though Articles are allowed to have more than one Image in the
// object model, this UI only allows them to have one at a time...
// so first off we get rid of all the existing images.
item.clearImages();
item.save();
a = new ReusableImageAsset();
// Load the asset from file
a.loadFromFile(fileName, file, ImageAsset.MIME_JPEG);
// Save everything
a.save();
// Update caption
item.addImage(a, caption);
item.save();
this.setImageAsset(state, a);
s_log.debug("Image Uploaded");
} catch (Exception e) {
s_log.error("Uploading error", e);
throw new FormProcessException(e);
}
if (m_step != null) {
m_step.maybeForwardToNextStep(event.getPageState());
}
}
/**
* @return the save/cancel section for this form
*/
public FileUploadSection getFileUploadSection() {
return m_fileUploadSection;
}
}