LinkPropertyForm

Validierung erweitert, so daß Links auf sich selbst ausgeschlossen werden.

git-svn-id: https://svn.libreccm.org/ccm/trunk@1481 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-01-30 13:58:29 +00:00
parent 050cd8bb3c
commit 503d7519c2
1 changed files with 53 additions and 37 deletions

View File

@ -58,17 +58,21 @@ import java.net.URL;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Form to edit the basic properties of an Link. This form can be * Form to edit the basic properties of an Link. This form can be extended to
* extended to create forms for Link subclasses. * create forms for Link subclasses.
*
* @version $Revision: #5 $ $Date: 2004/08/17 $ * @version $Revision: #5 $ $Date: 2004/08/17 $
* @author Nobuko Asakai (nasakai@redhat.com) * @author Nobuko Asakai (nasakai@redhat.com)
* @author Sören Bernstein (sbernstein@zes.uni-bremen.de)
*/ */
public class LinkPropertyForm extends FormSection public class LinkPropertyForm extends FormSection
implements FormInitListener, FormProcessListener, FormValidationListener, implements FormInitListener, FormProcessListener, FormValidationListener,
FormSubmissionListener { FormSubmissionListener {
private static final Logger s_log = Logger.getLogger(LinkPropertyForm.class); private static final Logger s_log = Logger.getLogger(LinkPropertyForm.class);
/** Name of this form */ /**
* Name of this form
*/
public static final String ID = "link_edit"; public static final String ID = "link_edit";
public static final String SSL_PROTOCOL = "https://"; public static final String SSL_PROTOCOL = "https://";
public static final String HTTP_PROTOCOL = "http://"; public static final String HTTP_PROTOCOL = "http://";
@ -77,29 +81,29 @@ public class LinkPropertyForm extends FormSection
private TextField m_targetURI; private TextField m_targetURI;
private RadioGroup m_linkType; private RadioGroup m_linkType;
private CheckboxGroup m_URIOption; private CheckboxGroup m_URIOption;
private ItemSelectionModel m_itemModel; protected ItemSelectionModel m_itemModel;
private LinkSelectionModel m_linkModel; private LinkSelectionModel m_linkModel;
private SaveCancelSection m_saveCancelSection; private SaveCancelSection m_saveCancelSection;
private ItemSearchWidget m_itemSearch; private ItemSearchWidget m_itemSearch;
private TextField m_itemParams; private TextField m_itemParams;
private ContentType m_contentType; private ContentType m_contentType;
private final String ITEM_SEARCH = "contentItem"; protected final String ITEM_SEARCH = "contentItem";
/** /**
* Creates a new form to edit the Link object specified * Creates a new form to edit the Link object specified by the item
* by the item selection model passed in. * selection model passed in.
* @param itemModel The ItemSelectionModel to use to obtain the *
* ContentItem to which this link is (or will be) attached * @param itemModel The ItemSelectionModel to use to obtain the ContentItem
* @param link The LinkSelectionModel to use to obtain the * to which this link is (or will be) attached
* Link to work on * @param link The LinkSelectionModel to use to obtain the Link to work on
*/ */
public LinkPropertyForm(ItemSelectionModel itemModel, public LinkPropertyForm(ItemSelectionModel itemModel,
LinkSelectionModel link) { LinkSelectionModel link) {
this(itemModel, link, null); this(itemModel, link, null);
} }
public LinkPropertyForm(ItemSelectionModel itemModel, public LinkPropertyForm(ItemSelectionModel itemModel,
LinkSelectionModel link, ContentType contentType) { LinkSelectionModel link, ContentType contentType) {
super(new ColumnPanel(2)); super(new ColumnPanel(2));
s_log.debug("property form constructor"); s_log.debug("property form constructor");
m_linkModel = link; m_linkModel = link;
@ -166,7 +170,7 @@ public class LinkPropertyForm extends FormSection
false)); false));
add(new Label("Choose either a URL or a Content Item", Label.BOLD), add(new Label("Choose either a URL or a Content Item", Label.BOLD),
ColumnPanel.FULL_WIDTH); ColumnPanel.FULL_WIDTH);
m_linkType = new RadioGroup("linkType"); m_linkType = new RadioGroup("linkType");
Option m_external = new Option(Link.EXTERNAL_LINK, "URL"); Option m_external = new Option(Link.EXTERNAL_LINK, "URL");
//m_external.setOnClick("toggle_link_fields(false)"); //m_external.setOnClick("toggle_link_fields(false)");
@ -177,7 +181,7 @@ public class LinkPropertyForm extends FormSection
m_internal.setOnClick("enableItemFields()"); m_internal.setOnClick("enableItemFields()");
Option m_selectWindow = new Option(Link.TARGET_WINDOW, Option m_selectWindow = new Option(Link.TARGET_WINDOW,
"Open URL in new window"); "Open URL in new window");
m_URIOption = new CheckboxGroup("openOption"); m_URIOption = new CheckboxGroup("openOption");
m_URIOption.addOption(m_selectWindow); m_URIOption.addOption(m_selectWindow);
@ -224,7 +228,9 @@ public class LinkPropertyForm extends FormSection
false)); false));
} }
/** Adds the saveCancelSection */ /**
* Adds the saveCancelSection
*/
public void addSaveCancelSection() { public void addSaveCancelSection() {
m_saveCancelSection = new SaveCancelSection(); m_saveCancelSection = new SaveCancelSection();
try { try {
@ -258,12 +264,16 @@ public class LinkPropertyForm extends FormSection
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH); add(m_saveCancelSection, ColumnPanel.FULL_WIDTH);
} }
/** Retrieves the saveCancelSection */ /**
* Retrieves the saveCancelSection
*/
public SaveCancelSection getSaveCancelSection() { public SaveCancelSection getSaveCancelSection() {
return m_saveCancelSection; return m_saveCancelSection;
} }
/** return selection model for Link that we are dealing with. */ /**
* return selection model for Link that we are dealing with.
*/
protected LinkSelectionModel getLinkSelectionModel() { protected LinkSelectionModel getLinkSelectionModel() {
return m_linkModel; return m_linkModel;
} }
@ -284,7 +294,8 @@ public class LinkPropertyForm extends FormSection
} }
/** /**
* Validation listener. Ensures consistency of internal vs. external link data * Validation listener. Ensures consistency of internal vs. external link
* data
* *
* @param event the FormSectionEvent * @param event the FormSectionEvent
*/ */
@ -316,7 +327,7 @@ public class LinkPropertyForm extends FormSection
// "http://servername" on the front // "http://servername" on the front
newURL = HTTP_PROTOCOL + Web.getConfig().getHost() newURL = HTTP_PROTOCOL + Web.getConfig().getHost()
+ url; + url;
} else if (!hasProtocol) { } else if (!hasProtocol) {
// There's no protocol. See if it would be ok if we // There's no protocol. See if it would be ok if we
// put one on the beginning // put one on the beginning
@ -325,8 +336,7 @@ public class LinkPropertyForm extends FormSection
} else { } else {
// No idea, just throw the error // No idea, just throw the error
throw new FormProcessException("URL is not valid: " + ex. throw new FormProcessException("URL is not valid: " + ex.getMessage());
getMessage());
} }
try { try {
@ -366,6 +376,13 @@ public class LinkPropertyForm extends FormSection
throw new FormProcessException( throw new FormProcessException(
"Item selection is required for internal link."); "Item selection is required for internal link.");
} }
// Quasimodo
// The target of the link must not be the same as the owner
if(m_itemModel.getSelectedItem(state).getID().equals(
((ContentItem) data.get(ITEM_SEARCH)).getID())
) {
throw new FormProcessException("Link target is the same as this object.");
}
} }
} }
@ -410,14 +427,13 @@ public class LinkPropertyForm extends FormSection
m_title.setValue(state, link.getTitle()); m_title.setValue(state, link.getTitle());
m_description.setValue(state, link.getDescription()); m_description.setValue(state, link.getDescription());
if ((link.getTargetURI() != null) if ((link.getTargetURI() != null)
&& link.getTargetURI().startsWith("&")) { && link.getTargetURI().startsWith("&")) {
m_itemParams.setValue(state, m_itemParams.setValue(state,
link.getTargetURI().substring(1)); link.getTargetURI().substring(1));
} else { } else {
m_targetURI.setValue(state, link.getTargetURI()); m_targetURI.setValue(state, link.getTargetURI());
} }
if (com.arsdigita.bebop.Link.NEW_FRAME.equals(link. if (com.arsdigita.bebop.Link.NEW_FRAME.equals(link.getTargetWindow())) {
getTargetWindow())) {
m_URIOption.setValue(state, Link.TARGET_WINDOW); m_URIOption.setValue(state, Link.TARGET_WINDOW);
} else { } else {
m_URIOption.setValue(state, null); m_URIOption.setValue(state, null);
@ -472,7 +488,7 @@ public class LinkPropertyForm extends FormSection
//call to set various properties of Link. //call to set various properties of Link.
setLinkProperties(link, fse); setLinkProperties(link, fse);
s_log.debug("Created Link with ID: " + link.getOID().toString() s_log.debug("Created Link with ID: " + link.getOID().toString()
+ "Title " + link.getTitle()); + "Title " + link.getTitle());
} }
// XXX Initialize the form // XXX Initialize the form
m_linkModel.clearSelection(state); m_linkModel.clearSelection(state);
@ -480,8 +496,8 @@ public class LinkPropertyForm extends FormSection
} }
/** /**
* Set various properties of the Link.Child clases can over-ride this * Set various properties of the Link.Child clases can over-ride this method
* method to add additional properties to Link. * to add additional properties to Link.
*/ */
protected void setLinkProperties(Link link, FormSectionEvent fse) { protected void setLinkProperties(Link link, FormSectionEvent fse) {
PageState state = fse.getPageState(); PageState state = fse.getPageState();