You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2007/01/24 01:25:36 UTC

svn commit: r499193 [1/3] - in /forrest/trunk/whiteboard/dispatcher: ./ java/ java/org/ java/org/apache/ java/org/apache/forrest/ java/org/apache/forrest/dispatcher/ java/org/apache/forrest/dispatcher/api/ java/org/apache/forrest/dispatcher/helper/ jav...

Author: thorsten
Date: Tue Jan 23 16:25:33 2007
New Revision: 499193

URL: http://svn.apache.org/viewvc?view=rev&rev=499193
Log:
Adding a StAX implementation of the dispatcher to the whiteboard.

It is very basic and should be seen as proof of concept.

To make the version compile you need to download 
and copy the JSR 173 API from 
http://www.ibiblio.org/maven2/stax/stax-api/1.0/stax-api-1.0.jar 
and copy it to lib/api/. 

After building
./build.sh
try
./dispatch

Right now we using a master structurer and ignore any parameter coming in.
It should be easy to make the structurer configurable like said it is a PoF.

Added:
    forrest/trunk/whiteboard/dispatcher/   (with props)
    forrest/trunk/whiteboard/dispatcher/README.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/build.properties   (with props)
    forrest/trunk/whiteboard/dispatcher/build.sh   (with props)
    forrest/trunk/whiteboard/dispatcher/build.xml   (with props)
    forrest/trunk/whiteboard/dispatcher/dispatch   (with props)
    forrest/trunk/whiteboard/dispatcher/java/
    forrest/trunk/whiteboard/dispatcher/java/org/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java   (with props)
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/
    forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java   (with props)
    forrest/trunk/whiteboard/dispatcher/lib/   (with props)
    forrest/trunk/whiteboard/dispatcher/lib/commons-lang-2.1.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/lib/stax-1.2.0-dev.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/lib/stax-utils.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/targets/
    forrest/trunk/whiteboard/dispatcher/targets/dispatch.xml   (with props)
    forrest/trunk/whiteboard/dispatcher/themes/
    forrest/trunk/whiteboard/dispatcher/themes/contracts/
    forrest/trunk/whiteboard/dispatcher/themes/contracts/m2.contract.xml   (with props)
    forrest/trunk/whiteboard/dispatcher/themes/contracts/master.contract.xml   (with props)
    forrest/trunk/whiteboard/dispatcher/themes/structurer/
    forrest/trunk/whiteboard/dispatcher/themes/structurer/url/
    forrest/trunk/whiteboard/dispatcher/themes/structurer/url/master.structurer.xml   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/
    forrest/trunk/whiteboard/dispatcher/tools/ant/
    forrest/trunk/whiteboard/dispatcher/tools/ant/ant.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/README-forrest-upgrade.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/ant   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/ant.bat   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/ant.cmd   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/antRun
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/antRun.bat   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/antRun.pl   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/antenv.cmd   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/complete-ant-cmd.pl   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/envset.cmd   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/forrestant.bat   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/forrestpath.bat   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/lcp.bat   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/runant.pl   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/runant.py   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/bin/runrc.cmd   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-apache-oro.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-apache-resolver.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-commons-net.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-contrib-1.0b2.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-contrib-1.0b2.jar.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-jsch.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-launcher.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-nodeps.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-trax.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant-xalan2.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/ant.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/apache-jakarta-commons-net-1.4.1.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/apache-jakarta-commons-net-1.4.1.jar.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/jsch-0.1.28.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/jsch-0.1.28.jar.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/jsvn-0.9-dev.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/jsvn-0.9-dev.jar.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/oro-2.0.8.jar   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/oro-2.0.8.jar.license.txt   (with props)
    forrest/trunk/whiteboard/dispatcher/tools/ant/lib/xml-commons-resolver-1.1.jar   (with props)

Propchange: forrest/trunk/whiteboard/dispatcher/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 23 16:25:33 2007
@@ -0,0 +1,5 @@
+build
+cache
+.settings
+.classpath
+.project

Added: forrest/trunk/whiteboard/dispatcher/README.txt
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/README.txt?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/README.txt (added)
+++ forrest/trunk/whiteboard/dispatcher/README.txt Tue Jan 23 16:25:33 2007
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+StAX
+****
+You need to download and install JSR-000173 Streaming API for XML 1.0
+see http://jcp.org/aboutJava/communityprocess/final/jsr173/index.html
+and
+see https://stax-utils.dev.java.net/
+
+tutorials: http://www.devx.com/ibm/Door/20346
+
+history: http://www.xmlpull.org/history/index.html
+
+IBM Series
+cursor vs. iterator: http://www-128.ibm.com/developerworks/xml/library/x-tipstx/
+filtering: http://www-128.ibm.com/developerworks/xml/library/x-tipstx2/
\ No newline at end of file

Propchange: forrest/trunk/whiteboard/dispatcher/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/build.properties
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/build.properties?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/build.properties (added)
+++ forrest/trunk/whiteboard/dispatcher/build.properties Tue Jan 23 16:25:33 2007
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+dispatcher.contract.rep=${dispatcher.home}/themes/contracts
+dispatcher.cache=${dispatcher.home}/cache
+# Max memory to allocate to Java
+dispatcher.maxmemory=64m
+
+# Any other arguments to pass to the JVM. For example, to run on an X-less
+# server, set to -Djava.awt.headless=true
+dispatcher.jvmargs=
\ No newline at end of file

Propchange: forrest/trunk/whiteboard/dispatcher/build.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/build.sh
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/build.sh?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/build.sh (added)
+++ forrest/trunk/whiteboard/dispatcher/build.sh Tue Jan 23 16:25:33 2007
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# ----- Verify and Set Required Environment Variables -------------------------
+
+if [ "$TERM" = "cygwin" ] ; then
+  S=';'
+else
+  S=':'
+fi
+
+# ----- Set Up The Runtime Classpath ------------------------------------------
+
+OLD_ANT_HOME="$ANT_HOME"
+unset ANT_HOME
+
+CP=$CLASSPATH
+export CP
+unset CLASSPATH
+
+CLASSPATH="`echo lib/*.jar | tr ' ' $S`":"`echo lib/api/*.jar | tr ' ' $S`"
+export CLASSPATH
+
+echo "Using classpath: $CLASSPATH"
+"$PWD/tools/ant/bin/ant" -logger org.apache.tools.ant.NoBannerLogger -emacs  $@
+status=$?
+
+unset CLASSPATH
+
+CLASSPATH=$CP
+export CLASSPATH
+ANT_HOME=OLD_ANT_HOME
+export ANT_HOME
+
+# ----- Clean back the environment ------------------------------------------
+unset OLD_ANT_HOME
+unset CP
+
+exit $status

