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.util.MissingResourceException;
19import java.util.ResourceBundle;
20
21/**
22 *
23 * <p>Object representation of an inputField XML Element </p>
24 * <p>Also used to hold data of the results of the installer questions </p>
25 * @author Paul Hinds
26 * @version $Id: InputField.java,v 1.4 2006/12/07 02:50:27 teknopaul Exp $
27 */
28public abstract class InputField
29    extends OutputField {
30
31    // i18n support
32    private static ResourceBundle langPack = null;
33    static{
34        try {
35            langPack = ResourceBundle.getBundle("resources.LanguagePack");
36        } catch (MissingResourceException e) {
37            // ignore, signifies no lang packs installed  
38        }
39    }
40
41    private String property;
42    protected String defaultValue;
43
44    /**
45     * Flag to indicate that the user has already editted this field
46     */
47    private boolean editted = false;
48
49    public InputField() {
50    }
51
52    public String getDisplayText() {
53        if(langPack != null){
54            return langPack.getString(getProperty() + ".displayText");
55        }
56        return displayText;
57    }
58    public String getExplanatoryText() {
59        if(langPack != null){
60            try {
61                return langPack.getString(getProperty() + ".explanatoryText");
62            } catch (MissingResourceException e) {
63                // ignore and return null explanatoryText is optional
64            }
65        }
66        return explanatoryText;
67    }
68
69    /**
70     * Returns the input result if there is one and if this is a PropertyField
71     * @return String
72     */
73    public String getInputResult() {
74        return resultContainer.getProperty(property);
75    }
76
77    public void setInputResult(String inputResult) {
78        resultContainer.setProperty(property, inputResult);
79    }
80    public boolean isEditted() {
81        return editted;
82    }
83    public void setEditted(boolean editted) {
84        this.editted = editted;
85    }
86    public void setResultContainer(ResultContainer resultContainer) {
87        this.resultContainer = resultContainer;
88    }
89
90    public String getProperty() {
91        return property;
92    }
93
94    public void setProperty(String property) {
95        this.property = property;
96    }
97
98    public String getDefaultValue() {
99        return resultContainer.getDefaultValue(defaultValue);
00    }
01
02    public void setDefaultValue(String defaultValue) {
03        this.defaultValue = defaultValue;
04    }
05
06
07}
08