001: /*
002: * EditFileStep.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: import java.util.Map;
045:
046: import org.apache.avalon.framework.parameters.Parameters;
047: import org.apache.cocoon.ProcessingException;
048: import org.apache.cocoon.environment.SourceResolver;
049: import org.dspace.app.xmlui.utils.UIException;
050: import org.dspace.app.xmlui.aspect.submission.AbstractStep;
051: import org.dspace.app.xmlui.wing.Message;
052: import org.dspace.app.xmlui.wing.WingException;
053: import org.dspace.app.xmlui.wing.element.Body;
054: import org.dspace.app.xmlui.wing.element.Division;
055: import org.dspace.app.xmlui.wing.element.List;
056: import org.dspace.app.xmlui.wing.element.Select;
057: import org.dspace.app.xmlui.wing.element.Text;
058: import org.dspace.authorize.AuthorizeException;
059: import org.dspace.content.Bitstream;
060: import org.dspace.content.BitstreamFormat;
061: import org.dspace.content.Collection;
062: import org.dspace.content.FormatIdentifier;
063: import org.xml.sax.SAXException;
064:
065: /**
066: * This is a sub step of the Upload step during item submission. This
067: * page allows the user to edit metadata about a bitstream (aka file)
068: * that has been uploaded. The user can change the format or change
069: * the file's description.
070: * <P>
071: * Since this page is a sub step, the normal control actions are not
072: * present, the user only has the option of returning back to the
073: * upload step.
074: * <P>
075: * NOTE: As a sub step, it is called directly from the UploadStep class.
076: *
077: * @author Scott Phillips
078: * @author Tim Donohue (updated for Configurable Submission)
079: */
080: public class EditFileStep extends AbstractStep {
081:
082: /** Language Strings **/
083: protected static final Message T_head = message("xmlui.Submission.submit.EditFileStep.head");
084: protected static final Message T_file = message("xmlui.Submission.submit.EditFileStep.file");
085: protected static final Message T_description = message("xmlui.Submission.submit.EditFileStep.description");
086: protected static final Message T_description_help = message("xmlui.Submission.submit.EditFileStep.description_help");
087: protected static final Message T_info1 = message("xmlui.Submission.submit.EditFileStep.info1");
088: protected static final Message T_format_detected = message("xmlui.Submission.submit.EditFileStep.format_detected");
089: protected static final Message T_format_selected = message("xmlui.Submission.submit.EditFileStep.format_selected");
090: protected static final Message T_format_default = message("xmlui.Submission.submit.EditFileStep.format_default");
091: protected static final Message T_info2 = message("xmlui.Submission.submit.EditFileStep.info2");
092: protected static final Message T_format_user = message("xmlui.Submission.submit.EditFileStep.format_user");
093: protected static final Message T_format_user_help = message("xmlui.Submission.submit.EditFileStep.format_user_help");
094: protected static final Message T_submit_save = message("xmlui.general.save");
095: protected static final Message T_submit_cancel = message("xmlui.general.cancel");
096:
097: /** The bitstream we are editing */
098: private Bitstream bitstream;
099:
100: /**
101: * Establish our required parameters, abstractStep will enforce these.
102: */
103: public EditFileStep() {
104: this .requireSubmission = true;
105: this .requireStep = true;
106: }
107:
108: /**
109: * Get the bitstream we are editing
110: */
111: public void setup(SourceResolver resolver, Map objectModel,
112: String src, Parameters parameters)
113: throws ProcessingException, SAXException, IOException {
114: super .setup(resolver, objectModel, src, parameters);
115:
116: //the bitstream should be stored in our Submission Info object
117: this .bitstream = submissionInfo.getBitstream();
118: }
119:
120: public void addBody(Body body) throws SAXException, WingException,
121: UIException, SQLException, IOException, AuthorizeException {
122: Collection collection = submission.getCollection();
123: String actionURL = contextPath + "/handle/"
124: + collection.getHandle() + "/submit";
125:
126: // Get the bitstream and all the various formats
127: BitstreamFormat currentFormat = bitstream.getFormat();
128: BitstreamFormat guessedFormat = FormatIdentifier.guessFormat(
129: context, bitstream);
130: BitstreamFormat[] bitstreamFormats = BitstreamFormat
131: .findNonInternal(context);
132:
133: int itemID = submissionInfo.getSubmissionItem().getItem()
134: .getID();
135: String fileUrl = contextPath + "/bitstream/item/" + itemID
136: + "/" + bitstream.getName();
137: String fileName = bitstream.getName();
138:
139: // Build the form that describes an item.
140: Division div = body.addInteractiveDivision("submit-edit-file",
141: actionURL, Division.METHOD_POST, "primary submission");
142: div.setHead(T_submission_head);
143: addSubmissionProgressList(div);
144:
145: List edit = div.addList("submit-edit-file", List.TYPE_FORM);
146: edit.setHead(T_head);
147:
148: edit.addLabel(T_file);
149: edit.addItem().addXref(fileUrl, fileName);
150:
151: Text description = edit.addItem().addText("description");
152: description.setLabel(T_description);
153: description.setHelp(T_description_help);
154: description.setValue(bitstream.getDescription());
155:
156: edit.addItem(T_info1);
157: if (guessedFormat != null) {
158: edit.addLabel(T_format_detected);
159: edit.addItem(guessedFormat.getShortDescription());
160: }
161:
162: // System supported formats
163: Select format = edit.addItem().addSelect("format");
164: format.setLabel(T_format_selected);
165:
166: format.addOption(-1, T_format_default);
167: for (BitstreamFormat bitstreamFormat : bitstreamFormats) {
168: String supportLevel = "Unknown";
169: if (bitstreamFormat.getSupportLevel() == BitstreamFormat.KNOWN)
170: supportLevel = "known";
171: else if (bitstreamFormat.getSupportLevel() == BitstreamFormat.SUPPORTED)
172: supportLevel = "Supported";
173: String name = bitstreamFormat.getShortDescription() + " ("
174: + supportLevel + ")";
175: int id = bitstreamFormat.getID();
176:
177: format.addOption(id, name);
178: }
179: if (currentFormat != null) {
180: format.setOptionSelected(currentFormat.getID());
181: } else if (guessedFormat != null) {
182: format.setOptionSelected(guessedFormat.getID());
183: } else {
184: format.setOptionSelected(-1);
185: }
186:
187: edit.addItem(T_info2);
188:
189: // User supplied format
190: Text userFormat = edit.addItem().addText("format_description");
191: userFormat.setLabel(T_format_user);
192: userFormat.setHelp(T_format_user_help);
193: userFormat.setValue(bitstream.getUserFormatDescription());
194:
195: // add ID of bitstream we're editing
196: div.addHidden("bitstream_id").setValue(bitstream.getID());
197:
198: // Note, not standard control actions, this page just goes back to the upload step.
199: org.dspace.app.xmlui.wing.element.Item actions = edit.addItem();
200: actions.addButton("submit_save").setValue(T_submit_save);
201: actions.addButton("submit_edit_cancel").setValue(
202: T_submit_cancel);
203:
204: div.addHidden("submission-continue").setValue(knot.getId());
205:
206: }
207:
208: }
|