sylvain     2004/02/13 08:03:15

  Modified:    src/java/org/apache/cocoon/components/pipeline
                        AbstractProcessingPipeline.java
               src/java/org/apache/cocoon/components/source/impl
                        SitemapSource.java
               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:
  Porting some changes done in 2.1
  
  Revision  Changes    Path
  1.31      +32 -14    
cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
  
  Index: AbstractProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- AbstractProcessingPipeline.java   11 Feb 2004 15:59:02 -0000      1.30
  +++ AbstractProcessingPipeline.java   13 Feb 2004 16:03:14 -0000      1.31
  @@ -67,6 +67,7 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.cocoon.ConnectionResetException;
  +import org.apache.cocoon.Constants;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.environment.Environment;
  @@ -221,15 +222,17 @@
       public void setGenerator (String role, String source, Parameters param, 
Parameters hintParam)
       throws ProcessingException {
           if (this.generator != null) {
  -            throw new ProcessingException ("Generator already set. You can 
only select one Generator (" + role + ")");
  +            throw new ProcessingException ("Generator already set. Cannot 
set generator '" + role +
  +                "' at " + getLocation(param));
           }
           if (this.reader != null) {
  -            throw new ProcessingException ("Reader already set. You cannot 
use a reader and a generator for one pipeline.");
  +            throw new ProcessingException ("Reader already set. Cannot set 
generator '" + role +
  +                "' at " + getLocation(param));
           }
           try {
               this.generator = (Generator) newManager.lookup(role);
           } catch (ServiceException ce) {
  -            throw new ProcessingException("Lookup of generator for role 
'"+role+"' failed.", ce);
  +            throw new ProcessingException("Lookup of generator selector 
failed at " +getLocation(param), ce);
           }
           this.generatorSource = source;
           this.generatorParam = param;
  @@ -250,15 +253,18 @@
       public void addTransformer (String role, String source, Parameters 
param, Parameters hintParam)
       throws ProcessingException {
           if (this.reader != null) {
  -            throw new ProcessingException ("Reader already set. You cannot 
use a transformer with a reader.");
  +            // Should normally never happen as setting a reader starts 
pipeline processing
  +            throw new ProcessingException ("Reader already set. Cannot add 
transformer '" + role +
  +                "' at " + getLocation(param));
           }
           if (this.generator == null) {
  -            throw new ProcessingException ("You must set a generator first 
before you can use a transformer.");
  +            throw new ProcessingException ("Must set a generator before 
adding transformer '" + role +
  +                "' at " + getLocation(param));   
           }
           try {
               this.transformers.add(newManager.lookup(role));
           } catch (ServiceException ce) {
  -            throw new ProcessingException("Lookup of transformer for role 
'"+role+"' failed.", ce);
  +            throw new ProcessingException("Lookup of transformer '"+role+"' 
failed at " + getLocation(param), ce);
           }
           this.transformerSources.add(source);
           this.transformerParams.add(param);
  @@ -271,19 +277,24 @@
       public void setSerializer (String role, String source, Parameters param, 
Parameters hintParam, String mimeType)
       throws ProcessingException {
           if (this.serializer != null) {
  -            throw new ProcessingException ("Serializer already set. You can 
only select one Serializer (" + role + ")");
  +            // Should normally not happen as adding a serializer starts 
pipeline processing
  +            throw new ProcessingException ("Serializer already set. Cannot 
set serializer '" + role +
  +                "' at " + getLocation(param));
           }
           if (this.reader != null) {
  -            throw new ProcessingException ("Reader already set. You cannot 
use a serializer with a reader.");
  +            // Should normally never happen as setting a reader starts 
pipeline processing
  +            throw new ProcessingException ("Reader already set. Cannot set 
serializer '" + role +
  +                "' at " + getLocation(param));
           }
           if (this.generator == null) {
  -            throw new ProcessingException ("You must set a generator first 
before you can use a serializer.");
  +            throw new ProcessingException ("Must set a generator before 
setting serializer '" + role +
  +                "' at " + getLocation(param));
           }
   
           try {
               this.serializer = (Serializer) newManager.lookup(role);
           } catch (ServiceException ce) {
  -            throw new ProcessingException("Lookup of serializer for role 
'"+role+"' failed.", ce);
  +            throw new ProcessingException("Lookup of serializer '" + role + 
"' failed at " + getLocation(param), ce);
           }
           this.serializerSource = source;
           this.serializerParam = param;
  @@ -298,16 +309,20 @@
       public void setReader (String role, String source, Parameters param, 
String mimeType)
       throws ProcessingException {
           if (this.reader != null) {
  -            throw new ProcessingException ("Reader already set. You can only 
select one Reader (" + role + ")");
  +            // Should normally never happen as setting a reader starts 
pipeline processing
  +            throw new ProcessingException ("Reader already set. Cannot set 
reader '" + role +
  +                "' at " + getLocation(param));
           }
           if (this.generator != null) {
  -            throw new ProcessingException ("Generator already set. You 
cannot use a reader and a generator for one pipeline.");
  +            // Should normally never happen as setting a reader starts 
pipeline processing
  +            throw new ProcessingException ("Generator already set. Cannot 
use reader '" + role +
  +                "' at " + getLocation(param));
           }
   
           try {
               this.reader = (Reader) newManager.lookup(role);
           } catch (ServiceException ce) {
  -            throw new ProcessingException("Lookup of reader for role 
'"+role+"' failed.", ce);
  +            throw new ProcessingException("Lookup of reader '"+role+"' 
failed at " + getLocation(param), ce);
           }
           this.readerSource = source;
           this.readerParam = param;
  @@ -745,4 +760,7 @@
           return null;
       }
   
  +    protected String getLocation(Parameters param) {
  +        return param.getParameter(Constants.SITEMAP_PARAMETERS_LOCATION, 
"[unknown location]");
  +    }
   }
  
  
  
  1.27      +2 -2      
cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- SitemapSource.java        6 Feb 2004 11:42:46 -0000       1.26
  +++ SitemapSource.java        13 Feb 2004 16:03:14 -0000      1.27
  @@ -216,7 +216,7 @@
           }
           // VG: Why exception is not thrown in constructor?
           if (this.exception != null) {
  -            throw new IOException("SAXException: " + this.exception);
  +            throw new SourceException("Cannot get input stream for " + 
getURI(), this.exception);
           }
   
           if (this.redirectSource != null) {
  
  
  
  1.2       +1 -3      
cocoon-2.2/src/java/org/apache/cocoon/components/xpointer/UnsupportedPart.java
  
  Index: UnsupportedPart.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/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      13 Feb 2004 16:03:14 -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.4       +12 -7     
cocoon-2.2/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java
  
  Index: AbstractRegexpMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/matching/AbstractRegexpMatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractRegexpMatcher.java        5 Jan 2004 08:17:30 -0000       1.3
  +++ AbstractRegexpMatcher.java        13 Feb 2004 16:03:14 -0000      1.4
  @@ -54,6 +54,7 @@
   import java.util.Map;
   
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.cocoon.Constants;
   import org.apache.cocoon.sitemap.PatternException;
   import org.apache.regexp.RE;
   import org.apache.regexp.RECompiler;
  @@ -75,13 +76,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 
'^$'"
  @@ -105,7 +105,12 @@
       /**
        * Match the prepared pattern against the value returned by [EMAIL 
PROTECTED] #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.4       +11 -3     
cocoon-2.2/src/java/org/apache/cocoon/matching/AbstractWildcardMatcher.java
  
  Index: AbstractWildcardMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/matching/AbstractWildcardMatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractWildcardMatcher.java      5 Jan 2004 08:17:30 -0000       1.3
  +++ AbstractWildcardMatcher.java      13 Feb 2004 16:03:14 -0000      1.4
  @@ -54,7 +54,9 @@
   import java.util.Map;
   
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.cocoon.Constants;
   import org.apache.cocoon.matching.helpers.WildcardHelper;
  +import org.apache.cocoon.sitemap.PatternException;
   
   /**
    * Base class for wildcard matchers
  @@ -69,13 +71,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 [EMAIL PROTECTED] 
#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.2/src/java/org/apache/cocoon/matching/PreparableMatcher.java
  
  Index: PreparableMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/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    5 Jan 2004 08:17:30 -0000       1.2
  +++ PreparableMatcher.java    13 Feb 2004 16:03:14 -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.12      +5 -1      
cocoon-2.2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
  
  Index: CIncludeTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CIncludeTransformer.java  6 Dec 2003 21:22:07 -0000       1.11
  +++ CIncludeTransformer.java  13 Feb 2004 16:03:14 -0000      1.12
  @@ -493,6 +493,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.14      +51 -33    
cocoon-2.2/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java
  
  Index: XIncludeTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XIncludeTransformer.java  6 Feb 2004 22:24:40 -0000       1.13
  +++ XIncludeTransformer.java  13 Feb 2004 16:03:15 -0000      1.14
  @@ -186,40 +186,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 {
  @@ -468,6 +478,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();
  +            }
           }
       }
   }
  
  
  

Reply via email to