Statistics
| Revision:

root / org.gvsig.expressionfield / trunk / org.gvsig.expressionfield / src / main / java / org / gvsig / expressionfield / project / documents / table / operators / SubString.java @ 24

History | View | Annotate | Download (3.34 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

    
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

    
35

    
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class SubString extends AbstractOperator{
40

    
41
        public String addText(String s) {
42
                return toString()+"("+s+",,)";
43
        }
44
        public String toString() {
45
                return "subString";
46
        }
47
        public void eval(BSFManager interpreter) throws BSFException {
48
//                interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"String subString(String value1,int value2,int value3){return value1.substring(value2,value3);};");
49
                interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def subString(value1,value2,value3):\n" +
50
                                "  return value1[value2:value3]");
51
        }
52
        public boolean isEnable() {
53
                return (getType()==IOperator.STRING);
54
        }
55
        public String getTooltip(){
56
                return PluginServices.getText(this,"operator")+":  "+toString()+"("+PluginServices.getText(this,"parameter")+"1,"+PluginServices.getText(this,"parameter")+"2, "+PluginServices.getText(this,"parameter")+"3"+")"+"\n"+getDescription();
57
        }
58
        public String getDescription() {
59
        return PluginServices.getText(this, "parameter") + "1"+": " +
60
        PluginServices.getText(this, "string_value") + "\n"+
61
        PluginServices.getText(this, "parameter") + "2"+": " +
62
        PluginServices.getText(this, "numeric_value") + "\n"+
63
        PluginServices.getText(this, "parameter") + "3"+": " +
64
        PluginServices.getText(this, "numeric_value") + "\n"+
65
        PluginServices.getText(this, "returns") + ": " +
66
        PluginServices.getText(this, "string_value") + "\n" +
67
        PluginServices.getText(this, "description") + ": " +
68
        "Returns a new string that is a substring of parameter1.\n" +
69
        "The substring begins at the specified parameter2 and extends to the character at index parameter3 - 1.\n" +
70
        "Thus the length of the substring is endIndex-beginIndex.";
71
    }
72
}