Changeset 19 in bookmarks for trunk


Ignore:
Timestamp:
05/21/13 13:48:46 (12 years ago)
Author:
peter
Message:

added support for viewing the list of bookmarks as XBEL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BookmarkApp.pm

    r17 r19  
    77 
    88use Encode; 
     9use HTTP::Date qw{time2isoz}; 
    910use JSON; 
    1011use Bookmarks; 
     
    8889            }) 
    8990        ); 
     91    } elsif ($format eq 'xbel') { 
     92        require XML::XBEL; 
     93        #TODO: conditional support; if XML::XBEL is not present, return a 5xx response 
     94 
     95        my $xbel = XML::XBEL->new; 
     96 
     97        $xbel->new_document({ 
     98            title => 'Bookmarks' . ($tag ? " tagged as $tag" : ''), 
     99        }); 
     100 
     101        for my $bookmark (@resources) { 
     102            my $cdatetime = time2isoz $bookmark->{ctime}; 
     103            my $mdatetime = time2isoz $bookmark->{mtime}; 
     104            # make the timestamps W3C-correct 
     105            s/ /T/ foreach ($cdatetime, $mdatetime); 
     106 
     107            $xbel->add_bookmark({ 
     108                href     => $bookmark->{uri}, 
     109                title    => $bookmark->{title}, 
     110                desc     => 'Tags: ' . join(', ', @{ $bookmark->{tags} }), 
     111                added    => $cdatetime, 
     112                #XXX: are we sure that modified is the mtime of the bookmark or the resource? 
     113                modified => $mdatetime, 
     114            }); 
     115        } 
     116 
     117        $self->header_props( 
     118            -type    => 'application/xml', 
     119            -charset => 'UTF-8', 
     120        ); 
     121 
     122        return $xbel->toString; 
    90123    } else { 
    91124        $self->header_props( 
Note: See TracChangeset for help on using the changeset viewer.