From 6cc58a77461ee5159d564251dbdbc11aa6be9cd9 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 25 Aug 2004 10:06:14 +0000 Subject: [PATCH] enhanced input support in libxmlSAXdriver for HTML, changed factory for WOTemplateBuilder objects git-svn-id: http://svn.opengroupware.org/SOPE/trunk@54 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 10 ++++ .../NGObjWeb/DynamicElements/WOConditional.m | 1 - .../NGObjWeb/NGObjWeb/WOTemplateBuilder.h | 4 -- .../NGObjWeb/Templates/WOTemplateBuilder.m | 44 +-------------- .../Templates/WOWrapperTemplateBuilder.m | 5 +- .../NGObjWeb/Templates/WOxTemplateBuilder.m | 33 +++++++---- sope-appserver/NGObjWeb/Version | 2 +- .../NGObjWeb/WOComponentDefinition.m | 36 +++++++++++- .../NGExtensions/NGExtensions/NSURL+misc.h | 5 +- sope-xml/DOM/ChangeLog | 5 ++ sope-xml/DOM/DOMSaxHandler.m | 29 +++++----- sope-xml/DOM/Version | 4 +- sope-xml/libxmlSAXDriver/ChangeLog | 10 ++++ sope-xml/libxmlSAXDriver/Version | 4 +- sope-xml/libxmlSAXDriver/libxmlDocSAXDriver.m | 33 ++++++++--- .../libxmlSAXDriver/libxmlHTMLSAXDriver.m | 55 ++++++++++++++++++- 16 files changed, 189 insertions(+), 91 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index b2e0dbe5..b272d88e 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,13 @@ +2004-08-25 Helge Hess + + * v4.3.12 + + * Templates/WOxTemplateBuilder.m: properly select a DOM builder based + on the template extension + + * Templates/WOTemplateBuilder.m, WOComponentDefinition.m: moved + builder factory to WOComponentDefinition + 2004-08-24 Helge Hess * changed bundles to install in "xxx-4.3" pathes instead of "xxx/4.3" diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOConditional.m b/sope-appserver/NGObjWeb/DynamicElements/WOConditional.m index d8b2c5fe..74db45a1 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOConditional.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOConditional.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id: WOConditional.m 1 2004-08-20 10:08:27Z znek $ #include diff --git a/sope-appserver/NGObjWeb/NGObjWeb/WOTemplateBuilder.h b/sope-appserver/NGObjWeb/NGObjWeb/WOTemplateBuilder.h index cb276c53..4640ab29 100644 --- a/sope-appserver/NGObjWeb/NGObjWeb/WOTemplateBuilder.h +++ b/sope-appserver/NGObjWeb/NGObjWeb/WOTemplateBuilder.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGObjWeb_WOTemplateBuilder_H__ #define __NGObjWeb_WOTemplateBuilder_H__ @@ -34,9 +33,6 @@ { } -+ (WOTemplateBuilder *)templateBuilderForPath:(NSString *)_path; -+ (WOTemplateBuilder *)templateBuilderForURL:(NSURL *)_url; - - (WOTemplate *)buildTemplateAtURL:(NSURL *)_url; @end diff --git a/sope-appserver/NGObjWeb/Templates/WOTemplateBuilder.m b/sope-appserver/NGObjWeb/Templates/WOTemplateBuilder.m index c6db9519..980f6978 100644 --- a/sope-appserver/NGObjWeb/Templates/WOTemplateBuilder.m +++ b/sope-appserver/NGObjWeb/Templates/WOTemplateBuilder.m @@ -18,56 +18,18 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ +// $Id: WOTemplateBuilder.m 1 2004-08-20 10:08:27Z znek $ #include #include "common.h" @implementation WOTemplateBuilder -static NSArray *woxExtensions = nil; - + (int)version { - return 1; -} -+ (void)initialize { - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - woxExtensions = [[ud arrayForKey:@"WOxFileExtensions"] copy]; + return 2; } -/* builder factory */ - -+ (WOTemplateBuilder *)templateBuilderForPath:(NSString *)_path { - NSString *ext; - - if ([_path length] == 0) - return nil; - - ext = [_path pathExtension]; - if ([woxExtensions containsObject:ext]) { - static WOTemplateBuilder *woxBuilder = nil; - if (woxBuilder == nil) - woxBuilder = [[NSClassFromString(@"WOxTemplateBuilder") alloc] init]; - return woxBuilder; - } - - { - static WOTemplateBuilder *woBuilder = nil; - if (woBuilder == nil) { - woBuilder = - [[NSClassFromString(@"WOWrapperTemplateBuilder") alloc] init]; - } - return woBuilder; - } -} - -+ (WOTemplateBuilder *)templateBuilderForURL:(NSURL *)_url { - if ([_url isFileURL]) - return [self templateBuilderForPath:[_url path]]; - - [self logWithFormat:@"only supports file URLs: %@", _url]; - return nil; -} +/* building */ - (WOTemplate *)buildTemplateAtURL:(NSURL *)_url { #if APPLE_FOUNDATION_LIBRARY || NeXT_Foundation_LIBRARY diff --git a/sope-appserver/NGObjWeb/Templates/WOWrapperTemplateBuilder.m b/sope-appserver/NGObjWeb/Templates/WOWrapperTemplateBuilder.m index 4b360223..0cb83705 100644 --- a/sope-appserver/NGObjWeb/Templates/WOWrapperTemplateBuilder.m +++ b/sope-appserver/NGObjWeb/Templates/WOWrapperTemplateBuilder.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "WOWrapperTemplateBuilder.h" #include "WODParser.h" @@ -68,12 +67,12 @@ static BOOL logScriptAdditions = NO; static NSStringEncoding parserEncoding; + (int)version { - return [super version] + 0 /* v1 */; + return [super version] + 0 /* v2 */; } + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - NSAssert2([super version] == 1, + NSAssert2([super version] == 2, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); diff --git a/sope-appserver/NGObjWeb/Templates/WOxTemplateBuilder.m b/sope-appserver/NGObjWeb/Templates/WOxTemplateBuilder.m index eede0d9a..ea01ff0c 100644 --- a/sope-appserver/NGObjWeb/Templates/WOxTemplateBuilder.m +++ b/sope-appserver/NGObjWeb/Templates/WOxTemplateBuilder.m @@ -33,11 +33,11 @@ static BOOL profLoading = NO; static Class DateClass = Nil; + (int)version { - return [super version] + 0 /* v1 */; + return [super version] + 0 /* v2 */; } + (void)initialize { - NSAssert2([super version] == 1, + NSAssert2([super version] == 2, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); @@ -104,11 +104,20 @@ static Class DateClass = Nil; return template; } -- (id)xmlParser { - //static id builder = nil; +- (id)xmlParserForURL:(NSURL *)_url { + static DOMBuilderFactory *factory = nil; - return [[DOMBuilderFactory standardDOMBuilderFactory] - createDOMBuilderForMimeType:@"text/xml"]; + if (factory == nil) + factory = [[DOMBuilderFactory standardDOMBuilderFactory] retain]; + + // TODO: somewhat hackish + if ([[_url path] hasSuffix:@".html"]) + return [factory createDOMBuilderForMimeType:@"text/html"]; + if ([[_url path] hasSuffix:@".stx"]) + return [factory createDOMBuilderForMimeType:@"text/structured"]; + + // TODO: do we want to cache the builder? + return [factory createDOMBuilderForMimeType:@"text/xml"]; } - (WOTemplate *)buildTemplateAtURL:(NSURL *)_url { @@ -117,16 +126,20 @@ static Class DateClass = Nil; id builder; WOTemplate *template; - //NSLog(@"loading XML template %@ ...", self->path); +#if 0 + [self logWithFormat:@"loading XML template %@ ...", self->path]; +#endif pool = [[NSAutoreleasePool alloc] init]; - builder = [self xmlParser]; + builder = [self xmlParserForURL:_url]; NSAssert(builder != nil, @"missing XML parser .."); domDocument = [builder buildFromSource:_url]; - //[@"file://" stringByAppendingString:self->path]]; - +#if 0 + [@"file://" stringByAppendingString:self->path]]; +#endif + /* construct template for DOM document */ if (domDocument) { diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 12b8a0d3..955909db 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=9 +SUBMINOR_VERSION:=12 # v4.2.413 requires libSaxObjC v4.2.33 # v4.2.341 requires libNGExtensions v4.2.77 diff --git a/sope-appserver/NGObjWeb/WOComponentDefinition.m b/sope-appserver/NGObjWeb/WOComponentDefinition.m index 9b9200e8..6f61547a 100644 --- a/sope-appserver/NGObjWeb/WOComponentDefinition.m +++ b/sope-appserver/NGObjWeb/WOComponentDefinition.m @@ -191,6 +191,7 @@ static BOOL debugOn = NO; static BOOL profLoading = NO; static BOOL enableClassLessComponents = NO; static BOOL enableWOOFiles = NO; +static NSArray *woxExtensions = nil; + (int)version { return 4; @@ -217,6 +218,7 @@ static BOOL enableWOOFiles = NO; [ud boolForKey:@"WOEnableComponentsWithoutClasses"]; enableWOOFiles = [ud boolForKey:@"WOComponentLoadWOOFiles"]; debugOn = [ud boolForKey:@"WODebugComponentDefinition"]; + woxExtensions = [[ud arrayForKey:@"WOxFileExtensions"] copy]; } - (id)initWithName:(NSString *)_name @@ -497,6 +499,38 @@ static BOOL enableWOOFiles = NO; /* templates */ +- (WOTemplateBuilder *)templateBuilderForPath:(NSString *)_path { + NSString *ext; + + if ([_path length] == 0) + return nil; + + ext = [_path pathExtension]; + if ([woxExtensions containsObject:ext]) { + static WOTemplateBuilder *woxBuilder = nil; + if (woxBuilder == nil) + woxBuilder = [[NSClassFromString(@"WOxTemplateBuilder") alloc] init]; + return woxBuilder; + } + + { + static WOTemplateBuilder *woBuilder = nil; + if (woBuilder == nil) { + woBuilder = + [[NSClassFromString(@"WOWrapperTemplateBuilder") alloc] init]; + } + return woBuilder; + } +} + +- (WOTemplateBuilder *)templateBuilderForURL:(NSURL *)_url { + if ([_url isFileURL]) + return [self templateBuilderForPath:[_url path]]; + + [self logWithFormat:@"only supports file URLs: %@", _url]; + return nil; +} + - (BOOL)load { WOTemplateBuilder *builder; NSURL *url; @@ -518,7 +552,7 @@ static BOOL enableWOOFiles = NO; if (debugOn) [self debugWithFormat:@"url: %@", [url absoluteString]]; // TODO: maybe we should move the builder selection to the resource-manager - builder = [WOTemplateBuilder templateBuilderForURL:url]; + builder = [self templateBuilderForURL:url]; if (debugOn) [self debugWithFormat:@"builder: %@", builder]; self->template = [[builder buildTemplateAtURL:url] retain]; diff --git a/sope-core/NGExtensions/NGExtensions/NSURL+misc.h b/sope-core/NGExtensions/NGExtensions/NSURL+misc.h index 3e751b2d..7e3a0415 100644 --- a/sope-core/NGExtensions/NGExtensions/NSURL+misc.h +++ b/sope-core/NGExtensions/NGExtensions/NSURL+misc.h @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGExtensions_NSURL_misc_H__ #define __NGExtensions_NSURL_misc_H__ diff --git a/sope-xml/DOM/ChangeLog b/sope-xml/DOM/ChangeLog index 689fe42d..7709d76f 100644 --- a/sope-xml/DOM/ChangeLog +++ b/sope-xml/DOM/ChangeLog @@ -1,3 +1,8 @@ +2004-08-25 Helge Hess + + * DOMSaxHandler.m: do not print DOM parsing errors per default + (consumers need to check the errors array) (v4.3.12) + 2004-08-20 Helge Hess * moved to SOPE 4.3 (v4.3.11) diff --git a/sope-xml/DOM/DOMSaxHandler.m b/sope-xml/DOM/DOMSaxHandler.m index 86ce5ee2..00941e9c 100644 --- a/sope-xml/DOM/DOMSaxHandler.m +++ b/sope-xml/DOM/DOMSaxHandler.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "DOMSaxHandler.h" #include "DOMImplementation.h" @@ -33,6 +32,8 @@ @implementation DOMSaxHandler +static BOOL printErrors = NO; + - (id)initWithDOMImplementation:(id)_domImpl { if ((self = [super init])) { self->dom = [_domImpl retain]; @@ -347,19 +348,21 @@ } - (void)error:(SaxParseException *)_exception { - NSString *sysId; - int line; - self->errorCount++; - sysId = [[_exception userInfo] objectForKey:@"systemId"]; - line = [[[_exception userInfo] objectForKey:@"line"] intValue]; + if (printErrors) { + NSString *sysId; + int line; + + sysId = [[_exception userInfo] objectForKey:@"systemId"]; + line = [[[_exception userInfo] objectForKey:@"line"] intValue]; + + NSLog(@"DOM XML ERROR(%@:%i[%@]): %@ (errcount=%i,max=%i)", sysId, line, + [[_exception userInfo] objectForKey:@"parser"], + [_exception reason], + self->errorCount, self->maxErrorCount); + } - NSLog(@"DOM XML ERROR(%@:%i[%@]): %@ (errcount=%i,max=%i)", sysId, line, - [[_exception userInfo] objectForKey:@"parser"], - [_exception reason], - self->errorCount, self->maxErrorCount); - if (self->errors == nil) self->errors = [[NSMutableArray alloc] initWithCapacity:32]; diff --git a/sope-xml/DOM/Version b/sope-xml/DOM/Version index c351558f..02dd0f66 100644 --- a/sope-xml/DOM/Version +++ b/sope-xml/DOM/Version @@ -1,3 +1,3 @@ -# $Id$ +# $Id: Version 4 2004-08-20 17:04:31Z helge $ -SUBMINOR_VERSION:=11 +SUBMINOR_VERSION:=12 diff --git a/sope-xml/libxmlSAXDriver/ChangeLog b/sope-xml/libxmlSAXDriver/ChangeLog index f83bdc21..caa48d13 100644 --- a/sope-xml/libxmlSAXDriver/ChangeLog +++ b/sope-xml/libxmlSAXDriver/ChangeLog @@ -1,3 +1,13 @@ +2004-08-25 Helge Hess + + * v4.3.16 + + * libxmlHTMLSAXDriver.m: generate SAX events (HTML/BODY) for empty + documents + + * libxmlDocSAXDriver.m, libxmlHTMLSAXDriver.m: allows NSURL objects as + the source for parsing + 2004-08-24 Helge Hess * GNUmakefile: install SAX driver in Library/SaxDrivers-4.3/ (v4.3.15) diff --git a/sope-xml/libxmlSAXDriver/Version b/sope-xml/libxmlSAXDriver/Version index cf9e5c12..30986027 100644 --- a/sope-xml/libxmlSAXDriver/Version +++ b/sope-xml/libxmlSAXDriver/Version @@ -1,3 +1,3 @@ -# $Id$ +# version -SUBMINOR_VERSION:=15 +SUBMINOR_VERSION:=16 diff --git a/sope-xml/libxmlSAXDriver/libxmlDocSAXDriver.m b/sope-xml/libxmlSAXDriver/libxmlDocSAXDriver.m index 6df4edb0..1aab9de9 100644 --- a/sope-xml/libxmlSAXDriver/libxmlDocSAXDriver.m +++ b/sope-xml/libxmlSAXDriver/libxmlDocSAXDriver.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #import "libxmlDocSAXDriver.h" #import "libxmlSAXLocator.h" @@ -226,12 +225,25 @@ static void setLocator(void *udata, xmlSAXLocatorPtr _locator); - (void)parseFromSource:(id)_source systemId:(NSString *)_sysId { if ([_source isKindOfClass:[NSData class]]) { [self _parseFromData:_source systemId:nil]; + return; } - else if ([_source isKindOfClass:[NSString class]]) { + if ([_source isKindOfClass:[NSString class]]) { [self _parseFromData:[_source dataUsingEncoding:NSISOLatin1StringEncoding] systemId:nil]; + return; } - else { + if ([_source isKindOfClass:[NSURL class]]) { + NSData *data; + + data = [_source isFileURL] + ? [NSData dataWithContentsOfMappedFile:[_source path]] + : [_source resourceDataUsingCache:YES]; + + [self _parseFromData:data systemId:[_source absoluteString]]; + return; + } + + { SaxParseException *e; NSDictionary *ui; @@ -241,14 +253,21 @@ static void setLocator(void *udata, xmlSAXLocatorPtr _locator); nil]; e = (id)[SaxParseException exceptionWithName:@"SaxIOException" - reason:@"can't handle data-source" + reason:@"cannot handle data-source" userInfo:ui]; [self->errorHandler fatalError:e]; } } - (void)parseFromSource:(id)_source { - [self parseFromSource:_source systemId:@""]; + if ([_source isKindOfClass:[NSString class]]) + [self parseFromSource:_source systemId:@""]; + else if ([_source isKindOfClass:[NSData class]]) + [self parseFromSource:_source systemId:@""]; + else if ([_source isKindOfClass:[NSURL class]]) + [self parseFromSource:_source systemId:[_source absoluteString]]; + else + [self parseFromSource:_source systemId:@""]; } - (void)parseFromSystemId:(NSString *)_sysId { diff --git a/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m b/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m index 6e049f69..af285cc7 100644 --- a/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m +++ b/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m @@ -262,8 +262,37 @@ static void setLocator(void *udata, xmlSAXLocatorPtr _locator); /* parsing */ +- (void)_handleEmptyDataInSystemId:(NSString *)_sysId { + /* + An empty HTML file _is_ valid?! + I guess it equals to , wrong? => hh + */ + [self->contentHandler startDocument]; + [self->contentHandler startPrefixMapping:@"" uri:self->namespaceURI]; + + [self->contentHandler + startElement:@"html" namespace:XMLNS_XHTML + rawName:@"html" attributes:nil]; + [self->contentHandler + startElement:@"body" namespace:XMLNS_XHTML + rawName:@"body" attributes:nil]; + + [self->contentHandler + endElement:@"body" namespace:XMLNS_XHTML rawName:@"body"]; + [self->contentHandler + endElement:@"html" namespace:XMLNS_XHTML rawName:@"html"]; + + [self->contentHandler endPrefixMapping:@""]; + [self->contentHandler endDocument]; +} + - (void)_parseFromData:(NSData *)_data systemId:(NSString *)_sysId { NSAutoreleasePool *pool; + + if ([_data length] == 0) { + [self _handleEmptyDataInSystemId:_sysId]; + return; + } pool = [[NSAutoreleasePool alloc] init]; @@ -291,12 +320,25 @@ static void setLocator(void *udata, xmlSAXLocatorPtr _locator); if ([_source isKindOfClass:[NSData class]]) { [self _parseFromData:_source systemId:_sysId]; + return; } - else if ([_source isKindOfClass:[NSString class]]) { + if ([_source isKindOfClass:[NSString class]]) { [self _parseFromData:[_source dataUsingEncoding:NSISOLatin1StringEncoding] systemId:_sysId]; + return; } - else { + if ([_source isKindOfClass:[NSURL class]]) { + NSData *data; + + data = [_source isFileURL] + ? [NSData dataWithContentsOfMappedFile:[_source path]] + : [_source resourceDataUsingCache:YES]; + + [self _parseFromData:data systemId:[_source absoluteString]]; + return; + } + + { SaxParseException *e; NSDictionary *ui; @@ -317,7 +359,14 @@ static void setLocator(void *udata, xmlSAXLocatorPtr _locator); [pool release]; } - (void)parseFromSource:(id)_source { - [self parseFromSource:_source systemId:@""]; + if ([_source isKindOfClass:[NSString class]]) + [self parseFromSource:_source systemId:@""]; + else if ([_source isKindOfClass:[NSData class]]) + [self parseFromSource:_source systemId:@""]; + else if ([_source isKindOfClass:[NSURL class]]) + [self parseFromSource:_source systemId:[_source absoluteString]]; + else + [self parseFromSource:_source systemId:@""]; } - (void)parseFromSystemId:(NSString *)_sysId { -- 2.39.5