1 22 23 package com.izforge.izpack.panels; 24 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import java.util.Vector ; 28 29 import net.n3.nanoxml.XMLElement; 30 31 import com.izforge.izpack.installer.AutomatedInstallData; 32 import com.izforge.izpack.installer.PanelAutomation; 33 import com.izforge.izpack.util.Debug; 34 35 41 public class UserInputPanelAutomationHelper implements PanelAutomation 42 { 43 44 private static final String AUTO_KEY_USER_INPUT = "userInput"; 48 49 private static final String AUTO_KEY_ENTRY = "entry"; 50 51 private static final String AUTO_ATTRIBUTE_KEY = "key"; 55 56 private static final String AUTO_ATTRIBUTE_VALUE = "value"; 57 58 private Map entries; 62 63 66 public UserInputPanelAutomationHelper() 67 { 68 this.entries = null; 69 } 70 71 75 public UserInputPanelAutomationHelper(Map entries) 76 { 77 this.entries = entries; 78 } 79 80 86 public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot) 87 { 88 XMLElement userInput; 89 XMLElement dataElement; 90 91 userInput = new XMLElement(AUTO_KEY_USER_INPUT); 95 panelRoot.addChild(userInput); 96 97 Iterator keys = this.entries.keySet().iterator(); 101 while (keys.hasNext()) 102 { 103 String key = (String ) keys.next(); 104 String value = (String ) this.entries.get(key); 105 106 dataElement = new XMLElement(AUTO_KEY_ENTRY); 107 dataElement.setAttribute(AUTO_ATTRIBUTE_KEY, key); 108 dataElement.setAttribute(AUTO_ATTRIBUTE_VALUE, value); 109 110 userInput.addChild(dataElement); 111 } 112 } 113 114 122 public boolean runAutomated(AutomatedInstallData idata, XMLElement panelRoot) 123 { 124 XMLElement userInput; 125 XMLElement dataElement; 126 String variable; 127 String value; 128 129 userInput = panelRoot.getFirstChildNamed(AUTO_KEY_USER_INPUT); 133 134 if (userInput == null) { return false; } 135 136 Vector userEntries = userInput.getChildrenNamed(AUTO_KEY_ENTRY); 137 138 if (userEntries == null) { return false; } 139 140 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 return true; 155 } 156 } 157 | Popular Tags |