8 use Data::Dump qw(dump);
10 my $odt_file = 'contributions.odt';
12 my $xs = XML::Simple->new();
14 use OpenOffice::OODoc 2.101;
15 my $doc = odfDocument(file => $odt_file, create => 'text');
22 family => 'paragraph',
27 'fo:text-align' => 'justify'
33 #foreach my $file ( glob 'contributions/*.xml' ) {
36 open(my $fh, '<:encoding(utf-8)', 'contributions/all.xml');
43 warn "---xml---", dump($xml), "---/xml---\n";
45 foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
49 $xml = '<?xml' . $xml;
53 $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
55 warn "# abstract = ", dump($abstract);
57 my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
58 warn "# $id abstract = ", dump($abstract);
60 foreach my $k (qw( ContributionType )) {
61 push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id;
64 if ( $abstract->{'ContributionType'}->[0] eq 'Symposium proposal' ) {
65 my $t = $abstract->{Title}->[0];
66 push @{ $stat->{_symposium}->{ $t } }, -$id;
69 if ( my $s = $abstract->{Symposium_title} ) {
71 push @{ $stat->{_symposium}->{$s} }, $id;
74 if ( exists $abstract->{PrimaryAuthor}->[0]->{FamilyName} ) {
75 $stat->{_order_by}->{$id} = $abstract->{PrimaryAuthor}->[0]->{FamilyName}->[0];
78 $abstracts->{ $id } = $abstract;
82 #warn "# stat = ",dump($stat);
87 warn "# enc in ",Encode::is_utf8($b), dump($b);
89 # $b = Encode::decode('iso-8859-1',$b); # XXX doesn't work!
91 # Encode::from_to($b, 'iso-8859-1','utf-8');
92 # Encode::_utf8_on($b);
94 Encode::_utf8_off($b);
96 warn "# enc out ",Encode::is_utf8($b), dump($b);
101 #return 'FIXME ref ' . dump($l) if ref $l;
102 return undef if ref $l;
103 return enc($l) if $l =~ m/([\x{80}-\x{ff}])/;
110 my $abstract = $abstracts->{$id} || die "no $id in abstracts ",dump($abstracts);
112 my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
113 $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
115 foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
116 $doc->appendParagraph(text => join(' ',
117 # map { s/([\x{80}-\x{ff}])/enc($1)/eg && warn "# PrimaryAuthor Id: $id ",Encode::is_utf8($_), dump($_),"\n"; $_ }
118 map { l1($a->{$_}->[0]) } qw( FirstName FamilyName )
119 ), style => 'Heading 2');
120 $doc->appendParagraph(text => join(' ',
121 map { l1($a->{$_}->[0]) } qw( Affiliation )
122 ), style => 'Heading 3');
123 push @{ $stat->{_Affiliation}->{ $a->{Affiliation}->[0] } }, $id;
126 # $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
127 foreach my $p ( split(/[\n\r]+/, $abstract->{Content}->[0] ) ) {
128 $doc->appendParagraph(text => $p, style => 'Abstract');
131 $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
133 $doc->appendParagraph(text => "\nContributionType: " . $abstract->{ContributionType}->[0], style => 'Quotations');
135 $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
137 warn "# added $id to document\n";
140 #foreach my $id ( keys %$abstracts ) {
144 foreach my $symposium ( keys %{ $stat->{'_symposium'} } ) {
146 my $t = $doc->appendParagraph(text => $symposium, style => 'Title');
147 $doc->setPageBreak( $t, position => 'before', style => 'Title');
148 $doc->appendParagraph(text => 'Symposium', style => 'Subtitle');
150 my @symposium_ids = sort @{ $stat->{'_symposium'}->{$symposium} };
151 warn "## [$symposium] symposium_ids ", dump( @symposium_ids );
153 my $proposal_id = shift @symposium_ids;
154 if ( $proposal_id < 0 ) {
155 $proposal_id = abs( $proposal_id );
157 warn "ERROR: symposium [$symposium] doesn't have proposal!";
160 # @symposium_ids = sort { $stat->{_order_by}->{$a} cmp $stat->{_order_by}->{$b} } @symposium_ids;
161 @symposium_ids = sort @symposium_ids;
162 unshift @symposium_ids, $proposal_id;
164 $stat->{_order_symposium}->{$symposium} = [ @symposium_ids ];
166 foreach my $id ( @symposium_ids ) {
172 foreach my $type ( 'Oral presentation', 'Poster presentation' ) {
174 my $t = $doc->appendParagraph(text => $type, style => 'Title');
175 $doc->setPageBreak( $t, position => 'before', style => 'Title');
177 my @order = sort { lc $stat->{_order_by}->{$a} cmp lc $stat->{_order_by}->{$b} }
178 @{ $stat->{'ContributionType'}->{$type} };
180 $stat->{ '_order_' . $type } = [ @order ];
182 foreach my $id ( @order ) {
188 warn "# stat = ",dump($stat);
193 open(my $fh, '>', 'affiliation.csv');
194 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
195 print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
199 "Symposium proposal" => 12,
200 "Symposium abstract" => 52,
201 "Oral presentation" => 141,
202 "Poster presentation" => 71,