📄 webform.java
字号:
} /** * Returns the option values defined for the specified parameter name. **/ public String[] getOptionValues( String name ) { return getParameter( name ).getOptionValues(); } /** * Returns true if the named parameter accepts multiple values. **/ public boolean isMultiValuedParameter( String name ) { return getParameter( name ).isMultiValuedParameter(); } /** * Returns the number of text parameters in this form with the specified name. **/ public int getNumTextParameters( String name ) { return getParameter( name ).getNumTextParameters(); } /** * Returns true if the named parameter accepts free-form text. **/ public boolean isTextParameter( String name ) { return getParameter( name ).isTextParameter(); } void setSubmitAsMime( boolean mimeEncoded ) { throw new IllegalStateException( "May not change the encoding for a validated request created from a form" ); } /** * Returns true if this form is to be submitted using mime encoding (the default is URL encoding). **/ public boolean isSubmitAsMime() { return "multipart/form-data".equalsIgnoreCase( getAttribute( "enctype" ) ); } /** * Resets all parameters to their initial values. */ public void reset() { String event = getAttribute( "onreset" ); if (event.length() == 0 || getScriptableObject().doEvent( event )) resetControls(); } private void resetControls() { FormControl[] controls = getFormControls(); for (int i = 0; i < controls.length; i++) { controls[i].reset(); } } /** * Returns an object which provides scripting access to this form. **/ public Scriptable getScriptableObject() { if (_scriptable == null) { _scriptable = new Scriptable(); _scriptable.setScriptEngine( getBaseResponse().getScriptableObject().getDocument().getScriptEngine( _scriptable ) ); } return _scriptable; }//---------------------------------- WebRequestSource methods -------------------------------- /** * Returns the character set encoding for this form. **/ public String getCharacterSet() { return _characterSet; } /** * Returns true if the named parameter accepts files for upload. **/ public boolean isFileParameter( String name ) { return getParameter( name ).isFileParameter(); } /** * Returns an array containing the names of the parameters defined for this form. **/ public String[] getParameterNames() { ArrayList parameterNames = new ArrayList( getFormParameters().keySet() ); return (String[]) parameterNames.toArray( new String[ parameterNames.size() ] ); } /** * Returns the multiple default values of the named parameter. **/ public String[] getParameterValues( String name ) { final FormParameter parameter = getParameter( name ); return parameter.getValues(); } /** * Returns true if the named parameter is read-only. If more than one control exists with the same name, * will return true only if all such controls are read-only. **/ public boolean isReadOnlyParameter( String name ) { return getParameter( name ).isReadOnlyParameter(); } /** * Returns true if the named parameter is disabled. If more than one control exists with the same name, * will return true only if all such controls are read-only. **/ public boolean isDisabledParameter( String name ) { return getParameter( name ).isDisabledParameter(); } /** * Returns true if the named parameter is hidden. If more than one control exists with the same name, * will return true only if all such controls are hidden. **/ public boolean isHiddenParameter( String name ) { return getParameter( name ).isHiddenParameter(); } /** * Creates and returns a web request which will simulate the submission of this form with an unnamed submit button. **/ public WebRequest getRequest() { return getRequest( (SubmitButton) null ); } /** * Creates and returns a web request based on the current state of this form. No parameter validation will be done * and there is no guarantee over the order of parameters transmitted. */ public WebRequest newUnvalidatedRequest() { return newUnvalidatedRequest( null ); } /** * Returns the scriptable delegate. */ public ScriptableDelegate getScriptableDelegate() { return getScriptableObject(); } /** * Records a parameter defined by including it in the destination URL. Ignores any parameters whose name matches * a form control. **/ protected void addPresetParameter( String name, String value ) { FormControl[] formControls = getFormControls(); for (int i = 0; i < formControls.length; i++) { if (formControls[i].getName().equals( name)) return; } _presets.add( new PresetFormParameter( this, name, value ) ); } protected String getEmptyParameterValue() { return null; }//---------------------------------- ParameterHolder methods -------------------------------- /** * Specifies the position at which an image button (if any) was clicked. **/ void selectImageButtonPosition( SubmitButton imageButton, int x, int y ) { imageButton.setLocation( x, y ); } /** * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter processor.\ * These parameters always go on the URL, no matter what encoding method is used. **/ void recordPredefinedParameters( ParameterProcessor processor ) throws IOException { FormControl[] controls = getPresetParameters(); for (int i = 0; i < controls.length; i++) { controls[i].addValues( processor, getCharacterSet() ); } } /** * Iterates through the parameters in this holder, recording them in the supplied parameter processor. **/ void recordParameters( ParameterProcessor processor ) throws IOException { FormControl[] controls = getFormControls(); for (int i = 0; i < controls.length; i++) { controls[i].addValues( processor, getCharacterSet() ); } } /** * Removes a parameter name from this collection. **/ public void removeParameter( String name ) { setParameter( name, NO_VALUES ); } /** * Sets the value of a parameter in this form. **/ public void setParameter( String name, String value ) { setParameter( name, new String[] { value } ); } /** * Sets the multiple values of a parameter in this form. This is generally used when there are multiple * controls with the same name in the form. */ public void setParameter( String name, final String[] values ) { FormParameter parameter = getParameter( name ); if (parameter == UNKNOWN_PARAMETER) throw new NoSuchParameterException( name ); parameter.setValues( values ); } /** * Sets the multiple values of a file upload parameter in a web request. **/ public void setParameter( String name, UploadFileSpec[] files ) { FormParameter parameter = getParameter( name ); if (parameter == null) throw new NoSuchParameterException( name ); parameter.setFiles( files ); } /** * Sets the single value of a file upload parameter in this form. * A more convenient way to do this than using {@link #setParameter(String,UploadFileSpec[])} * @since 1.6 */ public void setParameter( String name, File file ) { setParameter( name, new UploadFileSpec[] { new UploadFileSpec( file ) } ); } /** * Toggles the value of the specified checkbox parameter. * @param name the name of the checkbox parameter * @throws IllegalArgumentException if the specified parameter is not a checkbox or there is more than one * control with that name. * @since 1.5.4 */ public void toggleCheckbox( String name ) { FormParameter parameter = getParameter( name ); if (parameter == null) throw new NoSuchParameterException( name ); parameter.toggleCheckbox(); } /** * Toggles the value of the specified checkbox parameter. * @param name the name of the checkbox parameter * @param value of the checkbox parameter * @throws IllegalArgumentException if the specified parameter is not a checkbox or if there is no checkbox * with the specified name and value. * @since 1.6 */ public void toggleCheckbox( String name, String value ) { FormParameter parameter = getParameter( name ); if (parameter == null) throw new NoSuchParameterException( name ); parameter.toggleCheckbox( value ); } /** * Sets the value of the specified checkbox parameter. * @param name the name of the checkbox parameter * @param state the new state of the checkbox * @throws IllegalArgumentException if the specified parameter is not a checkbox or there is more than one * control with that name. * @since 1.5.4 */ public void setCheckbox( String name, boolean state ) { FormParameter parameter = getParameter( name ); if (parameter == null) throw new NoSuchParameterException( name ); parameter.setValue( state ); } /** * Sets the value of the specified checkbox parameter. * @param name the name of the checkbox parameter * @param value of the checkbox parameter * @param state the new state of the checkbox * @throws IllegalArgumentException if the specified parameter is not a checkbox or if there is no checkbox * with the specified name and value. * @since 1.6 */ public void setCheckbox( String name, String value, boolean state ) { FormParameter parameter = getParameter( name ); if (parameter == null) throw new NoSuchParameterException( name ); parameter.setValue( value, state ); } public class Scriptable extends HTMLElementScriptable implements NamedDelegate { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; } public void submit() throws IOException, SAXException { submitRequest( getScriptedSubmitRequest() ); } public void reset() throws IOException, SAXException { resetControls(); } public String getName() { return WebForm.this.getID().length() != 0 ? WebForm.this.getID() : WebForm.this.getName(); } public Object get( String propertyName ) { if (propertyName.equals( "target" )) { return getTarget(); } else if (propertyName.equals( "length" )) { return new Integer(getFormControls().length); } else { final FormParameter parameter = getParameter( propertyName ); if (parameter != UNKNOWN_PARAMETER) return parameter.getScriptableObject(); FormControl control = getControlWithID( propertyName ); return control == null ? super.get( propertyName ) : control.getScriptableDelegate(); } } /** * Sets the value of the named property. Will throw a runtime exception if the property does not exist or * cannot accept the specified value. **/ public void set( String propertyName, Object value ) { if (propertyName.equals( "target" )) { setTargetAttribute( value.toString() ); } else if (value instanceof String) { setParameterValue( propertyName, (String) value );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -