ObjFW
src/OFXMLParser.h
00001 /*
00002  * Copyright (c) 2008, 2009, 2010, 2011
00003  *   Jonathan Schleifer <js@webkeks.org>
00004  *
00005  * All rights reserved.
00006  *
00007  * This file is part of ObjFW. It may be distributed under the terms of the
00008  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
00009  * the packaging of this file.
00010  *
00011  * Alternatively, it may be distributed under the terms of the GNU General
00012  * Public License, either version 2 or 3, which can be found in the file
00013  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
00014  * file.
00015  */
00016 
00017 #import "OFObject.h"
00018 #import "OFString.h"
00019 #import "OFXMLAttribute.h"
00020 
00021 @class OFXMLParser;
00022 @class OFArray;
00023 @class OFMutableArray;
00024 @class OFStream;
00025 
00026 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
00027 typedef void (^of_xml_parser_processing_instructions_block_t)(
00028     OFXMLParser *parser, OFString *pi);
00029 typedef void (^of_xml_parser_element_start_block_t)(OFXMLParser *parser,
00030     OFString *name, OFString *prefix, OFString *ns, OFArray *attrs);
00031 typedef void (^of_xml_parser_element_end_block_t)(OFXMLParser *parser,
00032     OFString *name, OFString *prefix, OFString *ns);
00033 typedef void (^of_xml_parser_string_block_t)(OFXMLParser *parser,
00034     OFString *string);
00035 typedef OFString* (^of_xml_parser_unknown_entity_block_t)(OFXMLParser *parser,
00036     OFString *entity);
00037 #endif
00038 
00042 #ifndef OF_XML_PARSER_M
00043 @protocol OFXMLParserDelegate <OFObject>
00044 #else
00045 @protocol OFXMLParserDelegate
00046 #endif
00047 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
00048 @optional
00049 #endif
00050 
00056 -                (void)parser: (OFXMLParser*)parser
00057   foundProcessingInstructions: (OFString*)pi;
00058 
00068 -    (void)parser: (OFXMLParser*)parser
00069   didStartElement: (OFString*)name
00070        withPrefix: (OFString*)prefix
00071         namespace: (OFString*)ns
00072        attributes: (OFArray*)attrs;
00073 
00082 -  (void)parser: (OFXMLParser*)parser
00083   didEndElement: (OFString*)name
00084      withPrefix: (OFString*)prefix
00085       namespace: (OFString*)ns;
00086 
00096 -    (void)parser: (OFXMLParser*)parser
00097   foundCharacters: (OFString*)string;
00098 
00105 - (void)parser: (OFXMLParser*)parser
00106     foundCDATA: (OFString*)cdata;
00107 
00114 - (void)parser: (OFXMLParser*)parser
00115   foundComment: (OFString*)comment;
00116 
00127 -       (OFString*)parser: (OFXMLParser*)parser
00128   foundUnknownEntityNamed: (OFString*)entity;
00129 @end
00130 
00137 @interface OFXMLParser: OFObject <OFStringXMLUnescapingDelegate>
00138 {
00139         id <OFXMLParserDelegate> delegate;
00140         enum {
00141                 OF_XMLPARSER_OUTSIDE_TAG,
00142                 OF_XMLPARSER_TAG_OPENED,
00143                 OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
00144                 OF_XMLPARSER_IN_TAG_NAME,
00145                 OF_XMLPARSER_IN_CLOSE_TAG_NAME,
00146                 OF_XMLPARSER_IN_TAG,
00147                 OF_XMLPARSER_IN_ATTR_NAME,
00148                 OF_XMLPARSER_EXPECT_DELIM,
00149                 OF_XMLPARSER_IN_ATTR_VALUE,
00150                 OF_XMLPARSER_EXPECT_CLOSE,
00151                 OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE,
00152                 OF_XMLPARSER_IN_EXCLAMATIONMARK,
00153                 OF_XMLPARSER_IN_CDATA_OPENING,
00154                 OF_XMLPARSER_IN_CDATA_1,
00155                 OF_XMLPARSER_IN_CDATA_2,
00156                 OF_XMLPARSER_IN_COMMENT_OPENING,
00157                 OF_XMLPARSER_IN_COMMENT_1,
00158                 OF_XMLPARSER_IN_COMMENT_2,
00159                 OF_XMLPARSER_IN_DOCTYPE,
00160                 OF_XMLPARSER_NUM_STATES
00161         } state;
00162         OFMutableString *cache;
00163         OFString *name;
00164         OFString *prefix;
00165         OFMutableArray *namespaces;
00166         OFMutableArray *attrs;
00167         OFString *attrName;
00168         OFString *attrPrefix;
00169         char delim;
00170         OFMutableArray *previous;
00171 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
00172         of_xml_parser_processing_instructions_block_t
00173             processingInstructionsHandler;
00174         of_xml_parser_element_start_block_t elementStartHandler;
00175         of_xml_parser_element_end_block_t elementEndHandler;
00176         of_xml_parser_string_block_t charactersHandler;
00177         of_xml_parser_string_block_t CDATAHandler;
00178         of_xml_parser_string_block_t commentHandler;
00179         of_xml_parser_unknown_entity_block_t unknownEntityHandler;
00180 #endif
00181         size_t level;
00182         BOOL acceptProlog;
00183         size_t lineNumber;
00184         BOOL lastCarriageReturn;
00185         BOOL finishedParsing;
00186 }
00187 
00188 #ifdef OF_HAVE_PROPERTIES
00189 @property (retain) id <OFXMLParserDelegate> delegate;
00190 # ifdef OF_HAVE_BLOCKS
00191 @property (copy) of_xml_parser_processing_instructions_block_t
00192     processingInstructionsHandler;
00193 @property (copy) of_xml_parser_element_start_block_t elementStartHandler;
00194 @property (copy) of_xml_parser_element_end_block_t elementEndHandler;
00195 @property (copy) of_xml_parser_string_block_t charactersHandler;
00196 @property (copy) of_xml_parser_string_block_t CDATAHandler;
00197 @property (copy) of_xml_parser_string_block_t commentHandler;
00198 @property (copy) of_xml_parser_unknown_entity_block_t unknownEntityHandler;
00199 # endif
00200 #endif
00201 
00205 + parser;
00206 
00210 - (id <OFXMLParserDelegate>)delegate;
00211 
00217 - (void)setDelegate: (id <OFXMLParserDelegate>)delegate;
00218 
00219 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
00220 
00223 - (of_xml_parser_processing_instructions_block_t)processingInstructionsHandler;
00224 
00230 - (void)setProcessingInstructionsHandler:
00231     (of_xml_parser_processing_instructions_block_t)block;
00232 
00236 - (of_xml_parser_element_start_block_t)elementStartHandler;
00237 
00243 - (void)setElementStartHandler: (of_xml_parser_element_start_block_t)block;
00244 
00248 - (of_xml_parser_element_end_block_t)elementEndHandler;
00249 
00255 - (void)setElementEndHandler: (of_xml_parser_element_end_block_t)block;
00256 
00260 - (of_xml_parser_string_block_t)charactersHandler;
00261 
00267 - (void)setCharactersHandler: (of_xml_parser_string_block_t)block;
00268 
00272 - (of_xml_parser_string_block_t)CDATAHandler;
00273 
00279 - (void)setCDATAHandler: (of_xml_parser_string_block_t)block;
00280 
00284 - (of_xml_parser_string_block_t)commentHandler;
00285 
00291 - (void)setCommentHandler: (of_xml_parser_string_block_t)block;
00292 
00296 - (of_xml_parser_unknown_entity_block_t)unknownEntityHandler;
00297 
00303 - (void)setUnknownEntityHandler: (of_xml_parser_unknown_entity_block_t)block;
00304 #endif
00305 
00312 - (void)parseBuffer: (const char*)buf
00313            withSize: (size_t)size;
00314 
00320 - (void)parseString: (OFString*)str;
00321 
00327 - (void)parseStream: (OFStream*)stream;
00328 
00334 - (void)parseFile: (OFString*)path;
00335 
00339 - (size_t)lineNumber;
00340 
00344 - (BOOL)finishedParsing;
00345 @end
00346 
00347 @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate>
00348 @end
 All Classes Functions Variables