PageRenderTime 31ms CodeModel.GetById 24ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llxml/llxmlparser.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 133 lines | 58 code | 23 blank | 52 comment | 0 complexity | aecee5aa7b80a2dea0f8f723d0e1911c MD5 | raw file
  1/** 
  2 * @file llxmlparser.h
  3 * @brief LLXmlParser class definition
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLXMLPARSER_H
 28#define LL_LLXMLPARSER_H
 29
 30#ifndef XML_STATIC
 31#define XML_STATIC
 32#endif
 33#ifdef LL_STANDALONE
 34#include <expat.h>
 35#else
 36#include "expat/expat.h"
 37#endif
 38
 39class LLXmlParser
 40{
 41public:
 42	LLXmlParser();
 43	virtual ~LLXmlParser();
 44
 45	// Parses entire file
 46	BOOL parseFile(const std::string &path);
 47
 48	//	Parses some input. Returns 0 if a fatal error is detected.
 49	//	The last call must have isFinal true;
 50	//	len may be zero for this call (or any other).
 51	S32 parse( const char* buf, int len, int isFinal );
 52
 53	const char* getErrorString();
 54	
 55	S32 getCurrentLineNumber();
 56
 57	S32 getCurrentColumnNumber();
 58
 59	S32 getDepth() { return mDepth; }
 60
 61protected:
 62	// atts is array of name/value pairs, terminated by 0;
 63	// names and values are 0 terminated.
 64	virtual void startElement(const char *name, const char **atts) {}
 65
 66	virtual void endElement(const char *name) {}
 67
 68	// s is not 0 terminated.
 69	virtual void characterData(const char *s, int len) {}
 70	
 71	// target and data are 0 terminated
 72	virtual void processingInstruction(const char *target, const char *data) {}
 73
 74	// data is 0 terminated 
 75	virtual void comment(const char *data) {}
 76
 77	virtual void startCdataSection() {}
 78
 79	virtual void endCdataSection() {}
 80
 81	//	This is called for any characters in the XML document for
 82	//	which there is no applicable handler.  This includes both
 83	//	characters that are part of markup which is of a kind that is
 84	//	not reported (comments, markup declarations), or characters
 85	//	that are part of a construct which could be reported but
 86	//	for which no handler has been supplied. The characters are passed
 87	//	exactly as they were in the XML document except that
 88	//	they will be encoded in UTF-8.  Line boundaries are not normalized.
 89	//	Note that a byte order mark character is not passed to the default handler.
 90	//	There are no guarantees about how characters are divided between calls
 91	//	to the default handler: for example, a comment might be split between
 92	//	multiple calls.
 93	virtual void defaultData(const char *s, int len) {}
 94
 95	//	This is called for a declaration of an unparsed (NDATA)
 96	//	entity.  The base argument is whatever was set by XML_SetBase.
 97	//	The entityName, systemId and notationName arguments will never be null.
 98	//	The other arguments may be.
 99	virtual void unparsedEntityDecl(
100		const char *entityName,
101		const char *base,
102		const char *systemId,
103		const char *publicId,
104		const char *notationName) {}
105
106public:
107	///////////////////////////////////////////////////////////////////////////////
108	// Pseudo-private methods.  These are only used by internal callbacks.
109	
110	static void startElementHandler(void *userData, const XML_Char *name, const XML_Char **atts);
111	static void endElementHandler(void *userData, const XML_Char *name);
112	static void characterDataHandler(void *userData, const XML_Char *s, int len);
113	static void processingInstructionHandler(void *userData, const XML_Char *target, const XML_Char *data);
114	static void commentHandler(void *userData, const XML_Char *data);
115	static void startCdataSectionHandler(void *userData);
116	static void endCdataSectionHandler(void *userData);
117	static void defaultDataHandler( void *userData, const XML_Char *s, int len);
118	static void unparsedEntityDeclHandler(
119		void *userData,
120		const XML_Char *entityName,
121		const XML_Char *base,
122		const XML_Char *systemId,
123		const XML_Char *publicId,
124		const XML_Char *notationName);
125
126
127protected:
128	XML_Parser		mParser;
129	int				mDepth;
130	std::string		mAuxErrorString;
131};
132
133#endif  // LL_LLXMLPARSER_H