Changeset 27173
- Timestamp:
- 2013-04-11T18:56:35+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r27168 r27173 317 317 if (!defined $docid) 318 318 { 319 $gsdl_cgi->generate_error _message("No docid (d=...) specified.\n");319 $gsdl_cgi->generate_error("No docid (d=...) specified.\n"); 320 320 } 321 321 … … 660 660 # want either d= or f= 661 661 my $docid = $self->{'d'}; 662 my ($docid_root,$docid_secnum); 663 if(defined $docid) { 664 ($docid_root,$docid_secnum) = ($docid =~ m/^(.*?)(\..*)?$/); 665 # as yet no support for setting subsection metadata in metadata.xml 666 if ((defined $docid_secnum) && ($docid_secnum !~ m/^\s*$/)) { 667 $gsdl_cgi->generate_ok_message("*** Unable to set import metadata for subsections at this stage.\n"); 668 return; 669 } 670 } 671 662 672 my $import_file = $self->{'f'}; 663 673 if ((!defined $docid) && (!defined $import_file)) { … … 684 694 if (defined $docid) { 685 695 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 686 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid );696 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid_root); 687 697 688 698 # This now stores the full pathname … … 706 716 # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file) 707 717 $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, 708 718 $metaname, $metavalue, $metamode, $import_tailname); 709 719 710 720 … … 1300 1310 1301 1311 my $curr_secnum = $parser->{'parameters'}->{'curr_section_num'}; 1302 my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'} ;1312 my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'} || ""; 1303 1313 1304 1314 print STDERR "**** Processing a closing </Description> tag \n"; … … 1329 1339 } 1330 1340 1331 # If get to here and metamode is override, thethis means there1341 # If we get to here and metamode is override, this means there 1332 1342 # was no existing value to overide => treat as an append operation 1333 1343 … … 1809 1819 rules => \@rules, 1810 1820 style => 'filter', 1811 output_encoding => 'utf8' 1821 output_encoding => 'utf8', 1822 # normalisespaces => 1, # http://search.cpan.org/~jenda/XML-Rules-1.16/lib/XML/Rules.pm 1823 stripspaces => 2|0|0 # ineffectual 1812 1824 ); 1813 1825 … … 1849 1861 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 1850 1862 1851 if (!($parser->{'parameters'}->{'secid'} eq $parser->{'parameters'}->{'curr_section_num'})) 1863 # For comparisons, toplevel section is indicated by "" 1864 my $curr_sec_num = $parser->{'parameters'}->{'curr_section_num'} || ""; 1865 my $secid = $parser->{'parameters'}->{'secid'} || ""; 1866 1867 if (!($secid eq $curr_sec_num)) 1852 1868 { 1853 1869 # RAW is [$tagname => $attrHash] not $tagname => $attrHash!! … … 1893 1909 1894 1910 # Report error if we don't see FileName tag before this 1895 die "Fatal Error: Unexpected metadata.xml structure. Undefin d current_file, possiblely encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'}));1911 die "Fatal Error: Unexpected metadata.xml structure. Undefined current_file, possibly encountered Description before FileName" if (!defined($parser->{'parameters'}->{'current_file'})); 1896 1912 1897 1913 # Don't do anything if we are not in the right FileSet … … 1901 1917 # file. 1902 1918 # So, skip anything with a .* in it as it is too general 1919 # print STDERR "@@@@ Skipping entry in metadata.xml where FileName=.* as it is too general\n"; 1903 1920 return [$tagname => $attrHash]; 1904 1921 } … … 1916 1933 $attrHash->{'_content'} = $metavalue; 1917 1934 1918 ## print STDERR "**** overrid eing metadata.xml\n";1935 ## print STDERR "**** overriding metadata.xml\n"; 1919 1936 1920 1937 # Don't want it to wipe out any other pieces of metadata … … 2016 2033 } 2017 2034 2035 sub mxml_directorymetadata 2036 { 2037 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 2038 2039 # if we haven't processed the metadata when we reach the end of metadata.xml 2040 # it's because there's no particular FileSet element whose FileName matched 2041 # In which case, add a new FileSet for this FileName 2042 my $metamode = $parser->{'parameters'}->{'metamode'}; 2043 if($metamode ne "done") { 2044 2045 if ($metamode eq "override") { 2046 print "No metadata value to override. Switching 'metamode' to accumulate\n"; 2047 } 2048 2049 # If we get to here and metamode is override, this means there 2050 # was no existing value to overide => treat as an append operation 2051 2052 # Create a new FileSet element and append to DirectoryMetadata 2053 # <FileSet> 2054 # <FileName>src_file</FileName> 2055 # <Description> 2056 # <Metadata mode="" name="">metavalue</Metadata> 2057 # </Description> 2058 # </FileSet> 2059 my $src_file = $parser->{'parameters'}->{'src_file'}; 2060 my $metaname = $parser->{'parameters'}->{'metaname'}; 2061 my $metavalue = $parser->{'parameters'}->{'metavalue'}; 2062 my $metadata_attr = { 2063 '_content' => $metavalue, 2064 'name' => $metaname, 2065 'mode' => "accumulate" 2066 }; 2067 my $append_metadata = [ "Metadata" => $metadata_attr ]; 2068 my $description_attr->{'_content'} = [ "\n\t\t ", $append_metadata, "\n\t\t"]; 2069 my $description_element = [ "Description" => $description_attr ]; 2070 2071 #_content is not an attribute, it's special and holds the children of this element 2072 # including the textnode value embedded in this element if any. 2073 my $filename_attr = {'_content' => $src_file}; 2074 my $filename_element = [ "FileName" => $filename_attr ]; 2075 2076 my $fileset_attr = {}; 2077 $fileset_attr->{'_content'} = [ "\n\t\t", $filename_element,"\n\t\t",$description_element ,"\n\t" ]; 2078 my $fileset = [ "FileSet" => $fileset_attr ]; #my $fileset = [ "FileSet" => {} ]; 2079 2080 2081 # get children of dirmeta, and push the new FileSet element onto it 2082 print "Appending metadata to metadata.xml\n"; 2083 my $dirmeta_content = $attrHash->{'_content'}; 2084 if (ref($dirmeta_content)) { 2085 # got some existing interesting nested content 2086 #push(@$dirmeta_content, " ", $fileset ,"\n "); 2087 push(@$dirmeta_content, "\t", $fileset ,"\n"); 2088 } 2089 else { 2090 #description_content is most likely a string such as "\n" 2091 #$attrHash->{'_content'} = [$dirmeta_content, " ", $fileset ,"\n" ]; 2092 $attrHash->{'_content'} = [$dirmeta_content, "\t", $fileset ,"\n" ]; 2093 } 2094 2095 $parser->{'parameters'}->{'metamode'} = "done"; 2096 } 2097 # RAW is [$tagname => $attrHash] not $tagname => $attrHash!! 2098 return [$tagname => $attrHash]; 2099 } 2100 2018 2101 2019 2102 sub edit_metadata_xml … … 2028 2111 'Metadata' => \&mxml_metadata, 2029 2112 'Description' => \&mxml_description, 2030 'FileSet' => \&mxml_fileset); 2113 'FileSet' => \&mxml_fileset, 2114 'DirectoryMetadata' => \&mxml_directorymetadata); 2031 2115 2032 2116 # use XML::Rules to add it in (read in and out again) 2033 2117 my $parser = XML::Rules->new(rules => \@rules, 2034 2118 style => 'filter', 2035 output_encoding => 'utf8'); 2119 output_encoding => 'utf8', 2120 stripspaces => 2|0|0); # http://search.cpan.org/~jenda/XML-Rules-1.16/lib/XML/Rules.pm 2036 2121 2037 2122 if (!-e $metadata_xml_filename) { … … 2276 2361 if ((!defined $docid) || ($docid =~ m/^\s*$/)) 2277 2362 { 2278 $gsdl_cgi->generate_error _message("No docid (d=...) specified.\n");2363 $gsdl_cgi->generate_error("No docid (d=...) specified.\n"); 2279 2364 } 2280 2365 … … 2298 2383 if((!defined $import_filename) || ($import_filename =~ m/^\s*$/)) 2299 2384 { 2300 $gsdl_cgi->generate_error _message("There is no metadata\n");2385 $gsdl_cgi->generate_error("There is no metadata\n"); 2301 2386 } 2302 2387 … … 2358 2443 rules => \@rules, 2359 2444 style => 'filter', 2360 output_encoding => 'utf8' 2445 output_encoding => 'utf8', 2446 #normalisespaces => 1, 2447 stripspaces => 2|0|0 # ineffectual 2361 2448 ); 2362 2449 … … 2396 2483 if ((defined $parser->{'parameters'}->{'metavalue'}) && ($parser->{'parameters'}->{'src_file'} eq $parser->{'parameters'}->{'current_file'}) && ($attrHash->{'name'} eq $parser->{'parameters'}->{'metaname'}) && ($attrHash->{'_content'} eq $parser->{'parameters'}->{'metavalue'})) 2397 2484 { 2398 2485 return []; 2399 2486 } 2400 2487
Note:
See TracChangeset
for help on using the changeset viewer.