Fast vollständig, nur noch eine Kleinigkeit. Beim Anlegen eines neuen CI funktioniert der Upload nicht. Erst, wenn man den Edit-Schritt mit Cancel beendet oder das CI neu öffnet.

git-svn-id: https://svn.libreccm.org/ccm/trunk@752 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-02-17 13:08:13 +00:00
parent f53938ad94
commit c05550db60
11 changed files with 391 additions and 283 deletions

View File

@ -5,17 +5,14 @@ import com.arsdigita.cms.*;
object type Image extends ContentPage { object type Image extends ContentPage {
component ImageAsset[0..1] image = join ct_images.image_id to cms_images.image_id; component ImageAsset[0..1] image = join ct_images.image_id to cms_images.image_id;
// Blob[0..1] image = ct_images.image BLOB; String[0..1] caption = ct_images.caption VARCHAR(400);
// BigDecimal[0..1] width = ct_images.width INTEGER; String[0..1] description = ct_images.description VARCHAR(2000);
// BigDecimal[0..1] height = ct_images.height INTEGER;
String[0..1] caption = ct_images.caption VARCHAR(200);
String[0..1] description = ct_images.description VARCHAR(200);
String[0..1] artist = ct_images.artist VARCHAR(200); String[0..1] artist = ct_images.artist VARCHAR(200);
String[0..1] publishDate = ct_images.publish_date VARCHAR(200); Date [0..1] publishDate = ct_images.publish_date DATE;
String[0..1] source = ct_images.source VARCHAR(200); String[0..1] source = ct_images.source VARCHAR(600);
String[0..1] media = ct_images.media VARCHAR(200); String[0..1] media = ct_images.media VARCHAR(300);
String[0..1] copyright = ct_images.copyright VARCHAR(200); String[0..1] copyright = ct_images.copyright VARCHAR(400);
// String[0..1] standort = ct_images. VARCHAR(200); String[0..1] site = ct_images.site VARCHAR(500);
reference key (ct_images.item_id); reference key (ct_images.item_id);
} }

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<registry> <registry>
<!-- nothing yet --> <config class="com.arsdigita.cms.contenttypes.ImageConfig"
storage="ccm-cms-types-image/image.properties"/>
</registry> </registry>

View File

@ -18,14 +18,12 @@
*/ */
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ImageAsset; import com.arsdigita.cms.ImageAsset;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@ -37,10 +35,8 @@ import java.util.Date;
*/ */
public class Image extends ContentPage { public class Image extends ContentPage {
private final static org.apache.log4j.Logger s_log = private final static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(GenericArticle.class); org.apache.log4j.Logger.getLogger(GenericArticle.class);
/** PDL property name for lead */ /** PDL property name for lead */
public static final String IMAGE = "image"; public static final String IMAGE = "image";
// public static final String WIDTH = "width"; // public static final String WIDTH = "width";
@ -52,37 +48,47 @@ public class Image extends ContentPage {
public static final String SOURCE = "source"; public static final String SOURCE = "source";
public static final String MEDIA = "media"; public static final String MEDIA = "media";
public static final String COPYRIGHT = "copyright"; public static final String COPYRIGHT = "copyright";
// public static final String LEAD = "lead"; public static final String SITE = "site";
/** Data object type for this domain object */ /** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Image";
= "com.arsdigita.cms.contenttypes.Image"; private static final ImageConfig s_config = new ImageConfig();
static {
s_log.debug("Static initalizer starting...");
s_config.load();
s_log.debug("Static initalizer finished.");
}
public static final ImageConfig getConfig() {
return s_config;
}
public Image() { public Image() {
this( BASE_DATA_OBJECT_TYPE ); this(BASE_DATA_OBJECT_TYPE);
} }
public Image( BigDecimal id ) public Image(BigDecimal id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
this( new OID( BASE_DATA_OBJECT_TYPE, id ) ); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
public Image( OID id ) public Image(OID id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
super( id ); super(id);
} }
public Image( DataObject obj ) { public Image(DataObject obj) {
super( obj ); super(obj);
} }
public Image( String type ) { public Image(String type) {
super( type ); super(type);
} }
public ImageAsset getImage() { public ImageAsset getImage() {
DataObject dobj = (DataObject) get(IMAGE); DataObject dobj = (DataObject) get(IMAGE);
if(dobj != null) { if (dobj != null) {
return (ImageAsset) DomainObjectFactory.newInstance(dobj); return (ImageAsset) DomainObjectFactory.newInstance(dobj);
} else { } else {
return null; return null;
@ -90,34 +96,9 @@ public class Image extends ContentPage {
} }
public void setImage(ImageAsset image) { public void setImage(ImageAsset image) {
// Assert.exists(image, ImageAsset.class);
set(IMAGE, image); set(IMAGE, image);
} }
// public byte[] getImage() {
// return (byte[]) get(IMAGE);
// }
//
// public void setImage(byte[] image) {
// set(IMAGE, image);
// }
// public BigDecimal getWidth() {
// return (BigDecimal) get(WIDTH);
// }
//
// public void setWidth(BigDecimal width) {
// set(WIDTH, width);
// }
//
// public BigDecimal getHeight() {
// return (BigDecimal) get(HEIGHT);
// }
//
// public void setHeight(BigDecimal height) {
// set(HEIGHT, height);
// }
public String getCaption() { public String getCaption() {
return (String) get(CAPTION); return (String) get(CAPTION);
} }
@ -176,12 +157,11 @@ public class Image extends ContentPage {
set(COPYRIGHT, copyright); set(COPYRIGHT, copyright);
} }
// public String get() { public String getSite() {
// return (String) get(); return (String) get(SITE);
// } }
//
// public void set(String) {
// set(,);
// }
public void setSite(String site) {
set(SITE, site);
}
} }

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 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.runtime.AbstractConfig;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.IntegerParameter;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class ImageConfig extends AbstractConfig {
private final Parameter m_startYear;
private final Parameter m_endYearDelta;
public ImageConfig() {
m_startYear = new IntegerParameter(
"com.arsdigita.cms.contenttypes.event.start_year",
Parameter.REQUIRED,
new Integer(GregorianCalendar.getInstance().get(Calendar.YEAR) - 1));
m_endYearDelta = new IntegerParameter(
"com.arsdigita.cms.contenttypes.event.end_year_delta",
Parameter.REQUIRED,
new Integer(3));
register(m_startYear);
register(m_endYearDelta);
loadInfo();
}
public final int getStartYear() {
return ((Integer) get(m_startYear)).intValue();
}
public final int getEndYearDelta() {
return ((Integer) get(m_endYearDelta)).intValue();
}
}

View File

@ -0,0 +1,9 @@
com.arsdigita.cms.contenttypes.image.start_year.title=Start Year
com.arsdigita.cms.contenttypes.image.start_year.purpose=Start year for the year select box
com.arsdigita.cms.contenttypes.image.start_year.example=2008
com.arsdigita.cms.contenttypes.image.start_year.format=[integer]
com.arsdigita.cms.contenttypes.image.end_year_delta.title=End Year
com.arsdigita.cms.contenttypes.image.end_year_delta.purpose=End year delta for the year select box
com.arsdigita.cms.contenttypes.image.end_year_delta.example=3
com.arsdigita.cms.contenttypes.image.end_year_delta.format=[integer]

View File

@ -1,2 +1,9 @@
article.authoring.image.title=Image article.authoring.image.title=Image
article.authoring.image.description=Image article.authoring.image.description=Image
cms.contenttypes.ui.image.caption=Caption:
cms.contenttypes.ui.image.artist=Artist:
cms.contenttypes.ui.image.publishDate=Publishing Date:
cms.contenttypes.ui.image.source=Source:
cms.contenttypes.ui.image.media=Media:
cms.contenttypes.ui.image.copyright=Copyright:
cms.contenttypes.ui.image.site=Site:

View File

@ -0,0 +1,7 @@
cms.contenttypes.ui.image.caption=Bilduntertitel:
cms.contenttypes.ui.image.artist=K\u00fcnstler:
cms.contenttypes.ui.image.publishDate=Ver\u00f6ffentlichungsdatum:
cms.contenttypes.ui.image.source=Quelle:
cms.contenttypes.ui.image.media=Medium:
cms.contenttypes.ui.image.copyright=Copyright:
cms.contenttypes.ui.image.site=Standort:

View File

@ -18,16 +18,29 @@
*/ */
package com.arsdigita.cms.contenttypes.ui; package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.MapComponentSelectionModel;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ImageAsset; import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Image; import com.arsdigita.cms.contenttypes.Image;
import com.arsdigita.cms.contenttypes.util.ImageGlobalizationUtil;
import com.arsdigita.cms.ui.FileUploadSection;
import com.arsdigita.cms.ui.ImageDisplay; import com.arsdigita.cms.ui.ImageDisplay;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
@ -35,9 +48,11 @@ import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.cms.util.GlobalizationUtil; import java.io.File;
import com.arsdigita.util.Assert; import java.io.IOException;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.HashMap;
import java.util.Map;
/** /**
* Authoring step to edit the simple attributes of the Image content * Authoring step to edit the simple attributes of the Image content
@ -50,18 +65,30 @@ public class ImagePropertiesStep extends SimpleEditStep {
/** The name of the editing sheet added to this step */ /** The name of the editing sheet added to this step */
public static String EDIT_SHEET_NAME = "edit"; public static String EDIT_SHEET_NAME = "edit";
public static String UPLOAD_SHEET_NAME = "uploadSheet";
private final StringParameter m_imageComponentKey;
private final MapComponentSelectionModel m_imageComponent;
private final String UPLOAD = "upload";
private ImageUploadComponent uploadSheet;
public ImagePropertiesStep(ItemSelectionModel itemModel, public ImagePropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) {
AuthoringKitWizard parent) {
super(itemModel, parent); super(itemModel, parent);
setDefaultEditKey(EDIT_SHEET_NAME); setDefaultEditKey(EDIT_SHEET_NAME);
BasicPageForm editSheet; BasicPageForm editSheet;
m_imageComponentKey = new StringParameter("imageComponent");
ParameterSingleSelectionModel componentModel = new ParameterSingleSelectionModel(m_imageComponentKey);
m_imageComponent = new MapComponentSelectionModel(componentModel, new HashMap());
Map selectors = m_imageComponent.getComponentsMap();
uploadSheet = new ImageUploadComponent();
uploadSheet.getForm().addProcessListener(new ImageUploadListerner());
selectors.put(UPLOAD, uploadSheet);
editSheet = new ImagePropertyForm(itemModel, this); editSheet = new ImagePropertyForm(itemModel, this);
add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel), add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel), editSheet.getSaveCancelSection().getCancelButton());
editSheet.getSaveCancelSection().getCancelButton()); add(UPLOAD_SHEET_NAME, "Upload", new WorkflowLockedComponentAccess(uploadSheet, itemModel), uploadSheet.getSaveCancelSection().getCancelButton());
setDisplayComponent(getImagePropertySheet(itemModel)); setDisplayComponent(getImagePropertySheet(itemModel));
} }
@ -88,10 +115,10 @@ public class ImagePropertiesStep extends SimpleEditStep {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.name"), Image.NAME); sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.name"), Image.NAME);
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.title"), Image.TITLE); sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.title"), Image.TITLE);
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"), sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"),
ContentPage.LAUNCH_DATE, ContentPage.LAUNCH_DATE,
new DomainObjectPropertySheet.AttributeFormatter() { new DomainObjectPropertySheet.AttributeFormatter() {
@ -102,29 +129,133 @@ public class ImagePropertiesStep extends SimpleEditStep {
if (page.getLaunchDate() != null) { if (page.getLaunchDate() != null) {
return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate()); return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate());
} else { } else {
return (String) GlobalizationUtil.globalize("cms.ui.unknown").localize(); return (String) ImageGlobalizationUtil.globalize("cms.ui.unknown").localize();
} }
} }
}); });
} }
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.caption"), Image.CAPTION);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.description"), Image.DESCRIPTION);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.artist"), Image.ARTIST);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.publishDate"), Image.PUBLISHDATE,
new DomainObjectPropertySheet.AttributeFormatter() {
// sheet.add( GlobalizationUtil.globalize("cms.contenttypes.ui.image"), new ImageDisplay(null)); public String format(DomainObject item, String attribute, PageState state) {
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.caption"), Image.CAPTION); Image image = (Image) item;
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.description"), Image.DESCRIPTION); if ((image.getPublishDate()) != null) {
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.artist"), Image.ARTIST); return DateFormat.getDateInstance(DateFormat.LONG).format(image.getPublishDate());
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.publishDate"), Image.PUBLISHDATE); } else {
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.source"), Image.SOURCE); return (String) ImageGlobalizationUtil.globalize("cms.ui.unknown").localize();
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.media"), Image.MEDIA); }
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.copyright"), Image.COPYRIGHT); }
// sheet.add( GlobalizationUtil.globalize("cms.contenttypes.ui.lead"), Image.LEAD ); });
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.source"), Image.SOURCE);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.media"), Image.MEDIA);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.copyright"), Image.COPYRIGHT);
sheet.add(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.site"), Image.SITE);
container.add(sheet); container.add(sheet);
return container; return container;
} }
public ContentItem getItem( PageState ps ) { @Override
return getItemSelectionModel().getSelectedItem( ps ); public void register(Page p) {
super.register(p);
p.addComponentStateParam(this, m_imageComponentKey);
}
public ContentItem getItem(PageState ps) {
return getItemSelectionModel().getSelectedItem(ps);
}
class ImageUploadListerner implements FormProcessListener {
public void process(FormSectionEvent fse) {
FormData data = fse.getFormData();
PageState ps = fse.getPageState();
Image image = (Image) getItemSelectionModel().getSelectedObject(ps);
ImageAsset imageAsset = null;
ImageComponent component = getImageComponent(ps);
try {
imageAsset = component.getImage(fse);
} catch (FormProcessException ex) {
}
// save only if save button was pressed
if (image != null && uploadSheet.getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
image.setImage(imageAsset);
image.save();
}
}
private ImageComponent getImageComponent(PageState ps) {
if (!m_imageComponent.isSelected(ps)) {
m_imageComponent.setSelectedKey(ps, UPLOAD);
}
return (ImageComponent) m_imageComponent.getComponent(ps);
}
}
interface ImageComponent {
ImageAsset getImage(FormSectionEvent event)
throws FormProcessException;
SaveCancelSection getSaveCancelSection();
Form getForm();
}
private class ImageUploadComponent extends Form
implements ImageComponent {
private final FileUploadSection m_imageFile;
private final SaveCancelSection m_saveCancel;
public ImageUploadComponent() {
super("imageStepEditUpload", new ColumnPanel(2));
setEncType("multipart/form-data");
// Ignoring deprecated constructor.
m_imageFile = new FileUploadSection("Image Type", "image", ImageAsset.MIME_JPEG);
m_imageFile.getFileUploadWidget().addValidationListener(new NotNullValidationListener());
add(m_imageFile, ColumnPanel.FULL_WIDTH);
m_saveCancel = new SaveCancelSection();
add(m_saveCancel);
}
public SaveCancelSection getSaveCancelSection() {
return m_saveCancel;
}
public ImageAsset getImage(FormSectionEvent event)
throws FormProcessException {
PageState ps = event.getPageState();
String filename = (String) m_imageFile.getFileName(event);
File imageFile = m_imageFile.getFile(event);
try {
ImageAsset image = new ImageAsset();
image.loadFromFile(filename, imageFile, ImageAsset.MIME_JPEG);
return image;
} catch (IOException ex) {
throw new FormProcessException(ex.getMessage());
}
}
public Form getForm() {
return this;
}
} }
} }

