com.google.clearsilver.jsilver.functions
Class FunctionRegistry

java.lang.Object
  extended by com.google.clearsilver.jsilver.functions.FunctionRegistry
All Implemented Interfaces:
FunctionExecutor
Direct Known Subclasses:
CoreOperators

public class FunctionRegistry
extends Object
implements FunctionExecutor

Simple implementation of FunctionFinder that you can register your own functions with.

See Also:
FunctionExecutor

Field Summary
protected  Map<String,TextFilter> escapers
           
protected  Map<String,Function> functions
           
 
Constructor Summary
FunctionRegistry()
           
 
Method Summary
 void escape(String name, String input, Appendable output)
          Escapes some text.
 Value executeFunction(String name, Value... args)
          Lookup a function by name, execute it and return the results.
 boolean isEscapingFunction(String name)
          Look up a function by name, and report whether it is an escaping function.
 void registerEscapeMode(String name, TextFilter escaper)
          Registers an escaper, that is called when executing a <?cs escape ?> command.
 void registerFunction(String name, Function function)
          Register a Function with a given name.
 void registerFunction(String name, TextFilter textFilter)
          Register a TextFilter as a Function that takes a single String argument and returns the filtered value.
 void registerFunction(String name, TextFilter textFilter, boolean isEscaper)
           
protected  void setupDefaultFunctions()
          Subclasses can override this to register their own functions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

functions

protected Map<String,Function> functions

escapers

protected Map<String,TextFilter> escapers
Constructor Detail

FunctionRegistry

public FunctionRegistry()
Method Detail

executeFunction

public Value executeFunction(String name,
                             Value... args)
Description copied from interface: FunctionExecutor
Lookup a function by name, execute it and return the results.

Specified by:
executeFunction in interface FunctionExecutor

escape

public void escape(String name,
                   String input,
                   Appendable output)
            throws IOException
Description copied from interface: FunctionExecutor
Escapes some text.

Specified by:
escape in interface FunctionExecutor
Parameters:
name - Strategy for escaping text. If null or "none", text will be left as is.
input - Text to be escaped.
output - Where to write the result to.
Throws:
IOException

isEscapingFunction

public boolean isEscapingFunction(String name)
Description copied from interface: FunctionExecutor
Look up a function by name, and report whether it is an escaping function.

Specified by:
isEscapingFunction in interface FunctionExecutor

setupDefaultFunctions

protected void setupDefaultFunctions()
Subclasses can override this to register their own functions.


registerFunction

public void registerFunction(String name,
                             Function function)
Register a Function with a given name.


registerFunction

public void registerFunction(String name,
                             TextFilter textFilter)
Register a TextFilter as a Function that takes a single String argument and returns the filtered value.


registerFunction

public void registerFunction(String name,
                             TextFilter textFilter,
                             boolean isEscaper)

registerEscapeMode

public void registerEscapeMode(String name,
                               TextFilter escaper)
Registers an escaper, that is called when executing a <?cs escape ?> command.

Parameters:
name - The name with which <?cs escape ?> will invoke this escaper.
escaper - A TextFilter that implements the escaping functionality.


Copyright © 2010-2012 Google. All Rights Reserved.