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>
27
#include "NSException+HTTP.h"
30
@interface OFSFile(Render)
32
- (id)davContentLength;
33
- (NSDate *)davLastModified;
37
@implementation OFSFileRenderer
39
static NSTimeZone *gmt = nil;
42
gmt = [[NSTimeZone timeZoneWithAbbreviation:@"GMT"] retain];
45
+ (id)sharedRenderer {
46
static OFSFileRenderer *singleton = nil;
48
singleton = [[OFSFileRenderer alloc] init];
54
- (NSException *)renderHeadOfObject:(id)_object inContext:(WOContext *)_ctx {
62
if ((tmp = [_object contentTypeInContext:_ctx]))
63
[r setHeader:tmp forKey:@"content-type"];
64
if ((tmp = [_object davContentLength]))
65
[r setHeader:tmp forKey:@"content-length"];
67
if ((tmp = [_object davLastModified])) {
70
#if COCOA_Foundation_LIBRARY
71
date = [[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
72
[tmp timeIntervalSinceReferenceDate]];
74
date = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
75
[tmp timeIntervalSince1970]];
77
[date setTimeZone:gmt];
79
// "Tue, 10 Jul 2001 14:09:06 GMT"
80
tmp = [date descriptionWithCalendarFormat:@"%a, %d %b %Y %H:%M:%S GMT"];
82
[r setHeader:tmp forKey:@"last-modified"];
88
- (NSException *)renderBodyOfObject:(id)_object inContext:(WOContext *)_ctx {
94
fm = [_object fileManager];
95
storePath = [_object storagePath];
96
content = [fm contentsAtPath:storePath];
98
/* some error handling */
100
if (content == nil) {
101
// TODO: should render exception ?
102
if ([fm respondsToSelector:@selector(lastException)])
103
return (id)[fm lastException];
104
return [NSException exceptionWithHTTPStatus:404 /* not found */];
109
[r setContent:content];
113
- (NSException *)renderObject:(id)_object inContext:(WOContext *)_ctx {
116
if ((e = [self renderHeadOfObject:_object inContext:_ctx]))
119
if (![[[_ctx request] method] isEqualToString:@"HEAD"]) {
120
if ((e = [self renderBodyOfObject:_object inContext:_ctx]))
126
- (BOOL)canRenderObject:(id)_object inContext:(WOContext *)_ctx {
127
return [_object isKindOfClass:[OFSFile class]];
130
@end /* OFSFileRenderer */