Hi guys,

 

Just for the newbies among us who have difficulties grasping why their
sitemap is not doing what they expect... like me a couple of days ago
:-)

 

Here is a way to put a little debug information inside your sitemap:

 

Below you can find the code for the DebugPipelineAction.java

-----------------------------------------------------*******************
**********************--------------------------------------------------
---*****************************************

 

package com.ciber.actions;

 

import java.util.HashMap;

import java.util.Map;

 

import org.apache.avalon.framework.parameters.Parameters;

import org.apache.cocoon.acting.AbstractAction;

import org.apache.cocoon.environment.Redirector;

import org.apache.cocoon.environment.SourceResolver;

 

 

/**

 * @author robby.pelssers

 * This action can be used while developing the sitemap. It will log
which pipelines are 

 * executed, the pattern which is matched and the actual pattern-value 

 */

public class DebugPipelineAction extends AbstractAction {

 

    @Override

    public Map act(Redirector redirector, SourceResolver resolver, Map
objectModel, String source,

            Parameters params) throws Exception {

 

        Map sitemapParams = new HashMap();

        String pipelineId = params.getParameter("id");

        String pattern = params.getParameter("pattern");

        String patternValue = params.getParameter("pattern-value");

        System.out.println("----------------- Start Pipeline Debugging
--------------------------");

        System.out.println("Pipeline executed: " + pipelineId);

        System.out.println("Matched pattern: " + pattern);

        System.out.println("Pattern value: " + patternValue);        

        System.out.println("----------------- End Pipeline Debugging
--------------------------");        

        return sitemapParams;

    }

}

-----------------------------------------------------*******************
**********************--------------------------------------------------
---*****************************************

 

Sitemap.xmap:

 

You will need to add following snippet to your sitemap

 

<map:components>

  <map:actions>

     ...

    <map:action name="debug"
src="com.ciber.actions.DebugPipelineAction"/>

    ...  

  </map:actions>  

</map:components>

 

 

Now suppose you have a pipeline like the one below.  

 

The <map:act type="debug"> needs 3 parameters... 

*       Id  - > id of pipeline
*       Pattern -> the pattern which is matched
*       Pattern-value -> the actual pattern, but this you will need to
adjust of course (replace each * in the pattern with {number})

 

<map:pipeline id="static-content">

  <map:match pattern="static/page/*/page-*.*">

    <map:act type="debug">

       <map:parameter name="id" value="static-content"/>

       <map:parameter name="pattern" value="static/page/*/page-*.*"/>

       <map:parameter name="pattern-value"
value="static/page/{1}/page-{2}.{3}"/>               

    </map:act>     

    <map:generate src="myDemo/static/page/{1}/page-{2}.xml"/>

    <map:call resource="publish"/>

  </map:match>  

</map:pipeline>  

 

 

Now if I do following request 

http://localhost:8888/ciberBlock/static/page/general/page-home.xhtml

 

I will get following output in my console:

 

----------------- Start Pipeline Debugging --------------------------

Pipeline executed: static-content

Matched pattern: static/page/*/page-*.*

Pattern value: static/page/general/page-home.xhtml

----------------- End Pipeline Debugging ----------------------------

 

 

Cheers,

Robby Pelssers

Reply via email to