KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > util > DCInputSet


1 /*
2  * DCInputSet.java
3  *
4  * Version: $Revision: 1.5 $
5  *
6  * Date: $Date: 2005/07/29 15:56:09 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.webui.util;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.Vector JavaDoc;
46 import java.util.Map JavaDoc;
47
48 /**
49  * Class representing all DC inputs required for a submission, organized into pages
50  *
51  * @author Brian S. Hughes, based on work by Jenny Toves, OCLC
52  * @version $Revision: 1.5 $
53  */

54
55 public class DCInputSet
56 {
57     /** name of the input set */
58     private String JavaDoc formName = null;
59     /** the inputs ordered by page and row position */
60     private DCInput[][] inputPages = null;
61     
62     /** constructor */
63     public DCInputSet(String JavaDoc formName, Vector JavaDoc pages, Map JavaDoc listMap)
64     {
65         this.formName = formName;
66         inputPages = new DCInput[pages.size()][];
67         for ( int i = 0; i < inputPages.length; i++ )
68         {
69             Vector JavaDoc page = (Vector JavaDoc)pages.get(i);
70             inputPages[i] = new DCInput[page.size()];
71             for ( int j = 0; j < inputPages[i].length; j++ )
72             {
73                 inputPages[i][j] = new DCInput((Map JavaDoc)page.get(j), listMap);
74             }
75         }
76     }
77     
78     /**
79      * Return the name of the form that defines this input set
80      * @return formName the name of the form
81      */

82     public String JavaDoc getFormName()
83     {
84         return formName;
85     }
86     
87     /**
88      * Return the number of pages in this input set
89      * @return number of pages
90      */

91     public int getNumberPages()
92     {
93         return inputPages.length;
94     }
95     
96     /**
97      * Get all the rows for a page from the form definition
98      *
99      * @param pageNum desired page within set
100      * @param addTitleAlternative flag to add the additional title row
101      * @param addPublishedBefore flag to add the additional published info
102      *
103      * @return an array containing the page's displayable rows
104      */

105     
106     public DCInput[] getPageRows(int pageNum, boolean addTitleAlternative,
107                                  boolean addPublishedBefore)
108     {
109         List JavaDoc filteredInputs = new ArrayList JavaDoc();
110         if ( pageNum < inputPages.length )
111         {
112             for (int i = 0; i < inputPages[pageNum].length; i++ )
113             {
114                 DCInput input = inputPages[pageNum][i];
115                 if (doField(input, addTitleAlternative, addPublishedBefore))
116                 {
117                     filteredInputs.add(input);
118                 }
119             }
120         }
121
122         // Convert list into an array
123
DCInput[] inputArray = new DCInput[filteredInputs.size()];
124         return (DCInput[])filteredInputs.toArray(inputArray);
125     }
126     
127     /**
128      * Does this set of inputs include an alternate title field?
129      *
130      * @return true if the current set has an alternate title field
131      */

132     public boolean isDefinedMultTitles()
133     {
134         return isFieldPresent("title.alternative");
135     }
136     
137     /**
138      * Does this set of inputs include the previously published fields?
139      *
140      * @return true if the current set has all the prev. published fields
141      */

142     public boolean isDefinedPubBefore()
143     {
144         return ( isFieldPresent("date.issued") &&
145                  isFieldPresent("identifier.citation") &&
146                  isFieldPresent("publisher.null") );
147     }
148     
149     /**
150      * Does the current input set define the named field?
151      * Scan through every field in every page of the input set
152      *
153      * @return true if the current set has the named field
154      */

155     public boolean isFieldPresent(String JavaDoc fieldName)
156     {
157         for (int i = 0; i < inputPages.length; i++)
158         {
159             DCInput[] pageInputs = inputPages[i];
160             for (int row = 0; row < pageInputs.length; row++)
161             {
162                 String JavaDoc fullName = pageInputs[row].getElement() + "." +
163                                   pageInputs[row].getQualifier();
164                 if (fullName.equals(fieldName))
165                 {
166                     return true;
167                 }
168             }
169         }
170         return false;
171     }
172     
173     private static boolean doField(DCInput dcf, boolean addTitleAlternative,
174                                    boolean addPublishedBefore)
175     {
176         String JavaDoc rowName = dcf.getElement() + "." + dcf.getQualifier();
177         if ( rowName.equals("title.alternative") && ! addTitleAlternative )
178         {
179             return false;
180         }
181         if (rowName.equals("date.issued") && ! addPublishedBefore )
182         {
183             return false;
184         }
185         if (rowName.equals("publisher.null") && ! addPublishedBefore )
186         {
187             return false;
188         }
189         if (rowName.equals("identifier.citation") && ! addPublishedBefore )
190         {
191             return false;
192         }
193
194         return true;
195     }
196 }
197
Popular Tags