001: /*
002: * DCInputSet.java
003: *
004: * Version: $Revision: 2044 $
005: *
006: * Date: $Date: 2007-07-06 18:59:33 -0500 (Fri, 06 Jul 2007) $
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:
041: package org.dspace.app.util;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045: import java.util.Vector;
046: import java.util.Map;
047:
048: /**
049: * Class representing all DC inputs required for a submission, organized into pages
050: *
051: * @author Brian S. Hughes, based on work by Jenny Toves, OCLC
052: * @version $Revision: 2044 $
053: */
054:
055: public class DCInputSet {
056: /** name of the input set */
057: private String formName = null;
058: /** the inputs ordered by page and row position */
059: private DCInput[][] inputPages = null;
060:
061: /** constructor */
062: public DCInputSet(String formName, Vector pages, Map listMap) {
063: this .formName = formName;
064: inputPages = new DCInput[pages.size()][];
065: for (int i = 0; i < inputPages.length; i++) {
066: Vector page = (Vector) pages.get(i);
067: inputPages[i] = new DCInput[page.size()];
068: for (int j = 0; j < inputPages[i].length; j++) {
069: inputPages[i][j] = new DCInput((Map) page.get(j),
070: listMap);
071: }
072: }
073: }
074:
075: /**
076: * Return the name of the form that defines this input set
077: * @return formName the name of the form
078: */
079: public String getFormName() {
080: return formName;
081: }
082:
083: /**
084: * Return the number of pages in this input set
085: * @return number of pages
086: */
087: public int getNumberPages() {
088: return inputPages.length;
089: }
090:
091: /**
092: * Get all the rows for a page from the form definition
093: *
094: * @param pageNum desired page within set
095: * @param addTitleAlternative flag to add the additional title row
096: * @param addPublishedBefore flag to add the additional published info
097: *
098: * @return an array containing the page's displayable rows
099: */
100:
101: public DCInput[] getPageRows(int pageNum,
102: boolean addTitleAlternative, boolean addPublishedBefore) {
103: List filteredInputs = new ArrayList();
104: if (pageNum < inputPages.length) {
105: for (int i = 0; i < inputPages[pageNum].length; i++) {
106: DCInput input = inputPages[pageNum][i];
107: if (doField(input, addTitleAlternative,
108: addPublishedBefore)) {
109: filteredInputs.add(input);
110: }
111: }
112: }
113:
114: // Convert list into an array
115: DCInput[] inputArray = new DCInput[filteredInputs.size()];
116: return (DCInput[]) filteredInputs.toArray(inputArray);
117: }
118:
119: /**
120: * Does this set of inputs include an alternate title field?
121: *
122: * @return true if the current set has an alternate title field
123: */
124: public boolean isDefinedMultTitles() {
125: return isFieldPresent("title.alternative");
126: }
127:
128: /**
129: * Does this set of inputs include the previously published fields?
130: *
131: * @return true if the current set has all the prev. published fields
132: */
133: public boolean isDefinedPubBefore() {
134: return (isFieldPresent("date.issued")
135: && isFieldPresent("identifier.citation") && isFieldPresent("publisher.null"));
136: }
137:
138: /**
139: * Does the current input set define the named field?
140: * Scan through every field in every page of the input set
141: *
142: * @return true if the current set has the named field
143: */
144: public boolean isFieldPresent(String fieldName) {
145: for (int i = 0; i < inputPages.length; i++) {
146: DCInput[] pageInputs = inputPages[i];
147: for (int row = 0; row < pageInputs.length; row++) {
148: String fullName = pageInputs[row].getElement() + "."
149: + pageInputs[row].getQualifier();
150: if (fullName.equals(fieldName)) {
151: return true;
152: }
153: }
154: }
155: return false;
156: }
157:
158: private static boolean doField(DCInput dcf,
159: boolean addTitleAlternative, boolean addPublishedBefore) {
160: String rowName = dcf.getElement() + "." + dcf.getQualifier();
161: if (rowName.equals("title.alternative") && !addTitleAlternative) {
162: return false;
163: }
164: if (rowName.equals("date.issued") && !addPublishedBefore) {
165: return false;
166: }
167: if (rowName.equals("publisher.null") && !addPublishedBefore) {
168: return false;
169: }
170: if (rowName.equals("identifier.citation")
171: && !addPublishedBefore) {
172: return false;
173: }
174:
175: return true;
176: }
177: }
|