line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::NewsML;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
111376
|
use vars qw ($VERSION);
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
149
|
|
4
|
|
|
|
|
|
|
$VERSION = '0.5';
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2665
|
use XML::LibXML;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new {
|
9
|
|
|
|
|
|
|
my $who = shift;
|
10
|
|
|
|
|
|
|
my %args = @_;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $class = ref $who || $who;
|
13
|
|
|
|
|
|
|
my $this = {
|
14
|
|
|
|
|
|
|
provider => $args{provider},
|
15
|
|
|
|
|
|
|
timezone => $args{timezone} || 'Z',
|
16
|
|
|
|
|
|
|
};
|
17
|
|
|
|
|
|
|
bless $this, $class;
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$this->{datetime} = $args{datetime} . $this->{timezone} || $this->datetime(),
|
20
|
|
|
|
|
|
|
$this->_create_doc();
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $this;
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub toString {
|
26
|
|
|
|
|
|
|
my $this = shift;
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $this->{document}->toString(1);
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub addNews {
|
32
|
|
|
|
|
|
|
my $this = shift;
|
33
|
|
|
|
|
|
|
my %args = @_;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$args{datetime} = $this->datetime() unless $args{datetime};
|
36
|
|
|
|
|
|
|
$args{id} = 1 unless $args{id};
|
37
|
|
|
|
|
|
|
$args{revision} = 1 unless $args{revision};
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $NewsItem = new XML::LibXML::Element('NewsItem');
|
40
|
|
|
|
|
|
|
$this->{root}->appendChild($NewsItem);
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $Identification = new XML::LibXML::Element('Identification');
|
43
|
|
|
|
|
|
|
$NewsItem->appendChild($Identification);
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $NewsIdentifier = new XML::LibXML::Element('NewsIdentifier');
|
46
|
|
|
|
|
|
|
$Identification->appendChild($NewsIdentifier);
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $ProviderId = new XML::LibXML::Element('ProviderId');
|
49
|
|
|
|
|
|
|
$ProviderId->appendText($this->{provider});
|
50
|
|
|
|
|
|
|
$NewsIdentifier->appendChild($ProviderId);
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $DateId = new XML::LibXML::Element('DateId');
|
53
|
|
|
|
|
|
|
$DateId->appendText(substr $args{datetime}, 0, 8);
|
54
|
|
|
|
|
|
|
$NewsIdentifier->appendChild($DateId);
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $NewsItemId = new XML::LibXML::Element('NewsItemId');
|
57
|
|
|
|
|
|
|
$NewsItemId->appendText($args{id});
|
58
|
|
|
|
|
|
|
$NewsIdentifier->appendChild($NewsItemId);
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $RevisionId = new XML::LibXML::Element('RevisionId');
|
61
|
|
|
|
|
|
|
$RevisionId->appendText($args{revision});
|
62
|
|
|
|
|
|
|
$RevisionId->setAttribute('PreviousRevision', '0');
|
63
|
|
|
|
|
|
|
$RevisionId->setAttribute('Update', 'N');
|
64
|
|
|
|
|
|
|
$NewsIdentifier->appendChild($RevisionId);
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $PublicIdentifier = new XML::LibXML::Element('PublicIdentifier');
|
67
|
|
|
|
|
|
|
$NewsIdentifier->appendChild($PublicIdentifier);
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $NewsManagement = new XML::LibXML::Element('NewsManagement');
|
71
|
|
|
|
|
|
|
$NewsItem->appendChild($NewsManagement);
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $NewsItemType = new XML::LibXML::Element('NewsItemType');
|
74
|
|
|
|
|
|
|
$NewsItemType->setAttribute('FormalName', 'News');
|
75
|
|
|
|
|
|
|
$NewsManagement->appendChild($NewsItemType);
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $FirstCreated = new XML::LibXML::Element('FirstCreated');
|
78
|
|
|
|
|
|
|
$FirstCreated->appendText($args{datetime} . $this->{timezone});
|
79
|
|
|
|
|
|
|
$NewsManagement->appendChild($FirstCreated);
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $ThisRevisionCreated = new XML::LibXML::Element('ThisRevisionCreated');
|
82
|
|
|
|
|
|
|
$ThisRevisionCreated->appendText($args{datetime} . $this->{timezone});
|
83
|
|
|
|
|
|
|
$NewsManagement->appendChild($ThisRevisionCreated);
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $Status = new XML::LibXML::Element('Status');
|
86
|
|
|
|
|
|
|
$Status->setAttribute('FormalName', 'Usable');
|
87
|
|
|
|
|
|
|
$NewsManagement->appendChild($Status);
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $NewsComponent = new XML::LibXML::Element('NewsComponent');
|
91
|
|
|
|
|
|
|
$NewsItem->appendChild($NewsComponent);
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $NewsLines = new XML::LibXML::Element('NewsLines');
|
94
|
|
|
|
|
|
|
$NewsComponent->appendChild($NewsLines);
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $HeadLine = new XML::LibXML::Element('HeadLine');
|
97
|
|
|
|
|
|
|
$HeadLine->appendText($args{title});
|
98
|
|
|
|
|
|
|
$NewsLines->appendChild($HeadLine);
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $KeywordLine = new XML::LibXML::Element('KeywordLine');
|
101
|
|
|
|
|
|
|
$KeywordLine->appendText($args{keywords});
|
102
|
|
|
|
|
|
|
$NewsLines->appendChild($KeywordLine);
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $ContentItem = new XML::LibXML::Element('ContentItem');
|
106
|
|
|
|
|
|
|
$NewsComponent->appendChild($ContentItem);
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $MediaType = new XML::LibXML::Element('MediaType');
|
109
|
|
|
|
|
|
|
$MediaType->setAttribute('FormalName', 'Text');
|
110
|
|
|
|
|
|
|
$ContentItem->appendChild($MediaType);
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $MimeType = new XML::LibXML::Element('MimeType');
|
113
|
|
|
|
|
|
|
$MimeType->setAttribute('FormalName', 'text/plain');
|
114
|
|
|
|
|
|
|
$ContentItem->appendChild($MimeType);
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $Format = new XML::LibXML::Element('Format');
|
117
|
|
|
|
|
|
|
$Format->setAttribute('FormalName', 'Text');
|
118
|
|
|
|
|
|
|
$ContentItem->appendChild($Format);
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $DataContent = new XML::LibXML::Element('DataContent');
|
121
|
|
|
|
|
|
|
$DataContent->appendText($args{content});
|
122
|
|
|
|
|
|
|
$ContentItem->appendChild($DataContent);
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
if ($args{image}) {
|
125
|
|
|
|
|
|
|
if (ref $args{image} eq 'ARRAY') {
|
126
|
|
|
|
|
|
|
foreach (@{$args{image}}) {
|
127
|
|
|
|
|
|
|
$NewsComponent->appendChild($this->_image_node($_));
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
else {
|
131
|
|
|
|
|
|
|
$NewsComponent->appendChild($this->_image_node($args{image}));
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _image_node {
|
137
|
|
|
|
|
|
|
my $this = shift;
|
138
|
|
|
|
|
|
|
my $uri = shift;
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $ContentItem = new XML::LibXML::Element('ContentItem');
|
141
|
|
|
|
|
|
|
$ContentItem->setAttribute('Href', $uri);
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $MediaType = new XML::LibXML::Element('MediaType');
|
144
|
|
|
|
|
|
|
$MediaType->setAttribute('FormalName', 'Photo');
|
145
|
|
|
|
|
|
|
$ContentItem->appendChild($MediaType);
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $MimeType = new XML::LibXML::Element('MimeType');
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my $mimetype = 'image/';
|
150
|
|
|
|
|
|
|
my $formalname;
|
151
|
|
|
|
|
|
|
if ($uri =~ /\.jpe?g$/i){$mimetype .= 'jpeg'; $formalname = 'JPEG Baseline';}
|
152
|
|
|
|
|
|
|
elsif ($uri =~ /\.gif$/i){$mimetype .= 'gif'; $formalname = 'GIF';}
|
153
|
|
|
|
|
|
|
elsif ($uri =~ /\.png$/i){$mimetype .= 'png'; $formalname = 'PNG';}
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$MimeType->setAttribute('FormalName', $mimetype);
|
156
|
|
|
|
|
|
|
$ContentItem->appendChild($MimeType);
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $Format = new XML::LibXML::Element('Format');
|
159
|
|
|
|
|
|
|
$Format->setAttribute('FormalName', $formalname);
|
160
|
|
|
|
|
|
|
$ContentItem->appendChild($Format);
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
return $ContentItem;
|
163
|
|
|
|
|
|
|
}
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _mime_type {
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _create_doc {
|
169
|
|
|
|
|
|
|
my $this = shift;
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$this->{document} = new XML::LibXML::Document;
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$this->{root} = new XML::LibXML::Element('NewsML');
|
174
|
|
|
|
|
|
|
$this->{document}->setDocumentElement($this->{root});
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$this->{root}->appendChild($this->_envelope_node());
|
177
|
|
|
|
|
|
|
}
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub datetime {
|
180
|
|
|
|
|
|
|
$this = shift;
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my ($sec, $min, $hour, $mday, $mon, $year);
|
183
|
|
|
|
|
|
|
if (@_) {
|
184
|
|
|
|
|
|
|
($sec, $min, $hour, $mday, $mon, $year) = @_;
|
185
|
|
|
|
|
|
|
}
|
186
|
|
|
|
|
|
|
else {
|
187
|
|
|
|
|
|
|
($sec, $min, $hour, $mday, $mon, $year) = localtime time;
|
188
|
|
|
|
|
|
|
$year += 1900;
|
189
|
|
|
|
|
|
|
$mon++;
|
190
|
|
|
|
|
|
|
}
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
return sprintf "%4i%02i%02iT%02i%02i%02i%s", $year, $mon, $mday, $hour, $min, $sec, $this->{timezone};
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _envelope_node {
|
196
|
|
|
|
|
|
|
my $this = shift;
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $NewsEnvelope = new XML::LibXML::Element('NewsEnvelope');
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $DateAndTime = new XML::LibXML::Element('DateAndTime');
|
201
|
|
|
|
|
|
|
$DateAndTime->appendText($this->{datetime});
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $Priority = new XML::LibXML::Element('Priority');
|
204
|
|
|
|
|
|
|
$Priority->setAttribute('FormalName', '1');
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
my $NewsProduct = new XML::LibXML::Element('NewsProduct');
|
207
|
|
|
|
|
|
|
$NewsProduct->setAttribute('FormalName', '1');
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$NewsEnvelope->appendChild($DateAndTime);
|
210
|
|
|
|
|
|
|
$NewsEnvelope->appendChild($Priority);
|
211
|
|
|
|
|
|
|
$NewsEnvelope->appendChild($NewsProduct);
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
return $NewsEnvelope;
|
214
|
|
|
|
|
|
|
}
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
1;
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
__END__
|