private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; } else { return getSubmitButton( "" ); } }
/** * Creates and returns a web request which will simulate the submission of this form with a button with the specified name and value. **/ public WebRequest getRequest( String submitButtonName, String submitButtonValue ) { SubmitButton sb = getSubmitButton( submitButtonName, submitButtonValue ); if (sb == null) throw new IllegalSubmitButtonException( submitButtonName, submitButtonValue ); return getRequest( sb ); }
/** * 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 ); }
private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; } else { return getSubmitButton( "" ); } }
/** * Creates and returns a web request which will simulate the submission of this form with a button with the specified name and value. **/ public WebRequest getRequest( String submitButtonName, String submitButtonValue ) { SubmitButton sb = getSubmitButton( submitButtonName, submitButtonValue ); if (sb == null) throw new IllegalSubmitButtonException( submitButtonName, submitButtonValue ); return getRequest( sb ); }
private SubmitButton getDefaultButton() { if (getSubmitButtons().length == 1) { return getSubmitButtons()[0]; } else { return getSubmitButton( "" ); } }
/** * 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 ); }
/** * Creates and returns a web request which will simulate the submission of this form with a button with the specified name and value. **/ public WebRequest getRequest( String submitButtonName, String submitButtonValue ) { SubmitButton sb = getSubmitButton( submitButtonName, submitButtonValue ); if (sb == null) throw new IllegalSubmitButtonException( submitButtonName, submitButtonValue ); return getRequest( sb ); }
/** * 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 ); }
protected Object scrape() throws IOException, SAXException, ProcessingException { WebForm form = getListMemberForm(mode); form.setParameter("unsubscribeList",addresses.toArray(new String[addresses.size()])); // we must change the method, from get to post, to be able to include // a large number of e-mails... The unsubscribe has the same problem // of the subscribe (see method doMassSubscribe2()). // It is very unusual to have large unsubscibes and it is more dangerous // too, so, I'll leave this for a future implementation. Right now, // let's just handle small unsubscribes. SubmitButton subscribeBt = form.getSubmitButton("Button", "Unsubscribe"); if (subscribeBt == null) throw new ProcessingException("Error: submit button not found! This is probably the wrong page..."); WebResponse r = checkError(form.submit(subscribeBt)); String text = r.getText(); int start = text.indexOf("<p>Members unsubscribed:"); int end = text.indexOf("</p>", start); if (start == -1 || end == -1) throw new ProcessingException("Error: wrong answer while subscribing."); String numberTxt = text.substring(start+24, end).trim(); return new Integer(numberTxt); } }.run();
protected Integer scrape() throws IOException, SAXException, ProcessingException { WebForm form = getListMemberForm(mode); form.setParameter("subscribeList",Util.toList(addresses,' ')); // we must change the method, from get to post, to be able to include // a large number of e-mails... Need to experiment with that. // There's no way in HTTP Unit to change the method, so, we had to // break the e-mails in groups... SubmitButton subscribeBt = form.getSubmitButton("Button", "Subscribe"); if (subscribeBt == null) throw new ProcessingException("Error: submit button not found! This is probably the wrong page..."); // check the response WebResponse r = checkError(form.submit(subscribeBt)); String text = r.getText(); int start = text.indexOf("<p>New members subscribed:"); int end = text.indexOf("</p>", start); if (start == -1 || end == -1) throw new ProcessingException("Error: wrong answer while subscribing."); String numberTxt = text.substring(start+26, end).trim(); return new Integer(numberTxt); } }.run();
protected Object scrape() throws IOException, SAXException, ProcessingException { WebResponse r = wc.getResponse("https://www.dev.java.net/servlets/TLogin"); WebForm form = r.getFormWithID("loginform"); form.setParameter("loginID",userName); form.setParameter("password",password); checkError(form.submit(form.getSubmitButton("Login"))); // check if the login was successful if( wc.getCurrentPage().getURL().toExternalForm().indexOf("TLogin")!=-1) throw new ProcessingException("authentication failed. invalid username/password"); // create a special myself object. myself = new JNMyself(JavaNet.this,userName); users.put(userName,myself); return null; } }.run();
form.getSubmitButton(FORM_BUTTON, "Add new announcement"); if(submitButton==null) throw new ProcessingException();
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();
/** * 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); } }
form.setParameter("roles", Util.getOptionValueFor(form,"roles",roleName) ); SubmitButton submitButton = form.getSubmitButton("Button"); if(submitButton==null) throw new IllegalStateException("no grant role button");
checkError(form.submit(form.getSubmitButton("Button","Submit")));