Xalan-C++ API Reference  1.12.0
SAX2Handler.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(SAX2HANDLER_1357924680)
20 #define SAX2HANDLER_1357924680
21 
22 #include "MsgFileOutputStream.hpp"
23 
24 #include <xercesc/sax2/DefaultHandler.hpp>
25 #include <xercesc/util/XMLUniDefs.hpp>
26 
27 
28 namespace XALAN_CPP_NAMESPACE {
29 
30 
31 
32 using namespace xercesc;
33 
34 
35 
36 static const XMLCh s_transUnitXMLCh[] =
37 {
38  chLatin_t,
39  chLatin_r,
40  chLatin_a,
41  chLatin_n,
42  chLatin_s,
43  chDash,
44  chLatin_u,
45  chLatin_n,
46  chLatin_i,
47  chLatin_t,
48 
49  chNull
50 };
51 
52 
53 static const XMLCh s_sourceXMLCh[] =
54 {
55  chLatin_s,
56  chLatin_o,
57  chLatin_u,
58  chLatin_r,
59  chLatin_c,
60  chLatin_e,
61 
62  chNull
63 };
64 
65 
66 static const XMLCh s_targetXMLCh[] =
67 {
68  chLatin_t,
69  chLatin_a,
70  chLatin_r,
71  chLatin_g,
72  chLatin_e,
73  chLatin_t,
74 
75  chNull
76 };
77 
78 
79 static const XMLCh s_xmlLangXMLCh[] =
80 {
81  chLatin_x,
82  chLatin_m,
83  chLatin_l,
84  chColon,
85  chLatin_l,
86  chLatin_a,
87  chLatin_n,
88  chLatin_g,
89  chNull
90 };
91 
92 
93 
94 static const XMLCh s_idXMLCh[] =
95 {
96  chLatin_i,
97  chLatin_d,
98  chNull
99 };
100 
101 static const XMLCh s_textXMLCh[] =
102 {
103  chLatin_T,
104  chLatin_e,
105  chLatin_x,
106  chLatin_t,
107  chNull
108 };
109 
110 
111 // Common class for the all system: creates index file ( common for all localization systems)
112 // For creation data file responsible subclasses
113 
114 
115 class SAX2Handler : public xercesc::DefaultHandler
116 {
117 public:
118  // -----------------------------------------------------------------------
119  // Constructors
120  // -----------------------------------------------------------------------
121  SAX2Handler(const char* indexFileName);
122  virtual ~SAX2Handler();
123 
124 public:
125 
126  virtual void
127  startElement(
128  const XMLCh* const uri,
129  const XMLCh* const localname,
130  const XMLCh* const qname,
131  const Attributes& attributes);
132 
133  virtual void
134  startDocument();
135 
136  virtual void
137  endDocument();
138 
139  // -----------------------------------------------------------------------
140  // Implementations of the SAX ErrorHandler interface
141  // -----------------------------------------------------------------------
142  virtual void
143  error(const SAXParseException& e);
144 
145  virtual void
146  fatalError(const SAXParseException& e);
147 
148  virtual void
149  warning(const SAXParseException& e);
150 
151  void
152  setLocale(const char* localeName);
153 
154  const XMLCh*
155  getLocale () const
156  {
157  return m_locale;
158  }
159 
160 protected:
161 
162  bool
163  translateCharToXMLByteArray(
164  XMLByte* buffer,
165  int iBufLen,
166  const char* szSource) const;
167 
168  virtual void
169  createHeaderForDataFile() = 0;
170 
171  virtual void
172  createBottomForDataFile() = 0;
173 
174  virtual void
175  printBeginOfDataLine() = 0;
176 
177  virtual void
178  printEndOfDataLine() = 0;
179 
180  virtual void
181  printToDataFile(const char* sArrayOfStrings[]) = 0;
182 
183  void
184  printToIndexFile(const char* sArrayOfStrings[]);
185 
186  void
187  printNumbOfRecords();
188 
189 private:
190 
191  void
192  createHeaderForIndexFile();
193 
194  void
195  createBottomForIndexFile();
196 
197  void
198  printBeginOfIndexLine();
199 
200  void
201  printEndOfIndexLine();
202 
203 protected:
204 
206 
207  XMLCh* m_locale;
208 
210 
211  // -----------------------------------------------------------------------
212  // SAX2 Handler is responsible for creating index file, so keep
213  // index file FormatTarget as private data member
214  // -----------------------------------------------------------------------
215 
216 private:
217 
218  MsgFileOutputStream m_indexOutputStream;
219 
220  // Not implemented...
221  SAX2Handler&
222  operator=(const SAX2Handler&);
223 
224  SAX2Handler(const SAX2Handler&);
225 
226  bool
227  operator==(const SAX2Handler&) const;
228 };
229 
230 
231 
232 }
233 
234 
235 
236 #endif //SAX2HANDLER_1357924680
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::SAX2Handler::m_locale
XMLCh * m_locale
Definition: SAX2Handler.hpp:207
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xercesc
Definition: DOMSupportDefault.hpp:32
xalanc::SAX2Handler::m_numberOfRecords
int m_numberOfRecords
Definition: SAX2Handler.hpp:205
xalanc::SAX2Handler::m_startCollectingCharacters
bool m_startCollectingCharacters
Definition: SAX2Handler.hpp:209
xalanc::SAX2Handler::getLocale
const XMLCh * getLocale() const
Definition: SAX2Handler.hpp:155
MsgFileOutputStream.hpp
xalanc::MsgFileOutputStream
Definition: MsgFileOutputStream.hpp:41
xalanc::SAX2Handler
Definition: SAX2Handler.hpp:115