]> err.no Git - sope/blob - sope-appserver/WEExtensions/common.h
renamed packages as discussed in the developer list
[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$
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   resourceManager = [[_ctx application] resourceManager];
61   
62   uri = [resourceManager urlForResourceNamed:_name
63                          inFramework:nil
64                          languages:languages
65                          request:[_ctx request]];
66   if ([uri rangeOfString:@"/missingresource?"].length > 0)
67     uri = nil;
68   
69   return uri;
70 }
71
72 static inline void WEAppendFont(WOResponse *_resp,
73                                 NSString   *_color,
74                                 NSString   *_face,
75                                 NSString   *_size)
76 {
77   [_resp appendContentString:@"<font"];
78   if (_color) {
79     [_resp appendContentString:@" color=\""];
80     [_resp appendContentHTMLAttributeValue:_color];
81     [_resp appendContentCharacter:'"'];
82   }
83   if (_face) {
84     [_resp appendContentString:@" face=\""];
85     [_resp appendContentHTMLAttributeValue:_face];
86     [_resp appendContentCharacter:'"'];
87   }
88   if (_size) {
89     [_resp appendContentString:@" size=\""];
90     [_resp appendContentHTMLAttributeValue:_size];
91     [_resp appendContentCharacter:'"'];
92   }
93   [_resp appendContentCharacter:'>'];
94 }
95
96 static inline void WEAppendTD(WOResponse *_resp,
97                               NSString   *_align,
98                               NSString   *_valign,
99                               NSString   *_bgColor)
100 {
101   [_resp appendContentString:@"<td"];
102   if (_bgColor) {
103     [_resp appendContentString:@" bgcolor=\""];
104     [_resp appendContentHTMLAttributeValue:_bgColor];
105     [_resp appendContentCharacter:'"'];
106   }
107   if (_align) {
108     [_resp appendContentString:@" align=\""];
109     [_resp appendContentHTMLAttributeValue:_align];
110     [_resp appendContentCharacter:'"'];
111   }
112   if (_valign) {
113     [_resp appendContentString:@" valign=\""];
114     [_resp appendContentHTMLAttributeValue:_valign];
115     [_resp appendContentCharacter:'"'];
116   }
117   [_resp appendContentCharacter:'>'];
118 }
119
120 static inline WOElement *WECreateElement(NSString *_className,
121                                          NSString *_name,
122                                          NSDictionary *_config,
123                                          WOElement *_template)
124 {
125   Class               c;
126   WOElement           *result = nil;
127   NSMutableDictionary *config = nil;
128   
129   if ((c = NSClassFromString(_className)) == Nil) {
130     NSLog(@"%s: missing '%@' class", __PRETTY_FUNCTION__, _className);
131     return nil;
132   }
133   config = [NSMutableDictionary dictionaryWithCapacity:4];
134   {
135     NSEnumerator *keyEnum;
136     id           key;
137
138     keyEnum = [_config keyEnumerator];
139
140     while ((key = [keyEnum nextObject])) {
141       WOAssociation *a;
142
143       a = [WOAssociation associationWithValue:[_config objectForKey:key]];
144       [config setObject:a forKey:key];
145     }
146   }
147   result = [[c alloc] initWithName:_name
148                       associations:config
149                       template:_template];
150   return [result autorelease];
151 }
152
153 #define OWGetProperty WOExtGetProperty
154
155 #endif /* __WEExtensions_common_H__ */