MPA ImageAsset durch ReusableImageAsset ersetzt

git-svn-id: https://svn.libreccm.org/ccm/trunk@1538 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-03-07 14:37:44 +00:00
parent 291e6bbe68
commit 18eb7f05c6
4 changed files with 86 additions and 92 deletions

View File

@ -21,7 +21,7 @@ model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.TextAsset; import com.arsdigita.cms.TextAsset;
import com.arsdigita.cms.ImageAsset; import com.arsdigita.cms.ReusableImageAsset;
// object type to hold sections for multi-part article content type // object type to hold sections for multi-part article content type
@ -32,8 +32,8 @@ object type ArticleSection extends ContentPage {
component TextAsset[0..1] text = join ct_mp_sections.text component TextAsset[0..1] text = join ct_mp_sections.text
to cms_text.text_id; to cms_text.text_id;
component ImageAsset[0..1] image = join ct_mp_sections.image component ReusableImageAsset[0..1] image = join ct_mp_sections.image
to cms_images.image_id; to cms_images.image_id;
reference key (ct_mp_sections.section_id); reference key (ct_mp_sections.section_id);
} }

View File

@ -18,21 +18,15 @@
*/ */
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.*;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.TextAsset;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
import org.apache.log4j.Logger;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.log4j.Logger;
/** /**
* Represents a section within a MultiPartArticle * Represents a section within a MultiPartArticle
@ -63,7 +57,7 @@ public class ArticleSection extends ContentPage {
* *
* @param id the id of the object to retrieve * @param id the id of the object to retrieve
*/ */
public ArticleSection(BigDecimal id) public ArticleSection(BigDecimal id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
@ -73,7 +67,7 @@ public class ArticleSection extends ContentPage {
* *
* @param id the id of the object to retrieve * @param id the id of the object to retrieve
*/ */
public ArticleSection(OID id) public ArticleSection(OID id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
super(id); super(id);
} }
@ -100,7 +94,7 @@ public class ArticleSection extends ContentPage {
} }
/** Accessor. Get this item's rank in the set of ArticleSections */ /** Accessor. Get this item's rank in the set of ArticleSections */
public Integer getRank() { public Integer getRank() {
return (Integer)get(RANK); return (Integer)get(RANK);
} }
@ -109,7 +103,7 @@ public class ArticleSection extends ContentPage {
public void setRank(Integer rank) { public void setRank(Integer rank) {
set(RANK, rank); set(RANK, rank);
} }
public MultiPartArticle getMPArticle() { public MultiPartArticle getMPArticle() {
DataObject obj = (DataObject) get( MP_ARTICLE ); DataObject obj = (DataObject) get( MP_ARTICLE );
@ -130,21 +124,21 @@ public class ArticleSection extends ContentPage {
} }
/** Accessor. Get the image associated with this item. */ /** Accessor. Get the image associated with this item. */
public ImageAsset getImage() { public ReusableImageAsset getImage() {
if ( get(IMAGE) == null ) { if ( get(IMAGE) == null ) {
return null; return null;
} }
return new ImageAsset((DataObject)get(IMAGE)); return new ReusableImageAsset((DataObject)get(IMAGE));
} }
/** Mutator. Set the image associated with this item. */ /** Mutator. Set the image associated with this item. */
public void setImage(ImageAsset image) { public void setImage(ReusableImageAsset image) {
setAssociation(IMAGE, image); setAssociation(IMAGE, image);
} }
public void initialize() { public void initialize() {
super.initialize(); super.initialize();
if (isNew()) { if (isNew()) {
set(PAGE_BREAK, Boolean.FALSE); set(PAGE_BREAK, Boolean.FALSE);
} }
@ -160,30 +154,30 @@ public class ArticleSection extends ContentPage {
/** /**
* Depending on config parameter, either return the title * Depending on config parameter, either return the title
* of the section * of the section
* *
* OR * OR
* *
* return the title of the section at the top of the * return the title of the section at the top of the
* page on which the current section appears unless * page on which the current section appears unless
* the whole multipart article appears on one page, * the whole multipart article appears on one page,
* in which case null is returned. * in which case null is returned.
*/ */
public String getPageTitle() { public String getPageTitle() {
if (MultiPartArticle.getConfig().useSectionTitle()) { if (MultiPartArticle.getConfig().useSectionTitle()) {
return getTitle(); return getTitle();
} }
s_log.debug("retrieve pageTitle for section " + getTitle() + " ranked " + getRank()); s_log.debug("retrieve pageTitle for section " + getTitle() + " ranked " + getRank());
MultiPartArticle parent = getMPArticle(); MultiPartArticle parent = getMPArticle();
// is this a single page article? either page break on last section, // is this a single page article? either page break on last section,
// or no page breaks // or no page breaks
// boolean argument means order by rank ascending - no argument // boolean argument means order by rank ascending - no argument
// currently means ascending, but specify here in case that // currently means ascending, but specify here in case that
// changes // changes
ArticleSectionCollection sections = parent.getSections(true); ArticleSectionCollection sections = parent.getSections(true);
sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE); sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE);
@ -195,36 +189,36 @@ public class ArticleSection extends ContentPage {
sections.close(); sections.close();
int lastSection = parent.getMaxRank(); int lastSection = parent.getMaxRank();
s_log.debug("last section of article is ranked " + lastSection); s_log.debug("last section of article is ranked " + lastSection);
if (firstPageBreak == null || firstPageBreak.intValue() == lastSection) { if (firstPageBreak == null || firstPageBreak.intValue() == lastSection) {
s_log.debug("this is a single page article"); s_log.debug("this is a single page article");
return null; return null;
} else { } else {
s_log.debug("this article has more than one page"); s_log.debug("this article has more than one page");
} }
// okay - this article has more than one page - lets find the page break // okay - this article has more than one page - lets find the page break
// before this section and then the section following that page break // before this section and then the section following that page break
// boolean argument means order by rank descending // boolean argument means order by rank descending
sections = parent.getSections(false); sections = parent.getSections(false);
sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE); sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE);
sections.addFilter( sections.addFilter(
sections.getFilterFactory().lessThan(RANK, getRank(), true)); sections.getFilterFactory().lessThan(RANK, getRank(), true));
Integer topOfPageRank = new Integer(1); Integer topOfPageRank = new Integer(1);
if (sections.next()) { if (sections.next()) {
topOfPageRank = new Integer(sections.getArticleSection().getRank().intValue() + 1); topOfPageRank = new Integer(sections.getArticleSection().getRank().intValue() + 1);
s_log.debug("Found top of page rank: " s_log.debug("Found top of page rank: "
+ topOfPageRank.intValue()); + topOfPageRank.intValue());
} else { } else {
// If no page breaks before this section then we must be on // If no page breaks before this section then we must be on
// page one. // page one.
s_log.debug("This section is on first page."); s_log.debug("This section is on first page.");
} }
sections.close(); sections.close();
// Get 'clean' // Get 'clean'
sections = parent.getSections(false); sections = parent.getSections(false);
sections.addEqualsFilter(RANK, topOfPageRank); sections.addEqualsFilter(RANK, topOfPageRank);
String sectionTitle= null; String sectionTitle= null;
@ -232,10 +226,10 @@ public class ArticleSection extends ContentPage {
sectionTitle = sections.getArticleSection().getTitle(); sectionTitle = sections.getArticleSection().getTitle();
s_log.debug("Found page/section title: " + sectionTitle); s_log.debug("Found page/section title: " + sectionTitle);
} }
return sectionTitle; return sectionTitle;
} }
/** /**
* As sections don't have their own summary, return the parent's search * As sections don't have their own summary, return the parent's search
* summary. * summary.
@ -269,7 +263,7 @@ public class ArticleSection extends ContentPage {
/** /**
* This overrides the method on ContentItem, the API of which * This overrides the method on ContentItem, the API of which
* says that this method can return a null eg. if the method is * says that this method can return a null eg. if the method is
* called on an Article's ImageAsset. * called on an Article's ReusableImageAsset.
* *
* However there seems to be a problem with ArticleSections returning * However there seems to be a problem with ArticleSections returning
* null when they shouldn't. If that happens we are going to look up the * null when they shouldn't. If that happens we are going to look up the

View File

@ -29,8 +29,8 @@ import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.FileUpload; import com.arsdigita.bebop.form.FileUpload;
import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.form.TextField;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ReusableImageAsset;
import com.arsdigita.cms.ui.ImageDisplay; import com.arsdigita.cms.ui.ImageDisplay;
import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil;
import com.arsdigita.dispatcher.MultipartHttpServletRequest; import com.arsdigita.dispatcher.MultipartHttpServletRequest;
@ -61,7 +61,7 @@ public class ImageUploadSection extends FormSection
* *
* @param panel the panel used to lay out the components * @param panel the panel used to lay out the components
*/ */
public ImageUploadSection(String name, public ImageUploadSection(String name,
ItemSelectionModel selImage, ItemSelectionModel selImage,
Container panel) { Container panel) {
super(panel); super(panel);
@ -76,7 +76,7 @@ public class ImageUploadSection extends FormSection
add(m_currentImage); add(m_currentImage);
add(m_imageDisplay); add(m_imageDisplay);
m_spacer = new Label(""); m_spacer = new Label("");
add(m_spacer); add(m_spacer);
m_deleteImage = new Submit("Delete Image"); m_deleteImage = new Submit("Delete Image");
add(m_deleteImage); add(m_deleteImage);
add(new Label( add(new Label(
@ -113,7 +113,7 @@ public class ImageUploadSection extends FormSection
FormData data = event.getFormData(); FormData data = event.getFormData();
PageState state = event.getPageState(); PageState state = event.getPageState();
ImageAsset image = (ImageAsset)m_selImage.getSelectedObject(state); ReusableImageAsset image = (ReusableImageAsset)m_selImage.getSelectedObject(state);
m_currentImage.setVisible(state, false); m_currentImage.setVisible(state, false);
m_imageDisplay.setVisible(state, false); m_imageDisplay.setVisible(state, false);
@ -162,16 +162,16 @@ public class ImageUploadSection extends FormSection
* Process the image upload. Should be called form the form * Process the image upload. Should be called form the form
* process listener. * process listener.
*/ */
public ImageAsset processImageUpload(FormSectionEvent event) { public ReusableImageAsset processImageUpload(FormSectionEvent event) {
ImageAsset a = null; ReusableImageAsset a = null;
FormData data = event.getFormData(); FormData data = event.getFormData();
File image = getImage(event); File image = getImage(event);
if ( image != null ) { if ( image != null ) {
try { try {
a = new ImageAsset(); a = new ReusableImageAsset();
a.loadFromFile(getImageFilename(event), image, ImageAsset.MIME_JPEG); a.loadFromFile(getImageFilename(event), image, ReusableImageAsset.MIME_JPEG);
a.setDescription((String)data.get(m_name + CAPTION)); a.setDescription((String)data.get(m_name + CAPTION));
} catch ( Exception ex ) { } catch ( Exception ex ) {
log.error("Could not load " + getImageFilename(event)); log.error("Could not load " + getImageFilename(event));

View File

@ -37,7 +37,7 @@ import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener; import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.TrimmedStringParameter; import com.arsdigita.bebop.parameters.TrimmedStringParameter;
import com.arsdigita.cms.ImageAsset; import com.arsdigita.cms.ReusableImageAsset;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.TextAsset; import com.arsdigita.cms.TextAsset;
import com.arsdigita.cms.contenttypes.ArticleSection; import com.arsdigita.cms.contenttypes.ArticleSection;
@ -109,8 +109,8 @@ public class SectionEditForm extends Form {
m_container = container; m_container = container;
m_imageParam = new BigDecimalParameter(IMAGE_PARAM); m_imageParam = new BigDecimalParameter(IMAGE_PARAM);
m_selImage = new ItemSelectionModel(ImageAsset.class.getName(), m_selImage = new ItemSelectionModel(ReusableImageAsset.class.getName(),
ImageAsset.BASE_DATA_OBJECT_TYPE, ReusableImageAsset.BASE_DATA_OBJECT_TYPE,
m_imageParam); m_imageParam);
m_textParam = new BigDecimalParameter(TEXT_PARAM); m_textParam = new BigDecimalParameter(TEXT_PARAM);
@ -168,7 +168,7 @@ public class SectionEditForm extends Form {
add(new Label(MPArticleGlobalizationUtil add(new Label(MPArticleGlobalizationUtil
.globalize("cms.contenttypes.ui.mparticle.body_text")), .globalize("cms.contenttypes.ui.mparticle.body_text")),
ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH); ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH);
CMSDHTMLEditor textWidget = CMSDHTMLEditor textWidget =
new CMSDHTMLEditor(new TrimmedStringParameter(TEXT)); new CMSDHTMLEditor(new TrimmedStringParameter(TEXT));
textWidget.setRows(40); textWidget.setRows(40);
textWidget.setCols(70); textWidget.setCols(70);
@ -177,7 +177,7 @@ public class SectionEditForm extends Form {
ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH); ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH);
add(new Label(MPArticleGlobalizationUtil add(new Label(MPArticleGlobalizationUtil
.globalize("cms.contenttypes.ui.mparticle.image")), .globalize("cms.contenttypes.ui.mparticle.image")),
ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
m_imageUpload = new ImageUploadSection("image", m_selImage); m_imageUpload = new ImageUploadSection("image", m_selImage);
@ -195,43 +195,43 @@ public class SectionEditForm extends Form {
* into the form fields. * into the form fields.
*/ */
private class SectionInitListener implements FormInitListener { private class SectionInitListener implements FormInitListener {
public void init( FormSectionEvent event ) public void init( FormSectionEvent event )
throws FormProcessException { throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
FormData data = event.getFormData(); FormData data = event.getFormData();
m_selImage.setSelectedObject(state, null); m_selImage.setSelectedObject(state, null);
m_selText.setSelectedObject(state,null); m_selText.setSelectedObject(state,null);
if ( m_selSection.getSelectedKey(state) != null ) { if ( m_selSection.getSelectedKey(state) != null ) {
BigDecimal id = new BigDecimal(m_selSection BigDecimal id = new BigDecimal(m_selSection
.getSelectedKey(state).toString()); .getSelectedKey(state).toString());
try { try {
// retrieve the selected Section from the persistence layer // retrieve the selected Section from the persistence layer
ArticleSection section = new ArticleSection(id); ArticleSection section = new ArticleSection(id);
data.put(TITLE, section.getTitle()); data.put(TITLE, section.getTitle());
TextAsset t = section.getText(); TextAsset t = section.getText();
if ( t != null ) { if ( t != null ) {
m_selText.setSelectedObject(state, t); m_selText.setSelectedObject(state, t);
data.put(TEXT, t.getText()); data.put(TEXT, t.getText());
} }
ImageAsset img = section.getImage(); ReusableImageAsset img = section.getImage();
if (img != null) { if (img != null) {
m_selImage.setSelectedObject(state, img); m_selImage.setSelectedObject(state, img);
} }
if (section.isPageBreak()) { if (section.isPageBreak()) {
data.put(PAGE_BREAK, new Object[] { "true" }); data.put(PAGE_BREAK, new Object[] { "true" });
} }
} catch ( DataObjectNotFoundException ex ) { } catch ( DataObjectNotFoundException ex ) {
log.error("Section(" + id + ") could not be found"); log.error("Section(" + id + ") could not be found");
} }
} }
// Wait until the image selection model is updated before // Wait until the image selection model is updated before
// initializing the image section // initializing the image section
m_imageUpload.initImageUpload(event); m_imageUpload.initImageUpload(event);
@ -244,10 +244,10 @@ public class SectionEditForm extends Form {
* cancel button. If they did, don't continue with the form. * cancel button. If they did, don't continue with the form.
*/ */
private class SectionSubmissionListener implements FormSubmissionListener { private class SectionSubmissionListener implements FormSubmissionListener {
public void submitted( FormSectionEvent event ) public void submitted( FormSectionEvent event )
throws FormProcessException { throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
if ( m_saveCancelSection.getCancelButton() if ( m_saveCancelSection.getCancelButton()
.isSelected(state) && m_container != null) { .isSelected(state) && m_container != null) {
m_container.onlyShowComponent( m_container.onlyShowComponent(
@ -267,7 +267,7 @@ public class SectionEditForm extends Form {
} catch ( DataObjectNotFoundException ex ) { } catch ( DataObjectNotFoundException ex ) {
log.error("Section(" + id + ") could not be found"); log.error("Section(" + id + ") could not be found");
} }
} }
} }
} }
@ -277,52 +277,52 @@ public class SectionEditForm extends Form {
* assign it to the current MultiPartArticle. * assign it to the current MultiPartArticle.
*/ */
private class SectionProcessListener implements FormProcessListener { private class SectionProcessListener implements FormProcessListener {
public void process( FormSectionEvent event ) public void process( FormSectionEvent event )
throws FormProcessException { throws FormProcessException {
PageState state = event.getPageState(); PageState state = event.getPageState();
FormData data = event.getFormData(); FormData data = event.getFormData();
// retrieve the current MultiPartArticle // retrieve the current MultiPartArticle
BigDecimal id = new BigDecimal( BigDecimal id = new BigDecimal(
m_selArticle.getSelectedKey(state).toString()); m_selArticle.getSelectedKey(state).toString());
MultiPartArticle article = null; MultiPartArticle article = null;
try { try {
article = new MultiPartArticle(id); article = new MultiPartArticle(id);
} catch ( DataObjectNotFoundException ex ) { } catch ( DataObjectNotFoundException ex ) {
throw new UncheckedWrapperException(ex); throw new UncheckedWrapperException(ex);
} }
// get the selected section to update or create a new one // get the selected section to update or create a new one
ArticleSection section = (ArticleSection) ArticleSection section = (ArticleSection)
m_selSection.getSelectedObject(state); m_selSection.getSelectedObject(state);
if ( section == null ) { if ( section == null ) {
section = createSection(event, article); section = createSection(event, article);
article.addSection(section); article.addSection(section);
} }
section.setTitle((String)data.get(TITLE)); section.setTitle((String)data.get(TITLE));
Object[] pageBreakVal = (Object[])data.get(PAGE_BREAK); Object[] pageBreakVal = (Object[])data.get(PAGE_BREAK);
boolean pageBreak; boolean pageBreak;
if (pageBreakVal == null || if (pageBreakVal == null ||
pageBreakVal.length == 0 || pageBreakVal.length == 0 ||
!"true".equals(pageBreakVal[0])) { !"true".equals(pageBreakVal[0])) {
pageBreak = false; pageBreak = false;
} else { } else {
pageBreak = true; pageBreak = true;
} }
section.setPageBreak(pageBreak); section.setPageBreak(pageBreak);
// get the image asset // get the image asset
ImageAsset imageAsset = m_imageUpload.processImageUpload(event); ReusableImageAsset reusableImageAsset = m_imageUpload.processImageUpload(event);
if ( imageAsset != null ) { if ( reusableImageAsset != null ) {
section.setImage(imageAsset); section.setImage(reusableImageAsset);
m_selImage.setSelectedObject(state, imageAsset); m_selImage.setSelectedObject(state, reusableImageAsset);
} }
// get the text asset // get the text asset
TextAsset textAsset = (TextAsset)m_selText.getSelectedObject(state); TextAsset textAsset = (TextAsset)m_selText.getSelectedObject(state);
if ( textAsset == null ) { if ( textAsset == null ) {
@ -331,27 +331,27 @@ public class SectionEditForm extends Form {
m_selText.setSelectedObject(state, textAsset); m_selText.setSelectedObject(state, textAsset);
section.setText(textAsset); section.setText(textAsset);
} }
String text = (String)data.get(TEXT); String text = (String)data.get(TEXT);
if ( text == null ) { if ( text == null ) {
text = ""; text = "";
} }
textAsset.setText(text); textAsset.setText(text);
if ( m_container != null) { if ( m_container != null) {
m_container.onlyShowComponent( m_container.onlyShowComponent(
state, state,
MultiPartArticleViewSections.SECTION_TABLE+ MultiPartArticleViewSections.SECTION_TABLE+
m_container.getTypeIDStr()); m_container.getTypeIDStr());
} }
} }
} }
/** /**
* Utility method to create a Section from the form data supplied. * Utility method to create a Section from the form data supplied.
*/ */
protected ArticleSection createSection(FormSectionEvent event, protected ArticleSection createSection(FormSectionEvent event,
MultiPartArticle article) { MultiPartArticle article) {
PageState state = event.getPageState(); PageState state = event.getPageState();