You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/11/24 20:42:13 UTC
svn commit: r1771222 - in /myfaces/tobago/trunk:
tobago-core/src/main/faces-config/
tobago-core/src/main/java/org/apache/myfaces/tobago/context/
tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/
tobago-core/src/main/java/org/apache/myfaces/...
Author: lofwyr
Date: Thu Nov 24 20:42:13 2016
New Revision: 1771222
URL: http://svn.apache.org/viewvc?rev=1771222&view=rev
Log:
TOBAGO-1637: Load XML Properties via standard mechanism
Added:
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoMessage.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message.properties.xml
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoMessage_de.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message_de.properties.xml
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoMessage_es.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message_es.properties.xml
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoResource.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago.properties.xml
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoResource_de.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago_de.properties.xml
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/context/TobagoResource_es.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago_es.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo_de.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_de.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/demo_en.properties.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_en.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/demo_ja.properties.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_ja.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/demo_ru.properties.xml
- copied unchanged from r1771107, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_ru.properties.xml
Removed:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/LoadBundleHandler.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/LoadBundleTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/BundleMapWrapper.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_de.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_en.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_ja.properties.xml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/demo_ru.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message_de.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago-message_es.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago_de.properties.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/property/tobago_es.properties.xml
Modified:
myfaces/tobago/trunk/tobago-core/src/main/faces-config/faces-config.xml
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoBundle.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoMessageBundle.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoResourceBundle.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml
Modified: myfaces/tobago/trunk/tobago-core/src/main/faces-config/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/faces-config/faces-config.xml?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/faces-config/faces-config.xml (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/faces-config/faces-config.xml Thu Nov 24 20:42:13 2016
@@ -27,6 +27,11 @@
<application>
<default-render-kit-id>tobago</default-render-kit-id>
+ <message-bundle>org.apache.myfaces.tobago.context.TobagoResourceBundle</message-bundle>
+ <resource-bundle>
+ <base-name>org.apache.myfaces.tobago.context.TobagoResourceBundle</base-name>
+ <var>tobagoResourceBundle</var>
+ </resource-bundle>
</application>
<lifecycle>
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoBundle.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoBundle.java?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoBundle.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoBundle.java Thu Nov 24 20:42:13 2016
@@ -22,10 +22,18 @@ package org.apache.myfaces.tobago.contex
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.faces.context.FacesContext;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
import java.util.ResourceBundle;
+import java.util.Set;
/**
* This class works like the Java resource bundle mechanism for a named resource bundle
@@ -39,9 +47,11 @@ public class TobagoBundle extends Resour
private static final Logger LOG = LoggerFactory.getLogger(TobagoBundle.class);
private String bundleName;
+ private ResourceBundle bundle;
public TobagoBundle(final String bundleName) {
this.bundleName = bundleName;
+ this.bundle = ResourceBundle.getBundle(bundleName, new XmlTobagoBundle.XMLResourceBundleControl());
}
@Override
@@ -49,8 +59,7 @@ public class TobagoBundle extends Resour
if (LOG.isDebugEnabled()) {
LOG.debug("Searching for '{}' in bundle '{}'", key, bundleName);
}
- final FacesContext facesContext = FacesContext.getCurrentInstance();
- return ResourceManagerUtils.getProperty(facesContext, bundleName, key);
+ return bundle.getObject(key);
}
@Override
@@ -61,4 +70,68 @@ public class TobagoBundle extends Resour
public String getBundleName() {
return bundleName;
}
+
+ public static class XmlTobagoBundle extends ResourceBundle {
+
+ private static final String XML = "xml";
+
+ private Properties props;
+
+ private XmlTobagoBundle(InputStream stream) throws IOException {
+ props = new Properties();
+ props.loadFromXML(stream);
+ }
+
+ protected Object handleGetObject(String key) {
+ return props.getProperty(key);
+ }
+
+ public Enumeration<String> getKeys() {
+ Set<String> handleKeys = props.stringPropertyNames();
+ return Collections.enumeration(handleKeys);
+ }
+
+ public static class XMLResourceBundleControl extends Control {
+
+ public List<String> getFormats(String baseName) {
+ return Collections.singletonList(XML);
+ }
+
+ public ResourceBundle newBundle(String baseName, Locale locale, String format,
+ ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException,
+ IOException {
+
+ if ((baseName == null) || (locale == null) || (format == null) || (loader == null)) {
+ throw new NullPointerException();
+ }
+ ResourceBundle bundle = null;
+ if (!format.equals(XML)) {
+ return null;
+ }
+
+ String bundleName = toBundleName(baseName, locale);
+ String resourceName = toResourceName(bundleName, format);
+ URL url = loader.getResource(resourceName);
+ if (url == null) {
+ return null;
+ }
+ URLConnection connection = url.openConnection();
+ if (connection == null) {
+ return null;
+ }
+ if (reload) {
+ connection.setUseCaches(false);
+ }
+ InputStream stream = connection.getInputStream();
+ if (stream == null) {
+ return null;
+ }
+ BufferedInputStream bis = new BufferedInputStream(stream);
+ bundle = new XmlTobagoBundle(bis);
+ bis.close();
+
+ return bundle;
+ }
+ }
+ }
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoMessageBundle.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoMessageBundle.java?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoMessageBundle.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoMessageBundle.java Thu Nov 24 20:42:13 2016
@@ -19,16 +19,26 @@
package org.apache.myfaces.tobago.context;
+import javax.faces.context.FacesContext;
+
/**
* This ResourceBundle encapsulate the messages (e. g. validation) of Tobago components.
- * This class works like the Java resource bundle mechanism for the resource bundle "tobago-message"
- * and adds the functionality of the tobago themes and also supports XML properties files.
+ * This class works like the Java resource bundle mechanism for the resource bundle {@value BUNDLE_NAME}.
+ * Supports XML properties files.
*
* @since 1.5.0
*/
public class TobagoMessageBundle extends TobagoBundle {
+ public static final String VAR = "tobagoMessageBundle";
+ public static final String BUNDLE_NAME = "org.apache.myfaces.tobago.context.TobagoMessage";
+
public TobagoMessageBundle() {
- super("tobago-message");
+ super(BUNDLE_NAME);
+ }
+
+
+ public static String getString(final FacesContext facesContext, final String key) {
+ return facesContext.getApplication().getResourceBundle(facesContext, VAR).getString(key);
}
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoResourceBundle.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoResourceBundle.java?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoResourceBundle.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoResourceBundle.java Thu Nov 24 20:42:13 2016
@@ -19,14 +19,23 @@
package org.apache.myfaces.tobago.context;
+import javax.faces.context.FacesContext;
+
/**
* This ResourceBundle encapsulate string resources of Tobago components.
- * This class works like the Java resource bundle mechanism for the resource bundle "tobago"
- * and adds the functionality of the tobago themes and also supports XML properties files.
+ * This class works like the Java resource bundle mechanism for the resource bundle {@value BUNDLE_NAME}.
+ * Supports XML properties files.
*/
public class TobagoResourceBundle extends TobagoBundle {
+ public static final String VAR = "tobagoResourceBundle";
+ public static final String BUNDLE_NAME = "org.apache.myfaces.tobago.context.TobagoResource";
+
public TobagoResourceBundle() {
- super("tobago");
+ super(BUNDLE_NAME);
+ }
+
+ public static String getString(final FacesContext facesContext, final String key) {
+ return facesContext.getApplication().getResourceBundle(facesContext, VAR).getString(key);
}
}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml Thu Nov 24 20:42:13 2016
@@ -20,8 +20,6 @@
<f:view locale="#{clientConfigController.locale}"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:tc="http://myfaces.apache.org/tobago/component">
-
- <tc:loadBundle basename="demo" var="demoBundle"/>
<tc:page applicationIcon="icon/favicon.ico" label="#{demoBundle.pageTitle}" id="page">
<!-- this event will forward to the first node of the navitation menu after loading -->
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml?rev=1771222&r1=1771221&r2=1771222&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml Thu Nov 24 20:42:13 2016
@@ -22,7 +22,6 @@
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view locale="#{clientConfigController.locale}">
- <tc:loadBundle basename="demo" var="demoBundle"/>
<tc:page label="Test" id="page">
<ui:insert/>