📄 javascript.java
字号:
public String jsGet_appVersion() { return _clientProperties.getApplicationVersion(); } public String jsGet_userAgent() { return _clientProperties.getUserAgent(); } public String jsGet_platform() { return _clientProperties.getPlatform(); } public Object[] jsGet_plugins() { return new Object[0]; } public boolean jsFunction_javaEnabled() { return false; // no support is provided for applets at present } } static public class Screen extends JavaScriptEngine { private ClientProperties _clientProperties; void setClientProperties( ClientProperties clientProperties ) { _clientProperties = clientProperties; } public String getClassName() { return "Screen"; } public int jsGet_availWidth() { return _clientProperties.getAvailableScreenWidth(); } public int jsGet_availHeight() { return _clientProperties.getAvailHeight(); } } static public class ElementArray extends ScriptableObject { private JavaScriptEngine _contents[] = new HTMLElement[0]; static ElementArray newElementArray( Scriptable parent ) { try { return (ElementArray) Context.getCurrentContext().newObject( parent, "ElementArray" ); } catch (PropertyException e) { throw new RhinoException( e ); } catch (NotAFunctionException e) { throw new RhinoException( e ); } catch (JavaScriptException e) { throw new RhinoException( e ); } } public ElementArray() { } void initialize( JavaScriptEngine[] contents ) { _contents = contents; } public int jsGet_length() { return _contents.length; } public String getClassName() { return "ElementArray"; } public Object get( int i, Scriptable scriptable ) { if (i >= 0 && i < _contents.length) { return _contents[i]; } else { return super.get( i, scriptable ); } } public Object get( String name, Scriptable scriptable ) { for (int i = 0; i < _contents.length; i++) { JavaScriptEngine content = _contents[ i ]; if (name.equalsIgnoreCase( content.getID() )) return content; } for (int i = 0; i < _contents.length; i++) { JavaScriptEngine content = _contents[ i ]; if (name.equalsIgnoreCase( content.getName() )) return content; } return super.get( name, scriptable ); } protected JavaScriptEngine[] getContents() { return _contents; } } static public class HTMLElement extends JavaScriptEngine { private Style _style; private Document _document; public String getClassName() { return "HTMLElement"; } public Document jsGet_document() { return _document; } public Style jsGet_style() { return _style; } void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); _document = (Document) parent; _style = (Style) Context.getCurrentContext().newObject( this, "Style" ); } } static public class Image extends HTMLElement { public String getClassName() { return "Image"; } } static public class Link extends HTMLElement { public Document jsGet_document() { return super.jsGet_document(); } public String getClassName() { return "Link"; } } static public class Form extends HTMLElement { private ElementArray _controls; public String getClassName() { return "Form"; } public String jsGet_action() { return getDelegate().getAction(); } public void jsSet_action( String action ) { getDelegate().setAction( action ); } public Scriptable jsGet_elements() throws PropertyException, NotAFunctionException, JavaScriptException { if (_controls == null) { initializeControls(); } return _controls; } public Object jsFunction_getElementsByTagName( String name ) throws SAXException { return toElementArray( getDelegate().getElementsByTagName( name ) ); } public void jsFunction_submit() throws IOException, SAXException { getDelegate().submit(); } public void jsFunction_reset() throws IOException, SAXException { getDelegate().reset(); } private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException { ScriptableDelegate scriptables[] = getDelegate().getElementDelegates(); Control[] controls = new Control[ scriptables.length ]; for (int i = 0; i < controls.length; i++) { controls[ i ] = (Control) toScriptable( scriptables[ i ] ); } _controls = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" ); _controls.initialize( controls ); } private WebForm.Scriptable getDelegate() { return (WebForm.Scriptable) _scriptable; } } static public class Control extends JavaScriptEngine { private Form _form; public String getClassName() { return "Control"; } public Form jsGet_form() { return _form; } public void jsFunction_focus() {} public void jsFunction_select() {} public void jsFunction_click() throws IOException, SAXException { getDelegate().click(); } private Input getDelegate() { return (Input) _scriptable; } void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); if (parent instanceof Form) _form = (Form) parent; } } static public class Options extends JavaScriptEngine { public String getClassName() { return "Options"; } public int jsGet_length() { return getDelegate().getLength(); } public void jsSet_length( int length ) { getDelegate().setLength( length ); } public void put( int i, Scriptable scriptable, Object object ) { if (object == null) { getDelegate().put( i, null ); } else { if (!(object instanceof Option)) throw new IllegalArgumentException( "May only add an Option to this array" ); Option option = (Option) object; getDelegate().put( i, option.getDelegate() ); } } private SelectionOptions getDelegate() { return (SelectionOptions) _scriptable; } } static public class Option extends JavaScriptEngine { public String getClassName() { return "Option"; } public void jsConstructor( String text, String value, boolean defaultSelected, boolean selected ) { _scriptable = WebResponse.newDelegate( "Option" ); getDelegate().initialize( text, value, defaultSelected, selected ); } public int jsGet_index() { return getDelegate().getIndex(); } public String jsGet_text() { return getDelegate().getText(); } public void jsSet_text( String text ) { getDelegate().setText( text ); } public String jsGet_value() { return getDelegate().getValue(); } public void jsSet_value( String value ) { getDelegate().setValue( value ); } public boolean jsGet_selected() { return getDelegate().isSelected(); } public void jsSet_selected( boolean selected ) { getDelegate().setSelected( selected ); } public boolean jsGet_defaultSelected() { return getDelegate().isDefaultSelected(); } SelectionOption getDelegate() { return (SelectionOption) _scriptable; } }}class RhinoException extends RuntimeException { private Exception _cause; public RhinoException( Exception cause ) { _cause = cause; } public String getMessage() { return "Rhino exception: " + _cause; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -