InputSource.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // InputSource.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // SAX InputSource - A single input source for an XML entity.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef SAX_InputSource_INCLUDED
  16. #define SAX_InputSource_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. #include "Poco/XML/XMLStream.h"
  20. namespace Poco {
  21. namespace XML {
  22. class XML_API InputSource
  23. /// This class allows a SAX application to encapsulate information about an input
  24. /// source in a single object, which may include a public identifier, a system
  25. /// identifier, a byte stream (possibly with a specified encoding), and/or a character
  26. /// stream.
  27. ///
  28. /// There are two places that the application can deliver an input source to the
  29. /// parser: as the argument to the Parser.parse method, or as the return value of the
  30. /// EntityResolver::resolveEntity() method.
  31. ///
  32. /// The SAX parser will use the InputSource object to determine how to read XML input.
  33. /// If there is a character stream available, the parser will read that stream directly,
  34. /// disregarding any text encoding declaration found in that stream. If there is no character
  35. /// stream, but there is a byte stream, the parser will use that byte stream, using the
  36. /// encoding specified in the InputSource or else (if no encoding is specified) autodetecting
  37. /// the character encoding using an algorithm such as the one in the XML specification.
  38. /// If neither a character stream nor a byte stream is available, the parser will attempt
  39. /// to open a URI connection to the resource identified by the system identifier.
  40. ///
  41. /// An InputSource object belongs to the application: the SAX parser shall never modify it in
  42. /// any way (it may modify a copy if necessary). However, standard processing of both byte and
  43. /// character streams is to close them on as part of end-of-parse cleanup, so applications should
  44. /// not attempt to re-use such streams after they have been handed to a parser.
  45. {
  46. public:
  47. InputSource();
  48. /// Zero-argument default constructor.
  49. InputSource(const XMLString& systemId);
  50. /// Creates a new input source with a system identifier.
  51. /// Applications may use setPublicId to include a public identifier as well,
  52. /// or setEncoding to specify the character encoding, if known.
  53. ///
  54. /// If the system identifier is a URL, it must be fully resolved (it may not
  55. /// be a relative URL).
  56. InputSource(XMLByteInputStream& istr);
  57. /// Creates a new input source with a byte stream.
  58. ///
  59. /// Application writers should use setSystemId() to provide a base for resolving
  60. /// relative URIs, may use setPublicId to include a public identifier, and may use
  61. /// setEncoding to specify the object's character encoding.
  62. ~InputSource();
  63. /// Destroys the InputSource.
  64. void setPublicId(const XMLString& publicId);
  65. /// Set the public identifier for this input source.
  66. ///
  67. /// The public identifier is always optional: if the application writer includes one,
  68. /// it will be provided as part of the location information.
  69. void setSystemId(const XMLString& systemId);
  70. /// Set the system identifier for this input source.
  71. ///
  72. /// The system identifier is optional if there is a byte stream or a character stream,
  73. /// but it is still useful to provide one, since the application can use it to resolve
  74. /// relative URIs and can include it in error messages and warnings (the parser will
  75. /// attempt to open a connection to the URI only if there is no byte stream or character
  76. /// stream specified).
  77. ///
  78. /// If the application knows the character encoding of the object pointed to by the system
  79. /// identifier, it can register the encoding using the setEncoding method.
  80. ///
  81. /// If the system identifier is a URL, it must be fully resolved (it may not be a relative URL).
  82. const XMLString& getPublicId() const;
  83. /// Get the public identifier for this input source.
  84. const XMLString& getSystemId() const;
  85. /// Get the system identifier for this input source.
  86. void setByteStream(XMLByteInputStream& istr);
  87. /// Set the byte stream for this input source.
  88. /// The SAX parser will ignore this if there is also a character stream specified, but it
  89. /// will use a byte stream in preference to opening a URI connection itself.
  90. XMLByteInputStream* getByteStream() const;
  91. /// Get the byte stream for this input source.
  92. void setCharacterStream(XMLCharInputStream& istr);
  93. /// Set the character stream for this input source.
  94. XMLCharInputStream* getCharacterStream() const;
  95. /// Get the character stream for this input source.
  96. void setEncoding(const XMLString& encoding);
  97. /// Set the character encoding, if known.
  98. /// The encoding must be a string acceptable for an XML encoding declaration
  99. /// (see section 4.3.3 of the XML 1.0 recommendation).
  100. const XMLString& getEncoding() const;
  101. /// Get the character encoding for a byte stream or URI.
  102. private:
  103. XMLString _publicId;
  104. XMLString _systemId;
  105. XMLString _encoding;
  106. XMLByteInputStream* _bistr;
  107. XMLCharInputStream* _cistr;
  108. };
  109. //
  110. // inlines
  111. //
  112. inline const XMLString& InputSource::getPublicId() const
  113. {
  114. return _publicId;
  115. }
  116. inline const XMLString& InputSource::getSystemId() const
  117. {
  118. return _systemId;
  119. }
  120. inline const XMLString& InputSource::getEncoding() const
  121. {
  122. return _encoding;
  123. }
  124. inline XMLByteInputStream* InputSource::getByteStream() const
  125. {
  126. return _bistr;
  127. }
  128. inline XMLCharInputStream* InputSource::getCharacterStream() const
  129. {
  130. return _cistr;
  131. }
  132. } } // namespace Poco::XML
  133. #endif // SAX_InputSource_INCLUDED