source: release-kits/lirk3/bin/ant-installer/src/org/tp23/antinstaller/input/AppRootInput.java@ 14982

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

initial import of LiRK3

File size: 4.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.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 *
27 * <p>Input type to select a directory and validate it by checking the existence of
28 * files relative to the directory selected. An Expected use for this is to find the
29 * Application root of an exiting app on the clients machine. for example to find
30 * Tomcat, ask the user to select the tomcat root and check the existence of ./conf/tomcat-users.xml
31 * and ./webapps </p>
32 * @author Paul Hinds
33 * @version $Id: AppRootInput.java,v 1.2 2005/10/23 14:39:20 teknopaul Exp $
34 */
35public class AppRootInput
36 extends DirectoryInput {
37
38 private static final ResourceBundle res = ResourceBundle.getBundle("org.tp23.antinstaller.renderer.Res");
39
40
41 private String checkFile1;
42 private String checkFile2;
43 private String checkDir1;
44 private String checkDir2;
45
46 public AppRootInput() {
47 }
48
49 /**
50 * Called to validate the user input
51 */
52 public boolean validate(InstallerContext cxt) throws ValidationException{
53 if (getInputResult() == null)return false;
54 MessageRenderer mr = cxt.getMessageRenderer();
55 String directorySelected = getInputResult();
56 File file = new File(directorySelected);
57 // removed in response to BUG:1303230
58// if(!file.exists()){
59// if(mr.prompt(res.getString("dirNotExistCreate"))){
60// boolean ok = file.mkdirs();
61// if(!ok)mr.printMessage(res.getString("dirNotCreated"));
62// }
63// }
64 if(!file.isDirectory()){
65 mr.printMessage(res.getString("dirNotExist")+":"+file.getAbsolutePath());
66 return false;
67 }
68 else if(checkFile1!=null && ! checkExists(mr,file,checkFile1)){
69 return false ;
70 }
71 else if(checkFile2!=null && ! checkExists(mr,file,checkFile2)){
72 return false ;
73 }
74 else if(checkDir1!=null && ! checkExists(mr,file,checkDir1)){
75 return false ;
76 }
77 else if(checkDir2!=null && ! checkExists(mr,file,checkDir2)){
78 return false ;
79 }
80 return true;
81 }
82
83 private boolean checkExists(MessageRenderer mr,File root,String check){
84 File checkFile = new File(root,checkFile1);
85 if(!checkFile.exists()){
86 reportMissing(mr,checkFile);
87 return false;
88 }
89 return true;
90 }
91
92 private void reportMissing(MessageRenderer mr,File missing){
93 StringBuffer message = new StringBuffer();
94 message.append(res.getString("appRootInvalid"));
95 message.append(System.getProperty("line.separator"));
96 if(missing.isDirectory()){
97 message.append(res.getString("dirNotExist"));
98 }
99 else{
100 message.append(res.getString("fileNotExist"));
101 }
102 message.append(":");
103 message.append(missing.getAbsolutePath());
104 mr.printMessage(message.toString());
105 }
106
107
108
109 public String getCheckDir1() {
110 return checkDir1;
111 }
112
113 public String getCheckDir2() {
114 return checkDir2;
115 }
116
117 public String getCheckFile1() {
118 return checkFile1;
119 }
120
121 public String getCheckFile2() {
122 return checkFile2;
123 }
124
125 public void setCheckFile2(String checkFile2) {
126 this.checkFile2 = checkFile2;
127 }
128
129 public void setCheckFile1(String checkFile1) {
130 this.checkFile1 = checkFile1;
131 }
132
133 public void setCheckDir2(String checkDir2) {
134 this.checkDir2 = checkDir2;
135 }
136
137 public void setCheckDir1(String checkDir1) {
138 this.checkDir1 = checkDir1;
139 }
140
141 /**
142 * Used by checkConfig to validate the configuration file.
143 * Not used at runtime.
144 * @return boolean
145 */
146 public boolean validateObject() {
147 if(getDisplayText()==null){
148 System.out.println("AppRoot:displayText must be set");
149 return false;
150 }
151 if(getProperty()==null){
152 System.out.println("AppRoot:property must be set");
153 return false;
154 }
155 if(getDefaultValue()==null){
156 System.out.println("AppRoot:defaultValue must be set");
157 return false;
158 }
159 return true;
160 }
161
162}
Note: See TracBrowser for help on using the repository browser.