[Rt-commit] [svn] r866 - in RTx-Atom: . html/Atom/0.3
html/Atom/0.3/Add html/Atom/0.3/Describe html/Atom/0.3/Get
html/Atom/0.3/NoAuth html/Atom/0.3/Search
autrijus at pallas.eruditorum.org
autrijus at pallas.eruditorum.org
Tue May 11 15:18:14 EDT 2004
Author: autrijus
Date: Tue May 11 15:18:13 2004
New Revision: 866
Added:
RTx-Atom/html/Atom/0.3/Describe/Container
RTx-Atom/html/Atom/0.3/Describe/Object
RTx-Atom/html/Atom/0.3/Get/Object
RTx-Atom/html/Atom/0.3/Get/Property
Modified:
RTx-Atom/ (props changed)
RTx-Atom/html/Atom/0.3/Add/index
RTx-Atom/html/Atom/0.3/Describe/index
RTx-Atom/html/Atom/0.3/Get/index
RTx-Atom/html/Atom/0.3/NoAuth/feed.css
RTx-Atom/html/Atom/0.3/Search/index
RTx-Atom/html/Atom/0.3/dhandler
RTx-Atom/html/Atom/0.3/index
Log:
----------------------------------------------------------------------
r4766 at not: autrijus | 2004-05-11T19:18:03.722587Z
* Implement "Describe" and "Add".
* Refactor Error link into $ShowError.
* Implement "Get" on Properties.
* Handles 404 correctly for missing objects.
* Handles 400 correctly for failure in creation.
----------------------------------------------------------------------
Modified: RTx-Atom/html/Atom/0.3/Add/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Add/index (original)
+++ RTx-Atom/html/Atom/0.3/Add/index Tue May 11 15:18:13 2004
@@ -4,3 +4,29 @@
%# (for subsequent Get/Update). Body is success message in text/plain.
%# 400: Request failed. Body is error message in text/plain.
%# 404: There is no container matching the specified URI.
+<%INIT>
+my $obj = eval {$CollectionClass->new($session{CurrentUser})->NewItem}
+ or return $m->comp($ShowError, Status => 404);
+
+my ($status, $msg) = ($obj->Create( $m->request_args ))[0, -1];
+if (my $id = $obj->Id) {
+ $r->header_out(Location => "$FeedURI/$id");
+ return $m->comp($ShowError, Status => 303);
+}
+$r->content_type('text/plain');
+$r->status(400);
+print $msg;
+</%INIT>
+<%ARGS>
+$Path
+$BaseURI
+$Now
+$ShowLink
+$ShowEntry
+$ShowError
+$X
+
+$Type
+$CollectionClass
+$FeedURI
+</%ARGS>
Added: RTx-Atom/html/Atom/0.3/Describe/Container
==============================================================================
--- (empty file)
+++ RTx-Atom/html/Atom/0.3/Describe/Container Tue May 11 15:18:13 2004
@@ -0,0 +1,27 @@
+%# [OPTIONS FeedURI]
+%# On a container, returns the schema of objects acceptable by this container.
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
+<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
+ <& $ShowLink, Relation => "service.post", URI => $FeedURI, Id => '!add', Title => $Type &>
+ <& $ShowLink, Relation => "service.feed", URI => $FeedURI, Id => '!search', Title => $Type &>
+ <entry>
+ <content type="text/xml" mode="xml">
+% $Map->{action} = 'add';
+ <% $X->XMLout($Map) |n %>
+ <% $X->XMLout({ action => 'search', 'rows' => '' }) |n %>
+ </content>
+ </entry>
+</feed>
+<%ARGS>
+$Path
+$BaseURI
+$Now
+$ShowLink
+$ShowEntry
+$X
+
+$Type
+$FeedURI
+$Map
+</%ARGS>
Added: RTx-Atom/html/Atom/0.3/Describe/Object
==============================================================================
--- (empty file)
+++ RTx-Atom/html/Atom/0.3/Describe/Object Tue May 11 15:18:13 2004
@@ -0,0 +1,23 @@
+%# [OPTIONS EditURI]
+%# On an object, returns the schema acceptable by the specified update types.
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
+<entry xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
+ <& $ShowLink, Relation => "service.post", URI => "$BaseURI/$Path", Id => '!update', Title => $Type, Class => 'Update' &>
+ <& $ShowLink, Relation => "service.edit", URI => "$BaseURI/$Path", Id => '!put', Title => $Type &>
+ <content type="text/xml" mode="xml">
+ <% $X->XMLout($Map) |n %>
+ </content>
+</entry>
+<%ARGS>
+$Path
+$BaseURI
+$Now
+$ShowLink
+$ShowEntry
+$X
+
+$Type
+$FeedURI
+$Map
+</%ARGS>
Modified: RTx-Atom/html/Atom/0.3/Describe/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Describe/index (original)
+++ RTx-Atom/html/Atom/0.3/Describe/index Tue May 11 15:18:13 2004
@@ -1,6 +1,33 @@
-%# [OPTIONS PostURI], [GET PostURI]
+%# [OPTIONS AnyURI]
%# On a container, returns the schema of objects acceptable by this container.
-%# On an object, returns the schema acceptable by the specified 'adverb'.
+%# On an object, returns the schema acceptable by the specified update types.
%# 200: Success. Body is schema in a format determined by content negotiation.
%# 400: Request failed. Body is error message in text/plain.
%# 404: There is no container matching the specified URI.
+<%INIT>
+my $obj = $CollectionClass->new($session{CurrentUser})->NewItem;
+my $id = $1 if $Path =~ /(\d+)$/;
+$obj->Load($id);
+
+my $accessible = $obj->_ClassAccessible;
+
+my $map;
+while (my ($k, $v) = each %$accessible) {
+ $map->{$k} = '' if $v->{write};
+}
+
+my $type = ($id ? 'Object' : 'Container');
+return $m->comp($type, %ARGS, Map => $map, Object => $obj);
+</%INIT>
+<%ARGS>
+$Path
+$BaseURI
+$Now
+$ShowLink
+$ShowEntry
+$X
+
+$Type
+$CollectionClass
+$FeedURI
+</%ARGS>
Added: RTx-Atom/html/Atom/0.3/Get/Object
==============================================================================
--- (empty file)
+++ RTx-Atom/html/Atom/0.3/Get/Object Tue May 11 15:18:13 2004
@@ -0,0 +1,45 @@
+%# [GET EditURI]
+%# Retrieve a representation of an object.
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
+<entry xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
+ <& $ShowEntry, %ARGS, Object => $Object, IsChild => 0 &>
+ <content type="text/xml" mode="xml">
+ <% $xml|n %>
+ </content>
+ <html:dl>
+% foreach my $key (keys %$struct) {
+% my $value = $struct->{$key};
+% my $is_feed = ref($value);
+% my $sym = $is_feed ? '/' : '.';
+ <html:dt><& $ShowLink, Relation => "service.".($is_feed ? 'feed' : 'edit'), URI => "$BaseURI/$Path$sym$key", Title => $key, IsChild => 1, Text => $key &></html:dt>
+% next if $session{AtomClient};
+% foreach my $text ($is_feed ? @$value : $value) {
+ <html:dd><% $text %></html:dd>
+% }
+% }
+ </html:dl>
+</entry>
+<%INIT>
+my $type = lc(ref($Object));
+$type =~ s/.*:://g;
+
+$session{CurrentUser}->LanguageHandle('en-us');
+my $handler = "/REST/1.0/Forms/$type/default";
+my $struct = $m->comp($handler, id => $Object->Id, fields => {})->[2];
+delete $session{CurrentUser}{LangHandle};
+
+my $xml = $X->XMLout($struct);
+$xml =~ s/"Not set"/""/g;
+$xml =~ s/" "/"\n"/g;
+</%INIT>
+<%ARGS>
+$ShowLink
+$ShowEntry
+$BaseURI
+$Path
+$CollectionClass
+$X
+
+$Object
+</%ARGS>
Added: RTx-Atom/html/Atom/0.3/Get/Property
==============================================================================
--- (empty file)
+++ RTx-Atom/html/Atom/0.3/Get/Property Tue May 11 15:18:13 2004
@@ -0,0 +1,13 @@
+%# [GET EditURI]
+%# Retrieve a representation of an property.
+<%INIT>
+$r->content_type('text/plain');
+my $code = $Object->can($Property)
+ or return $m->comp($ShowError, Status => 404);
+print $code->($Object);
+</%INIT>
+<%ARGS>
+$Object
+$Property
+$ShowError
+</%ARGS>
Modified: RTx-Atom/html/Atom/0.3/Get/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Get/index (original)
+++ RTx-Atom/html/Atom/0.3/Get/index Tue May 11 15:18:13 2004
@@ -1,51 +1,22 @@
%# [GET EditURI]
-%# Get a representation of an object.
-%# 200: Success. Body is the object, serialized as an AtomEntry.
-%# 400: Request failed. Body is error message in text/plain.
+%# Retrieve a representation of an object or property.
+%# 200: Success. Body is the serialized item.
+%# 400: Request failed. Body is error message.
%# 404: There is no object matching the specified URI.
-<?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
-<entry xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
- <& $ShowEntry, %ARGS, Object => $obj, IsChild => 0 &>
- <content type="text/xml" mode="xml">
- <% $xml|n %>
- </content>
- <html:dl>
-% foreach my $key (keys %$struct) {
-% my $value = $struct->{$key};
-% my $is_feed = ref($value);
-% my $sym = $is_feed ? '/' : '.';
- <html:dt><& $ShowLink, Relation => "service.".($is_feed ? 'feed' : 'edit'), URI => "$BaseURI/$Path$sym$key", Title => $key, IsChild => 1, Text => $key &></html:dt>
-% next if $session{AtomClient};
-% foreach my $text ($is_feed ? @$value : $value) {
- <html:dd><% $text %></html:dd>
-% }
-% }
- </html:dl>
-</entry>
<%INIT>
my $obj = $CollectionClass->new($session{CurrentUser})->NewItem;
-my $id = $1 if $Path =~ /(\d+)$/;
+my ($id, $property) = ($1, $2) if $Path =~ /(\d+)(?:\.(\w+))?$/;
+$obj->Load($id) or return $m->comp($ShowError, Status => 404);
-$obj->Load($id);
-my $type = lc(ref($obj));
-$type =~ s/.*:://g;
-
-$session{CurrentUser}->LanguageHandle('en-us');
-my $handler = "/REST/1.0/Forms/$type/default";
-my $struct = $m->comp($handler, id => $id, fields => {})->[2];
-delete $session{CurrentUser}{LangHandle};
-
-require XML::Simple;
-my $xs = XML::Simple->new(RootName => 'body', NoIndent => 0);
-my $xml = $xs->XMLout($struct);
-$xml =~ s/"Not set"/""/g;
-$xml =~ s/" "/"\n"/g;
+my $type = ($property ? 'Property' : 'Object');
+return $m->comp($type, %ARGS, Object => $obj, Property => $property);
</%INIT>
<%ARGS>
$ShowLink
$ShowEntry
+$ShowError
$BaseURI
$Path
$CollectionClass
+$X
</%ARGS>
Modified: RTx-Atom/html/Atom/0.3/NoAuth/feed.css
==============================================================================
--- RTx-Atom/html/Atom/0.3/NoAuth/feed.css (original)
+++ RTx-Atom/html/Atom/0.3/NoAuth/feed.css Tue May 11 15:18:13 2004
@@ -69,6 +69,10 @@
background-color: #dddd66;
}
+a.update {
+ background-color: #ffcccc;
+}
+
entry title {
font-size:125%;
font-weight:bold;
Modified: RTx-Atom/html/Atom/0.3/Search/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Search/index (original)
+++ RTx-Atom/html/Atom/0.3/Search/index Tue May 11 15:18:13 2004
@@ -19,7 +19,7 @@
% }
</tagline>
<& $ShowLink, Relation => "service.feed", URI => $BaseURI, Id => '_up', Title => "Up" &>
- <& $ShowLink, Relation => "service.post", URI => "$FeedURI!add", Id => '!add', Title => $Type &>
+ <& $ShowLink, Relation => "service.post", URI => $FeedURI, Id => '!add', Title => $Type &>
% # XXX - The URI below is incorrect; should point to collection URL
<& $ShowLink, Type => 'text/html', URI => $RT::WebURL, Title => $Type &>
<modified><% $Now->W3CDTF %></modified>
Modified: RTx-Atom/html/Atom/0.3/dhandler
==============================================================================
--- RTx-Atom/html/Atom/0.3/dhandler (original)
+++ RTx-Atom/html/Atom/0.3/dhandler Tue May 11 15:18:13 2004
@@ -1,5 +1,6 @@
%# The main dispatcher for RT/Atom 0.3
<%INIT>
+require XML::Simple;
require Digest::MD5;
require MIME::Base64;
@@ -181,29 +182,27 @@
OPTIONS => 'Describe',
);
-my $verb = $Methods{$r->method}
- or return $m->comp('Elements/Error', Status => 405, Allow => join(', ', sort keys %Methods));
+my $method = $r->method;
my $path = $m->dhandler_arg;
$path =~ s{/+(?:index\.html)?$}{}g;
+$method = $1 if $path =~ s/!(\w+)$//;
my ($type, @parts) = grep length, split('/', $path);
$type =~ s{-}{::}g;
-my $adverb = '';
-if ($type =~ s/!(\w+)$//) {
- $adverb = $1;
- $verb = 'Describe' if $verb eq 'Get';
- $m->comp('Elements/Error', Status => 405, Allow => 'Add, Describe')
- unless $verb =~ /Add|Describe/;
-}
+my $verb = $Methods{$method} or return $m->comp(
+ 'Elements/Error',
+ Status => 405,
+ Allow => join(', ', sort keys %Methods)
+);
if ((@parts % 2) == 0) {
# FeedURI on collection
$verb = 'Search' if $verb eq 'Get';
}
-elsif ($adverb) {
- # PostURI on object
+elsif (0) {
+ # PostURI on object XXX
$verb = 'Update' if $verb eq 'Add';
}
@@ -221,9 +220,12 @@
}
if ($key =~ /\b\Q$type\E$/i) {
- my $new_type = $key;
- $new_type =~ s/::/-/g;
- $path = join('/', $new_type, @parts);
+ $class = $type = $key;
+ $type =~ s/::/-/g;
+ $method =~ /^(?:GET|HEAD|OPTIONS)$/ or last;
+
+ # Redirect "safe" methods.
+ $path = join('/', $type, @parts);
my $query = $m->comp('/Elements/QueryString', $m->request_args);
$r->header_out(Location => "$BaseURI/$path?$query");
return $m->comp('Elements/Error', Status => 301);
@@ -234,6 +236,7 @@
$ARGS{BaseURI} = $BaseURI;
$ARGS{ShowLink} = "/Atom/0.3/Elements/Link";
$ARGS{ShowEntry} = "/Atom/0.3/Elements/Entry";
+$ARGS{ShowError} = "/Atom/0.3/Elements/Error";
$ARGS{Now} = RT::Date->new($session{CurrentUser});
$ARGS{Now}->SetToNow;
@@ -259,9 +262,9 @@
$m->comp(
"$verb/index", %ARGS,
Type => $type,
- Adverb => $adverb,
CollectionClass => $class,
FeedURI => "$BaseURI/$type",
+ X => XML::Simple->new(RootName => 'body', NoIndent => 0),
);
</%INIT>
<%FILTER>
Modified: RTx-Atom/html/Atom/0.3/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/index (original)
+++ RTx-Atom/html/Atom/0.3/index Tue May 11 15:18:13 2004
@@ -16,7 +16,7 @@
<entry>
<title><% loc($type) %></title>
<& $ShowLink, Relation => "service.feed", URI => "$BaseURI/$class?", Title => $type, IsChild => 1 &>
- <& $ShowLink, Relation => 'service.post', URI => "$BaseURI/$class!add", Id => "$type!add", Title => $type &>
+ <& $ShowLink, Relation => 'service.post', URI => "$BaseURI/$class", Id => $type, Title => $type &>
<& $ShowLink, Type => "text/html", URI => $BaseURI, Title => $type &>
<id><% $RT::SystemUser->UserObj->URI %>/<% $class %></id>
<issued><% $RT::SystemUser->UserObj->CreatedObj->W3CDTF %></issued>
More information about the Rt-commit
mailing list