Ignore:
Timestamp:
2015-01-07T11:06:08+13:00 (9 years ago)
Author:
Jeremy Symon
Message:

Added ability to write to stdout (set output file to '-')

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/package-kits/linux/files/servlet.pl

    r29666 r29667  
    9999sub write_servlets {
    100100    my ($hash, $file) = @_;
    101     open OUT, '>', $file;
     101    my $OUT;
     102    if ($file ne '-') {
     103        open $OUT, '>', $file;
     104        select $OUT;
     105    }
    102106    sub open_tag {
    103107        my ($indent, $tag, $attr) = @_;
    104         print OUT $indent, "<", $tag;
     108        print $indent, "<", $tag;
    105109        if (defined $attr) {
    106110            for my $key (sort keys %$attr) {
    107                 print OUT " ", $key, '="', $attr->{$key}, '"';
    108             }
    109         }
    110         print OUT ">";
     111                print " ", $key, '="', $attr->{$key}, '"';
     112            }
     113        }
     114        print ">";
    111115    }
    112116    sub write_xml {
     
    116120            my $val = $hash->{$key};
    117121            $key eq '.value' && do {
    118                 print OUT $val, "\n";
     122                print $val, "\n";
    119123                next;
    120124            };
     
    125129                        for (ref $element) {
    126130                            /^HASH$/ && do {
    127                                 print OUT "\n";
     131                                print "\n";
    128132                                write_xml ("  $indent", $element);
    129                                 print OUT $indent, "</", $key, ">\n";
     133                                print $indent, "</", $key, ">\n";
    130134                                last;
    131135                            };
    132                             print OUT $element, "</", $key, ">\n";
     136                            print $element, "</", $key, ">\n";
    133137                        }
    134138                    }
     
    140144                    # it can be formatted on one line
    141145                    if (scalar keys %$val == 2 and defined $val->{'.value'}) {
    142                         print OUT $val->{'.value'}, "</", $key, ">\n";
     146                        print $val->{'.value'}, "</", $key, ">\n";
    143147                    } else {
    144                         print OUT "\n";
     148                        print "\n";
    145149                        write_xml ("  $indent", $val);
    146                         print OUT $indent, "</", $key, ">\n";
     150                        print $indent, "</", $key, ">\n";
    147151                    }
    148152                    last;
    149153                };
    150154                open_tag ($indent, $key);
    151                 print OUT $val;
    152                 print OUT "</", $key, ">\n";
     155                print $val;
     156                print "</", $key, ">\n";
    153157            }
    154158        }
    155159    }
    156160    write_xml ("", $hash);
    157     close OUT;
    158 }
     161    if (defined $OUT) {
     162        close $OUT;
     163    }
     164    select STDOUT;
     165}
     166# The code above is for generic XML read/writing
     167# The code below is specific to Greenstone's servlets.xml
    159168
    160169my $hash;
Note: See TracChangeset for help on using the changeset viewer.