]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOVBScript.m
fixed bundle resource lookup on MacOSX, changed resource lookup in
[sope] / sope-appserver / NGObjWeb / DynamicElements / WOVBScript.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "WOHTMLDynamicElement.h"
23 #include "WOElement+private.h"
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOApplication.h>
26 #include "common.h"
27
28 @interface WOVBScript : WOHTMLDynamicElement
29 {
30   // WODynamicElement: extraAttributes
31   // WODynamicElement: otherTagString
32 @protected
33   WOAssociation *scriptFile;
34   WOAssociation *scriptString;
35   WOAssociation *scriptSource;
36   WOAssociation *hideInComment;
37 }
38
39 @end /* WOVBScript */
40
41 @implementation WOVBScript
42
43 - (id)initWithName:(NSString *)_name
44   associations:(NSDictionary *)_config
45   template:(WOElement *)_tmpl
46 {
47   if ((self = [super initWithName:_name associations:_config template:_tmpl])) {
48     self->scriptFile    = OWGetProperty(_config, @"scriptFile");
49     self->scriptString  = OWGetProperty(_config, @"scriptString");
50     self->scriptSource  = OWGetProperty(_config, @"scriptSource");
51     self->hideInComment = OWGetProperty(_config, @"hideInComment");
52   }
53   return self;
54 }
55
56 #if !LIB_FOUNDATION_BOEHM_GC
57 - (void)dealloc {
58   RELEASE(self->scriptFile);
59   RELEASE(self->scriptString);
60   RELEASE(self->scriptSource);
61   RELEASE(self->hideInComment);
62   [super dealloc];
63 }
64 #endif
65
66 // ******************** responder ********************
67
68 #define StrVal(__x__) [self->__x__ stringValueInComponent:sComponent]
69
70 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
71   if (![[_ctx request] isFromClientComponent]) {
72     WOComponent *sComponent = [_ctx component];
73     BOOL hide = [self->hideInComment boolValueInComponent:sComponent];
74     
75     WOResponse_AddCString(_response, "<script language=\"VBScript\" ");
76
77     /* add URL to script */
78     if (self->scriptSource) {
79       WOResponse_AddCString(_response, " src=\"");
80       [_response appendContentHTMLAttributeValue:
81                    [self->scriptSource stringValueInComponent:sComponent]];
82       WOResponse_AddCString(_response, "\"");
83     }
84     
85     if (self->otherTagString) {
86       WOResponse_AddChar(_response, ' ');
87       WOResponse_AddString(_response,
88                            [self->otherTagString stringValueInComponent:
89                                                    [_ctx component]]);
90     }
91     WOResponse_AddChar(_response, '>');
92     if (hide) WOResponse_AddCString(_response, "<!--hide from older browsers");
93
94     /* add a script string */
95     if (self->scriptString) {
96       NSString *s = [self->scriptString stringValueInComponent:sComponent];
97
98       if (s) WOResponse_AddString(_response, s);
99     }
100
101     /* add a script file */
102     if (self->scriptFile) {
103       NSString *s;
104
105       s = [NSString stringWithContentsOfFile:
106                       [self->scriptFile stringValueInComponent:sComponent]];
107       if (s) WOResponse_AddString(_response, s);
108     }
109     
110     if (hide) WOResponse_AddCString(_response, "//hide from older browsers-->");
111     WOResponse_AddCString(_response, "</script>");
112   }
113 }
114
115 // description
116
117 - (NSString *)associationDescription {
118   NSMutableString *str = [[NSMutableString alloc] init];
119
120   if (self->scriptFile)    [str appendFormat:@" file=%@",   self->scriptFile];
121   if (self->scriptString)  [str appendFormat:@" string=%@", self->scriptString];
122   if (self->scriptSource)  [str appendFormat:@" source=%@", self->scriptSource];
123   if (self->hideInComment)
124     [str appendFormat:@" hide=%@",   self->hideInComment];
125   
126   return AUTORELEASE(str);
127 }
128
129 @end /* WOVBScript */