RSF Hello Example

The RSF Hello Example is an attempt to create the simplest possible Sakai RSF application. It is stripped bare of everything but the display of a single message.

File Structure

./Ex0-Hello
	maven.xml
	project.properties
	project.xml

	/src
		/java/org/sakaiproject/tool/simple/components:
			MainProducer.java
		/webapp
			/WEB-INF
				applicationContext.xml
				requestContext.xml
				web.xml
			/content:
				/templates
					main.html
			/tools:
				sakai.rsf.ex0.xml

The Template File

main.html

<!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:rsf="http://ponder.org.uk/rsf">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />

    <title>Sakai RSF - Link Example</title>

    <link href="/library/skin/tool_base.css" rsf:id="scr=portal-matter" type="text/css" rel="stylesheet" media="all"/>
    <link href="/library/skin/default/tool.css" rsf:id="scr=portal-matter" type="text/css" rel="stylesheet" media="all"/>
    <script type="text/javascript" rsf:id="scr=portal-matter" language="JavaScript" src="/library/js/headscripts.js"></script>

</head>
  <body>
    <h1>Sakai RSF - Hello World Example</h1>
    <span rsf:id="text">Hello world text goes here.</span>
  </body>
</html>

The Tool Registration File

sakai.rsf.ex0.xml

<?xml version="1.0"?>
<registration>
	<tool id="sakai.rsf.ex0" 
		title="Sakai RSF Example 0"
		description="Hello World Example.">

		<configuration name="rsf.property.msg" value="[Message here]" />
		<category name="sakai.sample" />
		<keyword name="rsf-examples" />
	</tool>
</registration>

The Spring Context Files

requestContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

  <!-- Define the component producer for the main view -->
  <bean id="MainProducer" class="org.sakaiproject.tool.simple.components.MainProducer" />

</beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

  <!-- Nothing defined in application scope.  --> 

</beans>

The Tomcat Application Definition File

web.xml

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  version="2.4">

<!-- CONFIG This is the name of the "punch-through" URL which will access the
    servlet directly bypassing the Sakai request filter. Paths beginning with
    / will be considered RELATIVE TO THE FIRST SLASH APPEARING IN THE REQUEST
    URL. Other paths will be considered as absolute URLS. 
    THIS MUST AGREE WITH THE DEPLOYED WEBAPP NAME, i.e. the artifactId of this
    tool, where the Sakai plugin build was used.
    -->
  <context-param>
    <param-name>resourceurlbase</param-name>
    <param-value>/rsf-ex-0/</param-value>
  </context-param>

  <!-- Configure standard Spring application contexts. Be sure to mention
    rsf config files first, so any overrides may be processed. The first two
    config files are loaded from inside the rsfutil.jar  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:conf/rsf-config.xml,
      classpath:conf/blank-applicationContext.xml,
      classpath:conf/sakai-applicationContext.xml,
      /WEB-INF/applicationContext.xml
    </param-value>
  </context-param>

  <!-- Configure "request scope" Spring application contexts (RSAC).
    Be sure to mention rsf config files first, so any overrides may be
    processed. -->
  <context-param>
    <param-name>requestContextConfigLocation</param-name>
    <param-value>
      classpath:conf/rsf-requestscope-config.xml,
      classpath:conf/blank-requestContext.xml,
      classpath:conf/sakai-requestContext.xml,
      /WEB-INF/requestContext.xml
    </param-value>
  </context-param>


  <!--  The Sakai Request Handler - standard request filtering.-->
  <filter>
    <filter-name>sakai.request</filter-name>
    <filter-class>org.sakaiproject.util.RequestFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sakai.request</filter-name>
    <servlet-name>sakai.rsf.ex0</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>

  <!--  The RSF Servlet.  -->
  <servlet>
    <!-- This must agree with the name advertised in the tool registration. -->
    <servlet-name>sakai.rsf.ex0</servlet-name>
    <servlet-class>
      uk.ac.cam.caret.sakai.rsf.servlet.ReasonableSakaiServlet
    </servlet-class>
    <!--<load-on-startup>1</load-on-startup>-->
  </servlet>
  
  <!-- URL mapping has handled by SakaiRequestParser -->
  <servlet-mapping>
    <servlet-name>sakai.rsf.ex0</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

  <!--  The ToolListener causes this tool to be registerd with Sakai.  -->
  <listener>
    <listener-class>org.sakaiproject.util.ToolListener</listener-class>
  </listener>

  <listener>
    <listener-class>
      org.sakaiproject.util.ContextLoaderListener
    </listener-class>
  </listener>

