[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



I think I got it working somewhat.  

Here is code:
#!/opt/SAM/perl/bin/perl -I/opt/SAM/perl-lib
                                                                                                                             
use XML::Parser;
                                                                                                                             
                                                                                                                             
my %PARAMS = ();
                                                                                                                             
sub add_param {
  my($name, $value) = @_;
  $PARAMS{$name} = $value;
  return;
}
                                                                                                                             
{
  package web_xml;
  my $p_name = undef;
  my $p_value = undef;
                                                                                                                             
  *{"param-name"} = sub {
    $p_name = 1;
  };
                                                                                                                             
                                                                                                                             
  *{"_param-name"} = sub {
    $p_name = undef;
  };
                                                                                                                             
  *{"param-value"} = sub {
  };
                                                                                                                             
                                                                                                                             
  *{"_param-value"} = sub {
    $p_value = undef;
  };
                                                                                                                             
  sub char_handler {
    my ($v1, $v2) = @_;
    return unless $p_name or $p_value;
    if($p_name == 1) {
      $p_name = $v2;
      $p_value = 2;
    } elsif ($p_value == 2) {
      return if $v2 =~ m/^\s/;
      #print "Paramater Name: [$p_name]\n";
      #print "Parameter Value: [$v2]\n";
      ::add_param($p_name, $v2);
      $p_value = undef;
      $p_name = 0;
    }
                                                                                                                             
  }
}
                                                                                                                             
                                                                                                                             
sub get_data {
  my $data = "";
  open(F, "</usr/local/tomcat/webapps/AlarmCenter/WEB-INF/web.xml");
  while(<F>) {
    chomp;
    $data .= $_;
  }
  close(F);
  return $data;
}
                                                                                                                             
                                                                                                                             
sub main {
  my $data =  get_data();
  my $parser = new XML::Parser(Style => 'Subs', Pkg => 'web_xml');
  $parser->setHandlers(Char  => \&web_xml::char_handler);
  $parser->parse($data);
                                                                                                                             
  foreach (keys %PARAMS) {
    print "$_ = $PARAMS{$_}\n";
  }
  return;
}
                                                                                                                             
                                                                                                                             
main;
# vi: set ts=2 sw=2: #

Here is output:

[tomcat at sam-devel Reports]$ /tmp/test.pl   | more
db-driver = org.gjt.mm.mysql.Driver
xslt = /WEB-INF/xml/main.xsl
cmsdb-service-name = cmsdb
web-version = Version 1.1.0 (Build 2944)
cc-proxy-timeout = 2
jcd-ssl = true
db-user = cms
console-log-path = /u01/cms/logs/
regex-validator = /opt/SAM/Utils/bin/regex_test.pl -t
db-url = jdbc:mysql://127.0.0.1/ALARMCENTER
notify-script = /opt/SAM/ensbins/notify.pl
cc-proxy-port = 4000
db-pass = cms
cc-ens-port = 782
restart-script = /opt/SAM/Utils/bin/restart.pl
jcd-port = 785

Here is XML piece:
 <!-- GENERAL APPLICATION CONFIGURATION -->^M
 
<context-param><param-name>db-driver</param-name><param-value>org.gjt.mm.mysql.Driver</param-value></context-param>^M
 
<context-param><param-name>db-url</param-name><param-value>jdbc:mysql://127.0.0.1/ALARMCENTER</param-value></context-param>^M
 
<context-param><param-name>db-user</param-name><param-value>cms</param-value></context-param>^M
 
<context-param><param-name>db-pass</param-name><param-value>cms</param-value></context-param>^M
 
<context-param><param-name>console-log-path</param-name><param-value>/u01/cms/logs/</param-value></context-param>^M
 
<context-param><param-name>default-organization</param-name><param-value/></context-param>^M
  <context-param>^M
        <param-name>cc-proxy-timeout</param-name>^M
        <param-value>2</param-value>^M
  </context-param>^M
 
<context-param><param-name>cc-proxy-port</param-name><param-value>4000</param-value></context-param>^M
  <context-param>^M
        <param-name>cc-ens-port</param-name>^M
        <param-value>782</param-value>^M
  </context-param>^M
  <context-param>^M
        <param-name>jcd-port</param-name>^M
        <param-value>785</param-value>^M
  </context-param>^M
  <context-param>^M
        <param-name>jcd-ssl</param-name>^M
        <param-value>true</param-value>^M
  </context-param>^M
 
<context-param><param-name>restart-script</param-name><param-value>/opt/SAM/Utils/bin/restart.pl</param-value></context-param>^M
  <context-param>^M
        <param-name>cmsdb-service-name</param-name>^M
        <param-value>cmsdb</param-value>^M
  </context-param>^M

The _<sub names> do not seem to be working.  I'msure there are some
gotchas that will break this code but the server is in a controlled
environment.  The users do not even have tty access to the Linux box. 
Web only.



</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00021" href="msg00021.html">[ale] Issue with sub name and XML::Parser</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00028" href="msg00028.html">[ale] Issue with sub name and XML::Parser</a></strong>
<ul><li><em>From:</em> fletch at phydeaux.org (Fletch)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00034.html">[ale] custome init levels</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00036.html">[ale] Introduction</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00028.html">[ale] Issue with sub name and XML::Parser</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00029.html">[ale] Linux PIM</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00035"><strong>Date</strong></a></li>
<li><a href="threads.html#00035"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>