MPA ImageAsset durch ReusableImageAsset ersetzt
git-svn-id: https://svn.libreccm.org/ccm/trunk@1538 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
291e6bbe68
commit
18eb7f05c6
|
|
@ -21,7 +21,7 @@ model com.arsdigita.cms.contenttypes;
|
|||
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
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
|
||||
|
||||
|
|
@ -32,8 +32,8 @@ object type ArticleSection extends ContentPage {
|
|||
component TextAsset[0..1] text = join ct_mp_sections.text
|
||||
to cms_text.text_id;
|
||||
|
||||
component ImageAsset[0..1] image = join ct_mp_sections.image
|
||||
to cms_images.image_id;
|
||||
component ReusableImageAsset[0..1] image = join ct_mp_sections.image
|
||||
to cms_images.image_id;
|
||||
|
||||
reference key (ct_mp_sections.section_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,21 +18,15 @@
|
|||
*/
|
||||
package com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
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.cms.*;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.kernel.ACSObject;
|
||||
import com.arsdigita.kernel.permissions.PermissionService;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Represents a section within a MultiPartArticle
|
||||
|
|
@ -63,7 +57,7 @@ public class ArticleSection extends ContentPage {
|
|||
*
|
||||
* @param id the id of the object to retrieve
|
||||
*/
|
||||
public ArticleSection(BigDecimal id)
|
||||
public ArticleSection(BigDecimal id)
|
||||
throws DataObjectNotFoundException {
|
||||
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
|
||||
*/
|
||||
public ArticleSection(OID id)
|
||||
public ArticleSection(OID id)
|
||||
throws DataObjectNotFoundException {
|
||||
super(id);
|
||||
}
|
||||
|
|
@ -100,7 +94,7 @@ public class ArticleSection extends ContentPage {
|
|||
}
|
||||
|
||||
/** Accessor. Get this item's rank in the set of ArticleSections */
|
||||
|
||||
|
||||
public Integer getRank() {
|
||||
return (Integer)get(RANK);
|
||||
}
|
||||
|
|
@ -109,7 +103,7 @@ public class ArticleSection extends ContentPage {
|
|||
|
||||
public void setRank(Integer rank) {
|
||||
set(RANK, rank);
|
||||
}
|
||||
}
|
||||
|
||||
public MultiPartArticle getMPArticle() {
|
||||
DataObject obj = (DataObject) get( MP_ARTICLE );
|
||||
|
|
@ -130,21 +124,21 @@ public class ArticleSection extends ContentPage {
|
|||
}
|
||||
|
||||
/** Accessor. Get the image associated with this item. */
|
||||
public ImageAsset getImage() {
|
||||
public ReusableImageAsset getImage() {
|
||||
if ( get(IMAGE) == null ) {
|
||||
return null;
|
||||
}
|
||||
return new ImageAsset((DataObject)get(IMAGE));
|
||||
return new ReusableImageAsset((DataObject)get(IMAGE));
|
||||
}
|
||||
|
||||
/** Mutator. Set the image associated with this item. */
|
||||
public void setImage(ImageAsset image) {
|
||||
public void setImage(ReusableImageAsset image) {
|
||||
setAssociation(IMAGE, image);
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
|
||||
if (isNew()) {
|
||||
set(PAGE_BREAK, Boolean.FALSE);
|
||||
}
|
||||
|
|
@ -160,30 +154,30 @@ public class ArticleSection extends ContentPage {
|
|||
|
||||
/**
|
||||
* Depending on config parameter, either return the title
|
||||
* of the section
|
||||
*
|
||||
* of the section
|
||||
*
|
||||
* 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
|
||||
* the whole multipart article appears on one page,
|
||||
* the whole multipart article appears on one page,
|
||||
* in which case null is returned.
|
||||
*/
|
||||
public String getPageTitle() {
|
||||
|
||||
|
||||
if (MultiPartArticle.getConfig().useSectionTitle()) {
|
||||
return getTitle();
|
||||
}
|
||||
|
||||
|
||||
s_log.debug("retrieve pageTitle for section " + getTitle() + " ranked " + getRank());
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
ArticleSectionCollection sections = parent.getSections(true);
|
||||
sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE);
|
||||
|
|
@ -195,36 +189,36 @@ public class ArticleSection extends ContentPage {
|
|||
sections.close();
|
||||
int lastSection = parent.getMaxRank();
|
||||
s_log.debug("last section of article is ranked " + lastSection);
|
||||
|
||||
|
||||
if (firstPageBreak == null || firstPageBreak.intValue() == lastSection) {
|
||||
s_log.debug("this is a single page article");
|
||||
return null;
|
||||
} else {
|
||||
s_log.debug("this article has more than one page");
|
||||
}
|
||||
|
||||
|
||||
// okay - this article has more than one page - lets find the page break
|
||||
// before this section and then the section following that page break
|
||||
// boolean argument means order by rank descending
|
||||
|
||||
|
||||
sections = parent.getSections(false);
|
||||
sections.addEqualsFilter(PAGE_BREAK, Boolean.TRUE);
|
||||
sections.addFilter(
|
||||
sections.getFilterFactory().lessThan(RANK, getRank(), true));
|
||||
|
||||
|
||||
Integer topOfPageRank = new Integer(1);
|
||||
if (sections.next()) {
|
||||
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());
|
||||
} 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.
|
||||
s_log.debug("This section is on first page.");
|
||||
}
|
||||
sections.close();
|
||||
|
||||
// Get 'clean'
|
||||
|
||||
// Get 'clean'
|
||||
sections = parent.getSections(false);
|
||||
sections.addEqualsFilter(RANK, topOfPageRank);
|
||||
String sectionTitle= null;
|
||||
|
|
@ -232,10 +226,10 @@ public class ArticleSection extends ContentPage {
|
|||
sectionTitle = sections.getArticleSection().getTitle();
|
||||
s_log.debug("Found page/section title: " + sectionTitle);
|
||||
}
|
||||
|
||||
|
||||
return sectionTitle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* As sections don't have their own summary, return the parent's search
|
||||
* summary.
|
||||
|
|
@ -269,7 +263,7 @@ public class ArticleSection extends ContentPage {
|
|||
/**
|
||||
* This overrides the method on ContentItem, the API of which
|
||||
* 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
|
||||
* null when they shouldn't. If that happens we are going to look up the
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ import com.arsdigita.bebop.event.FormSectionEvent;
|
|||
import com.arsdigita.bebop.form.FileUpload;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.cms.ImageAsset;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ReusableImageAsset;
|
||||
import com.arsdigita.cms.ui.ImageDisplay;
|
||||
import com.arsdigita.cms.contenttypes.util.MPArticleGlobalizationUtil;
|
||||
import com.arsdigita.dispatcher.MultipartHttpServletRequest;
|
||||
|
|
@ -61,7 +61,7 @@ public class ImageUploadSection extends FormSection
|
|||
*
|
||||
* @param panel the panel used to lay out the components
|
||||
*/
|
||||
public ImageUploadSection(String name,
|
||||
public ImageUploadSection(String name,
|
||||
ItemSelectionModel selImage,
|
||||
Container panel) {
|
||||
super(panel);
|
||||
|
|
@ -76,7 +76,7 @@ public class ImageUploadSection extends FormSection
|
|||
add(m_currentImage);
|
||||
add(m_imageDisplay);
|
||||
m_spacer = new Label("");
|
||||
add(m_spacer);
|
||||
add(m_spacer);
|
||||
m_deleteImage = new Submit("Delete Image");
|
||||
add(m_deleteImage);
|
||||
add(new Label(
|
||||
|
|
@ -113,7 +113,7 @@ public class ImageUploadSection extends FormSection
|
|||
FormData data = event.getFormData();
|
||||
PageState state = event.getPageState();
|
||||
|
||||
ImageAsset image = (ImageAsset)m_selImage.getSelectedObject(state);
|
||||
ReusableImageAsset image = (ReusableImageAsset)m_selImage.getSelectedObject(state);
|
||||
|
||||
m_currentImage.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 listener.
|
||||
*/
|
||||
public ImageAsset processImageUpload(FormSectionEvent event) {
|
||||
ImageAsset a = null;
|
||||
public ReusableImageAsset processImageUpload(FormSectionEvent event) {
|
||||
ReusableImageAsset a = null;
|
||||
FormData data = event.getFormData();
|
||||
|
||||
File image = getImage(event);
|
||||
|
||||
if ( image != null ) {
|
||||
try {
|
||||
a = new ImageAsset();
|
||||
a.loadFromFile(getImageFilename(event), image, ImageAsset.MIME_JPEG);
|
||||
a = new ReusableImageAsset();
|
||||
a.loadFromFile(getImageFilename(event), image, ReusableImageAsset.MIME_JPEG);
|
||||
a.setDescription((String)data.get(m_name + CAPTION));
|
||||
} catch ( Exception ex ) {
|
||||
log.error("Could not load " + getImageFilename(event));
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import com.arsdigita.bebop.form.Option;
|
|||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
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.TextAsset;
|
||||
import com.arsdigita.cms.contenttypes.ArticleSection;
|
||||
|
|
@ -109,8 +109,8 @@ public class SectionEditForm extends Form {
|
|||
m_container = container;
|
||||
|
||||
m_imageParam = new BigDecimalParameter(IMAGE_PARAM);
|
||||
m_selImage = new ItemSelectionModel(ImageAsset.class.getName(),
|
||||
ImageAsset.BASE_DATA_OBJECT_TYPE,
|
||||
m_selImage = new ItemSelectionModel(ReusableImageAsset.class.getName(),
|
||||
ReusableImageAsset.BASE_DATA_OBJECT_TYPE,
|
||||
m_imageParam);
|
||||
|
||||
m_textParam = new BigDecimalParameter(TEXT_PARAM);
|
||||
|
|
@ -168,7 +168,7 @@ public class SectionEditForm extends Form {
|
|||
add(new Label(MPArticleGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.mparticle.body_text")),
|
||||
ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH);
|
||||
CMSDHTMLEditor textWidget =
|
||||
CMSDHTMLEditor textWidget =
|
||||
new CMSDHTMLEditor(new TrimmedStringParameter(TEXT));
|
||||
textWidget.setRows(40);
|
||||
textWidget.setCols(70);
|
||||
|
|
@ -177,7 +177,7 @@ public class SectionEditForm extends Form {
|
|||
ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH);
|
||||
|
||||
add(new Label(MPArticleGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.mparticle.image")),
|
||||
.globalize("cms.contenttypes.ui.mparticle.image")),
|
||||
ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||
|
||||
m_imageUpload = new ImageUploadSection("image", m_selImage);
|
||||
|
|
@ -195,43 +195,43 @@ public class SectionEditForm extends Form {
|
|||
* into the form fields.
|
||||
*/
|
||||
private class SectionInitListener implements FormInitListener {
|
||||
public void init( FormSectionEvent event )
|
||||
public void init( FormSectionEvent event )
|
||||
throws FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
FormData data = event.getFormData();
|
||||
m_selImage.setSelectedObject(state, null);
|
||||
m_selText.setSelectedObject(state,null);
|
||||
|
||||
|
||||
|
||||
|
||||
if ( m_selSection.getSelectedKey(state) != null ) {
|
||||
BigDecimal id = new BigDecimal(m_selSection
|
||||
.getSelectedKey(state).toString());
|
||||
try {
|
||||
// retrieve the selected Section from the persistence layer
|
||||
ArticleSection section = new ArticleSection(id);
|
||||
|
||||
|
||||
data.put(TITLE, section.getTitle());
|
||||
|
||||
|
||||
TextAsset t = section.getText();
|
||||
if ( t != null ) {
|
||||
m_selText.setSelectedObject(state, t);
|
||||
data.put(TEXT, t.getText());
|
||||
}
|
||||
|
||||
ImageAsset img = section.getImage();
|
||||
|
||||
ReusableImageAsset img = section.getImage();
|
||||
if (img != null) {
|
||||
m_selImage.setSelectedObject(state, img);
|
||||
}
|
||||
|
||||
|
||||
if (section.isPageBreak()) {
|
||||
data.put(PAGE_BREAK, new Object[] { "true" });
|
||||
}
|
||||
|
||||
|
||||
} catch ( DataObjectNotFoundException ex ) {
|
||||
log.error("Section(" + id + ") could not be found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wait until the image selection model is updated before
|
||||
// initializing the image section
|
||||
m_imageUpload.initImageUpload(event);
|
||||
|
|
@ -244,10 +244,10 @@ public class SectionEditForm extends Form {
|
|||
* cancel button. If they did, don't continue with the form.
|
||||
*/
|
||||
private class SectionSubmissionListener implements FormSubmissionListener {
|
||||
public void submitted( FormSectionEvent event )
|
||||
public void submitted( FormSectionEvent event )
|
||||
throws FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
|
||||
|
||||
if ( m_saveCancelSection.getCancelButton()
|
||||
.isSelected(state) && m_container != null) {
|
||||
m_container.onlyShowComponent(
|
||||
|
|
@ -267,7 +267,7 @@ public class SectionEditForm extends Form {
|
|||
} catch ( DataObjectNotFoundException ex ) {
|
||||
log.error("Section(" + id + ") could not be found");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -277,52 +277,52 @@ public class SectionEditForm extends Form {
|
|||
* assign it to the current MultiPartArticle.
|
||||
*/
|
||||
private class SectionProcessListener implements FormProcessListener {
|
||||
public void process( FormSectionEvent event )
|
||||
public void process( FormSectionEvent event )
|
||||
throws FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
FormData data = event.getFormData();
|
||||
|
||||
|
||||
// retrieve the current MultiPartArticle
|
||||
BigDecimal id = new BigDecimal(
|
||||
m_selArticle.getSelectedKey(state).toString());
|
||||
MultiPartArticle article = null;
|
||||
|
||||
|
||||
try {
|
||||
article = new MultiPartArticle(id);
|
||||
} catch ( DataObjectNotFoundException ex ) {
|
||||
throw new UncheckedWrapperException(ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// get the selected section to update or create a new one
|
||||
ArticleSection section = (ArticleSection)
|
||||
m_selSection.getSelectedObject(state);
|
||||
if ( section == null ) {
|
||||
section = createSection(event, article);
|
||||
section = createSection(event, article);
|
||||
article.addSection(section);
|
||||
}
|
||||
|
||||
|
||||
section.setTitle((String)data.get(TITLE));
|
||||
|
||||
|
||||
Object[] pageBreakVal = (Object[])data.get(PAGE_BREAK);
|
||||
boolean pageBreak;
|
||||
if (pageBreakVal == null ||
|
||||
pageBreakVal.length == 0 ||
|
||||
if (pageBreakVal == null ||
|
||||
pageBreakVal.length == 0 ||
|
||||
!"true".equals(pageBreakVal[0])) {
|
||||
pageBreak = false;
|
||||
} else {
|
||||
pageBreak = true;
|
||||
}
|
||||
section.setPageBreak(pageBreak);
|
||||
|
||||
|
||||
// get the image asset
|
||||
ImageAsset imageAsset = m_imageUpload.processImageUpload(event);
|
||||
if ( imageAsset != null ) {
|
||||
section.setImage(imageAsset);
|
||||
m_selImage.setSelectedObject(state, imageAsset);
|
||||
ReusableImageAsset reusableImageAsset = m_imageUpload.processImageUpload(event);
|
||||
if ( reusableImageAsset != null ) {
|
||||
section.setImage(reusableImageAsset);
|
||||
m_selImage.setSelectedObject(state, reusableImageAsset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// get the text asset
|
||||
TextAsset textAsset = (TextAsset)m_selText.getSelectedObject(state);
|
||||
if ( textAsset == null ) {
|
||||
|
|
@ -331,27 +331,27 @@ public class SectionEditForm extends Form {
|
|||
m_selText.setSelectedObject(state, textAsset);
|
||||
section.setText(textAsset);
|
||||
}
|
||||
|
||||
|
||||
String text = (String)data.get(TEXT);
|
||||
if ( text == null ) {
|
||||
text = "";
|
||||
}
|
||||
|
||||
|
||||
textAsset.setText(text);
|
||||
if ( m_container != null) {
|
||||
m_container.onlyShowComponent(
|
||||
state,
|
||||
state,
|
||||
MultiPartArticleViewSections.SECTION_TABLE+
|
||||
m_container.getTypeIDStr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Utility method to create a Section from the form data supplied.
|
||||
*/
|
||||
protected ArticleSection createSection(FormSectionEvent event,
|
||||
protected ArticleSection createSection(FormSectionEvent event,
|
||||
MultiPartArticle article) {
|
||||
|
||||
PageState state = event.getPageState();
|
||||
|
|
|
|||
Loading…
Reference in New Issue