Xalan-C++ API Reference  1.12.0
XalanTranscodingServices.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(XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680)
19 #define XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
28 #include <cassert>
29 
30 
31 
34 
35 
36 
37 namespace XALAN_CPP_NAMESPACE {
38 
39 
40 
41 class XalanOutputTranscoder;
42 
43 
44 
46 {
47 public:
48 
49  /**
50  * Perform static initialization. See class PlatformSupportInit.
51  */
52  static void
53  initialize(MemoryManager& theManager);
54 
55  /**
56  * Perform static shut down. See class PlatformSupportInit.
57  */
58  static void
59  terminate();
60 
61  typedef unsigned char XalanXMLByte;
62  typedef XalanSize_t size_type;
63 
64  static size_type
65  length(const XalanXMLByte* theBytes)
66  {
67  assert(theBytes != 0);
68 
69  size_type i = 0;
70 
71  while(theBytes[i] != 0)
72  {
73  ++i;
74  }
75 
76  return i;
77  }
78 
79  enum eCode
80  {
81  OK,
84  SupportFilesNotFound
85  };
86 
87 
88  /**
89  * Create a transcoder instance for the specified encoding.
90  *
91  * @param theEncodingName The name of the desired output encoding.
92  * @param theResult The error code.
93  * @param theTarget The target array for storing the transcoded data.
94  * @param theBlockSize The block size the transcoder should use.
95  * @return The new transcoder, or 0 if there was an error.
96  */
97  static XalanOutputTranscoder*
98  makeNewTranscoder(
99  MemoryManager& theManager,
100  const XalanDOMString& theEncodingName,
101  eCode& theResult,
102  size_type theBlockSize);
103 
104  static XalanOutputTranscoder*
105  makeNewTranscoder(
106  MemoryManager& theManager,
107  const XalanDOMChar* theEncodingName,
108  eCode& theResult,
109  size_type theBlockSize);
110 
111  /**
112  * Destroy a transcoder instance.
113  *
114  * @theTranscoder The transcoder to destroy.
115  */
116  static void
117  destroyTranscoder(XalanOutputTranscoder* theTranscoder);
118 
119  /**
120  * Determine if the encoding name supplied is equivalent to UTF-8.
121  *
122  * @param theEncodingName The name of the output encoding.
123  * @return true or false
124  */
125  static bool
126  encodingIsUTF8(const XalanDOMChar* theEncodingName);
127 
128  /**
129  * Determine if the encoding name supplied is equivalent to UTF-8.
130  *
131  * @param theEncodingName The name of the output encoding.
132  * @return true or false
133  */
134  static bool
135  encodingIsUTF8(const XalanDOMString& theEncodingName);
136 
137  /**
138  * Determine if the encoding name supplied is equivalent to UTF-16.
139  *
140  * @param theEncodingName The name of the output encoding.
141  * @return true or false
142  */
143  static bool
144  encodingIsUTF16(const XalanDOMChar* theEncodingName);
145 
146  /**
147  * Determine if the encoding name supplied is equivalent to UTF-16.
148  *
149  * @param theEncodingName The name of the output encoding.
150  * @return true or false
151  */
152  static bool
153  encodingIsUTF16(const XalanDOMString& theEncodingName);
154 
155  /**
156  * Determine if the encoding name supplied is equivalent to UTF-32.
157  *
158  * @param theEncodingName The name of the output encoding.
159  * @return true or false
160  */
161  static bool
162  encodingIsUTF32(const XalanDOMChar* theEncodingName);
163 
164  /**
165  * Determine if the encoding name supplied is equivalent to UTF-32.
166  *
167  * @param theEncodingName The name of the output encoding.
168  * @return true or false
169  */
170  static bool
171  encodingIsUTF32(const XalanDOMString& theEncodingName);
172 
173  /**
174  * Get an array that contains any leading bytes that should be
175  * written to an XML stream for the specified encoding. For example,
176  * if the encoding is UTF-16, the vector will contain the appropriate
177  * byte order mark for the current platform. If there is no
178  * prolog for the encoding, or the encoding is unknown, an empty
179  * array is returned.
180  *
181  * @param theEncodingName The name of the desired output encoding.
182  * @return An array containing the appropriate bytes.
183  */
184  static const XalanXMLByte*
185  getStreamProlog(const XalanDOMString& theEncodingName);
186 
187  /**
188  * Get the maximum character value for the encoding.
189  *
190  * @param theEncoding The encoding name.
191  * @return The maximum character value the encoding supports.
192  */
193  static XalanDOMChar
194  getMaximumCharacterValue(const XalanDOMString& theEncoding);
195 
196  /**
197  * Get the maximum character value for the local code page.
198  * This is now deprecated, since it's impossibly broken.
199  *
200  * @deprecated
201  *
202  * @return The maximum character value the local code page supports.
203  */
204  static XalanDOMChar
205  getMaximumCharacterValue();
206 
207  /**
208  * Determine if the output stage can safely skip transcoding
209  * by truncating.
210  *
211  * @param theEncoding The encoding name.
212  * @return true if truncation is possible, false if not.
213  */
214  static bool
215  getBytesEqualChars(const XalanDOMString& theEncoding);
216 
217  static const XalanDOMChar s_utf8String[];
218 
219  static const XalanDOMChar s_utf16String[];
220 
221  static const XalanDOMChar s_utf16LEString[];
222 
223  static const XalanDOMChar s_utf16BEString[];
224 
225  static const XalanDOMChar s_utf32String[];
226 
227  static const XalanDOMChar s_asciiString[];
228 
229  static const XalanDOMChar s_usASCIIString[];
230 
231  static const XalanDOMChar s_windows1250String[];
232 
233  static const XalanDOMChar s_iso88591String[];
234 
235  static const XalanDOMChar s_shiftJISString[];
236 
237 
239  {
240  public:
241 
243  eCode theCode,
244  const XalanDOMChar* theEncoding,
245  XalanDOMString& theBuffer,
246  const Locator* theLocator = 0);
247 
249 
250  virtual
252 
253  eCode
254  getCode() const
255  {
256  return m_code;
257  }
258 
259  const XalanDOMString&
260  getEncoding() const
261  {
262  return m_encoding;
263  }
264 
265  virtual const XalanDOMChar*
266  getType() const
267  {
268  return s_type;
269  }
270 
271  private:
272 
273  static const XalanDOMChar s_type[];
274 
275  const eCode m_code;
276 
277  mutable XalanDOMString m_encoding;
278  };
279 
281  {
282  public:
283 
285  XalanUnicodeChar theCharacter,
286  const XalanDOMString& theEncoding,
287  XalanDOMString& theBuffer,
288  const Locator* theLocator = 0);
289 
291 
292  virtual
294 
295  XalanUnicodeChar
296  getCharacter() const
297  {
298  return m_badCharacter;
299  }
300 
301  const XalanDOMString&
302  getEncoding() const
303  {
304  return m_encoding;
305  }
306 
307  virtual const XalanDOMChar*
308  getType() const
309  {
310  return s_type;
311  }
312 
313  private:
314 
315  static const XalanDOMChar s_type[];
316 
317 
318  const XalanUnicodeChar m_badCharacter;
319 
320  mutable XalanDOMString m_encoding;
321  };
322 
323 private:
324 
325  static const XalanXMLByte s_dummyByteOrderMark[];
326  static const XalanXMLByte s_UTF8ByteOrderMark[];
327  static const XalanDOMChar s_UTF16ByteOrderMark[];
328 };
329 
330 
331 
333 {
334 public:
335 
339 
340  explicit
341  XalanOutputTranscoder(MemoryManager& theManager);
342 
343  virtual
345 
346  MemoryManager&
348  {
349  return m_memoryManager;
350  }
351 
352  /**
353  * Transcode data from UTF-16 to the transcoder's encoding. If successfull,
354  * theResult will be set to OK. If not, it will be set to one of the other
355  * codes.
356  *
357  * @param theSourceData The source data to transcode
358  * @param theSourceCount The length of the source data.
359  * @param theTarget The target array for storing the transcoded data.
360  * @param theTargetSize The number of characters that can be stored in the target.
361  * @param theSourceCharsTranscoded The count of the source characters that were transcoded.
362  * @param theTargetBytesUsed The number of characters stored in the target array
363  * @return The result code.
364  */
365  virtual eCode
366  transcode(
367  const XalanDOMChar* theSourceData,
368  size_type theSourceCount,
369  XalanXMLByte* theTarget,
370  size_type theTargetSize,
371  size_type& theSourceCharsTranscoded,
372  size_type& theTargetBytesUsed) = 0;
373 
374  /**
375  * Transcode data from the transcoder's encoding to UTF-16. If successfull,
376  * theResult will be set to OK. If not, it will be set to one of the other
377  * codes.
378  *
379  * @param theSourceData The source data to transcode
380  * @param theSourceCount The length of the source data.
381  * @param theTarget The target array for storing the transcoded data.
382  * @param theTargetSize The number of characters that can be stored in the target.
383  * @param theSourceCharsTranscoded The count of the source characters that were transcoded.
384  * @param theTargetBytesUsed The number of characters stored in the target array
385  * @param theCharSizes For each character in theTarget, the number of characters consumed from theSourceData.
386  * @return The result code.
387  */
388  virtual eCode
389  transcode(
390  const XalanXMLByte* theSourceData,
391  size_type theSourceCount,
392  XalanDOMChar* theTarget,
393  size_type theTargetSize,
394  size_type& theSourceCharsTranscoded,
395  size_type& theTargetBytesUsed,
396  unsigned char* theCharSizes) = 0;
397 
398  virtual bool
399  canTranscodeTo(XalanUnicodeChar theChar) const = 0;
400 
401 private:
402 
403  MemoryManager& m_memoryManager;
404 
405  // Not implemented...
407 
408  bool
409  operator==(const XalanOutputTranscoder& theRHS) const;
410 
412  operator=(const XalanOutputTranscoder& theRHS);
413 };
414 
415 
416 
417 }
418 
419 
420 
421 #endif // XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680
xalanc::XalanOutputTranscoder
Definition: XalanTranscodingServices.hpp:332
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanTranscodingServices::MakeTranscoderException
Definition: XalanTranscodingServices.hpp:238
xalanc::XalanTranscodingServices::InternalFailure
@ InternalFailure
Definition: XalanTranscodingServices.hpp:83
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::XalanOutputTranscoder::size_type
XalanTranscodingServices::size_type size_type
Definition: XalanTranscodingServices.hpp:338
DOMStringHelper.hpp
xalanc::XalanTranscodingServices::eCode
eCode
Definition: XalanTranscodingServices.hpp:79
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::XSLException
Definition: XSLException.hpp:42
xalanc::XalanTranscodingServices::MakeTranscoderException::getType
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
Definition: XalanTranscodingServices.hpp:266
xalanc::XalanTranscodingServices::length
static size_type length(const XalanXMLByte *theBytes)
Definition: XalanTranscodingServices.hpp:65
xalanc::XalanTranscodingServices::UnrepresentableCharacterException::getCharacter
XalanUnicodeChar getCharacter() const
Definition: XalanTranscodingServices.hpp:296
xalanc::XalanTranscodingServices::UnrepresentableCharacterException::getEncoding
const XalanDOMString & getEncoding() const
Definition: XalanTranscodingServices.hpp:302
xalanc::XalanTranscodingServices::XalanXMLByte
unsigned char XalanXMLByte
Definition: XalanTranscodingServices.hpp:61
XSLException.hpp
xalanc::XalanOutputTranscoder::eCode
XalanTranscodingServices::eCode eCode
Definition: XalanTranscodingServices.hpp:337
xalanc::XalanTranscodingServices::MakeTranscoderException::getEncoding
const XalanDOMString & getEncoding() const
Definition: XalanTranscodingServices.hpp:260
xalanc::XalanTranscodingServices::UnsupportedEncoding
@ UnsupportedEncoding
Definition: XalanTranscodingServices.hpp:82
xalanc::XalanTranscodingServices
Definition: XalanTranscodingServices.hpp:45
xalanc::XalanOutputTranscoder::getMemoryManager
MemoryManager & getMemoryManager()
Definition: XalanTranscodingServices.hpp:347
xalanc::XalanTranscodingServices::size_type
XalanSize_t size_type
Definition: XalanTranscodingServices.hpp:62
xalanc::XalanTranscodingServices::UnrepresentableCharacterException
Definition: XalanTranscodingServices.hpp:280
xalanc::XalanTranscodingServices::MakeTranscoderException::getCode
eCode getCode() const
Definition: XalanTranscodingServices.hpp:254
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanTranscodingServices::UnrepresentableCharacterException::getType
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
Definition: XalanTranscodingServices.hpp:308
xalanc::XalanOutputTranscoder::XalanXMLByte
XalanTranscodingServices::XalanXMLByte XalanXMLByte
Definition: XalanTranscodingServices.hpp:336
xalanc::XalanTranscodingServices::OK
@ OK
Definition: XalanTranscodingServices.hpp:81