neatening

This commit is contained in:
jez 2009-04-24 15:54:13 +01:00
parent 386513a84a
commit 6081659b71

View file

@ -49,54 +49,16 @@ public:
if(top_) if(top_)
{ {
if(namespaceURI != StylesheetConstant::NamespaceURI()) startStylesheet(namespaceURI, localName, qName, atts);
throw SAX::SAXException("The source file does not look like a stylesheet.");
if(localName != "stylesheet" && localName != "transform")
throw SAX::SAXException("Top-level element must be 'stylesheet' or 'transform'.");
static const ValueRule rules[] = { { "version", true, 0 },
{ "extension-element-prefixes", false, 0 },
{ "exclude-result-prefixes", false, 0 },
{ "id", false, 0 },
{ 0, false, 0 } };
std::map<std::string, std::string> attributes = gatherAttributes(qName, atts, rules);
if(attributes["version"] != StylesheetConstant::Version())
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
if(!attributes["extension-element-prefixes"].empty())
throw SAX::SAXException("Haven't implemented extension-element-prefixes yet");
top_ = false;
return; return;
} // if(top_) } // if(top_)
if(namespaceURI == StylesheetConstant::NamespaceURI()) if(namespaceURI == StylesheetConstant::NamespaceURI())
{ startXSLTElement(namespaceURI, localName, qName, atts);
if((localName == "import") || (localName == "include"))
{
include_stylesheet(namespaceURI, localName, qName, atts);
return;
} // if ...
for(const ChildElement* c = allowedChildren; c->name != 0; ++c)
if(c->name == localName)
{
context_.push(0,
c->createHandler(context_),
namespaceURI,
qName,
localName,
atts);
return;
} // if ...
} // if ...
else if(!namespaceURI.empty()) else if(!namespaceURI.empty())
{
++foreign_; ++foreign_;
return; else
} // if(!namespaceURI.empty()) oops(qName);
throw SAX::SAXException("xsl:stylesheet does not allow " + qName + " here.");
} // startElement } // startElement
virtual void endElement(const std::string& namespaceURI, virtual void endElement(const std::string& namespaceURI,
@ -124,6 +86,56 @@ public:
} // endDocument } // endDocument
private: private:
void startStylesheet(const std::string& namespaceURI,
const std::string& localName,
const std::string& qName,
const SAX::Attributes<std::string>& atts)
{
if(namespaceURI != StylesheetConstant::NamespaceURI())
throw SAX::SAXException("The source file does not look like a stylesheet.");
if(localName != "stylesheet" && localName != "transform")
throw SAX::SAXException("Top-level element must be 'stylesheet' or 'transform'.");
static const ValueRule rules[] = { { "version", true, 0 },
{ "extension-element-prefixes", false, 0 },
{ "exclude-result-prefixes", false, 0 },
{ "id", false, 0 },
{ 0, false, 0 } };
std::map<std::string, std::string> attributes = gatherAttributes(qName, atts, rules);
if(attributes["version"] != StylesheetConstant::Version())
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
if(!attributes["extension-element-prefixes"].empty())
throw SAX::SAXException("Haven't implemented extension-element-prefixes yet");
top_ = false;
} // startStylesheet
void startXSLTElement(const std::string& namespaceURI,
const std::string& localName,
const std::string& qName,
const SAX::Attributes<std::string>& atts)
{
if((localName == "import") || (localName == "include"))
{
include_stylesheet(namespaceURI, localName, qName, atts);
return;
} // if ...
for(const ChildElement* c = allowedChildren; c->name != 0; ++c)
if(c->name == localName)
{
context_.push(0,
c->createHandler(context_),
namespaceURI,
qName,
localName,
atts);
return;
} // if ...
oops(qName);
} // startXSLTElement
void include_stylesheet(const std::string& namespaceURI, void include_stylesheet(const std::string& namespaceURI,
const std::string& localName, const std::string& localName,
const std::string& qName, const std::string& qName,
@ -132,6 +144,11 @@ private:
includer_.start_include(namespaceURI, localName, qName, atts); includer_.start_include(namespaceURI, localName, qName, atts);
} // include_stylesheet } // include_stylesheet
void oops(const std::string& qName) const
{
throw SAX::SAXException("xsl:stylesheet does not allow " + qName + " here.");
} // oops
CompilationContext& context_; CompilationContext& context_;
SAX::DefaultHandler<std::string>* child_; SAX::DefaultHandler<std::string>* child_;
IncludeHandler includer_; IncludeHandler includer_;