From: <sa...@us...> - 2004-02-26 10:49:11
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24419/org/jrobin/graph Modified Files: RrdGraphDef.java RrdGraphDefTemplate.java Removed Files: XmlGraphDefConvertor.java Log Message: XML templates (finished) Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdGraphDef.java 25 Feb 2004 15:28:06 -0000 1.6 --- RrdGraphDef.java 26 Feb 2004 10:33:30 -0000 1.7 *************** *** 131,139 **** } - public RrdGraphDef( String jrobinXml ) throws RrdException - { - new XmlGraphDefConvertor( jrobinXml, this ); - } - /** * Constructs a new JRobin graph object, with a specified time span to be presented on the graph. --- 131,134 ---- *************** *** 905,912 **** } ! /** ! * ! * @return ! */ public String getJRobinXml() { --- 900,904 ---- } ! /* public String getJRobinXml() { *************** *** 1011,1015 **** return xml.toString(); } ! // ================================================================ // -- Protected (package) methods --- 1003,1007 ---- return xml.toString(); } ! */ // ================================================================ // -- Protected (package) methods Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdGraphDefTemplate.java 25 Feb 2004 15:28:06 -0000 1.1 --- RrdGraphDefTemplate.java 26 Feb 2004 10:33:30 -0000 1.2 *************** *** 36,44 **** import java.util.GregorianCalendar; import java.util.Date; - import java.text.SimpleDateFormat; - import java.text.ParseException; /** ! * Class used to create an arbitrary number of RrdGraphDefs (graph definition) objects * from a single XML template. XML template can be supplied as an XML InputSource, * XML file or XML formatted string.<p> --- 36,42 ---- import java.util.GregorianCalendar; import java.util.Date; /** ! * Class used to create an arbitrary number of RrdGraphDef (graph definition) objects * from a single XML template. XML template can be supplied as an XML InputSource, * XML file or XML formatted string.<p> *************** *** 214,218 **** * <li>hard-coded timestamps in templates should be long integeres * (like: 1000243567) or ISO formatted strings (like: 2004-02-21 12:25:45) ! * <li>all leading and trailing whitespaces are removed * <li>use <code>true</code>, <code>on</code>, <code>yes</code>, <code>y</code>, * or <code>1</code> to specify boolean <code>true</code> value (anything else will --- 212,216 ---- * <li>hard-coded timestamps in templates should be long integeres * (like: 1000243567) or ISO formatted strings (like: 2004-02-21 12:25:45) ! * <li>whitespaces are not harmful * <li>use <code>true</code>, <code>on</code>, <code>yes</code>, <code>y</code>, * or <code>1</code> to specify boolean <code>true</code> value (anything else will *************** *** 221,224 **** --- 219,223 ---- * (like: U, unknown, 12r.23) * <li>use #RRGGBB format to specify colors. + * <li>valid font styles are: PLAIN, ITALIC, BOLD, BOLD ITALIC * <li>comments are allowed. * </ul> *************** *** 226,230 **** * <code></some_tag></code>) can be replaced with * a variable of the following form: <code>${variable_name}</code>. Use ! * {@link XmlTemplate#setMapping(String, String) setMapping()} methods from the base class to replace * template variables with real values at runtime.<p> * --- 225,230 ---- * <code></some_tag></code>) can be replaced with * a variable of the following form: <code>${variable_name}</code>. Use ! * {@link XmlTemplate#setVariable(String, String) setVariable()} ! * methods from the base class to replace * template variables with real values at runtime.<p> * *************** *** 234,238 **** * <li>Replace template values with variables if you want to change them during runtime. * For example, time span should not be hard-coded in the template - you probably want to create ! * many different graphs with different time spans, but starting from the same XML template. * For example, your XML template could start with: * <pre> --- 234,238 ---- * <li>Replace template values with variables if you want to change them during runtime. * For example, time span should not be hard-coded in the template - you probably want to create ! * many different graphs with different time spans from the same XML template. * For example, your XML template could start with: * <pre> *************** *** 250,255 **** * <li>Then, specify real values for template variables: * <pre> ! * t.setMapping("start", new GregorianCalendar(2004, 2, 25)); ! * t.setMapping("end", new GregorianCalendar(2004, 2, 26)); * </pre> * <li>Once all template variables are set, just use the template object to create RrdGraphDef --- 250,255 ---- * <li>Then, specify real values for template variables: * <pre> ! * t.setVariable("start", new GregorianCalendar(2004, 2, 25)); ! * t.setVariable("end", new GregorianCalendar(2004, 2, 26)); * </pre> * <li>Once all template variables are set, just use the template object to create RrdGraphDef *************** *** 267,271 **** */ public class RrdGraphDefTemplate extends XmlTemplate { - static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; // ISO format private RrdGraphDef rrdGraphDef; --- 267,270 ---- *************** *** 305,309 **** * object (actual JRobin graphs). Before this method is called, all template variables (if any) * must be resolved (replaced with real values). ! * See {@link XmlTemplate#setMapping(String, String) setMapping()} method information to * understand how to supply values for template variables. * @return Graph definition which can be used to create RrdGraph object (actual JRobin graphs) --- 304,308 ---- * object (actual JRobin graphs). Before this method is called, all template variables (if any) * must be resolved (replaced with real values). ! * See {@link XmlTemplate#setVariable(String, String) setVariable()} method information to * understand how to supply values for template variables. * @return Graph definition which can be used to create RrdGraph object (actual JRobin graphs) *************** *** 315,319 **** throw new RrdException("XML definition must start with <rrd_graph_def>"); } ! validateOnce(root, new String[] {"span", "options", "datasources", "graph"}); rrdGraphDef = new RrdGraphDef(); // traverse all nodes --- 314,318 ---- throw new RrdException("XML definition must start with <rrd_graph_def>"); } ! validateTagsOnlyOnce(root, new String[] {"span", "options", "datasources", "graph"}); rrdGraphDef = new RrdGraphDef(); // traverse all nodes *************** *** 342,347 **** private void resolveGraphElements(Node graphNode) throws RrdException { ! validateOnce(graphNode, new String[] { ! "area", "line", "stack", "gprint", "hrule", "vrule", "comment" }); Node[] childs = getChildNodes(graphNode); --- 341,346 ---- private void resolveGraphElements(Node graphNode) throws RrdException { ! validateTagsOnlyOnce(graphNode, new String[] { ! "area*", "line*", "stack*", "gprint*", "hrule*", "vrule*", "comment*" }); Node[] childs = getChildNodes(graphNode); *************** *** 355,359 **** } else if(nodeName.equals("stack")) { ! validateOnce(childs[i], new String[] { "datasource", "color", "legend" }); String datasource = getChildValue(childs[i], "datasource"); String colorStr = getChildValue(childs[i], "color"); --- 354,358 ---- } else if(nodeName.equals("stack")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "color", "legend" }); String datasource = getChildValue(childs[i], "datasource"); String colorStr = getChildValue(childs[i], "color"); *************** *** 367,371 **** } else if(nodeName.equals("gprint")) { ! validateOnce(childs[i], new String[] { "datasource", "cf", "format" }); String datasource = getChildValue(childs[i], "datasource"); String consolFun = getChildValue(childs[i], "cf"); --- 366,370 ---- } else if(nodeName.equals("gprint")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "cf", "format" }); String datasource = getChildValue(childs[i], "datasource"); String consolFun = getChildValue(childs[i], "cf"); *************** *** 374,378 **** } else if(nodeName.equals("hrule")) { ! validateOnce(childs[i], new String[] { "value", "color", "legend", "width" }); double value = getChildValueAsDouble(childs[i], "value"); String colorStr = getChildValue(childs[i], "color"); --- 373,377 ---- } else if(nodeName.equals("hrule")) { ! validateTagsOnlyOnce(childs[i], new String[] { "value", "color", "legend", "width" }); double value = getChildValueAsDouble(childs[i], "value"); String colorStr = getChildValue(childs[i], "color"); *************** *** 386,392 **** } else if(nodeName.equals("vrule")) { ! validateOnce(childs[i], new String[] { "time", "color", "legend", "width" }); String timeStr = getChildValue(childs[i], "time"); ! GregorianCalendar gc = resolveTime(timeStr); String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); --- 385,391 ---- } else if(nodeName.equals("vrule")) { ! validateTagsOnlyOnce(childs[i], new String[] { "time", "color", "legend", "width" }); String timeStr = getChildValue(childs[i], "time"); ! GregorianCalendar gc = Util.getGregorianCalendar(timeStr); String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); *************** *** 404,408 **** if(hasChildNode(lineNode, "datasource")) { // ordinary line definition ! validateOnce(lineNode, new String[] { "datasource", "color", "legend", "width" }); String datasource = getChildValue(lineNode, "datasource"); String colorStr = getChildValue(lineNode, "color"); --- 403,407 ---- if(hasChildNode(lineNode, "datasource")) { // ordinary line definition ! validateTagsOnlyOnce(lineNode, new String[] { "datasource", "color", "legend", "width" }); String datasource = getChildValue(lineNode, "datasource"); String colorStr = getChildValue(lineNode, "color"); *************** *** 418,428 **** else if(hasChildNode(lineNode, "time1")) { // two point definition ! validateOnce(lineNode, new String[] { "time1", "time2", "value1", "value2", "color", "legend", "width" }); String t1str = getChildValue(lineNode, "time1"); ! GregorianCalendar gc1 = resolveTime(t1str); String t2str = getChildValue(lineNode, "time2"); ! GregorianCalendar gc2 = resolveTime(t2str); double v1 = getChildValueAsDouble(lineNode, "value1"); double v2 = getChildValueAsDouble(lineNode, "value2"); --- 417,427 ---- else if(hasChildNode(lineNode, "time1")) { // two point definition ! validateTagsOnlyOnce(lineNode, new String[] { "time1", "time2", "value1", "value2", "color", "legend", "width" }); String t1str = getChildValue(lineNode, "time1"); ! GregorianCalendar gc1 = Util.getGregorianCalendar(t1str); String t2str = getChildValue(lineNode, "time2"); ! GregorianCalendar gc2 = Util.getGregorianCalendar(t2str); double v1 = getChildValueAsDouble(lineNode, "value1"); double v2 = getChildValueAsDouble(lineNode, "value2"); *************** *** 443,447 **** private void resolveArea(Node areaNode) throws RrdException { if(hasChildNode(areaNode, "datasource")) { ! validateOnce(areaNode, new String[] { "datasource", "color", "legend" }); // ordinary area definition String datasource = getChildValue(areaNode, "datasource"); --- 442,446 ---- private void resolveArea(Node areaNode) throws RrdException { if(hasChildNode(areaNode, "datasource")) { ! validateTagsOnlyOnce(areaNode, new String[] { "datasource", "color", "legend" }); // ordinary area definition String datasource = getChildValue(areaNode, "datasource"); *************** *** 453,463 **** else if(hasChildNode(areaNode, "time1")) { // two point definition ! validateOnce(areaNode, new String[] { "time1", "time2", "value1", "value2", "color", "legend", "width" }); String t1str = getChildValue(areaNode, "time1"); ! GregorianCalendar gc1 = resolveTime(t1str); String t2str = getChildValue(areaNode, "time2"); ! GregorianCalendar gc2 = resolveTime(t2str); double v1 = getChildValueAsDouble(areaNode, "value1"); double v2 = getChildValueAsDouble(areaNode, "value2"); --- 452,462 ---- else if(hasChildNode(areaNode, "time1")) { // two point definition ! validateTagsOnlyOnce(areaNode, new String[] { "time1", "time2", "value1", "value2", "color", "legend", "width" }); String t1str = getChildValue(areaNode, "time1"); ! GregorianCalendar gc1 = Util.getGregorianCalendar(t1str); String t2str = getChildValue(areaNode, "time2"); ! GregorianCalendar gc2 = Util.getGregorianCalendar(t2str); double v1 = getChildValueAsDouble(areaNode, "value1"); double v2 = getChildValueAsDouble(areaNode, "value2"); *************** *** 472,482 **** } ! private void resolveDatasources(Node dsNode) throws RrdException { ! validateOnce(dsNode, new String[] { "def" }); ! Node[] nodes = getChildNodes(dsNode, "def"); for(int i = 0; i < nodes.length; i++) { if(hasChildNode(nodes[i], "rrd")) { // RRD datasource ! validateOnce(nodes[i], new String[] {"name", "rrd", "source", "cf"}); String name = getChildValue(nodes[i], "name"); String rrd = getChildValue(nodes[i], "rrd"); --- 471,481 ---- } ! private void resolveDatasources(Node datasourceNode) throws RrdException { ! validateTagsOnlyOnce(datasourceNode, new String[] { "def*" }); ! Node[] nodes = getChildNodes(datasourceNode, "def"); for(int i = 0; i < nodes.length; i++) { if(hasChildNode(nodes[i], "rrd")) { // RRD datasource ! validateTagsOnlyOnce(nodes[i], new String[] {"name", "rrd", "source", "cf"}); String name = getChildValue(nodes[i], "name"); String rrd = getChildValue(nodes[i], "rrd"); *************** *** 487,491 **** else if(hasChildNode(nodes[i], "rpn")) { // RPN datasource ! validateOnce(nodes[i], new String[] {"name", "rpn"}); String name = getChildValue(nodes[i], "name"); String rpn = getChildValue(nodes[i], "rpn"); --- 486,490 ---- else if(hasChildNode(nodes[i], "rpn")) { // RPN datasource ! validateTagsOnlyOnce(nodes[i], new String[] {"name", "rpn"}); String name = getChildValue(nodes[i], "name"); String rpn = getChildValue(nodes[i], "rpn"); *************** *** 499,503 **** private void resolveOptions(Node rootOptionNode) throws RrdException { ! validateOnce(rootOptionNode, new String[] { "anti_aliasing", "arrow_color", "axis_color", "back_color", "background", "base_value", "canvas", "left_padding", "default_font", "default_font_color", --- 498,502 ---- private void resolveOptions(Node rootOptionNode) throws RrdException { ! validateTagsOnlyOnce(rootOptionNode, new String[] { "anti_aliasing", "arrow_color", "axis_color", "back_color", "background", "base_value", "canvas", "left_padding", "default_font", "default_font_color", *************** *** 575,579 **** // GRID RANGE else if(option.equals("grid_range")) { ! validateOnce(optionNode, new String[] { "lower", "upper", "rigid" }); double lower = getChildValueAsDouble(optionNode, "lower"); double upper = getChildValueAsDouble(optionNode, "upper"); --- 574,578 ---- // GRID RANGE else if(option.equals("grid_range")) { ! validateTagsOnlyOnce(optionNode, new String[] { "lower", "upper", "rigid" }); double lower = getChildValueAsDouble(optionNode, "lower"); double upper = getChildValueAsDouble(optionNode, "upper"); *************** *** 593,597 **** // BORDER else if(option.equals("border")) { ! validateOnce(optionNode, new String[] {"color", "width"}); String colorStr = getChildValue(optionNode, "color"); int width = getChildValueAsInt(optionNode, "width"); --- 592,596 ---- // BORDER else if(option.equals("border")) { ! validateTagsOnlyOnce(optionNode, new String[] {"color", "width"}); String colorStr = getChildValue(optionNode, "color"); int width = getChildValueAsInt(optionNode, "width"); *************** *** 645,649 **** // TIME AXIS else if(option.equals("time_axis")) { ! validateOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", "maj_grid_unit_steps", "date_format", "center_labels" --- 644,648 ---- // TIME AXIS else if(option.equals("time_axis")) { ! validateTagsOnlyOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", "maj_grid_unit_steps", "date_format", "center_labels" *************** *** 684,688 **** // VALUE AXIS else if(option.equals("value_axis")) { ! validateOnce(optionNode, new String[] {"grid_step", "label_step"}); double gridStep = getChildValueAsDouble(optionNode, "grid_step"); double labelStep = getChildValueAsDouble(optionNode, "label_step"); --- 683,687 ---- // VALUE AXIS else if(option.equals("value_axis")) { ! validateTagsOnlyOnce(optionNode, new String[] {"grid_step", "label_step"}); double gridStep = getChildValueAsDouble(optionNode, "grid_step"); double labelStep = getChildValueAsDouble(optionNode, "label_step"); *************** *** 725,738 **** private void resolveSpan(Node spanNode) throws RrdException { ! validateOnce(spanNode, new String[] {"start", "end"}); String startStr = getChildValue(spanNode, "start"); String endStr = getChildValue(spanNode, "end"); ! GregorianCalendar gc1 = resolveTime(startStr); ! GregorianCalendar gc2 = resolveTime(endStr); rrdGraphDef.setTimePeriod(gc1, gc2); } private Font resolveFont(Node fontNode) throws RrdException { ! validateOnce(fontNode, new String[] {"name", "style", "size"}); String name = getChildValue(fontNode, "name"); String style = getChildValue(fontNode, "style"); --- 724,737 ---- private void resolveSpan(Node spanNode) throws RrdException { ! validateTagsOnlyOnce(spanNode, new String[] {"start", "end"}); String startStr = getChildValue(spanNode, "start"); String endStr = getChildValue(spanNode, "end"); ! GregorianCalendar gc1 = Util.getGregorianCalendar(startStr); ! GregorianCalendar gc2 = Util.getGregorianCalendar(endStr); rrdGraphDef.setTimePeriod(gc1, gc2); } private Font resolveFont(Node fontNode) throws RrdException { ! validateTagsOnlyOnce(fontNode, new String[] {"name", "style", "size"}); String name = getChildValue(fontNode, "name"); String style = getChildValue(fontNode, "style"); *************** *** 754,779 **** } - private GregorianCalendar resolveTime(String timeStr) { - // try to parse it as long - try { - long timestamp = Long.parseLong(timeStr); - return Util.getGregorianCalendar(timestamp); - } catch (NumberFormatException e) { } - // not a long timestamp, try to parse it as data - SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); - df.setLenient(false); - try { - Date date = df.parse(timeStr); - return Util.getGregorianCalendar(date); - } catch (ParseException e) { - throw new IllegalArgumentException("Time/date not in " + DATE_FORMAT + - " format: " + timeStr); - } - } - public static void main(String[] args) throws IOException, RrdException { File f = new File("work/test2.xml"); RrdGraphDefTemplate t = new RrdGraphDefTemplate(f); ! t.setMapping("date", new Date()); t.getRrdGraphDef(); } --- 753,760 ---- } public static void main(String[] args) throws IOException, RrdException { File f = new File("work/test2.xml"); RrdGraphDefTemplate t = new RrdGraphDefTemplate(f); ! t.setVariable("date", new Date()); t.getRrdGraphDef(); } --- XmlGraphDefConvertor.java DELETED --- |