You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2004/02/06 16:41:21 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/transformation CIncludeTransformer.java XIncludeTransformer.java
sylvain 2004/02/06 07:41:21
Modified: src/java/org/apache/cocoon/components/xpointer
UnsupportedPart.java
src/java/org/apache/cocoon/matching
AbstractRegexpMatcher.java
AbstractWildcardMatcher.java PreparableMatcher.java
src/java/org/apache/cocoon/transformation
CIncludeTransformer.java XIncludeTransformer.java
Log:
Better error reporting for missing or mistyped attributes and elements
Revision Changes Path
1.2 +1 -3 cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/UnsupportedPart.java
Index: UnsupportedPart.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/UnsupportedPart.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnsupportedPart.java 20 May 2003 11:57:13 -0000 1.1
+++ UnsupportedPart.java 6 Feb 2004 15:41:21 -0000 1.2
@@ -60,8 +60,6 @@
}
public boolean process(XPointerContext xpointerContext) throws SAXException {
- if (xpointerContext.getLogger().isDebugEnabled())
- xpointerContext.getLogger().debug("Scheme " + schemeName + " not supported by this XPointer implementation, as used in the fragment identifier " + xpointerContext.getXPointer());
- return false;
+ throw new SAXException("Scheme " + schemeName + " not supported by this XPointer implementation, as used in the fragment identifier " + xpointerContext.getXPointer());
}
}
1.2 +12 -7 cocoon-2.1/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java
Index: AbstractRegexpMatcher.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractRegexpMatcher.java 9 Mar 2003 00:09:33 -0000 1.1
+++ AbstractRegexpMatcher.java 6 Feb 2004 15:41:21 -0000 1.2
@@ -52,6 +52,7 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.Constants;
import org.apache.cocoon.sitemap.PatternException;
import org.apache.regexp.RE;
import org.apache.regexp.RECompiler;
@@ -76,13 +77,12 @@
* Compile the pattern in a <code>org.apache.regexp.REProgram</code>.
*/
public Object preparePattern(String pattern) throws PatternException {
- if (pattern == null)
- {
- throw new PatternException("null passed as a pattern", null);
+ // if pattern is null, return null to allow throwing a located exception in preparedMatch()
+ if (pattern == null) {
+ return null;
}
- if (pattern.length() == 0)
- {
+ if (pattern.length() == 0) {
pattern = "^$";
if (getLogger().isWarnEnabled()) {
getLogger().warn("The empty pattern string was rewritten to '^$'"
@@ -106,7 +106,12 @@
/**
* Match the prepared pattern against the value returned by {@link #getMatchString(Map, Parameters)}.
*/
- public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) {
+ public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException {
+
+ if(preparedPattern == null) {
+ throw new PatternException("A pattern is needed at " +
+ parameters.getParameter(Constants.SITEMAP_PARAMETERS_LOCATION, "unknown location"));
+ }
RE re = new RE((REProgram)preparedPattern);
String match = getMatchString(objectModel, parameters);
1.2 +11 -3 cocoon-2.1/src/java/org/apache/cocoon/matching/AbstractWildcardMatcher.java
Index: AbstractWildcardMatcher.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/matching/AbstractWildcardMatcher.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractWildcardMatcher.java 9 Mar 2003 00:09:33 -0000 1.1
+++ AbstractWildcardMatcher.java 6 Feb 2004 15:41:21 -0000 1.2
@@ -52,7 +52,9 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.Constants;
import org.apache.cocoon.matching.helpers.WildcardHelper;
+import org.apache.cocoon.sitemap.PatternException;
import java.util.HashMap;
import java.util.Map;
@@ -70,13 +72,19 @@
* Compile the pattern in an <code>int[]</code>.
*/
public Object preparePattern(String pattern) {
- return WildcardHelper.compilePattern(pattern);
+ // if pattern is null, return null to allow throwing a located exception in preparedMatch()
+ return pattern == null ? null : WildcardHelper.compilePattern(pattern);
}
/**
* Match the prepared pattern against the result of {@link #getMatchString(Map, Parameters)}.
*/
- public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) {
+ public Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException {
+
+ if(preparedPattern == null) {
+ throw new PatternException("A pattern is needed at " +
+ parameters.getParameter(Constants.SITEMAP_PARAMETERS_LOCATION, "unknown location"));
+ }
String match = getMatchString(objectModel, parameters);
1.3 +2 -2 cocoon-2.1/src/java/org/apache/cocoon/matching/PreparableMatcher.java
Index: PreparableMatcher.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/matching/PreparableMatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PreparableMatcher.java 23 Dec 2003 15:28:32 -0000 1.2
+++ PreparableMatcher.java 6 Feb 2004 15:41:21 -0000 1.3
@@ -90,7 +90,7 @@
* @return a <code>Map</code> object with replacements for wildcards/regular-expressions
* contained in the pattern. If the return value is null there was no match.
*/
- Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters);
+ Map preparedMatch(Object preparedPattern, Map objectModel, Parameters parameters) throws PatternException;
}
1.8 +5 -1 cocoon-2.1/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
Index: CIncludeTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CIncludeTransformer.java 21 Oct 2003 12:39:16 -0000 1.7
+++ CIncludeTransformer.java 6 Feb 2004 15:41:21 -0000 1.8
@@ -484,6 +484,10 @@
boolean cache)
throws SAXException, IOException {
+ if (src == null) {
+ throw new SAXException("Missing 'src' attribute on cinclude:include element");
+ }
+
if (element == null) element="";
if (select == null) select="";
if (ns == null) ns="";
1.11 +51 -33 cocoon-2.1/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java
Index: XIncludeTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XIncludeTransformer.java 24 Sep 2003 21:41:12 -0000 1.10
+++ XIncludeTransformer.java 6 Feb 2004 15:41:21 -0000 1.11
@@ -179,40 +179,50 @@
}
public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException {
- if (xIncludeLevel == 1 && useFallback && uri.equals(XINCLUDE_NAMESPACE_URI)
- && name.equals(XINCLUDE_FALLBACK_ELEMENT)) {
- fallbackLevel++;
-
- // don't need these anymore
- useFallback = false;
- fallBackException = null;
-
- return;
- } else if (xIncludeLevel > 0 && fallbackLevel < 1) {
- xIncludeLevel++;
- return;
- }
-
- xmlBaseSupport.startElement(uri, name, raw, attr);
- if (XINCLUDE_INCLUDE_ELEMENT.equals(name) && XINCLUDE_NAMESPACE_URI.equals(uri)) {
- String href = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_HREF_ATTRIBUTE);
- String parse = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_PARSE_ATTRIBUTE);
-
- if (null == parse) parse="xml";
- xIncludeLevel++;
-
- try {
- processXIncludeElement(href, parse);
- } catch (ProcessingException e) {
- getLogger().debug("Rethrowing exception", e);
- throw new SAXException(e);
- } catch (IOException e) {
- getLogger().debug("Rethrowing exception", e);
- throw new SAXException(e);
+ if (uri.equals(XINCLUDE_NAMESPACE_URI)) {
+ if (xIncludeLevel == 1 && useFallback && name.equals(XINCLUDE_FALLBACK_ELEMENT)) {
+ fallbackLevel++;
+
+ // don't need these anymore
+ useFallback = false;
+ fallBackException = null;
+
+ return;
+ } else if (xIncludeLevel > 0 && fallbackLevel < 1) {
+ xIncludeLevel++;
+ return;
}
- return;
+
+ xmlBaseSupport.startElement(uri, name, raw, attr);
+ if (XINCLUDE_INCLUDE_ELEMENT.equals(name)) {
+ String href = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_HREF_ATTRIBUTE);
+ if (href == null) {
+ throw new SAXException(raw + " must have a 'href' attribute at " + getLocation());
+ }
+
+ String parse = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_PARSE_ATTRIBUTE);
+
+ if (null == parse) parse="xml";
+ xIncludeLevel++;
+
+ try {
+ processXIncludeElement(href, parse);
+ } catch (ProcessingException e) {
+ getLogger().debug("Rethrowing exception", e);
+ throw new SAXException(e);
+ } catch (IOException e) {
+ getLogger().debug("Rethrowing exception", e);
+ throw new SAXException(e);
+ }
+ return;
+ }
+
+ throw new SAXException("Unknown XInclude element " + raw + " at " + getLocation());
+
+ } else {
+ xmlBaseSupport.startElement(uri, name, raw, attr);
+ super.startElement(uri,name,raw,attr);
}
- super.startElement(uri,name,raw,attr);
}
public void endElement(String uri, String name, String raw) throws SAXException {
@@ -461,6 +471,14 @@
parent = parent.getParent();
}
return false;
+ }
+
+ private String getLocation() {
+ if (this.locator == null) {
+ return "unknown location";
+ } else {
+ return this.locator.getSystemId() + ":" + this.locator.getColumnNumber() + ":" + this.locator.getLineNumber();
+ }
}
}
}