001package org.javasimon.console.action; 002 003import java.io.IOException; 004import javax.servlet.ServletException; 005 006import org.javasimon.Simon; 007import org.javasimon.console.Action; 008import org.javasimon.console.ActionContext; 009import org.javasimon.console.ActionException; 010import org.javasimon.console.SimonType; 011import org.javasimon.console.SimonTypeFactory; 012import org.javasimon.console.TimeFormatType; 013import org.javasimon.console.text.StringifierFactory; 014 015/** 016 * Export single Simon data as static HTML for printing purposes. 017 * <a href="http://.../data/detail.html?name=o.j...SimonName&timeFormat=MILLISECOND">path</a> 018 * 019 * @author gquintana 020 */ 021public class DetailHtmlAction extends Action { 022 023 /** URI for detail action. */ 024 public static final String PATH = "/data/detail.html"; 025 /** Value formatter. */ 026 protected StringifierFactory stringifierFactory; 027 /** Simon name. */ 028 private String name; 029 030 /** Constructor. */ 031 public DetailHtmlAction(ActionContext context) { 032 super(context); 033 this.stringifierFactory = new StringifierFactory(); 034 } 035 036 @Override 037 public void readParameters() { 038 name = getContext().getParameterAsString("name", null); 039 stringifierFactory.init(getContext().getParameterAsEnum("timeFormat", TimeFormatType.class, TimeFormatType.MILLISECOND), 040 StringifierFactory.READABLE_DATE_PATTERN, 041 StringifierFactory.READABLE_NUMBER_PATTERN); 042 } 043 044 @Override 045 public void execute() throws ServletException, IOException, ActionException { 046 // Check arguments 047 if (name == null) { 048 throw new ActionException("Null name"); 049 } 050 Simon simon = findSimonByName(name); 051 if (simon == null) { 052 throw new ActionException("Simon \"" + name + "\" not found"); 053 } 054 getContext().setContentType("text/html"); 055 SimonType simonType = SimonTypeFactory.getValueFromInstance(simon); 056 DetailHtmlBuilder htmlBuilder = new DetailHtmlBuilder(getContext().getWriter(), stringifierFactory); 057 // Page header 058 htmlBuilder.header("Detail View", DetailPlugin.getResources(getContext(), DetailPlugin.class)) 059 // Common Simon section 060 .beginSection("simonPanel", "Simon") 061 .beginRow() 062 .simonProperty(simon, "Name", "name", 5) 063 .endRow() 064 .beginRow() 065 .labelCell("Type") 066 .beginValueCell().simonTypeImg(simonType, "../../").object(simonType).endValueCell() 067 .simonProperty(simon, "State", "state") 068 .simonProperty(simon, "Enabled", "enabled") 069 .endRow() 070 .beginRow() 071 .simonProperty(simon, "Note", "note", 5) 072 .endRow() 073 .beginRow() 074 .simonProperty(simon, "First Use", "firstUsage") 075 .simonProperty(simon, "Last Use", "lastUsage") 076 .endRow() 077 .endSection(); 078 // Specific Stopwatch/Counter section 079 switch (simonType) { 080 case STOPWATCH: 081 htmlBuilder.beginSection("stopwatchPanel", "Stopwatch") 082 .beginRow() 083 .simonProperty(simon, "Counter", "counter") 084 .simonProperty(simon, "Total", "total", 3) 085 .endRow() 086 .beginRow() 087 .simonProperty(simon, "Min", "min", 3) 088 .simonProperty(simon, "Min Timestamp", "minTimeStamp") 089 .endRow() 090 .beginRow() 091 .simonProperty(simon, "Mean", "mean") 092 .simonProperty(simon, "Standard Deviation", "standardDeviation", 3) 093 .endRow() 094 .beginRow() 095 .simonProperty(simon, "Max", "max", 3) 096 .simonProperty(simon, "Max Timestamp", "maxTimeStamp") 097 .endRow() 098 .beginRow() 099 .simonProperty(simon, "Last", "last", 3) 100 .simonProperty(simon, "Last Timestamp", "lastUsage") 101 .endRow() 102 .beginRow() 103 .simonProperty(simon, "Active", "active") 104 .simonProperty(simon, "Max Active", "maxActive") 105 .simonProperty(simon, "Max Active Timestamp", "maxActiveTimestamp") 106 .endRow() 107 .endSection(); 108 break; 109 case COUNTER: 110 htmlBuilder.beginSection("counterPanel", "Counter") 111 .beginRow() 112 .simonProperty(simon, "Counter", "counter") 113 .endRow() 114 .beginRow() 115 .simonProperty(simon, "Min", "min") 116 .simonProperty(simon, "Min Timestamp", "minTimeStamp") 117 .endRow() 118 .beginRow() 119 .simonProperty(simon, "Max", "max") 120 .simonProperty(simon, "Max Timestamp", "maxTimeStamp") 121 .endRow() 122 .beginRow() 123 .simonProperty(simon, "Increment Sum", "incrementSum") 124 .simonProperty(simon, "Decrement Sum", "decrementSum") 125 .endRow() 126 .endSection(); 127 break; 128 } 129 // Plugins 130 for (DetailPlugin plugin : getContext().getPluginManager().getPluginsByType(DetailPlugin.class)) { 131 if (plugin.supports(simon)) { 132 htmlBuilder.beginSection(plugin.getId() + "Panel", plugin.getLabel()); 133 plugin.executeHtml(getContext(), htmlBuilder, stringifierFactory, simon); 134 htmlBuilder.endSection(); 135 } 136 } 137 // Page footer 138 htmlBuilder.footer(); 139 } 140}