home | news | documentation | downloads | discussion | projects | license  

 
Documentation
 
Overview
Why Clearsilver?
Clearsilver Basics
   HDF Dataset
   Template Syntax
      Expressions
      Macros
      Functions
   CGI Kit
      Config Vars
   FAQ
API Reference
   Concepts
   C API
   Python API
      Introduction
   Perl API
   Java API
Tools
   odb.py

Comparison with PHP, ASP, JSP
Comparison with XML/XSLT


 

    

ClearSilver Java Documentation

Read the concepts first.

Because the Java module is designed to fit well into a Java Servlet environment, it does not utilize the form processing and http handling of the Clearsilver CGI Kit. However, an emulation of the useful Clearsilver CGI Kit behavior, such as populating environment and form data into the HDF dataset, is provided as an extension to HttpServlet called CSPage.

org.clearsilver.HDF

HDF()

This creates a new HDF dataset object.

void close()

Cleans up the underlying HDF JNI non-managed memory. This call is ignored on non-root nodes. Java's GC doesn't understand how much memory is being held by the HDF wrapper, and its destruction can be delayed. In a high-load server, that can lead to a lot of memory waiting around to be re-claimed. Calling this method will free that memory immediately.

void readFile(String filename)

This method reads the contends of an on-disk HDF dataset into the current HDF object.

String fileLoad(String filename)

A protected method used as a callback from the JNI code to enable file load wrappers to be written in Java.

CSFileLoader getFileLoader()

Returns the current CSFileLoader

void setFileLoader(CSFileLoader)

Sets the file loader for the HDF to use to load files

boolean writeFile(String filename)

writes/serializes HDF dataset to file

boolean writeFileAtomic(String filename)

like writeFile, but first writes to a temp file then uses rename(2) to ensure updates are Atomic

boolean readString(String data)

parses/loads the contents of the given string as HDF into the current HDF object

String writeString()

serializes HDF contents to a string

int getIntValue(String hdfpath, int defaultValue)

This method retrieves an integer value from the HDF dataset. The hdfpath is a dotted path of the form "A.B.C".

String getValue(String hdfpath, String defaultValue)

This method retrieves a string value from the HDF dataset. The hdfpath is a dotted path of the form "A.B.C".

void setValue(String hdfpath, String newValue)

This method adds a string value to the HDF dataset.

void removeTree(String hdfpath)

Remove all nodes of the HDF subtree at hdfpath

void setSymLink(String hdfpathSrc, hdfpathDest)

Links the src hdfpath to the dest

void exportDate(String hdfpath, TimeZone timeZone, Date date)

Export date to an HDF tree using the specified timeZone. Matches the output of the C CGIKit's export_date* functions. Output is:
hdfpath.sec
hdfpath.min
hdfpath.24hour
hdfpath.hour
hdfpath.am
hdfpath.mday
hdfpath.mon
hdfpath.year
hdfpath.2yr
hdfpath.wday
hdfpath.tzoffset

void exportDate(String hdfpath, String tz, int tt)

Same as above exportDate but with a string representation of TimeZone, and a time_t as the Date (seconds since the epoch)

HDF getObj(String hdfpath)

This method allows you to retrieve the HDF object which represents the HDF subtree ad the named hdfpath.

HDF getChild(String hdfpath)

Retrieves the HDF for the first child of the root of the subtree at hdfpath, or null if no child exists of that path or if the path doesn't exist.

HDF getRootObj()

Return the root of the tree that this node is in.

HDF getOrCreateObj(String hdfpath)

Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist

String objName()

This method retrieves the name of the current HDF node. The name only includes the current level. Here is a sample code snippit:
  HDF hdf = new HDF();
  hdf.setValue("A.B.C","1");
  HDF hdf_subnode = hdf.getObj("A.B.C");

  // this will print "C"
  System.out.println(hdf_subnode.objName());

String objValue()

This method retrieves the value of the current HDF node. Here is a sample code snippit:
  HDF hdf = new HDF();
  hdf.setValue("A.B.C","1");
  HDF hdf_subnode = hdf.getObj("A.B.C");

  // this will print "1"
  System.out.println(hdf_subnode.objValue());

HDF objChild()

This method is used to walk the HDF tree. Keep in mind that every node in the tree can have a value, a child, and a next peer.

HDF objNext()

This method is used to walk the HDF tree to the next peer.

void copy(String hdfpath, HDF src)

Copy the HDF tree src to the destination path hdfpath in this HDF tree. src may be in this path or not. Result is undefined for overlapping source and destination.

String dump()

Serializes the HDF tree to a String in a slightly different format than writeString().

org.clearsilver.CS

CS(HDF dataset)

This method creates a new ClearSilver template rendering context. You should have already created and populated an HDF dataset which you provide as the only argument to the constructor.

CS(HDF dataset, HDF globalDataset)

Similar to CS(HDF), this takes a separate "global" dataset which is checked by CS evaluation for any "missing" HDF nodes in the local dataset.

void setGlobalHDF(HDF global)

Updates the global HDF for this CS object

HDF getGlobalHDF()

returns the global HDF for this CS object

void close()

Releases all of the unmanaged JNI memory used by this object. The object can't be used after this is called.

void parseStr(String template_fragment)

This method parses the provided string template fragment into the parse tree.

void parseFile(String filename)

This method parses the provided template file into the parse tree.

String render()

This method evaluates the parse tree and produces the rendered output as a string.

String fileLoad(String filename)

Used to load the file requested in parseFile or include directives. Allows for fileLoading to be overridden in Java.

CSFileLoader getFileLoader()

Returns current file loader

void setFileLoader(CSFileLoader fileLoader)

Sets the file loader to use. If null, uses the default C file loader.

 
Copyright © 2009 Brandon Long, All rights reserved.