root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / PacksPanelAutomationHelper.java @ 15280
History | View | Annotate | Download (4.81 KB)
1 |
/*
|
---|---|
2 |
* $Id: PacksPanelAutomationHelper.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2003 Jonathan Halliday, Julien Ponge
|
5 |
*
|
6 |
* File : PacksPanelAutomationHelper.java
|
7 |
* Description : Automation support functions for PacksPanel.
|
8 |
* Author's email : julien@izforge.com
|
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.Vector; |
29 |
|
30 |
import net.n3.nanoxml.XMLElement; |
31 |
|
32 |
import com.izforge.izpack.Pack; |
33 |
import com.izforge.izpack.installer.AutomatedInstallData; |
34 |
import com.izforge.izpack.installer.PanelAutomation; |
35 |
|
36 |
/**
|
37 |
* Functions to support automated usage of the PacksPanel
|
38 |
*
|
39 |
* @author Jonathan Halliday
|
40 |
* @author Julien Ponge
|
41 |
*/
|
42 |
public class PacksPanelAutomationHelper implements PanelAutomation |
43 |
{ |
44 |
/**
|
45 |
* Asks to make the XML panel data.
|
46 |
*
|
47 |
* @param idata The installation data.
|
48 |
* @param panelRoot The XML tree to write the data in.
|
49 |
*/
|
50 |
public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot) |
51 |
{ |
52 |
// We add each pack to the panelRoot element
|
53 |
for (int i = 0; i < idata.availablePacks.size(); i++) |
54 |
{ |
55 |
Pack pack = (Pack) idata.availablePacks.get(i); |
56 |
XMLElement el = new XMLElement("pack"); |
57 |
el.setAttribute ("index", new Integer(i).toString()); |
58 |
el.setAttribute ("name", pack.name);
|
59 |
Boolean selected = Boolean.valueOf(idata.selectedPacks.contains (pack)); |
60 |
el.setAttribute ("selected", selected.toString ());
|
61 |
|
62 |
panelRoot.addChild(el); |
63 |
} |
64 |
} |
65 |
|
66 |
|
67 |
/**
|
68 |
* Asks to run in the automated mode.
|
69 |
*
|
70 |
* @param idata The installation data.
|
71 |
* @param panelRoot The root of the panel data.
|
72 |
*/
|
73 |
public void runAutomated(AutomatedInstallData idata, XMLElement panelRoot) |
74 |
{ |
75 |
// We first get the <selected> child (new from version 3.7.0).
|
76 |
XMLElement selectedPacks = panelRoot.getFirstChildNamed("selected");
|
77 |
// We get the packs markups
|
78 |
Vector pm = selectedPacks.getChildrenNamed("pack"); |
79 |
|
80 |
// We figure out the selected ones
|
81 |
int size = pm.size();
|
82 |
idata.selectedPacks.clear(); |
83 |
for (int i = 0; i < size; i++) |
84 |
{ |
85 |
XMLElement el = (XMLElement) pm.get(i); |
86 |
Boolean selected = new Boolean(true); // No longer needed. |
87 |
|
88 |
if (selected.booleanValue ())
|
89 |
{ |
90 |
String index_str = el.getAttribute("index"); |
91 |
|
92 |
// be liberal in what we accept
|
93 |
// (For example, this allows auto-installer files to be fitted to automatically
|
94 |
// generated installers, yes I need this! tisc.)
|
95 |
if (index_str != null) |
96 |
{ |
97 |
try
|
98 |
{ |
99 |
int index = Integer.parseInt(index_str); |
100 |
if ((index >= 0 ) && (index < idata.availablePacks.size())) |
101 |
{ |
102 |
idata.selectedPacks.add(idata.availablePacks.get(index)); |
103 |
} |
104 |
else
|
105 |
{ |
106 |
System.err.println ("Invalid pack index \""+index_str+"\" in line "+el.getLineNr()); |
107 |
} |
108 |
} |
109 |
catch (NumberFormatException e) |
110 |
{ |
111 |
System.err.println ("Invalid pack index \""+index_str+"\" in line "+el.getLineNr()); |
112 |
} |
113 |
} |
114 |
else
|
115 |
{ |
116 |
String name = el.getAttribute ("name"); |
117 |
|
118 |
if (name != null) |
119 |
{ |
120 |
// search for pack with that name
|
121 |
Iterator pack_it = idata.availablePacks.iterator ();
|
122 |
|
123 |
boolean found = false; |
124 |
|
125 |
while ((! found) && pack_it.hasNext ())
|
126 |
{ |
127 |
Pack pack = (Pack)pack_it.next(); |
128 |
|
129 |
if (pack.name.equals (name))
|
130 |
{ |
131 |
idata.selectedPacks.add (pack); |
132 |
found = true;
|
133 |
} |
134 |
|
135 |
} |
136 |
|
137 |
if (! found)
|
138 |
{ |
139 |
System.err.println ("Could not find selected pack named \""+name+"\" in line "+el.getLineNr()); |
140 |
} |
141 |
|
142 |
} |
143 |
|
144 |
} |
145 |
|
146 |
} |
147 |
|
148 |
} |
149 |
|
150 |
} |
151 |
|
152 |
} |