/usr/include/xalanc/XMLSupport/XalanXMLSerializerBase.hpp is in libxalan-c-dev 1.11-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680)
#define XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680
// Base include file. Must be first.
#include "xalanc/XMLSupport/XMLSupportDefinitions.hpp"
#include "xalanc/Include/XalanVector.hpp"
#include "xalanc/XalanDOM/XalanDOMString.hpp"
// Base class header file.
#include "xalanc/PlatformSupport/FormatterListener.hpp"
XALAN_CPP_NAMESPACE_BEGIN
class XalanOutputStream;
XALAN_USING_XERCES(MemoryManager)
/**
* XalanXMLSerializerBase serves as a base class for XML serializers based on
* FormatterListener events.
*/
class XALAN_XMLSUPPORT_EXPORT XalanXMLSerializerBase : public FormatterListener
{
public:
/**
* Perform static initialization. See class XMLSupportInit.
*/
static void
initialize(MemoryManager& theManager);
/**
* Perform static shut down. See class XMLSupportInit.
*/
static void
terminate();
/**
* Constructor
*
* @param theManager The MemoryManager instance to use for any memory
* allocations
* @param doctypeSystem system identifier to be used in the document
* type declaration
* @param doctypePublic public identifier to be used in the document
* type declaration
* @param xmlDecl true if the XSLT processor should output an XML
* declaration
* @param theStandalone The string the XSLT processor should output for
* the standalone document declaration
*/
XalanXMLSerializerBase(
MemoryManager& theManager,
eXMLVersion theXMLVersion,
const XalanDOMString& theEncoding,
const XalanDOMString& theDoctypeSystem,
const XalanDOMString& theDoctypePublic,
bool xmlDecl,
const XalanDOMString& theStandalone);
virtual
~XalanXMLSerializerBase();
MemoryManager&
getMemoryManager()
{
return m_elemStack.getMemoryManager();
}
// These methods are inherited from FormatterListener ...
virtual void
setDocumentLocator(const Locator* const locator);
virtual void
startDocument();
virtual void
startElement(
const XMLCh* const name,
AttributeList& attrs) = 0;
virtual void
endElement(const XMLCh* const name) = 0;
virtual void
characters(
const XMLCh* const chars,
const size_type length);
virtual void
charactersRaw(
const XMLCh* const chars,
const size_type length) = 0;
virtual void
entityReference(const XMLCh* const name) = 0;
virtual void
ignorableWhitespace(
const XMLCh* const chars,
const size_type length);
virtual void
processingInstruction(
const XMLCh* const target,
const XMLCh* const data);
virtual void
resetDocument();
virtual void
comment(const XMLCh* const data) = 0;
virtual void
cdata(
const XMLCh* const ch,
const size_type length);
virtual const XalanDOMString&
getDoctypeSystem() const;
virtual const XalanDOMString&
getDoctypePublic() const;
virtual const XalanDOMString&
getEncoding() const;
const XalanDOMString&
getVersion() const
{
return m_version;
}
const XalanDOMString&
getStandalone() const
{
return m_standalone;
}
bool
getShouldWriteXMLHeader() const
{
return m_shouldWriteXMLHeader;
}
void
setShouldWriteXMLHeader(bool b)
{
m_shouldWriteXMLHeader = b;
}
typedef XalanVector<bool> BoolStackType;
static const XalanDOMString& s_1_0String;
static const XalanDOMString& s_1_1String;
class XALAN_XMLSUPPORT_EXPORT UTF8
{
public:
// Static data members...
/**
* The string "UTF-8".
*/
static const XalanDOMString& s_encodingString;
/**
* The string "<!DOCTYPE ".
*/
static const char s_doctypeHeaderStartString[];
static const size_type s_doctypeHeaderStartStringLength;
/**
* The string " PUBLIC \"".
*/
static const char s_doctypeHeaderPublicString[];
static const size_type s_doctypeHeaderPublicStringLength;
/**
* The string " SYSTEM \"".
*/
static const char s_doctypeHeaderSystemString[];
static const size_type s_doctypeHeaderSystemStringLength;
/**
* The string "<?xml version=\"".
*/
static const char s_xmlHeaderStartString[];
static const size_type s_xmlHeaderStartStringLength;
/**
* The string "\" encoding=\"".
*/
static const char s_xmlHeaderEncodingString[];
static const size_type s_xmlHeaderEncodingStringLength;
/**
* The string "\" standalone=\"".
*/
static const char s_xmlHeaderStandaloneString[];
static const size_type s_xmlHeaderStandaloneStringLength;
/**
* The string "\"?>".
*/
static const char s_xmlHeaderEndString[];
static const size_type s_xmlHeaderEndStringLength;
/**
* The string "1.0".
*/
static const char s_defaultVersionString[];
static const size_type s_defaultVersionStringLength;
/**
* The string "-//W3C//DTD XHTML".
*/
static const XalanDOMChar s_xhtmlDocTypeString[];
static const size_type s_xhtmlDocTypeStringLength;
/**
* The string "<![CDATA[".
*/
static const char s_cdataOpenString[];
static const size_type s_cdataOpenStringLength;
/**
* The string "]]>".
*/
static const char s_cdataCloseString[];
static const size_type s_cdataCloseStringLength;
/**
* The string "<".
*/
static const char s_lessThanEntityString[];
static const size_type s_lessThanEntityStringLength;
/**
* The string ">".
*/
static const char s_greaterThanEntityString[];
static const size_type s_greaterThanEntityStringLength;
/**
* The string "&".
*/
static const char s_ampersandEntityString[];
static const size_type s_ampersandEntityStringLength;
/**
* The string """.
*/
static const char s_quoteEntityString[];
static const size_type s_quoteEntityStringLength;
};
class XALAN_XMLSUPPORT_EXPORT UTF16
{
public:
/**
* The string "UTF-16".
*/
static const XalanDOMString& s_encodingString;
/**
* The string "<!DOCTYPE ".
*/
static const XalanDOMChar s_doctypeHeaderStartString[];
static const size_type s_doctypeHeaderStartStringLength;
/**
* The string " PUBLIC \"".
*/
static const XalanDOMChar s_doctypeHeaderPublicString[];
static const size_type s_doctypeHeaderPublicStringLength;
/**
* The string " SYSTEM \"".
*/
static const XalanDOMChar s_doctypeHeaderSystemString[];
static const size_type s_doctypeHeaderSystemStringLength;
/**
* The string "<?xml version=\"".
*/
static const XalanDOMChar s_xmlHeaderStartString[];
static const size_type s_xmlHeaderStartStringLength;
/**
* The string "\" encoding=\"".
*/
static const XalanDOMChar s_xmlHeaderEncodingString[];
static const size_type s_xmlHeaderEncodingStringLength;
/**
* The string "\" standalone=\"".
*/
static const XalanDOMChar s_xmlHeaderStandaloneString[];
static const size_type s_xmlHeaderStandaloneStringLength;
/**
* The string "\"?>".
*/
static const XalanDOMChar s_xmlHeaderEndString[];
static const size_type s_xmlHeaderEndStringLength;
/**
* The string "1.0".
*/
static const XalanDOMChar s_defaultVersionString[];
static const size_type s_defaultVersionStringLength;
/**
* The string "-//W3C//DTD XHTML".
*/
static const XalanDOMChar s_xhtmlDocTypeString[];
static const size_type s_xhtmlDocTypeStringLength;
/**
* The string "<![CDATA[".
*/
static const XalanDOMChar s_cdataOpenString[];
static const size_type s_cdataOpenStringLength;
/**
* The string "]]>".
*/
static const XalanDOMChar s_cdataCloseString[];
static const size_type s_cdataCloseStringLength;
/**
* The string "<".
*/
static const XalanDOMChar s_lessThanEntityString[];
static const size_type s_lessThanEntityStringLength;
/**
* The string ">".
*/
static const XalanDOMChar s_greaterThanEntityString[];
static const size_type s_greaterThanEntityStringLength;
/**
* The string "&".
*/
static const XalanDOMChar s_ampersandEntityString[];
static const size_type s_ampersandEntityStringLength;
/**
* The string """.
*/
static const XalanDOMChar s_quoteEntityString[];
static const size_type s_quoteEntityStringLength;
};
enum
{
eBufferSize = 512 // The size of the buffer
};
class XALAN_XMLSUPPORT_EXPORT CharFunctor1_0
{
public:
bool
attribute(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] > eNone;
}
bool
content(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] > eAttr;
}
bool
range(XalanDOMChar theChar) const
{
assert(theChar > 0);
return theChar > s_lastSpecial;
}
bool
isForbidden(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] == eForb;
}
bool
isCharRefForbidden(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] == eForb;
}
private:
static const size_t s_lastSpecial;
static const char s_specialChars[];
};
class XALAN_XMLSUPPORT_EXPORT CharFunctor1_1
{
public:
bool
attribute(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] > eNone;
}
bool
content(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] > eAttr;
}
bool
range(XalanDOMChar theChar) const
{
assert(theChar > 0);
return theChar > s_lastSpecial;
}
bool
isForbidden(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] == eForb;
}
bool
isCharRefForbidden(XalanDOMChar theChar) const
{
return theChar > s_lastSpecial ?
false :
s_specialChars[theChar] == eCRFb;
}
private:
static const size_t s_lastSpecial;
static const char s_specialChars[];
};
enum
{
eNone = 0u,
eAttr = 1u, // A flag to indicate a value in s_specialChars applies to attributes
eBoth = 2u, // A flag to indicate a value in s_specialChars applies to both content and attributes
eForb = 4u, // A flag to indicate a forbidden value in s_specialChars
// XML1.1 put a requirement to output chars #x1...#x1F and #x7F...#x9F as charRefs only
// In the comments , PI and CDATA usage of charRefs is forbidden, so we will report an error in
eCRFb = 5u // that case. For the elemets and attributes is should work the same as eBoth
};
protected:
virtual void
writeXMLHeader() = 0;
virtual void
flushBuffer() = 0;
virtual void
writeDoctypeDecl(const XalanDOMChar* name) = 0;
virtual void
writeProcessingInstruction(
const XMLCh* target,
const XMLCh* data) = 0;
virtual void
writeCharacters(
const XMLCh* chars,
size_type length) = 0;
virtual void
writeCDATA(
const XMLCh* chars,
size_type length) = 0;
virtual void
outputNewline() = 0;
/**
* Mark the parent element as having a child. If this
* is the first child, return true, otherwise, return
* false. This allows the child element to determine
* if the parent tag has already been closed.
*
* @return true if the parent element has not been previously marked for children.
*/
bool
markParentForChildren()
{
if(!m_elemStack.empty())
{
// See if the parent element has already been flagged as having children.
if(false == m_elemStack.back())
{
m_elemStack.back() = true;
return true;
}
}
return false;
}
/**
* Determine if it a DOCTYPE declaration needs to
* be written.
*/
bool
getNeedToOutputDoctypeDecl() const
{
return m_needToOutputDoctypeDecl;
}
/**
* Open an element for possibile children
*/
void
openElementForChildren()
{
m_elemStack.push_back(false);
}
bool
outsideDocumentElement() const
{
return m_elemStack.empty();
}
/**
* Determine if an element ever had any children added.
*
* @return true if the children were added, false if not.
*/
bool
childNodesWereAdded()
{
bool fResult = false;
if (m_elemStack.empty() == false)
{
fResult = m_elemStack.back();
m_elemStack.pop_back();
}
return fResult;
}
void
generateDoctypeDecl(const XalanDOMChar* name)
{
if(true == m_needToOutputDoctypeDecl)
{
assert(m_doctypeSystem.empty() == false);
writeDoctypeDecl(name);
m_needToOutputDoctypeDecl = false;
}
}
/**
* Tell if the next text should be raw.
*/
bool m_nextIsRaw;
/**
* Add space before '/>' for XHTML.
*/
bool m_spaceBeforeClose;
/**
* The System ID for the doc type.
*/
const XalanDOMString m_doctypeSystem;
/**
* The public ID for the doc type.
*/
const XalanDOMString m_doctypePublic;
/**
* Tells the XML version, for writing out to the XML decl.
*/
const XalanDOMString& m_version;
/**
* Text for standalone part of header.
*/
const XalanDOMString m_standalone;
const XalanDOMString m_encoding;
static bool
isUTF16HighSurrogate(XalanDOMChar theChar)
{
return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
}
static bool
isUTF16LowSurrogate(XalanDOMChar theChar)
{
return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
}
static XalanUnicodeChar
decodeUTF16SurrogatePair(
XalanDOMChar theHighSurrogate,
XalanDOMChar theLowSurrogate,
MemoryManager& theManager);
/**
* Throw an exception when an invalid
* surrogate is encountered.
* @param ch The first character in the surrogate
*/
static void
throwInvalidUTF16SurrogateException(
XalanDOMChar ch,
MemoryManager& theManager);
/**
* Throw an exception when an invalid
* surrogate is encountered.
* @param ch The first character in the surrogate
* @param next The next character in the surrogate
*/
static void
throwInvalidUTF16SurrogateException(
XalanDOMChar ch,
XalanDOMChar next,
MemoryManager& theManager);
/**
* Throw an exception when an invalid
* character is encountered.
* @param ch The first character in the surrogate
* @param next The next character in the surrogate
*/
static void
throwInvalidCharacterException(
XalanUnicodeChar ch,
MemoryManager& theManager);
/**
* Throw an exception when an invalid
* character for the specific XML version is encountered.
* @param ch The first character in the surrogate
* @param next The next character in the surrogate
*/
static void
throwInvalidXMLCharacterException(
XalanUnicodeChar ch,
const XalanDOMString& theXMLversion,
MemoryManager& theManager);
private:
// These are not implemented.
XalanXMLSerializerBase(const XalanXMLSerializerBase&);
XalanXMLSerializerBase&
operator=(const XalanXMLSerializerBase&);
bool
operator==(const XalanXMLSerializerBase&) const;
// Data members...
/**
* Flag to tell that we need to add the doctype decl,
* which we can't do until the first element is
* encountered.
*/
bool m_needToOutputDoctypeDecl;
/**
* If true, XML header should be written to output.
*/
bool m_shouldWriteXMLHeader;
/**
* A stack of Boolean objects that tell if the given element
* has children.
*/
BoolStackType m_elemStack;
/**
* The string "-//W3C//DTD XHTML".
*/
static const XalanDOMChar s_xhtmlDocTypeString[];
static const size_type s_xhtmlDocTypeStringLength;
};
XALAN_CPP_NAMESPACE_END
#endif // XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680
|