morten 01/08/13 03:33:37
Modified: java/src/org/apache/xalan/xsltc/compiler Parser.java
Log:
I added a flag to the compiler/Parser class that is set if the outermost
element
in the stylesheet contains a definition of the XSL namespace. The parser
already
has a global variable '_target' that is set if the stylesheet contains a
<?xml-stylesheet?> PI or not. The compiler will now flag an error if neither
flags are set after the whole XSL/XML input document has been parsed.
PR: bugzilla 1780
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.20 +19 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Parser.java 2001/08/02 16:01:51 1.19
+++ Parser.java 2001/08/13 10:33:36 1.20
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Parser.java,v 1.19 2001/08/02 16:01:51 morten Exp $
+ * @(#)$Id: Parser.java,v 1.20 2001/08/13 10:33:36 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -94,7 +94,7 @@
private XSLTC _xsltc; // Reference to the compiler object.
private XPathParser _xpathParser; // Reference to the XPath parser.
private Vector _errors; // Contains all compilation errors
- private Vector _warnings; // Contains all compilation errors
+ private Vector _warnings; // Contains all compilation errors
private Hashtable _instructionClasses; // Maps instructions to classes
private Hashtable _qNames;
@@ -108,6 +108,8 @@
private Output _output = null;
private Template _template; // Reference to the template being
parsed.
+ private boolean _rootNamespaceDef = false; // Used for validity check
+
private SyntaxTreeNode _root = null;
private String _target;
@@ -128,6 +130,9 @@
"Text data outside of top-level <xsl:stylesheet> element.";
private final static String MISSING_HREF_ERROR =
"Processing instruction <?xml-stylesheet ... ?> is missing href data.";
+ private final static String MISSING_XSLT_URI_ERROR =
+ "The input document is not a stylesheet "+
+ "(the XSL namespace is not declared in the root element).";
public Parser(XSLTC xsltc) {
_xsltc = xsltc;
@@ -452,7 +457,11 @@
// Assume that this is a pure XSL stylesheet if there is not
// <?xml-stylesheet ....?> processing instruction
- if (_target == null) return(root);
+ if (_target == null) {
+ if (!_rootNamespaceDef)
+ throw new CompilerException(MISSING_XSLT_URI_ERROR);
+ return(root);
+ }
// Find the xsl:stylesheet or xsl:transform with this reference
if (_target.charAt(0) == '#') {
@@ -1038,7 +1047,14 @@
throw new SAXException("Error while parsing stylesheet.");
}
+ // If this is the root element of the XML document we need to make sure
+ // that it contains a definition of the XSL namespace URI
if (_root == null) {
+ if ((_prefixMapping == null) ||
+ (_prefixMapping.containsValue(Constants.XSLT_URI) == false))
+ _rootNamespaceDef = false;
+ else
+ _rootNamespaceDef = true;
_root = element;
}
else {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]