CT Image
erste Version git-svn-id: https://svn.libreccm.org/ccm/trunk@746 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
d7ec456d78
commit
f8cd0349e9
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0"?>
|
||||
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
||||
name="ccm-cms-types-image"
|
||||
prettyName="Red Hat CCM Content Types"
|
||||
version="6.6.0"
|
||||
release="1"
|
||||
webapp="ROOT">
|
||||
<ccm:dependencies>
|
||||
<ccm:requires name="ccm-core" version="6.6.0" relation="ge"/>
|
||||
<ccm:requires name="ccm-cms" version="6.6.0" relation="ge"/>
|
||||
</ccm:dependencies>
|
||||
<ccm:directories>
|
||||
<ccm:directory name="pdl"/>
|
||||
<ccm:directory name="sql"/>
|
||||
<ccm:directory name="src"/>
|
||||
</ccm:directories>
|
||||
<ccm:contacts>
|
||||
<ccm:contact uri="http://www.redhat.com/software/rhea" type="website"/>
|
||||
<ccm:contact uri="mailto:rhea@redhat.com" type="support"/>
|
||||
</ccm:contacts>
|
||||
<ccm:description>
|
||||
The Image Content Type for the Red Hat CCM CMS.
|
||||
</ccm:description>
|
||||
</ccm:application>
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
model com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.cms.*;
|
||||
|
||||
object type Image extends ContentPage {
|
||||
|
||||
component ImageAsset[0..1] image = join ct_images.image_id to cms_images.image_id;
|
||||
// Blob[0..1] image = ct_images.image BLOB;
|
||||
// BigDecimal[0..1] width = ct_images.width INTEGER;
|
||||
// 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] publishDate = ct_images.publish_date VARCHAR(200);
|
||||
String[0..1] source = ct_images.source VARCHAR(200);
|
||||
String[0..1] media = ct_images.media VARCHAR(200);
|
||||
String[0..1] copyright = ct_images.copyright VARCHAR(200);
|
||||
// String[0..1] standort = ct_images. VARCHAR(200);
|
||||
|
||||
reference key (ct_images.item_id);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ctd:content-types xmlns:ctd="http://xmlns.redhat.com/cms/content-types"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.redhat.com/cms/content-types content-types.xsd">
|
||||
|
||||
<ctd:content-type label="Image"
|
||||
description="An image type"
|
||||
objectType="com.arsdigita.cms.contenttypes.Image"
|
||||
classname="com.arsdigita.cms.contenttypes.Image">
|
||||
|
||||
<ctd:authoring-kit createComponent="com.arsdigita.cms.ui.authoring.PageCreate">
|
||||
|
||||
<ctd:authoring-step
|
||||
labelKey="cms.contenttypes.shared.basic_properties.title"
|
||||
labelBundle="com.arsdigita.cms.CMSResources"
|
||||
descriptionKey="cms.contenttypes.shared.basic_properties.description"
|
||||
descriptionBundle="com.arsdigita.cms.CMSResources"
|
||||
component="com.arsdigita.cms.contenttypes.ui.ImagePropertiesStep"/>
|
||||
|
||||
<ctd:include href="/WEB-INF/content-types/assign-categories-step.xml"/>
|
||||
</ctd:authoring-kit>
|
||||
</ctd:content-type>
|
||||
</ctd:content-types>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<registry>
|
||||
<!-- nothing yet -->
|
||||
</registry>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<load>
|
||||
<requires>
|
||||
<table name="inits"/>
|
||||
<table name="acs_objects"/>
|
||||
<table name="cms_items"/>
|
||||
<initializer class="com.arsdigita.cms.Initializer"/>
|
||||
</requires>
|
||||
<provides>
|
||||
<table name="ct_images"/>
|
||||
<initializer class="com.arsdigita.cms.contenttypes.ImageInitializer"/>
|
||||
</provides>
|
||||
<scripts>
|
||||
<schema directory="ccm-cms-types-image"/>
|
||||
<data class="com.arsdigita.cms.contenttypes.ImageLoader"/>
|
||||
</scripts>
|
||||
</load>
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* 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.ContentPage;
|
||||
import com.arsdigita.cms.ImageAsset;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* This content type represents an article.
|
||||
*
|
||||
* @version $Revision: #6 $ $Date: 2004/08/17 $
|
||||
*/
|
||||
public class Image extends ContentPage {
|
||||
|
||||
|
||||
private final static org.apache.log4j.Logger s_log =
|
||||
org.apache.log4j.Logger.getLogger(GenericArticle.class);
|
||||
|
||||
/** PDL property name for lead */
|
||||
public static final String IMAGE = "image";
|
||||
// public static final String WIDTH = "width";
|
||||
// public static final String HEIGHT = "height";
|
||||
public static final String CAPTION = "caption";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String ARTIST = "artist";
|
||||
public static final String PUBLISHDATE = "publishDate";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String MEDIA = "media";
|
||||
public static final String COPYRIGHT = "copyright";
|
||||
// public static final String LEAD = "lead";
|
||||
|
||||
/** Data object type for this domain object */
|
||||
public static final String BASE_DATA_OBJECT_TYPE
|
||||
= "com.arsdigita.cms.contenttypes.Image";
|
||||
|
||||
public Image() {
|
||||
this( BASE_DATA_OBJECT_TYPE );
|
||||
}
|
||||
|
||||
public Image( BigDecimal id )
|
||||
throws DataObjectNotFoundException {
|
||||
this( new OID( BASE_DATA_OBJECT_TYPE, id ) );
|
||||
}
|
||||
|
||||
public Image( OID id )
|
||||
throws DataObjectNotFoundException {
|
||||
super( id );
|
||||
}
|
||||
|
||||
public Image( DataObject obj ) {
|
||||
super( obj );
|
||||
}
|
||||
|
||||
public Image( String type ) {
|
||||
super( type );
|
||||
}
|
||||
|
||||
public ImageAsset getImage() {
|
||||
DataObject dobj = (DataObject) get(IMAGE);
|
||||
if(dobj != null) {
|
||||
return (ImageAsset) DomainObjectFactory.newInstance(dobj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setImage(ImageAsset image) {
|
||||
// Assert.exists(image, ImageAsset.class);
|
||||
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() {
|
||||
return (String) get(CAPTION);
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
set(CAPTION, caption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return (String) get(DESCRIPTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
set(DESCRIPTION, description);
|
||||
}
|
||||
|
||||
public String getArtist() {
|
||||
return (String) get(ARTIST);
|
||||
}
|
||||
|
||||
public void setArtist(String artist) {
|
||||
set(ARTIST, artist);
|
||||
}
|
||||
|
||||
public Date getPublishDate() {
|
||||
return (Date) get(PUBLISHDATE);
|
||||
}
|
||||
|
||||
public void setPublishDate(Date publishDate) {
|
||||
set(PUBLISHDATE, publishDate);
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return (String) get(SOURCE);
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
set(SOURCE, source);
|
||||
}
|
||||
|
||||
public String getMedia() {
|
||||
return (String) get(MEDIA);
|
||||
}
|
||||
|
||||
public void setMedia(String media) {
|
||||
set(MEDIA, media);
|
||||
}
|
||||
|
||||
public String getCopyright() {
|
||||
return (String) get(COPYRIGHT);
|
||||
}
|
||||
|
||||
public void setCopyright(String copyright) {
|
||||
set(COPYRIGHT, copyright);
|
||||
}
|
||||
|
||||
// public String get() {
|
||||
// return (String) get();
|
||||
// }
|
||||
//
|
||||
// public void set(String) {
|
||||
// set(,);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.ContentPage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Initializes the image content type.
|
||||
* Defines the content type specific properties and just uses the super class
|
||||
* methods to register the content type with the (transient) content type store
|
||||
* (map).
|
||||
*
|
||||
* @author Sören Bernstein (sbernstein@zes.uni-bremen.de);
|
||||
*/
|
||||
public class ImageInitializer extends ContentTypeInitializer {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(ImageInitializer.class);
|
||||
|
||||
public ImageInitializer() {
|
||||
super("ccm-cms-types-image.pdl.mf", ContentPage.BASE_DATA_OBJECT_TYPE);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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;
|
||||
|
||||
/**
|
||||
* Loader.
|
||||
*
|
||||
* @author Sören Bernstein (sbernstein@zes.uni-bremen.de)
|
||||
*/
|
||||
public class ImageLoader extends AbstractContentTypeLoader {
|
||||
|
||||
private static final String[] TYPES = {
|
||||
"/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Image.xml"
|
||||
};
|
||||
|
||||
public String[] getTypes() {
|
||||
return TYPES;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
article.authoring.image.title=Image
|
||||
article.authoring.image.description=Image
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* 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.Component;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.ImageAsset;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.contenttypes.Image;
|
||||
import com.arsdigita.cms.ui.ImageDisplay;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import com.arsdigita.util.Assert;
|
||||
import java.text.DateFormat;
|
||||
|
||||
/**
|
||||
* Authoring step to edit the simple attributes of the Image content
|
||||
* type (and its subclasses). The attributes edited are 'name', 'title',
|
||||
* 'article date', 'location', 'lead', and 'article type'.
|
||||
* This authoring step replaces
|
||||
* the <code>com.arsdigita.ui.authoring.PageEdit</code> step for this type.
|
||||
*/
|
||||
public class ImagePropertiesStep extends SimpleEditStep {
|
||||
|
||||
/** The name of the editing sheet added to this step */
|
||||
public static String EDIT_SHEET_NAME = "edit";
|
||||
|
||||
public ImagePropertiesStep(ItemSelectionModel itemModel,
|
||||
AuthoringKitWizard parent) {
|
||||
super(itemModel, parent);
|
||||
|
||||
setDefaultEditKey(EDIT_SHEET_NAME);
|
||||
|
||||
BasicPageForm editSheet;
|
||||
|
||||
editSheet = new ImagePropertyForm(itemModel, this);
|
||||
add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel),
|
||||
editSheet.getSaveCancelSection().getCancelButton());
|
||||
|
||||
setDisplayComponent(getImagePropertySheet(itemModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a component that displays the properties of the
|
||||
* Image specified by the ItemSelectionModel passed in.
|
||||
* @param itemModel The ItemSelectionModel to use
|
||||
* @pre itemModel != null
|
||||
* @return A component to display the state of the basic properties
|
||||
* of the release
|
||||
*/
|
||||
public static Component getImagePropertySheet(final ItemSelectionModel itemModel) {
|
||||
SimpleContainer container = new SimpleContainer();
|
||||
|
||||
container.add(new ImageDisplay(null) {
|
||||
|
||||
@Override
|
||||
protected ImageAsset getImageAsset(PageState state) {
|
||||
ImageAsset image = ((Image) itemModel.getSelectedItem(state)).getImage();
|
||||
return image;
|
||||
}
|
||||
});
|
||||
|
||||
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
|
||||
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.name"), Image.NAME);
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.title"), Image.TITLE);
|
||||
if (!ContentSection.getConfig().getHideLaunchDate()) {
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.launch_date"),
|
||||
ContentPage.LAUNCH_DATE,
|
||||
new DomainObjectPropertySheet.AttributeFormatter() {
|
||||
|
||||
public String format(DomainObject item,
|
||||
String attribute,
|
||||
PageState state) {
|
||||
ContentPage page = (ContentPage) item;
|
||||
if (page.getLaunchDate() != null) {
|
||||
return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate());
|
||||
} else {
|
||||
return (String) GlobalizationUtil.globalize("cms.ui.unknown").localize();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// sheet.add( GlobalizationUtil.globalize("cms.contenttypes.ui.image"), new ImageDisplay(null));
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.caption"), Image.CAPTION);
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.description"), Image.DESCRIPTION);
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.artist"), Image.ARTIST);
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.publishDate"), Image.PUBLISHDATE);
|
||||
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.source"), Image.SOURCE);
|
||||
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 );
|
||||
|
||||
container.add(sheet);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public ContentItem getItem( PageState ps ) {
|
||||
return getItemSelectionModel().getSelectedItem( ps );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,351 @@
|
|||
/*
|
||||
* 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.ColumnPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.MapComponentSelectionModel;
|
||||
import com.arsdigita.bebop.Page;
|
||||
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.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.Date;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.DateParameter;
|
||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.ImageAsset;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.contenttypes.Image;
|
||||
import com.arsdigita.cms.ui.FileUploadSection;
|
||||
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import java.io.File;
|
||||
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
|
||||
* extended to create forms for Image subclasses.
|
||||
*/
|
||||
public class ImagePropertyForm
|
||||
extends BasicPageForm
|
||||
implements FormProcessListener, FormInitListener, FormSubmissionListener {
|
||||
|
||||
private final static org.apache.log4j.Logger s_log =
|
||||
org.apache.log4j.Logger.getLogger(ImagePropertyForm.class);
|
||||
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
|
||||
* by the item selection model passed in.
|
||||
* @param itemModel The ItemSelectionModel to use to obtain the
|
||||
* Image to work on
|
||||
*/
|
||||
public ImagePropertyForm(ItemSelectionModel itemModel) {
|
||||
this(itemModel, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new form to edit the Image object specified
|
||||
* by the item selection model passed in.
|
||||
* @param itemModel The ItemSelectionModel to use to obtain the
|
||||
* Image to work on
|
||||
* @param step The ImagePropertiesStep which controls this form.
|
||||
*/
|
||||
public ImagePropertyForm(ItemSelectionModel itemModel, ImagePropertiesStep step) {
|
||||
super(ID, itemModel);
|
||||
m_step = step;
|
||||
// m_imageComponentKey = new StringParameter("imageComponent");
|
||||
// ParameterSingleSelectionModel componentModel = new ParameterSingleSelectionModel(m_imageComponentKey);
|
||||
// m_imageComponent = new MapComponentSelectionModel(componentModel, new HashMap());
|
||||
addSubmissionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds widgets to the form.
|
||||
*/
|
||||
protected void addWidgets() {
|
||||
super.addWidgets();
|
||||
|
||||
// Map selectors = m_imageComponent.getComponentsMap();
|
||||
// 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);
|
||||
captionParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField caption = new TextField(captionParam);
|
||||
add(caption);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.description")));
|
||||
ParameterModel descriptionParam = new StringParameter(Image.DESCRIPTION);
|
||||
descriptionParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField description = new TextField(descriptionParam);
|
||||
add(description);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.artist")));
|
||||
ParameterModel artistParam = new StringParameter(Image.ARTIST);
|
||||
artistParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField artist = new TextField(artistParam);
|
||||
add(artist);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.publish_date")));
|
||||
ParameterModel publishDateParam = new DateParameter(Image.PUBLISHDATE);
|
||||
Date publishDate = new Date(publishDateParam);
|
||||
add(publishDate);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.source")));
|
||||
ParameterModel sourceParam = new StringParameter(Image.SOURCE);
|
||||
sourceParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField source = new TextField(sourceParam);
|
||||
add(source);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.media")));
|
||||
ParameterModel mediaParam = new StringParameter(Image.MEDIA);
|
||||
mediaParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField media = new TextField(mediaParam);
|
||||
add(media);
|
||||
|
||||
add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.copyright")));
|
||||
ParameterModel copyrightParam = new StringParameter(Image.COPYRIGHT);
|
||||
copyrightParam.addParameterListener(new StringInRangeValidationListener(0, 200));
|
||||
TextField copyright = new TextField(copyrightParam);
|
||||
add(copyright);
|
||||
|
||||
}
|
||||
|
||||
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. */
|
||||
public void init(FormSectionEvent fse) {
|
||||
// Do some initialization hook stuff
|
||||
FormData data = fse.getFormData();
|
||||
PageState ps = fse.getPageState();
|
||||
Image image = (Image) super.initBasicWidgets(fse);
|
||||
|
||||
// ItemImageAttachment attachment = m_imageStep.getAttachment(ps);
|
||||
|
||||
data.put(Image.CAPTION, image.getCaption());
|
||||
data.put(Image.DESCRIPTION, image.getDescription());
|
||||
data.put(Image.ARTIST, image.getArtist());
|
||||
data.put(Image.PUBLISHDATE, image.getPublishDate());
|
||||
data.put(Image.SOURCE, image.getSource());
|
||||
data.put(Image.MEDIA, image.getMedia());
|
||||
data.put(Image.COPYRIGHT, image.getCopyright());
|
||||
// data.put( LEAD, image.getLead() );
|
||||
}
|
||||
|
||||
/** Cancels streamlined editing. */
|
||||
public void submitted(FormSectionEvent fse) {
|
||||
if (m_step != null
|
||||
&& getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) {
|
||||
m_step.cancelStreamlinedCreation(fse.getPageState());
|
||||
}
|
||||
}
|
||||
|
||||
/** Form processing hook. Saves Event object. */
|
||||
public void process(FormSectionEvent fse) {
|
||||
FormData data = fse.getFormData();
|
||||
PageState ps = fse.getPageState();
|
||||
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
|
||||
if (image != null
|
||||
&& getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
|
||||
|
||||
image.setCaption((String) data.get(Image.CAPTION));
|
||||
image.setDescription((String) data.get(Image.DESCRIPTION));
|
||||
image.setArtist((String) data.get(Image.ARTIST));
|
||||
image.setPublishDate((java.util.Date) data.get(Image.PUBLISHDATE));
|
||||
image.setSource((String) data.get(Image.SOURCE));
|
||||
image.setMedia((String) data.get(Image.MEDIA));
|
||||
image.setCopyright((String) data.get(Image.COPYRIGHT));
|
||||
// image.setLead( (String) data.get( LEAD ) );
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE stylesheet [
|
||||
<!ENTITY nbsp " " ><!-- no-break space = non-breaking space, U+00A0 ISOnum -->
|
||||
]>
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:cms="http://www.arsdigita.com/cms/1.0"
|
||||
version="1.0">
|
||||
|
||||
<xsl:template match="cms:item[objectType='com.arsdigita.cms.contenttypes.Image']" mode="cms:CT_graphics"
|
||||
name="cms:CT_graphics_com_arsdigita_cms_contenttypes_Image">
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="cms:item[objectType='com.arsdigita.cms.contenttypes.Image']" mode="cms:CT_text"
|
||||
name="cms:CT_text_com_arsdigita_cms_contenttypes_Image">
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Loading…
Reference in New Issue