Validierung auf doppelte URL beim Bearbeiten eingefügt (Ticket #1261).

git-svn-id: https://svn.libreccm.org/ccm/trunk@1682 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-06-04 13:55:18 +00:00
parent ec2f5b22ff
commit f2a0bf9ba3
1 changed files with 35 additions and 31 deletions

View File

@ -32,6 +32,7 @@ import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
@ -49,7 +50,6 @@ import java.util.Date;
public abstract class BasicPageForm extends BasicItemForm { public abstract class BasicPageForm extends BasicItemForm {
private FormSection m_widgetSection; private FormSection m_widgetSection;
// public static final String DESCRIPTION = ContentPage.DESCRIPTION; // public static final String DESCRIPTION = ContentPage.DESCRIPTION;
public static final String LAUNCH_DATE = ContentPage.LAUNCH_DATE; public static final String LAUNCH_DATE = ContentPage.LAUNCH_DATE;
@ -72,13 +72,12 @@ public abstract class BasicPageForm extends BasicItemForm {
* @param itemModel The {@link ItemSelectionModel} which will * @param itemModel The {@link ItemSelectionModel} which will
* be responsible for loading the current item * be responsible for loading the current item
*/ */
public BasicPageForm(String formName, public BasicPageForm(String formName,
ColumnPanel columnPanel, ColumnPanel columnPanel,
ItemSelectionModel itemModel) { ItemSelectionModel itemModel) {
super(formName, columnPanel, itemModel); super(formName, columnPanel, itemModel);
} }
/** /**
* Add various widgets to the form. Child classes should override * Add various widgets to the form. Child classes should override
* this method to perform all their widget-adding needs * this method to perform all their widget-adding needs
@ -95,11 +94,9 @@ public abstract class BasicPageForm extends BasicItemForm {
// add(description); // add(description);
// //
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
add(new Label(GlobalizationUtil. add(new Label(GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date")));
globalize("cms.ui.authoring.page_launch_date")));
ParameterModel launchDateParam = new DateParameter(LAUNCH_DATE); ParameterModel launchDateParam = new DateParameter(LAUNCH_DATE);
com.arsdigita.bebop.form.Date launchDate com.arsdigita.bebop.form.Date launchDate = new com.arsdigita.bebop.form.Date(launchDateParam);
= new com.arsdigita.bebop.form.Date(launchDateParam);
if (ContentSection.getConfig().getRequireLaunchDate()) { if (ContentSection.getConfig().getRequireLaunchDate()) {
launchDate.addValidationListener(new LaunchDateValidationListener()); launchDate.addValidationListener(new LaunchDateValidationListener());
// if launch date is required, help user by suggesting today's date // if launch date is required, help user by suggesting today's date
@ -124,7 +121,7 @@ public abstract class BasicPageForm extends BasicItemForm {
FormData data = e.getFormData(); FormData data = e.getFormData();
PageState state = e.getPageState(); PageState state = e.getPageState();
ContentPage item = ContentPage item =
(ContentPage)getItemSelectionModel().getSelectedObject(state); (ContentPage) getItemSelectionModel().getSelectedObject(state);
if (item != null) { if (item != null) {
// Preset fields // Preset fields
@ -134,16 +131,23 @@ public abstract class BasicPageForm extends BasicItemForm {
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
data.put(LAUNCH_DATE, item.getLaunchDate()); data.put(LAUNCH_DATE, item.getLaunchDate());
// if launch date is required, help user by suggesting today's date // if launch date is required, help user by suggesting today's date
if (ContentSection.getConfig().getRequireLaunchDate() if (ContentSection.getConfig().getRequireLaunchDate()
&& item.getLaunchDate() == null) { && item.getLaunchDate() == null) {
data.put(LAUNCH_DATE, new Date()); data.put(LAUNCH_DATE, new Date());
} }
} }
} }
return item; return item;
} }
@Override
public void validate(final FormSectionEvent fse) throws FormProcessException {
final Folder folder = (Folder) getItemSelectionModel().getSelectedItem(fse.getPageState()).getParent();
Assert.exists(folder);
validateNameUniqueness(folder, fse);
}
/** /**
* Utility method to process the name/title widgets. Child classes * Utility method to process the name/title widgets. Child classes
* may call this method from the process listener. * may call this method from the process listener.
@ -157,15 +161,15 @@ public abstract class BasicPageForm extends BasicItemForm {
FormData data = e.getFormData(); FormData data = e.getFormData();
PageState state = e.getPageState(); PageState state = e.getPageState();
ContentPage item = ContentPage item =
(ContentPage)getItemSelectionModel().getSelectedObject(state); (ContentPage) getItemSelectionModel().getSelectedObject(state);
if (item != null) { if (item != null) {
// Update attributes // Update attributes
item.setName((String)data.get(NAME)); item.setName((String) data.get(NAME));
item.setTitle((String)data.get(TITLE)); item.setTitle((String) data.get(TITLE));
// item.setDescription((String)data.get(DESCRIPTION)); // item.setDescription((String)data.get(DESCRIPTION));
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
item.setLaunchDate((Date)data.get(LAUNCH_DATE)); item.setLaunchDate((Date) data.get(LAUNCH_DATE));
} }
} }
@ -183,8 +187,8 @@ public abstract class BasicPageForm extends BasicItemForm {
* @pre state != null * @pre state != null
* @post return != null * @post return != null
*/ */
public ContentPage createContentPage(PageState state) public ContentPage createContentPage(PageState state)
throws FormProcessException { throws FormProcessException {
ItemSelectionModel m = getItemSelectionModel(); ItemSelectionModel m = getItemSelectionModel();
Assert.exists(m); Assert.exists(m);
@ -195,8 +199,8 @@ public abstract class BasicPageForm extends BasicItemForm {
try { try {
item = (ContentPage) m.createItem(); item = (ContentPage) m.createItem();
} catch (ServletException ex) { } catch (ServletException ex) {
throw new throw new FormProcessException((String) GlobalizationUtil.globalize(
FormProcessException((String)GlobalizationUtil.globalize("cms.ui.authoring.couldnt_create_contentpage").localize(), ex); "cms.ui.authoring.couldnt_create_contentpage").localize(), ex);
} }
// Make sure the item will be remembered across requests // Make sure the item will be remembered across requests
@ -211,16 +215,16 @@ public abstract class BasicPageForm extends BasicItemForm {
public class LaunchDateValidationListener implements ParameterListener { public class LaunchDateValidationListener implements ParameterListener {
@Override @Override
public void validate(final ParameterEvent e) { public void validate(final ParameterEvent e) {
final ParameterData data = e.getParameterData(); final ParameterData data = e.getParameterData();
final Object value = data.getValue(); final Object value = data.getValue();
if (value == null) {
data.addError("launch date is required");
return;
}
}
if (value == null) {
data.addError("launch date is required");
return;
}
}
} }
} }