source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/input/DirectoryInput.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: 4.5 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.input;
17
18import java.io.File;
19import java.util.ResourceBundle;
20
21import org.tp23.antinstaller.InstallerContext;
22import org.tp23.antinstaller.ValidationException;
23import org.tp23.antinstaller.renderer.MessageRenderer;
24
25/**
26 * <p>Input type to select a directory </p>
27 * <p> </p>
28 * <p>Copyright: Copyright (c) 2004</p>
29 * <p>Company: tp23</p>
30 * @author Paul Hinds
31 * @version $Id: DirectoryInput.java,v 1.5 2007/01/28 10:25:48 teknopaul Exp $
32 */
33public class DirectoryInput
34 extends OSSpecific {
35
36 private boolean abort = false;
37 private String create;
38 private String checkExists;
39
40 public DirectoryInput() {
41 }
42
43 /**
44 * Called to validate the user input
45 */
46 public boolean validate(InstallerContext cxt) throws ValidationException{
47 if (getInputResult() == null)return false;
48 MessageRenderer mr = cxt.getMessageRenderer();
49 String selectedName = getInputResult();
50 // handle no directory option
51 if( "".equals(selectedName) ){
52 if( InputField.isTrue(create) || InputField.isTrue(checkExists) ){
53 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("dirNotExist"));
54 return false;
55 }
56 else {
57 return true;
58 }
59 }
60 File file = new File(selectedName);
61 if(InputField.isTrue(create)){
62 if(!file.exists()){
63 try {
64 if(mr.prompt(org.tp23.antinstaller.Installer.langPack.getString("dirNotExistCreate") + "\n" + file.getAbsolutePath())){
65 boolean ok = file.mkdirs();
66 if(!ok){
67 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("dirNotCreated"));
68 }
69 }
70 }
71 catch (Exception ex) {
72 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("canNotCreateFile") + "\n" + file.getAbsolutePath());
73 //FIXME should not throw here, should do something better so users on linux can chmod where necessary
74 // then try again
75 throw new ValidationException(org.tp23.antinstaller.Installer.langPack.getString("canNotCreateFile"),ex);
76
77 }
78 }
79 }
80 if(InputField.isTrue(checkExists)){
81// if( ( !file.exists() || !file.isDirectory() ) && triedToCreate){
82// //TODO add some usefull text here to explain that we can not continue
83// }
84 if(!file.exists() || !file.isDirectory()){
85 mr.printMessage(org.tp23.antinstaller.Installer.langPack.getString("dirNotExist") + "\n" + file.getAbsolutePath());
86 return false;
87 }
88 }
89 return true;
90 }
91
92 public boolean isAbort() {
93 return abort;
94 }
95
96 public void setAbort(boolean abort) {
97 this.abort = abort;
98 }
99
100 public String getCreate() {
101 return create;
102 }
103 public void setCreate(String create) {
104 this.create = create;
105 }
106 public void setValue(String dir){
107 setInputResult(dir);
108 }
109
110 public String getCheckExists() {
111 return checkExists;
112 }
113
114 public void setCheckExists(String checkExists) {
115 this.checkExists = checkExists;
116 }
117
118 /**
119 * Used by checkConfig to validate the configuration file.
120 * Not used at runtime.
121 * @return boolean
122 */
123 public boolean validateObject() {
124 if(getDisplayText() == null){
125 System.out.println("Directory:displayText must be set");
126 return false;
127 }
128 if(getProperty() == null){
129 System.out.println("Directory:property must be set");
130 return false;
131 }
132 if(getDefaultValue() == null){
133 System.out.println("Directory:defaultValue must be set");
134 return false;
135 }
136 if(getDefaultValue().equals("")){
137 if( isTrue(getCreate()) || isTrue(getCheckExists()) ) {
138 System.out.println("Directory:defaultValue must be set if checkExists or create are true");
139 return false;
140 }
141 }
142 if(!InputField.optionalBoolean(getCreate())){
143 System.out.println("Directory:create must be true or false or null");
144 return false;
145 }
146 if(!InputField.optionalBoolean(getCheckExists())){
147 System.out.println("Directory:checkExists must be true or false or null");
148 return false;
149 }
150 return true;
151 }
152
153}
Note: See TracBrowser for help on using the repository browser.