/[suikacvs]/messaging/manakai/lib/Message/DOM/Atom/AtomElement.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/Atom/AtomElement.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun Jul 15 05:18:46 2007 UTC (19 years ago) by wakaba
Branch: MAIN
++ manakai/lib/Message/DOM/Atom/ChangeLog	15 Jul 2007 05:16:12 -0000
	* AtomElement.pm: New module.

2007-07-15  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	15 Jul 2007 05:18:34 -0000
	* DOMConfiguration.pm: Configuration parameter |create-child-element|
	implemented.

	* DOMElement.pm (create_element_ns): Support for Atom
	subclasses.

	* DOMImplementation.pm (DOMImplementation): Now
	implements the |AtomDOMImplementation| interface.
	($HasFeature): Features |atom| and |atomthreading| are added.

	* NodeList.pm (StaticNodeList): Implemented.

2007-07-15  Wakaba  <wakaba@suika.fam.cx>

	* Atom/: New directory.

2007-07-15  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package Message::DOM::Atom::AtomElement;
2     use strict;
3     our $VERSION=do{my @r=(q$Revision: 1.9 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4     push our @ISA, 'Message::DOM::Element';
5     require Message::DOM::Element;
6    
7     my $ATOM_NS = q<http://www.w3.org/2005/Atom>;
8     my $CREATE_CHILD_URI = q<http://suika.fam.cx/www/2006/dom-config/create-child-element>;
9    
10     sub AUTOLOAD {
11     my $method_name = our $AUTOLOAD;
12     return if $method_name =~ /::DESTROY$/;
13    
14     if (my $ln = { ## Reflecting the string value of a content attribute
15     'Message::DOM::Atom::AtomElement::AtomCategoryElement::label' => 'label',
16     'Message::DOM::Atom::AtomElement::AtomCategoryElement::term' => 'term',
17     'Message::DOM::Atom::AtomElement::AtomGeneratorElement::version' => 'version',
18     'Message::DOM::Atom::AtomElement::AtomLinkElement::hreflang' => 'hreflang',
19     'Message::DOM::Atom::AtomElement::AtomLinkElement::title' => 'title',
20     'Message::DOM::Atom::AtomElement::AtomLinkElement::length' => 'length',
21     }->{$method_name}) {
22     no strict 'refs';
23     eval qq{
24     sub $method_name (\$;\$) {
25     local \$Error::Depth = \$Error::Depth + 1;
26    
27     if (\@_ > 1) {
28     if (defined \$_[1]) {
29     \$_[0]->set_attribute_ns (undef, '$ln', ''.\$_[1]);
30     } else {
31     \$_[0]->remove_attribute_ns (undef, '$ln');
32     }
33     return unless defined wantarray;
34     }
35    
36     return \$_[0]->get_attribute_ns (undef, '$ln');
37     }
38     };
39     goto &{ $AUTOLOAD };
40     } elsif (my $ln = { ## Reflecting the URI value of a content attribute
41     'Message::DOM::Atom::AtomElement::AtomContentElement::src' => 'src',
42     'Message::DOM::Atom::AtomElement::AtomCategoryElement::scheme' => 'scheme',
43     'Message::DOM::Atom::AtomElement::AtomGeneratorElement::uri' => 'uri',
44     'Message::DOM::Atom::AtomElement::AtomLinkElement::href' => 'href',
45     }->{$method_name}) {
46     no strict 'refs';
47     eval qq{
48     sub $method_name (\$;\$) {
49     local \$Error::Depth = \$Error::Depth + 1;
50    
51     if (\@_ > 1) {
52     if (defined \$_[1]) {
53     \$_[0]->set_attribute_ns (undef, '$ln', ''.\$_[1]);
54     } else {
55     \$_[0]->remove_attribute_ns (undef, '$ln');
56     }
57     return unless defined wantarray;
58     }
59    
60     my \$v = \$_[0]->get_attribute_ns (undef, '$ln');
61     if (defined \$v) {
62     my \$base = \$_[0]->base_uri;
63     if (defined \$base) {
64     return \$_[0]->owner_document->implementation
65     ->create_uri_reference (\$v)
66     ->get_absolute_reference (\$base)->uri_reference;
67     } else {
68     return \$v;
69     }
70     } else {
71     return undef;
72     }
73     }
74     };
75     goto &{ $AUTOLOAD };
76     } elsif (my $ln = { ## Reflecting the string value of a child element
77     'Message::DOM::Atom::AtomElement::AtomPersonConstruct::email' => 'email',
78     'Message::DOM::Atom::AtomElement::AtomPersonConstruct::name' => 'name',
79     'Message::DOM::Atom::AtomElement::AtomFeedElement::id' => 'id',
80     'Message::DOM::Atom::AtomElement::AtomEntryElement::id' => 'id',
81     'Message::DOM::Atom::AtomElement::AtomSourceElement::id' => 'id',
82     }->{$method_name}) {
83     no strict 'refs';
84     eval qq{
85     sub $method_name (\$;\$) {
86     no warnings 'uninitialized';
87     local \$Error::Depth = \$Error::Depth + 1;
88    
89     if (\@_ > 1) {
90     if (defined \$_[0]) {
91     my \$target;
92     E: {
93     for my \$cl (@{\$_[0]->child_nodes}) {
94     if (\$cl->node_type == 1 and # ELEMENT_NODE
95     \$cl->manakai_local_name eq '$ln' and
96     \$cl->namespace_uri eq \$ATOM_NS) {
97     \$target = \$cl;
98     last E;
99     }
100     }
101    
102     \$target = \$_[0]->owner_document->create_element_ns
103     (\$ATOM_NS, '$ln');
104     \$_[0]->append_child (\$target);
105     } # E
106    
107     return \$target->text_content (\$_[0]);
108     } else {
109     my \@remove;
110     for my \$cl (@{\$_[0]->child_nodes}) {
111     if (\$cl->node_type == 1 and # ELEMENT_NODE
112     \$cl->manakai_local_name eq '$ln' and
113     \$cl->namespace_uri eq \$ATOM_NS) {
114     push \@remove, \$cl;
115     }
116     }
117    
118     \$_[0]->remove_child (\$_) for \@remove;
119     return undef;
120     }
121     }
122    
123     for my \$cl (@{\$_[0]->child_nodes}) {
124     if (\$cl->node_type == 1 and # ELEMENT_NODE
125     \$cl->manakai_local_name eq '$ln' and
126     \$cl->namespace_uri eq \$ATOM_NS) {
127     return \$cl->text_content;
128     }
129     }
130    
131     return undef;
132     }
133     };
134     goto &{ $AUTOLOAD };
135     } elsif (my $ln = { ## Reflecting the URI value of a child element
136     'Message::DOM::Atom::AtomElement::AtomPersonConstruct::uri' => 'uri',
137     'Message::DOM::Atom::AtomElement::AtomFeedElement::icon' => 'icon',
138     'Message::DOM::Atom::AtomElement::AtomFeedElement::logo' => 'logo',
139     'Message::DOM::Atom::AtomElement::AtomSourceElement::icon' => 'icon',
140     'Message::DOM::Atom::AtomElement::AtomSourceElement::logo' => 'logo',
141     }->{$method_name}) {
142     no strict 'refs';
143     eval qq{
144     sub $method_name (\$;\$) {
145     no warnings 'uninitialized';
146     local \$Error::Depth = \$Error::Depth + 1;
147    
148     if (\@_ > 1) {
149     if (defined \$_[0]) {
150     my \$target;
151     E: {
152     for my \$cl (@{\$_[0]->child_nodes}) {
153     if (\$cl->node_type == 1 and # ELEMENT_NODE
154     \$cl->manakai_local_name eq '$ln' and
155     \$cl->namespace_uri eq \$ATOM_NS) {
156     \$target = \$cl;
157     last E;
158     }
159     }
160    
161     \$target = \$_[0]->owner_document->create_element_ns
162     (\$ATOM_NS, '$ln');
163     \$_[0]->append_child (\$target);
164     } # E
165    
166     \$target->text_content (\$_[0]);
167     return unless defined wantarray;
168     } else {
169     my \@remove;
170     for my \$cl (@{\$_[0]->child_nodes}) {
171     if (\$cl->node_type == 1 and # ELEMENT_NODE
172     \$cl->manakai_local_name eq '$ln' and
173     \$cl->namespace_uri eq \$ATOM_NS) {
174     push \@remove, \$cl;
175     }
176     }
177    
178     \$_[0]->remove_child (\$_) for \@remove;
179     return undef;
180     }
181     }
182    
183     for my \$cl (@{\$_[0]->child_nodes}) {
184     if (\$cl->node_type == 1 and # ELEMENT_NODE
185     \$cl->manakai_local_name eq '$ln' and
186     \$cl->namespace_uri eq \$ATOM_NS) {
187     my \$base = \$cl->base_uri;
188     if (defined \$base) {
189     return \$cl->owner_document->implementation
190     ->create_uri_reference (\$cl->text_content)
191     ->get_absolute_reference (\$base)->uri_reference;
192     } else {
193     return \$cl->text_content;
194     }
195     }
196     }
197    
198     return undef;
199     }
200     };
201     goto &{ $AUTOLOAD };
202     } elsif (my $ln = { ## Return the child element
203     'Message::DOM::Atom::AtomElement::AtomPersonConstruct::name_element' => 'name',
204     'Message::DOM::Atom::AtomElement::AtomFeedElement::generator_element' => 'generator',
205     'Message::DOM::Atom::AtomElement::AtomFeedElement::rights_element' => 'rights',
206     'Message::DOM::Atom::AtomElement::AtomFeedElement::subtitle_element' => 'subtitle',
207     'Message::DOM::Atom::AtomElement::AtomFeedElement::title_element' => 'title',
208     'Message::DOM::Atom::AtomElement::AtomFeedElement::updated_element' => 'updated',
209     'Message::DOM::Atom::AtomElement::AtomEntryElement::content_element' => 'content',
210     'Message::DOM::Atom::AtomElement::AtomEntryElement::published_element' => 'published',
211     'Message::DOM::Atom::AtomElement::AtomEntryElement::rights_element' => 'rights',
212     'Message::DOM::Atom::AtomElement::AtomEntryElement::source_element' => 'source',
213     'Message::DOM::Atom::AtomElement::AtomEntryElement::summary_element' => 'summary',
214     'Message::DOM::Atom::AtomElement::AtomEntryElement::title_element' => 'title',
215     'Message::DOM::Atom::AtomElement::AtomEntryElement::updated_element' => 'updated',
216     'Message::DOM::Atom::AtomElement::AtomSourceElement::generator_element' => 'generator',
217     'Message::DOM::Atom::AtomElement::AtomSourceElement::rights_element' => 'rights',
218     'Message::DOM::Atom::AtomElement::AtomSourceElement::subtitle_element' => 'subtitle',
219     'Message::DOM::Atom::AtomElement::AtomSourceElement::title_element' => 'title',
220     'Message::DOM::Atom::AtomElement::AtomSourceElement::updated_element' => 'updated',
221     }->{$method_name}) {
222     no strict 'refs';
223     eval qq{
224     sub $method_name (\$) {
225     no warnings 'uninitialized';
226     local \$Error::Depth = \$Error::Depth + 1;
227    
228     for my \$el (@{\$_[0]->child_nodes}) {
229     if (\$el->node_type == 1 and # ELEMENT_NODE
230     \$el->manakai_local_name eq '$ln' and
231     \$el->namespace_uri eq \$ATOM_NS) {
232     return \$el;
233     }
234     }
235    
236     my \$od = \$_[0]->owner_document;
237     if (\$od->dom_config->get_parameter (\$CREATE_CHILD_URI)) {
238     return \$_[0]->append_child
239     (\$od->create_element_ns (\$ATOM_NS, '$ln'));
240     } else {
241     return undef;
242     }
243     }
244     };
245     goto &{ $AUTOLOAD };
246     } elsif (my $ln = { ## Return a child element list
247     'Message::DOM::Atom::AtomElement::AtomFeedElement::author_elements' => 'author',
248     'Message::DOM::Atom::AtomElement::AtomFeedElement::category_elements' => 'category',
249     'Message::DOM::Atom::AtomElement::AtomFeedElement::contributor_elements' => 'contributor',
250     'Message::DOM::Atom::AtomElement::AtomFeedElement::entry_elements' => 'entry',
251     'Message::DOM::Atom::AtomElement::AtomFeedElement::link_elements' => 'link',
252     'Message::DOM::Atom::AtomElement::AtomEntryElement::author_elements' => 'author',
253     'Message::DOM::Atom::AtomElement::AtomEntryElement::category_elements' => 'category',
254     'Message::DOM::Atom::AtomElement::AtomEntryElement::contributor_elements' => 'contributor',
255     'Message::DOM::Atom::AtomElement::AtomEntryElement::link_elements' => 'link',
256     'Message::DOM::Atom::AtomElement::AtomSourceElement::author_elements' => 'author',
257     'Message::DOM::Atom::AtomElement::AtomSourceElement::category_elements' => 'category',
258     'Message::DOM::Atom::AtomElement::AtomSourceElement::contributor_elements' => 'contributor',
259     'Message::DOM::Atom::AtomElement::AtomSourceElement::link_elements' => 'link',
260     }->{$method_name}) {
261     no strict 'refs';
262     eval qq{
263     sub $method_name (\$) {
264     local \$Error::Depth = \$Error::Depth + 1;
265     no warnings 'uninitialized';
266     my \$r = [];
267     for my \$el (\@{\$_[0]->child_nodes}) {
268     if (\$el->node_type == 1 and # ELEMENT_NODE
269     \$el->manakai_local_name eq '$ln' and
270     \$el->namespace_uri eq \$ATOM_NS) {
271     push \@\$r, \$el;
272     }
273     }
274     require Message::DOM::NodeList;
275     return bless \$r, 'Message::DOM::NodeList::StaticNodeList';
276     }
277     };
278     goto &{ $AUTOLOAD };
279     } else {
280     require Carp;
281     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
282     }
283     } # AUTOLOAD
284    
285     package Message::DOM::Atom::AtomElement::AtomTextConstruct;
286     push our @ISA, 'Message::DOM::Atom::AtomElement';
287    
288     sub container ($) {
289     local $Error::Depth = $Error::Depth + 1;
290    
291     my $type = $_[0]->type;
292     if ($type eq 'xhtml') {
293     ## "Return the child element"
294     no warnings 'uninitialized';
295     for my $el (@{$_[0]->child_nodes}) {
296     if ($el->node_type == 1 and # ELEMENT_NODE
297     $el->manakai_local_name eq 'div' and
298     $el->namespace_uri eq q<http://www.w3.org/1999/xhtml>) {
299     return $el;
300     }
301     }
302    
303     my $od = $_[0]->owner_document;
304     if ($od->dom_config->get_parameter ($CREATE_CHILD_URI)) {
305     return $_[0]->append_child
306     ($od->create_element_ns (q<http://www.w3.org/1999/xhtml>, 'div'));
307     } else {
308     return undef;
309     }
310     } else {
311     return $_[0];
312     }
313     } # container
314    
315     sub type ($;$) {
316     local $Error::Depth = $Error::Depth + 1;
317    
318     if (@_ > 1) {
319     if (defined $_[1]) {
320     $_[0]->set_attribute_ns (undef, 'type', ''.$_[1]);
321     } else {
322     $_[0]->remove_attribute_ns (undef, 'type');
323     }
324    
325     return unless defined wantarray;
326     }
327    
328     my $v = $_[0]->get_attribute_ns (undef, 'type');
329     return defined $v ? $v : 'text';
330     } # type
331    
332     package Message::DOM::Atom::AtomElement::AtomPersonConstruct;
333     push our @ISA, 'Message::DOM::Atom::AtomElement';
334    
335     sub email ($;$);
336    
337     sub name ($;$);
338    
339     sub name_element ($);
340    
341     sub uri ($;$);
342    
343     package Message::DOM::AtomElement::AtomDateConstruct;
344     push our @ISA, 'Message::DOM::Atom::AtomElement';
345    
346     ## TODO: Use HTML5 algorithm
347     sub value ($;$) {
348     local $Error::Depth = $Error::Depth + 1;
349    
350     if (@_ > 1) {
351     my $given = 0+($_[1] or 0);
352     my @value = gmtime (int ($given / 1));
353     my $value = sprintf '%04d-%02d-%02dT%02d:%02d:%02d',
354     $value[5] + 1900, $value[4] + 1,
355     $value[3], $value[2], $value[1], $value[0];
356     my $f = $given % 1;
357     $value .= substr (''.$f, 1) if $f;
358     $value .= 'Z';
359     $_[0]->text_content ($value);
360     return unless defined wantarray;
361     }
362    
363     my $value = $_[0]->text_content;
364     if ($value =~ /\A(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)(\.\d+)?
365     (?:Z|([+-]\d+):(\d+))\z/x) {
366     require Time::Local;
367     my $r = Time::Local::timegm_nocheck
368     ($6, defined $8 ? $8 > 0 ? $5 - $9 : $5 + $9 : $5,
369     defined $8 ? $4 - $8 : $4, $3, $2-1, $1-1900);
370     $r += "0$7" if defined $7;
371     return $r;
372     } else {
373     return 0;
374     }
375     } # value
376    
377     package Message::DOM::Atom::AtomElement::AtomFeedElement;
378     push our @ISA, 'Message::DOM::Atom::AtomElement';
379    
380     sub add_new_entry ($$;$$) {
381     local $Error::Depth = $Error::Depth + 1;
382    
383     my $od = $_[0]->owner_document;
384     my $r = $od->create_element_ns ($ATOM_NS, 'entry');
385     $r->manakai_language (''.$_[3]) if defined $_[3];
386     $r->id (''.$_[1]);
387    
388     my $titlee = $od->create_element_ns ($ATOM_NS, 'title');
389     $titlee->text_content (defined $_[2] ? ''.$_[2] : '');
390     $r->append_child ($titlee);
391    
392     my $updatede = $od->create_element_ns ($ATOM_NS, 'updated');
393     $updatede->value (scalar time);
394     $r->append_child ($updatede);
395    
396     return $_[0]->append_child ($r);
397     } # add_new_entry
398    
399     sub author_elements ($);
400    
401     sub category_elements ($);
402    
403     sub contributor_elements ($);
404    
405     sub entry_elements ($);
406    
407     sub generator_element ($);
408    
409     sub get_entry_element_by_id ($$) {
410     my $id = ''.$_[1];
411     no warnings 'uninitialized';
412     local $Error::Depth = $Error::Depth + 1;
413    
414     for my $cn (@{$_[0]->child_nodes}) {
415     if ($cn->node_type == 1 and # ELEMENT_NODE
416     $cn->manakai_local_name eq 'entry' and
417     $cn->namespace_uri eq $ATOM_NS) {
418     if ($cn->id eq $id) {
419     return $cn;
420     }
421     }
422     }
423     return undef;
424     } # get_entry_element_by_id
425    
426     sub icon ($;$);
427    
428     sub id ($;$);
429    
430     sub link_elements ($);
431    
432     sub logo ($;$);
433    
434     sub rights_element ($);
435    
436     sub subtitle_element ($);
437    
438     sub title_element ($);
439    
440     sub updated_element ($);
441    
442     package Message::DOM::Atom::AtomElement::AtomEntryElement;
443     push our @ISA, 'Message::DOM::Atom::AtomElement';
444    
445     sub author_elements ($);
446    
447     sub entry_author_elements ($) {
448     no warnings 'uninitialized';
449     local $Error::Depth = $Error::Depth + 1;
450    
451     require Message::DOM::NodeList;
452     my $r = bless [], 'Message::DOM::NodeList::StaticNodeList';
453     my $source;
454     for my $cn (@{$_[0]->child_nodes}) {
455     if ($cn->node_type == 1 and # ELEMENT_NODE
456     $cn->namespace_uri eq $ATOM_NS) {
457     my $ln = $cn->manakai_local_name;
458     if ($ln eq 'author') {
459     push @$r, $cn;
460     } elsif ($cn->manakai_local_name eq 'source') {
461     $source = $cn;
462     }
463     }
464     }
465     return $r unless @$r == 0;
466    
467     if (defined $source) {
468     $r = $source->author_elements;
469     return $r unless @$r == 0;
470     }
471    
472     my $parent = $_[0]->parent_node;
473     if (defined $parent and
474     $parent->node_type == 1 and # ELEMENT_NODE
475     $parent->manakai_local_name eq 'feed' and
476     $parent->namespace_uri eq $ATOM_NS) {
477     return $parent->author_elements;
478     }
479    
480     return $r;
481     } # entry_author_elements
482    
483     sub category_elements ($);
484    
485     sub content_element ($);
486    
487     sub contributor_elements ($);
488    
489     sub id ($;$);
490    
491     sub link_elements ($);
492    
493     sub published_element ($);
494    
495     sub rights_element ($);
496    
497     sub entry_rights_element ($) {
498     no warnings 'uninitialized';
499     local $Error::Depth = $Error::Depth + 1;
500    
501     for my $cn (@{$_[0]->child_nodes}) {
502     if ($cn->node_type == 1 and # ELEMENT_NODE
503     $cn->manakai_local_name eq 'rights' and
504     $cn->namespace_uri eq $ATOM_NS) {
505     return $cn;
506     }
507     }
508    
509     my $parent = $_[0]->parent_node;
510     if (defined $parent and
511     $parent->node_type == 1 and # ELEMENT_NODE
512     $parent->manakai_local_name eq 'feed' and
513     $parent->namespace_uri eq $ATOM_NS) {
514     for my $cn (@{$parent->child_nodes}) {
515     if ($cn->node_type == 1 and # ELEMENT_NODE
516     $cn->manakai_local_name eq 'rights' and
517     $cn->namespace_uri eq $ATOM_NS) {
518     return $cn;
519     }
520     }
521     }
522    
523     my $od = $_[0]->owner_document;
524     if ($od->dom_config->get_parameter ($CREATE_CHILD_URI)) {
525     return $_[0]->append_child ($od->create_element_ns ($ATOM_NS, 'rights'));
526     }
527     } # entry_rights_element
528    
529     sub source_element ($);
530    
531     sub summary_element ($);
532    
533     sub title_element ($);
534    
535     sub updated_element ($);
536    
537     package Message::DOM::Atom::AtomElement::AtomContentElement;
538     push our @ISA, 'Message::DOM::Atom::AtomElement';
539    
540     sub container ($) {
541     local $Error::Depth = $Error::Depth + 1;
542    
543     my $type = $_[0]->type;
544     if ($type eq 'xhtml') {
545     ## "Return the child element"
546     no warnings 'uninitialized';
547     for my $el (@{$_[0]->child_nodes}) {
548     if ($el->node_type == 1 and # ELEMENT_NODE
549     $el->manakai_local_name eq 'div' and
550     $el->namespace_uri eq q<http://www.w3.org/1999/xhtml>) {
551     return $el;
552     }
553     }
554    
555     my $od = $_[0]->owner_document;
556     if ($od->dom_config->get_parameter ($CREATE_CHILD_URI)) {
557     return $_[0]->append_child
558     ($od->create_element_ns (q<http://www.w3.org/1999/xhtml>, 'div'));
559     } else {
560     return undef;
561     }
562     } elsif ($_[0]->has_attribute_ns (undef, 'src')) {
563     return undef;
564     } else {
565     return $_[0];
566     }
567     } # container
568    
569     sub src ($;$);
570    
571     sub type ($;$) {
572     local $Error::Depth = $Error::Depth + 1;
573    
574     if (@_ > 1) {
575     if (defined $_[1]) {
576     $_[0]->set_attribute_ns (undef, 'type', ''.$_[1]);
577     } else {
578     $_[0]->remove_attribute_ns (undef, 'type');
579     }
580    
581     return unless defined wantarray;
582     }
583    
584     my $v = $_[0]->get_attribute_ns (undef, 'type');
585     return defined $v ? $v : $_[0]->has_attribute_ns (undef, 'src') ? undef : 'text';
586     } # type
587    
588     package Message::DOM::Atom::AtomElement::AtomCategoryElement;
589     push our @ISA, 'Message::DOM::Atom::AtomElement';
590    
591     sub label ($;$);
592    
593     sub scheme ($;$);
594    
595     sub term ($;$);
596    
597     package Message::DOM::Atom::AtomElement::AtomGeneratorElement;
598     push our @ISA, 'Message::DOM::Atom::AtomElement';
599    
600     sub uri ($;$);
601    
602     sub version ($;$);
603    
604     package Message::DOM::Atom::AtomElement::AtomLinkElement;
605     push our @ISA, 'Message::DOM::Atom::AtomElement';
606    
607     sub href ($;$);
608    
609     sub hreflang ($;$);
610    
611     sub length ($;$);
612    
613     sub rel ($;$) {
614     local $Error::Depth = $Error::Depth + 1;
615    
616     if (@_ > 1) {
617     if (defined $_[1]) {
618     my $given = ''.$_[1];
619     $given =~ s[\Ahttp://www.iana.org/assignments/relation/([^:/?#]+)\z][$1];
620     $_[0]->set_attribute_ns (undef, 'rel', $given);
621     } else {
622     $_[0]->remove_attribute_ns (undef, 'rel');
623     }
624    
625     return unless defined wantarray;
626     }
627    
628     my $v = $_[0]->get_attribute_ns (undef, 'rel');
629     if (defined $v and index ($v, ':') == -1) {
630     return q<http://www.iana.org/assignments/relation/> . $v;
631     } elsif (defined $v) {
632     return $v;
633     } else {
634     return q<http://www.iana.org/assignments/relation/alternate>;
635     }
636     } # rel
637    
638     sub title ($;$);
639    
640     sub type ($;$) {
641     local $Error::Depth = $Error::Depth + 1;
642    
643     if (@_ > 1) {
644     if (defined $_[1]) {
645     $_[0]->set_attribute_ns (undef, 'type', ''.$_[1]);
646     } else {
647     $_[0]->remove_attribute_ns (undef, 'type');
648     }
649    
650     return unless defined wantarray;
651     }
652    
653     my $v = $_[0]->get_attribute_ns (undef, 'type');
654     if (defined $v) {
655     return $v;
656     } else {
657     my $rel = $_[0]->rel;
658     if (defined $rel and
659     $rel eq q<http://www.iana.org/assignments/relation/replies>) {
660     return q<application/atom+xml>;
661     }
662     }
663     return undef;
664     } # type
665    
666     package Message::DOM::Atom::AtomElement::AtomSourceElement;
667     push our @ISA, 'Message::DOM::Atom::AtomElement';
668    
669     sub author_elements ($);
670    
671     sub category_elements ($);
672    
673     sub contributor_elements ($);
674    
675     sub generator_element ($);
676    
677     sub icon ($;$);
678    
679     sub id ($;$);
680    
681     sub link_elements ($);
682    
683     sub logo ($;$);
684    
685     sub rights_element ($);
686    
687     sub subtitle_element ($);
688    
689     sub title_element ($);
690    
691     sub updated_element ($);
692    
693     package Message::DOM::DOMImplementation;
694    
695     sub create_atom_entry_document ($$;$$) {
696     local $Error::Depth = $Error::Depth + 1;
697    
698     my $r = $_[0]->create_document ($ATOM_NS, 'entry');
699     $r->xml_version ('1.0');
700    
701     my $feede = $r->document_element;
702     $feede->manakai_language (defined $_[3] ? $_[3] : '');
703     $feede->id (''.$_[1]);
704    
705     my $titlee = $r->create_element_ns ($ATOM_NS, 'title');
706     $titlee->text_content (defined $_[2] ? $_[2] : '');
707     $feede->append_child ($titlee);
708    
709     my $updatede = $r->create_element_ns ($ATOM_NS, 'updated');
710     $updatede->value (scalar time);
711     $feede->append_child ($updatede);
712    
713     return $r;
714     } # create_atom_entry_document
715    
716     sub create_atom_feed_document ($$;$$) {
717     local $Error::Depth = $Error::Depth + 1;
718    
719     my $r = $_[0]->create_document ($ATOM_NS, 'feed');
720     $r->xml_version ('1.0');
721    
722     my $feede = $r->document_element;
723     $feede->manakai_language (defined $_[3] ? $_[3] : '');
724     $feede->id (''.$_[1]);
725    
726     my $titlee = $r->create_element_ns ($ATOM_NS, 'title');
727     $titlee->text_content (defined $_[2] ? $_[2] : '');
728     $feede->append_child ($titlee);
729    
730     my $updatede = $r->create_element_ns ($ATOM_NS, 'updated');
731     $updatede->value (scalar time);
732     $feede->append_child ($updatede);
733    
734     return $r;
735     } # create_atom_feed_document
736    
737     =head1 LICENSE
738    
739     Copyright 2007 Wakaba <[email protected]>
740    
741     This program is free software; you can redistribute it and/or
742     modify it under the same terms as Perl itself.
743    
744     =cut
745    
746     1;
747     ## $Date: 2007/07/14 16:32:28 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24