]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOMessage+XML.m
fixed gcc 4.0 warnings
[sope] / sope-appserver / NGObjWeb / WOMessage+XML.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/WOMessage.h>
23 #include "common.h"
24
25 @interface NSObject(DOMXML)
26 - (void)outputDocument:(id)_document to:(id)_target;
27 - (id)buildFromData:(NSData *)_data;
28 - (id)documentElement;
29 - (void)appendChild:(id)_child;
30 @end
31
32 @implementation WOMessage(XMLSupport)
33
34 - (void)_rebuildDOMDataContent {
35   NSMutableString *ms;
36   id     outputter;
37   NSData *data;
38   id     dom;
39   
40   if ((dom = self->domCache) == nil) {
41     [self setContent:nil];
42     return;
43   }
44   
45   outputter =
46     [[[NSClassFromString(@"DOMXMLOutputter") alloc] init] autorelease];
47   
48   ms = [NSMutableString stringWithCapacity:2048];
49   [outputter outputDocument:dom to:ms];
50   
51   data = [ms dataUsingEncoding:NSUTF8StringEncoding];
52
53   [self setContent:data];
54 }
55
56 - (void)setContentDOMDocument:(id)_dom {
57   ASSIGN(self->domCache, _dom);
58   [self _rebuildDOMDataContent];
59 }
60
61 - (void)appendContentDOMDocumentFragment:(id)_domfrag {
62   id dom;
63   
64   if (_domfrag == nil)
65     return;
66   
67   if ((dom = [self contentAsDOMDocument])) {
68     [[dom documentElement] appendChild:_domfrag];
69     [self setContentDOMDocument:dom];
70   }
71   else {
72     [self setContentDOMDocument:_domfrag];
73   }
74 }
75
76 - (id)contentAsDOMDocument {
77   NSData *data;
78   id dom;
79   
80   if ((dom = self->domCache) != nil)
81     return dom;
82   
83   if ((data = [self content]) != nil) {
84     id builder;
85     
86     builder = [[[NSClassFromString(@"DOMSaxBuilder") alloc] init] autorelease];
87     dom = [[builder buildFromData:data] retain];
88   }
89   
90   /* cache DOM structure */
91   if (dom != nil) {
92     ASSIGN(self->domCache, dom);
93   }
94   return dom;
95 }
96
97 @end /* WOMessage */