source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/page/Page.java@ 17514

Last change on this file since 17514 was 17514, checked in by oranfry, 16 years ago

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 7.3 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.page;
17
18import java.util.ArrayList;
19import java.util.Iterator;
20import java.util.List;
21import java.util.MissingResourceException;
22import java.util.ResourceBundle;
23import java.util.Set;
24import java.util.StringTokenizer;
25import java.util.TreeSet;
26
27import org.tp23.antinstaller.InstallException;
28import org.tp23.antinstaller.InstallerContext;
29import org.tp23.antinstaller.input.OutputField;
30import org.tp23.antinstaller.input.TargetInput;
31import org.tp23.antinstaller.runtime.IfPropertyHelper;
32/**
33 *
34 * <p>Represents a page in the installer. </p>
35 * <p>This object maintians an ordered list of targets that have been selected
36* so that when ant is run the targets are run in the correct order. If
37* Targets exist in multiple pages they are run in the order they appear in the config file. </p>
38 * <p>Copyright: Copyright (c) 2004</p>
39 * <p>Company: tp23</p>
40 * @author Paul Hinds
41 * @version $Id: Page.java,v 1.10 2007/01/19 00:24:36 teknopaul Exp $
42 */
43
44public abstract class Page {
45
46 //private static final int MAX_TARGETS = 10;
47 private String name;
48 private String displayText;
49 private String imageResource;
50 private OutputField[] outputField;
51 private boolean abort;
52 /**
53 * target to be called as the installer is running
54 */
55 private String postDisplayTarget;
56 private Set targets = new TreeSet();
57
58 public Page() {
59 }
60
61 public String getName() {
62 return name;
63 }
64
65 public void setName(String name) {
66 this.name = name;
67 }
68
69 public String getDisplayText() {
70 if( org.tp23.antinstaller.Installer.langPack != null ) {
71 return org.tp23.antinstaller.Installer.langPack.getString("page." + getName() + ".displayText");
72 }
73 return displayText;
74 }
75
76 public void setDisplayText(String displayText) {
77 this.displayText = displayText;
78 }
79
80 public String getImageResource() {
81 return imageResource;
82 }
83
84 public void setImageResource(String imageResource) {
85 this.imageResource = imageResource;
86 }
87
88 public OutputField[] getOutputField() {
89 return outputField;
90 }
91
92 public void setOutputField(OutputField[] outputField) {
93 this.outputField = outputField;
94 }
95
96 public String getPostDisplayTarget() {
97 return postDisplayTarget;
98 }
99
100 public void setPostDisplayTarget(String runtimeTarget) {
101 this.postDisplayTarget = runtimeTarget;
102 }
103
104
105 /**
106 * These are the ant targets that will be run, this is decided after
107 * the Page has been displayed. For example if the user chooses not
108 * to enter a field that may signify that a target should not be run
109 * @return A sorted List a list of Ant targets as Strings;
110 * @throws InstallException
111 */
112 public List getTargets(InstallerContext ctx) {
113 List results = new ArrayList(targets.size());
114 try {
115 Iterator iter = targets.iterator();
116 IfPropertyHelper helper = new IfPropertyHelper(ctx);
117 while(iter.hasNext()){
118 IndexedTarget idxTarget = (IndexedTarget)iter.next();
119 if( IndexedTarget.PAGE.equals(idxTarget.getTargetType()) ){
120 if( helper.ifProperty(this) || helper.ifTarget(this, ctx.getInstaller().getPages() ) ){
121 results.add(idxTarget.target);
122 }
123 }
124 else{
125 results.add(idxTarget.target);
126 }
127 }
128 } catch (InstallException e) {
129 // should not happen at runtime if ifProperty has been validated
130 e.printStackTrace();
131 ctx.log(ctx.getInstaller().isVerbose(), e);
132 throw new RuntimeException();
133 }
134 return results;
135 }
136 /**
137 * get input targets that are selected and all page targets, independent of
138 * the ifProperty value
139 * @return
140 */
141 public List getAllTargets() {
142 List results = new ArrayList(targets.size());
143 Iterator iter = targets.iterator();
144 while(iter.hasNext()){
145 IndexedTarget idxTarget = (IndexedTarget)iter.next();
146 results.add(idxTarget.target);
147 }
148 return results;
149 }
150 /**
151 * Comma separated list of targets for this page, called when parsing the
152 * config file
153 * @param target String
154 */
155 public void setTarget(String targetList) {
156 StringTokenizer st = new StringTokenizer(targetList, ",");
157 while (st.hasMoreTokens()) {
158 targets.add(new IndexedTarget(TargetInput.getGlobalIdx(),
159 st.nextToken(),
160 IndexedTarget.PAGE));
161 }
162 }
163 /**
164 * Adds an INPUT target to the Page config
165 * @param idx
166 * @param target
167 */
168 public void addTarget(int idx, String target) {
169 this.targets.add(new IndexedTarget(idx, target, IndexedTarget.INPUT));
170 }
171 public void removeTarget(int idx) {
172 this.targets.remove(new IndexedTarget(idx, null));
173 }
174 /**
175 * returns true if the page has the current target set
176 * @param target String
177 * @return boolean
178 */
179 public boolean isTarget(String target) {
180 if(target == null){
181 return false;
182 }
183 Iterator iter = targets.iterator();
184 while(iter.hasNext()) {
185 IndexedTarget idxTarget = (IndexedTarget)iter.next();
186 if(idxTarget.target.equals(target)){
187 return true;
188 }
189 }
190 return false;
191 }
192
193 /**
194 * @return a List of IndexedTarget objects
195 */
196 public List getPageTargets(){
197 List toReturn = new ArrayList(targets.size());
198 Iterator iter = targets.iterator();
199 while(iter.hasNext()) {
200 IndexedTarget idxTarget = (IndexedTarget)iter.next();
201 if( IndexedTarget.PAGE.equals(idxTarget.targetType) ){
202 toReturn.add(idxTarget);
203 }
204 }
205 return toReturn;
206 }
207
208 /**
209 * @return a List of IndexedTarget objects
210 */
211 public List getElementTargets(){
212 List toReturn = new ArrayList(targets.size());
213 Iterator iter = targets.iterator();
214 while(iter.hasNext()) {
215 IndexedTarget idxTarget = (IndexedTarget)iter.next();
216 if( IndexedTarget.INPUT.equals(idxTarget.targetType) ){
217 toReturn.add(idxTarget);
218 }
219 }
220 return toReturn;
221 }
222 /**
223 * This is called after the page is displayed, a page can return false to indicate
224 * that the installation should abort. Should be false if the cancel button is pressed.
225 * System.exit is not called to allow the installer to clean up temporary files.
226 * @return boolean
227 */
228 public boolean isAbort() {
229 return abort;
230 }
231
232 public void setAbort(boolean abort) {
233 this.abort = abort;
234 }
235 public static class IndexedTarget implements Comparable{
236
237 private static final String PAGE = "page";
238 private static final String INPUT = "input";
239
240 int idx;
241 String target;
242 String targetType = INPUT;
243
244 IndexedTarget(int idx, String target){
245 this.idx = idx;
246 this.target = target;
247 }
248 IndexedTarget(int idx, String target, String targetType){
249 this.idx = idx;
250 this.target = target;
251 this.targetType = targetType;
252 }
253
254 public boolean equals(Object target){
255 IndexedTarget test = (IndexedTarget)target;
256 return test.idx == idx;
257 }
258 // FindBugs - part of equals() contract
259 public int hashCode(){
260 return this.idx;
261 }
262 public int compareTo(Object o) {
263 IndexedTarget test = (IndexedTarget)o;
264 return idx - test.idx;
265 }
266 public String getTarget() {
267 return target;
268 }
269 public String getTargetType() {
270 return targetType;
271 }
272
273 }
274}
Note: See TracBrowser for help on using the repository browser.