svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extExpressionField / src / org / gvsig / expressionfield / project / documents / table / operators / ToDate.java @ 39133
History | View | Annotate | Download (2.55 KB)
1 |
package org.gvsig.expressionfield.project.documents.table.operators; |
---|---|
2 |
|
3 |
import org.apache.bsf.BSFException; |
4 |
import org.apache.bsf.BSFManager; |
5 |
import org.gvsig.andami.PluginServices; |
6 |
import org.gvsig.expressionfield.ExpressionFieldExtension; |
7 |
import org.gvsig.expressionfield.project.documents.table.AbstractOperator; |
8 |
import org.gvsig.expressionfield.project.documents.table.IOperator; |
9 |
|
10 |
|
11 |
/**
|
12 |
* @author Vicente Caballero Navarro
|
13 |
*/
|
14 |
public class ToDate extends AbstractOperator{ |
15 |
|
16 |
public String addText(String s) { |
17 |
return toString()+"("+s+")"; |
18 |
} |
19 |
public String toString() { |
20 |
return "toDate"; |
21 |
} |
22 |
public void eval(BSFManager interpreter) throws BSFException { |
23 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"java.util.Date toDate(String value){return new java.text.SimpleDateFormat().parse(value);};");
|
24 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1, |
25 |
"import java.text.DateFormat as DateFormat\n" +
|
26 |
"import java.text.SimpleDateFormat as SimpleDateFormat\n" +
|
27 |
"dateFormat = DateFormat.getInstance()\n" +
|
28 |
"myDateFormat = SimpleDateFormat()\n" +
|
29 |
"def toDate(value, format=None):\n" +
|
30 |
" if format != None:\n"+
|
31 |
" myDateFormat.applyPattern(format)\n"+
|
32 |
" return myDateFormat.parse(value)\n"+
|
33 |
" return dateFormat.parse(value)");
|
34 |
} |
35 |
public boolean isEnable() { |
36 |
return (getType()==IOperator.DATE);
|
37 |
} |
38 |
|
39 |
public String getTooltip(){ |
40 |
return PluginServices.getText(this,"operator")+": "+toString()+"("+PluginServices.getText(this,"parameter")+"[,"+PluginServices.getText(this,"format")+"])"+"\n"+getDescription(); |
41 |
} |
42 |
|
43 |
public String getDescription() { |
44 |
return PluginServices.getText(this, "parameter") + "1: " + |
45 |
PluginServices.getText(this, "string_value") + "\n" + |
46 |
PluginServices.getText(this, "format") + " ("+PluginServices.getText(this, "optional")+"): " + |
47 |
PluginServices.getText(this, "string_value") + "\n" + |
48 |
PluginServices.getText(this, "returns") + ": " + |
49 |
PluginServices.getText(this, "date_value") + "\n" + |
50 |
PluginServices.getText(this, "description") + ": " + |
51 |
"Returns a date object from string parameter formatted according to\nthe parameter format if it is supplied.\n\n"+
|
52 |
"The format should follow the specifications of\n" +
|
53 |
"'http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html'.\n\n"+
|
54 |
"Examples: (for the date of December 23, 2008)\n"+
|
55 |
" 'dd/MM/yy' 23/12/08\n"+
|
56 |
" 'dd/MM/yyyy' 23/12/2008\n"+
|
57 |
" 'dd/MMM/yyyy' 23/dec/2008\n"+
|
58 |
" 'dd/MMMM/yyyy' 23/december/2008\n";
|
59 |
|
60 |
} |
61 |
} |