001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.input;
017:
018: import java.io.File;
019:
020: import org.tp23.antinstaller.InstallerContext;
021: import org.tp23.antinstaller.ValidationException;
022:
023: /**
024: *
025: * <p>Input type to select a directory </p>
026: * <p> </p>
027: * <p>Copyright: Copyright (c) 2004</p>
028: * <p>Company: tp23</p>
029: * @author Paul Hinds
030: * @version $Id: FileInput.java,v 1.2 2007/01/28 10:25:48 teknopaul Exp $
031: */
032: public class FileInput extends OSSpecific {
033:
034: private boolean abort = false;
035: private String checkExists;
036:
037: public FileInput() {
038: }
039:
040: /**
041: * Called to validate the user input
042: */
043: public boolean validate(InstallerContext ctx)
044: throws ValidationException {
045: if (getInputResult() == null) { // this does not happen
046: return false;
047: }
048: if (InputField.isTrue(checkExists)) {
049: File file = new File(getInputResult());
050: if (!file.exists()) {
051: return false;
052: }
053: }
054: return true;
055: }
056:
057: public boolean isAbort() {
058: return abort;
059: }
060:
061: public void setAbort(boolean abort) {
062: this .abort = abort;
063: }
064:
065: public String getCheckExists() {
066: return checkExists;
067: }
068:
069: public void setCheckExists(String checkExists) {
070: this .checkExists = checkExists;
071: }
072:
073: public void setValue(String dir) {
074: setInputResult(dir);
075: }
076:
077: /**
078: * Used by checkConfig to validate the configuration file.
079: * Not used at runtime.
080: * @return boolean
081: */
082: public boolean validateObject() {
083: if (getDisplayText() == null) {
084: System.out.println("File:displayText must be set");
085: return false;
086: }
087: if (getProperty() == null) {
088: System.out.println("File:property must be set");
089: return false;
090: }
091: if (getDefaultValue() == null) {
092: System.out.println("File:defaultValue must be set");
093: return false;
094: }
095: if (!InputField.optionalBoolean(getCheckExists())) {
096: System.out
097: .println("File:checkExists must be true or false or null");
098: return false;
099: }
100: return true;
101: }
102: }
|