svn commit: r655712 - in /ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/UtilHttp.java common/webcommon/login.ftl webapp/src/org/ofbiz/webapp/control/LoginWorker.java widget/src/org/ofbiz/widget/screen/ScreenRenderer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r655712 - in /ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/UtilHttp.java common/webcommon/login.ftl webapp/src/org/ofbiz/webapp/control/LoginWorker.java widget/src/org/ofbiz/widget/screen/ScreenRenderer.java

adrianc
Author: adrianc
Date: Mon May 12 19:25:55 2008
New Revision: 655712

URL: http://svn.apache.org/viewvc?rev=655712&view=rev
Log:
Added JavaScript detection to the framework. See https://issues.apache.org/jira/browse/OFBIZ-1648.

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/framework/common/webcommon/login.ftl
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=655712&r1=655711&r2=655712&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Mon May 12 19:25:55 2008
@@ -54,10 +54,9 @@
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
-import javolution.util.FastSet;
 
 /**
- * HttpUtil - Misc TTP Utility Functions
+ * HttpUtil - Misc HTTP Utility Functions
  */
 public class UtilHttp {
 
@@ -690,6 +689,34 @@
         return requestUri;
     }
 
+    /** Returns the query string contained in a request target - basically everything
+     * after and including the ? character.
+     * @param target The request target
+     * @return The query string or null if none is found
+     */
+    public static String getQueryStringFromTarget(String target) {
+        if (target == null || target.length() == 0) return null;
+        int queryStart = target.indexOf('?');
+        if (queryStart != -1) {
+            return target.substring(queryStart);
+        }
+        return null;
+    }
+
+    /** Removes the query string from a request target - basically everything
+     * after and including the ? character.
+     * @param target The request target
+     * @return The request target string
+     */
+    public static String removeQueryStringFromTarget(String target) {
+        if (target == null || target.length() == 0) return null;
+        int queryStart = target.indexOf('?');
+        if (queryStart < 0) {
+            return target;
+        }
+        return target.substring(0, queryStart);
+    }
+
     public static String getWebappMountPointFromTarget(String target) {
         int firstChar = 0;
         if (target == null || target.length() == 0) return null;
@@ -1122,4 +1149,16 @@
         return result;
     }
 
+    /** Returns true if the user has JavaScript enabled.
+     * @param request
+     * @return
+     */
+    public static boolean isJavaScriptEnabled(HttpServletRequest request) {
+        HttpSession session = request.getSession();
+        Boolean javaScriptEnabled = (Boolean) session.getAttribute("javaScriptEnabled");
+        if (javaScriptEnabled != null) {
+            return javaScriptEnabled.booleanValue();
+        }
+        return false;
+    }
 }

Modified: ofbiz/trunk/framework/common/webcommon/login.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/login.ftl?rev=655712&r1=655711&r2=655712&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/webcommon/login.ftl (original)
+++ ofbiz/trunk/framework/common/webcommon/login.ftl Mon May 12 19:25:55 2008
@@ -52,12 +52,14 @@
             </td>
           </tr>
         </table>
+        <input type="hidden" name="JavaScriptEnabled" value="N"/>
       </form>
     </div>
   </div>
 </center>
 
 <script language="JavaScript" type="text/javascript">
+  document.loginform.JavaScriptEnabled.value = "Y";
   <#if focusName>
     document.loginform.USERNAME.focus();
   <#else>

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java?rev=655712&r1=655711&r2=655712&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java Mon May 12 19:25:55 2008
@@ -18,14 +18,18 @@
  *******************************************************************************/
 package org.ofbiz.webapp.control;
 
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import java.security.cert.X509Certificate;
+import java.io.UnsupportedEncodingException;
 import java.math.BigInteger;
 import java.net.URLEncoder;
-import java.io.UnsupportedEncodingException;
+import java.security.cert.X509Certificate;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import javax.security.auth.x500.X500Principal;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.Cookie;
@@ -34,18 +38,25 @@
 import javax.servlet.http.HttpSession;
 import javax.servlet.jsp.PageContext;
 import javax.transaction.Transaction;
-import javax.security.auth.x500.X500Principal;
 
 import javolution.util.FastList;
 
 import org.ofbiz.base.component.ComponentConfig;
-import org.ofbiz.base.util.*;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.KeyStoreUtil;
+import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.common.login.LoginServices;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.transaction.GenericTransactionException;
 import org.ofbiz.entity.transaction.TransactionUtil;
@@ -55,7 +66,6 @@
 import org.ofbiz.service.ModelService;
 import org.ofbiz.service.ServiceUtil;
 import org.ofbiz.webapp.stats.VisitHandler;
-import org.ofbiz.common.login.LoginServices;
 
 /**
  * Common Workers
@@ -375,6 +385,15 @@
             if (userLogin != null && "Y".equals(userLogin.getString("requirePasswordChange"))) {
                 return "requirePasswordChange";
             }
+            String javaScriptEnabled = "N";
+            if ("Y".equals(request.getParameter("JavaScriptEnabled"))) {
+                javaScriptEnabled = "Y";
+            }
+            try {
+                result = dispatcher.runSync("setUserPreference", UtilMisc.toMap("userPrefTypeId", "javaScriptEnabled", "userPrefGroupId", "GLOBAL_PREFS", "userPrefValue", javaScriptEnabled, "userLogin", userLogin));
+            } catch (GenericServiceException e) {
+                Debug.logError(e, "Error setting user preference", module);
+            }
             return doMainLogin(request, response, userLogin, userLoginSession);
         } else {
             Map messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));
@@ -412,6 +431,16 @@
         HttpSession session = request.getSession();
         session.setAttribute("userLogin", userLogin);
 
+        String javaScriptEnabled = null;
+        try {
+            LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+            Map<String, Object> result = dispatcher.runSync("getUserPreference", UtilMisc.toMap("userPrefTypeId", "javaScriptEnabled", "userPrefGroupId", "GLOBAL_PREFS", "userLogin", userLogin));
+            javaScriptEnabled = (String) result.get("userPrefValue");
+        } catch (GenericServiceException e) {
+            Debug.logError(e, "Error getting user preference", module);
+        }
+        session.setAttribute("javaScriptEnabled", new Boolean("Y".equals(javaScriptEnabled)));
+
         ModelEntity modelUserLogin = userLogin.getModelEntity();
         if (modelUserLogin.isField("partyId")) {
             // if partyId is a field, then we should have these relations defined

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java?rev=655712&r1=655711&r2=655712&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java Mon May 12 19:25:55 2008
@@ -26,7 +26,6 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -37,7 +36,6 @@
 import javolution.util.FastMap;
 import javolution.util.FastSet;
 
-import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilFormatOut;
@@ -226,6 +224,7 @@
                 context.put("https", https);
             }
         }
+        context.put("javaScriptEnabled", new Boolean(UtilHttp.isJavaScriptEnabled(request)));
 
         // these ones are FreeMarker specific and will only work in FTL templates, mainly here for backward compatibility
         BeansWrapper wrapper = BeansWrapper.getDefaultInstance();