2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
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
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.
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
22 #include "WOHTMLDynamicElement.h"
23 #include "WOElement+private.h"
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOApplication.h>
28 @interface WOVBScript : WOHTMLDynamicElement
30 // WODynamicElement: extraAttributes
31 // WODynamicElement: otherTagString
33 WOAssociation *scriptFile;
34 WOAssociation *scriptString;
35 WOAssociation *scriptSource;
36 WOAssociation *hideInComment;
41 @implementation WOVBScript
43 - (id)initWithName:(NSString *)_name
44 associations:(NSDictionary *)_config
45 template:(WOElement *)_tmpl
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");
56 #if !LIB_FOUNDATION_BOEHM_GC
58 RELEASE(self->scriptFile);
59 RELEASE(self->scriptString);
60 RELEASE(self->scriptSource);
61 RELEASE(self->hideInComment);
66 // ******************** responder ********************
68 #define StrVal(__x__) [self->__x__ stringValueInComponent:sComponent]
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];
75 WOResponse_AddCString(_response, "<script language=\"VBScript\" ");
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, "\"");
85 if (self->otherTagString) {
86 WOResponse_AddChar(_response, ' ');
87 WOResponse_AddString(_response,
88 [self->otherTagString stringValueInComponent:
91 WOResponse_AddChar(_response, '>');
92 if (hide) WOResponse_AddCString(_response, "<!--hide from older browsers");
94 /* add a script string */
95 if (self->scriptString) {
96 NSString *s = [self->scriptString stringValueInComponent:sComponent];
98 if (s) WOResponse_AddString(_response, s);
101 /* add a script file */
102 if (self->scriptFile) {
105 s = [NSString stringWithContentsOfFile:
106 [self->scriptFile stringValueInComponent:sComponent]];
107 if (s) WOResponse_AddString(_response, s);
110 if (hide) WOResponse_AddCString(_response, "//hide from older browsers-->");
111 WOResponse_AddCString(_response, "</script>");
117 - (NSString *)associationDescription {
118 NSMutableString *str = [[NSMutableString alloc] init];
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];
126 return AUTORELEASE(str);
129 @end /* WOVBScript */