//--------------------------------------------------------------------------------------- // EDStyleSheetProcessor.m created by erik on Thu Jun 13 2002 // @(#)$Id: EDStyleSheetProcessor.m,v 1.3 2002-12-16 22:42:34 erik Exp $ // // Copyright (c) 2002 by Erik Doernenburg. All rights reserved. // // Permission to use, copy, modify and distribute this software and its documentation // is hereby granted, provided that both the copyright notice and this permission // notice appear in all copies of the software, derivative works or modified versions, // and any portions thereof, and that both notices appear in supporting documentation, // and that credit is given to Erik Doernenburg in all documents and publicity // pertaining to direct or indirect use of this code or its derivatives. // // THIS IS EXPERIMENTAL SOFTWARE AND IT IS KNOWN TO HAVE BUGS, SOME OF WHICH MAY HAVE // SERIOUS CONSEQUENCES. THE COPYRIGHT HOLDER ALLOWS FREE USE OF THIS SOFTWARE IN ITS // "AS IS" CONDITION. THE COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY // DAMAGES WHATSOEVER RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE // OR OF ANY DERIVATIVE WORK. //--------------------------------------------------------------------------------------- #import #import "EDSLStyleElement.h" #import "EDStyleSheetContext.h" #import "EDStyleSheetDocument.h" #import "EDStyleSheetProcessor.h" //--------------------------------------------------------------------------------------- @implementation EDStyleSheetProcessor //--------------------------------------------------------------------------------------- - (id)initWithContentsOfFile:(NSString *)fullPath { #warning * should handle inaccessible files [self initWithStyleSheet:[NSData dataWithContentsOfFile:fullPath]]; return self; } - (id)initWithStyleSheet:(NSData *)source { NSString *path; NSDictionary *slTags; EDMLParser *styleParser; [self init]; NS_DURING if((path = [[NSBundle bundleForClass:[self class]] pathForResource:@"EDSLTags" ofType:@"plist"]) == nil) [NSException raise:NSGenericException format:@"Missing resource EDSLTags.plist"]; slTags = [[NSString stringWithContentsOfFile:path] propertyList]; styleParser = [[EDMLParser parserWithTagDefinitions:slTags] retain]; [styleParser setPreservesWhitespace:YES]; document = [[styleParser parseXMLDocument:source] retain]; NS_HANDLER [self autorelease]; [localException raise]; NS_ENDHANDLER return self; } - (void)dealloc { [document release]; [super dealloc]; } - (NSString *)processObject:(id)object { EDStyleSheetContext *rootContext; NSMutableString *buffer; rootContext = [[[EDStyleSheetContext alloc] init] autorelease]; [rootContext setValue:object forVariable:@"object"]; [rootContext setShouldOmitSpaces:YES]; buffer = [NSMutableString string]; [[document rootElement] appendToString:buffer inContext:rootContext]; return buffer; } //--------------------------------------------------------------------------------------- @end //---------------------------------------------------------------------------------------