⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrdgraphdeftemplate.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* ============================================================
 * JRobin : Pure java implementation of RRDTool's functionality
 * ============================================================
 *
 * Project Info:  http://www.jrobin.org
 * Project Lead:  Sasa Markovic (saxon@jrobin.org);
 *
 * (C) Copyright 2003, by Sasa Markovic.
 *
 * Developers:    Sasa Markovic (saxon@jrobin.org)
 *                Arne Vandamme (cobralord@jrobin.org)
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
package net.jumperz.ext.org.jrobin.graph;

import net.jumperz.ext.org.jrobin.core.RrdException;
import net.jumperz.ext.org.jrobin.core.Util;
import net.jumperz.ext.org.jrobin.core.XmlTemplate;

import org.xml.sax.InputSource;
import org.w3c.dom.Node;

import java.io.IOException;
import java.io.File;
import java.awt.*;
import java.util.GregorianCalendar;

/**
 * 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>
 *
 * Here is an example of a properly formatted XML template with all available options in it
 * (unwanted options can be removed):<p>
 * <pre>
 * &lt;rrd_graph_def&gt;
 *     &lt;span&gt;
 *         &lt;!-- ISO FORMAT: yyyy-MM-dd HH:mm:ss --&gt;
 *         &lt;start&gt;2004-02-27 13:35:00&lt;/start&gt;
 *         &lt;!-- timestamp in seconds is also allowed --&gt;
 *         &lt;end&gt;1234567890&lt;/end&gt;
 *     &lt;/span&gt;
 *     &lt;options&gt;
 *         &lt;anti_aliasing&gt;true&lt;/anti_aliasing&gt;
 *         &lt;arrow_color&gt;#FF0000&lt;/arrow_color&gt;
 *         &lt;axis_color&gt;#00FF00&lt;/axis_color&gt;
 *         &lt;back_color&gt;#00FF00&lt;/back_color&gt;
 *         &lt;background&gt;#FFFFFF&lt;/background&gt;
 *         &lt;base_value&gt;1024&lt;/base_value&gt;
 *         &lt;canvas&gt;#112211&lt;/canvas&gt;
 *         &lt;left_padding&gt;55&lt;/left_padding&gt;
 *         &lt;default_font&gt;
 *             &lt;name&gt;Times&lt;/name&gt;
 *             &lt;style&gt;BOLD ITALIC&lt;/style&gt;
 *             &lt;size&gt;15&lt;/size&gt;
 *         &lt;/default_font&gt;
 *         &lt;default_font_color&gt;#000000&lt;/default_font_color&gt;
 *         &lt;frame_color&gt;#0000FF&lt;/frame_color&gt;
 *         &lt;front_grid&gt;true&lt;/front_grid&gt;
 *         &lt;grid_range&gt;
 *             &lt;lower&gt;100&lt;/lower&gt;
 *             &lt;upper&gt;200&lt;/upper&gt;
 *             &lt;rigid&gt;false&lt;/rigid&gt;
 *         &lt;/grid_range&gt;
 *         &lt;grid_x&gt;true&lt;/grid_x&gt;
 *         &lt;grid_y&gt;false&lt;/grid_y&gt;
 *         &lt;border&gt;
 *             &lt;color&gt;#00FFFF&lt;/color&gt;
 *             &lt;width&gt;2&lt;/width&gt;
 *         &lt;/border&gt;
 *         &lt;major_grid_color&gt;#00FF00&lt;/major_grid_color&gt;
 *         &lt;major_grid_x&gt;true&lt;/major_grid_x&gt;
 *         &lt;major_grid_y&gt;false&lt;/major_grid_y&gt;
 *         &lt;minor_grid_color&gt;#00FFFF&lt;/minor_grid_color&gt;
 *         &lt;minor_grid_x&gt;true&lt;/minor_grid_x&gt;
 *         &lt;minor_grid_y&gt;false&lt;/minor_grid_y&gt;
 *         &lt;overlay&gt;overlay_image.png&lt;/overlay&gt;
 *         &lt;show_legend&gt;true&lt;/show_legend&gt;
 *         &lt;show_signature&gt;false&lt;/show_signature&gt;
 *         &lt;time_axis&gt;
 *             &lt;!-- ALLOWED TIME UNITS: SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR --&gt;
 *             &lt;min_grid_time_unit&gt;HOUR&lt;/min_grid_time_unit&gt;
 *             &lt;min_grid_unit_steps&gt;4&lt;/min_grid_unit_steps&gt;
 *             &lt;maj_grid_time_unit&gt;DAY&lt;/maj_grid_time_unit&gt;
 *             &lt;maj_grid_unit_steps&gt;2&lt;/maj_grid_unit_steps&gt;
 *             &lt;date_format&gt;HH:mm&lt;/date_format&gt;
 *             &lt;center_labels&gt;true&lt;/center_labels&gt;
 *             &lt;!-- ALLOWED DAYS OF WEEK: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY --&gt;
 *             &lt;first_day_of_week&gt;MONDAY&lt;/first_day_of_week&gt;
 *         &lt;/time_axis&gt;
 *         &lt;time_axis_label&gt;time&lt;/time_axis_label&gt;
 *         &lt;title&gt;Graph title&lt;/title&gt;
 *         &lt;title_font&gt;
 *             &lt;name&gt;Verdana&lt;/name&gt;
 *             &lt;style&gt;BOLD&lt;/style&gt;
 *             &lt;size&gt;17&lt;/size&gt;
 *         &lt;/title_font&gt;
 *         &lt;title_font_color&gt;#FF0000&lt;/title_font_color&gt;
 *         &lt;units_exponent&gt;6&lt;/units_exponent&gt;
 *         &lt;value_axis&gt;
 *             &lt;grid_step&gt;100&lt;/grid_step&gt;
 *             &lt;label_step&gt;200&lt;/label_step&gt;
 *         &lt;/value_axis&gt;
 *         &lt;vertical_label&gt;voltage [V]&lt;/vertical_label&gt;
 *     &lt;/options&gt;
 *     &lt;datasources&gt;
 *         &lt;def&gt;
 *             &lt;name&gt;input&lt;/name&gt;
 *             &lt;rrd&gt;test1.rrd&lt;/rrd&gt;
 *             &lt;source&gt;inOctets&lt;/source&gt;
 *             &lt;cf&gt;AVERAGE&lt;/cf&gt;
 *         &lt;/def&gt;
 *         &lt;def&gt;
 *             &lt;name&gt;output&lt;/name&gt;
 *             &lt;rrd&gt;test2.rrd&lt;/rrd&gt;
 *             &lt;source&gt;outOctets&lt;/source&gt;
 *             &lt;cf&gt;MAX&lt;/cf&gt;
 *             &lt;backend&gt;FILE&lt;/backend&gt;
 *         &lt;/def&gt;
 *         &lt;def&gt;
 *             &lt;name&gt;input8&lt;/name&gt;
 *             &lt;rpn&gt;input,8,*&lt;/rpn&gt;
 *         &lt;/def&gt;
 *         &lt;def&gt;
 *             &lt;name&gt;output8&lt;/name&gt;
 *             &lt;rpn&gt;output,8,*,-1,*&lt;/rpn&gt;
 *         &lt;/def&gt;
 *         &lt;def&gt;
 *             &lt;name&gt;avgOutput8&lt;/name&gt;
 *             &lt;datasource&gt;output8&lt;/datasource&gt;
 *             &lt;cf&gt;AVERAGE&lt;/cf&gt;
 *         &lt;/def&gt;
 *         &lt;export_data&gt;
 *             &lt;file&gt;exportdata1.xml&lt;/file&gt;
 *             &lt;ds_name_prefix&gt;traffic&lt;/ds_name_prefix&gt;
 *         &lt;/export_data&gt;
 *         &lt;export_data&gt;
 *             &lt;file&gt;exportdata2.xml&lt;/file&gt;
 *             &lt;use_legend_names&gt;true&lt;/use_legend_names&gt;
 *         &lt;/export_data&gt;
 *         &lt;export_data&gt;
 *             &lt;file&gt;exportdata3.xml&lt;/file&gt;
 *         &lt;/export_data&gt;
 *     &lt;/datasources&gt;
 *     &lt;graph&gt;
 *         &lt;area&gt;
 *             &lt;datasource&gt;input&lt;/datasource&gt;
 *             &lt;color&gt;#FF0000&lt;/color&gt;
 *             &lt;legend&gt;Input traffic&lt;/legend&gt;
 *         &lt;/area&gt;
 *         &lt;area&gt;
 *             &lt;datasource&gt;output&lt;/datasource&gt;
 *             &lt;color&gt;#00FF00&lt;/color&gt;
 *             &lt;legend&gt;Output traffic&lt;/legend&gt;
 *         &lt;/area&gt;
 *         &lt;stack&gt;
 *             &lt;datasource&gt;input8&lt;/datasource&gt;
 *             &lt;color&gt;#AA00AA&lt;/color&gt;
 *             &lt;legend&gt;Stacked input@r&lt;/legend&gt;
 *         &lt;/stack&gt;
 *         &lt;line&gt;
 *             &lt;datasource&gt;input&lt;/datasource&gt;
 *             &lt;color&gt;#AB7777&lt;/color&gt;
 *             &lt;legend&gt;Input traffic@l&lt;/legend&gt;
 *         &lt;/line&gt;
 *         &lt;line&gt;
 *             &lt;datasource&gt;output&lt;/datasource&gt;
 *             &lt;color&gt;#AA00AA&lt;/color&gt;
 *             &lt;legend&gt;Output traffic@r&lt;/legend&gt;
 *             &lt;width&gt;2&lt;/width&gt;
 *         &lt;/line&gt;
 *         &lt;area&gt;
 *             &lt;time1&gt;2004-02-25 12:00:01&lt;/time1&gt;
 *             &lt;time2&gt;1000222333&lt;/time2&gt;
 *             &lt;value1&gt;1001.23&lt;/value1&gt;
 *             &lt;value2&gt;2765.45&lt;/value2&gt;
 *             &lt;color&gt;#AABBCC&lt;/color&gt;
 *             &lt;legend&gt;simeple two point area&lt;/legend&gt;
 *         &lt;/area&gt;
 *         &lt;line&gt;
 *             &lt;time1&gt;1000111444&lt;/time1&gt;
 *             &lt;time2&gt;2004-02-25 12:00:01&lt;/time2&gt;
 *             &lt;value1&gt;1009.23&lt;/value1&gt;
 *             &lt;value2&gt;9002.45&lt;/value2&gt;
 *             &lt;color&gt;#AABB33&lt;/color&gt;
 *             &lt;legend&gt;simple two point line&lt;/legend&gt;
 *             &lt;width&gt;5&lt;/width&gt;
 *         &lt;/line&gt;
 *         &lt;gprint&gt;
 *             &lt;datasource&gt;input&lt;/datasource&gt;
 *             &lt;cf&gt;AVERAGE&lt;/cf&gt;
 *             &lt;format&gt;Average input: @2@c&lt;/format&gt;
 *         &lt;/gprint&gt;
 *         &lt;gprint&gt;
 *             &lt;datasource&gt;output&lt;/datasource&gt;
 *             &lt;cf&gt;TOTAL&lt;/cf&gt;
 *             &lt;format&gt;total output: @2@r&lt;/format&gt;
 *             &lt;-- optional base value --&gt;
 *             &lt;base&gt;1024&lt;/base&gt;
 *         &lt;/gprint&gt;
 *         &lt;hrule&gt;
 *             &lt;value&gt;1234.5678&lt;/value&gt;
 *             &lt;color&gt;#112233&lt;/color&gt;
 *             &lt;legend&gt;horizontal rule&lt;/legend&gt;
 *             &lt;width&gt;3&lt;/width&gt;
 *         &lt;/hrule&gt;
 *         &lt;vrule&gt;
 *             &lt;time&gt;2004-02-22 17:43:57&lt;/time&gt;
 *             &lt;color&gt;#112299&lt;/color&gt;
 *             &lt;legend&gt;vertical rule&lt;/legend&gt;
 *             &lt;width&gt;6&lt;/width&gt;
 *         &lt;/vrule&gt;
 *         &lt;time&gt;
 *             &lt;format&gt;Current time: @t&lt;/format&gt;
 *             &lt;pattern&gt;MMM dd, yyyy   HH:mm:ss&lt;/pattern&gt;
 *         &lt;/time&gt;
 *         &lt;time&gt;
 *             &lt;format&gt;Month: @t&lt;/format&gt;
 *             &lt;pattern&gt;MMMM yyyy&lt;/pattern&gt;
 *             &lt;value&gt;2004-01-01 12:00:00&lt;/value&gt;
 *         &lt;/time&gt;
 *         &lt;comment&gt;Created with JRobin&lt;/comment&gt;
 *     &lt;/graph&gt;
 * &lt;/rrd_graph_def&gt;
 * </pre>
 * Notes on the template syntax:<p>
 * <ul>
 * <li>There is a strong relation between the XML template syntax and the syntax of
 * {@link RrdGraphDef} class methods. If you are not sure what some XML tag means, check javadoc
 * for the corresponding class.
 * <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, however, whitespaces do get special treatment in case of printed text: it is not
 * necessary to use CDATA blocks to specify fixed whitespace with <code>comment</code>,<code>title</code>, <code>time</code>,
 * <code>gprint</code> or <code>legend</code> tags
 * <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
 * be treated as <code>false</code>).
 * <li>floating point values: anything that cannot be parsed will be treated as Double.NaN
 * (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>
 * Any template value (text between <code>&lt;some_tag&gt;</code> and
 * <code>&lt;/some_tag&gt;</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>
 *
 * Typical usage scenario:<p>
 * <ul>
 * <li>Create your XML template and save it to a file (template.xml, for example)
 * <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>
 * &lt;rrd_graph_def&gt;
 *     &lt;span&gt;
 *         &lt;start&gt;${start}&lt;/start&gt;
 *         &lt;end&gt;${end}&lt;/end&gt;
 *     &lt;/span&gt;
 *     ...
 * </pre>
 * <li>In your Java code, create RrdGraphDefTemplate object using your XML template file:
 * <pre>
 * RrdGraphDefTemplate t = new RrdGraphDefTemplate(new File(template.xml));
 * </pre>
 * <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
 * object. This object is actually used to create JRobin grahps:
 * <pre>
 * RrdGraphDef gdef = t.getRrdGraphDef();
 * RrdGraph g = new RrdGraph(gdef);
 * g.saveAsPNG("graph.png");
 * </pre>
 * </ul>
 * You should create new RrdGraphDefTemplate object only once for each XML template. Single template
 * object can be reused to create as many RrdGraphDef objects as needed, with different values
 * specified for template variables. XML synatax check is performed only once - the first graph
 * definition object gets created relatively slowly, but it will be created much faster next time.
 */
public class RrdGraphDefTemplate extends XmlTemplate {

	private RrdGraphDef rrdGraphDef;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -