001: /*
002: * InitialQuestionsStep.java
003: *
004: * Version: $Revision: 1.4 $
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.submission.submit;
041:
042: import java.io.IOException;
043: import java.sql.SQLException;
044:
045: import org.dspace.app.xmlui.utils.UIException;
046: import org.dspace.app.xmlui.aspect.submission.AbstractSubmissionStep;
047: import org.dspace.app.xmlui.wing.Message;
048: import org.dspace.app.xmlui.wing.WingException;
049: import org.dspace.app.xmlui.wing.element.Body;
050: import org.dspace.app.xmlui.wing.element.CheckBox;
051: import org.dspace.app.xmlui.wing.element.Division;
052: import org.dspace.app.xmlui.wing.element.List;
053: import org.dspace.authorize.AuthorizeException;
054: import org.dspace.content.Collection;
055: import org.dspace.content.DCValue;
056: import org.dspace.content.Item;
057: import org.xml.sax.SAXException;
058:
059: /**
060: * This is the first official step of the item submission processes. This
061: * step will ask the user two questions which will direct whether future
062: * questions will be asked of the user. Since they user may move next or
063: * previous or even jump around between the stages some metadata values
064: * may all ready be filled for selected values. i.e. if the user selected
065: * that there may be multiple titles and then later comes back and unchecks
066: * then multiple titles box. In this case these metadata entries are removed
067: * from the item, a note is displayed informing the user of this discrepency.
068: *
069: * Questions:
070: * - Multiple titles
071: * - Published Before
072: *
073: * @author Scott Phillips
074: * @author Tim Donohue (updated for Configurable Submission)
075: */
076: public class InitialQuestionsStep extends AbstractSubmissionStep {
077: /** Language Strings **/
078: protected static final Message T_head = message("xmlui.Submission.submit.InitialQuestionsStep.head");
079: protected static final Message T_important_note = message("xmlui.Submission.submit.InitialQuestionsStep.important_note");
080: protected static final Message T_and = message("xmlui.Submission.submit.InitialQuestionsStep.and");
081: protected static final Message T_separator = message("xmlui.Submission.submit.InitialQuestionsStep.separator");
082: protected static final Message T_open = message("xmlui.Submission.submit.InitialQuestionsStep.open_set");
083: protected static final Message T_close = message("xmlui.Submission.submit.InitialQuestionsStep.close_set");
084: protected static final Message T_multiple_titles = message("xmlui.Submission.submit.InitialQuestionsStep.multiple_titles");
085: protected static final Message T_multiple_titles_help = message("xmlui.Submission.submit.InitialQuestionsStep.multiple_titles_help");
086: protected static final Message T_multiple_titles_note = message("xmlui.Submission.submit.InitialQuestionsStep.multiple_titles_note");
087: protected static final Message T_published_before = message("xmlui.Submission.submit.InitialQuestionsStep.published_before");
088: protected static final Message T_published_before_help = message("xmlui.Submission.submit.InitialQuestionsStep.published_before_help");
089: protected static final Message T_published_before_note = message("xmlui.Submission.submit.InitialQuestionsStep.published_before_note");
090: protected static final Message T_date_issued = message("xmlui.Submission.submit.InitialQuestionsStep.date_issued");
091: protected static final Message T_citation = message("xmlui.Submission.submit.InitialQuestionsStep.citation");
092: protected static final Message T_publisher = message("xmlui.Submission.submit.InitialQuestionsStep.publisher");
093:
094: /**
095: * Establish our required parameters, abstractStep will enforce these.
096: */
097: public InitialQuestionsStep() {
098: this .requireSubmission = true;
099: this .requireStep = true;
100: }
101:
102: public void addBody(Body body) throws SAXException, WingException,
103: UIException, SQLException, IOException, AuthorizeException {
104: // Get any metadata that may be removed by unselecting one of these options.
105: Item item = submission.getItem();
106: Collection collection = submission.getCollection();
107: String actionURL = contextPath + "/handle/"
108: + collection.getHandle() + "/submit";
109:
110: DCValue[] titles = item.getDC("title", "alternative", Item.ANY);
111:
112: DCValue[] dateIssued = item.getDC("date", "issued", Item.ANY);
113: DCValue[] citation = item.getDC("identifier", "citation",
114: Item.ANY);
115: DCValue[] publisher = item.getDC("publisher", null, Item.ANY);
116:
117: // Generate a from asking the user two questions: multiple
118: // titles & published before.
119: Division div = body.addInteractiveDivision(
120: "submit-initial-questions", actionURL,
121: Division.METHOD_POST, "primary submission");
122: div.setHead(T_submission_head);
123: addSubmissionProgressList(div);
124:
125: List form = div.addList("submit-initial-questions",
126: List.TYPE_FORM);
127: form.setHead(T_head);
128:
129: CheckBox multipleTitles = form.addItem().addCheckBox(
130: "multiple_titles");
131: multipleTitles.setLabel(T_multiple_titles);
132: multipleTitles.setHelp(T_multiple_titles_help);
133: multipleTitles.addOption("true");
134: if (submission.hasMultipleTitles()) {
135: multipleTitles.setOptionSelected("true");
136: }
137:
138: // If any titles would be removed if the user unselected this box then
139: // warn the user!
140: if (titles.length > 0) {
141: org.dspace.app.xmlui.wing.element.Item note = form
142: .addItem();
143: note.addHighlight("bold").addContent(T_important_note);
144: note.addContent(T_multiple_titles_note);
145: for (int i = 0; i < titles.length; i++) {
146: if (i > 0)
147: note.addContent(T_separator);
148: note.addContent("\"");
149: note.addHighlight("bold").addContent(titles[i].value);
150: note.addContent("\"");
151: }
152: }
153:
154: CheckBox publishedBefore = form.addItem().addCheckBox(
155: "published_before");
156: publishedBefore.setLabel(T_published_before);
157: publishedBefore.setHelp(T_published_before_help);
158: publishedBefore.addOption("true");
159: if (submission.isPublishedBefore()) {
160: publishedBefore.setOptionSelected("true");
161: }
162:
163: // If any metadata would be removed if the user unselected the box then warn
164: // the user about what will be removed.
165: if (dateIssued.length > 0 || citation.length > 0
166: || publisher.length > 0) {
167: org.dspace.app.xmlui.wing.element.Item note = form
168: .addItem();
169: note.addHighlight("bold").addContent(T_important_note);
170: note.addContent(T_published_before_note);
171:
172: // Start a convoluted processes to build an english list of values.
173: // Format: Date Issued (value, value, value), Citation (value, value, value), Publisher (value, value, value)
174: if (dateIssued.length > 0) {
175: note.addHighlight("bold").addContent(T_date_issued);
176: note.addContent(T_open);
177: for (int i = 0; i < dateIssued.length; i++) {
178: if (i > 0)
179: note.addContent(T_separator);
180: note.addContent(dateIssued[i].value);
181: }
182: note.addContent(T_close);
183: }
184:
185: // Conjunction
186: if (dateIssued.length > 0
187: && (citation.length > 0 || publisher.length > 0))
188: note.addContent(T_separator);
189:
190: if (dateIssued.length > 0 && citation.length > 0
191: && publisher.length == 0) {
192: note.addContent(T_and);
193: }
194:
195: // Citation
196: if (citation.length > 0) {
197: note.addHighlight("bold").addContent(T_citation);
198: note.addContent(T_open);
199: for (int i = 0; i < citation.length; i++) {
200: if (i > 0)
201: note.addContent(T_separator);
202: note.addContent(citation[i].value);
203: }
204: note.addContent(T_close);
205: }
206:
207: // Conjunction
208: if (citation.length > 0 && publisher.length > 0) {
209: note.addContent(T_separator);
210: }
211:
212: if ((dateIssued.length > 0 || citation.length > 0)
213: && publisher.length > 0) {
214: note.addContent(T_and);
215: }
216:
217: // Publisher
218: if (publisher.length > 0) {
219: note.addHighlight("bold").addContent(T_publisher);
220: note.addContent(T_open);
221: for (int i = 0; i < publisher.length; i++) {
222: if (i > 0)
223: note.addContent(T_separator);
224: note.addContent(publisher[i].value);
225: }
226: note.addContent(T_close);
227: }
228: }
229:
230: //Since we already warn users about the metadata pruning to happen
231: //if they uncheck an already checked box, then
232: //we can let the prune process occur immediately!
233: form.addItem().addHidden("prune").setValue("true");
234:
235: //add standard control/paging buttons
236: addControlButtons(form);
237:
238: div.addHidden("submission-continue").setValue(knot.getId());
239:
240: }
241:
242: /**
243: * Each submission step must define its own information to be reviewed
244: * during the final Review/Verify Step in the submission process.
245: * <P>
246: * The information to review should be tacked onto the passed in
247: * List object.
248: * <P>
249: * NOTE: To remain consistent across all Steps, you should first
250: * add a sub-List object (with this step's name as the heading),
251: * by using a call to reviewList.addList(). This sublist is
252: * the list you return from this method!
253: *
254: * @param reviewList
255: * The List to which all reviewable information should be added
256: * @return
257: * The new sub-List object created by this step, which contains
258: * all the reviewable information. If this step has nothing to
259: * review, then return null!
260: */
261: public List addReviewSection(List reviewList) throws SAXException,
262: WingException, UIException, SQLException, IOException,
263: AuthorizeException {
264: //Create a new section for this Initial Questions information
265: List initSection = reviewList.addList("submit-review-"
266: + this .stepAndPage, List.TYPE_FORM);
267: initSection.setHead(T_head);
268:
269: //add information to review
270: Message multipleTitles = ReviewStep.T_no;
271: if (submission.hasMultipleTitles())
272: multipleTitles = ReviewStep.T_yes;
273:
274: Message publishedBefore = ReviewStep.T_no;
275: if (submission.isPublishedBefore())
276: publishedBefore = ReviewStep.T_yes;
277:
278: initSection.addLabel(T_multiple_titles);
279: initSection.addItem(multipleTitles);
280: initSection.addLabel(T_published_before);
281: initSection.addItem(publishedBefore);
282:
283: //return this new review section
284: return initSection;
285: }
286: }
|