working on detecting illegal xsl:stylesheet children - including is currently broken

This commit is contained in:
jez 2007-11-20 23:12:08 +00:00
parent 1f7dd78a3e
commit a9a5858300
3 changed files with 28 additions and 28 deletions

View file

@ -46,6 +46,7 @@ int main(int argc, const char* argv[])
document.normalize();
stylesheet->execute(document);
/*
std::cout << "==============" << std::endl;
Arabica::XSLT::DOMSink output;
@ -55,6 +56,7 @@ int main(int argc, const char* argv[])
Arabica::DOM::Node<std::string> node = output.node();
std::cout << node << std::endl;
*/
}
catch(const std::runtime_error& ex)
{

View file

@ -17,10 +17,13 @@ public:
context_(0),
compiler_(0),
pass_through_(0),
no_content_(false)
no_content_(false),
including_(false)
{
} // IncludeHandler
bool active() const { return including_; }
void context(CompilationContext& context, SAX::DefaultHandler<std::string>* compiler)
{
context_ = &context;
@ -163,7 +166,10 @@ private:
include_parser.setContentHandler(*this);
include_parser.setErrorHandler(errorHandler);
including_ = true;
include_parser.parse(source);
including_ = false;
context_->setBase(prev);
@ -177,6 +183,7 @@ private:
CompilationContext* context_;
unsigned int pass_through_;
bool no_content_;
bool including_;
std::vector<std::string> import_stack_;
std::vector<std::string> current_includes_;

View file

@ -24,8 +24,7 @@ class StylesheetHandler : public SAX::DefaultHandler<std::string>
public:
StylesheetHandler(CompilationContext& context) :
context_(context),
top_(true),
foreign_(0)
top_(true)
{
context_.root(*this);
includer_.context(context_, this);
@ -52,45 +51,38 @@ public:
return;
} // if(stylesheet_ == 0)
if(namespaceURI != StylesheetConstant::NamespaceURI())
if(namespaceURI == StylesheetConstant::NamespaceURI())
{
++foreign_;
return;
} //
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)
if((localName == "import") || (localName == "include"))
{
context_.push(0,
c->createHandler(context_),
namespaceURI,
qName,
localName,
atts);
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 ...
throw SAX::SAXException("xsl:stylesheet does not allow " + qName + " here.");
} // startElement
virtual void endElement(const std::string& namespaceURI,
const std::string& localName,
const std::string& qName)
{
if(namespaceURI != StylesheetConstant::NamespaceURI())
--foreign_;
} // endElement
virtual void characters(const std::string& ch)
{
if(foreign_)
return;
for(std::string::const_iterator s = ch.begin(), e = ch.end(); s != e; ++s)
if(!Arabica::XML::is_space(*s))
throw SAX::SAXException("stylesheet element can not contain character data :'" + ch +"'");
@ -115,7 +107,6 @@ private:
SAX::DefaultHandler<std::string>* child_;
IncludeHandler includer_;
bool top_;
unsigned int foreign_;
static const ChildElement allowedChildren[];
}; // class StylesheetHandler