Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

No Format
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
  <!--
	This xsp don't use cocoon taglib action.xsl 
	(less easier than a simple java line), but learn from it the code to put
-->
  <xsp:structure>
    <xsp:include>org.apache.cocoon.environment.Session</xsp:include>
    <xsp:include>java.util.*</xsp:include>
    <xsp:include>java.io.*</xsp:include>
    <xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
    <xsp:include>org.apache.cocoon.generation.XfolioDirectoryGenerator</xsp:include>
    <xsp:include>org.apache.cocoon.environment.Redirector</xsp:include>
    <xsp:include>org.apache.cocoon.acting.ServerPagesAction</xsp:include>
    <xsp:include>java.util.Map</xsp:include>
  </xsp:structure>
  <!-- class variable, outside of the generate() method, begun by the root element <action/> -->
  <xsp:logic>
      private Redirector actionRedirector;
      private Map actionResultMap;
		</xsp:logic>
  <action>
    <xsp:logic>
      <!-- 
  if you are fed up of &lt; instead of < in your javacode 
  remember XML/SGML spec and the <![CDATA[ ]]> sections
--><![CDATA[ 

  /* from the generated JAVA of the XSPAction logicsheet */
  this.actionRedirector = (Redirector)this.objectModel.get(ServerPagesAction.REDIRECTOR_OBJECT);
  this.actionResultMap = (Map)this.objectModel.get(ServerPagesAction.ACTION_RESULT_OBJECT);

  // output of the action. If it stay like that, action failed
  String radical="";


	String path=parameters.getParameter("folder", null);
	// For sitemap authors
  if (path == null) throw new ProcessingException ("Action, redirect.xsp, folder parameter is empty" ); 	
	File folder=new File (path);
  if (!folder.isDirectory()) {
    //  throwing exception is a bad idea, failed action is a not so bad effect
    //  throw new ProcessingException ("Action, redirect.xsp : " + folder + " is not a directory" );
  }
  else {
    // when a page not found is provide, for example a not available language or an identifier witout extension
    String search=parameters.getParameter("radical", null);
    File[] files;
    files=folder.listFiles();
  
    /* 
    logic is, scan all files, and keep the best as possible
    some more parameters may be useful
    
    For now, effect on lang is to get the last for index
    the first for first file
    */
    
    String candidate="";
    String extension="";
    String htmlisable="html sxw dbx jpg";
    String lang="";
    for (int i=0 ; i < files.length ; i++) {
      candidate=files[i].getName();
      int dotPos=candidate.lastIndexOf(".");
      extension=( dotPos > 0)?candidate.substring(dotPos+1):"";
      candidate=( dotPos > 0)?candidate.substring(0, dotPos):candidate;
  
      if (files[i].isDirectory()) {}
      else if (candidate.startsWith("_") || candidate.startsWith(".")) {}
      // first file
      else if ("".equals(radical) && htmlisable.indexOf(extension) != -1) {radical=candidate ;}
      // index
      else if (candidate.startsWith("index") && htmlisable.indexOf(extension) != -1) {
        radical=candidate;
      }
      // after index
      else if (radical.startsWith("index")) {break;}
    }

  }
  
	// give the path of generated file as a sitemap parameter
	this.actionResultMap.put("radical", radical);
	// if no radical found (probably folder doesn't exist), action fails
	try {	
		if (!"".equals(radical)) this.objectModel.put(ServerPagesAction.ACTION_SUCCESS_OBJECT, Boolean.TRUE);
		else this.objectModel.put(ServerPagesAction.ACTION_SUCCESS_OBJECT, Boolean.FALSE);
	} 
	catch (Exception e) {this.objectModel.put(ServerPagesAction.ACTION_SUCCESS_OBJECT, Boolean.FALSE);} 
	
	]]></xsp:logic>
  </action>
</xsp:page>

Changes

  • Wiki Markup
    2004-07-14 more detailes explanation --\[FredericGlorieux FG\]

  • Wiki Markup
    2004-07-13 Creation --\[FredericGlorieux FG\]