Examples of HtmlGenerator


Examples of org.w3c.jigsaw.html.HtmlGenerator

    CvsDirectory cvs = null ;

    protected Reply badAction(Request request, String action) {
  Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
  HtmlGenerator g = CvsFrame.getHtmlGenerator ("Bad CVS command") ;
  g.append ("<center>");
  g.append ("[ <A HREF=\"./CVS\">Back</A> ]<hr noshade width=\"80%\">");
  g.append ("<p>Your command "
      + "<strong>"+ action + "</strong>"
      + " wasn't undesrtood.<p>");
  g.append ("<hr noshade width=\"80%\"></center>");
  error.setStream (g) ;
  return error;
    }
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

  Reply reply = request.makeReply(HTTP.SEE_OTHER);
  URL loc = null;
  String target = (String) getValue(ATTR_TARGET_URL, null) ;
  if (target == null) {
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      HtmlGenerator g = new HtmlGenerator("Error");
      g.append("The target RelocateResource doesn't define the"
         + " relocation location. The server is "
         + " misconfigured.") ;
      error.setStream(g);
      return error ;
  }
  try {
      loc = new URL(getURL(request), target);
  } catch (MalformedURLException ex) {
      // still not well configured :)
      Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
      HtmlGenerator g = new HtmlGenerator("Error");
      g.append("The target RelocateResource doesn't define the"
         + " relocation location. The server is "
         + " misconfigured.") ;
      error.setStream(g);
      return error ;
  }
  reply.setLocation(loc);
  HtmlGenerator g = new HtmlGenerator("Moved");
  g.append("<P>You should see the following resource, with a GET"+
     ", click on the link if your"
     + " browser doesn't support automatic redirection<BR>"+
     "<A HREF=\""+loc.toExternalForm()+"\">"+
     loc.toExternalForm()+"</A>");
  reply.setStream(g);
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

      }
      if (lmbest != 0) {
    // always temporary and no good support for 307 :(
    Reply reply = request.makeReply(HTTP.FOUND);
    reply.setLocation(best+"/");
    HtmlGenerator g = new HtmlGenerator("Moved");
    g.append("<P>The freshest child is available from "+
       "<A HREF=\""+best+"/\">"+best
       +"</A>");
    reply.setStream(g);
    return reply ;
      }
  }
  Reply reply = request.makeReply(HTTP.FOUND);
  reply.setLocation("./");
  HtmlGenerator g = new HtmlGenerator("Moved");
  g.append("<P>No child available, see parent: "+
     "<A HREF=\"./\">parent</A>");
  reply.setStream(g);
  return reply ;
    }
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

     * Dump the current memory status.
     * @param request The request we are to reply to.
     */

    protected Reply dumpMemoryStatus (Request request) {
  HtmlGenerator g = new HtmlGenerator ("Memory Status") ;
  int refresh = getInt(ATTR_REFRESH, REFRESH_DEFAULT);
  if (refresh > 0) {
      g.addMeta("Refresh", Integer.toString(refresh));
  }
  addStyleSheet(g);
  g.append("<h1>Memory status</h1>") ;
  long bytes = runtime.freeMemory();
  long kbytes = bytes / 1024;
  long mbytes = kbytes / 1024;
  if (mbytes != 0) {
      g.append("<p>Free Memory: " +mbytes+ "Mb, " +kbytes % 1024+ "Kb, "
         + bytes % 1024 + " (" + Long.toString(bytes) +")");
  } else if (kbytes != 0) {
      g.append("<p>Free Memory: " + kbytes + "Kb, " + bytes % 1024 +
         " (" + Long.toString(bytes) +")");
  } else {
      g.append("<p>Free Memory:" + Long.toString(bytes));
  }
  bytes = runtime.totalMemory();
  kbytes = bytes / 1024;
  mbytes = kbytes / 1024;
  if (mbytes != 0) {
      g.append("<p>Total Memory: "+mbytes+"Mb, " +kbytes % 1024+ "Kb, "
         + bytes % 1024 + " (" + Long.toString(bytes) +")");
  } else if (kbytes != 0) {
      g.append("<p>Total Memory: " + kbytes + "Kb, " + bytes % 1024
         + " (" + Long.toString(bytes) +")");
  } else {
      g.append("<p>Total Memory:", Long.toString(bytes));
  }
  g.append("<p>GC count: "+GcCounter.getGcCount()) ;
  g.append("<hr>") ;
  // Reply back:
  Reply  reply = request.makeReply(HTTP.OK) ;
  reply.setNoCache();
  reply.setStream (g) ;
  reply.setDynamic(true);
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

     * @param request The request we are to reply to.
     */
    public Reply listThreads (Request request) {
  // enumerate all thread, and return a full thread listing:
  int    tcount   = Thread.activeCount() ;
  HtmlGenerator g = new HtmlGenerator ("Thread status") ;
  g.meta ("Refresh", getValue(ATTR_REFRESH, REFRESH_DEFAULT).toString());
  addStyleSheet(g);
  // Dump thread informations:
  Thread tarray[] = new Thread[tcount] ;
  Thread.enumerate (tarray) ;
  g.append ("<h1>Thread dump</h1>") ;
  g.append ("<ul>") ;
  String rname = getResource().getIdentifier();
  for (int i = 0 ; i < tcount ; i++) {
      String name = tarray[i].getName() ;
      g.append ("<li>"
          + "<a href=\""+rname+"?" + name + "\">" + name + "</a>"
          + (tarray[i].isDaemon() ? "D " : "  ")
          + (tarray[i].isAlive()  ? "R " : "  ")
          + " Prio: " +(tarray[i].getPriority())) ;
  }
  g.append ("</ul>") ;
  // Dark features:
  g.append ("<p>To kill a thread, add a <b>?</b><em>thread-name</em> "
      + "to the current URL.</p>") ;
  // Add global java process informations:
  g.append ("<h2>Misc informations</h2>") ;
  g.append ("<p>Total free memory: " + runtime.freeMemory());
  g.append ("<p>Toal memory      : " + runtime.totalMemory()) ;
  g.close() ;
  // Reply back:
  Reply  reply = request.makeReply(HTTP.OK) ;
  reply.setStream (g) ;
  return reply ;
    }
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

     * Display the collected statistics in an HTML table.
     * @param request TYhe request to process.
     */

    public Reply get (Request request) {
  HtmlGenerator g = new HtmlGenerator("Statistics") ;
  int refresh = getInt(ATTR_REFRESH, REFRESH_DEFAULT);
  if (refresh > 0) {
      g.addMeta("Refresh", Integer.toString(refresh));
  }
  addStyleSheet(g);
  // Dump the statistics:
  httpdStatistics stats = ((httpd)getServer()).getStatistics() ;
  // Uptime:
  g.append("<h1>Server statistics</h1>");
  long start_time = stats.getStartTime();
  long uptime     = (System.currentTimeMillis() - start_time) / 1000;
  g.append("<p>Your server was started on <span class=\"date\">");
  g.append(new Date(start_time).toString());
  long duptime = uptime / (3600L*24L);
  long htemp   = uptime % (3600L*24L);
  long huptime = htemp / 3600L;
  long mtemp   = htemp % 3600L;
  long muptime = mtemp / 60L;
  long suptime = mtemp % 60L;
  g.append("</span>\n<p>It has now been running for <span "+
     "class=\"uptime\">");
  g.append(Long.toString(duptime));
  g.append(" days, ");
  g.append(Long.toString(huptime));
  g.append(" hours, ");
  g.append(Long.toString(muptime));
  g.append(" minutes and ");
  g.append(Long.toString(suptime));
  g.append(" seconds.</span>\n");
  // Hits and bytes:
  long  nb_hits      = stats.getHitCount();
  long  dyn_hits     = stats.getDynamicHitCount();
  long  static_hits  = stats.getStaticHitCount();
  float static_pcent = 0;
  float dyn_pcent    = 0;
  if (nb_hits > 0) {
      static_pcent = ((float) static_hits / (float) nb_hits) * 100;
      dyn_pcent = ((float) dyn_hits / (float) nb_hits) * 100;
  }
  g.append("<ul><li>hits: ", Long.toString(nb_hits));
  g.append("  <ul>\n    <li>static: ",Long.toString(static_hits));
  g.append(" (", Float.toString(static_pcent));
  g.append("%)</li>\n    <li>dynamic: ", Long.toString(dyn_hits));
  g.append(" (", Float.toString(dyn_pcent));
  g.append("%)</li>\n  </ul>\n");
  long bytes = stats.getEmittedBytes();
  long kbytes = bytes / 1024;
  long mbytes = kbytes / 1024;
  long gbytes = mbytes / 1024;
        long tbytes = gbytes / 1024;
  if (tbytes != 0) {
      g.append("</li>\n<li>bytes: ", Long.toString( tbytes),"TB, ");
      g.append(Long.toString(gbytes % 1024), "GB, ");
      g.append(Long.toString(mbytes % 1024), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(bytes % 1024));
  } else if (gbytes != 0) {
      g.append("</li>\n<li>bytes: ", Long.toString(gbytes), "GB, ");
      g.append(Long.toString(mbytes % 1024), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(bytes % 1024));
  } else if (mbytes != 0) {
      g.append("</li>\n<li>bytes: ", Long.toString(mbytes), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(bytes % 1024));
  } else if (kbytes != 0) {
      g.append("</li>\n<li>bytes: ", Long.toString(kbytes), "KB, ");
      g.append(Long.toString(bytes % 1024));
  } else {
      g.append("</li>\n<li>bytes: ", Long.toString(bytes));
  }
  // avg hit/sec
  float avghits = 0;
  float avghitsday = 0;
  if (uptime > 0) {
      avghits = ((float) nb_hits) / ((float) uptime);
      avghitsday = ((float) nb_hits * 86400) / ((float) uptime);
  }
  g.append("</li>\n<li>Average hits per second: ");
  g.append(Float.toString(avghits));
  g.append("</li>\n<li>Average hits per day: ");
  g.append(Integer.toString((int) avghitsday));
  // avg bytes/hit
  long avgbph;

  if (nb_hits > 0) {
      avgbph = bytes / nb_hits;
  } else {
      avgbph = 0;
  }
  kbytes = avgbph / 1024;
  mbytes = kbytes / 1024;
  gbytes = mbytes / 1024;
  if (gbytes != 0) {
      g.append("</li>\n<li>Average bytes per hit: ");
      g.append(Long.toString(gbytes), "GB, ");
      g.append(Long.toString(mbytes % 1024), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(avgbph % 1024));
  } else if (mbytes != 0) {
      g.append("</li>\n<li>Average bytes per hit: ");
      g.append(Long.toString(mbytes), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(avgbph % 1024));     
  } else if (kbytes != 0) {
      g.append("</li>\n<li>Average bytes per hit: ");
      g.append(Long.toString(kbytes), "KB, ");
      g.append(Long.toString(avgbph % 1024));
  } else {
      g.append("</li>\n<li>Average bytes per hit: ",
         Long.toString(avgbph));
  }
  // avg throughput
  long avgbps = 0;
  if (uptime > 0) {
      avgbps = bytes / uptime;
  }
  kbytes = avgbps / 1024;
  mbytes = kbytes / 1024;
  gbytes = mbytes / 1024;
  if (gbytes != 0) {
      g.append("</li>\n<li>Average bytes per second: ");
      g.append(Long.toString(gbytes)"GB, ");
      g.append(Long.toString(mbytes % 1024), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(avgbps % 1024));
  } else if (mbytes != 0) {
      g.append("</li>\n<li>Average bytes per second: ");
      g.append(Long.toString(mbytes), "MB, ");
      g.append(Long.toString(kbytes % 1024), "KB, ");
      g.append(Long.toString(avgbps % 1024));
  } else if (kbytes != 0) {
      g.append("</li>\n<li>Average bytes per second: ");
      g.append(Long.toString(kbytes), "KB, ");
      g.append(Long.toString(avgbps % 1024));
  } else {
      g.append("</li>\n<li>Average bytes per second: ",
         Long.toString(avgbps));
  }   
  g.append("</li>\n</ul>");
  // Request times:
  g.append(time_tbl) ;
  g.append("<td>"
     , Long.toString(stats.getMinRequestTime())
     , " <span class=\"unit\">ms</span>") ;
  g.append("</td>\n<td>"
     , Long.toString(stats.getMeanRequestTime())
     , " <span class=\"unit\">ms</span>") ;
  g.append("</td>\n<td>"
     , Long.toString(stats.getMaxRequestTime())
     , " <span class=\"unit\">ms</span>") ;
  g.append("</td>\n</table>\n") ;

  // static
  if (static_hits>0) {
      g.append(sta_time_tbl) ;
      g.append("<td>"
         , Long.toString(stats.getMinStaticRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n<td>"
         , Long.toString(stats.getMeanStaticRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n<td>"
         , Long.toString(stats.getMaxStaticRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n</table>\n") ;
  }

  // dynamic
  if (dyn_hits>0) {
      g.append(dyn_time_tbl) ;
      g.append("<td>"
         , Long.toString(stats.getMinDynamicRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n<td>"
         , Long.toString(stats.getMeanDynamicRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n<td>"
         , Long.toString(stats.getMaxDynamicRequestTime())
         , " <span class=\"unit\">ms</span>") ;
      g.append("</td>\n</table>\n") ;
  }

  // Get Server internal Stats
  try {
      g.append(((httpd)getServer()).getHTMLStatus());
  } catch (Exception ex) {
      ex.printStackTrace();
  }
  Reply reply = request.makeReply(HTTP.OK) ;
  reply.setNoCache();
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

    public Reply handle (Request request, URLDecoder data)
  throws ProtocolException
    {
  // Now we just dump back the variables we got:
  HtmlGenerator g = new HtmlGenerator ("Form decoded values") ;
  if (data != null) {
      Enumeration   e = data.keys() ;
      g.append ("<p>List of variables and values:</p><ul>") ;
      while ( e.hasMoreElements () ) {
    String name = (String) e.nextElement() ;
    g.append ("<li><em>"+
        name+"</em> = <b>"+
        data.getValue(name)+
        "</b></li>");
      }
      g.append ("</ul>") ;
  } else {
      g.append ("<p>Not with the application/x-www-form-urlencoded"
          +" mime type");
  }
  Reply reply = request.makeReply(HTTP.OK) ;
  reply.setStream (g) ;
  return reply ;
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

      e.setProxyAuthenticate(challenge);
  } else {
      e = request.makeReply(HTTP.UNAUTHORIZED);
      e.setWWWAuthenticate (challenge);
  }
  HtmlGenerator g = new HtmlGenerator("Unauthorized");
  g.append ("<h1>Unauthorized access</h1>"
      + "<p>You are denied access to this resource.");
  e.setStream(g);
  throw new HTTPException (e);
    }
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

    // Stop the thread
    chkpr.stop();
      }
  }
  // Emit output:
  HtmlGenerator g = new HtmlGenerator("CheckpointResource");
  addStyleSheet(g);
  g.append("<h1>CheckpointResource status</h1>");
  g.append("<p>Checkpoint is currently "
     , ((chkpr.thread == null) ? " stopped " : "running")
     , ".");
  g.append("<hr>You can:<p><dl>");
  g.append("<dt><a href=\""
     , chkpr.getURLPath()
     , "?start\">start</a><dd>Start the checkpointer.");
  g.append("<dt><a href=\""
     , chkpr.getURLPath()
     , "?stop\">stop</a><dd>Stop the checkpointer.");
  g.append("</dl><hr>Last checkpoint at <strong>"
     , ((chkpr.checkpoint == null)
        ? "no checkpoint run yet"
        : chkpr.checkpoint.toString())
     , "</strong>.");
  Reply reply = createDefaultReply(request, HTTP.OK);
View Full Code Here

Examples of org.w3c.jigsaw.html.HtmlGenerator

  }
   
  int len = -1;
  if ((len = notsupported.size()) > 0) {
      Reply error   = request.makeReply(HTTP.NOT_EXTENDED) ;
      HtmlGenerator content = new HtmlGenerator("Error");
      content.append("<h1>Mandatory extension(s) not supported:",
         "</h1><p>\n");
      content.append("<ul>\n");
      for (int i = 0; i < len; i++)
    content.append("<li> "+(String)notsupported.elementAt(i)+"\n");
      content.append("</ul>\n");
      error.setStream(content);
      throw new HTTPException(error);
  }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.