root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / UserInputPanelAutomationHelper.java @ 15280
History | View | Annotate | Download (5.09 KB)
1 |
/*
|
---|---|
2 |
* $Id: UserInputPanelAutomationHelper.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2002-2003 Jonathan Halliday, Elmar Grom
|
5 |
*
|
6 |
* File : UserInputPanelAutomationHelper.java
|
7 |
* Description : Automation support functions for UserInputPanel.
|
8 |
* Author's email : elmar@grom.net
|
9 |
* Author's Website : http://www.izforge.com
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
24 |
*/
|
25 |
package com.izforge.izpack.panels; |
26 |
|
27 |
import java.util.Iterator; |
28 |
import java.util.Map; |
29 |
import java.util.Vector; |
30 |
|
31 |
import net.n3.nanoxml.XMLElement; |
32 |
|
33 |
import com.izforge.izpack.installer.AutomatedInstallData; |
34 |
import com.izforge.izpack.installer.PanelAutomation; |
35 |
import com.izforge.izpack.util.Debug; |
36 |
|
37 |
/**
|
38 |
* Functions to support automated usage of the UserInputPanel
|
39 |
*
|
40 |
* @author Jonathan Halliday
|
41 |
* @author Elmar Grom
|
42 |
*/
|
43 |
public class UserInputPanelAutomationHelper implements PanelAutomation |
44 |
{ |
45 |
// ------------------------------------------------------
|
46 |
// automatic script section keys
|
47 |
// ------------------------------------------------------
|
48 |
private static final String AUTO_KEY_USER_INPUT = "userInput"; |
49 |
private static final String AUTO_KEY_ENTRY = "entry"; |
50 |
|
51 |
// ------------------------------------------------------
|
52 |
// automatic script keys attributes
|
53 |
// ------------------------------------------------------
|
54 |
private static final String AUTO_ATTRIBUTE_KEY = "key"; |
55 |
private static final String AUTO_ATTRIBUTE_VALUE = "value"; |
56 |
|
57 |
// ------------------------------------------------------
|
58 |
// String-String key-value pairs
|
59 |
// ------------------------------------------------------
|
60 |
private Map entries; |
61 |
|
62 |
public UserInputPanelAutomationHelper ()
|
63 |
{ |
64 |
this.entries = null; |
65 |
} |
66 |
|
67 |
/**
|
68 |
*
|
69 |
* @param entries String-String key-value pairs representing the state of the Panel
|
70 |
*/
|
71 |
public UserInputPanelAutomationHelper(Map entries) |
72 |
{ |
73 |
this.entries = entries;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Serialize state to XML and insert under panelRoot.
|
78 |
*
|
79 |
* @param idata The installation data.
|
80 |
* @param panelRoot The XML root element of the panels blackbox tree.
|
81 |
*/
|
82 |
public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot) |
83 |
{ |
84 |
XMLElement userInput; |
85 |
XMLElement dataElement; |
86 |
|
87 |
// ----------------------------------------------------
|
88 |
// add the item that combines all entries
|
89 |
// ----------------------------------------------------
|
90 |
userInput = new XMLElement(AUTO_KEY_USER_INPUT);
|
91 |
panelRoot.addChild(userInput); |
92 |
|
93 |
// ----------------------------------------------------
|
94 |
// add all entries
|
95 |
// ----------------------------------------------------
|
96 |
Iterator keys = entries.keySet().iterator();
|
97 |
while (keys.hasNext())
|
98 |
{ |
99 |
String key = (String) keys.next(); |
100 |
String value = (String) entries.get(key); |
101 |
|
102 |
dataElement = new XMLElement(AUTO_KEY_ENTRY);
|
103 |
dataElement.setAttribute(AUTO_ATTRIBUTE_KEY, key); |
104 |
dataElement.setAttribute(AUTO_ATTRIBUTE_VALUE, value); |
105 |
|
106 |
userInput.addChild(dataElement); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Deserialize state from panelRoot and set idata variables accordingly.
|
112 |
*
|
113 |
* @param idata The installation data.
|
114 |
* @param panelRoot The XML root element of the panels blackbox tree.
|
115 |
*/
|
116 |
public void runAutomated(AutomatedInstallData idata, XMLElement panelRoot) |
117 |
{ |
118 |
XMLElement userInput; |
119 |
XMLElement dataElement; |
120 |
String variable;
|
121 |
String value;
|
122 |
|
123 |
// ----------------------------------------------------
|
124 |
// get the section containing the user entries
|
125 |
// ----------------------------------------------------
|
126 |
userInput = panelRoot.getFirstChildNamed(AUTO_KEY_USER_INPUT); |
127 |
|
128 |
if (userInput == null) |
129 |
{ |
130 |
return;
|
131 |
} |
132 |
|
133 |
Vector userEntries = userInput.getChildrenNamed(AUTO_KEY_ENTRY);
|
134 |
|
135 |
if (userEntries == null) |
136 |
{ |
137 |
return;
|
138 |
} |
139 |
|
140 |
// ----------------------------------------------------
|
141 |
// retieve each entry and substitute the associated
|
142 |
// variable
|
143 |
// ----------------------------------------------------
|
144 |
for (int i = 0; i < userEntries.size(); i++) |
145 |
{ |
146 |
dataElement = (XMLElement) userEntries.elementAt(i); |
147 |
variable = dataElement.getAttribute(AUTO_ATTRIBUTE_KEY); |
148 |
value = dataElement.getAttribute(AUTO_ATTRIBUTE_VALUE); |
149 |
|
150 |
Debug.trace ("UserInputPanel: setting variable "+variable+" to "+value); |
151 |
idata.setVariable(variable, value); |
152 |
} |
153 |
} |
154 |
} |