Author: dmaliarevich
Date: 2009-12-03 08:41:45 -0500 (Thu, 03 Dec 2009)
New Revision: 19022
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/i18n/JsfLocaleProvider.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfView.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/converter/OpenKeyHelper.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/bundle/BundleMap.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/ILocaleProvider.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/MainLocaleProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5218, locale attribute was added to f:view
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/converter/OpenKeyHelper.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/converter/OpenKeyHelper.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/helpers/converter/OpenKeyHelper.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -71,15 +71,32 @@
}
public static String getDeafultLocale(XModel model) {
+ String facesConfigLocale = getDeafultLocaleFromFacesConfig(model);
+ if (facesConfigLocale.length() == 0) {
+ Locale locale = Locale.getDefault();
+ facesConfigLocale = locale == null || locale.toString().length() == 0 ? null :
locale.toString();
+ }
+ return facesConfigLocale;
+ }
+
+ /**
+ * Gets the default locale from faces config file.
+ *
+ * @param model XModel
+ * @return locale string or empty string if no locale was found
+ */
+ public static String getDeafultLocaleFromFacesConfig(XModel model) {
+ String facesConfigLocale = ""; //$NON-NLS-1$
JSFProjectsRoot root = JSFProjectsTree.getProjectsRoot(model);
WebProjectNode conf = root == null ? null :
(WebProjectNode)root.getChildByPath(JSFProjectTreeConstants.CONFIGURATION);
XModelObject[] fs = conf == null ? new XModelObject[0] : conf.getTreeChildren();
for (int i = 0; i < fs.length; i++) {
XModelObject o = fs[i].getChildByPath("application/Locale Config");
//$NON-NLS-1$
String res = (o == null) ? "" :
o.getAttributeValue("default-locale"); //$NON-NLS-1$ //$NON-NLS-2$
- if(res != null && res.length() > 0) return res;
+ if(res != null && res.length() > 0) {
+ facesConfigLocale = res;
+ }
}
- Locale locale = Locale.getDefault();
- return locale == null || locale.toString().length() == 0 ? null : locale.toString();
+ return facesConfigLocale;
}
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/i18n/JsfLocaleProvider.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/i18n/JsfLocaleProvider.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/i18n/JsfLocaleProvider.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -28,6 +28,11 @@
*/
public class JsfLocaleProvider implements ILocaleProvider {
+ /*
+ * Stores the string representation of the current locale.
+ */
+ private String localeString = ""; //$NON-NLS-1$
+
/**
* Returns the locale for given {@code editor}, or {@code null} if it
* can not determine it.
@@ -39,9 +44,15 @@
.getFile().getProject();
XModel model = EclipseResourceUtil.getModelNature(project)
.getModel();
- return new Locale(OpenKeyHelper.getDeafultLocale(model));
+ localeString = OpenKeyHelper.getDeafultLocaleFromFacesConfig(model);
+ return new Locale(localeString);
} else {
return null;
}
}
+
+ public String getLocaleString() {
+ return localeString;
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfView.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfView.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfView.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -12,11 +12,15 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+import org.jboss.tools.jsf.vpe.jsf.template.util.ComponentUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.i18n.MainLocaleProvider;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMDocument;
@@ -26,12 +30,16 @@
import org.w3c.dom.NodeList;
/**
+ * Creates template for JSF f:view tag.
+ * <p>Parses the locale attribute.
+ * <p>Adds nested children.
+ *
* @author dmaliarevich
- *
*/
public class JsfView extends VpeAbstractTemplate {
private static String TABLE_WIDTH_STYLE = "width: 100%;"; //$NON-NLS-1$
+ private static String ATTR_LOCALE = "locale"; //$NON-NLS-1$
/**
* Instantiates a new jsf view.
@@ -55,7 +63,50 @@
td.appendChild(div);
tr.appendChild(td);
table.appendChild(tr);
+
+ /*
+ * Variables that are used in locale processing.
+ * By default Locale object will be created for the empty string.
+ */
+ String localeString = Constants.EMPTY;
+ Locale locale = null;
+ /*
+ * 1. Get locale value.
+ *
+ * 1.1 Parse EL expression from locale atrribute:
+ * VPE cannot resolve runtime values for EL expressions,
+ * only Substituted and Global EL expression will be resolved.
+ * These expressions are parsed before template creating
+ * in VpeVisualDomBuilder, f:view template has already got parsed el.
+ *
+ * 1.2 If there is a default locale specified - use it in any case,
+ * otherwise get the locale from the attribute.
+ */
+ String defaultLocaleString = MainLocaleProvider.getInstance().getLocaleString();
+ if (ComponentUtil.isNotBlank(defaultLocaleString)) {
+ localeString = defaultLocaleString;
+ } else {
+ String localeAttribute = sourceElement.getAttribute(ATTR_LOCALE);
+ if (ComponentUtil.isNotBlank(localeAttribute)) {
+ localeString = localeAttribute;
+ }
+ }
+
+ /*
+ * 2. Create Locale object from locale string.
+ */
+ locale = createLocale(localeString);
+
+ /*
+ * 3. Get bundles for this Locale and Refresh the page.
+ * If there is no locale attribute in f:view - use default locale,
+ * that is got from MainLocaleProvider.
+ * When Default Locate is found - use it in any case.
+ */
+ pageContext.getBundle().setLocale(locale);
+ pageContext.getBundle().refreshRegisteredBundles();
+
VpeCreationData creationData = new VpeCreationData(table);
VpeChildrenInfo divInfo = new VpeChildrenInfo(div);
creationData.addChildrenInfo(divInfo);
@@ -68,6 +119,27 @@
}
/**
+ * Creates the locale.
+ * <p>If the locale string could be parsed into language and country -
+ * creates Locale for this arguments.
+ * <p> By default - locale for empty string is created.
+ *
+ * @param localeString the locale string
+ * @return Locale object
+ */
+ Locale createLocale(String localeString) {
+ Locale newLocale = null;
+ if (localeString.length() == 2) {
+ newLocale = new Locale(localeString);
+ } else if ((localeString.length() == 5) && (localeString.indexOf("_")
== 2)) { //$NON-NLS-1$
+ newLocale = new Locale(localeString.substring(0, 2), localeString.substring(3));
+ } else {
+ newLocale = new Locale(Constants.EMPTY);
+ }
+ return newLocale;
+ }
+
+ /**
* Gets the children.
*
* @param sourceElement the source element
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfAllTests.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -67,6 +67,7 @@
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4509Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4510Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4534Test;
+import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE5218Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE675Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE788Test;
import org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE924Test;
@@ -180,6 +181,8 @@
suite.addTestSuite(VPERefreshTest.class);
suite.addTestSuite(OpenOnInsideJspRoot_JBIDE4852.class);
suite.addTestSuite(NullPointerWithStyleProperty_JBIDE5193.class);
+ suite.addTestSuite(JBIDE5218Test.class);
+
// $JUnit-END$
// added by Max Areshkau
// add here projects which should be imported for junit tests
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/bundle/BundleMap.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/bundle/BundleMap.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/bundle/BundleMap.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -62,8 +62,11 @@
private StructuredTextEditor editor;
private String[] javaSources;
-
- private BundleEntry[] bundles = new BundleEntry[0];
+ /*
+ * Stores the current VPE locale.
+ */
+ private Locale locale;
+ private BundleEntry[] bundles = new BundleEntry[0];
private Map<String,UsedKey> usedKeys = new HashMap<String,UsedKey>();
boolean isShowBundleUsageAsEL =
JspEditorPlugin.getDefault().getPreferenceStore().getBoolean(
@@ -78,25 +81,53 @@
if (input instanceof IFileEditorInput) {
javaSources =
getJavaProjectSrcLocations(((IFileEditorInput)input).getFile().getProject());
}
+ /*
+ * Initialize the locale with default value.
+ */
+ locale = MainLocaleProvider.getInstance().getLocale(editor);
refreshRegisteredBundles();
PreferenceModelUtilities.getPreferenceModel().addModelTreeListener(modelListener);
}
public void refreshRegisteredBundles() {
- if (!hasJsfProjectNatureType() || !(editor.getEditorInput() instanceof
IFileEditorInput)) return;
- IProject project = ((IFileEditorInput)editor.getEditorInput()).getFile().getProject();
+ if (!hasJsfProjectNatureType()
+ || !(editor.getEditorInput() instanceof IFileEditorInput)) {
+ return;
+ }
+ IProject project = ((IFileEditorInput) editor.getEditorInput())
+ .getFile().getProject();
XModel model = EclipseResourceUtil.getModelNature(project).getModel();
- List<Object> l = WebPromptingProvider.getInstance().getList(model,
WebPromptingProvider.JSF_REGISTERED_BUNDLES, null, null);
- if(l == null || l.size() < 2 || !(l.get(1) instanceof Map)) return;
- Map<?,?> map = (Map<?,?>)l.get(1);
- Iterator<?> it = map.keySet().iterator();
- while(it.hasNext()) {
- String uri = it.next().toString();
- String prefix = map.get(uri).toString();
- int hash = (prefix + ":" + uri).hashCode(); //$NON-NLS-1$
- removeBundle(hash);
- addBundle(hash, prefix, uri, true);
+ List<Object> l = WebPromptingProvider.getInstance().getList(model,
+ WebPromptingProvider.JSF_REGISTERED_BUNDLES, null, null);
+ if (l == null || l.size() < 2 || !(l.get(1) instanceof Map)) {
+ return;
}
+ Map<?, ?> map = (Map<?, ?>) l.get(1);
+ /*
+ * Fix for
https://jira.jboss.org/jira/browse/JBIDE-5218
+ * When updating f:view's locale attribute right after template creation -
+ * map of registered bundles is empty and couldn't be updated.
+ * To change bundle's locale they should be accessed through
+ * <code>bundles</code> variable.
+ */
+ if (map.keySet().size() > 0) {
+ Iterator<?> it = map.keySet().iterator();
+ while (it.hasNext()) {
+ String uri = it.next().toString();
+ String prefix = map.get(uri).toString();
+ int hash = (prefix + ":" + uri).hashCode(); //$NON-NLS-1$
+ removeBundle(hash);
+ addBundle(hash, prefix, uri, true);
+ }
+ } else if (bundles.length > 0) {
+ for (int i = 0; i < bundles.length; i++) {
+ String uri = bundles[i].uri;
+ String prefix = bundles[i].prefix;
+ int hash = (prefix + ":" + uri).hashCode(); //$NON-NLS-1$
+ removeBundle(hash);
+ addBundle(hash, prefix, uri, true);
+ }
+ }
}
public void clearAll() {
@@ -207,7 +238,8 @@
return null;
}
- private ResourceBundle getBundleByUrl(String uri) {
+
+ private ResourceBundle getBundleByUrl(String uri, Locale locale) {
try {
if (javaSources!=null) {
File file;
@@ -223,8 +255,6 @@
}
ClassLoader classLoader = new URLClassLoader(urls,
ClassLoader.getSystemClassLoader());
-
- Locale locale = MainLocaleProvider.getInstance().getLocale(editor);
ResourceBundle bundle = ResourceBundle.getBundle(uri, locale, classLoader);
return bundle;
@@ -272,7 +302,7 @@
}
private void addBundle(int hashCode, String prefix, String uri,boolean refresh) {
- ResourceBundle bundle = getBundleByUrl(uri);
+ ResourceBundle bundle = getBundleByUrl(uri, locale);
BundleEntry entry = new BundleEntry(bundle, uri, prefix, hashCode);
if (bundle != null) {
BundleEntry[] newBundles = new BundleEntry[bundles.length + 1];
@@ -480,11 +510,20 @@
refresh();
}
}
+
public void updateShowBundleUsageAsEL() {
updateShowBundleUsageAsEL(JspEditorPlugin.getDefault().getPreferenceStore().getBoolean(
IVpePreferencesPage.SHOW_RESOURCE_BUNDLES_USAGE_AS_EL));
}
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
static class Expression {
public String prefix;
public String propertyName;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/ILocaleProvider.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/ILocaleProvider.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/ILocaleProvider.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -13,6 +13,7 @@
import java.util.Locale;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.common.model.XModel;
/**
* This interface is intended for creation extensions of {@code localeProvider}
@@ -26,4 +27,12 @@
* may return {@code null} if they can not determine the locale.
*/
Locale getLocale(StructuredTextEditor editor);
+
+ /**
+ * Shows the string representation of the locale
+ * returned by #getLocale(StructuredTextEditor) method.
+ *
+ * @return the string representation of the locale
+ */
+ String getLocaleString();
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/MainLocaleProvider.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/MainLocaleProvider.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/i18n/MainLocaleProvider.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -51,6 +51,8 @@
.getExtensionPoint(VpePlugin.EXTESION_POINT_LOCALE_PROVIDER);
private static MainLocaleProvider instance;
+ private String localeString = ""; //$NON-NLS-1$
+
private MainLocaleProvider() {
// private constructor
initNatureExtensionsMap();
@@ -83,6 +85,7 @@
for (ILocaleProvider provider : getProviders(natureId)) {
Locale locale = provider.getLocale(editor);
if (locale != null) {
+ localeString = provider.getLocaleString();
return locale;
}
}
@@ -180,4 +183,9 @@
}
return provider;
}
+
+ public String getLocaleString() {
+ return localeString;
+ }
+
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2009-12-03
13:39:04 UTC (rev 19021)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2009-12-03
13:41:45 UTC (rev 19022)
@@ -13,6 +13,7 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;