1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#!/usr/bin/perl
package Debbugs::BugReport;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{BTSATTRIBS}={};
$self->{DMBTATTRIBS}={};
$self->{USERATTRIBS}={};
bless ($self, $class);
return $self;
}
sub init_from_LDAP_entry {
my $self = shift;
my ($entry) = @_;
use Net::LDAP::Entry;
$self->{BTSATTRIBS}={};
foreach my $attr ($entry->attributes) {
# FIXME: no support for multiline fields
$self->{BTSATTRIBS}->{$attr} = $entry->get($attr)->[0];
}
}
sub init_from_XML_tree {
my $self = shift;
my ($tree) = @_;
my $attr = shift @$tree;
while (my $categ = shift @$tree) {
my $categtree = shift @$tree;
my $categattr = shift @$categtree;
while (my $key = shift @$categtree) {
# FIXME: no support for multiline fields
$self->{uc ($categ) . 'ATTRIBS'}->{$key} = ${shift @{$categtree}}[2];
}
}
}
use XML::Writer;
sub write_to_XML_stream {
my $self = shift;
my ($writer) = @_;
$writer->startTag ("bug");
$writer->startTag ("bts");
_write_attribs_hash ($writer, $self->{BTSATTRIBS});
$writer->endTag ("bts");
$writer->startTag ("dmbt");
_write_attribs_hash ($writer, $self->{DMBTATTRIBS});
$writer->endTag ("dmbt");
$writer->startTag ("user");
_write_attribs_hash ($writer, $self->{USERATTRIBS});
$writer->endTag ("user");
$writer->endTag ("bug");
}
sub _write_attribs_hash {
my ($writer, $attribs) = @_;
foreach my $key (keys %{$attribs}) {
$writer->startTag ($key);
# foreach my $line (@{$attribs->{$key}}) {
# $writer->characters($line);
# }
$writer->characters ($attribs->{$key});
$writer->endTag ($key);
}
}
TRUE;
|