1
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
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
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 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{
00 message.append(res.getString("fileNotExist"));
01 }
02 message.append(":");
03 message.append(missing.getAbsolutePath());
04 mr.printMessage(message.toString());
05 }
06
07
08
09 public String getCheckDir1() {
10 return checkDir1;
11 }
12
13 public String getCheckDir2() {
14 return checkDir2;
15 }
16
17 public String getCheckFile1() {
18 return checkFile1;
19 }
20
21 public String getCheckFile2() {
22 return checkFile2;
23 }
24
25 public void setCheckFile2(String checkFile2) {
26 this.checkFile2 = checkFile2;
27 }
28
29 public void setCheckFile1(String checkFile1) {
30 this.checkFile1 = checkFile1;
31 }
32
33 public void setCheckDir2(String checkDir2) {
34 this.checkDir2 = checkDir2;
35 }
36
37 public void setCheckDir1(String checkDir1) {
38 this.checkDir1 = checkDir1;
39 }
40
41
46 public boolean validateObject() {
47 if(getDisplayText()==null){
48 System.out.println("AppRoot:displayText must be set");
49 return false;
50 }
51 if(getProperty()==null){
52 System.out.println("AppRoot:property must be set");
53 return false;
54 }
55 if(getDefaultValue()==null){
56 System.out.println("AppRoot:defaultValue must be set");
57 return false;
58 }
59 return true;
60 }
61
62}
63