/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.http;

import foam.core.*;
import java.io.PrintWriter;
import foam.nanos.http.WebAgent;
import foam.nanos.http.ProxyWebAgent;
import javax.servlet.http.HttpServletRequest;

public class RefreshWebAgent
  extends ProxyWebAgent
{
  public RefreshWebAgent(WebAgent delegate) {
    setDelegate(delegate);
  }

  public void execute(X x) {
    final PrintWriter out = (PrintWriter) x.get(PrintWriter.class);
    HttpServletRequest req     = (HttpServletRequest) x.get(HttpServletRequest.class);
    String json = req.getParameter("refresh");

    out.println("<pre>");
    out.println("<form>");
    out.println("<label>Refresh Rate (sec):</label>");
    out.println("<input name=\"refresh\" type=\"number\" value=\"refresh\" style=\"width:150px;display:inline-block;\"></input>");
    out.println("<button type=submit style=\"display:inline-block;margin-top:10px;\";>Set Refresh</button>");
    out.println("</form>");
    out.println("</pre>");

    if( json != null || !"".equals(json)){
      int refresh = Integer.parseInt(json);
      out.println("<script>");
      out.println("setTimeout(function(){ window.location.href = window.location.href; }, "+ refresh * 1000 + "); ");
      out.println("</script>");
    }

    getDelegate().execute(x);
  }
}
@@ -174,27 +174,37 @@
 ort 
-java.io.PrintWriter
+foam.nanos.http.ProxyWebAgent
 ;%0Aim
@@ -245,37 +245,27 @@
 ort 
-foam.nanos.http.ProxyWebAgent
+java.io.PrintWriter
 ;%0Aim
@@ -1077,16 +1077,51 @@
 /pre%3E%22);
+%0A    %0A    getDelegate().execute(x);
 %0A%0A    if
@@ -1154,16 +1154,17 @@
 ls(json)
+ 
 )%7B%0A     
@@ -1392,39 +1392,8 @@
    %7D
-%0A%0A    getDelegate().execute(x);
 %0A  %7D

refresh web agent pr fixes