Propchange: forrest/trunk/whiteboard/dispatcher/build.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: forrest/trunk/whiteboard/dispatcher/build.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: forrest/trunk/whiteboard/dispatcher/build.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/build.xml?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/build.xml (added)
+++ forrest/trunk/whiteboard/dispatcher/build.xml Tue Jan 23 16:25:33 2007
@@ -0,0 +1,166 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project default="dispatcher.jar" basedir="." name="Dispatcher build file">
+
+  <description>
+    Build system for Apache Forrest Dispatcher.
+    Run the build script: build.bat or build.sh
+  </description>
+  
+   <import file="targets/dispatch.xml"/>
+   <target name="dispatcher.init">
+    <tstamp>
+      <format property="YEAR" pattern="yyyy" locale="en"/>
+    </tstamp>
+     
+    <property name="dispatcher.build.compiler.emacs"       value="on"/>
+    <property name="dispatcher.build.compiler.warnings"    value="true"/>
+    <property name="dispatcher.build.compiler.pedantic"    value="false"/>
+    <property name="dispatcher.build.compiler.depend"      value="true"/>
+    <property name="dispatcher.build.compiler.fulldepend"  value="true"/>
+    <property name="dispatcher.build.compiler.debug"       value="on"/>    
+    <property name="dispatcher.build.compiler.optimize"    value="off"/>
+    <property name="dispatcher.build.compiler.deprecation" value="on"/>
+    <property name="dispatcher.build.compiler.nowarn"      value="on"/>    
+    <property name="dispatcher.build.compiler.type"        value="classic"/>
+    <property name="dispatcher.build.compiler.vm"          value="1.5"/>
+   
+    <property name="name" value="apache-dispatcher"/>
+    <property name="dispatcher.version" value="0.0.1-dev"/>
+    <property name="dispatcher.home" location="."/>
+     
+    <property file="${dispatcher.home}/local.build.properties" />
+    <property file="${dispatcher.home}/build.properties" />
+
+    <property name="java.dir"              location="java"/>
+    <property name="dispatcher.build.dir"             location="${dispatcher.home}/build"/>
+    <property name="dispatcher.build.docs"            location="${dispatcher.build.dir}/docs"/>
+    <property name="dispatcher.build.classes"         location="${dispatcher.build.dir}/classes"/>
+    <property name="dispatcher.lib.dir"               location="${dispatcher.home}/lib"/>
+    <property name="dispatcher.lib.api.dir"           location="${dispatcher.home}/lib/api"/>
+     
+    <property name="dispatcher.ant.lib-dir"        location="${dispatcher.home}/tools/ant/lib"/>
+    <property name="dispatcher.anttasks"           location="${dispatcher.home}/tools/anttasks"/>
+
+    <property name="tools.jar"             location="${java.home}/../lib/tools.jar"/>
+    <available file="${tools.jar}"         property="tools.jar.present"/>
+    
+    <mkdir dir="${dispatcher.build.dir}"/>
+    
+    <buildnumber file="${dispatcher.build.dir}/build.number"/>
+     
+    <echo>
+      --------------------------------------------------------------
+
+      Using ${ant.version}
+      Build file ${ant.file}
+      Use 'build.[sh|bat] -projecthelp' to see other options.
+      Build system home ${ant.home}
+      Build number ${dispatcher.build.number}
+      Project Name ${ant.project.name}
+      Java Version ${ant.java.version}      
+      Timestamp ${DSTAMP}${TSTAMP}
+      This is: ${name} ${dispatcher.version}
+
+      --------------------------------------------------------------
+    </echo>
+    
+    <path id="dispatcher.classpath">
+      <fileset dir="${dispatcher.home}/lib" includes="**/*.jar"/>
+      <pathelement location="${tools.jar}"/>
+    </path>
+  <taskdef resource="net/sf/antcontrib/antlib.xml">
+    <classpath>
+      <fileset dir="${dispatcher.ant.lib-dir}" includes="ant-contrib-*.jar" />
+    </classpath>
+  </taskdef>
+  </target>
+
+  <target name="dispatcher.clean" depends="dispatcher.init" description="Delete all generated files">
+    <delete dir="${dispatcher.build.dir}"/>
+  </target>
+  
+  <target name="dispatcher.clean-cache" depends="dispatcher.init" 
+     description="Delete dispatcher cache dir.">
+    <echo>Deleting cache dir ${dispatcher.cache}</echo>
+    <delete dir="${dispatcher.cache}"/>
+  </target>
+
+  <!-- =================================================================== -->
+  <!-- Clean build, that is clean before build                             -->
+  <!-- =================================================================== -->
+  <target name="dispatcher.clean-build" depends="dispatcher.clean, dispatcher.jar" description="Clean build, that is clean before build..." />
+  
+  <!-- =================================================================== -->
+  <!-- Compile Dispatcher java classes                                         -->
+  <!-- =================================================================== -->
+  <target name="dispatcher.compile" depends="dispatcher.init">
+    <mkdir dir="${dispatcher.build.classes}"/>
+    <javac srcdir=   "${java.dir}"
+      destdir=       "${dispatcher.build.classes}"
+      debug=         "${dispatcher.build.compiler.debug}"
+      optimize=      "${dispatcher.build.compiler.optimize}"
+      deprecation=   "${dispatcher.build.compiler.deprecation}"
+      nowarn=        "${dispatcher.build.compiler.nowarn}"
+      classpathref=  "dispatcher.classpath">
+    </javac>
+  </target>
+  
+<!-- =================================================================== -->
+  <!-- Jar dispatcher classes                                                  -->
+  <!-- =================================================================== -->
+  <target name="dispatcher.jar" depends="dispatcher.init, dispatcher.compile" description="Generates the dispatcher jar.">
+    <jar destfile="${dispatcher.build.dir}/dispatcher-${dispatcher.version}.jar"
+      basedir="${dispatcher.build.classes}">
+      <manifest>
+        <section name="org/apache/forrest/dispatcher/">
+          <attribute name="Comment" value="Support classes for Apache Forrest Dispatcher"/>
+          <attribute name="Implementation-Title" value="org.apache.forrest.dispatcher"/>
+          <attribute name="Implementation-Version" value="${dispatcher.version} ${TODAY}"/> 
+          <attribute name="Implementation-Vendor" value="The Apache Software Foundation"/>
+          <attribute name="Implementation-URL" value="http://forrest.apache.org/dipatcher/"/>
+        </section>
+      </manifest>
+    </jar>
+    <echo>
+  +-------------------------------------------------------------------------+
+  | Installation notice                                                     
+  +-------------------------------------------------------------------------+
+  | You have built the ${dispatcher.version} version of the dispatcher.     
+  |                                                                         
+  | find the jar: 
+  | ${dispatcher.build.dir}/dispatcher-${dispatcher.version}.jar         
+  +-------------------------------------------------------------------------+
+    </echo>
+  </target>
+  <target name="dispatcher.-prepare-classpath">
+    <path id="dispatcher.cp">
+         <pathelement path="${env.CLASSPATH}" />
+         <pathelement location="${dispatcher.build.classes}"/>
+         <fileset dir="${dispatcher.lib.dir}" casesensitive="no">
+           <include name="*.jar"/>
+           <include name="*.zip"/>
+         </fileset>
+         <fileset dir="${dispatcher.lib.api.dir}" casesensitive="no">
+           <include name="*.jar"/>
+           <include name="*.zip"/>
+         </fileset>
+         <pathelement location="${tools.jar}"/>
+    </path>
+  </target>
+</project>

