Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


XalanFormatterWriter.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 #if !defined(XALANFORMATTERWRITER_HEADER_GUARD_1357924680)
19 #define XALANFORMATTERWRITER_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 #include <xercesc/sax/SAXException.hpp>
27 
33 
34 
35 
36 XALAN_CPP_NAMESPACE_BEGIN
37 
38 
39 
40 XALAN_USING_XERCES(MemoryManager)
41 
42 
43 
45 {
46 public:
47 
49 
50 
51  template <class WriterType>
53  {
54  public:
55 
56  typedef WriterType writer_type;
57 
58  NewLineWriterFunctor(WriterType& writer) :
59  m_writer(writer),
60  m_newlineString(0),
61  m_newlineStringLength(0)
62  {
63  XalanOutputStream* stream = writer.getStream();
64 
65  if(stream != 0)
66  {
67  m_newlineString = stream->getNewlineString();
68  }
69  else
70  {
71  m_newlineString = XalanOutputStream::defaultNewlineString();
72  }
73 
74  assert(m_newlineString != 0);
75 
76  m_newlineStringLength = length(m_newlineString);
77  }
78 
79  void
81  {
82  assert(m_newlineString != 0 && length(m_newlineString) == m_newlineStringLength);
83 
84  m_writer.write(m_newlineString, m_newlineStringLength);
85  }
86 
87  private:
88 
89  WriterType& m_writer;
90 
91  /**
92  * The string of characters that represents the newline
93  */
94  const XalanDOMChar* m_newlineString;
95 
96  /**
97  * The length of the the string of characters that represents the newline
98  */
99  size_type m_newlineStringLength;
100  };
101 
102  template<class WriterType>
104  {
105  typedef typename WriterType::value_type value_type;
106 
107  public:
108  typedef WriterType writer_type;
109 
110  WhiteSpaceWriterFunctor(WriterType& writer) :
111  m_writer(writer)
112  {
113  }
114 
115  void
116  operator()(size_type count)
117  {
118  for ( size_type i = 0 ; i < count ; i++ )
119  {
120  m_writer.write(value_type(XalanUnicode::charSpace));
121  }
122  }
123 
124  private:
125 
126  WriterType& m_writer;
127  };
128 
130  {
131  public:
132 
134  m_stream(stream)
135  {
136  assert(stream != 0);
137  }
138 
139  bool
140  operator()(XalanUnicodeChar theChar) const
141  {
142  bool result = true;
143 
144  if (m_stream != 0)
145  {
146  result = m_stream->canTranscodeTo(theChar);
147  }
148 
149  return result;
150  }
151 
152  private:
153 
154  const XalanOutputStream* const m_stream;
155  };
156 
157 public:
158 
160  Writer& theWriter,
161  MemoryManager& theMemoryManager) :
162  m_writer(theWriter),
163  m_memoryManager(theMemoryManager),
164  m_stringBuffer(5, 0, theMemoryManager)
165  {
166  const XalanOutputStream* const theStream =
167  theWriter.getStream();
168 
169  if (theStream == 0)
170  {
171  m_newlineString = XalanOutputStream::defaultNewlineString();
172  }
173  else
174  {
175  m_newlineString = theStream->getNewlineString();
176  }
177 
178  assert(m_newlineString != 0);
179 
180  m_newlineStringLength = length(m_newlineString);
181 
182  assert(m_newlineString != 0);
183  }
184 
185  MemoryManager&
187  {
188  return m_memoryManager;
189  }
190 
191  virtual
193  {
194  }
195 
196  Writer*
197  getWriter() const
198  {
199  return &m_writer;
200  }
201 
204  {
205  return m_writer.getStream();
206  }
207 
208  const XalanOutputStream*
209  getStream() const
210  {
211  return m_writer.getStream();
212  }
213 
214  void
216  {
217  m_writer.flush();
218  }
219 
220 
221  static bool
222  isUTF16HighSurrogate(XalanDOMChar theChar)
223  {
224  return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
225  }
226 
227  static bool
228  isUTF16LowSurrogate(XalanDOMChar theChar)
229  {
230  return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
231  }
232 
233  static XalanUnicodeChar
235  XalanDOMChar theHighSurrogate,
236  XalanDOMChar theLowSurrogate,
237  MemoryManager& theManager)
238  {
239  assert(isUTF16HighSurrogate(theHighSurrogate) == true);
240 
241  if (isUTF16LowSurrogate(theLowSurrogate) == false)
242  {
243  throwInvalidUTF16SurrogateException(theHighSurrogate, theLowSurrogate, theManager);
244  }
245 
246  return ((theHighSurrogate - 0xD800u) << 10) + theLowSurrogate - 0xDC00u + 0x00010000u;
247  }
248 
249  static void
251  XalanUnicodeChar ch,
252  MemoryManager& theManager)
253  {
254  XalanDOMString theMessage(theManager);
255  XalanDOMString theBuffer(theManager);
256 
258  theMessage,
259  XalanMessages::InvalidScalar_1Param,
260  NumberToHexDOMString(ch, theBuffer));
261 
262  XALAN_USING_XERCES(SAXException)
263 
264  throw SAXException(theMessage.c_str(), &theManager);
265  }
266 
267  void
269  XalanUnicodeChar ch,
270  MemoryManager& theManager)
271  {
272  XalanDOMString theBuffer(theManager);
273 
274  const XalanOutputStream* const theStream =
275  m_writer.getStream();
276 
278  ch,
279  theStream->getOutputEncoding(),
280  theBuffer);
281  }
282 
283  static void
285  XalanDOMChar ch,
286  XalanDOMChar next,
287  MemoryManager& theManager)
288  {
289 
290  XalanDOMString chStr(theManager);
291 
292  XalanDOMString nextStr(theManager);
293 
294  NumberToHexDOMString(ch, chStr);
295 
296  NumberToHexDOMString(next, nextStr);
297 
298  XalanDOMString theMessage(theManager);
299 
301  theMessage,
302  XalanMessages::InvalidSurrogatePair_2Param,
303  theMessage,
304  chStr,
305  nextStr);
306 
307  XALAN_USING_XERCES(SAXException)
308 
309  throw SAXException(theMessage.c_str(),&theManager);
310  }
311 
312 protected:
313 
314  /**
315  * The writer.
316  */
318 
319  /**
320  * The MemoryManager instance to use for any dynamically-
321  * allocated memory.
322  */
323  MemoryManager& m_memoryManager;
324 
326 
327  /**
328  * The string of characters that represents the newline
329  */
330  const XalanDOMChar* m_newlineString;
331 
332  /**
333  * The length of the the string of characters that represents the newline
334  */
336 
337  /**
338  * Format a code point as a numeric character reference.
339  *
340  * @param theChar A Unicode code point.
341  */
342  const XalanDOMString&
343  formatNumericCharacterReference(XalanUnicodeChar theChar)
344  {
345  m_stringBuffer.clear();
346 
347  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charAmpersand));
348  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charNumberSign));
349 
350  NumberToDOMString(theChar, m_stringBuffer);
351 
352  m_stringBuffer.push_back(XalanDOMChar(XalanUnicode::charSemicolon));
353 
354  return m_stringBuffer;
355  }
356 
357 private:
358 
359  // These are not implemented.
360  XalanFormatterWriter();
361 
362  XalanFormatterWriter&
363  operator=(const XalanFormatterWriter&);
364 };
365 
366 
367 
368 XALAN_CPP_NAMESPACE_END
369 
370 
371 
372 #endif // XALANFORMATTERWRITER_HEADER_GUARD_1357924680
static const XalanDOMChar * defaultNewlineString()
static bool isUTF16LowSurrogate(XalanDOMChar theChar)
static XalanDOMString & getMessage(XalanDOMString &theResultMessage, XalanMessages::Codes msgToLoad, const char *repText1, const char *repText2=0, const char *repText3=0, const char *repText4=0)
CommonRepresentableCharFunctor(const XalanOutputStream *stream)
static void throwInvalidUTF16SurrogateException(XalanDOMChar ch, XalanDOMChar next, MemoryManager &theManager)
static bool isUTF16HighSurrogate(XalanDOMChar theChar)
const XalanDOMChar * c_str() const
MemoryManager & getMemoryManager()
Writer & m_writer
The writer.
static XalanUnicodeChar decodeUTF16SurrogatePair(XalanDOMChar theHighSurrogate, XalanDOMChar theLowSurrogate, MemoryManager &theManager)
const XalanOutputStream * getStream() const
size_type m_newlineStringLength
The length of the the string of characters that represents the newline.
void push_back(XalanDOMChar theChar)
NumberToDOMString(double theValue, XalanDOMString &theResult)
Converts a double value into a XalanDOMString.
const XalanDOMString & getOutputEncoding() const
Get the output encoding for the stream.
void throwUnrepresentableCharacterException(XalanUnicodeChar ch, MemoryManager &theManager)
static void throwInvalidCharacterException(XalanUnicodeChar ch, MemoryManager &theManager)
MemoryManager & m_memoryManager
The MemoryManager instance to use for any dynamically- allocated memory.
const XalanDOMString & formatNumericCharacterReference(XalanUnicodeChar theChar)
Format a code point as a numeric character reference.
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
NumberToHexDOMString(XALAN_UINT64 theValue, XalanDOMString &theResult)
Converts an 64-bit unsigned value into a XalanDOMString.
XALAN_CPP_NAMESPACE_BEGIN XALAN_USING_XERCES(Locator)
const XalanDOMChar * m_newlineString
The string of characters that represents the newline.
virtual const XalanDOMChar * getNewlineString() const
Get the string which is appropriate for inserting a line feed in the stream.
XalanFormatterWriter(Writer &theWriter, MemoryManager &theMemoryManager)
XalanOutputStream * getStream()
virtual XalanOutputStream * getStream()
Get the stream associated with the writer...
FormatterListener::size_type size_type

Interpreting class diagrams

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

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

Apache Logo