mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-18 22:26:32 +01:00
*** empty log message ***
This commit is contained in:
parent
4e7e47a6de
commit
d31cba3174
2 changed files with 242 additions and 0 deletions
164
SAX/ext/ProgressiveParser.h
Normal file
164
SAX/ext/ProgressiveParser.h
Normal file
|
@ -0,0 +1,164 @@
|
|||
#ifndef ARABICA_PROGRESSIVE_PARSER_H
|
||||
#define ARABICA_PROGRESSIVE_PARSER_H
|
||||
|
||||
#include <SAX/ArabicaConfig.h>
|
||||
#include <string>
|
||||
|
||||
// $Id$
|
||||
|
||||
namespace SAX
|
||||
{
|
||||
/** Abstract base class for the parser-specific XMLPScanToken data.
|
||||
*/
|
||||
class XMLPScanTokenParserImpl
|
||||
{
|
||||
public:
|
||||
virtual ~XMLPScanTokenParserImpl() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Current state of a progressive parsing operation.
|
||||
*
|
||||
* This is basically a container to hold any kind of XMLPScanTokenParserImpl a
|
||||
* parser can implement.
|
||||
*/
|
||||
class XMLPScanToken
|
||||
{
|
||||
public:
|
||||
void setParserData(std::auto_ptr<XMLPScanTokenParserImpl>& data)
|
||||
{
|
||||
data_ = data;
|
||||
}
|
||||
XMLPScanTokenParserImpl* parserImpl()
|
||||
{
|
||||
return data_.get();
|
||||
}
|
||||
private:
|
||||
std::auto_ptr<XMLPScanTokenParserImpl> data_;
|
||||
}; // XMLPScanToken
|
||||
|
||||
template<class string_type>
|
||||
class basic_ProgressiveParser : public basic_XMLReader<string_type>
|
||||
{
|
||||
public:
|
||||
typedef typename basic_XMLReader<string_type>::InputSourceT InputSourceT;
|
||||
|
||||
/** @name Progressive Parsing Methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Begin a progressive parse operation.
|
||||
*
|
||||
* This method is used to start a progressive parse on an XML file. To
|
||||
* continue parsing, subsequent calls must be to the parseNext method.
|
||||
*
|
||||
* It scans through the prolog and returns a token to be used on
|
||||
* subsequent scanNext() calls. If the return value is true, then the
|
||||
* token is legal and ready for further use. If it returns false, then
|
||||
* the scan of the prolog failed and the token is not going to work on
|
||||
* subsequent scanNext() calls.
|
||||
*
|
||||
* @param systemId The system identifier (URI).
|
||||
* @param toFill A token maintaining state information to maintain
|
||||
* internal consistency between invocation of parseNext
|
||||
* calls.
|
||||
*
|
||||
* @return true if sucessful in parsing the prolog. It indicates that the
|
||||
* user can go ahead with parsing the rest of the file.
|
||||
* @return false to indicate that the parser could not parse the prologue
|
||||
* (which means the token will not be valid).
|
||||
*
|
||||
* @see parseNext(XMLPScanToken&)
|
||||
* @see parseFirst(const InputSource&, XMLPScanToken&)
|
||||
*/
|
||||
virtual bool parseFirst(const std::string &systemId,
|
||||
XMLPScanToken &toFill) = 0;
|
||||
|
||||
/**
|
||||
* Begin a progressive parse operation.
|
||||
*
|
||||
* This method is used to start a progressive parse on an XML file. To
|
||||
* continue parsing, subsequent calls must be to the parseNext method.
|
||||
*
|
||||
* It scans through the prolog and returns a token to be used on
|
||||
* subsequent scanNext() calls. If the return value is true, then the
|
||||
* token is legal and ready for further use. If it returns false, then
|
||||
* the scan of the prolog failed and the token is not going to work on
|
||||
* subsequent scanNext() calls.
|
||||
*
|
||||
* @param input The input source for the top-level of the XML document.
|
||||
* @param toFill A token maintaining state information to maintain
|
||||
* internal consistency between invocation of parseNext
|
||||
* calls.
|
||||
*
|
||||
* @return true if sucessful in parsing the prolog. It indicates that the
|
||||
* user can go ahead with parsing the rest of the file.
|
||||
* @return false to indicate that the parser could not parse the prologue
|
||||
* (which means the token will not be valid).
|
||||
*
|
||||
* @see parseNext(XMLPScanToken&)
|
||||
* @see parseFirst(const string_type&, XMLPScanToken&)
|
||||
*/
|
||||
virtual bool parseFirst(InputSourceT& input,
|
||||
XMLPScanToken& toFill) = 0;
|
||||
|
||||
/**
|
||||
* Continue a progressive parse operation.
|
||||
*
|
||||
* This method is used to continue with progressive parsing of XML files
|
||||
* started by a call to parseFirst method.
|
||||
*
|
||||
* It parses the XML file and stops as soon as it comes across an XML
|
||||
* token (as defined in the XML specification). Relevant callbaqck
|
||||
* handlers are invoked as required by the SAX specification.
|
||||
*
|
||||
* @param token A token maintaining state information to maintain internal
|
||||
* consistency between invocation of parseNext calls. Clearly
|
||||
* token must come from a call to parseFirst() on <b>this</b>
|
||||
* ProgressiveParser.
|
||||
*
|
||||
* @return true if successful in parsing the next XML token. It indicates
|
||||
* the user can go ahead with parsing the rest of the file.
|
||||
* @return false to indicate that the parser could not find next token as
|
||||
* per the XML specification production rule.
|
||||
*
|
||||
* @see parseFirst(const string_type&, XMLPScanToken&)
|
||||
* @see parseFirst(const InputSource&, XMLPScanToken&)
|
||||
*/
|
||||
virtual bool parseNext(XMLPScanToken& token) = 0;
|
||||
|
||||
/**
|
||||
* Reset the parser after a progressive parse.
|
||||
*
|
||||
* If a progressive parse loop exits before the end of the document is
|
||||
* reached, the parser has no way of knowing this. So it will leave open
|
||||
* any files or sockets or memory buffers that were in use at the time
|
||||
* that the parse loop exited.
|
||||
*
|
||||
* The next parse operation will cause these open files and such to be
|
||||
* closed, but the next parse operation might occur at some unknown future
|
||||
* point. To avoid this problem, you should reset the parser if you exit
|
||||
* the loop early.
|
||||
*
|
||||
* If you exited because of an error, then this cleanup will be done for
|
||||
* you. Its only when you exit the file prematurely of your own accord,
|
||||
* because you've found what you wanted in the file most likely.
|
||||
*
|
||||
* @param token A token maintaing state information to maintain internal
|
||||
* consistency between invocation of parseNext calls. Clearly
|
||||
* token must come from a call to parseFirst() on <b>this</b>
|
||||
* ProgressiveParser.
|
||||
*/
|
||||
virtual void parseReset(XMLPScanToken& token) = 0;
|
||||
//@}
|
||||
}; // basic_ProgressiveParser
|
||||
|
||||
typedef basic_ProgressiveParser<std::string> ProgressiveParser;
|
||||
#ifndef ARABICA_NO_WCHAR_T
|
||||
typedef basic_ProgressiveParser<std::wstring> wProgressiveParser;
|
||||
#endif
|
||||
}; // namespace SAX
|
||||
|
||||
#endif /* PROGRESSIVE_PARSER_H */
|
||||
// end of file
|
||||
|
78
SAX/wrappers/XercesPropertyNames.h
Normal file
78
SAX/wrappers/XercesPropertyNames.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef ARABICA_XERCES_PROPERTYNAMES_H
|
||||
#define ARABICA_XERCES_PROPERTYNAMES_H
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <SAX/helpers/StringAdaptor.h>
|
||||
#include <SAX/helpers/PropertyNames.h>
|
||||
|
||||
namespace SAX
|
||||
{
|
||||
template<class string_type,
|
||||
class string_adaptor_type = default_string_adaptor<string_type> >
|
||||
struct XercesPropertyNames : public PropertyNames<string_type,
|
||||
string_adaptor_type>
|
||||
{
|
||||
/** \name Xerces properties.
|
||||
* @{ */
|
||||
|
||||
/** Used to set and get a fixed schema location for the
|
||||
* parser.
|
||||
*
|
||||
* The syntax is the same as for schemaLocation attributes in
|
||||
* instance documents: e.g, <code>"http://www.example.com
|
||||
* file_name.xsd"</code>. The user can specify more than one
|
||||
* XML Schema in the list.
|
||||
*
|
||||
* The XML Schema Recommendation explicitly states that the
|
||||
* inclusion of schemaLocation/ noNamespaceSchemaLocation
|
||||
* attributes in the instance document is only a hint; it does
|
||||
* not mandate that these attributes must be used to locate
|
||||
* schemas. Similar situation happens to <import> element in
|
||||
* schema documents. This property allows the user to specify
|
||||
* a list of schemas to use. If the targetNamespace of a
|
||||
* schema specified using this method matches the
|
||||
* targetNamespace of a schema occurring in the instance
|
||||
* document in schemaLocation attribute, or if the
|
||||
* targetNamespace matches the namespace attribute of <import>
|
||||
* element, the schema specified by the user using this
|
||||
* property will be used (i.e., the schemaLocation attribute
|
||||
* in the instance document or on the <import> element will be
|
||||
* effectively ignored).
|
||||
*/
|
||||
const string_type externalSchemaLocation;
|
||||
/** Used to set and get a fixed no-namespace schema location
|
||||
* for the parser.
|
||||
*
|
||||
* The syntax is the same as for the noNamespaceSchemaLocation
|
||||
* attribute that may occur in an instance document:
|
||||
* e.g.<code>"file_name.xsd"</code>.
|
||||
*
|
||||
* The XML Schema Recommendation explicitly states that the
|
||||
* inclusion of schemaLocation/ noNamespaceSchemaLocation
|
||||
* attributes in the instance document is only a hint; it does
|
||||
* not mandate that these attributes must be used to locate
|
||||
* schemas. This property allows the user to specify the no
|
||||
* target namespace XML Schema Location externally. If
|
||||
* specified, the instance document's
|
||||
* noNamespaceSchemaLocation attribute will be effectively
|
||||
* ignored.
|
||||
*/
|
||||
const string_type externalNoNamespaceSchemaLocation;
|
||||
|
||||
/** @} */
|
||||
|
||||
XercesPropertyNames() :
|
||||
externalSchemaLocation(string_adaptor_type().makeStringT(
|
||||
"http://apache.org/xml/properties/schema/external-schemaLocation")),
|
||||
externalNoNamespaceSchemaLocation(string_adaptor_type().makeStringT(
|
||||
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"))
|
||||
{
|
||||
} // XercesPropertyNames()
|
||||
}; // class XercesPropertyNames
|
||||
} // namespace SAX
|
||||
|
||||
#endif
|
||||
// end of file
|
||||
|
Loading…
Reference in a new issue