cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java sitemap.xsl
Date Tue, 24 Jul 2001 03:00:42 GMT
vgritsenko    01/07/23 20:00:42

  Modified:    src/org/apache/cocoon/components/language/markup/sitemap/java
                        sitemap.xsl
  Log:
  - fix subsitemap invokation so <map:handle-error> works
  - allow optional <map:generator> element in <map:handle-error>
  - add @type attribute to <map:handle-erorr> with values "500" (default) and "404"
  - optimize error logging (reduce log file size)
  
  Revision  Changes    Path
  1.31      +70 -46    xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl
  
  Index: sitemap.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- sitemap.xsl	2001/07/20 07:26:53	1.30
  +++ sitemap.xsl	2001/07/24 03:00:42	1.31
  @@ -124,7 +124,7 @@
        *
        * @author &lt;a href="mailto:giacomo@apache.org"&gt;Giacomo Pati&lt;/a&gt;
        * @author &lt;a href="mailto:bloritsch@apache.org"&gt;Berin Loritsch&lt;/a&gt;
  -     * @version CVS $Id: sitemap.xsl,v 1.30 2001/07/20 07:26:53 cziegeler Exp $
  +     * @version CVS $Id: sitemap.xsl,v 1.31 2001/07/24 03:00:42 vgritsenko Exp $
        */
       public class <xsl:value-of select="@file-name"/> extends AbstractSitemap {
         static final String LOCATION = "<xsl:value-of select="translate(@file-path, '/',
'.')"/>.<xsl:value-of select="@file-name"/>";
  @@ -414,13 +414,17 @@
           StreamPipeline pipeline = null;
           boolean result = false;
           try {
  -          eventPipeline = (EventPipeline)this.manager.lookup(EventPipeline.ROLE);
  -          pipeline = (StreamPipeline)this.manager.lookup(StreamPipeline.ROLE);
  -          pipeline.setEventPipeline(eventPipeline);
  +          try {
  +            eventPipeline = (EventPipeline)this.manager.lookup(EventPipeline.ROLE);
  +            pipeline = (StreamPipeline)this.manager.lookup(StreamPipeline.ROLE);
  +            pipeline.setEventPipeline(eventPipeline);
  +          } catch (Exception e) {
  +            getLogger().error("processing of resource failed", e);
  +            throw e;
  +          }
  +
             result = process (environment, pipeline, eventPipeline, false);
  -        } catch (Exception e) {
  -          getLogger().error("processing of resource failed", e);
  -          throw e;
  +
           } finally {
             if(eventPipeline != null)
               this.manager.release(eventPipeline);
  @@ -472,26 +476,45 @@
                         environment, pipeline, eventPipeline, internalRequest,listOfMaps))
                   return true;
               </xsl:for-each>
  +
  +            <xsl:if test="position() = last()">
  +              throw new ResourceNotFoundException("No pipeline matched request");
  +            </xsl:if>
             } catch (ConnectionResetException cre) {
  -            getLogger().debug("Connection reset by peer");
  +             // Will be reported by CocoonServlet, rethrowing
               throw cre;
  -          } catch (ResourceNotFoundException rse) {
  -            getLogger().warn("404 Resource Not Found", rse);
  -            throw rse;
  +          } catch (ResourceNotFoundException e) {
  +            <xsl:choose>
  +              <xsl:when test="(./map:handle-errors[@type='404'])">
  +                getLogger().warn("404, try to process the error page", e);
  +                try {
  +                  return error_process_<xsl:value-of select="$pipeline-position"/>_404
(environment,
  +                          environment.getObjectModel(), e, internalRequest);
  +                } catch (Exception ex) {
  +                  getLogger().warn("Sitemap Error Process", ex);
  +                  if (true) return false;
  +                }
  +              </xsl:when>
  +              <xsl:otherwise>
  +                // Will be reported by CocoonServlet, rethrowing
  +                if (true) throw e;
  +              </xsl:otherwise>
  +            </xsl:choose>
             } catch (Exception e) {
               <xsl:choose>
  -              <xsl:when test="(./map:handle-errors)">
  +              <xsl:when test="(./map:handle-errors[not(@type) or (@type='500')])">
                   getLogger().warn("Error, try to process the error page", e);
                   try {
  -                  return error_process_<xsl:value-of select="$pipeline-position"/>
(environment,
  +                  return error_process_<xsl:value-of select="$pipeline-position"/>_500
(environment,
                             environment.getObjectModel(), e, internalRequest);
                   } catch (Exception ex) {
                     getLogger().warn("Sitemap Error Process", ex);
  +                  if (true) return false;
                   }
                 </xsl:when>
                 <xsl:otherwise>
                   getLogger().error("Sitemap", e);
  -                throw e;
  +                if (true) throw e;
                 </xsl:otherwise>
               </xsl:choose>
             }
  @@ -508,8 +531,20 @@
           <xsl:call-template name="line-number"/>
           <xsl:variable name="pipeline-position" select="position()"/>
           <xsl:apply-templates select="./*"/>
  -        <xsl:if test="(./map:handle-errors)">
  -          private boolean error_process_<xsl:value-of select="$pipeline-position"/>
(Environment environment, Map objectModel, Exception e, boolean internalRequest)
  +
  +        <xsl:for-each select="./map:handle-errors">
  +          <!-- Default error handler's type is 500 -->
  +          <xsl:variable name="type">
  +            <xsl:choose>
  +              <xsl:when test="@type">
  +                <xsl:text>_</xsl:text><xsl:value-of select="@type"/>
  +              </xsl:when>
  +              <xsl:otherwise>
  +                <xsl:text>_500</xsl:text>
  +              </xsl:otherwise>
  +            </xsl:choose>
  +          </xsl:variable>
  +          private boolean error_process_<xsl:value-of select="concat($pipeline-position,$type)"/>
(Environment environment, Map objectModel, Exception e, boolean internalRequest)
             throws Exception {
               EventPipeline eventPipeline = null;
               StreamPipeline pipeline = null;
  @@ -521,8 +556,10 @@
                 List listOfMaps = (List)(new ArrayList());
                 Map map;
                 Parameters param;
  -              eventPipeline.setGenerator ("!error-notifier!", e.getMessage(), emptyParam,
e);
  -              <xsl:apply-templates select="./map:handle-errors/*"/>
  +              <xsl:if test="not(./map:generate)">
  +                eventPipeline.setGenerator ("!error-notifier!", e.getMessage(), emptyParam,
e);
  +              </xsl:if>
  +              <xsl:apply-templates select="./*"/>
               } catch (Exception ex) {
                 getLogger().error("error notifier barfs", ex);
                 throw e;
  @@ -534,7 +571,7 @@
               }
               return false;
             }
  -        </xsl:if>
  +        </xsl:for-each>
         </xsl:for-each>
       }
     </xsl:template> <!-- match="map:sitemap" -->
  @@ -1075,16 +1112,7 @@
   
       <xsl:if test="not(ancestor::map:pipeline[@internal-only='yes' or @internal-only='true'])">
         if (!internalRequest) {
  -        boolean result = false;
  -
  -        try {
  -            result = pipeline.process(environment);
  -        } catch (Exception pipelineException<xsl:value-of select="generate-id(.)"/>)
{
  -            getLogger().debug("Error processing pipeline", pipelineException<xsl:value-of
select="generate-id(.)"/>);
  -            throw pipelineException<xsl:value-of select="generate-id(.)"/>;
  -        }
  -
  -        return result;
  +        return pipeline.process(environment);
         }
       </xsl:if>
       <!-- the if(true) prevents "unreachable statement" errors during compile -->
  @@ -1102,20 +1130,11 @@
   
       <xsl:if test="not(ancestor::map:pipeline[@internal-only='yes' or @internal-only='true'])">
         if (!internalRequest) {
  -        boolean result = false;
  -
  -        try {
  -            result = pipeline.process(environment);
  -        } catch (Exception RpipelineException<xsl:value-of select="generate-id(.)"/>)
{
  -            getLogger().debug("Error processing pipeline", RpipelineException<xsl:value-of
select="generate-id(.)"/>);
  -            throw RpipelineException<xsl:value-of select="generate-id(.)"/>;
  -        }
  -
  -        return result;
  +        return pipeline.process(environment);
         }
       </xsl:if>
       <!-- the if(true) prevents "unreachable statement" errors during compile -->
  -    if(true)return true;
  +    if (true) return true;
     </xsl:template> <!-- match="map:read" -->
   
     <!-- generate the code to invoke a sub sitemap  -->
  @@ -1154,11 +1173,16 @@
         </xsl:choose>
       </xsl:variable>
   
  -    <!-- generate the code to invoke the sitemapManager which handles delegation of
