1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | BEGIN {
|
---|
4 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
5 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
6 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
7 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
8 | #unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
9 | # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
10 | }
|
---|
11 |
|
---|
12 | #use arcinfo;
|
---|
13 | use colcfg;
|
---|
14 | #use plugin;
|
---|
15 | use docprint;
|
---|
16 | use util;
|
---|
17 | use parsargv;
|
---|
18 | use FileHandle;
|
---|
19 | use XML::Writer;
|
---|
20 |
|
---|
21 | &main();
|
---|
22 | sub print_usage() {
|
---|
23 | print STDOUT "Usage: convert_coll_from_gs2.pl [options] coll-name\n";
|
---|
24 | print STDOUT "options:\n";
|
---|
25 |
|
---|
26 | }
|
---|
27 |
|
---|
28 | sub main {
|
---|
29 |
|
---|
30 | my ($collectdir);
|
---|
31 | # note that no defaults are passed for most options as they're set
|
---|
32 | # later (after we check the collect.cfg file)
|
---|
33 | if (!parsargv::parse(\@ARGV,
|
---|
34 | 'verbosity/\d+/', \$verbosity,
|
---|
35 | 'collectdir/.*/', \$collectdir,
|
---|
36 | 'faillog/.*/', \$faillog)) {
|
---|
37 | &print_usage();
|
---|
38 | die "\n";
|
---|
39 | }
|
---|
40 |
|
---|
41 | # get and check the collection name
|
---|
42 | if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
|
---|
43 | &print_usage();
|
---|
44 | die "\n";
|
---|
45 | }
|
---|
46 |
|
---|
47 | $collconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
|
---|
48 | my $collectcfg;
|
---|
49 | if (-e $collconfigfilename) {
|
---|
50 | $collectcfg = &colcfg::read_collect_cfg ($collconfigfilename);
|
---|
51 |
|
---|
52 | }
|
---|
53 | $buildconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "build.cfg");
|
---|
54 | my $buildcfg;
|
---|
55 | if (-e $buildconfigfilename) {
|
---|
56 | $buildcfg = &colcfg::read_build_cfg ($buildconfigfilename);
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 | my $outfile = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "buildConfig.xml");
|
---|
61 | if (-e $outfile) {
|
---|
62 | print STDOUT "buildConfig file already exists! overwriting it!\n";
|
---|
63 |
|
---|
64 | }
|
---|
65 |
|
---|
66 | my $buildtype;
|
---|
67 | if (defined $collectcfg->{'buildtype'}) {
|
---|
68 | $buildtype = $collectcfg->{'buildtype'};
|
---|
69 | } else {
|
---|
70 | $buildtype = 'mg';
|
---|
71 | }
|
---|
72 |
|
---|
73 | my $output = new IO::File(">$outfile");
|
---|
74 | my $writer = new XML::Writer(OUTPUT => $output);
|
---|
75 |
|
---|
76 | $writer->startTag('buildConfig');
|
---|
77 |
|
---|
78 | if (defined $collectcfg->{'collectionmeta'}) {
|
---|
79 | my $collmeta = $collectcfg->{'collectionmeta'};
|
---|
80 | $writer->startTag('metadataList');
|
---|
81 | #just do collname for now
|
---|
82 | my $collnames = $collmeta->{'collectionname'};
|
---|
83 | foreach $lang (keys %$collnames) {
|
---|
84 | my $short_lang;
|
---|
85 | if ($lang eq 'default') {
|
---|
86 | $short_lang = 'en';
|
---|
87 | } else {
|
---|
88 | ($short_lang) = $lang =~ /^\[l=(..)\]/;
|
---|
89 | }
|
---|
90 | $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collName');
|
---|
91 | $writer->characters($collnames->{$lang});
|
---|
92 | $writer->endTag('metadata');
|
---|
93 | }
|
---|
94 | my $collabouts = $collmeta->{'collectionextra'};
|
---|
95 | foreach $lang (keys %$collabouts) {
|
---|
96 | my $short_lang;
|
---|
97 | if ($lang eq 'default') {
|
---|
98 | $short_lang = 'en';
|
---|
99 | } else {
|
---|
100 | ($short_lang) = $lang =~ /^\[l=(..)\]/;
|
---|
101 | }
|
---|
102 | $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collDescript');
|
---|
103 | $writer->characters($collabouts->{$lang});
|
---|
104 | $writer->endTag('metadata');
|
---|
105 | }
|
---|
106 | $writer->endTag('metadataList');
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | #indexes
|
---|
111 | my $indexmap = {};
|
---|
112 | if (defined $buildcfg->{'indexmap'}) {
|
---|
113 | $indexmap_t = $buildcfg->{'indexmap'};
|
---|
114 | foreach $i (@$indexmap_t) {
|
---|
115 | my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
|
---|
116 | $indexmap->{$k} = $v;
|
---|
117 | }
|
---|
118 | } else {
|
---|
119 | print STDERR "indexmap not defined";
|
---|
120 | }
|
---|
121 | my $defaultindex;
|
---|
122 | if (defined $collectcfg->{'defaultindex'}) {
|
---|
123 | $defaultindex = $collectcfg->{'defaultindex'};
|
---|
124 | } else {
|
---|
125 | print STDERR "defaultindex not defined";
|
---|
126 | }
|
---|
127 | $defaultindex = $indexmap->{$defaultindex};
|
---|
128 |
|
---|
129 |
|
---|
130 | $writer->startTag('serviceRackList');
|
---|
131 |
|
---|
132 | if ($buildtype =~ /^mg/) {
|
---|
133 | if ($buildtype eq 'mgpp') {
|
---|
134 | #for each level
|
---|
135 | my @levels = ('Document');
|
---|
136 | my $defaultlevel = 'Document';
|
---|
137 | if (defined $collectcfg->{'levels'}) {
|
---|
138 | push @levels, @{$collectcfg->{'levels'}};
|
---|
139 |
|
---|
140 | foreach $l(@levels){
|
---|
141 | $defaultlevel = 'Section' if $l eq 'Section';
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | $writer->startTag('serviceRack', 'name'=>'GS2MGPPRetrieve');
|
---|
146 | $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
|
---|
147 | $writer->endTag('serviceRack');
|
---|
148 |
|
---|
149 | $writer->startTag('serviceRack', 'name'=>'GS2MGPPSearch');
|
---|
150 | $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
|
---|
151 | $writer->startTag('levelList');
|
---|
152 | foreach $level (@levels) {
|
---|
153 | $writer->emptyTag('level', 'name'=>$level);
|
---|
154 | }
|
---|
155 | $writer->endTag('levelList');
|
---|
156 |
|
---|
157 | #fieldlist
|
---|
158 |
|
---|
159 | } elsif ($buildtype eq 'mg') {
|
---|
160 | $writer->startTag('serviceRack', 'name'=>'GS2MGRetrieve');
|
---|
161 | $writer->emptyTag('defaultIndex', 'name'=>$defaultindex);
|
---|
162 | $writer->endTag('serviceRack');
|
---|
163 | $writer->startTag('serviceRack', 'name'=>'GS2MGSearch');
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | $writer->emptyTag('defaultIndex', 'name'=>$defaultindex);
|
---|
168 | $writer->startTag('indexList');
|
---|
169 | #for each index
|
---|
170 | foreach $i (keys %$indexmap) {
|
---|
171 | $index = $indexmap->{$i};
|
---|
172 | $writer->emptyTag('index', 'name'=>$index);
|
---|
173 | }
|
---|
174 | $writer->endTag('indexList');
|
---|
175 |
|
---|
176 | $writer->endTag('serviceRack');
|
---|
177 | }
|
---|
178 |
|
---|
179 | #my $classifiers = {};
|
---|
180 | my $count = 1;
|
---|
181 | my $phind = 0;
|
---|
182 | my $started_classifiers = 0;
|
---|
183 | if (defined $collectcfg->{'classify'}) {
|
---|
184 | my $classifiers = $collectcfg->{'classify'};
|
---|
185 | foreach $cl (@$classifiers) {
|
---|
186 | print STDERR "cl=$cl\n";
|
---|
187 | $name = "CL$count";
|
---|
188 | $count++;
|
---|
189 | my ($classname) = @$cl[0];
|
---|
190 | if ($classname eq "Phind") {
|
---|
191 | $phind=1;
|
---|
192 | next;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if (not $started_classifiers) {
|
---|
196 | $writer->startTag('serviceRack', 'name'=>'GS2Browse');
|
---|
197 | $writer->startTag('classifierList');
|
---|
198 | $started_classifiers = 1;
|
---|
199 | }
|
---|
200 | my $title = ''; #use buttonname if defined, otherwise use metadata
|
---|
201 |
|
---|
202 | for ($i=0; $i<scalar(@$cl); $i++) {
|
---|
203 | $arg = @$cl[$i];
|
---|
204 | if ($arg eq "-buttonname") {
|
---|
205 | $title = @$cl[$i+1];
|
---|
206 | last;
|
---|
207 | }
|
---|
208 | if ($arg eq "-metadata") {
|
---|
209 | $title = @$cl[$i+1];
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | $writer->startTag('classifier', 'name'=>$name);
|
---|
214 | $writer->startTag('metadataList');
|
---|
215 | #title meta
|
---|
216 | $writer->startTag('metadata', 'name'=>'Title');
|
---|
217 | $writer->characters($title);
|
---|
218 | $writer->endTag('metadata');
|
---|
219 | $writer->endTag('metadataList');
|
---|
220 | $writer->endTag('classifier');
|
---|
221 |
|
---|
222 |
|
---|
223 | } #foreach classifier
|
---|
224 | if ($started_classifiers) {
|
---|
225 | # end the classifiers
|
---|
226 | $writer->endTag('classifierList');
|
---|
227 | $writer->endTag('serviceRack');
|
---|
228 | }
|
---|
229 | if ($phind) {
|
---|
230 | # if phind classifier
|
---|
231 | $writer->emptyTag('serviceRack', 'name'=>'PhindPhraseBrowse');
|
---|
232 | }
|
---|
233 |
|
---|
234 | }
|
---|
235 | $writer->endTag('serviceRackList');
|
---|
236 | $writer->endTag('buildConfig');
|
---|
237 | $writer->end();
|
---|
238 | $output->close();
|
---|
239 |
|
---|
240 | }
|
---|
241 |
|
---|
242 | #$writer->startTag('');
|
---|
243 | #$writer->endTag('');
|
---|
244 | #$writer->characters();
|
---|
245 | #$writer->emptyTag('');
|
---|
246 |
|
---|
247 | 1;
|
---|