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