control to sub sitemaps -->
  -    if (internalRequest)
  -      return sitemapManager.invoke (this.manager, environment, substitute(listOfMaps,"<xsl:value-of
select="@uri-prefix"/>"), substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
<xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>,
pipeline, eventPipeline);
  -    else
  -      if (true) return sitemapManager.invoke (this.manager, environment, substitute(listOfMaps,"<xsl:value-of
select="@uri-prefix"/>"), substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
<xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>);
  +    environment.pushURI(null, XSPRequestHelper.getSitemapURI(objectModel));
  +    try{
  +      <!-- generate the code to invoke the sitemapManager which handles delegation of
control to sub sitemaps -->
  +      if (internalRequest)
  +        return sitemapManager.invoke (this.manager, environment, substitute(listOfMaps,"<xsl:value-of
select="@uri-prefix"/>"), substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
<xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>,
pipeline, eventPipeline);
  +      else
  +        if (true) return sitemapManager.invoke (this.manager, environment, substitute(listOfMaps,"<xsl:value-of
select="@uri-prefix"/>"), substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
<xsl:value-of select="$check-reload"/>, <xsl:value-of select="$reload-method"/>);
  +    }finally{
  +      environment.popURI();
  +    }
     </xsl:template> <!-- match="map:mount" -->
   
     <!-- generate the code to redirect a request -->
  @@ -1180,7 +1204,7 @@
            Class[] argTypes = new Class[] {StreamPipeline.class, EventPipeline.class, List.class,
Environment.class, String.class, Boolean.TYPE};
            Object[] argValues = new Object[] {pipeline, eventPipeline, listOfMaps, environment,
cocoon_view, new Boolean(internalRequest)};
            String methodName = "resource_" + substitute(listOfMaps, "<xsl:value-of select="translate(@resource,
'- ', '__')"/>");
  -         if(true)return invokeMethod(methodName, argTypes, argValues);
  +         if (true) return invokeMethod(methodName, argTypes, argValues);
         </xsl:when>
   
         <!-- redirect to a external resource definition with optional session mode attribute.
Let the environment do the redirect -->
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message