</web-app>

The Main Producer Java Code

MainProducer.java

/*
 * Created on Mar. 8, 2007 by mjn
 * This file is (c) 2007 Nolaria Consulting, all rights reserved.
 */
package org.sakaiproject.tool.simple.components;

import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.viewstate.ViewParameters;
import uk.org.ponder.rsf.view.ComponentChecker;
import uk.org.ponder.rsf.view.DefaultView;
import uk.org.ponder.rsf.view.ViewComponentProducer;


public class MainProducer implements ViewComponentProducer, DefaultView {
  public static final String VIEW_ID = "main";

  public String getViewID() {
    return VIEW_ID;
  }

  public void fillComponents(UIContainer tofill, ViewParameters params, ComponentChecker checker) {
    UIOutput.make(tofill, "text", "Hello RSF World!");
  }
}

The Maven Project

project.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <pomVersion>3</pomVersion>
  <extend>../../master/project.xml</extend>
  <artifactId>rsf-ex-0</artifactId>
  <name>RsfEx0</name>
  <groupId>sakaiproject</groupId>
  <currentVersion>${sakai.version}</currentVersion>

  <properties>
    <!-- deploy as a war -->
    <deploy.type>war</deploy.type>
  </properties>

  <organization>
    <name>Nolaria Consulting</name>
    <url>http://wwww.nolaria.com</url>
  </organization>
  <inceptionYear>2007</inceptionYear>
  <description>RSF Example 0 - Hello World</description>
  <repository />

  <dependencies>

    <!-- begin standard RSF dependencies here -->
    <dependency>
      <groupId>ponderutilcore</groupId>
      <artifactId>ponderutilcore</artifactId>
      <version>${ponderutilcore.version}</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
    <dependency>
      <groupId>j-servletutil</groupId>
      <artifactId>j-servletutil</artifactId>
      <version>${jservletutil.version}</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
    <dependency>
      <groupId>rsfutil</groupId>
      <artifactId>rsfutil</artifactId>
      <version>${rsfutil.version}</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>

    <dependency>
      <groupId>servletapi</groupId>
      <artifactId>servletapi</artifactId>
      <version>2.4-20040521</version>
      <type>jar</type>
    </dependency>
     <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.9</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>1.2.8</version>
      <type>jar</type> 
    </dependency>

    <!--  The framework requires CGLIB (Java bytecode manipulation library) 
    in order to implement lazy-loaded beans  -->
    <dependency>
      <groupId>aopalliance</groupId>
      <artifactId>aopalliance</artifactId>
      <version>1.0</version>
      <type>jar</type> 
    </dependency>
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>nodep-2.1_3</version>
      <type>jar</type> 
    </dependency>  

    <dependency>
      <!-- Doug Lea's Oswego concurrency package. The forerunner of JSR 166
        java.util.concurrent -->
      <groupId>concurrent</groupId>
      <artifactId>concurrent</artifactId>
      <version>1.3.4</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
    <!-- Aleksander Slominski's (U Indiana) lightning-fast XML pull parser -->
      <dependency>
      <groupId>xpp3</groupId>
      <artifactId>xpp3</artifactId>
      <version>1.1.3.4-RC8_min</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>

    <!-- Sakai Util is required to resolve user's Locale -->
    <dependency>
      <groupId>sakaiproject</groupId>
      <artifactId>sakai-util</artifactId>
      <version>${sakai.version}</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
    <dependency>
      <groupId>sakairsf</groupId>
      <artifactId>sakairsf</artifactId>
      <version>${rsfutil.version}-sakai_${sakai.version}</version>
      <type>jar</type>
      <properties>
        <war.bundle>true</war.bundle>
      </properties>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/java</sourceDirectory>
  </build>
</project>