2 Copyright (C) 2002-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "OFSFileRenderer.h"
24 #include <NGObjWeb/WORequest.h>
25 #include <NGObjWeb/WOResponse.h>
26 #include <NGObjWeb/WOContext.h>
29 @interface OFSFile(Render)
31 - (id)davContentLength;
32 - (NSDate *)davLastModified;
36 @implementation OFSFileRenderer
38 static NSTimeZone *gmt = nil;
41 gmt = [[NSTimeZone timeZoneWithAbbreviation:@"GMT"] retain];
44 + (id)sharedRenderer {
45 static OFSFileRenderer *singleton = nil;
47 singleton = [[OFSFileRenderer alloc] init];
53 - (NSException *)renderHeadOfObject:(id)_object inContext:(WOContext *)_ctx {
61 if ((tmp = [_object contentTypeInContext:_ctx]))
62 [r setHeader:tmp forKey:@"content-type"];
63 if ((tmp = [_object davContentLength]))
64 [r setHeader:tmp forKey:@"content-length"];
66 if ((tmp = [_object davLastModified])) {
69 #if COCOA_Foundation_LIBRARY
70 date = [[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
71 [tmp timeIntervalSinceReferenceDate]];
73 date = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
74 [tmp timeIntervalSince1970]];
76 [date setTimeZone:gmt];
78 // "Tue, 10 Jul 2001 14:09:06 GMT"
79 tmp = [date descriptionWithCalendarFormat:@"%a, %d %b %Y %H:%M:%S GMT"];
81 [r setHeader:tmp forKey:@"last-modified"];
87 - (NSException *)renderBodyOfObject:(id)_object inContext:(WOContext *)_ctx {
93 fm = [_object fileManager];
94 storePath = [_object storagePath];
95 content = [fm contentsAtPath:storePath];
97 /* some error handling */
100 // TODO: should render exception ?
101 if ([fm respondsToSelector:@selector(lastException)])
102 return (id)[fm lastException];
103 return [NSException exceptionWithHTTPStatus:404 /* not found */];
108 [r setContent:content];
112 - (NSException *)renderObject:(id)_object inContext:(WOContext *)_ctx {
115 if ((e = [self renderHeadOfObject:_object inContext:_ctx]))
118 if (![[[_ctx request] method] isEqualToString:@"HEAD"]) {
119 if ((e = [self renderBodyOfObject:_object inContext:_ctx]))
125 - (BOOL)canRenderObject:(id)_object inContext:(WOContext *)_ctx {
126 return [_object isKindOfClass:[OFSFile class]];
129 @end /* OFSFileRenderer */