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

« back to all changes in this revision

Viewing changes to sope-xml/STXSaxDriver/ExtraSTX/StructuredText_XHTML.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) 2004 eXtrapola Srl
 
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
#error does not compile, just for reference!
 
23
 
 
24
#include "StructuredText_XHTML.h"
 
25
#include "common.h"
 
26
 
 
27
@implementation StructuredTextRenderingDelegate_XHTML
 
28
 
 
29
- (NSString *)insertText:(NSString *)_txt inContext:(NSDictionary *)_ctx {
 
30
  return [NSString stringWithFormat:@"<p>%@</p>", _txt];
 
31
}
 
32
 
 
33
- (NSString *)insertItalics:(NSString *)_txt inContext:(NSDictionary *)_ctx {
 
34
  return [NSString stringWithFormat:
 
35
                     @"<span class=\"italics\">%@</span>", _txt];
 
36
}
 
37
 
 
38
- (NSString *)insertUnderline:(NSString *)_txt inContext:(NSDictionary *)_ctx {
 
39
  return [NSString stringWithFormat:
 
40
                     @"<span class=\"underline\">%@</span>", _txt];
 
41
}
 
42
 
 
43
- (NSString *)insertBold:(NSString *)_txt inContext:(NSDictionary *)_ctx {
 
44
  return [NSString stringWithFormat:@"<span class=\"bold\">%@</span>", _txt];
 
45
}
 
46
 
 
47
- (NSString *)insertPreformatted:(NSString *)_txt 
 
48
  inContext:(NSDictionary *)_ctx 
 
49
{
 
50
  return [NSString stringWithFormat:
 
51
                     @"<span class=\"preformatted\">%@</span>", _txt];
 
52
}
 
53
 
 
54
- (NSString *)insertLink:(NSString *)_txt 
 
55
  withUrl:(NSString *)anUrl target:(NSString *)aTarget 
 
56
  inContext:(NSDictionary *)_ctx 
 
57
{
 
58
  NSString *result;
 
59
 
 
60
  if ([aTarget length] > 0) {
 
61
    result = [NSString stringWithFormat:
 
62
                         @"<a href=\"%@\" target=\"%@\">%@</a>", 
 
63
                         anUrl, aTarget, _txt];
 
64
  } 
 
65
  else {
 
66
    result = [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", anUrl, _txt];
 
67
  }
 
68
  
 
69
  return result;
 
70
}
 
71
 
 
72
- (NSString *)insertEmail:(NSString *)_txt withAddress:(NSString *)anAddress 
 
73
  inContext:(NSDictionary *)_ctx 
 
74
{
 
75
  return [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", anAddress, _txt];
 
76
}
 
77
 
 
78
- (NSString *)insertImage:(NSString *)_txt withUrl:(NSString *)anUrl 
 
79
  inContext:(NSDictionary *)_ctx 
 
80
{
 
81
  return [NSString stringWithFormat:@"<img src=\"%@\" title=\"%@\" />", 
 
82
                     anUrl, _txt];
 
83
}
 
84
 
 
85
- (NSString *)insertExtrapolaLink:(NSString *)_txt 
 
86
  parameters:(NSDictionary *)someParameters withTarget:(NSString *)aTarget 
 
87
  inContext:(NSDictionary *)_ctx 
 
88
{
 
89
  NSString      *result;
 
90
  NSString      *targetString;
 
91
 
 
92
        
 
93
  if ([aTarget length] > 0)
 
94
    targetString = [NSString stringWithFormat:@" target = \"%@\"", aTarget];
 
95
  else
 
96
    targetString = @"";
 
97
  
 
98
  result = [NSString stringWithFormat:
 
99
                       @"<a href=\"/cgi-bin/WebObjects/NewsX.woa/wa/%@\" %@>%@</a>", 
 
100
                     [someParameters objectForKey:@"page"], 
 
101
                     targetString, _txt];
 
102
 
 
103
  return result;
 
104
}
 
105
 
 
106
- (NSString *)insertPreprocessedTextForKey:(NSString *)aKey 
 
107
  inContext:(NSDictionary *)_ctx 
 
108
{
 
109
  return [_ctx objectForKey:aKey];
 
110
}
 
111
 
 
112
@end /* StructuredTextRenderingDelegate_XHTML */
 
113
 
 
114
@implementation NSArray (StructuredText_XHTML)
 
115
 
 
116
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
117
  NSMutableString       *result;
 
118
  int   i,c;
 
119
 
 
120
  c = [self count];
 
121
  result = [NSMutableString stringWithCapacity:(c * 16)];
 
122
  for (i = 0; i < c; i++) {
 
123
    id  currentObject;
 
124
 
 
125
    currentObject = [self objectAtIndex:i];
 
126
    [result appendString:[currentObject toXhtmlInContext:_ctx]];
 
127
  }
 
128
 
 
129
  return result;
 
130
}
 
131
 
 
132
@end
 
133
 
 
134
@implementation StructuredText(StructuredText_XHTML)
 
135
 
 
136
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
137
  return [[self document] toXhtmlInContext:_ctx];
 
138
}
 
