From a3b060487cf8e0dd1195ca9722c50cc590fbf61f Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 24 Aug 2005 19:48:36 +0000 Subject: [PATCH] added WOSetHeader element git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1071 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 10 ++ .../NGObjWeb/DynamicElements/GNUmakefile | 1 + .../NGObjWeb/DynamicElements/WOCopyValue.api | 2 +- .../NGObjWeb/DynamicElements/WOSetHeader.api | 8 ++ .../NGObjWeb/DynamicElements/WOSetHeader.m | 130 ++++++++++++++++++ sope-appserver/NGObjWeb/Version | 2 +- 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.api create mode 100644 sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.m diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index ce05640b..8227755f 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,13 @@ +2005-08-23 Helge Hess + + * v4.5.192 + + * DynamicElements/WOCopyValue.api: fixed required attribute + + * DynamicElements: added WOSetHeader dynamic element, this renders + nothing and is used to manipulate the headers of the response being + generated (or other objects with the same API) + 2005-08-23 Marcus Mueller * DynamicElements/WOCopyValue.api: completed definition (v4.5.191) diff --git a/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile b/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile index ba5464a0..07085bc5 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile +++ b/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile @@ -54,6 +54,7 @@ DynamicElements_OBJC_FILES = \ WOEntity.m \ WOSetCursor.m \ WOCopyValue.m \ + WOSetHeader.m \ \ WONoContentElement.m \ _WOStaticHTMLElement.m \ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOCopyValue.api b/sope-appserver/NGObjWeb/DynamicElements/WOCopyValue.api index 0cb48bf8..6f9c6124 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOCopyValue.api +++ b/sope-appserver/NGObjWeb/DynamicElements/WOCopyValue.api @@ -1,7 +1,7 @@ - + diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.api b/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.api new file mode 100644 index 00000000..2068b5d3 --- /dev/null +++ b/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.api @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.m b/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.m new file mode 100644 index 00000000..bf58be5c --- /dev/null +++ b/sope-appserver/NGObjWeb/DynamicElements/WOSetHeader.m @@ -0,0 +1,130 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include + +/* + WOSetHeader / + + This element can set/add a header field using -setHeader:forKey:. Usually its + used with a WOResponse (context.response is the default 'object'), but can be + used with arbitary objects implementing the same API (eg context.request). + + Usage: + ChangeContentType: WOSetHeader { + header = "content-type"; + value = "text/plain"; + } + + Bindings: + header|key|name - name of header (should be lowercase for WOResponse) + value - value to apply + addToExisting - use -appendHeader:forKey: or -setHeader:forKey:? + object - object to manipulate (defaults to [context response]) +*/ + +@interface WOSetHeader : WODynamicElement // TODO: should be WOElement? +{ + WOAssociation *object; + WOAssociation *header; + WOAssociation *value; + WOAssociation *addToExisting; +} + +@end + +#include +#include +#include +#include "common.h" + +@implementation WOSetHeader + +- (id)initWithName:(NSString *)_name + associations:(NSDictionary *)_config + template:(WOElement *)_c +{ + if ((self = [super initWithName:_name associations:_config template:_c])) { + self->header = OWGetProperty(_config, @"header"); + self->value = OWGetProperty(_config, @"value"); + self->addToExisting = OWGetProperty(_config, @"addToExisting"); + self->object = OWGetProperty(_config, @"object"); + + if (self->header == nil) self->header = OWGetProperty(_config, @"key"); + if (self->header == nil) self->header = OWGetProperty(_config, @"name"); + } + return self; +} + +- (void)dealloc { + [self->object release]; + [self->header release]; + [self->value release]; + [self->addToExisting release]; + [super dealloc]; +} + +/* generating response */ + +- (id)objectForKey:(NSString *)_key inContext:(WOContext *)_ctx { + if (![_key isNotEmpty]) + return nil; + + if ([_key isEqualToString:@"response"]) + return [_ctx response]; + if ([_key isEqualToString:@"request"]) + return [_ctx request]; + + [self errorWithFormat:@"Unknown object key: '%@'", _key]; + return nil; +} + +- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { + WOMessage *lObject; + NSString *k, *v; + BOOL doAdd; + + doAdd = (self->addToExisting != nil) + ? [self->addToExisting boolValueInContext:_ctx] + : NO; + + k = [self->header stringValueInContext:_ctx]; + v = [self->value stringValueInContext:_ctx]; + + /* determine object to manipulate */ + + lObject = (self->object != nil) + ? [self->object valueInContext:_ctx] + : [_ctx response]; + if ([lObject isKindOfClass:[NSString class]]) + lObject = [self objectForKey:(NSString *)lObject inContext:_ctx]; + + /* apply */ + + if (doAdd) { + if ([v isNotNull]) + [lObject appendHeader:v forKey:k]; + } + else + [lObject setHeader:([v isNotNull] ? v : nil) forKey:k]; +} + +@end /* WOSetHeader */ diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 1d11bdf5..7baefdff 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=191 +SUBMINOR_VERSION:=192 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134 -- 2.39.5