From: helge Date: Thu, 15 Sep 2005 13:12:05 +0000 (+0000) Subject: started TAL element builder X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ab66ac1cf4eea1331d3b6b26aeebb77e7255ad4;p=sope started TAL element builder git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1109 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 4675b661..fa4a1ae3 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,7 @@ +2005-09-15 Helge Hess + + * started WOxTalElemBuilder (v4.5.200) + 2005-09-13 Marcus Mueller * DynamicElements/_WOComplexHyperlink.m: do not generate hyperlink diff --git a/sope-appserver/NGObjWeb/Defaults.plist b/sope-appserver/NGObjWeb/Defaults.plist index ee70e7ed..8ee9a096 100644 --- a/sope-appserver/NGObjWeb/Defaults.plist +++ b/sope-appserver/NGObjWeb/Defaults.plist @@ -127,6 +127,7 @@ WOxComponentElemBuilderDebugEnabled = NO; WOxLogBuilderQueue = NO; WOxBuilderClasses = ( + WOxTalElemBuilder, WOxControlElemBuilder, WOxMiscElemBuilder, WOxHTMLElemBuilder, diff --git a/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile b/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile index 55fcf889..d7d14ac6 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile +++ b/sope-appserver/NGObjWeb/DynamicElements/GNUmakefile @@ -12,6 +12,7 @@ DynamicElements_OBJC_FILES = \ WOxControlElemBuilder.m \ WOxMiscElemBuilder.m \ WOxXULElemBuilder.m \ + WOxTalElemBuilder.m \ \ WOActionURL.m \ WOBody.m \ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOxTalElemBuilder.m b/sope-appserver/NGObjWeb/DynamicElements/WOxTalElemBuilder.m new file mode 100644 index 00000000..973ba84e --- /dev/null +++ b/sope-appserver/NGObjWeb/DynamicElements/WOxTalElemBuilder.m @@ -0,0 +1,149 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE 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. + + SOPE 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 SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include + +/* + This builder processes elements in a way inspired by the Zope TAL. It is + incomplete / work in progress. + + Since this builds scans the attributes of _all_ tags, it might lead to some + slow-down when parsing templates. But this should be negligible in the real + world (with WO template caching) + + Note: for processing 'TAL associations', we also need a (TALES?) + WOAssociation subclass. + + Supported attributes: + + Processing order as per Zope doc: + 1. define + 2. condition + 3. repeat + 4. content OR replace + 5. attributes + 6. omit-tag +*/ + +@interface WOxTalElemBuilder : WOxElemBuilder +{ +} + +@end + +#include +#include "decommon.h" + +@implementation WOxTalElemBuilder + +- (WOElement *)buildElement:(id)_element templateBuilder:(id)_b { + // TODO: scan attributes for TAL/VAR attributes + id attrs; + unsigned len; + + attrs = [_element attributes]; + if ((len = [attrs length]) > 0) { + id talDefine = nil; // len=6, d, define + id talCondition = nil; // len=9, c, condition + id talRepeat = nil; // len=6, r, repeat + id talContent = nil; // len=7, c, content + id talReplace = nil; // len=7, r, replace + id talAttributes = nil; // len=10, a, attributes + id talOmitTag = nil; // len=8, o, omit-tag + unsigned i; + + /* collect TAL attributes */ + + for (i = 0; i < len; i++) { + id attr; + NSString *ns, *aname; + unsigned alen; + unichar c0; + BOOL isBindNS = NO; + + attr = [attrs objectAtIndex:i]; + aname = [attr name]; + alen = [aname length]; + + /* some pre-filtering based on name */ + + if (alen < 6 || alen > 10) + continue; + c0 = [aname characterAtIndex:0]; + if (!(c0 == 'd' && alen == 6 /* define */) && + !(c0 == 'c' && (alen == 9 || alen == 7)) && + !(c0 == 'r' && (alen == 6 || alen == 7)) && + !(c0 == 'a' && alen == 10 /* attributes */) && + !(c0 == 'o' && alen == 8 /* omit-tag */)) + continue; + + /* check namespace */ + + ns = [attr namespaceURI]; + // TODO: cache isEqualToString method? + if (![XMLNS_Zope_TAL isEqualToString:ns] && + !(isBindNS = [XMLNS_OD_BIND isEqualToString:ns])) + continue; + + /* check names and derive attributes */ + + // TODO: use var:if instead of tal:condition + // and var:foreach instead of tal:repeat + // ? + // TODO: the biggest issue to be solved is how to know when + // the element itself would be dynamic and resolve the binding + // => eg: aka WOConditional and 'tal:condition' + + switch (c0) { + case 'd': + if (alen == 6 && [aname isEqualToString:@"define"]) + talDefine = attr; + break; + case 'c': + if (alen == 7 && [aname isEqualToString:@"content"]) + talContent = attr; + else if (alen == 9 && [aname isEqualToString:@"condition"]) + talCondition = attr; + break; + case 'r': + if (alen == 6 && [aname isEqualToString:@"repeat"]) + talRepeat = attr; + else if (alen == 7 && [aname isEqualToString:@"replace"]) + talReplace = attr; + break; + case 'a': + if (alen == 10 && [aname isEqualToString:@"attributes"]) + talAttributes = attr; + break; + case 'o': + if (alen == 8 && [aname isEqualToString:@"omit-tag"]) + talOmitTag = attr; + break; + } + } + + /* process TAL attributes */ + } + + return [self->nextBuilder buildElement:_element templateBuilder:_b]; +} + +@end /* WOxTalElemBuilder */ diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 6697266a..16c96dd2 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=199 +SUBMINOR_VERSION:=200 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134