xref: /aoo42x/main/xml2cmp/source/xcd/parse.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef X2C_PARSE_HXX
29 #define X2C_PARSE_HXX
30 
31 
32 
33 // USED SERVICES
34 	// BASE CLASSES
35 	// COMPONENTS
36 #include "filebuff.hxx"
37 #include "../support/sistr.hxx"
38 #include "../support/list.hxx"
39 	// PARAMETERS
40 
41 
42 class XmlElement;
43 class ListElement;
44 
45 class X2CParser
46 {
47   public:
48 	typedef XmlElement * (*F_CREATE)(const Simstr &);
49 
50 						X2CParser(
51 							XmlElement &		o_rDocumentData );
52 						~X2CParser();
53 
54 	bool			 	LoadFile(
55 							const char *		i_sFilename );
56 	void                Parse();
57 	bool                Parse(
58 							const char *		i_sFilename );
59 
60 
61 	const char *		PureText() const		{ return aFile.operator const char*(); }
62 
63 	void				Parse_Sequence(
64 						   DynamicList<XmlElement> &
65 												o_rElements,
66 						   const Simstr &		i_sElementName );
67 	void				Parse_FreeChoice(
68 							DynamicList<XmlElement> &
69 												o_rElements );
70 	void				Parse_List(
71 							ListElement &		o_rListElem );
72 	void                Parse_Text(
73 							Simstr &			o_sText,
74 							const Simstr &		i_sElementName,
75 							bool				i_bReverseName );
76 	void                Parse_MultipleText(
77 							List<Simstr> &	    o_rTexts,
78 							const Simstr &		i_sElementName,
79 							bool				i_bReverseName );
80 	void                Parse_SglAttr(
81 							Simstr &			o_sAttrValue,
82 							const Simstr &		i_sElementName,
83 							const Simstr &		i_sAttrName );
84 	void                Parse_MultipleAttr(
85 							List<Simstr> &		o_rAttrValues,
86 							const Simstr &		i_sElementName,
87 							const List<Simstr> &
88 												i_rAttrNames );
89 
90   private:
91 	void				Parse_XmlDeclaration();
92 	void				Parse_Doctype();
93 
94 	void				Get_Attribute(
95 							Simstr &			o_rAttrValue,
96 							Simstr &			o_rAttrName );
97 	bool				IsText(
98 							const char *		i_sComparedText );
99 	bool				IsBeginTag(
100 							const char *		i_sTagName );
101 	bool				IsEndTag(
102 							const char *		i_sTagName );
103 	void				Goto(
104 							char				i_cNext );
105 	void				Goto_And_Pass(
106 							char				i_cNext );
107 	void				Move(
108 							int					i_nForward );
109 	void				Pass_White();
110 	void				GetTextTill(
111 							Simstr & 			o_rText,
112 							char				i_cEnd,
113 							bool                i_bReverseName = false );
114     /// @return false in case of empty tag with no attributes.
115 	bool				CheckAndPassBeginTag(
116 							const char *		i_sElementName );
117 	void				CheckAndPassEndTag(
118 							const char *		i_sElementName );
119     /// @precond IsBeginTag() == true.
120     bool                IsAbsoluteEmpty() const;
121 
122 
123 	void				SyntaxError(
124 							const char *		i_sText );
125 	void				TestCurChar();
126 
127 	// DATA
128 	Simstr				sFileName;
129 	unsigned			nFileLine;
130 
131 	Buffer 				aFile;
132 	XmlElement *		pDocumentData;
133 
134 	char                sWord[8192];
135 	const char *        text;
136 };
137 
138 
139 
140 // IMPLEMENTATION
141 
142 #endif
143 
144