01: /*
02: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
03: *
04: * http://izpack.org/
05: * http://izpack.codehaus.org/
06: *
07: * Copyright 2003 Jonathan Halliday
08: *
09: * Licensed under the Apache License, Version 2.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.apache.org/licenses/LICENSE-2.0
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: */
21: package com.izforge.izpack.panels;
22:
23: import net.n3.nanoxml.XMLElement;
24: import com.izforge.izpack.installer.AutomatedInstallData;
25: import com.izforge.izpack.installer.PanelAutomation;
26: import com.izforge.izpack.util.VariableSubstitutor;
27:
28: /**
29: * Functions to support automated usage of the UserPathPanel
30: *
31: * @author Jonathan Halliday
32: * @author Julien Ponge
33: * @author Jeff Gordon
34: */
35: public class UserPathPanelAutomationHelper implements PanelAutomation {
36:
37: /**
38: * Asks to make the XML panel data.
39: *
40: * @param idata The installation data.
41: * @param panelRoot The tree to put the data in.
42: */
43: public void makeXMLData(AutomatedInstallData idata,
44: XMLElement panelRoot) {
45: // Installation path markup
46: XMLElement ipath = new XMLElement(UserPathPanel.pathElementName);
47: // check this writes even if value is the default,
48: // because without the constructor, default does not get set.
49: ipath.setContent(idata
50: .getVariable(UserPathPanel.pathVariableName));
51:
52: // Checkings to fix bug #1864
53: XMLElement prev = panelRoot
54: .getFirstChildNamed(UserPathPanel.pathElementName);
55: if (prev != null) {
56: panelRoot.removeChild(prev);
57: }
58: panelRoot.addChild(ipath);
59: }
60:
61: /**
62: * Asks to run in the automated mode.
63: *
64: * @param idata The installation data.
65: * @param panelRoot The XML tree to read the data from.
66: *
67: * @return always true.
68: */
69: public boolean runAutomated(AutomatedInstallData idata,
70: XMLElement panelRoot) {
71: // We set the installation path
72: XMLElement ipath = panelRoot
73: .getFirstChildNamed(UserPathPanel.pathElementName);
74:
75: // Allow for variable substitution of the installpath value
76: VariableSubstitutor vs = new VariableSubstitutor(idata
77: .getVariables());
78: String path = ipath.getContent();
79: path = vs.substitute(path, null);
80: idata.setVariable(UserPathPanel.pathVariableName, path);
81: return true;
82: }
83: }
|