/** * Removes a parameter name from this collection. **/ public void removeParameter( String name ) { setParameter( name, NO_VALUES ); }
/** * Submits this form using the web client from which it was originally obtained. * Will usually return the result of that submission; however, if the submit button's 'onclick' * or the form's 'onsubmit' event is triggered and * inhibits the submission, will return the updated contents of the frame containing this form. **/ public WebResponse submit( SubmitButton button ) throws IOException, SAXException { WebResponse result=submit(button,0,0); return result; }
public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); _presetParameters = null; }
private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; } else { return getSubmitButton( "" ); } }
public void update(WebForm form) { final String field = "status_whiteboard"; String value = form.getParameterValue(field); form.setParameter(field, (value == null ? words : value + " " + words)); } });
/** * Submits this form using the web client from which it was originally obtained. **/ public WebResponse submit() throws IOException, SAXException { return submit( getDefaultButton() ); }
form.getSubmitButton(FORM_BUTTON, "Add new announcement"); if(submitButton==null) throw new ProcessingException(); form.setParameter(FORM_HEADLINE, headline); form.setParameter( FORM_YEAR, String.valueOf(date.get(Calendar.YEAR))); form.setParameter( FORM_MONTH, pad(String.valueOf(date.get(Calendar.MONTH) + 1),2)); form.setParameter( FORM_DAY, pad(String.valueOf(date.get(Calendar.DAY_OF_MONTH)),2)); form.setParameter(FORM_BODY, body); form.setParameter(FORM_IMAGEURL, imageUrl); form.setParameter(FORM_ARTICLEURL, articleUrl); checkError(form.submit(submitButton));
protected Void scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/ProjectMailingListList"); for (WebForm form : response.getForms()) { if(!form.getAction().equals("ProjectMailingListList")) continue; if(!form.getParameterValue("listName").equals(name)) continue; // found the form SubmitButton sb = form.getSubmitButtons()[0]; if(!sb.getValue().equals("Subscribe")) throw new ProcessingException("Found "+sb.getValue()+" but expected Subscribe"); // set the mode form.setParameter("subtype",mode.getNameAsWord()); checkError(form.submit(sb)); return null; } throw new ProcessingException("no subscription form found"); } }.run();
/** * Creates and returns a web request which will simulate the submission of this form with a button with the specified name. **/ public WebRequest getRequest( String submitButtonName ) { SubmitButton sb = getSubmitButton( submitButtonName ); if (sb == null) throw new IllegalSubmitButtonException( submitButtonName, "" ); return getRequest( sb ); }
/** * Submits the form without also invoking the button's "onclick" event. */ WebResponse doFormSubmit( SubmitButton button ) throws IOException, SAXException { return submitRequest( getAttribute( "onsubmit" ), getRequest( button ) ); }
protected JNFileFolder scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/ProjectFolderAdd?folderID="+id); WebForm form = Util.getFormWithAction(response, "ProjectFolderAdd"); form.setParameter("name",name); form.setParameter("description",description); response = checkError(form.submit()); // make sure there's no error if(response.getText().indexOf("Validation error")!=-1) throw new ProcessingException("failed to create a folder"); subFolders = null; return getSubFolder(name); } }.run();
/** * Creates and returns a web request which includes the specified button and position. If no button is specified, * will include the default button, if any. No parameter validation will be done on the returned request * and no scripts will be run when it is submitted. **/ public WebRequest newUnvalidatedRequest( SubmitButton button, int x, int y ) { if (button == null) button = getDefaultButton(); SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } button.setPressed( true ); if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } else { return new GetMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } }
WebForm[] forms = r.getForms(); for (WebForm form : forms) { String action = form.getAction(); if ((action != null) && (action.contains("ProjectDocumentEdit?action=Edit%20file"))) { form.setParameter("name",fileName); actor.act(form); r = checkError(form.submit()); form.setParameter("name",fileName); if( fileStatus!=null ) form.setParameter("status",fileStatus.toString()); form.setParameter("description",description); form.setParameter("text",""); r = checkError(form.submit());
protected String scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(_getURL()+"/servlets/ProjectEdit"); WebForm form = Util.getFormWithAction(response,"ProjectEdit"); String old = form.getParameterValue("status"); form.setParameter("status",msg); checkError(form.submit()); return old; } }.run();
private WebRequest getScriptedSubmitRequest() { SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this ); } else { return new GetMethodWebRequest( this ); } }
/** * Returns the submit button defined in this form with the specified name. * If more than one such button exists, will return the first found. * If no such button is found, will return null. **/ public SubmitButton getSubmitButton( String name ) { SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { if (buttons[i].getName().equals( name )) { return buttons[i]; } } return null; }
/** * Revokes the specified role from the user. */ public void revokeRole( JNUser user, String roleName ) throws ProcessingException { try { WebResponse r = goTo(project._getURL()+"/servlets/ProjectMemberList"); WebForm form = Util.getFormWithAction(r,"ProjectMemberList"); if(form==null) throw new IllegalStateException("form not found in "+r.getURL()); // starts-with is necesasry because someone fails to handle correctly String propName = (String)Util.getDom4j(r).selectObject( "string(//FORM[@action='ProjectMemberList']//TR[normalize-space(TD[1])='"+user.getName()+"']/TD[3]/text()[normalize-space(.)='"+roleName+"']/preceding-sibling::INPUT[1]/@name)"); if(propName==null || propName.length()==0) throw new ProcessingException("Unable to find the user "+user.getName()+" or the role "+roleName); form.toggleCheckbox(propName); SubmitButton submitButton = form.getSubmitButton("Button"); if(submitButton==null) throw new IllegalStateException("no submit button"); r = checkError(form.submit(submitButton)); if( r.getURL().toExternalForm().endsWith("ProjectMemberList") ) return; // successful throw new ProcessingException("failed to revoke role from "+user.getName()); } catch( IOException e ) { throw new ProcessingException("failed to revoke role from "+user.getName(),e); } catch( SAXException e ) { throw new ProcessingException("failed to revoke role from "+user.getName(),e); } }
/** * Creates and returns a web request which will simulate the submission of this form by pressing the specified button. * If the button is null, simulates the pressing of the default button. **/ public WebRequest getRequest( SubmitButton button ) { return getRequest( button, 0, 0 ); }
protected Object scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/ProjectNewsDelete?newsItemID="+id); WebForm form = Util.getFormWithAction(response,"ProjectNewsDelete"); if(form==null) throw new ProcessingException("missing form"); SubmitButton submit = form.getSubmitButton("Button","Confirm delete"); if(submit==null) throw new ProcessingException("no submit button"); checkError(form.submit(submit)); return null; } }.run();
/** * Submits the form without also invoking the button's "onclick" event. */ WebResponse doFormSubmit( SubmitButton button ) throws IOException, SAXException { return submitRequest( getAttribute( "onsubmit" ), getRequest( button ) ); }