001: /*
002: * SampleStep.java
003: *
004: * Version: $Revision$
005: *
006: * Date: $Date$
007: *
008: * Copyright (c) 2002-2005, 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.submit.step;
041:
042: import java.io.IOException;
043: import java.sql.SQLException;
044:
045: import javax.servlet.ServletException;
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048:
049: import org.apache.log4j.Logger;
050:
051: import org.dspace.app.util.SubmissionInfo;
052: import org.dspace.authorize.AuthorizeException;
053: import org.dspace.core.Context;
054: import org.dspace.submit.AbstractProcessingStep;
055:
056: /**
057: * This is a Sample Step class which can be used as template for creating new
058: * custom Step processing classes!
059: * <p>
060: * Please Note: The basic methods you will want to override are described below.
061: * However, obviously, you are completely free to create your own methods for
062: * this Step, or override other methods. For more examples, look at the code
063: * from one of the provided DSpace step classes in the "org.dspace.submit.step"
064: * package.
065: * <P>
066: * This class performs all the behind-the-scenes processing that
067: * this particular step requires. This class's methods are utilized
068: * by both the JSP-UI and the Manakin XML-UI
069: * <P>
070: * If you are utilizing the JSP-UI, you will also be required to create
071: * a class which implements org.dspace.app.webui.submit.JSPStep, and provide
072: * the necessary JSP-related methods. There is a corresponding sample
073: * of such a class at org.dspace.app.webui.submit.step.JSPSampleStep.
074: *
075: * @see org.dspace.app.util.SubmissionConfig
076: * @see org.dspace.app.util.SubmissionStepConfig
077: * @see org.dspace.submit.AbstractProcessingStep
078: *
079: * @author Tim Donohue
080: * @version $Revision$
081: */
082: public class SampleStep extends AbstractProcessingStep {
083:
084: /***************************************************************************
085: * STATUS / ERROR FLAGS (returned by doProcessing() if an error occurs or
086: * additional user interaction may be required)
087: *
088: * (Do NOT use status of 0, since it corresponds to STATUS_COMPLETE flag
089: * defined in the JSPStepManager class)
090: **************************************************************************/
091: public static final int STATUS_USER_INPUT_ERROR = 1;
092:
093: /** log4j logger */
094: private static Logger log = Logger.getLogger(SampleStep.class);
095:
096: /**
097: * Do any processing of the information input by the user, and/or perform
098: * step processing (if no user interaction required)
099: * <P>
100: * It is this method's job to save any data to the underlying database, as
101: * necessary, and return error messages (if any) which can then be processed
102: * by the appropriate user interface (JSP-UI or XML-UI)
103: * <P>
104: * NOTE: If this step is a non-interactive step (i.e. requires no UI), then
105: * it should perform *all* of its processing in this method!
106: *
107: * @param context
108: * current DSpace context
109: * @param request
110: * current servlet request object
111: * @param response
112: * current servlet response object
113: * @param subInfo
114: * submission info object
115: * @return Status or error flag which will be processed by
116: * doPostProcessing() below! (if STATUS_COMPLETE or 0 is returned,
117: * no errors occurred!)
118: */
119: public int doProcessing(Context context,
120: HttpServletRequest request, HttpServletResponse response,
121: SubmissionInfo subInfo) throws ServletException,
122: IOException, SQLException, AuthorizeException {
123: /*
124: * In this method, you should do any processing of any user input (if
125: * this step requires user input). If this step does not require user
126: * interaction (i.e. it has no UI), then ALL of the backend processing
127: * should occur in this method.
128: *
129: * Processing may include, but is not limited to:
130: *
131: * 1) Saving user input data to the database (e.g. saving metadata from
132: * a web form that a user filled out) 2) Performing ALL backend
133: * processing for non-interactive steps 3) Determine if any errors
134: * occurred during processing, and if so, return those error flags.
135: *
136: * For steps with user interaction, this method is called right after
137: * the web form or page is submitted. For steps without user
138: * interaction, this method is called whenever the step itself is
139: * supposed to be processed.
140: *
141: */
142:
143: /*
144: * HINT:
145: *
146: * If any errors occurred, its recommended to create a global "flag" to
147: * represent that error. It's much easier then for the
148: * JSP-UI or Manakin XML-UI to determine what to do with that error.
149: *
150: * For example, if an error occurred, you may specify the following
151: * return call:
152: *
153: * return USER_INPUT_ERROR_FLAG;
154: *
155: * (Note: this flag is defined at the top of this class)
156: */
157:
158: // If no errors occurred, and there were no other special messages to
159: // report to the doPostProcessing() method, just return STATUS_COMPLETE!
160: return STATUS_COMPLETE;
161: }
162:
163: /**
164: * Retrieves the number of pages that this "step" extends over. This method
165: * is used to build the progress bar.
166: * <P>
167: * This method may just return 1 for most steps (since most steps consist of
168: * a single page). But, it should return a number greater than 1 for any
169: * "step" which spans across a number of HTML pages. For example, the
170: * configurable "Describe" step (configured using input-forms.xml) overrides
171: * this method to return the number of pages that are defined by its
172: * configuration file.
173: * <P>
174: * Steps which are non-interactive (i.e. they do not display an interface to
175: * the user) should return a value of 1, so that they are only processed
176: * once!
177: *
178: *
179: * @param request
180: * The HTTP Request
181: * @param subInfo
182: * The current submission information object
183: *
184: * @return the number of pages in this step
185: */
186: public int getNumberOfPages(HttpServletRequest request,
187: SubmissionInfo subInfo) throws ServletException {
188: /*
189: * This method reports how many "pages" to put in
190: * the Progress Bar for this Step.
191: *
192: * Most steps should just return 1 (which means the Step only appears
193: * once in the Progress Bar).
194: *
195: * If this Step should be shown as multiple "Pages" in the Progress Bar,
196: * then return a value higher than 1. For example, return 2 in order to
197: * have this Step appear twice in a row within the Progress Bar.
198: *
199: * If you return 0, this Step will not appear in the Progress Bar at
200: * ALL! Therefore it is important for non-interactive steps to return 0.
201: */
202:
203: // in most cases, you'll want to just return 1
204: return 1;
205: }
206: }
|