diff debian/patches/12_optional_xml_elements @ 4:c5749e43b1d7

Adding debian files (to original 1.1.29)
author Peter Gervai <grin@grin.hu>
date Wed, 15 Oct 2008 23:35:35 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/patches/12_optional_xml_elements	Wed Oct 15 23:35:35 2008 +0200
@@ -0,0 +1,107 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 12_optional_xml_elements.dpatch  by Martin Michlmayr <tbm@cyrius.com>
+##
+## DP: Make XML elements optional and check whether the XML files are
+## DP: valid bins files [#308338]
+
+@DPATCH@
+--- bins-1.1.29.orig/bins
++++ bins-1.1.29/bins
+@@ -3899,10 +3899,14 @@
+     if (-e $descFile) {
+         beVerboseN("  Reading desc file $descFile.", 3);
+         $document = getXMLAsGrove($descFile);
+-        %descHash   = getDescXML($document, $configHash);
+-        #$descHash{descFileName} =  uri_escape($descFile, '^-A-Za-z0-9/_\.');
+-        $configHash = getConfigXML($document, '/image/bins', $configHash);
+-        %exifHash   = getExifXML($document, \@priorityList);
++        if (! $document->at_path("/image")) {
++            beVerboseN("Description file $descFile has no <image> element, ignoring.", 1);
++        } else {
++            %descHash   = getDescXML($document, $configHash) if $document->at_path("/image/description");
++            #$descHash{descFileName} =  uri_escape($descFile, '^-A-Za-z0-9/_\.');
++            $configHash = getConfigXML($document, '/image/bins', $configHash) if $document->at_path("/image/bins");
++            %exifHash   = getExifXML($document, \@priorityList) if $document->at_path("/image/exif");
++        }
+     } else {
+         $descHash{descFileName} =  "";
+     }
+@@ -4541,6 +4545,10 @@
+     beVerboseN("Reading album description file '$descFile'...", 3);
+ 
+     my $document = getXMLAsGrove($descFile);
++    if (! $document->at_path("/album")) {
++        beVerboseN("Description file $descFile has no <album> element, ignoring.", 1);
++        return $configHash;
++    }
+     # I have to do that, don't ask me why...
+ 
+     #$XML::UM::ENCDIR="/usr/lib/perl5/XML/Parser/";
+@@ -4548,37 +4556,40 @@
+     #             Encoding => 'ISO-8859-9',
+     #             EncodeUnmapped => \&XML::UM::encode_unmapped_dec);
+ 
+-    $configHash = getConfigXML($document, "/album/bins", $configHash);
++    $configHash = getConfigXML($document, "/album/bins", $configHash) if
++        $document->at_path("/album/bins");
+ 
+-    foreach my $element
+-        (@{$document->at_path('/album/description')->{Contents}}) {
+-            if (UNIVERSAL::isa($element, 'XML::Grove::Element') && $element->{Name} eq "field") {
+-                $fieldName = $element->{Attributes}{'name'};
+-                $fieldValue = "";
+-                if (grep (/^$fieldName$/, @AlbumFieldNames)) {
+-                    beVerbose("    Reading field '$fieldName':", 3);
+-                    foreach my $characters (@{$element->{Contents}}) {
+-                        $fieldValue .= $characters->as_canon_xml();
+-                    }
+-                    #if ($fieldName ne "shortdesc" && $fieldName ne "longdesc"){
+-                    #  $fieldValue = decode_entities($fieldValue);
+-                    #}
+-                    if ($fieldName eq "sampleimage"){
+-                        $fieldValue =
+-                            trimWhiteSpace(decode_entities($fieldValue));
+-                        beVerbose("'".$fieldValue."'\n", 3);
+-                    }else{
+-                        $fieldValue =
+-                            trimWhiteSpace(decode_entities(xml2html($fieldValue)));
+-                        beVerbose("'".$fieldValue."'\n", 3);
++    if ($document->at_path("/album/description")) {
++        foreach my $element
++            (@{$document->at_path('/album/description')->{Contents}}) {
++                if (UNIVERSAL::isa($element, 'XML::Grove::Element') && $element->{Name} eq "field") {
++                    $fieldName = $element->{Attributes}{'name'};
++                    $fieldValue = "";
++                    if (grep (/^$fieldName$/, @AlbumFieldNames)) {
++                        beVerbose("    Reading field '$fieldName':", 3);
++                        foreach my $characters (@{$element->{Contents}}) {
++                            $fieldValue .= $characters->as_canon_xml();
++                        }
++                        #if ($fieldName ne "shortdesc" && $fieldName ne "longdesc"){
++                        #  $fieldValue = decode_entities($fieldValue);
++                        #}
++                        if ($fieldName eq "sampleimage"){
++                            $fieldValue =
++                                trimWhiteSpace(decode_entities($fieldValue));
++                            beVerbose("'".$fieldValue."'\n", 3);
++                        }else{
++                            $fieldValue =
++                                trimWhiteSpace(decode_entities(xml2html($fieldValue)));
++                            beVerbose("'".$fieldValue."'\n", 3);
++                        }
++                        #       $fieldValue = $encode->(trimWhiteSpace($fieldValue));
++                        $hash->{$fieldName} = $fieldValue;
++                    } else {
++                        beVerboseN("    Ignoring unknown field '$fieldName'.", 3);
+                     }
+-                    #       $fieldValue = $encode->(trimWhiteSpace($fieldValue));
+-                    $hash->{$fieldName} = $fieldValue;
+-                } else {
+-                    beVerboseN("    Ignoring unknown field '$fieldName'.", 3);
+                 }
+             }
+-        }
++    }
+     return $configHash;
+ }
+