/* Copyright (C) 2000-2003 SKYRIX Software AG This file is part of OGo OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include //#include #include "common.h" @interface NSObject(DOMXML) - (void)outputDocument:(id)_document to:(id)_target; - (id)buildFromData:(NSData *)_data; - (id)documentElement; - (void)appendChild:(id)_child; @end @implementation WOMessage(XMLSupport) - (void)_rebuildDOMDataContent { NSMutableString *ms; id outputter; NSData *data; id dom; if ((dom = [[self userInfo] objectForKey:@"WODOMContent"]) == nil) { [self setContent:nil]; return; } outputter = [[NSClassFromString(@"DOMXMLOutputter") alloc] init]; AUTORELEASE(outputter); ms = [NSMutableString stringWithCapacity:2048]; [outputter outputDocument:dom to:ms]; data = [ms dataUsingEncoding:NSUTF8StringEncoding]; [self setContent:data]; } - (void)setContentDOMDocument:(id)_dom { if (_dom == nil) { if ((_dom = [[self userInfo] objectForKey:@"WODOMContent"])) { NSMutableDictionary *ui; ui = [[self userInfo] mutableCopy]; [ui removeObjectForKey:@"WODOMContent"]; [self setUserInfo:ui]; RELEASE(ui); ui = nil; } [self _rebuildDOMDataContent]; return; } else { NSMutableDictionary *ui; /* cache DOM structure in userInfo */ ui = [[self userInfo] mutableCopy]; if (ui == nil) ui = [[NSMutableDictionary alloc] initWithCapacity:2]; [ui setObject:_dom forKey:@"WODOMContent"]; [self setUserInfo:ui]; RELEASE(ui); ui = nil; [self _rebuildDOMDataContent]; } } - (void)appendContentDOMDocumentFragment:(id)_domfrag { id dom; if (_domfrag == nil) return; if ((dom = [self contentAsDOMDocument])) { [[dom documentElement] appendChild:_domfrag]; [self setContentDOMDocument:dom]; } else { [self setContentDOMDocument:_domfrag]; } } - (id)contentAsDOMDocument { NSData *data; id dom; if ((dom = [[self userInfo] objectForKey:@"WODOMContent"])) return dom; if ((data = [self content])) { id builder; builder = [[[NSClassFromString(@"DOMSaxBuilder") alloc] init] autorelease]; dom = [[builder buildFromData:data] retain]; } /* cache DOM structure in userInfo */ if (dom) { NSMutableDictionary *ui; ui = [[self userInfo] mutableCopy]; if (ui == nil) ui = [[NSMutableDictionary alloc] initWithCapacity:2]; [ui setObject:dom forKey:@"WODOMContent"]; [self setUserInfo:ui]; RELEASE(ui); ui = nil; } return dom; } @end /* WOMessage */