首页 > 代码库 > ScriptTransformer

ScriptTransformer

ScriptTransformer可能由java支持的JavaScript语言或者其他脚本语言写成的转换器.只支持Java 6以上版本.

例1:

<dataConfig>    <script><![CDATA[                function f1(row)        {                    row.put(‘message‘, ‘Hello World!‘);                    return row;                }        ]]></script>    <document>        <entity name="e" pk="id" transformer="script:f1" query="select * from X">            ....        </entity>    </document></dataConfig>

例2:

<dataConfig>        <script><![CDATA[                function CategoryPieces(row)    {                    var pieces = row.get(‘category‘).split(‘/‘);                    var arr = new java.util.ArrayList();                    for (var i=0; i<pieces.length; i++) {                       arr.add(pieces[i]);                    }                    row.put(‘categorypieces‘, arr);                    row.remove(‘category‘);                    return row;                }        ]]></script>        <document>                <entity name="e" pk="id" transformer="script:CategoryPieces" query="select * from X">                ....                </entity>        </document></dataConfig>

例3:

<script><![CDATA[        id = 1;        function GenerateId(row) {            row.put(‘id‘, (id ++).toFixed());            return row;        }         function WipOffHtml(row) {            var file = row.get(‘file‘);            row.put(‘file‘,file.substr(0,file.indexOf(‘.‘)));            return row;        }                 ]]></script>

 

ScriptTransformer