2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #include "NGJavaScriptContext.h"
24 #import <Foundation/Foundation.h>
25 #import <EOControl/EONull.h>
26 #include "../common.h"
28 @implementation NSDictionary(NGJavaScript)
30 - (id)valueForJSPropertyNamed:(NSString *)_key {
31 return [self objectForKey:_key];
34 - (id)_jsfunc_allKeys:(NSArray *)_args {
35 return [self allKeys];
37 - (id)_jsfunc_allKeysForObject:(NSArray *)_args {
38 return [self allKeysForObject:[_args objectAtIndex:0]];
40 - (id)_jsfunc_allValues:(NSArray *)_args {
41 return [self allValues];
44 - (id)_jsfunc_objectForKey:(NSArray *)_args {
45 return [self objectForKey:[_args objectAtIndex:0]];
47 - (id)_jsfunc_objectsForKeys:(NSArray *)_args {
51 notFound = ((count = [_args count]) > 1)
52 ? [_args objectAtIndex:1]
55 return [self objectsForKeys:[_args objectAtIndex:0] notFoundMarker:notFound];
60 - (id)_jsfunc_writeToFile:(NSArray *)_args {
63 atomically = ([_args count] > 1)
64 ? [[_args objectAtIndex:1] boolValue]
67 atomically = [self writeToFile:[[_args objectAtIndex:0] stringValue]
68 atomically:atomically];
69 return [NSNumber numberWithBool:atomically];
72 @end /* NSDictionary(NGJavaScript) */
74 @implementation NSMutableDictionary(NGJavaScript)
76 - (BOOL)takeValue:(id)_value forJSPropertyNamed:(NSString *)_key {
77 if ((_value == nil) || (_key == nil))
80 [self setObject:_value forKey:_key];
86 - (id)_jsfunc_addEntriesFromDictionary:(NSArray *)_args {
90 e = [_args objectEnumerator];
91 while ((d = [e nextObject]))
92 [self addEntriesFromDictionary:d];
95 - (id)_jsfunc_setObjectForKey:(NSArray *)_args {
96 [self setObject:[_args objectAtIndex:0] forKey:[_args objectAtIndex:1]];
99 - (id)_jsfunc_setDictionary:(NSArray *)_args {
100 [self setDictionary:[_args objectAtIndex:0]];
104 /* removing objects */
106 - (id)_jsfunc_removeAllObjects:(NSArray *)_args {
107 [self removeAllObjects];
110 - (id)_jsfunc_removeObjectForKey:(NSArray *)_args {
114 e = [_args objectEnumerator];
115 while ((d = [e nextObject]))
116 [self removeObjectForKey:d];
119 - (id)_jsfunc_removeObjectsForKeys:(NSArray *)_args {
123 e = [_args objectEnumerator];
124 while ((d = [e nextObject]))
125 [self removeObjectsForKeys:d];
129 @end /* NSMutableDictionary(NGJavaScript) */