| 1 | #! /bin/perl | ||
| 2 | ############################################################################# | ||
| 3 | # | ||
| 4 | # NOTE: This file under revision control using RCS | ||
| 5 | # Any changes made without RCS will be lost | ||
| 6 | # | ||
| 7 | # $Source: /usr/local/cvsroot/vbtk/VBTK/Objects/Graph.pm,v $ | ||
| 8 | # $Revision: 1.6 $ | ||
| 9 | # $Date: 2002/03/04 20:53:07 $ | ||
| 10 | # $Author: bhenry $ | ||
| 11 | # $Locker: $ | ||
| 12 | # $State: Exp $ | ||
| 13 | # | ||
| 14 | # Purpose: A perl library used to store VB Object Graph Groupings | ||
| 15 | # | ||
| 16 | # Copyright (C) 1996 - 2002 Brent Henry | ||
| 17 | # | ||
| 18 | # This program is free software; you can redistribute it and/or | ||
| 19 | # modify it under the terms of version 2 of the GNU General Public | ||
| 20 | # License as published by the Free Software Foundation available at: | ||
| 21 | # http://http://www.gnu.org/copyleft/gpl.html | ||
| 22 | # | ||
| 23 | # This program is distributed in the hope that it will be useful, | ||
| 24 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 26 | # GNU General Public License for more details. | ||
| 27 | # | ||
| 28 | ############################################################################# | ||
| 29 | # | ||
| 30 | # | ||
| 31 | # REVISION HISTORY: | ||
| 32 | # | ||
| 33 | # $Log: Graph.pm,v $ | ||
| 34 | # Revision 1.6 2002/03/04 20:53:07 bhenry | ||
| 35 | # *** empty log message *** | ||
| 36 | # | ||
| 37 | # Revision 1.5 2002/03/04 16:49:10 bhenry | ||
| 38 | # Changed requirement back to perl 5.6.0 | ||
| 39 | # | ||
| 40 | # Revision 1.4 2002/03/02 00:53:55 bhenry | ||
| 41 | # Documentation updates | ||
| 42 | # | ||
| 43 | # Revision 1.3 2002/01/28 18:46:48 bhenry | ||
| 44 | # Removed reference to VBTK::Serialize | ||
| 45 | # | ||
| 46 | # Revision 1.2 2002/01/21 17:07:50 bhenry | ||
| 47 | # Disabled 'uninitialized' warnings | ||
| 48 | # | ||
| 49 | # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry | ||
| 50 | # VBTK Project | ||
| 51 | # | ||
| 52 | |||
| 53 | package VBTK::Objects::Graph; | ||
| 54 | |||
| 55 | use 5.6.0; | ||
| 56 | use strict; | ||
| 57 | use warnings; | ||
| 58 | # I like using undef as a value so I'm turning off the uninitialized warnings | ||
| 59 | no warnings qw(uninitialized); | ||
| 60 | |||
| 61 | use VBTK::Common; | ||
| 62 | use VBTK::File; | ||
| 63 | use VBTK::Client; | ||
| 64 | use URI::Escape; | ||
| 65 | |||
| 66 | our $VERBOSE=$ENV{'VERBOSE'}; | ||
| 67 | |||
| 68 | # Define a list of abbreviation which can be used for the member parms. These | ||
| 69 | # will be used mostly when passing parm values through html. | ||
| 70 | our %ABBREV = ( | ||
| 71 | DataSourceList => 'dsl', | ||
| 72 | Labels => 'l', | ||
| 73 | LineWidth => 'lw', | ||
| 74 | Colors => 'c', | ||
| 75 | CF => 'cf', | ||
| 76 | VLabel => 'vl', | ||
| 77 | Title => 't', | ||
| 78 | TimeWindow => 'tw', | ||
| 79 | XSize => 'xs', | ||
| 80 | YSize => 'ys' ); | ||
| 81 | |||
| 82 | #------------------------------------------------------------------------------- | ||
| 83 | # Function: new | ||
| 84 | # Description: Object constructor. Allocates memory for all class members | ||
| 85 | # Input Parms: Configuration filename | ||
| 86 | # Output Parms: Pointer to class | ||
| 87 | #------------------------------------------------------------------------------- | ||
| 88 | sub new | ||
| 89 | { | ||
| 90 | my $type = shift; | ||
| 91 | my $self = {}; | ||
| 92 | bless $self, $type; | ||
| 93 | |||
| 94 | log("Setting up Graph") if ($VERBOSE > 1); | ||
| 95 | |||
| 96 | $self->set(@_); | ||
| 97 | |||
| 98 | my($parmHash,$parm); | ||
| 99 | |||
| 100 | # If the 'Parms' parameter was passed, then search through it for any of the | ||
| 101 | # abbreviated parms defined in the %ABBREV hash and if any are found, then use | ||
| 102 | # them to set the associated member parms. | ||
| 103 | if ($self->{Parms} ne undef) | ||
| 104 | { | ||
| 105 | my $parmHash = $self->{Parms}; | ||
| 106 | foreach $parm (keys %ABBREV) | ||
| 107 | { | ||
| 108 | $self->{$parm} = $parmHash->{$ABBREV{$parm}} || $parmHash->{$parm} | ||
| 109 | if ($self->{$parm} eq undef); | ||
| 110 | } | ||
| 111 | delete($self->{Parms}); | ||
| 112 | } | ||
| 113 | |||
| 114 | # Setup a hash of default parameters | ||
| 115 | my $defaultParms = { | ||
| 116 | DataSourceList => undef, | ||
| 117 | Labels => $::REQUIRED, | ||
| 118 | LineWidth => undef, | ||
| 119 | Colors => undef, | ||
| 120 | CF => undef, | ||
| 121 | VLabel => undef, | ||
| 122 | Title => undef, | ||
| 123 | TimeWindow => undef, | ||
| 124 | XSize => undef, | ||
| 125 | YSize => undef, | ||
| 126 | Target => undef | ||
| 127 | }; | ||
| 128 | |||
| 129 | # Run a validation on the passed parms, using the default parms | ||
| 130 | $self->validateParms($defaultParms) || return undef; | ||
| 131 | |||
| 132 | ($self); | ||
| 133 | } | ||
| 134 | |||
| 135 | #------------------------------------------------------------------------------- | ||
| 136 | # Function: generateUrlParms | ||
| 137 | # Description: Generate the URL parameters which will cause the Rrd.pm library to | ||
| 138 | # generate the appropriate graphs for this graph object | ||
| 139 | # Input Parms: Parms ptr | ||
| 140 | # Output Parms: Array of URL parms | ||
| 141 | #------------------------------------------------------------------------------- | ||
| 142 | sub generateUrlParms | ||
| 143 | { | ||
| 144 | my $self = shift; | ||
| 145 | my ($_parms) = shift; | ||
| 146 | my $Target = $self->{Target}; | ||
| 147 | |||
| 148 | my ($parm,$abbrev,$targetVal,$imgVal,@imgUrlParms,@targetUrlParms,$val); | ||
| 149 | |||
| 150 | # Step through each parm,abbreviation pair, setting the values in the | ||
| 151 | # currParms hash appropriately. Try the parms hash first (both abbreviated | ||
| 152 | # and full names), then try the object itself. | ||
| 153 | while(($parm,$abbrev) = each(%ABBREV)) | ||
| 154 | { | ||
| 155 | $val = $_parms->{$abbrev} || $_parms->{$parm}; | ||
| 156 | $imgVal = $val || $self->{$parm}; | ||
| 157 | |||
| 158 | # If there's a value to pass, then encode it and add it to the list | ||
| 159 | if ($imgVal ne undef) | ||
| 160 | { | ||
| 161 | $imgVal = &uriEscape($imgVal); | ||
| 162 | push(@imgUrlParms,"$abbrev=$imgVal"); | ||
| 163 | } | ||
| 164 | |||
| 165 | # Now form the url pairs for the Target URL. If no 'VBObjName' parm | ||
| 166 | # is specified in the Target hash, then set all URL pairs just like | ||
| 167 | # for the image URL. | ||
| 168 | if($Target->{VBObjName} eq undef) | ||
| 169 | { | ||
| 170 | $targetVal = $val || $Target->{$parm} || $self->{$parm}; | ||
| 171 | |||
| 172 | if($targetVal ne undef) | ||
| 173 | { | ||
| 174 | $targetVal = &uriEscape($targetVal); | ||
| 175 | push(@targetUrlParms,"$abbrev=$targetVal"); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | # If the 'VBObjName' was specified, then ignore any parms passed in | ||
| 179 | # only set URL pairs for parms actually specified in the Target hash. | ||
| 180 | elsif($Target->{$parm} ne undef) | ||
| 181 | { | ||
| 182 | $targetVal = &uriEscape($Target->{$parm}); | ||
| 183 | push(@targetUrlParms,"$abbrev=$targetVal"); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | # If the VBObjName parm is specified in the Target hash, then add in the URL | ||
| 188 | # pairs for the VBObjName and GroupNumber. | ||
| 189 | if($Target->{VBObjName} ne undef) | ||
| 190 | { | ||
| 191 | $Target->{GroupNumber} = 1 if ($Target->{GroupNumber} < 1); | ||
| 192 | push(@targetUrlParms,"name=$Target->{VBObjName}","groupNumber=$Target->{GroupNumber}"); | ||
| 193 | } | ||
| 194 | |||
| 195 | (join('&',@imgUrlParms),join('&',@targetUrlParms)); | ||
| 196 | } | ||
| 197 | |||
| 198 | #------------------------------------------------------------------------------- | ||
| 199 | # Function: uriEscape | ||
| 200 | # Description: Escape out all non alpha-numeric characters in preparation for | ||
| 201 | # transmission over a HTTP request | ||
| 202 | # Input Parms: String | ||
| 203 | # Output Parms: Escaped String | ||
| 204 | #------------------------------------------------------------------------------- | ||
| 205 | sub uriEscape | ||
| 206 | { | ||
| 207 | my ($var) = @_; | ||
| 208 | |||
| 209 | # Escape out any unsafe characters in the text | ||
| 210 | my $safeVar = uri_escape($var,"^A-Za-z0-9-_"); | ||
| 211 | |||
| 212 | ($safeVar); | ||
| 213 | } | ||
| 214 | |||
| 215 | # Simple Get Methods | ||
| 216 | sub getTimeWindow { $_[0]->{TimeWindow}; } | ||
| 217 | sub getDataSourceList { $_[0]->{DataSourceList}; } | ||
| 218 | sub getLabels { $_[0]->{Labels}; } | ||
| 219 | sub getLineWidth { $_[0]->{LineWidth}; } | ||
| 220 | sub getColors { $_[0]->{Colors}; } | ||
| 221 | sub getCF { $_[0]->{CF}; } | ||
| 222 | sub getVLabel { $_[0]->{VLabel}; } | ||
| 223 | sub getTitle { $_[0]->{Title}; } | ||
| 224 | sub getXSize { $_[0]->{XSize}; } | ||
| 225 | sub getYSize { $_[0]->{YSize}; } | ||
| 226 | sub getTarget { $_[0]->{Target}; } | ||
| 227 | |||
| 228 | 1; | ||
| 229 | __END__ |