1 package org.sourceforge.vlibrary.user.forms;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.StringTokenizer;
6
7 import javax.servlet.http.HttpServletRequest;
8
9 import org.apache.struts.action.ActionErrors;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionMapping;
12 import org.apache.struts.action.ActionMessage;
13 import org.sourceforge.vlibrary.user.domain.Location;
14 import org.sourceforge.vlibrary.user.domain.Subject;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public class BookSearchForm extends ActionForm {
34 private static final long serialVersionUID = 0;
35
36 private String selector = "None";
37 private String title = null;
38 private String authorLastName = null;
39 private ArrayList<Subject> subjects = null;
40 private ArrayList<Location> locations = null;
41 private String queryType = "Or";
42 private ArrayList<Subject> subjectList = null;
43
44 public BookSearchForm() {
45 }
46
47 public String getAuthorLastName() {
48 return authorLastName;
49 }
50
51 public void setAuthorLastName(String authorLastName) {
52 this.authorLastName = authorLastName;
53 }
54
55 public String getQueryType() {
56 return queryType;
57 }
58
59 public void setQueryType(String queryType) {
60 this.queryType = queryType;
61 }
62
63 public String getSelector() {
64 return selector;
65 }
66
67 public void setSelector(String selector) {
68 this.selector = selector;
69 }
70
71 public ArrayList<Subject> getSubjects() {
72 return subjects;
73 }
74
75 public void setSubjects(ArrayList<Subject> subjects) {
76 this.subjects = subjects;
77 }
78
79 public String getSubjectString() {
80 if (subjects == null) return null;
81
82 StringBuffer buf = new StringBuffer();
83 Subject su = null;
84
85 for (int i=0;i<subjects.size();i++) {
86 su = subjects.get(i);
87 buf.append(su.getDescription());
88 buf.append("\n");
89 }
90
91 return buf.toString();
92 }
93
94 public String getSubjectListString() {
95 if (subjectList == null) return null;
96 StringBuffer buf = new StringBuffer();
97 Subject su = null;
98
99 for (int i=0;i<subjectList.size();i++) {
100 su = (Subject)subjectList.get(i);
101 buf.append(su.getDescription());
102 buf.append("\n");
103 }
104
105 return buf.toString();
106 }
107
108
109
110
111
112
113
114
115
116 public void setSubjectString(String inString) {
117 StringTokenizer st = new StringTokenizer(inString,"\n");
118 if (!st.hasMoreElements()) return;
119 subjects = null;
120 subjects = new ArrayList<Subject>();
121 while (st.hasMoreElements()) {
122 Subject su = new Subject(st.nextToken());
123 subjects.add(su);
124 }
125 }
126
127 public String getTitle() {
128 return title;
129 }
130
131 public void setTitle(String title) {
132 this.title = title;
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147 public ActionErrors validate(ActionMapping mapping,
148 HttpServletRequest request) {
149
150 ActionErrors errors = new ActionErrors();
151
152 if ( selector.equals("Title") &&
153 ( title == null || title.length() < 1)) {
154 errors.add("title", new ActionMessage("error.book.title.required"));
155
156 return errors;
157 }
158
159 if ( selector.equals("Author") &&
160 (authorLastName == null || authorLastName.length() < 1)) {
161 errors.add("author", new ActionMessage("error.book.author.required"));
162
163 return errors;
164 }
165
166
167 if ( selector.equals("Subject") && subjects == null) {
168 errors.add("subjects",
169 new ActionMessage("error.book.search.subject.required"));
170
171 return errors;
172 }
173
174 return errors;
175 }
176
177
178
179
180 public ArrayList<Subject> getSubjectList() {
181 return subjectList;
182 }
183
184
185
186
187 public void setSubjectList(ArrayList<Subject> subjectList) {
188 this.subjectList = subjectList;
189 }
190
191 public void setLocations(ArrayList<Location> locations) {
192 this.locations = locations;
193 }
194
195 public ArrayList<Location> getLocations() {
196 return locations;
197 }
198 }