001: package com.canoo.webtest.extension.applet;
002:
003: import org.apache.commons.httpclient.Cookie;
004: import org.apache.log4j.Logger;
005:
006: import java.io.File;
007: import java.io.Serializable;
008: import java.net.URL;
009: import java.util.ArrayList;
010: import java.util.Arrays;
011: import java.util.HashMap;
012: import java.util.List;
013: import java.util.Map;
014: import java.util.Iterator;
015:
016: /**
017: * @author Denis N. Antonioli
018: */
019: public class AppletPluginArguments implements Serializable {
020: private static final Logger LOG = Logger
021: .getLogger(AppletPluginArguments.class);
022: static final URL[] EMPTY_URL_LIST = new URL[0];
023:
024: private URL fScenarioLocation[];
025: private String fScenario;
026: private AbstractAppletTag fAppletTag;
027: private final Map fArguments;
028: private File fOutputFile;
029: private boolean fSaveResponse;
030: private File fSaveDirectory;
031: private String fBaseWindowName;
032: private final List fCookies;
033:
034: {
035: fCookies = new ArrayList();
036: fArguments = new HashMap();
037: fScenarioLocation = EMPTY_URL_LIST;
038: }
039:
040: public URL[] getScenarioLocation() {
041: LOG.debug("get scenario location\n"
042: + listURLs(fScenarioLocation));
043: return fScenarioLocation;
044: }
045:
046: public void setScenarioLocation(URL[] newScenarioLocation) {
047: URL[] scenarioLocation = newScenarioLocation;
048: if (scenarioLocation == null) {
049: scenarioLocation = EMPTY_URL_LIST;
050: }
051: LOG.debug("set scenario location\n"
052: + listURLs(scenarioLocation));
053: fScenarioLocation = scenarioLocation;
054: }
055:
056: private static String listURLs(URL[] scenarioLocation) {
057: StringBuffer sb = new StringBuffer();
058: for (int i = 0; i < scenarioLocation.length; i++) {
059: sb.append(" ").append(
060: scenarioLocation[i].toExternalForm()).append("\n");
061: }
062: if (sb.length() > 0) {
063: sb.setLength(sb.length() - 1);
064: }
065: return sb.toString();
066: }
067:
068: public String getScenario() {
069: return fScenario;
070: }
071:
072: public void setScenario(String scenario) {
073: LOG.debug("set scenario " + scenario);
074: fScenario = scenario;
075: }
076:
077: public AbstractAppletTag getAppletTag() {
078: return fAppletTag;
079: }
080:
081: public void setAppletTag(AbstractAppletTag appletTag) {
082: fAppletTag = appletTag;
083: }
084:
085: public boolean hasArguments() {
086: return !fArguments.isEmpty();
087: }
088:
089: public void addArgument(Parameter parameter) {
090: LOG.debug("add parameter " + parameter.getName() + " to "
091: + parameter.getValue());
092: fArguments.put(parameter.getName(), parameter.getValue());
093: }
094:
095: public String getArgument(String name) {
096: return (String) fArguments.get(name);
097: }
098:
099: public Iterator getArguments() {
100: return fArguments.entrySet().iterator();
101: }
102:
103: public void setOutputFile(File outputFile) {
104: LOG.debug("set output file " + outputFile);
105: fOutputFile = outputFile;
106: }
107:
108: public File getOutputFile() {
109: return fOutputFile;
110: }
111:
112: public void setSaveResponse(boolean saveResponse) {
113: LOG.debug("set save response " + saveResponse);
114: fSaveResponse = saveResponse;
115: }
116:
117: public boolean isSaveResponse() {
118: return fSaveResponse;
119: }
120:
121: public void setSaveDirectory(File saveDirectory) {
122: LOG.debug("set save directory " + saveDirectory);
123: fSaveDirectory = saveDirectory;
124: }
125:
126: public File getSaveDirectory() {
127: return fSaveDirectory;
128: }
129:
130: public void setBaseWindowName(String baseWindowName) {
131: LOG.debug("set base window name " + baseWindowName);
132: fBaseWindowName = baseWindowName;
133: }
134:
135: public String getBaseWindowName() {
136: return fBaseWindowName;
137: }
138:
139: public void addCookies(Cookie cookies[]) {
140: fCookies.addAll(Arrays.asList(cookies));
141: }
142:
143: public Cookie[] getCookies() {
144: return (Cookie[]) fCookies.toArray(new Cookie[0]);
145: }
146: }
|