Changeset 14028


Ignore:
Timestamp:
2007-04-30T15:53:08+12:00 (17 years ago)
Author:
xiao
Message:
  1. Changes made to look for collectionConfig.xml in gs3 mode and collect.cfg in gs2 mode, rather than presumably only for the file collect.cfg. 2. In the method create_images(), update the file collectionConfig.xml for the default images icon.gif and smallicon.gif if the 'create_image' option is set.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/buildcol.pl

    r12964 r14028  
    3333    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    3434    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
     35    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/XML/XPath");
    3536    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
    3637    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
     
    4849no strict 'refs'; # allow filehandles to be variables and vice versa
    4950no strict 'subs'; # allow barewords (eg STDERR) as function arguments
     51
     52# used in updating Collectionconfig.xml in create_images()
     53use Twig;
    5054
    5155my $mode_list =
     
    215219my $out;
    216220
     221# used to signify "gs2"(default) or "gs3"
     222my $gs_mode = "gs2";
     223
    217224## @method gsprintf()
    218225#  Print a string to the screen after looking it up from a locale dependant
     
    340347    unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib/plugins");
    341348
    342     # read the configuration file
     349    # read the configuration file (for gs2)
    343350    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
    344351    my ($collectcfg, $buildtype);
    345352
    346     if (!-e $configfilename) {
     353    if (-e $configfilename) {
     354      $collectcfg = &colcfg::read_collect_cfg ($configfilename);
     355      $gs_mode = "gs2"; 
     356    }
     357    else {
     358
     359      # If it is gs3
     360      $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");
     361
     362      if (!-e $configfilename) {
    347363    &gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die;
    348     }
    349    
    350     $collectcfg = &colcfg::read_collect_cfg ($configfilename);
     364      }
     365      else {
     366    $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
     367    $gs_mode = "gs3";
     368      }
     369    }
    351370   
    352371    if ($verbosity !~ /\d+/) {
     
    600619    system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
    601620
     621    if ($gs_mode eq "gs3") {
     622    # update the CollectionConfig.xml file
     623    # what we need to do is find in CollectionConfig.xml the two elements with attributes 'icon' and 'smallicon'
     624    # and replace the node text with $collection.gif and ${collection}sm.gif respectively. If they don't exist,
     625    # create new ones by using the image names.
     626
     627
     628    my $found = 0; my $foundsm = 0;
     629   
     630    my $twig = XML::Twig->new();
     631    $twig->parsefile($configfilename);
     632    my $root = $twig->root;
     633    my $displayItemList = $root->first_child('displayItemList');
     634    my @displayItem = $displayItemList->children('displayItem');
     635    foreach my $displayItem (@displayItem) {
     636        my $att_value = $displayItem->{'att'}->{'name'};
     637       
     638        if($att_value eq 'icon') {
     639        $found = 1;
     640        }
     641        elsif ( $att_value eq 'smallicon') {
     642        $foundsm = 1;
     643        }
     644    }
     645
     646    if ($found eq 0) { print "write icon";
     647        my $icon_displayItem_element = XML::Twig::Elt->new('displayItem');
     648        $icon_displayItem_element->set_att('name', '$collection.gif');
     649        $icon_displayItem_element->set_att('lang', 'en');
     650        $icon_displayItem_element->set_text("$collection.gif");
     651        $icon_displayItem_element->paste('last_child', $displayItemList);
     652    }
     653    if ($foundsm eq 0) {
     654        my $smallicon_displayItem_element = XML::Twig::Elt->new('displayItem');
     655        $smallicon_displayItem_element->set_att('name', 'smallicon');
     656        $smallicon_displayItem_element->set_att('lang', 'en');
     657        $smallicon_displayItem_element->set_text("${collection}sm.gif");
     658        $smallicon_displayItem_element->paste('last_child', $displayItemList);
     659       
     660       
     661    }
     662    open (OUT, ">$configfilename") or die "cannot open file $configfilename for output: $!";
     663    #select OUT;
     664    $twig->print( \*OUT );
     665    close OUT;
     666    return;
     667    }
     668
    602669    # update the collect.cfg configuration file (this will need
    603670    # to be changed when the config file format changes)
Note: See TracChangeset for help on using the changeset viewer.