View File

@ -18,17 +18,10 @@
*/ */
package com.arsdigita.cms.contenttypes.ui; package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.MapComponentSelectionModel;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormSubmissionListener;
@ -37,21 +30,15 @@ import com.arsdigita.bebop.form.Date;
import com.arsdigita.bebop.form.TextArea; import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.DateParameter; import com.arsdigita.bebop.parameters.DateParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener; import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Image; import com.arsdigita.cms.contenttypes.Image;
import com.arsdigita.cms.ui.FileUploadSection; import com.arsdigita.cms.contenttypes.util.ImageGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.util.GlobalizationUtil; import java.util.Calendar;
import java.io.File; import java.util.GregorianCalendar;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/** /**
* Form to edit the basic properties of an article. This form can be * Form to edit the basic properties of an article. This form can be
@ -64,9 +51,6 @@ public class ImagePropertyForm
private final static org.apache.log4j.Logger s_log = private final static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(ImagePropertyForm.class); org.apache.log4j.Logger.getLogger(ImagePropertyForm.class);
private ImagePropertiesStep m_step; private ImagePropertiesStep m_step;
// private final StringParameter m_imageComponentKey;
// private final MapComponentSelectionModel m_imageComponent;
private final String UPLOAD = "upload";
/** /**
* Creates a new form to edit the Image object specified * Creates a new form to edit the Image object specified
@ -88,129 +72,69 @@ public class ImagePropertyForm
public ImagePropertyForm(ItemSelectionModel itemModel, ImagePropertiesStep step) { public ImagePropertyForm(ItemSelectionModel itemModel, ImagePropertiesStep step) {
super(ID, itemModel); super(ID, itemModel);
m_step = step; m_step = step;
// m_imageComponentKey = new StringParameter("imageComponent");
// ParameterSingleSelectionModel componentModel = new ParameterSingleSelectionModel(m_imageComponentKey);
// m_imageComponent = new MapComponentSelectionModel(componentModel, new HashMap());
addSubmissionListener(this); addSubmissionListener(this);
} }
/** /**
* Adds widgets to the form. * Adds widgets to the form.
*/ */
@Override
protected void addWidgets() { protected void addWidgets() {
super.addWidgets(); super.addWidgets();
// Map selectors = m_imageComponent.getComponentsMap(); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.caption")));
// ImageUploadComponent upload = new ImageUploadComponent();
// upload.getForm().addInitListener(this);
// upload.getForm().addProcessListener(this);
// selectors.put(UPLOAD, upload);
// add(upload);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.caption")));
ParameterModel captionParam = new StringParameter(Image.CAPTION); ParameterModel captionParam = new StringParameter(Image.CAPTION);
captionParam.addParameterListener(new StringInRangeValidationListener(0, 200)); captionParam.addParameterListener(new StringInRangeValidationListener(0, 400));
TextField caption = new TextField(captionParam); TextField caption = new TextField(captionParam);
add(caption); add(caption);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.description"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.description")));
ParameterModel descriptionParam = new StringParameter(Image.DESCRIPTION); ParameterModel descriptionParam = new StringParameter(Image.DESCRIPTION);
descriptionParam.addParameterListener(new StringInRangeValidationListener(0, 200)); descriptionParam.addParameterListener(new StringInRangeValidationListener(0, 2000));
TextField description = new TextField(descriptionParam); TextArea description = new TextArea(descriptionParam);
description.setRows(10);
description.setCols(60);
add(description); add(description);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.artist"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.artist")));
ParameterModel artistParam = new StringParameter(Image.ARTIST); ParameterModel artistParam = new StringParameter(Image.ARTIST);
artistParam.addParameterListener(new StringInRangeValidationListener(0, 200)); artistParam.addParameterListener(new StringInRangeValidationListener(0, 200));
TextField artist = new TextField(artistParam); TextField artist = new TextField(artistParam);
add(artist); add(artist);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.publish_date"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.publishDate")));
ParameterModel publishDateParam = new DateParameter(Image.PUBLISHDATE); ParameterModel publishDateParam = new DateParameter(Image.PUBLISHDATE);
Date publishDate = new Date(publishDateParam); Date publishDate = new Date(publishDateParam);
publishDate.setYearRange(Image.getConfig().getStartYear(),
GregorianCalendar.getInstance().get(Calendar.YEAR) + Image.getConfig().getEndYearDelta());
add(publishDate); add(publishDate);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.source"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.source")));
ParameterModel sourceParam = new StringParameter(Image.SOURCE); ParameterModel sourceParam = new StringParameter(Image.SOURCE);
sourceParam.addParameterListener(new StringInRangeValidationListener(0, 200)); sourceParam.addParameterListener(new StringInRangeValidationListener(0, 600));
TextField source = new TextField(sourceParam); TextField source = new TextField(sourceParam);
add(source); add(source);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.media"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.media")));
ParameterModel mediaParam = new StringParameter(Image.MEDIA); ParameterModel mediaParam = new StringParameter(Image.MEDIA);
mediaParam.addParameterListener(new StringInRangeValidationListener(0, 200)); mediaParam.addParameterListener(new StringInRangeValidationListener(0, 300));
TextField media = new TextField(mediaParam); TextField media = new TextField(mediaParam);
add(media); add(media);
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.copyright"))); add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.copyright")));
ParameterModel copyrightParam = new StringParameter(Image.COPYRIGHT); ParameterModel copyrightParam = new StringParameter(Image.COPYRIGHT);
copyrightParam.addParameterListener(new StringInRangeValidationListener(0, 200)); copyrightParam.addParameterListener(new StringInRangeValidationListener(0, 400));
TextField copyright = new TextField(copyrightParam); TextField copyright = new TextField(copyrightParam);
add(copyright); add(copyright);
} add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.site")));
ParameterModel siteParam = new StringParameter(Image.SITE);
siteParam.addParameterListener(new StringInRangeValidationListener(0, 500));
TextField site = new TextField(siteParam);
add(site);
public void validate(FormSectionEvent e) throws FormProcessException {
FormData d = e.getFormData();
} }
// @Override
// public void register(Page p) {
// super.register(p);
//
// Map componentsMap = m_imageComponent.getComponentsMap();
// Iterator i = componentsMap.keySet().iterator();
// while (i.hasNext()) {
// Object key = i.next();
// Component component = (Component) componentsMap.get(key);
//
// p.setVisibleDefault(component, UPLOAD.equals(key));
// }
//
// p.addComponentStateParam(this, m_imageComponentKey);
// }
//
// Iterator getImageComponents() {
// return m_imageComponent.getComponentsMap().values().iterator();
// }
//
// private ImageComponent getImageComponent(PageState ps) {
// if (!m_imageComponent.isSelected(ps)) {
// if (s_log.isDebugEnabled()) {
// s_log.debug("No component selected");
// s_log.debug("Selected: " + m_imageComponent.getComponent(ps));
// }
//
// m_imageComponent.setSelectedKey(ps, UPLOAD);
// }
//
// return (ImageComponent) m_imageComponent.getComponent(ps);
//
// }
//
// private void setImageComponent(PageState ps, final String activeKey) {
// m_imageComponent.setSelectedKey(ps, activeKey);
//
// if (s_log.isDebugEnabled()) {
// s_log.debug("Selected component: " + activeKey);
// }
//
// Map componentsMap = m_imageComponent.getComponentsMap();
// Iterator i = componentsMap.keySet().iterator();
// while (i.hasNext()) {
// Object key = i.next();
// Component component = (Component) componentsMap.get(key);
//
// boolean isVisible = activeKey.equals(key);
//
// if (s_log.isDebugEnabled()) {
// s_log.debug("Key: " + key + "; Visibility: " + isVisible);
// }
//
// ps.setVisible(component, isVisible);
// }
// }
/** Form initialisation hook. Fills widgets with data. */ /** Form initialisation hook. Fills widgets with data. */
public void init(FormSectionEvent fse) { public void init(FormSectionEvent fse) {
// Do some initialization hook stuff // Do some initialization hook stuff
@ -218,8 +142,6 @@ public class ImagePropertyForm
PageState ps = fse.getPageState(); PageState ps = fse.getPageState();
Image image = (Image) super.initBasicWidgets(fse); Image image = (Image) super.initBasicWidgets(fse);
// ItemImageAttachment attachment = m_imageStep.getAttachment(ps);
data.put(Image.CAPTION, image.getCaption()); data.put(Image.CAPTION, image.getCaption());
data.put(Image.DESCRIPTION, image.getDescription()); data.put(Image.DESCRIPTION, image.getDescription());
data.put(Image.ARTIST, image.getArtist()); data.put(Image.ARTIST, image.getArtist());
@ -227,7 +149,12 @@ public class ImagePropertyForm
data.put(Image.SOURCE, image.getSource()); data.put(Image.SOURCE, image.getSource());
data.put(Image.MEDIA, image.getMedia()); data.put(Image.MEDIA, image.getMedia());
data.put(Image.COPYRIGHT, image.getCopyright()); data.put(Image.COPYRIGHT, image.getCopyright());
// data.put( LEAD, image.getLead() ); data.put(Image.SITE, image.getSite());
}
@Override
public void validate(FormSectionEvent e) throws FormProcessException {
FormData d = e.getFormData();
} }
/** Cancels streamlined editing. */ /** Cancels streamlined editing. */
@ -244,34 +171,8 @@ public class ImagePropertyForm
PageState ps = fse.getPageState(); PageState ps = fse.getPageState();
Image image = (Image) super.processBasicWidgets(fse); Image image = (Image) super.processBasicWidgets(fse);
// ImageComponent component = getImageComponent(ps);
// try {
// ImageAsset imageAsset = component.getImage(fse);
// ItemImageAttachment attachment = m_imageStep.getAttachment(ps);
// if (null == attachment) {
// attachment = new ItemImageAttachment(item, imageAsset);
// }
// attachment.setCaption( component.getCaption( event ) );
//
// // We only set the description and title based on the UI in
// // the case where getIsImageStepDescriptionAndTitleShown is true.
// // Otherwise, we leave this as the default value. This means
// // existing values are not overwritten if the image is edited when
// // isImageStepDescriptionAndTitleShown is false.
// if(ItemImageAttachment.getConfig().getIsImageStepDescriptionAndTitleShown()) {
// attachment.setDescription(component.getDescription( event ));
// attachment.setTitle(component.getTitle( event ));
// }
// attachment.setUseContext( component.getUseContext( event ) );
// } catch (FormProcessException ex) {
// }
// save only if save button was pressed // save only if save button was pressed
if (image != null if (image != null && getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
&& getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
image.setCaption((String) data.get(Image.CAPTION)); image.setCaption((String) data.get(Image.CAPTION));
image.setDescription((String) data.get(Image.DESCRIPTION)); image.setDescription((String) data.get(Image.DESCRIPTION));
@ -280,72 +181,9 @@ public class ImagePropertyForm
image.setSource((String) data.get(Image.SOURCE)); image.setSource((String) data.get(Image.SOURCE));
image.setMedia((String) data.get(Image.MEDIA)); image.setMedia((String) data.get(Image.MEDIA));
image.setCopyright((String) data.get(Image.COPYRIGHT)); image.setCopyright((String) data.get(Image.COPYRIGHT));
// image.setLead( (String) data.get( LEAD ) ); image.setSite((String) data.get(Image.SITE));
image.save(); image.save();
} }
// if (m_step != null) {
// m_step.maybeForwardToNextStep(fse.getPageState());
// }
}
interface ImageComponent {
ImageAsset getImage(FormSectionEvent event)
throws FormProcessException;
SaveCancelSection getSaveCancelSection();
Form getForm();
}
private class ImageUploadComponent extends Form
implements ImageComponent {
private final FileUploadSection m_imageFile;
private final SaveCancelSection m_saveCancel;
public ImageUploadComponent() {
super("imageStepEditUpload", new ColumnPanel(2));
setEncType("multipart/form-data");
// Ignoring deprecated constructor.
m_imageFile = new FileUploadSection("Image Type", "image", ImageAsset.MIME_JPEG);
m_imageFile.getFileUploadWidget().addValidationListener(new NotNullValidationListener());
add(m_imageFile, ColumnPanel.FULL_WIDTH);
m_saveCancel = new SaveCancelSection();
add(m_saveCancel);
}
public SaveCancelSection getSaveCancelSection() {
return m_saveCancel;
}
public ImageAsset getImage(FormSectionEvent event)
throws FormProcessException {
PageState ps = event.getPageState();
String filename = (String) m_imageFile.getFileName(event);
File imageFile = m_imageFile.getFile(event);
try {
ImageAsset image = new ImageAsset();
image.loadFromFile(filename, imageFile, ImageAsset.MIME_JPEG);
// image.setDescription((String) m_caption.getValue(ps));
return image;
} catch (IOException ex) {
s_log.error("Error loading image from file", ex);
throw new FormProcessException(ex.getMessage());
}
}
public Form getForm() {
return this;
}
} }
} }

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 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.util;
import com.arsdigita.globalization.GlobalizedMessage;
public class ImageGlobalizationUtil {
final public static String BUNDLE_NAME =
"com.arsdigita.cms.contenttypes.util.ImageResourceBundle";
/**
* This returns a globalized message using the type specific bundle,
* BUNDLE_NAME
*/
public static GlobalizedMessage globalize(String key) {
return new GlobalizedMessage(key, BUNDLE_NAME);
}
/**
* This returns a globalized message using the type specific bundle,
* BUNDLE_NAME
*/
public static GlobalizedMessage globalize(String key, Object[] args) {
return new GlobalizedMessage(key, BUNDLE_NAME, args);
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 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.util;
import java.util.PropertyResourceBundle;
import com.arsdigita.globalization.ChainedResourceBundle;
import com.arsdigita.cms.CMSGlobalized;
/**
* Resource Bundle used in UI for Image ContentType.
*/
public class ImageResourceBundle extends ChainedResourceBundle implements CMSGlobalized {
public final static String IMAGE_BUNDLE_NAME =
"com.arsdigita.cms.contenttypes.ImageResources";
public ImageResourceBundle() {
super();
addBundle((PropertyResourceBundle)getBundle(IMAGE_BUNDLE_NAME));
addBundle((PropertyResourceBundle)getBundle(BUNDLE_NAME));
}
}