Skip to content

Commit 5f6b7ec

Browse files
JihoonKim1004JihoonKim1004
authored andcommitted
Initial changes for multilingual application support [meaning support for ResourceBundle]. Improve + clean up later and also finish with implementation by adding ResourceBundle component.
1 parent ef3555f commit 5f6b7ec

29 files changed

Lines changed: 418 additions & 179 deletions

File tree

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/context/MxmlContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public abstract class MxmlContext {
7474

7575
public abstract void setFlexSDKPath(String flexSDKPath);
7676

77+
public abstract String getLocaleWebContextPath();
78+
79+
public abstract void setLocaleWebContextPath(String localeWebContextPath);
80+
7781
public abstract String getMxmlPath();
7882

7983
public abstract void setMxmlPath(String mxmlPath);

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/context/MxmlContextImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MxmlContextImpl extends MxmlContext {
6363
private boolean _simplySWF;
6464

6565
private String _flexSDKPath;
66+
private String _localeWebContextPath;
6667
private String _mxmlPath;
6768
private String _preMxmlPath;
6869
private String _swcPath;
@@ -137,6 +138,12 @@ public String getFlexSDKPath() {
137138
public void setFlexSDKPath(String flexSDKPath) {
138139
_flexSDKPath = flexSDKPath;
139140
}
141+
public String getLocaleWebContextPath() {
142+
return _localeWebContextPath;
143+
}
144+
public void setLocaleWebContextPath(String localeWebContextPath) {
145+
_localeWebContextPath = localeWebContextPath;
146+
}
140147
public String getMxmlPath() {
141148
return _mxmlPath;
142149
}

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/tasks/_FlexTaskRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface _FlexTaskRunner extends _TaskRunner {
4646

4747
void createSystemSWCFile(String sourcePath, String outPut, String flexSDKRootPath, String loadConfigFilePath);
4848

49-
void createSWF(_MXMLApplicationContract componentMXML, String mxmlFile, String swfPath, String flexSDKRootPath);
49+
void createSWF(String mxmlFile, String swfPath, _MXMLApplicationContract componentMXML, String flexSDKRootPath, String locale, String localePath);
5050

5151
void createSwfSourceFiles(String swfBasePath, List systemSwfSourceFiles);
5252

jsf-flex-shared/core/src/main/java/com/googlecode/jsfFlex/shared/util/MXMLConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
*/
4040
public final class MXMLConstants {
4141

42+
public static final String LOCALE_WEB_CONTEXT_RELATIVE_PATH = "com.googlecode.jsfFlex.LocaleWebContextRelativePath";
43+
public static final String DEFAULT_LOCALE = "DefaultLocale";
44+
public static final char SWF_FILE_NAME_LOCALE_SEPARATOR = '-';
45+
4246
public static final String FLASH_TO_JAVASCRIPT_LOG_LEVEL_NAME = "com.googlecode.jsfFlex.FlashToJavaScriptLogLevel";
4347
public static final String FLASH_TO_JAVASCRIPT_LOG_LOG_LEVEL = "Log";
4448
public static final String FLASH_TO_JAVASCRIPT_LOG_DEBUG_LEVEL = "Debug";

jsf-flex/core/src/main/java/com/googlecode/jsfFlex/component/ext/AbstractMXMLUIApplication.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javax.faces.component.UIComponentBase;
2525
import javax.faces.context.FacesContext;
2626
import javax.servlet.ServletContext;
27-
import javax.servlet.http.HttpServletRequest;
2827

2928
import org.json.JSONObject;
3029

@@ -289,8 +288,7 @@ public void encodeBegin(FacesContext context) throws IOException {
289288
mxmlContext.setProductionEnv(isProduction);
290289
mxmlContext.setSimplySWF(isSimplySwf);
291290

292-
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
293-
String webContextPath = request.getContextPath();
291+
String webContextPath = context.getExternalContext().getRequestContextPath();
294292
String swfWebPath = webContextPath + "/" + MXMLConstants.SWF_DIRECTORY_NAME + "/" + getMxmlPackageName() + "/";
295293
mxmlContext.setSwfWebPath(swfWebPath);
296294
mxmlContext.setWebContextPath(webContextPath);
@@ -300,6 +298,11 @@ public void encodeBegin(FacesContext context) throws IOException {
300298
init = (init == null) ? INITIALIZE_CALL : init + " " + INITIALIZE_CALL;
301299
getAttributes().put(INITIALIZE_ATTR, init);
302300

301+
String localeWebContextRelativePath = context.getExternalContext().getInitParameter(MXMLConstants.LOCALE_WEB_CONTEXT_RELATIVE_PATH);
302+
if(localeWebContextRelativePath != null){
303+
mxmlContext.setLocaleWebContextPath(_applicationPath + File.separatorChar + localeWebContextRelativePath + File.separatorChar);
304+
}
305+
303306
//to reflect the correct state when debugging
304307
if(isProduction){
305308
//do not need to create preMXML, MXML, and SWF files

jsf-flex/core/src/main/java/com/googlecode/jsfFlex/renderkit/mxml/AbstractMXMLResponseWriter.java

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.io.InputStream;
2424
import java.io.Writer;
2525
import java.util.HashMap;
26+
import java.util.Iterator;
27+
import java.util.LinkedHashMap;
2628
import java.util.List;
2729
import java.util.Map;
2830
import java.util.Properties;
@@ -147,14 +149,12 @@ public final String siblingReplaceTokenWithPreMxmlIdentifier(_MXMLContract currI
147149
* One can consider this method to be somewhat of a facade in creating application SWF file.<br>
148150
*
149151
* @param componentMXML
150-
* @param mxmlFile
151152
*/
152-
public final void processCreateSwf(_MXMLApplicationContract componentMXML, String mxmlFile) {
153+
public final void processCreateSwf(String mxmlFile, _MXMLApplicationContract componentMXML, Map multiLingualSupportMap) {
153154

154155
MxmlContext mxmlContext = MxmlContext.getCurrentInstance();
155-
String copyTo = mxmlContext.getMxmlPath() + mxmlContext.getCurrMxml() + MXMLConstants.MXML_FILE_EXT;
156156
//now create the MXML file
157-
createMXML(componentMXML.getAbsolutePathToPreMxmlFile(), copyTo);
157+
createMXML(componentMXML.getAbsolutePathToPreMxmlFile(), mxmlFile);
158158

159159
if(!new File(mxmlContext.getFlexSDKPath()).exists()){
160160
makeDirectory(mxmlContext.getFlexSDKPath());
@@ -195,8 +195,45 @@ public final void processCreateSwf(_MXMLApplicationContract componentMXML, Strin
195195
createJsfFlexFlashApplicationConfigurationFile();
196196

197197
//finally the SWF file
198-
createSWF(componentMXML, mxmlFile, mxmlContext.getSwfPath(), mxmlContext.getFlexSDKPath());
198+
createSWF(mxmlFile, componentMXML, mxmlContext.getFlexSDKPath(), multiLingualSupportMap, mxmlContext.getLocaleWebContextPath());
199+
200+
}
201+
202+
/**
203+
* Returns the multiLingualSupport Map for this web application.<br>
204+
*
205+
* @param componentMXML
206+
* @return
207+
*/
208+
public final Map getMultiLingualSupportMap(){
209+
Map multiLingualSupportMap = new LinkedHashMap();
210+
211+
MxmlContext mxmlContext = MxmlContext.getCurrentInstance();
212+
String localeWebContextPath = mxmlContext.getLocaleWebContextPath();
213+
214+
if(localeWebContextPath != null){
215+
String swfBaseName = mxmlContext.getCurrMxml();
216+
String swfFileNameBasePath = mxmlContext.getSwfBasePath() + swfBaseName + File.separatorChar;
217+
218+
File localeWebContextDirectory = new File(localeWebContextPath);
219+
if(localeWebContextDirectory.isDirectory()){
220+
String[] directoryChildren = localeWebContextDirectory.list();
221+
for(int i=0; i < directoryChildren.length; i++){
222+
File currentChild = new File(localeWebContextPath + directoryChildren[i]);
223+
if(currentChild.isDirectory()){
224+
//a locale
225+
String locale = currentChild.getName();
226+
multiLingualSupportMap.put(locale, swfFileNameBasePath + swfBaseName + MXMLConstants.SWF_FILE_NAME_LOCALE_SEPARATOR
227+
+ locale + MXMLConstants.SWF_FILE_EXT);
228+
}
229+
}
230+
}
231+
232+
}
199233

234+
//Always include Default Locale in case unsupported Locale is requested
235+
multiLingualSupportMap.put(MXMLConstants.DEFAULT_LOCALE, mxmlContext.getSwfPath());
236+
return multiLingualSupportMap;
200237
}
201238

202239
/**
@@ -241,8 +278,23 @@ public final void createMXML(String targetAbsolutePath, String copyTo) {
241278
* @param swfPath
242279
* @param flexSDKRootPath
243280
*/
244-
public final void createSWF(_MXMLApplicationContract componentMXML, String mxmlFile, String swfPath, String flexSDKRootPath) {
245-
getFlexTaskRunner().createSWF(componentMXML, mxmlFile, swfPath, flexSDKRootPath);
281+
public final void createSWF(String mxmlFile, _MXMLApplicationContract componentMXML, String flexSDKRootPath, Map multiLingualSupportMap, String localeWebContextPath) {
282+
283+
for(Iterator iterate = multiLingualSupportMap.keySet().iterator(); iterate.hasNext();){
284+
String currLocale = (String) iterate.next();
285+
String currLocaleFileName = (String) multiLingualSupportMap.get(currLocale);
286+
String currLocaleSourcePath = null;
287+
288+
if(currLocale.equals(MXMLConstants.DEFAULT_LOCALE)){
289+
currLocale = null;
290+
currLocaleSourcePath = null;
291+
}else{
292+
currLocaleSourcePath = localeWebContextPath + currLocale + File.separatorChar;
293+
}
294+
295+
getFlexTaskRunner().createSWF(mxmlFile, currLocaleFileName, componentMXML, flexSDKRootPath, currLocale, currLocaleSourcePath);
296+
}
297+
246298
}
247299

248300
/**

jsf-flex/examples/src/main/webapp/WEB-INF/web.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
<param-value>server</param-value>
4949
</context-param>
5050

51+
<context-param>
52+
<description>
53+
The relative web context path for the locale resources, if being used for
54+
multilingual application
55+
</description>
56+
<param-name>com.googlecode.jsfFlex.LocaleWebContextRelativePath</param-name>
57+
<param-value>locale</param-value>
58+
</context-param>
59+
5160
<context-param>
5261
<description>
5362
For JSF Flex Flash To JavaScript Log Level, possible values are (Log, Debug, Info, Warn, Error)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
greeting=Hello
2+
street_address=Street Address
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
greeting=Hola
2+
street_address=Dirección de Calle

jsf-flex/renderKit14/src/main/java/com/googlecode/jsfFlex/renderkit/component/ext/MXMLApplicationRenderer.java

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.Iterator;
2525
import java.util.List;
26+
import java.util.Locale;
2627
import java.util.Map;
2728
import java.util.Set;
2829

@@ -151,15 +152,19 @@ public void encodeEnd(FacesContext context, UIComponent componentObj) throws IOE
151152
AbstractMXMLResponseWriter writer = (AbstractMXMLResponseWriter) context.getResponseWriter();
152153

153154
MxmlContext mxmlContext = MxmlContext.getCurrentInstance();
154-
String mxmlFile = mxmlContext.getMxmlPath() + mxmlContext.getCurrMxml() + MXMLConstants.MXML_FILE_EXT;;
155+
String mxmlFile = mxmlContext.getMxmlPath() + mxmlContext.getCurrMxml() + MXMLConstants.MXML_FILE_EXT;
156+
String localeWebContextPath = mxmlContext.getLocaleWebContextPath();
157+
Map multiLingualSupportMap = writer.getMultiLingualSupportMap();
155158

156159
//check if simplySWF boolean flag is set and if so, create the SWF file and exit
157160
if(mxmlContext.isSimplySWF()){
158161
if(!new File(mxmlContext.getFlexSDKPath()).exists()){
159162
writer.makeDirectory(mxmlContext.getFlexSDKPath());
160163
writer.unZipArchiveRelative(MXMLConstants.FLEX_SDK_ZIP, mxmlContext.getFlexSDKPath());
161164
}
162-
writer.createSWF(componentMXML, mxmlFile, mxmlContext.getSwfPath(), mxmlContext.getFlexSDKPath());
165+
166+
writer.createSWF(mxmlFile, componentMXML, mxmlContext.getFlexSDKPath(), multiLingualSupportMap, localeWebContextPath);
167+
163168
}else if(!mxmlContext.isProductionEnv()){
164169
//means it is of debugMode, so must create mxml and etcetera
165170

@@ -203,13 +208,13 @@ public void encodeEnd(FacesContext context, UIComponent componentObj) throws IOE
203208

204209
}
205210

206-
writer.processCreateSwf(componentMXML, mxmlFile);
211+
writer.processCreateSwf(mxmlFile, componentMXML, multiLingualSupportMap);
207212

208213
}
209214

210215
}
211216

212-
_mxmlApplicationHtmlRenderer.renderHtmlContent(context, componentObj);
217+
_mxmlApplicationHtmlRenderer.renderHtmlContent(context, componentObj, multiLingualSupportMap);
213218

214219
}
215220

@@ -222,7 +227,7 @@ private final class MXMLApplicationHTMLRenderer {
222227
private static final String JS_COMMUNICATION_CORE_NS = "com.googlecode.jsfFlex.communication.core";
223228
private static final String JS_COMMUNICATION_CORE_PAGE_LOAD_NS = "com.googlecode.jsfFlex.communication.core.pageLoad";
224229

225-
private void renderHtmlContent(FacesContext context, UIComponent component) throws IOException {
230+
private void renderHtmlContent(FacesContext context, UIComponent component, Map multiLingualSupportMap) throws IOException {
226231

227232
MxmlContext mxmlContext = MxmlContext.getCurrentInstance();
228233
com.googlecode.jsfFlex.component.ext.MXMLUIApplication appComponent =
@@ -254,18 +259,65 @@ private void renderHtmlContent(FacesContext context, UIComponent component) thro
254259
writer.write(toWrite.toString());
255260
writer.endElement(MXMLAttributeConstants.SCRIPT_ELEM);
256261

257-
writeHTMLSWF(writer, appComponent, mxmlContext.getSwfWebPath());
262+
String swfFile = getLocaleSwfFile(mxmlContext, context, appComponent, multiLingualSupportMap);
263+
264+
writeHTMLSWF(writer, appComponent, swfFile);
265+
266+
}
267+
268+
private String getLocaleSwfFile(MxmlContext mxmlContext, FacesContext context,
269+
com.googlecode.jsfFlex.component.ext.MXMLUIApplication appComponent, Map multiLingualSupportMap){
270+
271+
String localeWebContextPath = mxmlContext.getLocaleWebContextPath();
272+
String swfFile = null;
273+
String defaultLocale = mxmlContext.getSwfWebPath() + appComponent.getMxmlPackageName() + MXMLConstants.SWF_FILE_EXT;
274+
if(localeWebContextPath == null){
275+
swfFile = defaultLocale;
276+
}else{
277+
278+
Locale preferredLocale = context.getExternalContext().getRequestLocale();
279+
280+
String languageMatch = preferredLocale.getLanguage();
281+
languageMatch = languageMatch == null ? "" : languageMatch.toUpperCase().trim();
282+
283+
String countryMatch = preferredLocale.getCountry();
284+
countryMatch = countryMatch == null ? "" : countryMatch.toUpperCase().trim();
285+
int countryMatchLength = countryMatch.length();
286+
287+
String closestMatch = null;
288+
for(Iterator iterate = multiLingualSupportMap.keySet().iterator(); iterate.hasNext();){
289+
String currCountryLocale = (String) iterate.next();
290+
String currCountryLocaleMatch = currCountryLocale.toUpperCase().trim();
291+
292+
if(currCountryLocaleMatch.indexOf(languageMatch) == 0){
293+
closestMatch = mxmlContext.getSwfWebPath() + appComponent.getMxmlPackageName() +
294+
MXMLConstants.SWF_FILE_NAME_LOCALE_SEPARATOR + currCountryLocale + MXMLConstants.SWF_FILE_EXT;
295+
296+
int matchIndex = currCountryLocaleMatch.indexOf(countryMatch);
297+
if((matchIndex > -1 && (matchIndex + countryMatchLength) == currCountryLocaleMatch.length())){
298+
swfFile = closestMatch;
299+
break;
300+
}
301+
}
302+
303+
}
304+
305+
if(swfFile == null){
306+
swfFile = closestMatch != null ? closestMatch : defaultLocale;
307+
}
308+
309+
}
258310

311+
return swfFile;
259312
}
260313

261314
private void writeHTMLSWF(ResponseWriter writer, com.googlecode.jsfFlex.component.ext.MXMLUIApplication appComponent,
262-
String swfPath) throws IOException{
315+
String swfFile) throws IOException{
263316
Object heightO = appComponent.getAttributes().get(MXMLAttributeConstants.HEIGHT_ATTR);
264317
Object widthO = appComponent.getAttributes().get(MXMLAttributeConstants.WIDTH_ATTR);
265318

266319
String height = (heightO == null) ? "100%" : (String) heightO;
267320
String width = (widthO == null) ? "100%" : (String) widthO;
268-
String swfFile = swfPath + appComponent.getMxmlPackageName() + MXMLConstants.SWF_FILE_EXT;
269321

270322
writer.startElement("object", appComponent);
271323

0 commit comments

Comments
 (0)