Quick start

The jxp distribution

The jxp distribution contains the following files/directory:

- README - the readme file

- LICENSE - the license file

- /jars - the jxp and its dependencies jar files

- /scripts - simple batch file and shell script for invoking the jxp processor in the command line to run a script

- /src - jxp source code (if you download the source distribution)

Running jxp in command line

The batch file (jxp.bat) and shell script (jxp.sh*) in the jxp distribution allow you to test the jxp processor. It will run the simple script in samples/jxp-scripts to show some of the features of jxp scripts. You can run it by typing the command: jxp-1.0.0-beta2$ scripts/jxp.sh samples/jxp-scripts test.jxp You can refer to the scripts on how the JxpProcessor can be invoked directly using java interpreter on each platform. Arguably, jxp script can be used as a type of shell scripts if you like :>.



* you might need dos2unix to fix the shell script for unix system

Using the JxpProcessor in your source code

The following code section shows how to use the JxpProcessor in your program.

//first of all, declare a page source
FilePageSource pageSource = new FilePageSource("/home/joe/jxp");

//then declare a jxp context which encapsulate the processing environment for jxp (including the page source)
//optionally, you can also use JxpContext(JxpPageSource pageSource, Map defaultEnv) which will pass in a default
//environment that is will be available to all the pages you are processing using the context
JxpContext context = new JxpContext(pageSource);

//declare the processor and make it use the context
JxpProcessor processor = new JxpProcessor(context);

//now, you can start process pages
Writer writer = new OutputStreamWriter(System.output);
processor.process("test.jxp", writer); //this will process page "/home/joe/jxp/test.jxp"
writer.flush();

//you can also process another page with some given initial environment (which become variables in your page)
Map env = new HashMap();
env.put("ONE", new Integer(1));
//start processing
processor.process("/test2.jxp", writer, env); //you can refer "ONE" as a variable in your script
                

Using jxp as a web script processor

To configure the jxp as a web script processor, you need to add the following config in your web.xml (there's a sample web.xml in samples directory)

                
<servlet>
      <servlet-name>jxp-servlet</servlet-name>
      <servlet-class>org.onemind.jxp.servlet.JxpServlet</servlet-class>
</servlet>

<!-- The mapping for the webdav servlet -->
<servlet-mapping>
  <servlet-name>jxp-servlet</servlet-name>
  <url-pattern>*.jxp</url-pattern>
</servlet-mapping>
                    
Once this is set up, the file with *.jxp extension in your web context will be processed by the jxp processor.