]> err.no Git - sope/blob - Recycler/NGObjDOM/common.h
added maintenance directory
[sope] / Recycler / NGObjDOM / common.h
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
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 __NGObjDOM_common_H__
24 #define __NGObjDOM_common_H__
25
26 #import <Foundation/Foundation.h>
27
28 #if NeXT_Foundation_LIBRARY || APPLE_FOUNDATION_LIBRARY
29 #  include <NGExtensions/NGObjectMacros.h>
30 #endif
31
32 #include <NGExtensions/NGExtensions.h>
33 #include <NGObjWeb/NGObjWeb.h>
34 #include <DOM/DOM.h>
35
36 @class ODNodeRenderer;
37
38 @interface WOContext(ODNodeRenderPrivate)
39 - (void)addActiveFormElement:(ODNodeRenderer *)_element;
40 @end
41
42 @interface DOMElement(ODNodeRenderPrivate)
43 - (id)lookupQueryPath:(NSString *)_queryPath;
44 @end
45
46
47 static inline void ODRAppendFont(WOResponse *_resp,
48                                  NSString   *_color,
49                                  NSString   *_face,
50                                  NSString   *_size)
51 {
52   [_resp appendContentString:@"<font"];
53   if (_color) {
54     [_resp appendContentString:@" color=\""];
55     [_resp appendContentHTMLAttributeValue:_color];
56     [_resp appendContentCharacter:'"'];
57   }
58   if (_face) {
59     [_resp appendContentString:@" face=\""];
60     [_resp appendContentHTMLAttributeValue:_face];
61     [_resp appendContentCharacter:'"'];
62   }
63   if (_size) {
64     [_resp appendContentString:@" size=\""];
65     [_resp appendContentHTMLAttributeValue:_size];
66     [_resp appendContentCharacter:'"'];
67   }
68   [_resp appendContentCharacter:'>'];
69 }
70
71 static inline void ODRAppendTD(WOResponse *_resp,
72                                NSString   *_align,
73                                NSString   *_valign,
74                                NSString   *_bgColor,
75                                NSString   *_colspan)
76 {
77   [_resp appendContentString:@"<td"];
78   if (_bgColor) {
79     [_resp appendContentString:@" bgcolor=\""];
80     [_resp appendContentHTMLAttributeValue:_bgColor];
81     [_resp appendContentCharacter:'"'];
82   }
83   if (_align) {
84     [_resp appendContentString:@" align=\""];
85     [_resp appendContentHTMLAttributeValue:_align];
86     [_resp appendContentCharacter:'"'];
87   }
88   if (_valign) {
89     [_resp appendContentString:@" valign=\""];
90     [_resp appendContentHTMLAttributeValue:_valign];
91     [_resp appendContentCharacter:'"'];
92   }
93   if (_colspan) {
94     [_resp appendContentString:@" colspan=\""];
95     [_resp appendContentHTMLAttributeValue:_colspan];
96     [_resp appendContentCharacter:'"'];
97   }
98   [_resp appendContentCharacter:'>'];
99 }
100
101 static inline void ODRAppendButton(WOResponse *_response,
102                                    NSString   *_name,
103                                    NSString   *_src,
104                                    NSString   *_alt)
105 {
106   
107   if (_name == nil) {
108     [_response appendContentHTMLString:(_alt) ? _alt : @"[button]"];
109     return;
110   }
111   [_response appendContentString:@"<input border=\"0\" type=\""];
112   [_response appendContentString:(_src) ? @"image" : @"submit"];
113   [_response appendContentString:@"\" name=\""];
114   [_response appendContentString:_name];
115   [_response appendContentCharacter:'"'];
116   if (_src) {
117     [_response appendContentString:@" src=\""];
118     [_response appendContentString:_src];
119     [_response appendContentCharacter:'"'];
120     // append alt-text
121     if (_alt) {
122       [_response appendContentString:@" alt=\""];
123       [_response appendContentString:_alt];
124       [_response appendContentCharacter:'"'];
125     }
126   }
127   else {
128     [_response appendContentString:@" value=\""];
129     [_response appendContentString:(_alt) ? _alt : @"submit"];
130     [_response appendContentCharacter:'"'];
131   }
132   [_response appendContentString:@" />"];
133 }
134
135 static inline void ODRAppendImage(WOResponse *_response,
136                                    NSString   *_name,
137                                    NSString   *_src,
138                                    NSString   *_alt)
139 {
140   if (_src == nil) {
141     [_response appendContentHTMLString:(_alt) ? _alt : @"[img]"];
142     return;
143   }
144
145   [_response appendContentString:@"<img border=\"0\" src=\""];
146   [_response appendContentString:_src];
147   if (_name) {
148     [_response appendContentString:@"\" name=\""];
149     [_response appendContentString:_name];
150   }
151   [_response appendContentString:@"\" alt=\""];
152   [_response appendContentString:_alt];
153   [_response appendContentString:@"\" />"];
154 }
155
156
157 static inline NSArray *ODRLookupQueryPath(id _node, NSString *_path) {
158   static Class arrayClass = Nil;
159   id     tmp;
160
161   if (arrayClass == Nil)
162     arrayClass = [NSArray class];
163
164   if (!(tmp = [_node lookupQueryPath:_path]))
165     return nil;
166   
167   return ([tmp isKindOfClass:arrayClass])
168     ? tmp
169     : [arrayClass arrayWithObject:tmp];
170 }
171
172 static inline NSString *ODRUriOfResource(NSString *_name, WOContext *_ctx) {
173   NSArray           *languages;
174   WOResourceManager *resourceManager;
175   NSString          *uri;
176
177   if (_name == nil)
178     return nil;
179
180   languages = [_ctx hasSession]
181     ? [[_ctx session] languages]
182     : [[_ctx request] browserLanguages];
183
184   if ((resourceManager = [[_ctx component] resourceManager]) == nil)
185     resourceManager = [[_ctx application] resourceManager];
186   
187   uri = [resourceManager urlForResourceNamed:_name
188                          inFramework:nil
189                          languages:languages
190                          request:[_ctx request]];
191   if ([uri rangeOfString:@"/missingresource?"].length > 0)
192     uri = nil;
193   
194   return uri;
195 }
196
197 #if PROFILE
198 #  define BEGIN_PROFILE \
199      { NSTimeInterval __ti = [[NSDate date] timeIntervalSince1970];
200
201 #  define END_PROFILE \
202      __ti = [[NSDate date] timeIntervalSince1970] - __ti;\
203      if (__ti > 0.05) \
204        printf("***PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
205      else if (__ti > 0.005) \
206        printf("PROF[%s]: %0.3fs\n", __PRETTY_FUNCTION__, __ti);\
207      }
208
209 #  define PROFILE_CHECKPOINT(__key__) \
210        printf("---PROF[%s] CP %s: %0.3fs\n", __PRETTY_FUNCTION__, __key__,\
211               [[NSDate date] timeIntervalSince1970] - __ti)
212
213 #else
214 #  define BEGIN_PROFILE {
215 #  define END_PROFILE   }
216 #  define PROFILE_CHECKPOINT(__key__)
217 #endif
218
219 @interface NSObject(AttrNodeNSURI)
220 - (id)attributeNode:(NSString *)_name namespaceURI:(NSString *)_nsuri;
221 @end
222
223 #endif /* __NGObjDOM_common_H__ */