details: /erp/devel/pi/rev/12b53f471269
changeset: 6703:12b53f471269
user: Adrián Romero <adrianromero <at> openbravo.com>
date: Sat Mar 13 09:17:34 2010 +0100
summary: Small improvements for SimpleCallout
diffstat:
src/org/openbravo/erpCommon/ad_callouts/SL_Project_Service.java | 22 +-
src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java | 385
++++++---
2 files changed, 261 insertions(+), 146 deletions(-)
diffs (truncated from 459 to 300 lines):
diff -r 00600b268925 -r 12b53f471269
src/org/openbravo/erpCommon/ad_callouts/SL_Project_Service.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Project_Service.java Sat Mar
13 10:31:41 2010 +0530
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Project_Service.java Sat Mar
13 09:17:34 2010 +0100
@@ -23,14 +23,16 @@
public class SL_Project_Service extends SimpleCallout {
- @Override
- protected void execute(CalloutInfo info) throws ServletException {
-
- BigDecimal serviceSerCost =
info.getBigDecimalParameter("inpservsercost");
- BigDecimal serviceOutCost =
info.getBigDecimalParameter("inpservoutcost");
-
- BigDecimal serviceTotalCost = serviceSerCost.add(serviceOutCost);
-
- info.addResult("inpservcost", serviceTotalCost);
- }
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void execute(CalloutInfo info) throws ServletException {
+
+ BigDecimal serviceSerCost = info.getBigDecimalParameter("inpservsercost");
+ BigDecimal serviceOutCost = info.getBigDecimalParameter("inpservoutcost");
+
+ BigDecimal serviceTotalCost = serviceSerCost.add(serviceOutCost);
+
+ info.addResult("inpservcost", serviceTotalCost);
+ }
}
diff -r 00600b268925 -r 12b53f471269
src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java Sat Mar
13 10:31:41 2010 +0530
+++ b/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java Sat Mar
13 09:17:34 2010 +0100
@@ -21,176 +21,289 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
-
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
+import org.apache.log4j.Logger;
+import org.openbravo.base.filter.RequestFilter;
import org.openbravo.base.secureApp.HttpSecureAppServlet;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.utils.FormatUtilities;
import org.openbravo.xmlEngine.XmlDocument;
+/**
+ * This class is used to implement Openbravo ERP servlet callouts in a simple
+ * manner.
+ * <p>
+ * To develop a new servlet callout based on this class you only have to create
+ * a new java class that extends the method:
+ * <p><blockquote><pre>
+ * protected void execute(CalloutInfo info) throws ServletException;
+ * </pre></blockquote>
+ * <p>
+ * In this method you can develop the logic of the callout and use the
+ * infoobject of class <code>CalloutInfo<code/> to access window fields,
+ * database and other methods
+ *
+ * @author aro
+ */
public abstract class SimpleCallout extends HttpSecureAppServlet {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
+ private static Logger log = Logger.getLogger(SimpleCallout.class);
- protected abstract void execute(CalloutInfo info) throws ServletException;
+ /**
+ * Overwrite this method to implement a new servlet callout based in
+ * <code>SimlpleCallout</code>
+ *
+ * @param info
+ * The {...@code CalloutInfo} that contains all helper data to access
+ * callout information and servlet information
+ * @throws ServletException
+ */
+ protected abstract void execute(CalloutInfo info) throws ServletException;
- @Override
- public void init(ServletConfig config) {
- super.init(config);
- boolHist = false;
+ @Override
+ public void init(ServletConfig config) {
+ super.init(config);
+ boolHist = false;
+ }
+
+ @Override
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
+
+ VariablesSecureApp vars = new VariablesSecureApp(request);
+
+ if (vars.commandIn("DEFAULT")) {
+ try {
+ printPage(response, vars);
+ } catch (ServletException ex) {
+ pageErrorCallOut(response);
+ }
+ } else {
+ pageError(response);
+ }
+ }
+
+ private void printPage(HttpServletResponse response, VariablesSecureApp
vars) throws IOException, ServletException {
+
+ log.debug("Output: dataSheet");
+
+ XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
+ "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
+
+ CalloutInfo info = new CalloutInfo(vars, getSimpleClassName());
+
+ execute(info);
+
+ xmlDocument.setParameter("array", info.finishResult());
+ xmlDocument.setParameter("frameName", "appFrame");
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ out.println(xmlDocument.print());
+ out.close();
+ }
+
+ private String getSimpleClassName() {
+ String classname = getClass().getName();
+ int i = classname.lastIndexOf(".");
+ if (i < 0) {
+ return classname;
+ } else {
+ return classname.substring(i + 1);
+ }
+ }
+
+ /**
+ * Helper class that contains all data to access
+ * callout information and servlet information
+ */
+ protected static class CalloutInfo {
+
+ private StringBuilder result;
+ private int rescounter;
+ private int selectcounter;
+ /**
+ * Provides the coder friendly methods to retrieve certain environment,
+ * session and servlet call variables.
+ */
+ public VariablesSecureApp vars;
+
+ private CalloutInfo(VariablesSecureApp vars, String classname) {
+ this.vars = vars;
+
+ result = new StringBuilder();
+ result.append("var calloutName='");
+ result.append(classname);
+ result.append("';\nvar respuesta = new Array(");
+
+ rescounter = 0;
+ selectcounter = 0;
}
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
-
- VariablesSecureApp vars = new VariablesSecureApp(request);
-
- if (vars.commandIn("DEFAULT")) {
- try {
- printPage(response, vars);
- } catch (ServletException ex) {
- pageErrorCallOut(response);
- }
- } else {
- pageError(response);
- }
+ private String finishResult() {
+ result.append(");");
+ return result.toString();
}
- private void printPage(HttpServletResponse response, VariablesSecureApp
vars) throws IOException, ServletException {
-
- if (log4j.isDebugEnabled()) {
- log4j.debug("Output: dataSheet");
- }
-
- XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
-
"org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
-
- CalloutInfo info = new CalloutInfo(vars, getSimpleClassName());
-
- execute(info);
-
- xmlDocument.setParameter("array", info.finishResult());
- xmlDocument.setParameter("frameName", "appFrame");
- response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- out.println(xmlDocument.print());
- out.close();
+ /**
+ *
+ * @return
+ * The name of field that triggered the callout.
+ */
+ public String getLastFieldChanged() {
+ return vars.getStringParameter("inpLastFieldChanged");
}
- private String getSimpleClassName() {
- String classname = getClass().getName();
- int i = classname.lastIndexOf(".");
- if (i < 0) {
- return classname;
- } else {
- return classname.substring(i + 1);
- }
+ /**
+ *
+ * @return
+ * The Tab Id that triggered the callout.
+ */
+ public String getTabId() {
+ return vars.getStringParameter("inpTabId");
}
- protected static class CalloutInfo {
+ /**
+ *
+ * @return
+ * The Window Id that triggered the callout.
+ */
+ public String getWindowId() {
+ return vars.getStringParameter("inpwindowId");
+ }
- private StringBuffer result;
- private int rescounter;
- private int selectcounter;
+ /**
+ *
+ * @param param
+ * The name of the field to get the value.
+ * @return
+ * The value of a field named param as an {...@code String}.
+ */
+ public String getStringParameter(String param) {
+ return vars.getStringParameter(param);
+ }
- public VariablesSecureApp vars;
+ /**
+ *
+ * @param param
+ * The name of the field to get the value.
+ * @param filter
+ * Filter used to validate the input against list of allowed inputs.
+ * @return
+ * The value of a field named param as an {...@code String}.
+ */
+ public String getStringParameter(String param, RequestFilter filter) {
+ return vars.getStringParameter(param, filter);
+ }
- private CalloutInfo(VariablesSecureApp vars, String classname) {
- this.vars = vars;
+ /**
+ *
+ * @param param
+ * The name of the field to get the value.
+ * @return
+ * The value of a field named param as a {...@code BigDecimal}.
+ * @throws ServletException
+ */
+ public BigDecimal getBigDecimalParameter(String param) throws
ServletException {
+ return new BigDecimal(vars.getNumericParameter(param, "0"));
+ }
- result = new StringBuffer();
- result.append("var calloutName='");
- result.append(classname);
- result.append("';\nvar respuesta = new Array(");
+ /**
+ * Starts the inclusion of values of a field named param of type select.
+ * @param param
+ * The name of the select field to set the values.
+ */
+ public void addSelect(String param) {
- rescounter = 0;
- selectcounter = 0;
- }
+ if (rescounter > 0) {
+ result.append(',');
+ }
+ rescounter++;
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits