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 2011/09/18 22:48:27 UTC
svn commit: r1172342 -
/ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java
Author: jleroux
Date: Sun Sep 18 20:48:27 2011
New Revision: 1172342
URL: http://svn.apache.org/viewvc?rev=1172342&view=rev
Log:
A slightly modified patch from Dimitri Unruh "Minor code style improvement" https://issues.apache.org/jira/browse/OFBIZ-4400
In the createJsLanguageFileMapping service, the catch blocks have assigns to a local variable in a return statement.
Simplified further on Adrian's advice.
jleroux: I have also organized imports
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java?rev=1172342&r1=1172341&r2=1172342&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/JsLanguageFileMappingCreator.java Sun Sep 18 20:48:27 2011
@@ -1,10 +1,8 @@
package org.ofbiz.common;
import java.io.File;
-import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -20,19 +18,18 @@ import org.ofbiz.base.util.template.Free
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
-import freemarker.template.TemplateException;
-
public class JsLanguageFileMappingCreator {
private static final String module = JsLanguageFileMappingCreator.class.getName();
public static Map<String, Object> createJsLanguageFileMapping(DispatchContext ctx, Map<String, ?> context) {
Map<String, Object> result = ServiceUtil.returnSuccess();
+ String encoding = (String) context.get("encoding"); // default value: UTF-8
+
List<Locale> localeList = UtilMisc.availableLocales();
Map<String, Object> jQueryLocaleFile = FastMap.newInstance();
Map<String, String> dateJsLocaleFile = FastMap.newInstance();
Map<String, String> validationLocaleFile = FastMap.newInstance();
- //Map<String, String> validationMethodsLocaleFile = FastMap.newInstance();
// setup some variables to locate the js files
String componentRoot = "component://images/webapp";
@@ -147,32 +144,13 @@ public class JsLanguageFileMappingCreato
Writer writer = new StringWriter();
try {
FreeMarkerWorker.renderTemplateAtLocation(template, mapWrapper, writer);
+ // write it as a Java file
+ File file = new File(output);
+ FileUtils.writeStringToFile(file, writer.toString(), encoding);
}
- catch (MalformedURLException e) {
- Debug.logError(e, module);
- return result = ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
- }
- catch (TemplateException e) {
- Debug.logError(e, module);
- return result = ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
- }
- catch (IOException e) {
- Debug.logError(e, module);
- return result = ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
- }
- catch (IllegalArgumentException e) {
- Debug.logError(e, module);
- return result = ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
- }
-
- // write it as a Java file
- File file = new File(output);
- try {
- FileUtils.writeStringToFile(file, writer.toString(), "UTF-8");
- }
- catch (IOException e) {
+ catch (Exception e) {
Debug.logError(e, module);
- return result = ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
+ return ServiceUtil.returnError("The Outputfile could not be created: " + e.getMessage());
}
return result;