BrightSide Workbench Full Report + Source Code
elephant/impl/abstracts/AbstractAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.abstracts;
19 
20 import java.sql.Timestamp;
21 import java.util.Date;
22 import org.turro.string.ObjectString;
23 import org.turro.elephant.context.IAction;
24 import org.turro.elephant.context.IConstructor;
25 
30 public abstract class AbstractAction implements IAction {
32 
34  public AbstractAction() {
35  }
36 
37  @Override
39  this.constructor = constructor;
40  }
41 
43  return constructor;
44  }
45 
46  @Override
47  public abstract int execute() throws Exception;
48 
49  public String getContextParameter() {
51  }
52 
53  public String getIdelParameter() {
55  }
56 
57  public String getActionParameter() {
59  }
60 
61  @Override
62  public String getParameter(String param) {
63  return getParameter(param, false);
64  }
65 
66  public String getParameter(String param, boolean encode) {
67  return constructor.getParameter(param, encode);
68  }
69 
70  public String getStringParameter(String param) {
71  String value = getParameter(param);
72  if(value == null) return "";
73  return value;
74  }
75 
76  public String getValueParameter(String param) {
77  return getValuePortion(null, getParameter(param));
78  }
79 
80  public boolean getBooleanParameter(String param) {
81  return "true".equals(getParameter(param));
82  }
83 
84  public int getIntParameter(String param, int defaultValue) {
85  Integer i = (Integer) ObjectString.parseNativeString(getParameter(param), Integer.class, false);
86  if(i == null) {
87  return defaultValue;
88  }
89  else {
90  return i.intValue();
91  }
92  }
93 
94  public double getDoubleParameter(String param, double defaultValue) {
95  Double d = (Double) ObjectString.parseNativeString(getParameter(param), Double.class, false);
96  if(d == null) {
97  return defaultValue;
98  }
99  else {
100  return d.doubleValue();
101  }
102  }
103 
104  public Date getDateParameter(String param, Date defaultValue) {
105  Date d = (Date) ObjectString.parseString(getParameter(param), ObjectString.COMPRESSED_DATE_PATTERN, Date.class, false);
106  if(d == null) {
107  return defaultValue;
108  }
109  else {
110  return d;
111  }
112  }
113 
114  public static String makeDateParameter(Date date) {
115  return ObjectString.formatObject(date, ObjectString.COMPRESSED_DATE_PATTERN, false);
116  }
117 
118  public static String makeDateParameter(Timestamp date) {
119  return makeDateParameter((Date)date);
120  }
121 
122  public static String getValuePortion(String key, String value) {
123  if(value != null && value.indexOf(":") > -1) {
124  String parts[] = value.split("\\:");
125  if(key == null || key.equals(parts[0])) {
126  return parts[1];
127  }
128  }
129  return value;
130  }
131 
132 }