001: /*
002: * NoticeTransformer.java
003: *
004: * Version: $Revision: 1.0 $
005: *
006: * Date: $Date: 2006/07/13 23:20:54 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.xmlui.aspect.general;
041:
042: import java.sql.SQLException;
043:
044: import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
045: import org.dspace.app.xmlui.wing.Message;
046: import org.dspace.app.xmlui.wing.WingException;
047: import org.dspace.app.xmlui.wing.element.Body;
048: import org.dspace.app.xmlui.wing.element.Division;
049: import org.dspace.authorize.AuthorizeException;
050:
051: /**
052: * This class will add a simple notification div the DRI document. Typicaly
053: * this transformer is used after an action has been preformed to let the
054: * user know if an operation succeded or failed.
055: *
056: * The possible paramaters are:
057: *
058: * outcome: The outcome determines whether the notice is positive or negative.
059: * Possible values are: "success", "failure", or "netural". If no values are
060: * supplied then netural is assumed.
061: *
062: * header: An i18n dictionary key referencing the text that should be used
063: * as a header for this notice.
064: *
065: * message: An i18n dictionary key refrencing the text that should be used as
066: * the content for this notice.
067: *
068: * characters: Plain text string that should be used as the content for this
069: * notice. Normaly all messages should be i18n dictionary keys however this
070: * parameter is usefull for error messages that are not nessasarly translated.
071: *
072: * All parameters are optional but you must supply at least the message or the
073: * characters
074: *
075: *
076: *
077: * Examlpe:
078: * <map:transformer type="notice">
079: * <map:parameter name="outcome" value="success"/>
080: * <map:parameter name="message" value="xmlui.<aspect>.<class>.<type>"/>
081: * </map:transformer>
082: *
083: * @author Scott Phillips
084: * @author Alexey Maslov
085: */
086: public class NoticeTransformer extends AbstractDSpaceTransformer {
087:
088: /** Language Strings */
089: private static final Message T_head = message("xmlui.general.notice.default_head");
090:
091: /**
092: * Add the notice div to the body.
093: */
094: public void addBody(Body body) throws WingException, SQLException,
095: AuthorizeException {
096: String outcome = parameters.getParameter("outcome", null);
097: String header = parameters.getParameter("header", null);
098: String message = parameters.getParameter("message", null);
099: String characters = parameters.getParameter("characters", null);
100:
101: if ((message == null || message.length() <= 0)
102: && (characters == null || characters.length() <= 0))
103: throw new WingException("No message found.");
104:
105: String rend = "notice";
106: if ("netural".equals(outcome))
107: rend += " netural";
108: else if ("success".equals(outcome))
109: rend += " success";
110: else if ("failure".equals(outcome))
111: rend += " failure";
112:
113: Division div = body.addDivision("general-message", rend);
114: if ((header != null) && (!"".equals(header)))
115: div.setHead(message(header));
116: else
117: div.setHead(T_head);
118:
119: if (message != null && message.length() > 0)
120: div.addPara(message(message));
121:
122: if (characters != null && characters.length() > 0)
123: div.addPara(characters);
124: }
125: }
|