Korrektur für #1212

git-svn-id: https://svn.libreccm.org/ccm/trunk@1590 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-04-13 08:14:00 +00:00
parent 5a1c089921
commit 46927538cd
1 changed files with 96 additions and 62 deletions

View File

@ -18,34 +18,57 @@
*/ */
package com.arsdigita.bebop; package com.arsdigita.bebop;
import com.arsdigita.xml.Element;
import java.util.TooManyListenersException;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.xml.Element;
import java.util.TooManyListenersException;
/** /**
* The parent of all Bebop Link classes, this class represents a URL on a page. * The parent of all Bebop Link classes, this class represents a URL on a page.
* It may contain a label, an image, or any other component. * It may contain a label, an image, or any other component.
* *
* <p> The following table lists all Bebop Link classes and suggests when they * <p> The following table lists all Bebop Link classes and suggests
* might be used. <p> <table BORDER=3> <tr> <th>Link Class</th> <th>Usage</th> * when they might be used.
* </tr> <tr> <td>{@link BaseLink}</td> <td>Parent class of Bebop Link classes. * <p>
* Extend this class to build your own Link class.</td> </tr> <tr> <td>{@link Link}</td> * <table BORDER=3>
* <td>Link class that manages its own URL variables. Session information is * <tr>
* added to the target URL for this type.</td> </tr> <tr> <td>{@link ExternalLink}</td> * <th>Link Class</th>
* <td>Link that does not encode the URL with any session information. Used for * <th>Usage</th>
* a link to a page outside the site.</td> </tr> <tr> <td>{@link ControlLink}</td> * </tr>
* <td> Used for references within its own page (often as fields in a table * <tr>
* header for sorting a column).</td> </tr> <tr> <td>{@link ActionLink}</td> * <td>{@link BaseLink}</td>
* <td>Parent class of Bebop Link classes. Extend this class to
* build your own Link class.</td>
* </tr>
* <tr>
* <td>{@link Link}</td>
* <td>Link class that manages its own URL variables. Session information
* is added to the target URL for this type.</td>
* </tr>
* <tr>
* <td>{@link ExternalLink}</td>
* <td>Link that does not encode the URL with any session information.
* Used for a link to a page outside the site.</td>
* </tr>
* <tr>
* <td>{@link ControlLink}</td>
* <td> Used for references within its own page (often
* as fields in a table header for sorting a column).</td>
* </tr>
* <tr>
* <td>{@link ActionLink}</td>
* <td>Sets its own control event and runs its own * <td>Sets its own control event and runs its own
* {@link com.arsdigita.bebop.event.ActionListener}s. When the link is clicked, * {@link com.arsdigita.bebop.event.ActionListener}s. When the link is clicked,
* the code in the Listener's <tt>actionPerformed</tt> method runs.</td> </tr> * the code in the Listener's <tt>actionPerformed</tt> method runs.</td>
* <tr> <td>{@link ToggleLink}</td> <td>A link that turns into label when it is * </tr>
* selected and turns back into a link when it is unselected.</td> </tr> * <tr>
* <td>{@link ToggleLink}</td>
* <td>A link that turns into label when it is selected and
* turns back into a link when it is unselected.</td>
* </tr>
* </table> * </table>
* *
* @version $Id: BaseLink.java 998 2005-11-15 22:27:13Z sskracic $ * @version $Id: BaseLink.java 998 2005-11-15 22:27:13Z sskracic $
@ -60,10 +83,13 @@ public abstract class BaseLink extends TextStylable
private final String TYPE_ATTR = "type"; private final String TYPE_ATTR = "type";
private final String HREF_NO_JAVASCRIPT = "href_no_javascript"; private final String HREF_NO_JAVASCRIPT = "href_no_javascript";
private final String HREF = "href"; private final String HREF = "href";
protected String m_url; protected String m_url;
protected String m_noJavascriptURL = null; protected String m_noJavascriptURL = null;
protected Component m_child; protected Component m_child;
private PrintListener m_printListener; private PrintListener m_printListener;
private String m_sConfirmMsg = ""; private String m_sConfirmMsg = "";
private GlobalizedMessage m_confirmMsg; private GlobalizedMessage m_confirmMsg;
@ -132,16 +158,15 @@ public abstract class BaseLink extends TextStylable
} }
/** /**
* Adds a print listener. Since the * Adds a print listener.
* <code>PrintListener</code> is expected to modify the target of the * Since the <code>PrintListener</code> is expected to modify the
* <code>PrintEvent</code>, only one print listener can be set for a link. * target of the <code>PrintEvent</code>, only one print listener can be
* * set for a link.
* @param listener the print listener * @param listener the print listener
* @throws IllegalArgumentException if * @throws IllegalArgumentException if <code>listener</code> is null.
* <code>listener</code> is null.
* @throws TooManyListenersException if a print listener has previously been * @throws TooManyListenersException if a print listener has previously been
* added. @pre listener != null * added.
*/ * @pre listener != null */
public void addPrintListener(PrintListener listener) public void addPrintListener(PrintListener listener)
throws IllegalStateException, TooManyListenersException { throws IllegalStateException, TooManyListenersException {
if (listener == null) { if (listener == null) {
@ -222,19 +247,18 @@ public abstract class BaseLink extends TextStylable
protected abstract void generateURL(PageState state, Element parent); protected abstract void generateURL(PageState state, Element parent);
/** /**
* <p>Generates a DOM fragment: <p><pre> * <p>Generates a DOM fragment:
* <p><pre>
* &lt;bebop:link href="..." type="..." %bebopAttr;/> * &lt;bebop:link href="..." type="..." %bebopAttr;/>
* </pre> The * </pre>
* <code>href</code> attribute contains the target the link should point to. * The <code>href</code> attribute contains the target the link
* The * should point to. The <code>type</code> attribute is used to
* <code>type</code> attribute is used to give more finegrained control over * give more finegrained control over which kind of link this element
* which kind of link this element represents. The types are * represents. The types are <code>link</code> for a
* <code>link</code> for a * <code>Link</code>, <code>control</code> for a {@link ControlLink},
* <code>Link</code>, * and <code>toggle</code> for a {@link ToggleLink}. There may be
* <code>control</code> for a {@link ControlLink}, and * additional attributes depending on what type of link this link
* <code>toggle</code> for a {@link ToggleLink}. There may be additional * represents.
* attributes depending on what type of link this link represents.
*
* @see ControlLink#generateXML * @see ControlLink#generateXML
* @see ToggleLink#generateXML * @see ToggleLink#generateXML
*/ */
@ -245,7 +269,7 @@ public abstract class BaseLink extends TextStylable
Element link = parent.newChildElement("bebop:link", BEBOP_XML_NS); Element link = parent.newChildElement("bebop:link", BEBOP_XML_NS);
target.generateURL(state, link); target.generateURL(state, link);
target.exportConfirmAttributes(state, link); target.exportConfirmAttributes(state, link);
// target.exportAttributes(link);
//setup the link without javascript //setup the link without javascript
target.setupNoJavascriptURL(state, link); target.setupNoJavascriptURL(state, link);
target.exportAttributes(link); target.exportAttributes(link);
@ -320,10 +344,10 @@ public abstract class BaseLink extends TextStylable
} }
/** /**
* Adds type-specific XML attributes to the XML element representing this * Adds type-specific XML attributes to the XML element representing
* link. Subclasses should override this method if they introduce more * this link. Subclasses should override this method if they introduce
* attributes than the ones {@link #generateXML generateXML} produces by * more attributes than the ones {@link #generateXML generateXML}
* default. * produces by default.
* *
* @param state the current request * @param state the current request
* @param link the XML element representing this link * @param link the XML element representing this link
@ -336,8 +360,8 @@ public abstract class BaseLink extends TextStylable
* protection for this link</em>. Not for confirmation messages; Should call * protection for this link</em>. Not for confirmation messages; Should call
* setConfirmation for that. * setConfirmation for that.
* *
* @param value @pre value.toLowerCase().startsWith("return confirm(") == * @param value
* false * @pre value.toLowerCase().startsWith("return confirm(") == false
* *
* @see #setConfirmation * @see #setConfirmation
*/ */
@ -355,13 +379,14 @@ public abstract class BaseLink extends TextStylable
/** /**
* Forces the user to click through a confirmation dialog before this link * Forces the user to click through a confirmation dialog before this link
* is followed. The user is prompted with the specified message. If the user * is followed. The user is prompted with the specified message. If the
* does not does not confirm, the link is not followed. The current * user does not does not confirm, the link is not followed. The current
* implementation uses the JavaScript confirm function and the onClick * implementation uses the JavaScript confirm function and the onClick
* attribute. If JavaScript is not enabled in the client browser, this * attribute.
* method will redirect the browser to a Bebop confirmation page rather than * If JavaScript is not enabled in the client browser, this method will
* use a JavaScript confirmation. Subsequent calls to setOnClick will undo * redirect the browser to a Bebop confirmation page rather than use
* the effect of this method. * a JavaScript confirmation.
* Subsequent calls to setOnClick will undo the effect of this method.
* *
* @param message the confirmation message presented to the user. This * @param message the confirmation message presented to the user. This
* message cannot have an apostrophe or back slash * message cannot have an apostrophe or back slash
@ -379,33 +404,42 @@ public abstract class BaseLink extends TextStylable
"confirmation message cannot contain apostrophe or back slash"); "confirmation message cannot contain apostrophe or back slash");
} }
setAttribute("confirm", "confirm");
//set the onclick attribute for the link
setAttribute(ON_CLICK, "return confirm(\\'" + message + "\\');");
m_sConfirmMsg = message; m_sConfirmMsg = message;
} }
/**
* Set a GlobalizedMessage as confirmation message
* @param msg
*/
public void setConfirmation(GlobalizedMessage msg) { public void setConfirmation(GlobalizedMessage msg) {
m_confirmMsg = msg; m_confirmMsg = msg;
} }
/**
* Generate XML output for confirmation links
*
* @param state PageState
* @param link Parent element
*/
private void exportConfirmAttributes(PageState state, Element link) { private void exportConfirmAttributes(PageState state, Element link) {
// If a confirmation message is set
if (m_sConfirmMsg.length() > 0 || m_confirmMsg != null) { if (m_sConfirmMsg.length() > 0 || m_confirmMsg != null) {
// Set confirm link, if
setAttribute("confirm", "confirm");
// then add the needed attributes to link
link.addAttribute("confirm", "confirm");
// If m_sConfirmMsg is not empty
if (m_sConfirmMsg.length() > 0) { if (m_sConfirmMsg.length() > 0) {
//set the onclick attribute for the link // then set the onclick attribute for the link with the static message
setAttribute(ON_CLICK, "return confirm(\\'" + m_sConfirmMsg + "\\');"); link.addAttribute(ON_CLICK, "return confirm(\\'" + m_sConfirmMsg + "\\');");
// else if m_configMsg is set
} else if (m_confirmMsg != null) { } else if (m_confirmMsg != null) {
//set the onclick attribute for the link //then set the onclick attribute for the link with a globalized message
setAttribute(ON_CLICK, "return confirm(\\'" + m_confirmMsg.localize() + "\\');"); link.addAttribute(ON_CLICK, "return confirm(\\'" + m_confirmMsg.localize() + "\\');");
} }
} }