139
 
 
140
@end /* StructuredText(StructuredText_XHTML) */
 
141
 
 
142
@implementation StructuredTextDocument(StructuredText_XHTML)
 
143
 
 
144
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
145
  return [[self bodyElements] toXhtmlInContext:_ctx];
 
146
}
 
147
 
 
148
@end /* StructuredTextDocument(StructuredText_XHTML) */
 
149
 
 
150
@implementation StructuredTextBodyElement(StructuredText_XHTML)
 
151
 
 
152
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
153
  return [[self elements] toXhtmlInContext:_ctx];
 
154
}
 
155
 
 
156
@end /* StructuredTextBodyElement(StructuredText_XHTML) */
 
157
 
 
158
@implementation StructuredTextHeader(StructuredText_XHTML)
 
159
 
 
160
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
161
  NSMutableString *ms;
 
162
  id delegate;
 
163
  
 
164
  delegate = [StructuredTextRenderingDelegate_XHTML delegate] ;
 
165
  
 
166
  ms = [NSMutableString stringWithCapacity:64];
 
167
  [ms appendFormat:@"<h%d>", [self level]];
 
168
  [ms appendString:[self textParsedWithDelegate:delegate inContext:_ctx]];
 
169
  [ms appendFormat:@"</h%d>", [self level]];
 
170
  
 
171
  [ms appendString:[super toXhtmlInContext:_ctx]];
 
172
  return ms;
 
173
}
 
174
 
 
175
@end /* StructuredTextHeader(StructuredText_XHTML) */
 
176
 
 
177
@implementation StructuredTextParagraph(StructuredText_XHTML)
 
178
 
 
179
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
180
  id delegate;
 
181
 
 
182
  delegate = [StructuredTextRenderingDelegate_XHTML delegate];
 
183
  return [self textParsedWithDelegate:delegate inContext:_ctx];
 
184
}
 
185
 
 
186
@end /* StructuredTextParagraph (StructuredText_XHTML) */
 
187
 
 
188
@implementation StructuredTextList(StructuredText_XHTML)
 
189
 
 
190
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
191
  NSString *result;
 
192
  NSString *elemText;
 
193
  
 
194
  elemText = [[self elements] toXhtmlInContext:_ctx];
 
195
  
 
196
  switch ([self typology]) {
 
197
    case StructuredTextList_BULLET: {
 
198
      result = [NSString stringWithFormat:@"<ul>%@</ul>", elemText];
 
199
      break;
 
200
    }
 
201
    case StructuredTextList_ENUMERATED: {
 
202
      result = [NSString stringWithFormat:@"<ol>%@</ol>", elemText];
 
203
      break;
 
204
    }
 
205
    case StructuredTextList_DEFINITION: {
 
206
      result = [NSString stringWithFormat:@"<dl>%@</dl>", elemText];
 
207
      break;
 
208
    }
 
209
    default: {
 
210
      result = @"";
 
211
      break;
 
212
    }
 
213
  }
 
214
  return result;
 
215
}
 
216
 
 
217
@end /* StructuredTextList(StructuredText_XHTML) */
 
218
 
 
219
@implementation StructuredTextListItem(StructuredText_XHTML)
 
220
 
 
221
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
222
  NSString *result;
 
223
  NSString *textParsed;
 
224
  NSString *elemText;
 
225
  
 
226
  elemText   = [[self elements] toXhtmlInContext:_ctx];
 
227
  textParsed = [self textParsedWithDelegate:
 
228
                       [StructuredTextRenderingDelegate_XHTML delegate] 
 
229
                     inContext:_ctx];
 
230
 
 
231
  switch ([[self list] typology]) {
 
232
  case StructuredTextList_BULLET: {
 
233
    result = [NSString stringWithFormat:@"<li>%@%@</li>", 
 
234
                       textParsed, elemText];
 
235
    break;
 
236
  }
 
237
  case StructuredTextList_ENUMERATED: {
 
238
    result = [NSString stringWithFormat:@"<li>%@%@</li>", 
 
239
                       textParsed, elemText];
 
240
    break;
 
241
  }
 
242
  case StructuredTextList_DEFINITION: {
 
243
    result = [NSString stringWithFormat:@"<dt>%@</dt><dd>%@</dd>", 
 
244
                       [self titleParsedWithDelegate:
 
245
                               [StructuredTextRenderingDelegate_XHTML delegate] 
 
246
                             inContext:_ctx], 
 
247
                       textParsed];
 
248
    break;
 
249
  }
 
250
  default: {
 
251
    result = @"";
 
252
    break;
 
253
  }
 
254
  }
 
255
 
 
256
  return result;
 
257
}
 
258
 
 
259
@end /* StructuredTextListItem(StructuredText_XHTML) */
 
260
 
 
261
@implementation StructuredTextLiteralBlock(StructuredText_XHTML)
 
262
 
 
263
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
 
264
  return [NSString stringWithFormat:
 
265
                     @"<div class=\"preformatted\">%@</div>", [self text]];
 
266
}
 
267
 
 
268
@end /* StructuredTextLiteralBlock(StructuredText_XHTML) */