~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/NGObjWeb/DynamicElements/_WOTemporaryHyperlink.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "WOHyperlinkInfo.h"
 
24
#include "WOCompoundElement.h"
 
25
#include <NGObjWeb/WOAssociation.h>
 
26
#include "common.h"
 
27
 
 
28
@implementation _WOTemporaryHyperlink
 
29
 
 
30
static Class _WOSimpleActionHyperlinkClass       = Nil;
 
31
static Class _WOSimpleStringActionHyperlinkClass = Nil;
 
32
static Class _WOActionHyperlinkClass             = Nil;
 
33
static Class _WOPageHyperlinkClass               = Nil;
 
34
static Class _WOHrefHyperlinkClass               = Nil;
 
35
static Class _WOCommonStaticDAHyperlinkClass     = Nil;
 
36
static Class _WODirectActionHyperlinkClass       = Nil;
 
37
 
 
38
+ (void)initialize {
 
39
  static BOOL didInit = NO;
 
40
  if (didInit) return;
 
41
  didInit = YES;
 
42
 
 
43
  _WOSimpleActionHyperlinkClass = 
 
44
    NSClassFromString(@"_WOSimpleActionHyperlink");
 
45
  _WOSimpleStringActionHyperlinkClass = 
 
46
    NSClassFromString(@"_WOSimpleStringActionHyperlink");
 
47
 
 
48
  _WOActionHyperlinkClass = NSClassFromString(@"_WOActionHyperlink");
 
49
  _WOPageHyperlinkClass   = NSClassFromString(@"_WOPageHyperlink");
 
50
  _WOHrefHyperlinkClass   = NSClassFromString(@"_WOHrefHyperlink");
 
51
 
 
52
  _WOCommonStaticDAHyperlinkClass = 
 
53
    NSClassFromString(@"_WOCommonStaticDAHyperlink");
 
54
  _WODirectActionHyperlinkClass = 
 
55
    NSClassFromString(@"_WODirectActionHyperlink");
 
56
}
 
57
 
 
58
- (id)initWithName:(NSString *)_name
 
59
  associations:(NSDictionary *)_config
 
60
  template:(WOElement *)_t
 
61
{
 
62
  WOHyperlinkInfo *info;
 
63
  Class linkClass = Nil;
 
64
  
 
65
  if ((info = [[WOHyperlinkInfo alloc] initWithConfig:(id)_config]) == nil) {
 
66
    return nil;
 
67
  }
 
68
  
 
69
  if (info->action) {
 
70
    if (info->assocCount == 0)
 
71
      linkClass = [_WOSimpleActionHyperlinkClass class];
 
72
    else if ((info->assocCount == 1) && (info->string != nil))
 
73
      linkClass = [_WOSimpleStringActionHyperlinkClass class];
 
74
    else
 
75
      linkClass = [_WOActionHyperlinkClass class];
 
76
  }
 
77
  else if (info->pageName) {
 
78
    linkClass = [_WOPageHyperlinkClass class];
 
79
  }
 
80
  else if (info->href) {
 
81
    linkClass = [_WOHrefHyperlinkClass class];
 
82
  }
 
83
  else if (info->directActionName) {
 
84
    linkClass = Nil;
 
85
    
 
86
    if (info->assocCount < 3) {
 
87
      if ([info->directActionName isValueConstant]) {
 
88
        if (info->actionClass == nil ||
 
89
            ([info->actionClass isValueConstant])) {
 
90
          if (info->assocCount == 1) {
 
91
            if (info->queryParameters != nil || info->string != nil)
 
92
              linkClass = [_WOCommonStaticDAHyperlinkClass class];
 
93
          }
 
94
          else if (info->assocCount == 2 &&
 
95
                   (info->queryParameters != nil) &&
 
96
                   (info->string != nil)) {
 
97
            linkClass = [_WOCommonStaticDAHyperlinkClass class];
 
98
          }
 
99
        }
 
100
      }
 
101
    }
 
102
 
 
103
    if (linkClass == Nil)
 
104
      linkClass = [_WODirectActionHyperlinkClass class];
 
105
  }
 
106
  else {
 
107
    NSLog(@"%s: found no setting for link named '%@', assocs %@",
 
108
          __PRETTY_FUNCTION__, _name, _config);
 
109
    return nil;
 
110
  }
 
111
  
 
112
  self =
 
113
    [[linkClass alloc] initWithName:_name hyperlinkInfo:info template:_t];
 
114
  [info release]; info = nil;
 
115
  return self;
 
116
}
 
117
 
 
118
- (id)initWithName:(NSString *)_name
 
119
  associations:(NSDictionary *)_associations
 
120
  contentElements:(NSArray *)_contents
 
121
{
 
122
  WOCompoundElement *template;
 
123
  int count;
 
124
  
 
125
  count = [_contents count];
 
126
  
 
127
  if (count == 0) {
 
128
    template = nil;
 
129
  }
 
130
  else if (count == 1) {
 
131
    template = [_contents objectAtIndex:0];
 
132
  }
 
133
  else {
 
134
    template = [[WOCompoundElement allocForCount:[_contents count]
 
135
                                   zone:[self zone]]
 
136
                                   initWithContentElements:_contents];
 
137
  }
 
138
  
 
139
  return [self initWithName:_name
 
140
               associations:_associations
 
141
               template:template];
 
142
}
 
143
 
 
144
- (void)dealloc {
 
145
  NSLog(@"ERROR: called dealloc on %@", self);
 
146
#if DEBUG
 
147
  abort();
 
148
#endif
 
149
  return;
 
150
}
 
151
 
 
152
@end /* _WOTemporaryHyperlink */