xref: /aoo41x/main/xml2cmp/source/xcd/parse.hxx (revision dd7bc091)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef X2C_PARSE_HXX
25 #define X2C_PARSE_HXX
26 
27 
28 
29 // USED SERVICES
30 	// BASE CLASSES
31 	// COMPONENTS
32 #include "filebuff.hxx"
33 #include "../support/sistr.hxx"
34 #include "../support/list.hxx"
35 	// PARAMETERS
36 
37 
38 class XmlElement;
39 class ListElement;
40 
41 class X2CParser
42 {
43   public:
44 	typedef XmlElement * (*F_CREATE)(const Simstr &);
45 
46 						X2CParser(
47 							XmlElement &		o_rDocumentData );
48 						~X2CParser();
49 
50 	bool			 	LoadFile(
51 							const char *		i_sFilename );
52 	void                Parse();
53 	bool                Parse(
54 							const char *		i_sFilename );
55 
56 
PureText() const57 	const char *		PureText() const		{ return aFile.operator const char*(); }
58 
59 	void				Parse_Sequence(
60 						   DynamicList<XmlElement> &
61 												o_rElements,
62 						   const Simstr &		i_sElementName );
63 	void				Parse_FreeChoice(
64 							DynamicList<XmlElement> &
65 												o_rElements );
66 	void				Parse_List(
67 							ListElement &		o_rListElem );
68 	void                Parse_Text(
69 							Simstr &			o_sText,
70 							const Simstr &		i_sElementName,
71 							bool				i_bReverseName );
72 	void                Parse_MultipleText(
73 							List<Simstr> &	    o_rTexts,
74 							const Simstr &		i_sElementName,
75 							bool				i_bReverseName );
76 	void                Parse_SglAttr(
77 							Simstr &			o_sAttrValue,
78 							const Simstr &		i_sElementName,
79 							const Simstr &		i_sAttrName );
80 	void                Parse_MultipleAttr(
81 							List<Simstr> &		o_rAttrValues,
82 							const Simstr &		i_sElementName,
83 							const List<Simstr> &
84 												i_rAttrNames );
85 
86   private:
87 	void				Parse_XmlDeclaration();
88 	void				Parse_Doctype();
89 
90 	void				Get_Attribute(
91 							Simstr &			o_rAttrValue,
92 							Simstr &			o_rAttrName );
93 	bool				IsText(
94 							const char *		i_sComparedText );
95 	bool				IsBeginTag(
96 							const char *		i_sTagName );
97 	bool				IsEndTag(
98 							const char *		i_sTagName );
99 	void				Goto(
100 							char				i_cNext );
101 	void				Goto_And_Pass(
102 							char				i_cNext );
103 	void				Move(
104 							int					i_nForward );
105 	void				Pass_White();
106 	void				GetTextTill(
107 							Simstr & 			o_rText,
108 							char				i_cEnd,
109 							bool                i_bReverseName = false );
110     /// @return false in case of empty tag with no attributes.
111 	bool				CheckAndPassBeginTag(
112 							const char *		i_sElementName );
113 	void				CheckAndPassEndTag(
114 							const char *		i_sElementName );
115     /// @precond IsBeginTag() == true.
116     bool                IsAbsoluteEmpty() const;
117 
118 
119 	void				SyntaxError(
120 							const char *		i_sText );
121 	void				TestCurChar();
122 
123 	// DATA
124 	Simstr				sFileName;
125 	unsigned			nFileLine;
126 
127 	Buffer 				aFile;
128 	XmlElement *		pDocumentData;
129 
130 	char                sWord[8192];
131 	const char *        text;
132 };
133 
134 
135 
136 // IMPLEMENTATION
137 
138 #endif
139 
140