1 38 package com.gargoylesoftware.htmlunit; 39 40 import java.io.IOException ; 41 import java.net.URL ; 42 43 55 public class WaitingRefreshHandler implements RefreshHandler { 56 private final int maxwait_; 57 65 public WaitingRefreshHandler(final int maxwait) { 66 maxwait_ = maxwait; 67 } 68 72 public WaitingRefreshHandler() { 73 maxwait_ = 0; 74 } 75 76 85 public void handleRefresh(final Page page, final URL url, final int requestedWait) throws IOException { 86 int seconds = requestedWait; 87 if (seconds > maxwait_ && maxwait_ > 0) { 88 seconds = maxwait_; 89 } 90 try { 91 Thread.sleep( seconds * 1000 ); 92 } 93 catch (final InterruptedException e) { 94 throw new RuntimeException ("Unknown threading error during refresh", e); 95 } 96 final WebWindow window = page.getEnclosingWindow(); 97 if( window == null ) { 98 return; 99 } 100 final WebClient client = window.getWebClient(); 101 client.getPage( window, new WebRequestSettings( url ) ); 102 } 103 104 } 105 | Popular Tags |