]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOHyperlink.m
started TAL element builder
[sope] / sope-appserver / NGObjWeb / DynamicElements / WOHyperlink.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 "WOHyperlink.h"
23 #include "WOElement+private.h"
24 #include "WOHyperlinkInfo.h"
25 #include "WOCompoundElement.h"
26 #include <NGObjWeb/WOApplication.h>
27 #include <NGObjWeb/WOResourceManager.h>
28 #include <NGExtensions/NSString+Ext.h>
29 #include "decommon.h"
30
31 #define PROFILE_CLUSTERS 0
32
33 #if PROFILE_CLUSTERS
34 #  warning HYPERLINK CLUSTER PROFILING IS TURNED ON !!!
35 #endif
36
37 // TODO(perf): all adding of links to an anker can probably be added using
38 //             appendContentCString because they are already escaped
39 //             => check that for umlauts in downloads !
40
41 /*
42   WOHyperlink associations:
43
44     href | pageName | action | (directActionName & actionClass)
45     fragmentIdentifier
46     string
47     target
48     disabled
49     queryDictionary
50
51   Concrete Class Hierachy
52
53     _WOTemporaryHyperlink
54     WOHTMLDynamicElement
55       WOHyperlink
56         _WOComplexHyperlink
57           _WOHrefHyperlink
58           _WOActionHyperlink
59           _WOPageHyperlink
60           _WODirectActionHyperlink
61         _WOSimpleActionHyperlink
62           _WOSimpleStringActionHyperlink
63         _WOCommonStaticDAHyperlink
64 */
65
66 @implementation WOHyperlink
67
68 + (int)version {
69   return [super version] + 2 /* v4 */;
70 }
71 + (void)initialize {
72   NSAssert2([super version] == 2,
73             @"invalid superclass (%@) version %i !",
74             NSStringFromClass([self superclass]), [super version]);
75 }
76
77 + (id)allocWithZone:(NSZone *)zone {
78   static Class WOHyperlinkClass = Nil;
79   static _WOTemporaryHyperlink *temporaryHyperlink = nil;
80   
81   if (WOHyperlinkClass == Nil)
82     WOHyperlinkClass = [WOHyperlink class];
83   if (temporaryHyperlink == nil)
84     temporaryHyperlink = [_WOTemporaryHyperlink allocWithZone:zone];
85   
86   if (self == WOHyperlinkClass)
87     return temporaryHyperlink;
88   else {
89 #if PROFILE_CLUSTERS
90     static unsigned totalCount        = 0;
91     static unsigned countSimpleAction = 0;
92     static unsigned countAction       = 0;
93     static unsigned countHref         = 0;
94     static unsigned countDirectAction = 0;
95     static unsigned countCommonDA     = 0;
96     static unsigned countOther        = 0;
97     totalCount++;
98     if (self == [_WOSimpleActionHyperlink class])
99       countSimpleAction++;
100     else if (self == [_WOActionHyperlink class])
101       countAction++;
102     else if (self == [_WODirectActionHyperlink class])
103       countDirectAction++;
104     else if (self == [_WOHrefHyperlink class])
105       countHref++;
106     else if (self == NSClassFromString(@"_WOCommonStaticDAHyperlink"))
107       countCommonDA++;
108     else
109       countOther++;
110
111     if (totalCount % 30 == 0) {
112       NSLog(@"WOHyperlink statistics:\n"
113             @" total: %d,"
114             @" simple action: %d,"
115             @" action: %d,"
116             @" direct action: %d,"
117             @" common DA:     %d,"
118             @" href: %d,"
119             @" other: %d",
120             totalCount, countSimpleAction, countAction,
121             countDirectAction, countCommonDA, countHref, countOther);
122     }
123 #endif
124     return NSAllocateObject(self, 0, zone);
125   }
126 }
127
128 - (id)initWithName:(NSString *)_name
129   hyperlinkInfo:(WOHyperlinkInfo *)_info
130   template:(WOElement *)_t
131 {
132   return [super initWithName:_name associations:nil template:_t];
133 }
134
135 @end /* WOHyperlink */