From: Arne V. <cob...@us...> - 2004-07-13 12:13:24
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26272/org/jrobin/graph Modified Files: ExportData.java RrdExportDefTemplate.java RrdGraphDefTemplate.java Log Message: JRobin 1.4.0 - Minor tweaks - Added ExportExportDemo and ExportImportDemo - Added importXml() with dsNamePrefix to FetchData - Added demo resources Index: ExportData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ExportData.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExportData.java 11 Jul 2004 22:04:13 -0000 1.3 --- ExportData.java 13 Jul 2004 12:13:13 -0000 1.4 *************** *** 103,106 **** --- 103,121 ---- /** + * Create an ExportData object based on export XML string.. + * + * @param xportXml File containing export xml. + * @param dsNamePrefix Prefix of the datasource names. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ + public ExportData( String xportXml, String dsNamePrefix ) throws RrdException, IOException + { + this(); + + importXml( xportXml, dsNamePrefix ); + } + + /** * Create an ExportData object based on export XML file. * *************** *** 131,134 **** --- 146,163 ---- } + /** + * Create an ExportData object based on export XML file. + * + * @param xmlFile File containing export xml. + * @param dsNamePrefix Prefix of the datasource names. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ + public ExportData( File xmlFile, String dsNamePrefix ) throws RrdException, IOException + { + this(); + + importXml( xmlFile, dsNamePrefix ); + } *************** *** 390,394 **** { Element root = Util.Xml.getRootElement( xmlFile ); ! importXml( root, useLegendNames ); } --- 419,423 ---- { Element root = Util.Xml.getRootElement( xmlFile ); ! importXml( root, useLegendNames, "d" ); } *************** *** 397,459 **** * The XML can be from either a JRobin or RRDtool export. * ! * The name of the datasources found will depend on the 'useLegendNames' flag. * * @param xportXml String containing the XML result of an export. ! * @param useLegendNames True if the names for the datasources should be set to ! * the legend values, false if they should be d1, d2, ... */ ! public void importXml( String xportXml, boolean useLegendNames ) throws RrdException, IOException { Element root = Util.Xml.getRootElement( xportXml ); ! importXml( root, useLegendNames ); } ! private void importXml( Element root, boolean useLegendNames ) throws RrdException, IOException { ! Node meta = Util.Xml.getFirstChildNode( root, "meta" ); ! Node[] dataRows = Util.Xml.getChildNodes( Util.Xml.getFirstChildNode( root, "data" ), "row" ); ! ! sourceByName.clear(); ! legends.clear(); ! ! // -- Parse the metadata ! int columns = Util.Xml.getChildValueAsInt( meta, "columns" ); ! long step = Util.Xml.getChildValueAsLong( meta, "step" ); ! String[] dsNames = new String[ columns ]; ! Node[] legendNodes = Util.Xml.getChildNodes( Util.Xml.getFirstChildNode( meta, "legend"), "entry" ); ! for ( int i = 0; i < legendNodes.length; i++ ) ! { ! String legend = Util.Xml.getValue( legendNodes[i] ); ! if ( useLegendNames ) ! dsNames[i] = legend; ! else ! dsNames[i] = "d" + (i + 1); ! ! legends.put( dsNames[i], legend ); ! } ! ! // -- Parse the data ! timestamps = new long[ dataRows.length ]; ! sources = new Source[ columns ]; ! arraySize = timestamps.length; ! ! for ( int i = 0; i < sources.length; i++ ) ! { ! sources[i] = new Def( dsNames[i], arraySize, arraySize ); ! sources[i].setFetchedStep( step ); ! } ! ! for ( int i = 0; i < dataRows.length; i++ ) ! { ! timestamps[i] = Util.Xml.getChildValueAsLong( dataRows[i], "t" ); ! Node[] data = Util.Xml.getChildNodes( dataRows[i], "v" ); ! ! for ( int j = 0; j < data.length; j++ ) ! sources[j].set( i, timestamps[i], Util.Xml.getValueAsDouble(data[j]) ); ! } ! // -- Set the datasource - name ! for ( int i = 0; i < sources.length; i++ ) ! sourceByName.put( sources[i].getName(), sources[i] ); } --- 426,471 ---- * The XML can be from either a JRobin or RRDtool export. * ! * The name of the datasources found will be the prefix passed as parameter, ! * followed by a number, making the name unique. * * @param xportXml String containing the XML result of an export. ! * @param dsNamePrefix Prefix of the datasource names. */ ! public void importXml( String xportXml, String dsNamePrefix ) throws RrdException, IOException { Element root = Util.Xml.getRootElement( xportXml ); ! importXml( root, false, dsNamePrefix ); } ! /** ! * Imports a export XML string and maps it back to this ExportData object. ! * The XML can be from either a JRobin or RRDtool export. ! * ! * The name of the datasources found will be the prefix passed as parameter, ! * followed by a number, making the name unique. ! * ! * @param xmlFile File containing export XML dump. ! * @param dsNamePrefix Prefix of the datasource names. ! */ ! public void importXml( File xmlFile, String dsNamePrefix ) throws RrdException, IOException { ! Element root = Util.Xml.getRootElement( xmlFile ); ! importXml( root, false, dsNamePrefix ); ! } ! /** ! * Imports a export XML string and maps it back to this ExportData object. ! * The XML can be from either a JRobin or RRDtool export. ! * ! * The name of the datasources found will depend on the 'useLegendNames' flag. ! * ! * @param xportXml String containing the XML result of an export. ! * @param useLegendNames True if the names for the datasources should be set to ! * the legend values, false if they should be d1, d2, ... ! */ ! public void importXml( String xportXml, boolean useLegendNames ) throws RrdException, IOException ! { ! Element root = Util.Xml.getRootElement( xportXml ); ! importXml( root, useLegendNames, "d" ); } *************** *** 553,555 **** --- 565,616 ---- return (Source) sourceByName.get(name); } + + private void importXml( Element root, boolean useLegendNames, String dsNamePrefix ) throws RrdException + { + Node meta = Util.Xml.getFirstChildNode( root, "meta" ); + Node[] dataRows = Util.Xml.getChildNodes( Util.Xml.getFirstChildNode( root, "data" ), "row" ); + + sourceByName.clear(); + legends.clear(); + + // -- Parse the metadata + int columns = Util.Xml.getChildValueAsInt( meta, "columns" ); + long step = Util.Xml.getChildValueAsLong( meta, "step" ); + String[] dsNames = new String[ columns ]; + Node[] legendNodes = Util.Xml.getChildNodes( Util.Xml.getFirstChildNode( meta, "legend"), "entry" ); + for ( int i = 0; i < legendNodes.length; i++ ) + { + String legend = Util.Xml.getValue( legendNodes[i] ); + if ( useLegendNames ) + dsNames[i] = legend; + else + dsNames[i] = dsNamePrefix + (i + 1); + + legends.put( dsNames[i], legend ); + } + + // -- Parse the data + timestamps = new long[ dataRows.length ]; + sources = new Source[ columns ]; + arraySize = timestamps.length; + + for ( int i = 0; i < sources.length; i++ ) + { + sources[i] = new Def( dsNames[i], arraySize, arraySize ); + sources[i].setFetchedStep( step ); + } + + for ( int i = 0; i < dataRows.length; i++ ) + { + timestamps[i] = Util.Xml.getChildValueAsLong( dataRows[i], "t" ); + Node[] data = Util.Xml.getChildNodes( dataRows[i], "v" ); + + for ( int j = 0; j < data.length; j++ ) + sources[j].set( i, timestamps[i], Util.Xml.getValueAsDouble(data[j]) ); + } + + // -- Set the datasource - name + for ( int i = 0; i < sources.length; i++ ) + sourceByName.put( sources[i].getName(), sources[i] ); + } } Index: RrdExportDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExportDefTemplate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExportDefTemplate.java 11 Jul 2004 22:04:14 -0000 1.1 --- RrdExportDefTemplate.java 13 Jul 2004 12:13:13 -0000 1.2 *************** *** 134,138 **** 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++) { --- 134,138 ---- private void resolveDatasources(Node datasourceNode) throws RrdException { ! validateTagsOnlyOnce(datasourceNode, new String[] { "def*", "export_data*" }); Node[] nodes = getChildNodes(datasourceNode, "def"); for(int i = 0; i < nodes.length; i++) { *************** *** 173,176 **** --- 173,202 ---- } } + + nodes = getChildNodes(datasourceNode, "export_data"); + for ( int i = 0; i < nodes.length; i++ ) + { + validateTagsOnlyOnce( nodes[i], new String[] {"file", "ds_name_prefix", "use_legend_names"} ); + String file = getChildValue( nodes[i], "file" ); + String prefix = "d"; + boolean use_legends = false; + + if ( Util.Xml.hasChildNode( nodes[i], "ds_name_prefix" ) ) + prefix = getChildValue(nodes[i], "ds_name_prefix"); + + if ( Util.Xml.hasChildNode( nodes[i], "use_legend_names" ) ) + use_legends = getChildValueAsBoolean(nodes[i], "use_legend_names"); + + try + { + if ( !prefix.equals("d") ) + def.addExportData( new ExportData( new File(file), prefix ) ); + else + def.addExportData( new ExportData( new File(file), use_legends ) ); + } + catch ( IOException ioe ) { + throw new RrdException( ioe ); + } + } } Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdGraphDefTemplate.java 11 Jul 2004 22:04:14 -0000 1.8 --- RrdGraphDefTemplate.java 13 Jul 2004 12:13:13 -0000 1.9 *************** *** 487,491 **** 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++) { --- 487,491 ---- private void resolveDatasources(Node datasourceNode) throws RrdException { ! validateTagsOnlyOnce(datasourceNode, new String[] { "def*", "export_data*" }); Node[] nodes = getChildNodes(datasourceNode, "def"); for(int i = 0; i < nodes.length; i++) { *************** *** 526,529 **** --- 526,555 ---- } } + + nodes = getChildNodes(datasourceNode, "export_data"); + for ( int i = 0; i < nodes.length; i++ ) + { + validateTagsOnlyOnce( nodes[i], new String[] {"file", "ds_name_prefix", "use_legend_names"} ); + String file = getChildValue( nodes[i], "file" ); + String prefix = "d"; + boolean use_legends = false; + + if ( Util.Xml.hasChildNode( nodes[i], "ds_name_prefix" ) ) + prefix = getChildValue(nodes[i], "ds_name_prefix"); + + if ( Util.Xml.hasChildNode( nodes[i], "use_legend_names" ) ) + use_legends = getChildValueAsBoolean(nodes[i], "use_legend_names"); + + try + { + if ( !prefix.equals("d") ) + rrdGraphDef.addExportData( new ExportData( new File(file), prefix ) ); + else + rrdGraphDef.addExportData( new ExportData( new File(file), use_legends ) ); + } + catch ( IOException ioe ) { + throw new RrdException( ioe ); + } + } } *************** *** 537,541 **** "overlay", "show_legend", "show_signature", "time_axis", "time_axis_label", "title", "title_font", "title_font_color", "units_exponent", "value_axis", ! "vertical_label" }); Node[] optionNodes = getChildNodes(rootOptionNode); --- 563,567 ---- "overlay", "show_legend", "show_signature", "time_axis", "time_axis_label", "title", "title_font", "title_font_color", "units_exponent", "value_axis", ! "vertical_label", "strict_export", "resolution" }); Node[] optionNodes = getChildNodes(rootOptionNode); *************** *** 679,685 **** "maj_grid_unit_steps", "date_format", "center_labels", "first_day_of_week" }); ! if ( hasChildNode( optionNode, "min_grid_time_unit" ) ) ! { int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); --- 705,711 ---- "maj_grid_unit_steps", "date_format", "center_labels", "first_day_of_week" }); ! if ( hasChildNode( optionNode, "min_grid_time_unit" ) ) ! { int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); *************** *** 690,697 **** rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); } ! // Determine first day of the week if ( hasChildNode( optionNode, "first_day_of_week" ) ) ! { int dow = resolveDayUnit( getChildValue(optionNode, "first_day_of_week") ); rrdGraphDef.setFirstDayOfWeek( dow ); --- 716,723 ---- rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); } ! // Determine first day of the week if ( hasChildNode( optionNode, "first_day_of_week" ) ) ! { int dow = resolveDayUnit( getChildValue(optionNode, "first_day_of_week") ); rrdGraphDef.setFirstDayOfWeek( dow ); *************** *** 735,738 **** --- 761,772 ---- rrdGraphDef.setVerticalLabel(label); } + // STRICT EXPORT + else if(option.equals("strict_export")) { + rrdGraphDef.setStrictExport( getValueAsBoolean(optionNode) ); + } + // RESOLUTION + else if(option.equals("resolution")) { + rrdGraphDef.setResolution( getValueAsInt(optionNode) ); + } } } *************** *** 764,768 **** } } ! private int resolveDayUnit( String unit ) { if ( unit.equalsIgnoreCase("monday") ) { --- 798,802 ---- } } ! private int resolveDayUnit( String unit ) { if ( unit.equalsIgnoreCase("monday") ) { *************** *** 790,794 **** throw new IllegalArgumentException( "Invalid day unit specified: " + unit ); } ! } --- 824,828 ---- throw new IllegalArgumentException( "Invalid day unit specified: " + unit ); } ! } |