You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/10/13 23:37:49 UTC

svn commit: r824937 - in /ofbiz/trunk: framework/base/src/org/ofbiz/base/util/UtilProperties.java specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Author: jleroux
Date: Tue Oct 13 21:37:49 2009
New Revision: 824937

URL: http://svn.apache.org/viewvc?rev=824937&view=rev
Log:
In this case I don't need to persist the property.
This changes just do that : set temporary the property in memory, and reset it back to its original value

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java
    ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java?rev=824937&r1=824936&r2=824937&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilProperties.java Tue Oct 13 21:37:49 2009
@@ -325,82 +325,97 @@
     }
 
     /** Sets the specified value of the specified property name to the specified resource/properties file
-    * @param resource The name of the resource - must be a file
-    * @param name The name of the property in the properties file
-    * @param value The value of the property in the properties file */
-    public static void setPropertyValue(String resource, String name, String value) {
-        if (resource == null || resource.length() <= 0) return;
-        if (name == null || name.length() <= 0) return;
-
-        Properties properties = getProperties(resource);
-        if (properties == null) {
-            return;
-        }
-
-        try {
-            properties.setProperty(name, value);
-            FileOutputStream propFile = new FileOutputStream(resource);
-            if ("XuiLabels".equals(name)) {
-                properties.store(propFile,
-                    "##############################################################################\n"
-                    +"# Licensed to the Apache Software Foundation (ASF) under one                   \n"
-                    +"# or more contributor license agreements.  See the NOTICE file                 \n"
-                    +"# distributed with this work for additional information                        \n"
-                    +"# regarding copyright ownership.  The ASF licenses this file                   \n"
-                    +"# to you under the Apache License, Version 2.0 (the                            \n"
-                    +"# \"License\"); you may not use this file except in compliance                 \n"
-                    +"# with the License.  You may obtain a copy of the License at                   \n"
-                    +"#                                                                              \n"
-                    +"# http://www.apache.org/licenses/LICENSE-2.0                                   \n"
-                    +"#                                                                              \n"
-                    +"# Unless required by applicable law or agreed to in writing,                   \n"
-                    +"# software distributed under the License is distributed on an                  \n"
-                    +"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY                     \n"
-                    +"# KIND, either express or implied.  See the License for the                    \n"
-                    +"# specific language governing permissions and limitations                      \n"
-                    +"# under the License.                                                           \n"
-                    +"###############################################################################\n"
-                    +"#                                                                              \n"
-                    +"# Dynamically modified by OFBiz Framework (org.ofbiz.base.util : UtilProperties.setPropertyValue)\n"
-                    +"#                                                                              \n"
-                    +"# By default the screen is 1024x768 wide. If you want to use another screen size,\n"
-                    +"# you must create a new directory under specialpurpose/pos/screens, like the 800x600.\n"
-                    +"# You must also set the 3 related parameters (StartClass, ClientWidth, ClientHeight) accordingly.\n"
-                    +"#");
-            } else {
-                properties.store(propFile,
-                    "##############################################################################\n"
-                    +"# Licensed to the Apache Software Foundation (ASF) under one                   \n"
-                    +"# or more contributor license agreements.  See the NOTICE file                 \n"
-                    +"# distributed with this work for additional information                        \n"
-                    +"# regarding copyright ownership.  The ASF licenses this file                   \n"
-                    +"# to you under the Apache License, Version 2.0 (the                            \n"
-                    +"# \"License\"); you may not use this file except in compliance                 \n"
-                    +"# with the License.  You may obtain a copy of the License at                   \n"
-                    +"#                                                                              \n"
-                    +"# http://www.apache.org/licenses/LICENSE-2.0                                   \n"
-                    +"#                                                                              \n"
-                    +"# Unless required by applicable law or agreed to in writing,                   \n"
-                    +"# software distributed under the License is distributed on an                  \n"
-                    +"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY                     \n"
-                    +"# KIND, either express or implied.  See the License for the                    \n"
-                    +"# specific language governing permissions and limitations                      \n"
-                    +"# under the License.                                                           \n"
-                    +"###############################################################################\n"
-                    +"#                                                                              \n"
-                    +"# Dynamically modified by OFBiz Framework (org.ofbiz.base.util : UtilProperties.setPropertyValue)\n"
-                    +"# The comments have been removed, you may still find them on the OFBiz repository... \n"
-                    +"#");
-                
-            }
-
-            propFile.close();
-        } catch (FileNotFoundException e) {
-            Debug.log(e, "Unable to located the resource file.", module);
-        } catch (IOException e) {
-            Debug.logError(e, module);
-        }
-    }
+     * @param resource The name of the resource - must be a file
+     * @param name The name of the property in the properties file
+     * @param value The value of the property in the properties file */
+     public static void setPropertyValue(String resource, String name, String value) {
+         if (resource == null || resource.length() <= 0) return;
+         if (name == null || name.length() <= 0) return;
+
+         Properties properties = getProperties(resource);
+         if (properties == null) {
+             return;
+         }
+
+         try {
+             properties.setProperty(name, value);
+             FileOutputStream propFile = new FileOutputStream(resource);
+             if ("XuiLabels".equals(name)) {
+                 properties.store(propFile,
+                     "##############################################################################\n"
+                     +"# Licensed to the Apache Software Foundation (ASF) under one                   \n"
+                     +"# or more contributor license agreements.  See the NOTICE file                 \n"
+                     +"# distributed with this work for additional information                        \n"
+                     +"# regarding copyright ownership.  The ASF licenses this file                   \n"
+                     +"# to you under the Apache License, Version 2.0 (the                            \n"
+                     +"# \"License\"); you may not use this file except in compliance                 \n"
+                     +"# with the License.  You may obtain a copy of the License at                   \n"
+                     +"#                                                                              \n"
+                     +"# http://www.apache.org/licenses/LICENSE-2.0                                   \n"
+                     +"#                                                                              \n"
+                     +"# Unless required by applicable law or agreed to in writing,                   \n"
+                     +"# software distributed under the License is distributed on an                  \n"
+                     +"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY                     \n"
+                     +"# KIND, either express or implied.  See the License for the                    \n"
+                     +"# specific language governing permissions and limitations                      \n"
+                     +"# under the License.                                                           \n"
+                     +"###############################################################################\n"
+                     +"#                                                                              \n"
+                     +"# Dynamically modified by OFBiz Framework (org.ofbiz.base.util : UtilProperties.setPropertyValue)\n"
+                     +"#                                                                              \n"
+                     +"# By default the screen is 1024x768 wide. If you want to use another screen size,\n"
+                     +"# you must create a new directory under specialpurpose/pos/screens, like the 800x600.\n"
+                     +"# You must also set the 3 related parameters (StartClass, ClientWidth, ClientHeight) accordingly.\n"
+                     +"#");
+             } else {
+                 properties.store(propFile,
+                     "##############################################################################\n"
+                     +"# Licensed to the Apache Software Foundation (ASF) under one                   \n"
+                     +"# or more contributor license agreements.  See the NOTICE file                 \n"
+                     +"# distributed with this work for additional information                        \n"
+                     +"# regarding copyright ownership.  The ASF licenses this file                   \n"
+                     +"# to you under the Apache License, Version 2.0 (the                            \n"
+                     +"# \"License\"); you may not use this file except in compliance                 \n"
+                     +"# with the License.  You may obtain a copy of the License at                   \n"
+                     +"#                                                                              \n"
+                     +"# http://www.apache.org/licenses/LICENSE-2.0                                   \n"
+                     +"#                                                                              \n"
+                     +"# Unless required by applicable law or agreed to in writing,                   \n"
+                     +"# software distributed under the License is distributed on an                  \n"
+                     +"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY                     \n"
+                     +"# KIND, either express or implied.  See the License for the                    \n"
+                     +"# specific language governing permissions and limitations                      \n"
+                     +"# under the License.                                                           \n"
+                     +"###############################################################################\n"
+                     +"#                                                                              \n"
+                     +"# Dynamically modified by OFBiz Framework (org.ofbiz.base.util : UtilProperties.setPropertyValue)\n"
+                     +"# The comments have been removed, you may still find them on the OFBiz repository... \n"
+                     +"#");
+                 
+             }
+
+             propFile.close();
+         } catch (FileNotFoundException e) {
+             Debug.log(e, "Unable to located the resource file.", module);
+         } catch (IOException e) {
+             Debug.logError(e, module);
+         }
+     }
+
+     /** Sets the specified value of the specified property name to the specified resource/properties in memory, does not persist it 
+      * @param resource The name of the resource
+      * @param name The name of the property in the resource
+      * @param value The value of the property to set in memory */
+      public static void setPropertyValueInMemory(String resource, String name, String value) {
+          if (resource == null || resource.length() <= 0) return;
+          if (name == null || name.length() <= 0) return;
+
+          Properties properties = getProperties(resource);
+          if (properties == null) {
+              return;
+          }
+          properties.setProperty(name, value);
+      }
 
     // ========= Locale & Resource Based Methods ==========
 

Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=824937&r1=824936&r2=824937&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Tue Oct 13 21:37:49 2009
@@ -1833,8 +1833,10 @@
                 if (UtilValidate.isNotEmpty(card)) {
                     svcCtx.put("memberId", card);
                     if (!card.equals(person.getString("memberId"))) {
-                        // Update password
-                        UtilProperties.setPropertyValue("security.properties", "password.accept.encrypted.and.plain", "true");
+                        // Update password, we need to temporary set password.accept.encrypted.and.plain to "true"
+                        // This is done only for the properties loaded for the session in memory (we don't persist the value)
+                        String passwordAcceptEncryptedAndPlain = UtilProperties.getPropertyValue("security.properties", "password.accept.encrypted.and.plain");
+                        UtilProperties.setPropertyValueInMemory("security.properties", "password.accept.encrypted.and.plain", "true");
                         try {
                             svcRes = dispatcher.runSync("updatePassword", 
                                     UtilMisc.toMap("userLogin", partyLogin,
@@ -1852,8 +1854,8 @@
                             pos.showDialog("dialog/error/exception", ServiceUtil.getErrorMessage(svcRes));
                             return result;
                         }
-                        // This remove comments from the security.properties file. I did not find a way to keep them, so I put a word about that
-                        UtilProperties.setPropertyValue("security.properties", "password.accept.encrypted.and.plain", "false");
+                        // Put back passwordAcceptEncryptedAndPlain value in memory
+                        UtilProperties.setPropertyValueInMemory("security.properties", "password.accept.encrypted.and.plain", passwordAcceptEncryptedAndPlain);
                         partyLogin = (GenericValue) svcRes.get("updatedUserLogin");
                         svcCtx.put("userLogin", partyLogin);
                     }