]> err.no Git - sope/blob - sope-appserver/WOXML/WOXMLSaxModelHandler.m
new Xcode projects, removed old Xcode project
[sope] / sope-appserver / WOXML / WOXMLSaxModelHandler.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "WOXMLSaxModelHandler.h"
24 #include "WOXMLMappingEntity.h"
25 #include "WOXMLMappingModel.h"
26 #include "WOXMLMappingProperty.h"
27 #include "common.h"
28
29 @implementation WOXMLSaxModelHandler
30
31 - (void)dealloc {
32   RELEASE(self->currentModel);
33   RELEASE(self->currentProperty);
34   RELEASE(self->currentEntity);
35   [super dealloc];
36 }
37
38 - (WOXMLMappingModel *)model {
39   return AUTORELEASE(RETAIN(self->currentModel));
40 }
41
42 /* tag handler */
43
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 !");
47     return;
48   }
49
50   RELEASE(self->currentModel); self->currentModel = nil;
51   self->currentModel = [[WOXMLMappingModel alloc] init];
52 }
53 - (void)endModel {
54   if ((self->currentProperty != nil) || (self->currentEntity != nil))
55     return;
56 }
57
58 - (void)startEntity:(id<SaxAttributes>)_attrs {
59   NSString *s;
60   
61   if (self->currentProperty) {
62     NSLog(@"cannot nest 'entity' tags inside property tags !");
63     return;
64   }
65   if (self->currentEntity) {
66     NSLog(@"cannot nest 'entity' tags inside entity tags !");
67     return;
68   }
69   if (self->currentModel == nil) {
70     NSLog(@"missing 'model' parent element for 'entity' tag !");
71     return;
72   }
73   
74   self->currentEntity = [[WOXMLMappingEntity alloc] init];
75   
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];
84   
85   if ((s = [_attrs valueForRawName:@"ignoreUnmappedTags"])) {
86     [self->currentEntity setIgnoreUnmappedTags:
87          [[s uppercaseString] isEqualToString:@"YES"]];
88   }
89 }
90 - (void)endEntity {
91   if ((self->currentProperty != nil) || (self->currentModel == nil))
92     return;
93   
94   if (self->currentEntity) {
95     if ([self->currentEntity isValid])
96       [self->currentModel addEntity:self->currentEntity];
97     RELEASE(self->currentEntity); self->currentEntity = nil;
98   }
99 }
100
101 - (void)startProperty:(id<SaxAttributes>)_attrs {
102   NSString *s;
103   
104   if (self->currentProperty) {
105     NSLog(@"cannot nest 'property' tags inside property tags !");
106     return;
107   }
108   if ((self->currentEntity == nil) || (self->currentModel == nil)) {
109     NSLog(@"missing 'entity' parent element for 'property' tag !");
110     return;
111   }
112
113   self->currentProperty = [[WOXMLMappingProperty alloc] init];
114
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];
123   
124   if ((s = [_attrs valueForRawName:@"attribute"])) {
125     [self->currentProperty setAttribute:
126          [[s uppercaseString] isEqualToString:@"YES"]];
127   }
128   if ((s = [_attrs valueForRawName:@"forceList"])) {
129     [self->currentProperty setForceList:
130          [[s uppercaseString] isEqualToString:@"YES"]];
131   }
132   if ((s = [_attrs valueForRawName:@"reportEmptyValues"])) {
133     [self->currentProperty setReportEmptyValues:
134          [[s uppercaseString] isEqualToString:@"YES"]];
135   }
136 }
137 - (void)endProperty {
138   if ((self->currentEntity == nil) || (self->currentModel == nil))
139     return;
140
141   if (self->currentProperty) {
142     if ([self->currentProperty isValid])
143       [self->currentEntity addProperty:self->currentProperty];
144
145     RELEASE(self->currentProperty); self->currentProperty = nil;
146   }
147 }
148
149 /* SAX */
150
151 - (void)startDocument {
152   RELEASE(self->currentModel);    self->currentModel    = nil;
153   RELEASE(self->currentEntity);   self->currentEntity   = nil;
154   RELEASE(self->currentProperty); self->currentProperty = nil;
155 }
156 - (void)endDocument {
157 }
158
159 - (void)startElement:(NSString *)_localName
160   namespace:(NSString *)_ns
161   rawName:(NSString *)_rawName
162   attributes:(id<SaxAttributes>)_attrs
163 {
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];
170 }
171 - (void)endElement:(NSString *)_localName
172   namespace:(NSString *)_ns
173   rawName:(NSString *)_rawName
174 {
175   if ([_rawName isEqualToString:@"model"])
176     [self endModel];
177   else if ([_rawName isEqualToString:@"entity"])
178     [self endEntity];
179   else if ([_rawName isEqualToString:@"property"])
180     [self endProperty];
181 }
182
183 @end /* WOXMLSaxModelHandler */