ObjFW  Check-in [d534f49a7d]

Overview
Comment:Add a handler for unknown entities to OFXMLElementBuilderDelegate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d534f49a7d0e1f2e86d94edcaf6311dbce83c723eca3bd859b4646d9a9402391
User & Date: js on 2011-06-29 19:06:53
Other Links: manifest | tags
Context
2011-06-29
19:17
Check for libobjc / libobjfw-rt and abort if not found. check-in: f19d3dcf08 user: js tags: trunk
19:06
Add a handler for unknown entities to OFXMLElementBuilderDelegate. check-in: d534f49a7d user: js tags: trunk
2011-06-28
22:56
Add -[readStringWithLength:] to OFStream. check-in: 90a9d9475a user: js tags: trunk
Changes

Modified src/OFXMLElementBuilder.h from [922beec8cc] to [3b177f300f].

11
12
13
14
15
16
17

18
19
20
21
22
23
24
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"


@class OFMutableArray;
@class OFXMLElement;
@class OFXMLElementBuilder;

/**
 * \brief A protocol that needs to be implemented by delegates for







>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"
#import "OFXMLParser.h"

@class OFMutableArray;
@class OFXMLElement;
@class OFXMLElementBuilder;

/**
 * \brief A protocol that needs to be implemented by delegates for
63
64
65
66
67
68
69










70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 * \param prefix The prefix of the close tag
 * \param ns The namespace of the close tag
 */
- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
	     namespace: (OFString*)ns;










@end

/**
 * \brief A class implementing the OFXMLParserDelegate protocol that can build
 * OFXMLElements from the document parsed by the OFXMLParser.
 *
 * It can also be used to build OFXMLElements from parts of the document by
 * first parsing stuff using the OFXMLParser with another delegate and then
 * setting the OFXMLElementBuilder as delegate for the parser.
 */
@interface OFXMLElementBuilder: OFObject
{
	OFMutableArray *stack;
	id <OFXMLElementBuilderDelegate> delegate;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLElementBuilderDelegate> delegate;







>
>
>
>
>
>
>
>
>
>










|







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 * \param prefix The prefix of the close tag
 * \param ns The namespace of the close tag
 */
- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
	     namespace: (OFString*)ns;

/**
 * This callback is called when the XML parser for the element builder found an
 * unknown entity.
 *
 * \param entity The name of the entity
 * \return The substitution for the entity
 */
- (OFString*)elementBuilder: (OFXMLElementBuilder*)builder
    foundUnknownEntityNamed: (OFString*)entity;
@end

/**
 * \brief A class implementing the OFXMLParserDelegate protocol that can build
 * OFXMLElements from the document parsed by the OFXMLParser.
 *
 * It can also be used to build OFXMLElements from parts of the document by
 * first parsing stuff using the OFXMLParser with another delegate and then
 * setting the OFXMLElementBuilder as delegate for the parser.
 */
@interface OFXMLElementBuilder: OFObject <OFXMLParserDelegate>
{
	OFMutableArray *stack;
	id <OFXMLElementBuilderDelegate> delegate;
}

#ifdef OF_HAVE_PROPERTIES
@property (retain) id <OFXMLElementBuilderDelegate> delegate;

Modified src/OFXMLElementBuilder.m from [04c630ff09] to [0ff6d1dc0d].

61
62
63
64
65
66
67





68
69
70
71
72
73
74
	OF_GETTER(delegate, YES)
}

- (void)setDelegate: (id <OFXMLElementBuilderDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
}






-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attributes
{







>
>
>
>
>







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	OF_GETTER(delegate, YES)
}

- (void)setDelegate: (id <OFXMLElementBuilderDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
}

-		 (void)parser: (OFXMLParser*)parser
  foundProcessingInstructions: (OFString*)pi
{
}

-    (void)parser: (OFXMLParser*)parser
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attributes
{
165
166
167
168
169
170
171







172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187






188
		[delegate elementBuilder: self
			 didBuildElement: element];
	else
		[[stack lastObject] addChild: element];

	[pool release];
}







@end

@implementation OFObject (OFXMLElementBuilderDelegate)
- (void)elementBuilder: (OFXMLElementBuilder*)builder
       didBuildElement: (OFXMLElement*)elem
{
}

- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
	     namespace: (OFString*)ns
{
	@throw [OFMalformedXMLException newWithClass: [builder class]
					      parser: nil];
}






@end







>
>
>
>
>
>
>
















>
>
>
>
>
>

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
		[delegate elementBuilder: self
			 didBuildElement: element];
	else
		[[stack lastObject] addChild: element];

	[pool release];
}

-	(OFString*)parser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	return [delegate elementBuilder: self
		foundUnknownEntityNamed: entity];
}
@end

@implementation OFObject (OFXMLElementBuilderDelegate)
- (void)elementBuilder: (OFXMLElementBuilder*)builder
       didBuildElement: (OFXMLElement*)elem
{
}

- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
	    withPrefix: (OFString*)prefix
	     namespace: (OFString*)ns
{
	@throw [OFMalformedXMLException newWithClass: [builder class]
					      parser: nil];
}

- (OFString*)elementBuilder: (OFXMLElementBuilder*)builder
    foundUnknownEntityNamed: (OFString*)entity
{
	return nil;
}
@end