- Timestamp:
- 04/29/09 07:07:50 (7 months ago)
- Location:
- trunk/extlib/XML
- Files:
-
- 12 modified
-
Atom.pm (modified) (1 diff)
-
Atom/Base.pm (modified) (10 diffs)
-
Atom/Client.pm (modified) (5 diffs)
-
Atom/Content.pm (modified) (4 diffs)
-
Atom/Entry.pm (modified) (2 diffs)
-
Atom/ErrorHandler.pm (modified) (1 diff)
-
Atom/Feed.pm (modified) (3 diffs)
-
Atom/Link.pm (modified) (1 diff)
-
Atom/Person.pm (modified) (1 diff)
-
Atom/Server.pm (modified) (1 diff)
-
Atom/Thing.pm (modified) (2 diffs)
-
Atom/Util.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/extlib/XML/Atom.pm
r1098 r3652 1 # $Id $1 # $Id: Atom.pm 110 2009-01-07 02:01:47Z miyagawa $ 2 2 3 3 package XML::Atom; 4 4 use strict; 5 5 6 our $VERSION = '0. 25';6 our $VERSION = '0.33'; 7 7 8 8 BEGIN { -
trunk/extlib/XML/Atom/Base.pm
r1098 r3652 1 # $Id: /mirror/code/XML-Atom/trunk/lib/XML/Atom/Base.pm 5342 2006-09-16T06:39:51.745764Z miyagawa$1 # $Id: Base.pm 106 2008-11-14 22:04:41Z swistow $ 2 2 3 3 package XML::Atom::Base; … … 7 7 use Encode; 8 8 use XML::Atom; 9 use XML::Atom::Util qw( set_ns first nodelist childlist create_element remove_default_ns);9 use XML::Atom::Util qw( set_ns first nodelist childlist create_element ); 10 10 11 11 __PACKAGE__->mk_classdata('__attributes', []); … … 29 29 if (LIBXML) { 30 30 my $doc = XML::LibXML::Document->createDocument('1.0', 'utf-8'); 31 $elem = $doc->createElementNS($obj->ns, $obj->element_name); 31 my $ns = $obj->ns; 32 my ($ns_uri, $ns_prefix); 33 if ( ref $ns and $ns->isa('XML::Atom::Namespace') ) { 34 $ns_uri = $ns->{uri}; 35 $ns_prefix = $ns->{prefix}; 36 } else { 37 $ns_uri = $ns; 38 } 39 if ( $ns_uri and $ns_prefix ) { 40 $elem = $doc->createElement($obj->element_name); 41 $elem->setNamespace( $ns_uri, $ns_prefix, 1 ); 42 } else { 43 $elem = $doc->createElementNS($obj->ns, $obj->element_name); 44 } 32 45 $doc->setDocumentElement($elem); 33 46 } else { … … 50 63 my $atom = shift; 51 64 XML::Atom::Util::ns_to_version($atom->ns); 65 } 66 67 sub content_type { 68 my $atom = shift; 69 if ($atom->version >= 1.0) { 70 return "application/atom+xml"; 71 } else { 72 return "application/x.atom+xml"; 73 } 52 74 } 53 75 … … 156 178 my $obj = shift; 157 179 my($ns, $name, $class) = @_; 158 my @elem = childlist($obj->elem, $ns, $name) or return; 180 my $ns_uri = ref($ns) eq 'XML::Atom::Namespace' ? $ns->{uri} : $ns; 181 my @elem = childlist($obj->elem, $ns_uri, $name) or return; 159 182 my @obj = map { $class->new( Elem => $_, Namespace => $ns ) } @elem; 160 183 return wantarray ? @obj : $obj[0]; … … 163 186 sub mk_elem_accessors { 164 187 my $class = shift; 165 my(@list) = @_; 166 no strict 'refs'; 167 for my $elem (@list) { 188 my (@list) = @_; 189 my $override_ns; 190 191 if ( ref $list[-1] ) { 192 my $ns_list = pop @list; 193 if ( ref $ns_list eq 'ARRAY' ) { 194 $ns_list = $ns_list->[0]; 195 } 196 if ( ref($ns_list) =~ /Namespace/ ) { 197 $override_ns = $ns_list; 198 } else { 199 if ( ref $ns_list eq 'HASH' ) { 200 $override_ns = XML::Atom::Namespace->new(%$ns_list); 201 } 202 elsif ( not ref $ns_list and $ns_list ) { 203 $override_ns = $ns_list; 204 } 205 } 206 } 207 208 no strict 'refs'; 209 for my $elem ( @list ) { 168 210 (my $meth = $elem) =~ tr/\-/_/; 169 211 *{"${class}::$meth"} = sub { 170 212 my $obj = shift; 171 213 if (@_) { 172 return $obj->set( $obj->ns, $elem, $_[0]);173 } else { 174 return $obj->get( $obj->ns, $elem);214 return $obj->set( $override_ns || $obj->ns, $elem, $_[0]); 215 } else { 216 return $obj->get( $override_ns || $obj->ns, $elem); 175 217 } 176 218 }; … … 219 261 $attr, $_[0]); 220 262 } 221 return $elem->getAttribute NS('http://www.w3.org/XML/1998/namespace', $attr);263 return $elem->getAttribute("xml:$attr"); 222 264 } else { 223 265 if (@_) { … … 294 336 295 337 my $ns_uri = $ext_class->element_ns || $obj->ns; 296 my $elem = ref $stuff eq $ext_class?338 my $elem = (ref $stuff && UNIVERSAL::isa($stuff, $ext_class)) ? 297 339 $stuff->elem : create_element($ns_uri, $name); 298 340 $obj->elem->appendChild($elem); … … 311 353 if (LIBXML) { 312 354 my $doc = XML::LibXML::Document->new('1.0', 'utf-8'); 313 $doc->setDocumentElement($obj->elem); 314 remove_default_ns($obj->elem); 355 $doc->setDocumentElement($obj->elem->cloneNode(1)); 315 356 return $doc->toString(1); 316 357 } else { … … 322 363 sub as_xml_utf8 { 323 364 my $obj = shift; 324 Encode::encode_utf8($obj->as_xml); 365 my $xml = $obj->as_xml; 366 if (utf8::is_utf8($xml)) { 367 return Encode::encode_utf8($xml); 368 } 369 return $xml; 325 370 } 326 371 -
trunk/extlib/XML/Atom/Client.pm
r1098 r3652 1 # $Id $1 # $Id: Client.pm 109 2009-01-07 01:59:33Z miyagawa $ 2 2 3 3 package XML::Atom::Client; … … 72 72 unless $uri; 73 73 my $req = HTTP::Request->new(POST => $uri); 74 $req->content_type( 'application/x.atom+xml');74 $req->content_type($entry->content_type); 75 75 my $xml = $entry->as_xml; 76 76 _utf8_off($xml); … … 87 87 my($url, $entry) = @_; 88 88 my $req = HTTP::Request->new(PUT => $url); 89 $req->content_type( 'application/x.atom+xml');89 $req->content_type($entry->content_type); 90 90 my $xml = $entry->as_xml; 91 91 _utf8_off($xml); … … 136 136 my($req) = @_; 137 137 $req->header( 138 Accept => 'application/ x.atom+xml, application/xml, text/xml, */*',138 Accept => 'application/atom+xml, application/x.atom+xml, application/xml, text/xml, */*', 139 139 ); 140 140 my $nonce = $client->make_nonce; … … 174 174 $req->content_type('text/xml'); 175 175 } else { 176 $req->header('X-WSSE', sprintf 177 qq(UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"), 178 $client->username || '', $digest, $nonce_enc, $now); 179 $req->header('Authorization', 'WSSE profile="UsernameToken"'); 176 if ($client->username) { 177 $req->header('X-WSSE', sprintf 178 qq(UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"), 179 $client->username || '', $digest, $nonce_enc, $now); 180 $req->header('Authorization', 'WSSE profile="UsernameToken"'); 181 } 180 182 } 181 183 } -
trunk/extlib/XML/Atom/Content.pm
r1098 r3652 1 # $Id $1 # $Id: Content.pm 89 2007-10-04 20:28:06Z miyagawa $ 2 2 3 3 package XML::Atom::Content; … … 10 10 use Encode; 11 11 use XML::Atom; 12 use XML::Atom::Util qw( remove_default_ns hack_unicode_entity );13 12 use MIME::Base64 qw( encode_base64 decode_base64 ); 14 13 … … 113 112 $content->{__body} = ''; 114 113 for my $n (@children) { 115 remove_default_ns($n) if LIBXML;116 114 $content->{__body} .= $n->toString(LIBXML ? 1 : 0); 117 115 } … … 120 118 } 121 119 if ($] >= 5.008) { 122 $content->{__body} = hack_unicode_entity($content->{__body});120 Encode::_utf8_off($content->{__body}) unless $XML::Atom::ForceUnicode; 123 121 } 124 122 } elsif ($mode eq 'base64') { -
trunk/extlib/XML/Atom/Entry.pm
r1098 r3652 1 # $Id $1 # $Id: Entry.pm 106 2008-11-14 22:04:41Z swistow $ 2 2 3 3 package XML::Atom::Entry; … … 26 26 27 27 __PACKAGE__->mk_elem_accessors(qw( summary source )); 28 __PACKAGE__->mk_xml_attr_accessors(qw( lang base )); 28 29 29 30 __PACKAGE__->_rename_elements('issued' => 'published'); -
trunk/extlib/XML/Atom/ErrorHandler.pm
r1098 r3652 1 # $Id: ErrorHandler.pm ,v 1.1 2003/09/08 00:00:50 btrott Exp$1 # $Id: ErrorHandler.pm 1 2006-08-16 05:19:58Z miyagawa $ 2 2 3 3 package XML::Atom::ErrorHandler; -
trunk/extlib/XML/Atom/Feed.pm
r1098 r3652 1 # $Id $1 # $Id: Feed.pm 106 2008-11-14 22:04:41Z swistow $ 2 2 3 3 package XML::Atom::Feed; … … 68 68 69 69 sub element_name { 'feed' } 70 71 sub language { 72 my $feed = shift; 73 if (LIBXML) { 74 my $elem = $feed->elem; 75 if (@_) { 76 $elem->setAttributeNS('http://www.w3.org/XML/1998/namespace', 77 'lang', $_[0]); 78 } 79 return $elem->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang'); 80 } else { 81 if (@_) { 82 $feed->elem->setAttribute('xml:lang', $_[0]); 83 } 84 return $feed->elem->getAttribute('xml:lang'); 85 } 86 } 70 *language = \⟨ # legacy 71 87 72 88 73 sub version { … … 153 138 154 139 __PACKAGE__->mk_elem_accessors(qw( generator )); 140 __PACKAGE__->mk_xml_attr_accessors(qw( lang base )); 155 141 156 142 __PACKAGE__->_rename_elements('modified' => 'updated'); -
trunk/extlib/XML/Atom/Link.pm
r1098 r3652 1 # $Id $1 # $Id: Link.pm 39 2006-08-16 05:34:19Z miyagawa $ 2 2 3 3 package XML::Atom::Link; -
trunk/extlib/XML/Atom/Person.pm
r1098 r3652 1 # $Id $1 # $Id: Person.pm 39 2006-08-16 05:34:19Z miyagawa $ 2 2 3 3 package XML::Atom::Person; -
trunk/extlib/XML/Atom/Server.pm
r1098 r3652 1 # $Id $1 # $Id: Server.pm 25 2006-08-16 05:30:14Z miyagawa $ 2 2 3 3 package XML::Atom::Server; -
trunk/extlib/XML/Atom/Thing.pm
r1098 r3652 1 # $Id $1 # $Id: Thing.pm 89 2007-10-04 20:28:06Z miyagawa $ 2 2 3 3 package XML::Atom::Thing; … … 7 7 use XML::Atom; 8 8 use base qw( XML::Atom::ErrorHandler ); 9 use XML::Atom::Util qw( first nodelist childlist remove_default_nscreate_element );9 use XML::Atom::Util qw( first nodelist childlist create_element ); 10 10 use XML::Atom::Category; 11 11 use XML::Atom::Link; -
trunk/extlib/XML/Atom/Util.pm
r1098 r3652 1 # $Id $1 # $Id: Util.pm 89 2007-10-04 20:28:06Z miyagawa $ 2 2 3 3 package XML::Atom::Util; … … 8 8 use Encode; 9 9 use Exporter; 10 @EXPORT_OK = qw( set_ns hack_unicode_entity first nodelist childlist textValue iso2dt encode_xml remove_default_nscreate_element );10 @EXPORT_OK = qw( set_ns first nodelist childlist textValue iso2dt encode_xml create_element ); 11 11 @ISA = qw( Exporter ); 12 12 … … 36 36 my $ns = shift; 37 37 $NS_VERSION{$ns}; 38 }39 40 sub hack_unicode_entity {41 my $data = shift;42 Encode::_utf8_on($data);43 $data =~ s/&#x(\w{4});/chr(hex($1))/eg;44 Encode::_utf8_off($data) unless $XML::Atom::ForceUnicode;45 $data;46 38 } 47 39 … … 115 107 } 116 108 117 sub remove_default_ns {118 my($node) = @_;119 if (ref($node) =~ /Element$/ && $node->nodeName =~ /^default\d*:/) {120 my $ns = $node->getNamespace;121 if ($ns and my $uri = $ns->getData) {122 $node->setNamespace($uri, '');123 }124 }125 for my $n ($node->childNodes) {126 remove_default_ns($n);127 }128 }129 130 109 sub create_element { 131 110 my($ns, $name) = @_;
