Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanFormatterWriter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XALANFORMATTERWRITER_HEADER_GUARD_1357924680)
17 #define XALANFORMATTERWRITER_HEADER_GUARD_1357924680
18 
19 
20 
21 // Base include file. Must be first.
23 
24 #include <xercesc/sax/SAXException.hpp>
25 
30 
31 
32 
33 XALAN_CPP_NAMESPACE_BEGIN
34 
35 
36 
37 XALAN_USING_XERCES(MemoryManager)
38 
39 
40 
42 {
43 public:
44 
45  template <class WriterType>
47  {
48  public:
49 
50  typedef WriterType writer_type;
51 
52  NewLineWriterFunctor(WriterType& writer) :
53  m_writer(writer),
54  m_newlineString(0),
55  m_newlineStringLength(0)
56  {
57  XalanOutputStream* stream = writer.getStream();
58 
59  if(stream != 0)
60  {
61  m_newlineString = stream->getNewlineString();
62  }
63  else
64  {
65  m_newlineString = XalanOutputStream::defaultNewlineString();
66  }
67 
68  assert(m_newlineString != 0);
69 
70  m_newlineStringLength = length(m_newlineString);
71  }
72 
73  void
75  {
76  assert(m_newlineString != 0 && length(m_newlineString) == m_newlineStringLength);
77 
78  m_writer.write(m_newlineString, m_newlineStringLength);
79  }
80 
81  private:
82 
83  WriterType& m_writer;
84 
88  const XalanDOMChar* m_newlineString;
89 
93  XalanDOMString::size_type m_newlineStringLength;
94  };
95 
96  template<class WriterType>
98  {
100  typedef typename WriterType::value_type value_type;
101  public:
102  typedef WriterType writer_type;
103 
104  WhiteSpaceWriterFunctor(WriterType& writer) :
105  m_writer(writer)
106  {
107  }
108 
109  void
110  operator()(size_type count)
111  {
112  for ( size_type i = 0 ; i < count ; i++ )
113  {
114  m_writer.write(value_type(XalanUnicode::charSpace));
115  }
116  }
117 
118  private:
119 
120  WriterType& m_writer;
121  };
122 
124  {
125  public:
126 
128  m_stream(stream)
129  {
130  assert(stream != 0);
131  }
132 
133  bool
134  operator()(unsigned int theChar) const
135  {
136  bool result = true;
137 
138  if( m_stream != 0)
139  {
140  result = m_stream->canTranscodeTo(theChar);
141  }
142 
143  return result;
144  }
145 
146  private:
147 
148  const XalanOutputStream* const m_stream;
149  };
150 
151 public:
152 
154 
155 
157  Writer& theWriter,
158  MemoryManager& theMemoryManager) :
159  m_writer(theWriter),
160  m_memoryManager(theMemoryManager),
161  m_stringBuffer(5, 0, theMemoryManager)
162  {
163  const XalanOutputStream* const theStream =
164  theWriter.getStream();
165 
166  if (theStream == 0)
167  {
168  m_newlineString = XalanOutputStream::defaultNewlineString();
169  }
170  else
171  {
172  m_newlineString = theStream->getNewlineString();
173  }
174 
175  assert(m_newlineString != 0);
176 
177  m_newlineStringLength = length(m_newlineString);
178 
179  assert(m_newlineString != 0);
180  }
181 
184  {
185  return m_memoryManager;
186  }
187 
188  virtual
190  {
191  }
192 
193  Writer*
194  getWriter() const
195  {
196  return &m_writer;
197  }
198 
201  {
202  return m_writer.getStream();
203  }
204 
205  const XalanOutputStream*
206  getStream() const
207  {
208  return m_writer.getStream();
209  }
210 
211  void
213  {
214  m_writer.flush();
215  }
216 
217 
218  static bool
219  isUTF16HighSurrogate(XalanDOMChar theChar)
220  {
221  return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
222  }
223 
224  static bool
225  isUTF16LowSurrogate(XalanDOMChar theChar)
226  {
227  return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
228  }
229 
230  static unsigned int
232  XalanDOMChar theHighSurrogate,
233  XalanDOMChar theLowSurrogate,
234  MemoryManager& theManager)
235  {
236  assert(isUTF16HighSurrogate(theHighSurrogate) == true);
237 
238  if (isUTF16LowSurrogate(theLowSurrogate) == false)
239  {
240  throwInvalidUTF16SurrogateException(theHighSurrogate, theLowSurrogate, theManager);
241  }
242 
243  return ((theHighSurrogate - 0xD800u) << 10) + theLowSurrogate - 0xDC00u + 0x00010000u;
244  }
245 
246  static void
248  unsigned int ch,
249  MemoryManager& theManager)
250  {
251  XalanDOMString theMessage(theManager);
252  XalanDOMString theBuffer(theManager);
253 
255  theMessage,
256  XalanMessages::InvalidScalar_1Param,
257  UnsignedLongToHexDOMString(ch, theBuffer));
258 
259  XALAN_USING_XERCES(SAXException)
260 
261  throw SAXException(c_wstr(theMessage), &theManager);
262  }
263 
264  static void
266  XalanDOMChar ch,
267  XalanDOMChar next,
268  MemoryManagerType& theManager)
269  {
270 
271  XalanDOMString chStr(theManager);
272 
273  XalanDOMString nextStr(theManager);
274 
275  UnsignedLongToHexDOMString(ch, chStr);
276 
277  UnsignedLongToHexDOMString(next, nextStr);
278 
279  XalanDOMString theMessage(theManager);
280 
282  theMessage,
283  XalanMessages::InvalidSurrogatePair_2Param,
284  theMessage,
285  chStr,
286  nextStr);
287 
288  XALAN_USING_XERCES(SAXException)
289 
290  throw SAXException(c_wstr(theMessage),&theManager);
291  }
292 
293 protected:
294 
299 
304  MemoryManager& m_memoryManager;
305 
307 
311  const XalanDOMChar* m_newlineString;
312 
317 
323  const XalanDOMString&
324  formatNumericCharacterReference(unsigned int theNumber)
325  {
326  clear(m_stringBuffer);
327 
328  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charAmpersand));
329  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charNumberSign));
330 
331  UnsignedLongToDOMString(theNumber, m_stringBuffer);
332 
333  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charSemicolon));
334 
335  return m_stringBuffer;
336  }
337 
338 private:
339 
340  // These are not implemented.
341  XalanFormatterWriter();
342 
343  XalanFormatterWriter&
344  operator=(const XalanFormatterWriter&);
345 };
346 
347 
348 
349 XALAN_CPP_NAMESPACE_END
350 
351 
352 
353 #endif // XALANFORMATTERWRITER_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo