]> err.no Git - sope/blob - sope-appserver/WEExtensions/common.h
fixed WEExtensions resource manager lookup
[sope] / sope-appserver / WEExtensions / common.h
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo 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
9   later version.
10
11   OGo 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.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id: common.h 1 2004-08-20 10:08:27Z znek $
22
23 #ifndef __WEExtensions_common_H__
24 #define __WEExtensions_common_H__
25
26 #import <Foundation/Foundation.h>
27 #include <NGObjWeb/NGObjWeb.h>
28 #include <NGExtensions/NGExtensions.h>
29
30 #if NeXT_Foundation_LIBRARY || APPLE_Foundation_LIBRARY
31 #  include <NGExtensions/NGObjectMacros.h>
32 #endif
33
34 @interface WOContext(WOExtensionsPrivate)
35 - (void)addActiveFormElement:(WOElement *)_element;
36 @end
37
38 static inline id WOExtGetProperty(NSDictionary *_set, NSString *_name) {
39   id propValue = [_set objectForKey:_name];
40
41   if (propValue) {
42     propValue = [propValue retain];
43     [(NSMutableDictionary *)_set removeObjectForKey:_name];
44   }
45   return propValue;
46 }
47
48 static inline NSString *WEUriOfResource(NSString *_name, WOContext *_ctx) {
49   NSArray           *languages;
50   WOResourceManager *resourceManager;
51   NSString          *uri;
52
53   if (_name == nil)
54     return nil;
55   
56   languages = [_ctx hasSession]
57     ? [[_ctx session] languages]
58     : [[_ctx request] browserLanguages];
59   
60   if ((resourceManager = [[_ctx component] resourceManager]) == nil)
61     resourceManager = [[_ctx application] resourceManager];
62   
63   uri = [resourceManager urlForResourceNamed:_name
64                          inFramework:nil
65                          languages:languages
66                          request:[_ctx request]];
67   if ([uri rangeOfString:@"/missingresource?"].length > 0)
68     uri = nil;
69   
70   return uri;
71 }
72
73 static inline void WEAppendFont(WOResponse *_resp,
74                                 NSString   *_color,
75                                 NSString   *_face,
76                                 NSString   *_size)
77 {
78   [_resp appendContentString:@"<font"];
79   if (_color) {
80     [_resp appendContentString:@" color=\""];
81     [_resp appendContentHTMLAttributeValue:_color];
82     [_resp appendContentCharacter:'"'];
83   }
84   if (_face) {
85     [_resp appendContentString:@" face=\""];
86     [_resp appendContentHTMLAttributeValue:_face];
87     [_resp appendContentCharacter:'"'];
88   }
89   if (_size) {
90     [_resp appendContentString:@" size=\""];
91     [_resp appendContentHTMLAttributeValue:_size];
92     [_resp appendContentCharacter:'"'];
93   }
94   [_resp appendContentCharacter:'>'];
95 }
96
97 static inline void WEAppendTD(WOResponse *_resp,
98                               NSString   *_align,
99                               NSString   *_valign,
100                               NSString   *_bgColor)
101 {
102   [_resp appendContentString:@"<td"];
103   if (_bgColor) {
104     [_resp appendContentString:@" bgcolor=\""];
105     [_resp appendContentHTMLAttributeValue:_bgColor];
106     [_resp appendContentCharacter:'"'];
107   }
108   if (_align) {
109     [_resp appendContentString:@" align=\""];
110     [_resp appendContentHTMLAttributeValue:_align];
111     [_resp appendContentCharacter:'"'];
112   }
113   if (_valign) {
114     [_resp appendContentString:@" valign=\""];
115     [_resp appendContentHTMLAttributeValue:_valign];
116     [_resp appendContentCharacter:'"'];
117   }
118   [_resp appendContentCharacter:'>'];
119 }
120
121 static inline WOElement *WECreateElement(NSString *_className,
122                                          NSString *_name,
123                                          NSDictionary *_config,
124                                          WOElement *_template)
125 {
126   Class               c;
127   WOElement           *result = nil;
128   NSMutableDictionary *config = nil;
129   
130   if ((c = NSClassFromString(_className)) == Nil) {
131     NSLog(@"%s: missing '%@' class", __PRETTY_FUNCTION__, _className);
132     return nil;
133   }
134   config = [NSMutableDictionary dictionaryWithCapacity:4];
135   {
136     NSEnumerator *keyEnum;
137     id           key;
138
139     keyEnum = [_config keyEnumerator];
140
141     while ((key = [keyEnum nextObject])) {
142       WOAssociation *a;
143
144       a = [WOAssociation associationWithValue:[_config objectForKey:key]];
145       [config setObject:a forKey:key];
146     }
147   }
148   result = [[c alloc] initWithName:_name
149                       associations:config
150                       template:_template];
151   return [result autorelease];
152 }
153
154 #define OWGetProperty WOExtGetProperty
155
156 #endif /* __WEExtensions_common_H__ */