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 <NGObjWeb/WOTemplateBuilder.h>
23 #include <NGObjWeb/WOComponent.h>
26 @implementation WOComponentScriptPart
28 - (id)initWithURL:(NSURL *)_url startLine:(unsigned)_ln script:(NSString *)_s {
29 self->url = RETAIN(_url);
30 self->startLine = _ln;
31 self->script = [_s copy];
34 - (id)initWithContentsOfFile:(NSString *)_path {
38 if ([_path length] == 0) {
43 if ((s = [[NSString alloc] initWithContentsOfFile:_path]) == nil) {
48 furl = [[NSURL alloc] initFileURLWithPath:_path];
49 self = [self initWithURL:furl startLine:0 script:s];
57 RELEASE(self->script);
63 - (NSException *)handleException:(NSException *)_exception {
64 if (self->startLine == 0)
67 if ([[_exception name] isEqualToString:@"JavaScriptError"]) {
68 /* correct script start lines to actual value */
69 NSMutableDictionary *ui;
72 ui = [[_exception userInfo] mutableCopy];
73 line = [[ui objectForKey:@"line"] intValue];
74 if (ui == nil) ui = [[NSMutableDictionary alloc] init];
75 [ui setObject:[NSNumber numberWithInt:(line + self->startLine)]
77 [_exception setUserInfo:ui];
83 - (void)initScriptWithComponent:(WOComponent *)_object {
85 [self errorWithFormat:@"cannot apply script on object: %@", _object];
87 /* fixed on JavaScript, part should have a language ... */
89 [_object evaluateScript:self->script language:@"javascript"
90 source:[self->url absoluteString] line:self->startLine];
93 [[self handleException:localException] raise];
100 - (NSString *)description {
103 ms = [NSMutableString stringWithCapacity:32];
104 [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
107 if ([self->url isFileURL])
108 [ms appendFormat:@" path=%@", [self->url path]];
110 [ms appendFormat:@" url=%@", self->url];
111 if (self->startLine > 0)
112 [ms appendFormat:@":%i", self->startLine];
114 else if (self->startLine > 0)
115 [ms appendFormat:@" line=%@", self->startLine];
117 if ([self->script length] == 0)
118 [ms appendString:@" no script"];
119 else if ([self->script length] < 16)
120 [ms appendFormat:@" script=%@", self->script];
122 [ms appendFormat:@" script=%@...", [self->script substringToIndex:13]];
124 [ms appendString:@">"];
128 @end /* WOComponentScriptPart */