Unescape the HREF attribute's text before passing it to NSURL which does not expect...
[adiumx.git] / Source / AICreateCommand.m
blobb73d802640f565bb9d8b4cfa19673f006550d196
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "AICreateCommand.h"
18 #import "NSStringScriptingAdditions.h"
20 @interface NSScriptObjectSpecifier(NSPrivate)
21 + (NSScriptObjectSpecifier *)_objectSpecifierFromDescriptor:(NSAppleEventDescriptor *)desc inCommandConstructionContext:(id)context;
22 @end
24 @implementation AICreateCommand
25 /**
26  * @brief Overrides default NSCreateCommand behavior when creating an object; rather than calling alloc/init, calls make<Key>WithProperties:
27  *
28  * make<Key>WithProperties: is responsible for parsing all options passed to it during creation.
29  * As well, it must insert the new object into the correct container, looking at the Location key if necessary.
30  */
31 - (id)performDefaultImplementation
33 #warning This uses a Private API
34         NSScriptClassDescription *newObjectDescription = [self createClassDescription]; 
35         id target = [self subjectsSpecifier];
37         if (!target)
38                 target = NSApp;
40         id r;
41         NSString *methodName = [NSString stringWithFormat:@"make%@WithProperties:",[[newObjectDescription className] camelCase]];
42         SEL customMethod = NSSelectorFromString(methodName);
44         if ([target respondsToSelector:customMethod])
45         {
46                 //this can do the insert, based on the parameters, methinks.
47                 NSMethodSignature *method = [target methodSignatureForSelector:customMethod];
48                 if (!method)
49                 {
50                         return nil;
51                 }
52                 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method];
53                 [invocation setSelector:customMethod];
54                 NSDictionary *resolvedKeyDictionary = [self evaluatedArguments];
55                 [invocation setArgument:&resolvedKeyDictionary atIndex:2];
56                 [invocation invokeWithTarget:target];
57                 [invocation getReturnValue:&r];
58         }
59         else
60                 r = [super performDefaultImplementation];
61         
62         if ([r isKindOfClass:[NSScriptObjectSpecifier class]])
63                 return r;
64         
65         return [r objectSpecifier];
68 /**
69  * @brief returns the object in the 'subj' key in this apple event.
70  *
71  * This uses a private API. It's the only way I've found to get the target of the 'make' command, which is necessary 
72  * in order to override performDefaultImplementation.
73  */
74 - (id)subjectsSpecifier
76         NSAppleEventDescriptor *subjDesc = [[self appleEvent] attributeDescriptorForKeyword: 'subj'];
77         NSScriptObjectSpecifier *subjSpec = [NSScriptObjectSpecifier _objectSpecifierFromDescriptor: subjDesc inCommandConstructionContext: nil];
78         return [subjSpec objectsByEvaluatingSpecifier];
80 @end