org.springframework.extensions.webscripts
Class ScriptProcessorRegistry

java.lang.Object
  extended by org.springframework.extensions.webscripts.ScriptProcessorRegistry

public class ScriptProcessorRegistry
extends Object

Registry of Script Processors If no processors are registered, the default script processor is the javascript processor.

Author:
muzquiano

Constructor Summary
ScriptProcessorRegistry()
           
 
Method Summary
 String findValidScriptPath(String path)
          Returns a variation on the provided path that exists and is processable by one of the processors in this registry.
protected  ScriptProcessor getDefaultScriptProcessor()
          Gets the default script processor.
 String getExtensionForProcessor(ScriptProcessor scriptProcessor)
          Gets the extension for given processor.
 String[] getRegisteredExtensions()
          Returns the extensions with registered processors
 ScriptProcessor getScriptProcessor(ScriptContent scriptContent)
          Returns the best fit script processor for the given script content object.
 ScriptProcessor getScriptProcessor(String path)
          Returns the script processor that matches the file extension for the given path.
 ScriptProcessor getScriptProcessorByExtension(String extension)
          Gets the script processor registered for the given extension
 void registerScriptProcessor(ScriptProcessor scriptProcessor)
          Registers a script processor
 void registerScriptProcessor(ScriptProcessor scriptProcessor, String extension, String name)
          Registers a script processor
 void reset()
          Resets all of the registered script processors
 void setDefaultScriptProcessor(String defaultScriptProcessorName)
          Sets the name of the default script processor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptProcessorRegistry

public ScriptProcessorRegistry()
Method Detail

setDefaultScriptProcessor

public void setDefaultScriptProcessor(String defaultScriptProcessorName)
Sets the name of the default script processor

Parameters:
defaultScriptProcessor - the name of the default script processor

registerScriptProcessor

public void registerScriptProcessor(ScriptProcessor scriptProcessor)
Registers a script processor

Parameters:
scriptProcessor - the script processor to register

registerScriptProcessor

public void registerScriptProcessor(ScriptProcessor scriptProcessor,
                                    String extension,
                                    String name)
Registers a script processor

Parameters:
scriptProcessor - the script processor to register
extension -
name -

getDefaultScriptProcessor

protected ScriptProcessor getDefaultScriptProcessor()
Gets the default script processor.

Returns:
the default script processor

getScriptProcessor

public ScriptProcessor getScriptProcessor(String path)
Returns the script processor that matches the file extension for the given path. If a script processor cannot be matched to the path, the default script processor will be returned.

Parameters:
path - the path
Returns:
the script processor

getScriptProcessor

public ScriptProcessor getScriptProcessor(ScriptContent scriptContent)
Returns the best fit script processor for the given script content object. If a script processor cannot be matched, the default script processor will be returned.

Parameters:
path - the path
Returns:
the script processor

getScriptProcessorByExtension

public ScriptProcessor getScriptProcessorByExtension(String extension)
Gets the script processor registered for the given extension

Parameters:
extension - the extension
Returns:
the script processor by extension or null if no match

findValidScriptPath

public String findValidScriptPath(String path)
Returns a variation on the provided path that exists and is processable by one of the processors in this registry. First attempts to find a script processor that contains the content located at the given path (using extension information, if available). If no match is found, iterates over the file extensions and attempts to find a match. Path can therefore be values like: testfile.js - matches to file testfile.js using javascript procesor testfile - matches for all extensions, potentially looking at testfile.js, testfile.groovy, etc. The extension annotated path is returned which will correctly dispatch to the discovered processor.

Parameters:
path - the path
Returns:
a valid processor file path or null if no match

getRegisteredExtensions

public String[] getRegisteredExtensions()
Returns the extensions with registered processors

Returns:
the registered extensions

getExtensionForProcessor

public String getExtensionForProcessor(ScriptProcessor scriptProcessor)
Gets the extension for given processor.

Parameters:
scriptProcessor - the script processor
Returns:
the extension for processor

reset

public void reset()
Resets all of the registered script processors



Copyright © 2009 SpringSource, Inc. All Rights Reserved.