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,21 +81,21 @@ 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) {
@ -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
*/ */
@ -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.");
}
} }
} }
@ -416,8 +433,7 @@ public class LinkPropertyForm extends FormSection
} 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);
@ -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();