📄 parameter.java
字号:
package com.ibm.staf.service.http.html;/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/import java.util.Vector;import java.util.HashMap;import java.util.List;import java.util.ArrayList;// xercesimport org.w3c.dom.html.HTMLElement;import org.w3c.dom.html.HTMLCollection;import org.w3c.dom.html.HTMLSelectElement;import org.w3c.dom.html.HTMLInputElement;import org.w3c.dom.html.HTMLTextAreaElement;import org.apache.html.dom.HTMLOptionElementImpl;/*****************************************************************************//* *//* Class: Parameter *//* Description: This class provides the handle to manipulate html form *//* controls. *//* *//*****************************************************************************/public abstract class Parameter{ String name; String type; boolean use; public static final String NAME="NAME"; public static final String TYPE="TYPE"; public static final String DISABLED="IS DISABLED"; public static final String READONLY="IS READONLY"; public static final String VALUE="VALUE"; public static final String POSSIBLEVALUES="OPTIONS"; public String getType() { return type; } public String getKey() { return name; } public boolean apply() { return use; } public void apply(boolean use) { this.use = use; } public abstract Vector[] paramString(); public abstract String getValue(); // ignores bad set values // this may change to throw some type of error // or apply(false) public abstract void setValue(String value) throws InvalidParameterValueException; public abstract void reset(); public abstract HashMap getSummary();} // end abstract class Parameter/*****************************************************************************//* *//* Class: InputParameter *//* Description: This class provides the handle to manipulate most html form *//* controls of type INPUT. *//* NOT for submit, reset, img, radio, or checkbox *//* *//*****************************************************************************/class InputParameter extends Parameter{ HTMLInputElement element; /*****************************************************************************//* *//* Method: Constructor *//* Description: Constructor method *//* Parameter: element - HTMLInputElement that will be wrapped by this class *//* to manipulate the control *//* *//*****************************************************************************/ public InputParameter(HTMLInputElement element) { name = element.getName(); if (name == null) { name = element.getId(); } type = "input type=" + element.getType(); this.element = element; use = ! element.getDisabled(); if (! element.getForm().hasAttribute(WebForm.VISITED)) element.setDefaultValue(element.getValue()); //System.out.println(name + " " + element.getDefaultValue() + // " " + element.getValue()); } public String toString() { String str = "<" + type + " name = " + name + " value = " + getValue(); if (!use) str += " disabled"; if (element != null) if (element.getReadOnly()) str += " readonly"; str += " >"; return str; } public void setValue(String value) throws InvalidParameterValueException { if (element == null) return; if (element.getReadOnly()) throw new InvalidParameterValueException (getKey() + ". readonly"); if (element.getDisabled()) throw new InvalidParameterValueException (getKey() + ". disabled"); element.setValue(value); } public String getValue() { if (element == null) return null; return element.getValue(); } public void reset() { if (element == null) return; ((HTMLInputElement)element).setValue( ((HTMLInputElement)element).getDefaultValue()); } public HashMap getSummary() { HashMap map = new HashMap(); map.put(NAME, name); map.put(TYPE, type); if (element.getDisabled()) map.put(DISABLED, "Yes"); else map.put(DISABLED, "No"); if (element.getReadOnly()) map.put(READONLY, "Yes"); else map.put(READONLY, "No"); map.put(VALUE, getValue()); return map; } public Vector[] paramString() { if (!use) return new Vector[0]; Vector[] params = new Vector [1]; params[0] = new Vector(); params[0].addElement(name); params[0].addElement(getValue()); return params; } }// end class InputParamater/*****************************************************************************//* *//* Class: NullParameter *//* Description: This class provides a way to store unused control elements. *//* This class serves as a placeholder in parameter lists for *//* reset buttons and an empty slot for submitless forms. *//* *//*****************************************************************************/class NullParameter extends Parameter{ /*****************************************************************************//* *//* Method: Constructor *//* Description: Constructor method *//* Parameter: none *//* *//*****************************************************************************/ public NullParameter() { type = "null type"; name = null; use = false; } public void reset() { return; } public HashMap getSummary() { HashMap map = new HashMap(); map.put(NAME, name); map.put(TYPE, type); map.put(VALUE, getValue()); return map; } public String getValue() { return ""; } public void setValue(String value) { return; } public Vector[] paramString() { return new Vector[0]; } public String toString() { String str = "<" + type + " name = " + name + " disabled >"; return str; }} // end class NullParameter/*****************************************************************************//* *//* Class: TextArea *//* Description: This class provides the handle to manipulate html form *//* textarea controls. *//* *//*****************************************************************************/class TextArea extends Parameter{ HTMLTextAreaElement element; /*****************************************************************************//* *//* Method: Constructor *//* Description: Constructor method *//* Parameter: element - HTMLTextAreaElement that will be wrapped by this *//* class to manipulate the control *//* *//*****************************************************************************/ public TextArea(HTMLTextAreaElement element) { name = element.getName(); if (name == null) name = element.getId(); type = "textarea"; this.element = element; use = ! element.getDisabled(); if (! element.getForm().hasAttribute(WebForm.VISITED)) element.setAttribute("DefaultValue", getValue()); } public String toString() { String str = "<" + type + " name = " + name; if (!use) str += " disabled"; if (element.getReadOnly()) str += " readonly"; str += ">" + getValue() +"</textarea>"; return str; } public void setValue(String value) throws InvalidParameterValueException { if (element.getReadOnly()) throw new InvalidParameterValueException (getKey() + ". readonly"); if (element.getDisabled()) throw new InvalidParameterValueException (getKey() + ". disabled"); /* this is not correct in xerces element.setValue(value); * below is an alternative way to get at the info */ org.w3c.dom.NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i).getNodeName().equals("#text")) list.item(i).setNodeValue(value); } } public String getValue() { /* this broken in xerces return element.getValue(); * below is an alternative way to get at the info */ org.w3c.dom.NodeList list = element.getChildNodes(); for (int i=0;i<list.getLength();i++) { if (list.item(i).getNodeName().equals("#text")) return list.item(i).getNodeValue(); } return ""; } public void reset() { try { setValue(element.getAttribute("DefaultValue")); } catch (InvalidParameterValueException e) { //should be ignored since value should be good. } } public HashMap getSummary() { HashMap map = new HashMap(); map.put(NAME, name); map.put(TYPE, type); map.put(VALUE, getValue()); if (element.getDisabled()) map.put(DISABLED, "Yes"); else map.put(DISABLED, "No"); if (element.getReadOnly()) map.put(READONLY, "Yes"); else map.put(READONLY, "No"); return map; } public Vector[] paramString() { if (!use) return new Vector[0]; Vector[] params = new Vector [1]; params[0] = new Vector(); params[0].addElement(name); params[0].addElement(getValue()); return params; } public String getType() { return type; }}// end class TextArea/*****************************************************************************//* *//* Class: Checkbox *//* Description: This class provides the handle to manipulate html form *//* input type checkbox controls. *//* *//*****************************************************************************/class CheckBox extends Parameter{ HTMLInputElement element; /*****************************************************************************//* *//* Method: Constructor *//* Description: Constructor method *//* Parameter: element - HTMLInputElement that will be wrapped by this class *//* to manipulate the control *//* *//*****************************************************************************/ public CheckBox (HTMLInputElement element) { name = element.getName(); if (name == null) name = element.getId(); type = "input type=checkbox"; this.element = element;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -