mmidy 01/03/13 11:55:00
Modified: java/src/org/apache/xalan/processor ProcessorLRE.java
java/src/org/apache/xalan/res XSLTErrorResources.java
Log:
Better error message for missing or incorrect XSLT namespace declaration in a
stylesheet
Revision Changes Path
1.17 +39 -0
xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java
Index: ProcessorLRE.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ProcessorLRE.java 2001/01/07 06:24:39 1.16
+++ ProcessorLRE.java 2001/03/13 19:54:55 1.17
@@ -62,6 +62,9 @@
import org.apache.xalan.templates.ElemExtensionCall;
import org.apache.xalan.templates.ElemTemplate;
import org.apache.xalan.templates.Constants;
+import org.apache.xalan.templates.XMLNSDecl;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xpath.XPath;
import org.apache.xalan.templates.StylesheetRoot;
@@ -73,6 +76,8 @@
import javax.xml.transform.TransformerConfigurationException;
import org.apache.xml.utils.SAXSourceLocator;
+import java.util.Vector;
+
/**
* <meta name="usage" content="internal"/>
* Processes an XSLT literal-result-element, or something that looks
@@ -181,8 +186,28 @@
// Set properties from the attributes, but don't throw
// an error if there is an attribute defined that is not
// allowed on a stylesheet.
+ try{
stylesheetProcessor.setPropertiesFromAttributes(handler,
"stylesheet",
stylesheetAttrs,
stylesheet);
+ }
+ catch (Exception e)
+ {
+ // This is pretty ugly, but it will
have to do for now.
+ // This is just trying to append some
text specifying that
+ // this error came from a missing or
invalid XSLT namespace
+ // declaration.
+ // If someone comes up with a better
solution, please feel
+ // free to contribute it. -mm
+ String msg = e.getMessage();
+ if (stylesheet.getDeclaredPrefixes() ==
null ||
+ !declaredXSLNS(stylesheet))
+ {
+ msg = msg +"; " +
XSLMessages.createWarning(XSLTErrorResources.WG_OLD_XSLT_NS, null);
+
+ }
+ //else
+ throw new
org.xml.sax.SAXException(msg, e);
+ }
handler.pushElemTemplateElement(stylesheet);
ElemTemplate template = new ElemTemplate();
@@ -346,4 +371,18 @@
super.endElement(handler, uri, localName, rawName);
}
+
+ private boolean declaredXSLNS(Stylesheet stylesheet)
+ {
+ Vector declaredPrefixes = stylesheet.getDeclaredPrefixes();
+ int n = declaredPrefixes.size();
+
+ for (int i = 0; i < n; i++)
+ {
+ XMLNSDecl decl = (XMLNSDecl)
declaredPrefixes.elementAt(i);
+ if(decl.getURI().equals(Constants.S_XSLNAMESPACEURL))
+ return true;
+ }
+ return false;
+ }
}
1.17 +1 -1
xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java
Index: XSLTErrorResources.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XSLTErrorResources.java 2001/03/13 17:28:34 1.16
+++ XSLTErrorResources.java 2001/03/13 19:54:58 1.17
@@ -1254,7 +1254,7 @@
static
{
- contents[WG_OLD_XSLT_NS + MAX_CODE][1] = "Old XSLT Namespace: {0}";
+ contents[WG_OLD_XSLT_NS + MAX_CODE][1] = "Missing or incorrect XSLT
Namespace. ";
}
/** WG_ONE_DEFAULT_XSLDECIMALFORMAT_ALLOWED */
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]