]> err.no Git - sope/blob - sope-appserver/WEExtensions/JSClipboard.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / JSClipboard.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGObjWeb/NGObjWeb.h>
23 #include <NGObjWeb/WEClientCapabilities.h>
24 #include "common.h"
25
26 @interface JSClipboard : WODynamicElement
27 {
28   WOAssociation *filename;
29   WOAssociation *imgURL;
30   WOAssociation *string;
31   WOAssociation *toolTip;
32   WOAssociation *value;
33 }
34 @end
35
36 @implementation JSClipboard
37
38 - (id)initWithName:(NSString *)_name
39   associations:(NSDictionary *)_config
40   template:(WOElement *)_subs
41 {
42   if((self = [super initWithName:_name associations:_config template:_subs])) {
43     self->filename = OWGetProperty(_config,@"filename");
44     self->imgURL   = OWGetProperty(_config,@"imgURL");
45     self->string   = OWGetProperty(_config,@"string");
46     self->toolTip  = OWGetProperty(_config,@"toolTip");
47     self->value    = OWGetProperty(_config,@"value");
48   }
49   return self;
50 }
51
52 - (void)dealloc {
53   [self->imgURL  release];
54   [self->string  release];
55   [self->toolTip release];
56   [self->value   release];
57   [super dealloc];
58 }
59
60 /* operations */
61
62 - (NSString *)imageByFilename:(NSString *)_name
63   inContext:(WOContext *)_ctx
64   framework:(NSString *)_framework
65 {
66   WOResourceManager *rm;
67   NSString          *tmp;
68   NSArray           *languages;
69
70   rm        = [[_ctx application] resourceManager];
71   languages = [_ctx resourceLookupLanguages];
72   tmp       = [rm urlForResourceNamed:_name
73                   inFramework:_framework
74                   languages:languages
75                   request:[_ctx request]];
76   return tmp;
77 }
78
79 - (void)appendToResponse:(WOResponse *)_response
80                inContext:(WOContext *)_ctx
81 {
82   WOComponent          *comp;
83   NSString             *tmp;
84   NSString             *tt;    // toolTip
85   WEClientCapabilities *ccaps;
86
87   comp    = [_ctx component];
88   ccaps   = [[_ctx request] clientCapabilities];
89   tt      = [self->toolTip stringValueInComponent:comp];
90   tt      = tt ? tt : @"";
91
92   if (![ccaps isInternetExplorer]) return;
93   if ([ccaps isMacBrowser]) return;
94
95   tmp = [[NSString alloc] initWithFormat:
96                   @"<a href=\"#\" onclick=\"javascript:clipboardData."
97                   @"setData('text', '%@');return false;\" title=\"%@\">",
98                   [self->value stringValueInComponent:comp], tt];
99   [_response appendContentString:tmp];
100   [tmp release]; tmp = nil;
101   
102   NSAssert(self->imgURL != nil || self->string != nil || self->filename != nil,
103            @"ERROR: no imageURL or string defined...");
104
105   if (self->filename) {
106     NSString *imageFilename;
107
108     imageFilename =
109       [self imageByFilename:[self->filename stringValueInComponent:comp]
110             inContext:_ctx
111             framework:[comp frameworkName]];
112
113     tmp = [[NSString alloc] initWithFormat:
114                     @"<img border=\"0\"src=\"%@\" /></a>",
115                     imageFilename];
116   }
117   else if (self->imgURL) {
118     tmp = [[NSString alloc] initWithFormat:
119                     @"<img border=\"0\"src=\"%@\" /></a>",
120                     [self->imgURL stringValueInComponent:comp]];
121   }
122   else {
123     tmp = [[NSString alloc] initWithFormat:
124                     @"%@</a>",
125                     [self->string stringValueInComponent:comp]];
126   }
127   [_response appendContentString:tmp];
128   [tmp release];
129 }
130
131 @end /* JSClipboard */