ro.isdc.wro.extensions.processor.js
Class NodeTypeScriptProcessor

java.lang.Object
  extended by ro.isdc.wro.extensions.processor.js.NodeTypeScriptProcessor
All Implemented Interfaces:
ResourcePostProcessor, ResourcePreProcessor, SupportAware

@SupportedResourceType(value=JS)
public class NodeTypeScriptProcessor
extends Object
implements ResourcePreProcessor, ResourcePostProcessor, SupportAware

Important node: this processor is not cross platform and has some pre-requesites in order to work.

Installation instructions: Install the typescript node package module (Unix OS)

    npm install -g typescript
 
It is possible to test whether the tsc utility is available using isSupported()

Since:
1.5.0
Author:
Alex Objelean

Field Summary
static String ALIAS
           
 
Constructor Summary
NodeTypeScriptProcessor()
           
 
Method Summary
protected  String[] getCommandLine(String filePath, String outFilePath)
          Creates the platform specific arguments to run the tsc shell utility.
 boolean isSupported()
           
protected  void onException(Exception e, String content)
          Invoked when a processing exception occurs.
 void process(Reader reader, Writer writer)
          Perform actual resource processing.
 void process(Resource resource, Reader reader, Writer writer)
          Process a content supplied by a reader and perform some sort of processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIAS

public static final String ALIAS
See Also:
Constant Field Values
Constructor Detail

NodeTypeScriptProcessor

public NodeTypeScriptProcessor()
Method Detail

process

public void process(Resource resource,
                    Reader reader,
                    Writer writer)
             throws IOException
Process a content supplied by a reader and perform some sort of processing. It is important to know that you should use reader for processing instead of trying to access the resource original content using Resource, because this way you can ignore the other preProcessors from the chain.
It is not require to explicitly handle exception. When the processing fails, the following can happen:
It is not required to close the reader and writers, because these will be closed for you.

Specified by:
process in interface ResourcePreProcessor
Parameters:
resource - the original resource as it found in the model.
reader - Reader used to read processed resource content.
writer - Writer where used to write processed results.
Throws:
IOException - when an exception occurs. The future version will change the exception type to Exception, because any exception may occur during processing. The processing failure will be handled based on value of WroConfiguration.isIgnoreFailingProcessor() configuration flag.

onException

protected void onException(Exception e,
                           String content)
Invoked when a processing exception occurs. Default implementation wraps the original exception into WroRuntimeException.

Parameters:
e - the Exception thrown during processing
content - the resource content being processed.

process

public void process(Reader reader,
                    Writer writer)
             throws IOException
Perform actual resource processing. The content to be processed is read from source Reader and is written to destination Writer. It is the client responsibility to close both: Reader and writer.

Specified by:
process in interface ResourcePostProcessor
Parameters:
reader - source stream.
writer - destination stream.
Throws:
IOException

isSupported

public boolean isSupported()
Specified by:
isSupported in interface SupportAware
Returns:
true if the processor is supported on this environment. The implementation check if the required shell utility is available.

getCommandLine

protected String[] getCommandLine(String filePath,
                                  String outFilePath)
Creates the platform specific arguments to run the tsc shell utility. Default implementation handles windows and unix platforms.

Returns:
arguments for command line. The implementation will take care of OS differences.


Copyright © 2008-2013. All Rights Reserved.