2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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
11 OGo 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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "WOXMLSaxModelHandler.h"
24 #include "WOXMLMappingEntity.h"
25 #include "WOXMLMappingModel.h"
26 #include "WOXMLMappingProperty.h"
29 @implementation WOXMLSaxModelHandler
32 RELEASE(self->currentModel);
33 RELEASE(self->currentProperty);
34 RELEASE(self->currentEntity);
38 - (WOXMLMappingModel *)model {
39 return AUTORELEASE(RETAIN(self->currentModel));
44 - (void)startModel:(id<SaxAttributes>)_attrs {
45 if ((self->currentProperty != nil) || (self->currentEntity != nil)) {
46 NSLog(@"cannot nest 'model' tags inside property or entity tags !");
50 RELEASE(self->currentModel); self->currentModel = nil;
51 self->currentModel = [[WOXMLMappingModel alloc] init];
54 if ((self->currentProperty != nil) || (self->currentEntity != nil))
58 - (void)startEntity:(id<SaxAttributes>)_attrs {
61 if (self->currentProperty) {
62 NSLog(@"cannot nest 'entity' tags inside property tags !");
65 if (self->currentEntity) {
66 NSLog(@"cannot nest 'entity' tags inside entity tags !");
69 if (self->currentModel == nil) {
70 NSLog(@"missing 'model' parent element for 'entity' tag !");
74 self->currentEntity = [[WOXMLMappingEntity alloc] init];
76 if ((s = [_attrs valueForRawName:@"name"]))
77 [self->currentEntity setName:s];
78 if ((s = [_attrs valueForRawName:@"xmlTag"]))
79 [self->currentEntity setXmlTag:s];
80 if ((s = [_attrs valueForRawName:@"unmappedTagsKey"]))
81 [self->currentEntity setUnmappedTagsKey:s];
82 if ((s = [_attrs valueForRawName:@"contentsKey"]))
83 [self->currentEntity setContentsKey:s];
85 if ((s = [_attrs valueForRawName:@"ignoreUnmappedTags"])) {
86 [self->currentEntity setIgnoreUnmappedTags:
87 [[s uppercaseString] isEqualToString:@"YES"]];
91 if ((self->currentProperty != nil) || (self->currentModel == nil))
94 if (self->currentEntity) {
95 if ([self->currentEntity isValid])
96 [self->currentModel addEntity:self->currentEntity];
97 RELEASE(self->currentEntity); self->currentEntity = nil;
101 - (void)startProperty:(id<SaxAttributes>)_attrs {
104 if (self->currentProperty) {
105 NSLog(@"cannot nest 'property' tags inside property tags !");
108 if ((self->currentEntity == nil) || (self->currentModel == nil)) {
109 NSLog(@"missing 'entity' parent element for 'property' tag !");
113 self->currentProperty = [[WOXMLMappingProperty alloc] init];
115 if ((s = [_attrs valueForRawName:@"name"]))
116 [self->currentProperty setName:s];
117 if ((s = [_attrs valueForRawName:@"xmlTag"]))
118 [self->currentProperty setXmlTag:s];
119 if ((s = [_attrs valueForRawName:@"codeBasedOn"]))
120 [self->currentProperty setCodeBasedOn:s];
121 if ((s = [_attrs valueForRawName:@"outputTags"]))
122 [self->currentProperty setOutputTags:s];
124 if ((s = [_attrs valueForRawName:@"attribute"])) {
125 [self->currentProperty setAttribute:
126 [[s uppercaseString] isEqualToString:@"YES"]];
128 if ((s = [_attrs valueForRawName:@"forceList"])) {
129 [self->currentProperty setForceList:
130 [[s uppercaseString] isEqualToString:@"YES"]];
132 if ((s = [_attrs valueForRawName:@"reportEmptyValues"])) {
133 [self->currentProperty setReportEmptyValues:
134 [[s uppercaseString] isEqualToString:@"YES"]];
137 - (void)endProperty {
138 if ((self->currentEntity == nil) || (self->currentModel == nil))
141 if (self->currentProperty) {
142 if ([self->currentProperty isValid])
143 [self->currentEntity addProperty:self->currentProperty];
145 RELEASE(self->currentProperty); self->currentProperty = nil;
151 - (void)startDocument {
152 RELEASE(self->currentModel); self->currentModel = nil;
153 RELEASE(self->currentEntity); self->currentEntity = nil;
154 RELEASE(self->currentProperty); self->currentProperty = nil;
156 - (void)endDocument {
159 - (void)startElement:(NSString *)_localName
160 namespace:(NSString *)_ns
161 rawName:(NSString *)_rawName
162 attributes:(id<SaxAttributes>)_attrs
164 if ([_rawName isEqualToString:@"model"])
165 [self startModel:_attrs];
166 else if ([_rawName isEqualToString:@"entity"])
167 [self startEntity:_attrs];
168 else if ([_rawName isEqualToString:@"property"])
169 [self startProperty:_attrs];
171 - (void)endElement:(NSString *)_localName
172 namespace:(NSString *)_ns
173 rawName:(NSString *)_rawName
175 if ([_rawName isEqualToString:@"model"])
177 else if ([_rawName isEqualToString:@"entity"])
179 else if ([_rawName isEqualToString:@"property"])
183 @end /* WOXMLSaxModelHandler */