Statistics
| Revision:

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

History | View | Annotate | Download (3.71 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 ToDate extends AbstractOperator{
40

    
41
        public String addText(String s) {
42
                return toString()+"("+s+")";
43
        }
44
        public String toString() {
45
                return "toDate";
46
        }
47
        public void eval(BSFManager interpreter) throws BSFException {
48
//                interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"java.util.Date toDate(String value){return new java.text.SimpleDateFormat().parse(value);};");
49
                interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,
50
                                "import java.text.DateFormat as DateFormat\n" +
51
                                "import java.text.SimpleDateFormat as SimpleDateFormat\n" +
52
                                "dateFormat = DateFormat.getInstance()\n" +
53
                                "myDateFormat = SimpleDateFormat()\n" +
54
                                "def toDate(value, format=None):\n" +
55
                                "  if format != None:\n"+
56
                                "    myDateFormat.applyPattern(format)\n"+
57
                                "    return myDateFormat.parse(value)\n"+
58
                                "  return dateFormat.parse(value)");
59
        }
60
        public boolean isEnable() {
61
                return (getType()==IOperator.DATE);
62
        }
63

    
64
        public String getTooltip(){
65
                return PluginServices.getText(this,"operator")+":  "+toString()+"("+PluginServices.getText(this,"parameter")+"[,"+PluginServices.getText(this,"format")+"])"+"\n"+getDescription();
66
        }
67

    
68
        public String getDescription() {
69
                return PluginServices.getText(this, "parameter") + "1: " +
70
            PluginServices.getText(this, "string_value") + "\n" +
71
                PluginServices.getText(this, "format") + " ("+PluginServices.getText(this, "optional")+"): " +
72
            PluginServices.getText(this, "string_value") + "\n" +
73
            PluginServices.getText(this, "returns") + ": " +
74
            PluginServices.getText(this, "date_value") + "\n" +
75
            PluginServices.getText(this, "description") + ": " +
76
            "Returns a date object from string parameter formatted according to\nthe parameter format if it is supplied.\n\n"+
77
            "The format should follow the specifications of\n" +
78
            "'http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html'.\n\n"+
79
            "Examples: (for the date of December 23, 2008)\n"+
80
            "  'dd/MM/yy'  23/12/08\n"+
81
            "  'dd/MM/yyyy'  23/12/2008\n"+
82
            "  'dd/MMM/yyyy'  23/dec/2008\n"+
83
            "  'dd/MMMM/yyyy'  23/december/2008\n";
84

    
85
        }
86
}