001: /*
002: * SelectCollectionStep.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.Button;
051: import org.dspace.app.xmlui.wing.element.Division;
052: import org.dspace.app.xmlui.wing.element.List;
053: import org.dspace.app.xmlui.wing.element.PageMeta;
054: import org.dspace.app.xmlui.wing.element.Select;
055: import org.dspace.authorize.AuthorizeException;
056: import org.dspace.content.Collection;
057: import org.dspace.content.Community;
058: import org.dspace.content.DSpaceObject;
059: import org.dspace.core.Constants;
060: import org.dspace.handle.HandleManager;
061: import org.xml.sax.SAXException;
062:
063: /**
064: * Allow the user to select a collection they wish to submit an item to,
065: * this step is sort-of but not officialy part of the item submission
066: * processes. Normaly a user will have selected a collection to submit
067: * too by going to the collection's page, but if that was invalid or the
068: * user came directly from the mydspace page then this step is given.
069: *
070: * @author Scott Phillips
071: * @author Tim Donohue (updated for Configurable Submission)
072: */
073: public class SelectCollectionStep extends AbstractSubmissionStep {
074:
075: /** Language Strings */
076: protected static final Message T_head = message("xmlui.Submission.submit.SelectCollection.head");
077: protected static final Message T_collection = message("xmlui.Submission.submit.SelectCollection.collection");
078: protected static final Message T_collection_help = message("xmlui.Submission.submit.SelectCollection.collection_help");
079: protected static final Message T_collection_default = message("xmlui.Submission.submit.SelectCollection.collection_default");
080: protected static final Message T_submit_next = message("xmlui.general.next");
081:
082: public SelectCollectionStep() {
083: this .requireHandle = true;
084: }
085:
086: public void addPageMeta(PageMeta pageMeta) throws SAXException,
087: WingException {
088:
089: pageMeta.addMetadata("title").addContent(T_submission_title);
090: pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
091: pageMeta.addTrail().addContent(T_submission_trail);
092: }
093:
094: public void addBody(Body body) throws SAXException, WingException,
095: UIException, SQLException, IOException, AuthorizeException {
096: Collection[] collections; // List of possible collections.
097: DSpaceObject dso = HandleManager.resolveToObject(context,
098: handle);
099:
100: if (dso != null && dso instanceof Community) {
101: collections = Collection.findAuthorized(context,
102: ((Community) dso), Constants.ADD);
103: } else {
104: collections = Collection.findAuthorized(context, null,
105: Constants.ADD);
106: }
107:
108: // Basic form with a drop down list of all the collections
109: // you can submit too.
110: Division div = body.addInteractiveDivision("select-collection",
111: contextPath + "/submit", Division.METHOD_POST,
112: "primary submission");
113: div.setHead(T_submission_head);
114:
115: List list = div.addList("select-collection", List.TYPE_FORM);
116: list.setHead(T_head);
117: Select select = list.addItem().addSelect("handle");
118: select.setLabel(T_collection);
119: select.setHelp(T_collection_help);
120:
121: select.addOption("", T_collection_default);
122: for (Collection collection : collections) {
123: String name = collection.getMetadata("name");
124: if (name.length() > 50)
125: name = name.substring(0, 47) + "...";
126: select.addOption(collection.getHandle(), name);
127: }
128:
129: Button submit = list.addItem().addButton("submit");
130: submit.setValue(T_submit_next);
131:
132: div.addHidden("submission-continue").setValue(knot.getId());
133:
134: }
135:
136: /**
137: * Each submission step must define its own information to be reviewed
138: * during the final Review/Verify Step in the submission process.
139: * <P>
140: * The information to review should be tacked onto the passed in
141: * List object.
142: * <P>
143: * NOTE: To remain consistent across all Steps, you should first
144: * add a sub-List object (with this step's name as the heading),
145: * by using a call to reviewList.addList(). This sublist is
146: * the list you return from this method!
147: *
148: * @param reviewList
149: * The List to which all reviewable information should be added
150: * @return
151: * The new sub-List object created by this step, which contains
152: * all the reviewable information. If this step has nothing to
153: * review, then return null!
154: */
155: public List addReviewSection(List reviewList) throws SAXException,
156: WingException, UIException, SQLException, IOException,
157: AuthorizeException {
158: //Currently, the selecting a Collection is not reviewable in DSpace,
159: //since it cannot be changed easily after creating the item
160: return null;
161: }
162:
163: /**
164: * Recycle
165: */
166: public void recycle() {
167: this.handle = null;
168: super.recycle();
169: }
170: }
|