]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOVBScript.m
renamed packages as discussed in the developer list
[sope] / sope-appserver / NGObjWeb / DynamicElements / WOVBScript.m
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 #include "WOHTMLDynamicElement.h"
24 #include "WOElement+private.h"
25 #include <NGObjWeb/WOResourceManager.h>
26 #include <NGObjWeb/WOApplication.h>
27 #include "common.h"
28
29 @interface WOVBScript : WOHTMLDynamicElement
30 {
31   // WODynamicElement: extraAttributes
32   // WODynamicElement: otherTagString
33 @protected
34   WOAssociation *scriptFile;
35   WOAssociation *scriptString;
36   WOAssociation *scriptSource;
37   WOAssociation *hideInComment;
38 }
39
40 @end /* WOVBScript */
41
42 @implementation WOVBScript
43
44 - (id)initWithName:(NSString *)_name
45   associations:(NSDictionary *)_config
46   template:(WOElement *)_tmpl
47 {
48   if ((self = [super initWithName:_name associations:_config template:_tmpl])) {
49     self->scriptFile    = OWGetProperty(_config, @"scriptFile");
50     self->scriptString  = OWGetProperty(_config, @"scriptString");
51     self->scriptSource  = OWGetProperty(_config, @"scriptSource");
52     self->hideInComment = OWGetProperty(_config, @"hideInComment");
53   }
54   return self;
55 }
56
57 #if !LIB_FOUNDATION_BOEHM_GC
58 - (void)dealloc {
59   RELEASE(self->scriptFile);
60   RELEASE(self->scriptString);
61   RELEASE(self->scriptSource);
62   RELEASE(self->hideInComment);
63   [super dealloc];
64 }
65 #endif
66
67 // ******************** responder ********************
68
69 #define StrVal(__x__) [self->__x__ stringValueInComponent:sComponent]
70
71 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
72   if (![[_ctx request] isFromClientComponent]) {
73     WOComponent *sComponent = [_ctx component];
74     BOOL hide = [self->hideInComment boolValueInComponent:sComponent];
75     
76     WOResponse_AddCString(_response, "<script language=\"VBScript\" ");
77
78     /* add URL to script */
79     if (self->scriptSource) {
80       WOResponse_AddCString(_response, " src=\"");
81       [_response appendContentHTMLAttributeValue:
82                    [self->scriptSource stringValueInComponent:sComponent]];
83       WOResponse_AddCString(_response, "\"");
84     }
85     
86     if (self->otherTagString) {
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 */