Propchange: forrest/trunk/whiteboard/dispatcher/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/dispatch
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/dispatch?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/dispatch (added)
+++ forrest/trunk/whiteboard/dispatcher/dispatch Tue Jan 23 16:25:33 2007
@@ -0,0 +1,124 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# set the current working dir as the PROJECT_HOME variable 
+
+cygwin=false;
+darwin=false;
+case `uname` in
+  CYGWIN*) cygwin=true ;;
+  Darwin*) darwin=true
+           if [ -z "$JAVA_HOME" ] ; then
+             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home   
+           fi
+           ;;
+esac
+
+if [ "$cygwin" = "true" ] ; then
+  PROJECT_HOME=`cygpath -w "$PWD"`
+else
+  PROJECT_HOME=`pwd`
+fi
+
+if [ -z "$DISPATCHER_HOME" ] ; then
+  # use the location of this script to infer $DISPATCHER_HOME
+
+  thisprg="$0"
+
+  # Resolve links - $thisprg may be a symbolic link
+
+  while [ -h "$thisprg" ] ; do
+    ls=`ls -ld "$thisprg"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+
+    if expr "$link" : '/.*' > /dev/null; then
+      thisprg="$link"
+    else
+      thisprg=`dirname "$thisprg"`/"$link"
+    fi
+  done
+
+  DISPATCHER_HOME=`dirname "$thisprg"`
+
+  # Make it fully qualified
+
+  DISPATCHER_HOME=`cd "$DISPATCHER_HOME" && pwd`
+  echo $DISPATCHER_HOME
+fi
+
+# Save old ANT_HOME
+OLD_ANT_HOME="$ANT_HOME"
+unset ANT_HOME
+ANT_HOME="$DISPATCHER_HOME/tools/ant"
+
+# ----- Set Up The Runtime Classpath ------------------------------------------
+
+if [ "$cygwin" = "true" ] ; then
+  S=';'
+  DISPATCHER_DOT_HOME=`cygpath -w "$DISPATCHER_HOME"`
+else
+  S=':'
+  DISPATCHER_DOT_HOME=$DISPATCHER_HOME
+fi
+
+# set the ant file to use
+ANTFILE="$DISPATCHER_DOT_HOME/build.xml"
+
+CP="$CLASSPATH"
+export CP
+unset CLASSPATH
+
+for i in $DISPATCHER_HOME/lib/*.jar; do
+  if [ "$cygwin" = "true" ] ; then
+    LIB=`cygpath -w $i`
+  else
+    LIB=$i
+  fi
+
+  CLASSPATH=$CLASSPATH$S$LIB
+done
+for i in $DISPATCHER_HOME/lib/api/*.jar; do
+  if [ "$cygwin" = "true" ] ; then
+    LIB=`cygpath -w $i`
+  else
+    LIB=$i
+  fi
+
+  CLASSPATH=$CLASSPATH$S$LIB
+done
+
+export CLASSPATH
+
+echo "Apache Forrest Dispatcher.  Run './dispatch -projecthelp' to list options"
+echo
+export DISPATCHER_HOME
+echo "$ANT_HOME/bin/ant" dispatch --noconfig -buildfile "$ANTFILE" -Dbasedir="$PROJECT_HOME" -emacs "$@"
+"$ANT_HOME/bin/ant" dispatcher.dispatch --noconfig -buildfile "$ANTFILE" -Dbasedir="$PROJECT_HOME" -emacs "$@"
+RESULT=$?
+
+# ---- Restore Classpath
+unset CLASSPATH
+CLASSPATH=$CP
+export CLASSPATH
+
+# ---- Restore ANT_HOME
+# Restore old ANT_HOME
+ANT_HOME="$OLD_ANT_HOME"
+export ANT_HOME
+
+exit $RESULT

Propchange: forrest/trunk/whiteboard/dispatcher/dispatch
------------------------------------------------------------------------------
    svn:executable = *

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher;
+
+import java.io.File;
+
+import org.apache.forrest.dispatcher.helper.DispatcherPropertiesHelper;
+import org.apache.forrest.dispatcher.helper.StructurerHelperStAX;
+
+public class Cli {
+    private static DispatcherPropertiesHelper propertiesHelper;
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        System.out.println("--- Dispatcher CLI ---");
+        final String home = args[0];
+        System.out.println("home: "+home);
+        propertiesHelper = new DispatcherPropertiesHelper(home);
+        String sourceUrl;
+        try {
+            sourceUrl = propertiesHelper.getMasterStructurerUrl().replace("file://", "");
+            System.out.println("sourceUrl "+sourceUrl);
+            StructurerHelperStAX helper = new StructurerHelperStAX(home);
+            File result = helper.execute(sourceUrl, "html");
+            System.out.println("********  END *********");
+            System.out.println("Structurer");
+            System.out.println("result:  " + result.getAbsolutePath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/Cli.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.api;
+
+import java.io.File;
+import java.util.HashMap;
+
+/**
+ * @author thorsten
+ *
+ */
+public interface Contract {
+    
+    /**
+     * @return the name of the contract
+     */
+    public abstract String getName();
+    
+    /**
+     * @param contractName - the name of the contract
+     */
+    public abstract void setName(String contractName);
+    
+    /**
+     * @return the description of the contract
+     */
+    public abstract String getDescription();
+    
+    /**
+     * @param Description - the description of the contract
+     */
+    public abstract void setDescription(String contractDescription);
+    
+    /**
+     * @return how to use the contract
+     */
+    public abstract String getUsage();
+
+    /**
+     * @param contractUsage - how to use the contract
+     */
+    public abstract void setUsage(String contractUsage);
+    
+    public abstract void initialize(String sourceUrl,String destination);
+    
+    public abstract File getTemplate();
+    
+    public abstract File execute(String dataUrl, HashMap param,String destination);
+    
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/api/Contract.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javanet.staxutils.BaseXMLInputFactory;
+import javanet.staxutils.BaseXMLOutputFactory;
+import javanet.staxutils.events.ProcessingInstructionEvent;
+import javanet.staxutils.io.XMLWriterUtils;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.ProcessingInstruction;
+import javax.xml.stream.util.XMLEventAllocator;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.xml.sax.SAXException;
+
+import com.bea.xml.stream.XMLEventAllocatorBase;
+
+public class ContractHelperStAX {
+
+    public static final String NS = "http://apache.org/forrest/templates/1.0";
+
+    public static final String CONTRACT_ELEMENT = "contract";
+
+    public static final String CONTRACT_NAME_ATT = "name";
+
+    public static final String DESCRIPTION_ELEMENT = "description";
+
+    public static final String TEMPLATE_ELEMENT = "template";
+
+    public static final String TEMPLATE_FORMAT_ATT = "inputFormat";
+
+    public static final String USAGE_ELEMENT = "usage";
+
+    public static final String RESULT_XPATH = "xpath";
+
+    private String name, usage, description;
+
+    private XMLOutputFactory outputFactory = BaseXMLOutputFactory.newInstance();
+
+    private XMLInputFactory inputFactory = BaseXMLInputFactory.newInstance();
+
+    private DispatcherPropertiesHelper propertiesHelper;
+
+    public ContractHelperStAX(String home) {
+        propertiesHelper= new DispatcherPropertiesHelper(home);
+    }
+
+    public File execute(String dataUrl, HashMap param, String destination,
+            File template) throws FileNotFoundException, SAXException {
+        boolean useCache = false;
+        // The incoming xml data for the transformation and the file we will
+        // return
+        File dataFile = new File(dataUrl);
+        File cachedContract = new File(destination);
+        if (!cachedContract.isFile()) {
+            try {
+                cachedContract.createNewFile();
+            } catch (IOException e) {
+                // if we cannot create a file that means that the parent path
+                // does not exists
+                File path = new File(cachedContract.getParent());
+                path.mkdirs();
+                try {
+                    cachedContract.createNewFile();
+                } catch (IOException e1) {
+                    throw new SAXException("IOException: "+e.getMessage());
+                }
+            }
+        } else {
+            // compare the url and the file and the datauri and the structurer
+            // url (not known here)
+            long modifiedCache = cachedContract.lastModified();
+            long modifiedContract = dataFile.lastModified();
+            if (modifiedCache > modifiedContract)
+                useCache = true;
+        }
+
+        if (!useCache) {
+            // FIXME activate when stable
+        }
+
+        // Create transformer
+        TransformerFactory transFact = TransformerFactory.newInstance();
+        FileReader templateReader = new FileReader(template), dataReader;
+        try {
+            // here we need to inject the dataUri or foo
+            if (!dataFile.isFile()) {
+                // no dataFile defined trying cache for foo
+                dataFile = new File(propertiesHelper.getMasterFooUrl().replace("file://", ""));
+                if (!dataFile.isFile()) {
+                    // not in cache either, so we create it and
+                    // store it in cache
+                    Writer foo = new FileWriter(dataFile);
+                    XMLStreamWriter fooWriter = outputFactory
+                            .createXMLStreamWriter(foo);
+                    fooWriter.writeStartDocument("UTF-8", "1.0");
+                    fooWriter.writeStartElement("foo");
+                    fooWriter.writeEndDocument();
+                    fooWriter.flush();
+                    fooWriter.close();
+                    foo.close();
+                }
+            }
+            dataReader = new FileReader(dataFile);
+            Source xslSource = new StreamSource(templateReader);
+            Source dataSource = new StreamSource(dataReader);
+            // prepare transformation
+            Transformer transformer = transFact.newTransformer(xslSource);
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            // It seems that the only way to pass a xml file to a xsl as param
+            // is as DOM
+            DocumentBuilder builder = DocumentBuilderFactory.newInstance()
+                    .newDocumentBuilder();
+            for (Iterator iter = param.keySet().iterator(); iter.hasNext();) {
+                String key = (String) iter.next();
+                File value = (File) param.get(key);
+                transformer.setParameter(key, builder.parse(value));
+            }
+            // create a StreamResult and write the result to disk
+            Result streamResult = new StreamResult(cachedContract);
+            transformer.transform(dataSource, streamResult);
+        } catch (Exception e1) {
+            throw new SAXException("Exception: "+e1.getMessage());
+        }
+
+        return cachedContract;
+    }
+
+    public File getTemplate(String sourceUrl, String destination)
+            throws IOException, FactoryConfigurationError, XMLStreamException,
+            InstantiationException, IllegalAccessException {
+        // setting up the files
+        String fileName = destination;
+        File cache = new File(fileName), contractFile = new File(sourceUrl);
+        // caching is ATM implemetent by writing the template to disk
+        boolean useCache = false;
+        // if no file exist, create it
+        if (!cache.isFile()) {
+            try {
+                cache.createNewFile();
+            } catch (Exception e) {
+                // if we cannot create a file that means that the parent path
+                // does not exists
+                File path = new File(cache.getParent());
+                path.mkdirs();
+                cache.createNewFile();
+            }
+        } else {
+            // compare the url and the file
+            long modifiedCache = cache.lastModified();
+            long modifiedContract = contractFile.lastModified();
+            if (modifiedCache > modifiedContract)
+                useCache = true;
+        }
+        // !useCache
+        if (true) {
+            URL contractUrl;
+            // if we do not have a protocol defined
+            // we define the file protocoll as default
+            if (sourceUrl.indexOf(":/") > -1)
+                contractUrl = new URL(sourceUrl);
+            else
+                contractUrl = new URL("file://" + sourceUrl);
+            InputStream in = contractUrl.openStream();
+            inputFactory.setEventAllocator(new XMLEventAllocatorBase());
+            XMLEventAllocator allocator = inputFactory.getEventAllocator();
+            XMLStreamReader parser = inputFactory.createXMLStreamReader(in);
+            // Create XML event writer
+            // Write the result to disk
+            Writer result = new FileWriter(fileName);
+            ProcessingInstruction procInst = new ProcessingInstructionEvent("xml",
+                    "version=\"1.0\" encoding=\"UTF-8\"");
+            XMLWriterUtils.writeProcessingInstruction(procInst, result);
+            XMLEventWriter writer = outputFactory.createXMLEventWriter(result);
+            while (true) {
+                int event = parser.next();
+                if (event == XMLStreamConstants.END_DOCUMENT) {
+                    break;
+                }
+                if (event == XMLStreamConstants.START_ELEMENT) {
+                    if (parser.getLocalName().equals(CONTRACT_ELEMENT))
+                        processContract(parser);
+                    if (parser.getLocalName().equals(DESCRIPTION_ELEMENT))
+                        processDescription(parser);
+                    if (parser.getLocalName().equals(USAGE_ELEMENT))
+                        processUsage(parser);
+                    if (parser.getLocalName().equals(TEMPLATE_ELEMENT))
+                        processTemplate(parser, writer, allocator);
+                } else if (event == XMLStreamConstants.END_ELEMENT) {
+                }
+            }
+            writer.flush();
+            parser.close();
+        }
+        return cache;
+    }
+
+    private static void processTemplate(XMLStreamReader parser,
+            XMLEventWriter writer, XMLEventAllocator allocator)
+            throws XMLStreamException {
+        String role = "";
+        for (int i = 0; i < parser.getAttributeCount(); i++) {
+            // Get attribute name
+            String localName = parser.getAttributeLocalName(i);
+            if (localName.equals(TEMPLATE_FORMAT_ATT)) {
+                // Return value
+                role = parser.getAttributeValue(i);
+            }
+        }
+        if (role.equals("xsl")) {
+            while (true) {
+                int event = parser.next();
+                switch (event) {
+
+                case XMLStreamConstants.END_ELEMENT:
+                    if (parser.getNamespaceURI() != null) {
+                        if (parser.getNamespaceURI().equals(NS)
+                                & parser.getLocalName().equals(TEMPLATE_ELEMENT))
+                            return;
+                        else
+                            writer.add(allocator.allocate(parser));
+                    } else
+                        writer.add(allocator.allocate(parser));
+                    break;
+
+                default:
+                    writer.add(allocator.allocate(parser));
+                    break;
+                }
+            }
+        }
+    }
+
+    private void processUsage(XMLStreamReader parser) throws XMLStreamException {
+        while (true) {
+            int event = parser.next();
+            switch (event) {
+
+            case XMLStreamConstants.CHARACTERS:
+                if (parser.getText().replace(" ", "").length() > 1) 
+                    usage = parser.getText().trim();
+                break;
+
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals(USAGE_ELEMENT))
+                    return;
+                break;
+            }
+        }
+    }
+
+    private void processDescription(XMLStreamReader parser)
+            throws XMLStreamException {
+        while (true) {
+            int event = parser.next();
+            switch (event) {
+            case XMLStreamConstants.START_ELEMENT:
+                System.out.println("ignoring " + parser.getLocalName());
+                break;
+
+            case XMLStreamConstants.CHARACTERS:
+                if (parser.getText().replace(" ", "").length() > 1) {
+                    description = parser.getText().trim();
+                }
+                break;
+
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals(DESCRIPTION_ELEMENT))
+                    return;
+                break;
+            }
+        }
+    }
+
+    private void processContract(XMLStreamReader parser) {
+        String contractName = "";
+        for (int i = 0; i < parser.getAttributeCount(); i++) {
+            // Get attribute name
+            String localName = parser.getAttributeLocalName(i);
+            if (localName.equals(CONTRACT_NAME_ATT)) {
+                // Return value
+                contractName = parser.getAttributeValue(i);
+            }
+        }
+        name = contractName;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getUsage() {
+        return usage;
+    }
+
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractHelperStAX.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import javax.xml.stream.*;
+
+public class ContractResultFilter {
+
+    private static StreamFilter filter = new StreamFilter() {
+        public boolean accept(XMLStreamReader reader) {
+            return ((!(reader.getEventType()==XMLStreamConstants.START_DOCUMENT)) & (!(reader.getEventType()==XMLStreamConstants.END_DOCUMENT)));
+        }
+    };
+
+    public static StreamFilter getFilter() {
+        return filter;
+    }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/ContractResultFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+public class DispatcherPropertiesHelper {
+    // home
+    private String dispatcherHome;
+
+    // reps
+    private String contractRep;
+
+    private String structurerRep ;
+
+    private String contractSuffix = ".contract.xml";
+
+    private String structurerSuffix = ".structurer.xml";
+
+    // caching
+    private String cacheHome;
+
+    private String cacheContracts ;
+
+    private String cacheStructure;
+
+    public final String MASTER_CONTRACT = "master.contract.xml";
+
+    public String getMasterContractUrl() {
+        String url = "file://" + contractRep + MASTER_CONTRACT;
+        return url;
+    }
+
+    public final String MASTER_STRUCTURER = "master.structurer.xml";
+
+    public String getMasterStructurerUrl() {
+        String url = "file://" + structurerRep + MASTER_STRUCTURER;
+        return url;
+    }
+
+    public final String MASTER_FOO = "foo.xml";
+
+    public String getMasterFooUrl() {
+        String url = "file://" + cacheHome + MASTER_FOO;
+        return url;
+    }
+
+    public DispatcherPropertiesHelper(String string) {
+        dispatcherHome = string;
+        contractRep = dispatcherHome + "/themes/contracts/";
+        structurerRep = dispatcherHome + "/themes/structurer/url/";
+        cacheHome = dispatcherHome + "/cache/";
+        cacheContracts = cacheHome + "/themes/contracts/";
+        cacheStructure = cacheHome + "/themes/structurer/url/";
+    }
+
+    public String getCacheContracts() {
+        return cacheContracts;
+    }
+
+    public void setCacheContracts(String cacheContracts) {
+        this.cacheContracts = cacheContracts;
+    }
+
+    public String getCacheHome() {
+        return cacheHome;
+    }
+
+    public void setCacheHome(String cacheHome) {
+        this.cacheHome = cacheHome;
+    }
+
+    public String getContractRep() {
+        return contractRep;
+    }
+
+    public void setContractRep(String contractRep) {
+        this.contractRep = contractRep;
+    }
+
+    public String getDispatcherHome() {
+        return dispatcherHome;
+    }
+
+    public void setDispatcherHome(String dispatcherHome) {
+        this.dispatcherHome = dispatcherHome;
+    }
+
+    public String getStructurerRep() {
+        return structurerRep;
+    }
+
+    public void setStructurerRep(String structurerRep) {
+        this.structurerRep = structurerRep;
+    }
+
+    public String getContractSuffix() {
+        return contractSuffix;
+    }
+
+    public void setContractSuffix(String contractSuffix) {
+        this.contractSuffix = contractSuffix;
+    }
+
+    public String getStructurerSuffix() {
+        return structurerSuffix;
+    }
+
+    public void setStructurerSuffix(String structurerSuffix) {
+        this.structurerSuffix = structurerSuffix;
+    }
+
+    public String getCacheStructure() {
+        return cacheStructure;
+    }
+
+    public void setCacheStructure(String cacheStructure) {
+        this.cacheStructure = cacheStructure;
+    }
+
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DispatcherPropertiesHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+public class DomHelper {
+    /**
+     * Creates a new document with the param rootName
+     * 
+     * @param rootName
+     * @return
+     * @throws SAXException
+     * @throws ParserConfigurationException 
+     */
+    public static Document createDocument(String rootName) throws SAXException, ParserConfigurationException {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder =factory.newDocumentBuilder();
+        Document foo=builder.newDocument();
+        foo.createElement(rootName);
+        return foo;
+    }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/DomHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLReporter;
+
+public class StAXHelper {
+
+    public static XMLInputFactory getValidatingFactory() throws FactoryConfigurationError {
+        XMLInputFactory factory;
+        factory = XMLInputFactory.newInstance();
+        factory.setProperty("javax.xml.stream.isValidating", Boolean.TRUE);
+        factory.setXMLReporter(new XMLReporter() {
+            public void report(String message, String errorType,
+                    Object relatedInformation, Location location) {
+                System.err.println("Problem in " + location.getPublicId());
+                System.err.println("at line " + location.getLineNumber()
+                        + ", column " + location.getColumnNumber());
+                System.err.println(message);
+            }
+        });
+        return factory;
+    }
+
+    public StAXHelper() {
+        super();
+    }
+
+}
\ No newline at end of file

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StAXHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,532 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.helper;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+
+import javanet.staxutils.BaseXMLInputFactory;
+import javanet.staxutils.BaseXMLOutputFactory;
+import javanet.staxutils.events.EventFactory;
+import javanet.staxutils.events.ProcessingInstructionEvent;
+import javanet.staxutils.io.XMLWriterUtils;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.ProcessingInstruction;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+import javax.xml.stream.util.XMLEventAllocator;
+import javax.xml.transform.TransformerConfigurationException;
+
+import org.apache.forrest.dispatcher.api.Contract;
+import org.apache.forrest.dispatcher.impl.DefaultContract;
+import org.apache.forrest.dispatcher.utils.CommonString;
+
+import com.bea.xml.stream.XMLEventAllocatorBase;
+
+public class StructurerHelperStAX {
+
+    public static final String NS = "http://apache.org/forrest/templates/1.0";
+
+    public static final String STRUCTUR_ELEMENT = "structur";
+
+    public static final String STRUCTURER_ELEMENT = "structurer";
+
+    public static final String STRUCTURER_TYPE_ATT = "type";
+
+    public static final String STRUCTURER_HOOKS_ATT = "hooksXpath";
+
+    public static final String CONTRACT_ELEMENT = "contract";
+
+    public static final String CONTRACT_NAME_ATT = "name";
+
+    public static final String CONTRACT_DATA_ATT = "dataURI";
+
+    public static final String PROPERTY_ELEMENT = "property";
+
+    public static final String HOOK_ELEMENT = "template";
+
+    public static final String PROPERTY_NAME_ATT = CONTRACT_NAME_ATT;
+
+    private String structurerResult;
+
+    private String structurerId;
+
+    private XMLInputFactory inputFactory = BaseXMLInputFactory.newInstance();
+
+    private XMLOutputFactory outputFactory = BaseXMLOutputFactory.newInstance();
+
+    private static DispatcherPropertiesHelper propertiesHelper;
+
+    private String currentPath = "";
+
+    private LinkedHashMap<String, LinkedHashSet> resultTree = new LinkedHashMap<String, LinkedHashSet>();
+
+    private XMLEventFactory eventFactory = EventFactory.newInstance();
+
+    private XMLEventAllocator allocator;
+
+    private String home;
+
+    public StructurerHelperStAX(String home) {
+        propertiesHelper = new DispatcherPropertiesHelper(home);
+        this.home=home;
+    }
+
+    public File execute(String sourceUrl, String type) throws IOException,
+            FactoryConfigurationError, XMLStreamException, InstantiationException,
+            IllegalAccessException, TransformerConfigurationException {
+        // setting up the files
+        structurerId = sourceUrl.replace(propertiesHelper.getStructurerRep(), "");
+        structurerId = structurerId.replace(propertiesHelper.getStructurerSuffix(),
+                "");
+        structurerResult = propertiesHelper.getCacheStructure() + structurerId
+                + "." + type;
+        File cache = new File(structurerResult), structurerFile = new File(
+                sourceUrl);
+        // caching is ATM implemetent by writing the template to disk
+        boolean useCache = false;
+        // if no file exist, create it
+        if (!cache.isFile()) {
+            try {
+                cache.createNewFile();
+            } catch (Exception e) {
+                // if we cannot create a file that means that the parent path
+                // does not exists
+                File path = new File(cache.getParent());
+                path.mkdirs();
+                cache.createNewFile();
+            }
+        } else {
+            // compare the url and the file
+            long modifiedCache = cache.lastModified();
+            long modifiedContract = structurerFile.lastModified();
+            if (modifiedCache > modifiedContract)
+                useCache = true;
+        }
+        // FIXME activate if stable
+        // if (!useCache) {
+        URL structurerUrl;
+        if (sourceUrl.indexOf(":/") > -1)
+            structurerUrl = new URL(sourceUrl);
+        else
+            structurerUrl = new URL("file://" + sourceUrl);
+        InputStream in = structurerUrl.openStream();
+        inputFactory.setEventAllocator(new XMLEventAllocatorBase());
+        allocator = inputFactory.getEventAllocator();
+        XMLStreamReader parser = inputFactory.createXMLStreamReader(in);
+        // Create the output factory
+
+        // Create XML event writer
+        // Write the result to disk
+        Writer result = new FileWriter(structurerResult);
+        XMLEventWriter writer = outputFactory.createXMLEventWriter(result);
+        processStructur(type, parser, writer);
+        // }
+        return cache;
+    }
+
+    private void processStructur(String type, XMLStreamReader parser,
+            XMLEventWriter writer) throws XMLStreamException, IOException,
+            FactoryConfigurationError, InstantiationException,
+            IllegalAccessException, TransformerConfigurationException {
+        while (true) {
+            int event = parser.next();
+            switch (event) {
+            case XMLStreamConstants.END_DOCUMENT:
+                writer.flush();
+                parser.close();
+                return;
+
+            case XMLStreamConstants.START_ELEMENT:
+                if (parser.getLocalName().equals(STRUCTURER_ELEMENT)) {
+                    System.out.println(STRUCTURER_ELEMENT + " " + structurerId);
+                    System.out.println("*********** START ****************");
+                    String m_type = "", path = "";
+                    // Get attribute names
+                    for (int i = 0; i < parser.getAttributeCount(); i++) {
+                        String localName = parser.getAttributeLocalName(i);
+                        if (localName.equals(STRUCTURER_TYPE_ATT)) {
+                            // Return value
+                            m_type = parser.getAttributeValue(i);
+                        } else if (localName.equals(STRUCTURER_HOOKS_ATT)) {
+                            path = parser.getAttributeValue(i);
+                        }
+                    }
+                    if (m_type.equals(type)) {
+                        System.out.println("matched - need to process");
+                        // adding the default path
+                        if (!"/".equals(String.valueOf(path.charAt(0)))) {
+                            path = "/" + path;
+                        }
+                        currentPath = path;
+                        processStructurer(parser, writer, type);
+                    } else {
+                        System.out.println("no-matched");
+                    }
+                }
+                break;
+
+            default:
+                break;
+            }
+
+        }
+
+    }
+
+    private void processStructurer(XMLStreamReader parser, XMLEventWriter writer,
+            String type) throws XMLStreamException, IOException,
+            FactoryConfigurationError, InstantiationException,
+            IllegalAccessException, TransformerConfigurationException {
+
+        // start processing
+        while (true) {
+            int event = parser.next();
+            switch (event) {
+
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals(STRUCTURER_ELEMENT)) {
+                    System.out
+                            .println("************ STRUCTURER_ELEMENT END ***************");
+                    // setting up the document
+                    System.out.println("Preparing the result object.");
+                    writer.add(eventFactory.createStartDocument("UTF-8", "1.0"));
+                    // we have now a resultTree setup
+                    System.out.println("we have now a resultTree setup: "
+                            + resultTree.size());
+                    Iterator<String> iterator = resultTree.keySet().iterator();
+                    String[] paths = resultTree.keySet().toArray(new String[1]);
+                    String rootPath = CommonString.common(paths);
+                    System.out.println("setting up root path");
+                    String[] tokenizer = rootPath.split("/");
+                    openPaths(writer, tokenizer);
+                    // here goes the contract/hook stuff
+                    // the idea is to decode the contracts and hooks from the hashmap
+                    // and process it here.
+                    System.out
+                            .println(" here goes the contract/hook stuff the idea is to store the contracts and hooks in a hashmap and process it here.");
+                    while (iterator.hasNext()) {
+                        String element = iterator.next();
+                        final String replaceFirst = element.replaceFirst(rootPath,
+                                "");
+                        System.out.println(replaceFirst);
+                        System.out
+                        .println("Now we need to look up the object and process it.");
+                        final String[] split = replaceFirst.split("/");
+                        if (split.length > 1) {
+                            System.out.println("replaceFirst.split(\"/\").length:  "+split.length);
+                            openPaths(writer, split);
+                            injectResult(writer, element);
+                            closingPaths(writer, split);
+                        } else {
+                            StartElement start = eventFactory.createStartElement(
+                                    "", "", replaceFirst);
+                            writer.add((XMLEvent) start);
+                            
+                            injectResult(writer, element);
+                            EndElement end = eventFactory.createEndElement("", "",
+                                    replaceFirst);
+                            writer.add((XMLEvent) end);
+                        }
+
+                    }
+                    closingPaths(writer, tokenizer);
+                    writer.add(eventFactory.createEndDocument());
+                    resultTree.clear();
+                    return;
+                } else
+                    System.out.println("end-name " + parser.getLocalName());
+                break;
+
+            case XMLStreamConstants.START_ELEMENT:
+                String localName=parser.getLocalName();
+                System.out
+                        .println("Here we need to check for hooks or contract and delegate the processing");
+                if (localName.equals(CONTRACT_ELEMENT)) {
+                   // currentPath += "/" + localName;
+                    System.out.println("CONTRACT " + localName);
+                    System.out.println("Path " + currentPath);
+                    processContract(parser, writer, allocator);
+                 //   currentPath = currentPath.substring(0, currentPath.lastIndexOf("/" + localName));
+                } else if (localName.equals(HOOK_ELEMENT)) {
+                    System.out.println("HOOKS " + localName);
+                    System.out.println("NOT IMPLEMENTED");
+                }
+                break;
+
+            default:
+                // writer.add(allocator.allocate(parser));
+                break;
+            }
+
+        }
+    }
+
+    private void openPaths(XMLEventWriter writer, String[] tokenizer) throws XMLStreamException {
+        for (int i = 0; i < tokenizer.length; i++) {
+            if (!tokenizer[i].equals("")) {
+                StartElement value = eventFactory.createStartElement(
+                        "", "", tokenizer[i]);
+                writer.add((XMLEvent) value);
+            }
+        }
+    }
+
+    private void closingPaths(XMLEventWriter writer, String[] tokenizer) throws XMLStreamException {
+        // closing the initial paths again
+        for (int j = tokenizer.length - 1; j >= 0; j--) {
+            if (!tokenizer[j].equals("")) {
+                EndElement value = eventFactory.createEndElement("",
+                        "", tokenizer[j]);
+                writer.add((XMLEvent) value);
+            }
+        }
+    }
+
+    private void injectResult(XMLEventWriter writer, String element) throws XMLStreamException {
+        LinkedHashSet<XMLEvent> part=resultTree.get(element);
+        Object[] partResult = part.toArray();
+        for (int i = 0; i < partResult.length; i++) {
+            writer.add((XMLEvent) partResult[i]);
+        }
+    }
+
+    private void processContract(XMLStreamReader parser, XMLEventWriter writer,
+            XMLEventAllocator allocator) throws XMLStreamException, IOException,
+            FactoryConfigurationError, InstantiationException,
+            IllegalAccessException, TransformerConfigurationException {
+        String name = "", data = "";
+        // Get attribute names
+        for (int i = 0; i < parser.getAttributeCount(); i++) {
+            String localName = parser.getAttributeLocalName(i);
+            if (localName.equals(CONTRACT_NAME_ATT)) {
+                // Return value
+                name = parser.getAttributeValue(i);
+            } else if (localName.equals(CONTRACT_DATA_ATT)) {
+                data = parser.getAttributeValue(i);
+            }
+        }
+
+        // Where we want to save the resulting contract after transformation
+        String destination = propertiesHelper.getCacheContracts() + name + "/"
+                + structurerId + ".xpath.xml";
+        String source = propertiesHelper.getContractRep() + name
+                + propertiesHelper.getContractSuffix();
+        String cachedTemplate = propertiesHelper.getCacheContracts() + name
+                + propertiesHelper.getContractSuffix() + ".xsl";
+        Contract contract = new DefaultContract(home);
+        contract.initialize(source, cachedTemplate);
+        HashMap<String, File> param = new HashMap<String, File>();
+        while (true) {
+            int event = parser.next();
+            switch (event) {
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals(CONTRACT_ELEMENT)) {
+                    System.out
+                            .println("here we need to execude the transformation");
+                    System.out.println("data "+data+" destination "+ destination);
+                    processContractResult(data, destination, contract, param);
+                    System.out.println("************ END CONTRACT ***************");
+                    // FROM HERE
+                    return;
+                }
+
+                break;
+
+            case XMLStreamConstants.START_ELEMENT:
+                if (parser.getLocalName().equals(PROPERTY_ELEMENT)) {
+                    processProperty(parser, param, name);
+                }
+                break;
+
+            default:
+                break;
+            }
+        }
+
+    }
+
+    private void processContractResult(String data, String destination,
+            Contract contract, HashMap<String, File> param)
+            throws XMLStreamException, FileNotFoundException {
+        File contractResult = contract.execute(data, param, destination);
+        LinkedHashSet<XMLEvent> pathElement;
+        XMLStreamReader contractResultReader = inputFactory
+                .createXMLStreamReader(new FileReader(contractResult));
+        // Main event loop
+        while (true) {
+            int resultEvent = contractResultReader.next();
+            switch (resultEvent) {
+            case XMLStreamConstants.START_ELEMENT:
+                if (contractResultReader.getLocalName().equals("part")) {
+                    String xpath = "", injectionPoint = "";
+                    // Get attribute names
+                    for (int i = 0; i < contractResultReader.getAttributeCount(); i++) {
+                        String localName = contractResultReader
+                                .getAttributeLocalName(i);
+                        if (localName.equals(ContractHelperStAX.RESULT_XPATH)) {
+                            // Return value
+                            xpath = contractResultReader.getAttributeValue(i);
+                        }
+                    }
+                    if (xpath.equals("")) {
+                        // iterate through the children and add them
+                        // to the pathElement
+                        if (resultTree.containsKey(currentPath))
+                            pathElement = resultTree.get(currentPath);
+                        else
+                            pathElement = new LinkedHashSet<XMLEvent>();
+                        injectionPoint = currentPath;
+                        inject(pathElement, contractResultReader, injectionPoint);
+                        // as soon as you find the end element add
+                        // it back to the resultTree
+                    } else {
+                        // iterate through the children and add them
+                        // to the xpath defined
+                        if (resultTree.containsKey(xpath))
+                            pathElement = resultTree.get(xpath);
+                        else
+                            pathElement = new LinkedHashSet<XMLEvent>();
+                        injectionPoint = xpath;
+                        inject(pathElement, contractResultReader, injectionPoint);
+                    }
+                }
+                break;
+            case XMLStreamConstants.END_DOCUMENT:
+                return;
+            default:
+                break;
+            }
+        }
+    }
+
+    private void inject(LinkedHashSet<XMLEvent> pathElement,
+            XMLStreamReader parser, String injectionPoint)
+            throws XMLStreamException {
+        System.out.println("injectionPoint " + injectionPoint);
+        while (true) {
+            int event = parser.next();
+            XMLEvent currentEvent = allocator.allocate(parser);
+            switch (event) {
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals("part")) {
+                    System.out.println("Trying to add to hash " + injectionPoint);
+                    resultTree.put(injectionPoint, pathElement);
+                   /* System.out.println("resultTree.size() " + resultTree.size());
+                    Iterator<String> iterator = resultTree.keySet().iterator();
+                    while (iterator.hasNext()) {
+                        System.out.println("key " + iterator.next());
+
+                    }*/
+                    return;
+                } else {
+                    pathElement.add(currentEvent);
+                    break;
+                }
+            default:
+                pathElement.add(currentEvent);
+                break;
+            }
+        }
+    }
+
+    private void processProperty(XMLStreamReader parser,
+            HashMap<String, File> transformer, String contractName)
+            throws XMLStreamException {
+        XMLEventWriter writerProperty = null;
+        XMLEvent currentEvent = allocator.allocate(parser);
+        String propertyName = null;
+        // Get attribute names
+        for (int i = 0; i < parser.getAttributeCount(); i++) {
+            String localName = parser.getAttributeLocalName(i);
+            if (localName.equals(PROPERTY_NAME_ATT)) {
+                // Return value
+                propertyName = parser.getAttributeValue(i);
+            }
+        }
+        // Write the result to disk
+        File cache = new File(propertiesHelper.getCacheStructure() + structurerId
+                + "/" + contractName + ".xpath.property." + propertyName + ".xml");
+        if (!cache.isFile()) {
+            try {
+                cache.createNewFile();
+            } catch (IOException e) {
+                // if we cannot create a file that means that the parent path
+                // does not exists
+                File path = new File(cache.getParent());
+                path.mkdirs();
+                try {
+                    cache.createNewFile();
+                } catch (IOException e1) {
+                    throw new XMLStreamException("IOException: "+e.getMessage());
+                }
+            }
+        }
+        Writer result = null;
+        try {
+            result = new FileWriter(cache.getAbsoluteFile());
+            ProcessingInstruction procInst = new ProcessingInstructionEvent("xml",
+                    "version=\"1.0\" encoding=\"UTF-8\"");
+            XMLWriterUtils.writeProcessingInstruction(procInst, result);
+        } catch (IOException e) {
+            throw new XMLStreamException("IOException: "+e.getMessage());
+        }
+        writerProperty = outputFactory.createXMLEventWriter(result);
+        writerProperty.add(currentEvent);
+        while (true) {
+            int event = parser.next();
+            currentEvent = allocator.allocate(parser);
+            switch (event) {
+
+            case XMLStreamConstants.END_ELEMENT:
+                if (parser.getLocalName().equals(PROPERTY_ELEMENT)) {
+                    writerProperty.add(currentEvent);
+                    writerProperty.flush();
+                    transformer.put(propertyName, cache);
+                    return;
+                } else {
+                    writerProperty.add(currentEvent);
+                    break;
+                }
+
+            default:
+                writerProperty.add(currentEvent);
+                break;
+            }
+        }
+    }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/helper/StructurerHelperStAX.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.impl;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.apache.forrest.dispatcher.api.Contract;
+import org.apache.forrest.dispatcher.helper.ContractHelperStAX;
+
+/**
+ * @author thorsten
+ * 
+ */
+public class DefaultContract implements Contract {
+
+    private String name, usage, description;
+    private File template;
+    private ContractHelperStAX helper;
+
+    public DefaultContract(String home) {
+        helper = new ContractHelperStAX(home);
+    }
+
+    public File execute(String dataUrl, HashMap param,String destination) {
+        File cachedContract = null;
+        try {
+            cachedContract = helper.execute(dataUrl, param, destination,template);
+        } catch (Exception e1) {
+            e1.printStackTrace();
+        }
+
+        return cachedContract;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getUsage() {
+        return usage;
+    }
+
+    public void setUsage(String usage) {
+        this.usage = usage;
+    }
+
+    public File getTemplate() {
+        return template;
+    }
+
+    public void initialize(String sourceUrl, String destination) {
+        try {
+            this.template = helper.getTemplate(sourceUrl,destination);
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/DefaultContract.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java?view=auto&rev=499193
==============================================================================
--- forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java (added)
+++ forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java Tue Jan 23 16:25:33 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.dispatcher.utils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+public class CommonString {
+
+    /**
+     * @param args
+     */
+    public static String common(String[] args) {
+        List<String> list = Arrays.asList(args);
+        Collections.sort(list, STRING_LENGTH_ORDER);
+        int length = list.size(), i = 0;
+        String common = "";
+        System.out.println("length: " + length);
+        for (Iterator<String> iter = list.iterator(); i < length;) {
+            i = i + 1;
+            String path = iter.next();
+            if (i == 1) {
+                common = path;
+            } else {
+                common = common(common, path);
+            }
+            System.out.println("common: " + common + "\npath: " + path + "\ni: "
+                    + i);
+        }
+        return common;
+    }
+
+    public static final Comparator<String> STRING_LENGTH_ORDER = new StringLengthComparator();
+
+    private static class StringLengthComparator implements Comparator<String>,
+            java.io.Serializable {
+
+        private static final long serialVersionUID = -1967432089082711940L;
+
+        public int compare(String s1, String s2) {
+            int n1 = s1.length(), n2 = s2.length();
+            return n1 - n2;
+        }
+    }
+
+    public static String common(String s1, String s2) {
+        StringBuffer common = new StringBuffer();
+        int n1 = s1.length(), n2 = s2.length();
+        for (int i1 = 0, i2 = 0; i1 < n1 && i2 < n2; i1++, i2++) {
+            char c1 = s1.charAt(i1);
+            char c2 = s2.charAt(i2);
+            if (c1 != c2) {
+                c1 = Character.toUpperCase(c1);
+                c2 = Character.toUpperCase(c2);
+                if (c1 != c2) {
+                    c1 = Character.toLowerCase(c1);
+                    c2 = Character.toLowerCase(c2);
+                    if (c1 != c2) {
+                        return new String(common);
+                    } else {
+                        common.append(c1);
+                    }
+                } else {
+                    common.append(c1);
+                }
+            } else {
+                common.append(c1);
+            }
+        }
+        return new String(common);
+    }
+}

Propchange: forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/utils/CommonString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: forrest/trunk/whiteboard/dispatcher/lib/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 23 16:25:33 2007
@@ -0,0 +1 @@
+api

Added: forrest/trunk/whiteboard/dispatcher/lib/commons-lang-2.1.jar
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/lib/commons-lang-2.1.jar?view=auto&rev=499193
==============================================================================
Binary file - no diff available.

Propchange: forrest/trunk/whiteboard/dispatcher/lib/commons-lang-2.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream