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;
/**
* Form to edit the basic properties of an Link. This form can be
* extended to create forms for Link subclasses.
* Form to edit the basic properties of an Link. This form can be extended to
* create forms for Link subclasses.
*
* @version $Revision: #5 $ $Date: 2004/08/17 $
* @author Nobuko Asakai (nasakai@redhat.com)
* @author Sören Bernstein (sbernstein@zes.uni-bremen.de)
*/
public class LinkPropertyForm extends FormSection
implements FormInitListener, FormProcessListener, FormValidationListener,
FormSubmissionListener {
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 SSL_PROTOCOL = "https://";
public static final String HTTP_PROTOCOL = "http://";
@ -77,21 +81,21 @@ public class LinkPropertyForm extends FormSection
private TextField m_targetURI;
private RadioGroup m_linkType;
private CheckboxGroup m_URIOption;
private ItemSelectionModel m_itemModel;
protected ItemSelectionModel m_itemModel;
private LinkSelectionModel m_linkModel;
private SaveCancelSection m_saveCancelSection;
private ItemSearchWidget m_itemSearch;
private TextField m_itemParams;
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
* by the item selection model passed in.
* @param itemModel The ItemSelectionModel to use to obtain the
* ContentItem to which this link is (or will be) attached
* @param link The LinkSelectionModel to use to obtain the
* Link to work on
* Creates a new form to edit the Link object specified by the item
* selection model passed in.
*
* @param itemModel The ItemSelectionModel to use to obtain the ContentItem
* to which this link is (or will be) attached
* @param link The LinkSelectionModel to use to obtain the Link to work on
*/
public LinkPropertyForm(ItemSelectionModel itemModel,
LinkSelectionModel link) {
@ -224,7 +228,9 @@ public class LinkPropertyForm extends FormSection
false));
}
/** Adds the saveCancelSection */
/**
* Adds the saveCancelSection
*/
public void addSaveCancelSection() {
m_saveCancelSection = new SaveCancelSection();
try {
@ -258,12 +264,16 @@ public class LinkPropertyForm extends FormSection
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH);
}
/** Retrieves the saveCancelSection */
/**
* Retrieves the saveCancelSection
*/
public SaveCancelSection getSaveCancelSection() {
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() {
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
*/
@ -325,8 +336,7 @@ public class LinkPropertyForm extends FormSection
} else {
// No idea, just throw the error
throw new FormProcessException("URL is not valid: " + ex.
getMessage());
throw new FormProcessException("URL is not valid: " + ex.getMessage());
}
try {
@ -366,6 +376,13 @@ public class LinkPropertyForm extends FormSection
throw new FormProcessException(
"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 {
m_targetURI.setValue(state, link.getTargetURI());
}
if (com.arsdigita.bebop.Link.NEW_FRAME.equals(link.
getTargetWindow())) {
if (com.arsdigita.bebop.Link.NEW_FRAME.equals(link.getTargetWindow())) {
m_URIOption.setValue(state, Link.TARGET_WINDOW);
} else {
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
* method to add additional properties to Link.
* Set various properties of the Link.Child clases can over-ride this method
* to add additional properties to Link.
*/
protected void setLinkProperties(Link link, FormSectionEvent fse) {
PageState state = fse.getPageState();