⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform.java

📁 这是远程web服务调用的一个包,可以将JSP直接作为服务
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            } else if (value instanceof Number) {                setParameterValue( propertyName, HttpUnitUtils.trimmedValue( (Number) value ) );            } else {                super.set( propertyName, value );            }        }        public void setParameterValue( String name, String value ) {            final Object scriptableObject = getParameter( name ).getScriptableObject();            if (scriptableObject instanceof ScriptableDelegate) {                ((ScriptableDelegate) scriptableObject).set( "value", value );            } else if (scriptableObject instanceof ScriptableDelegate[]) {                ((ScriptableDelegate[]) scriptableObject)[0].set( "value", value );            }        }        public ScriptableDelegate[] getElementDelegates() {            FormControl[] controls = getFormControls();            ScriptableDelegate[] result = new ScriptableDelegate[ controls.length ];            for (int i = 0; i < result.length; i++) {                result[i] = controls[i].getScriptableDelegate();            }            return result;        }        public ScriptableDelegate[] getElementsByTagName( String name ) throws SAXException {            return getDelegates( getHTMLPage().getElementsByTagName( getNode(), name ) );        }        Scriptable() {            super( WebForm.this );        }    }//---------------------------------- package members --------------------------------    /**     * Contructs a web form given the URL of its source page and the DOM extracted     * from that page.     **/    WebForm( WebResponse response, URL baseURL, Node node, FrameSelector frame, String defaultTarget, String characterSet ) {        super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "action" ), frame, defaultTarget );        _characterSet = characterSet;    }    /**     * Returns the form control which is part of this form with the specified ID.     */    FormControl getControlWithID( String id ) {        FormControl[] controls = getFormControls();        for (int i = 0; i < controls.length; i++) {            FormControl control = controls[i];            if (control.getID().equals(id)) return control;        }        return null;    }//---------------------------------- private members --------------------------------    private final static String[] NO_VALUES = new String[0];    /** The attributes of the form parameters. **/    private FormControl[] _formControls;    /** The submit buttons in this form. **/    private SubmitButton[] _submitButtons;    /** The character set in which the form will be submitted. **/    private String         _characterSet;    /** A map of parameter names to form parameter objects. **/    private Map            _formParameters;    /** The Scriptable object associated with this form. **/    private Scriptable _scriptable;    private Vector _buttonVector;    private FormControl[] _presetParameters;    private ArrayList     _presets;    private SubmitButton getDefaultButton() {        if (getSubmitButtons().length == 1) {            return getSubmitButtons()[0];        } else {            return getSubmitButton( "" );        }    }    private Vector getSubmitButtonVector() {        if (_buttonVector == null) {            _buttonVector = new Vector();            FormControl[] controls = getFormControls();            for (int i = 0; i < controls.length; i++) {                FormControl control = controls[ i ];                if (control instanceof SubmitButton) _buttonVector.add( control );            }            if (_buttonVector.isEmpty()) _buttonVector.addElement( new SubmitButton( this ) );        }        return _buttonVector;    }    private FormControl[] getPresetParameters() {        if (_presetParameters == null) {            _presets = new ArrayList();            loadDestinationParameters();            _presetParameters = (FormControl[]) _presets.toArray( new FormControl[ _presets.size() ] );        }        return _presetParameters;    }    private ArrayList _controlList = new ArrayList();    FormControl newFormControl( Node child ) {        return FormControl.newFormParameter( this, child );    }    void addFormControl( FormControl control ) {        _controlList.add( control );        _formControls = null;        _formParameters = null;    }    /**     * Returns an array of form parameter attributes for this form.     **/    private FormControl[] getFormControls() {        if (_formControls == null) {            _formControls = (FormControl[]) _controlList.toArray( new FormControl[ _controlList.size() ] );        }        return _formControls;    }    private FormParameter getParameter( String name ) {        final FormParameter parameter = ((FormParameter) getFormParameters().get( name ));        return parameter != null ? parameter : UNKNOWN_PARAMETER;    }    /**     * Returns a map of parameter name to form parameter objects. Each form parameter object represents the set of form     * controls with a particular name. Unnamed parameters are ignored.     */    private Map getFormParameters() {        if (_formParameters == null) {            _formParameters = new HashMap();            loadFormParameters( getPresetParameters() );            loadFormParameters( getFormControls() );        }        return _formParameters;    }    private void loadFormParameters( FormControl[] controls ) {        for (int i = 0; i < controls.length; i++) {            if (controls[i].getName().length() == 0) continue;            FormParameter parameter = (FormParameter) _formParameters.get( controls[i].getName() );            if (parameter == null) {                parameter = new FormParameter();                _formParameters.put( controls[i].getName(), parameter );            }            parameter.addControl( controls[i] );        }    }    static {        MATCH_NAME = new HTMLElementPredicate() {            public boolean matchesCriteria( Object htmlElement, Object criteria ) {                return HttpUnitUtils.matches( ((WebForm) htmlElement).getName(), (String) criteria );            };        };    }//===========================---===== exception class NoSuchParameterException =========================================    /**     * This exception is thrown on an attempt to set a parameter to a value not permitted to it by the form.     **/    class NoSuchParameterException extends IllegalRequestParameterException {        NoSuchParameterException( String parameterName ) {            _parameterName = parameterName;        }        public String getMessage() {            return "No parameter named '" + _parameterName + "' is defined in the form";        }        private String _parameterName;    }//============================= exception class IllegalUnnamedSubmitButtonException ======================================    /**     * This exception is thrown on an attempt to define a form request with a button not defined on that form.     **/    class IllegalUnnamedSubmitButtonException extends IllegalRequestParameterException {        IllegalUnnamedSubmitButtonException() {        }        public String getMessage() {            return "This form has more than one submit button, none unnamed. You must specify the button to be used.";        }    }//============================= exception class IllegalSubmitButtonException ======================================    /**     * This exception is thrown on an attempt to define a form request with a button not defined on that form.     **/    class IllegalSubmitButtonException extends IllegalRequestParameterException {        IllegalSubmitButtonException( SubmitButton button ) {            _name  = button.getName();            _value = button.getValue();        }        IllegalSubmitButtonException( String name, String value ) {            _name = name;            _value = value;        }        public String getMessage() {            return "Specified submit button (name=\"" + _name + "\" value=\"" + _value + "\") not part of this form.";        }        private String _name;        private String _value;    }//============================= exception class IllegalUnnamedSubmitButtonException ======================================    /**     * This exception is thrown on an attempt to define a form request with a button not defined on that form.     **/    class DisabledSubmitButtonException extends IllegalStateException {        DisabledSubmitButtonException( SubmitButton button ) {            _name  = button.getName();            _value = button.getValue();        }        public String getMessage() {            return "The specified button (name='" + _name + "' value='" + _value                   + "' is disabled and may not be used to submit this form.";        }        private String _name;        private String _value;    }}//========================================== class PresetFormParameter =================================================    class PresetFormParameter extends FormControl {        PresetFormParameter( WebForm form, String name, String value ) {            super( form );            _name   = name;            _value  = value;        }        /**         * Returns the name of this control..         **/        public String getName() {            return _name;        }        /**         * Returns true if this control is read-only.         **/        public boolean isReadOnly() {            return true;        }        /**         * Returns true if this control accepts free-form text.         **/        public boolean isTextControl() {            return true;        }        /**         * Remove any required values for this control from the list, throwing an exception if they are missing.         **/        void claimRequiredValues( List values ) {            if (_value != null) claimValueIsRequired( values, _value );        }        public String getType() {            return UNDEFINED_TYPE;        }        /**         * Returns the current value(s) associated with this control. These values will be transmitted to the server         * if the control is 'successful'.         **/        public String[] getValues() {            if (_values == null) _values = new String[] { _value };            return _values;        }        void addValues( ParameterProcessor processor, String characterSet ) throws IOException {            processor.addParameter( _name, _value, characterSet );        }        private String   _name;        private String   _value;        private String[] _values;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -