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:
22: package com.izforge.izpack.panels;
23:
24: import net.n3.nanoxml.XMLElement;
25:
26: import com.izforge.izpack.installer.AutomatedInstallData;
27: import com.izforge.izpack.installer.PanelAutomation;
28: import com.izforge.izpack.util.VariableSubstitutor;
29:
30: /**
31: * Functions to support automated usage of the TargetPanel
32: *
33: * @author Jonathan Halliday
34: * @author Julien Ponge
35: */
36: public class TargetPanelAutomationHelper implements PanelAutomation {
37:
38: /**
39: * Asks to make the XML panel data.
40: *
41: * @param idata The installation data.
42: * @param panelRoot The tree to put the data in.
43: */
44: public void makeXMLData(AutomatedInstallData idata,
45: XMLElement panelRoot) {
46: // Installation path markup
47: XMLElement ipath = new XMLElement("installpath");
48: // check this writes even if value is the default,
49: // because without the constructor, default does not get set.
50: ipath.setContent(idata.getInstallPath());
51:
52: // Checkings to fix bug #1864
53: XMLElement prev = panelRoot.getFirstChildNamed("installpath");
54: if (prev != null)
55: panelRoot.removeChild(prev);
56:
57: panelRoot.addChild(ipath);
58: }
59:
60: /**
61: * Asks to run in the automated mode.
62: *
63: * @param idata The installation data.
64: * @param panelRoot The XML tree to read the data from.
65: *
66: * @return always true.
67: */
68: public boolean runAutomated(AutomatedInstallData idata,
69: XMLElement panelRoot) {
70: // We set the installation path
71: XMLElement ipath = panelRoot.getFirstChildNamed("installpath");
72:
73: // Allow for variable substitution of the installpath value
74: VariableSubstitutor vs = new VariableSubstitutor(idata
75: .getVariables());
76: String path = ipath.getContent();
77: path = vs.substitute(path, null);
78:
79: idata.setInstallPath(path);
80: return true;
81: }
82: }
|