Seam SVN: r9053 - trunk/seam-gen.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 18:43:25 -0400 (Sat, 20 Sep 2008)
New Revision: 9053
Modified:
trunk/seam-gen/build.xml
Log:
create package names when setting up project
Modified: trunk/seam-gen/build.xml
===================================================================
--- trunk/seam-gen/build.xml 2008-09-20 22:42:35 UTC (rev 9052)
+++ trunk/seam-gen/build.xml 2008-09-20 22:43:25 UTC (rev 9053)
@@ -843,9 +843,9 @@
<filterset refid="project"/>
</copy>
- <mkdir dir="${project.home}/src/model"/>
- <mkdir dir="${project.home}/src/action"/>
- <mkdir dir="${project.home}/src/test"/>
+ <mkdir dir="${project.home}/src/${model.dir}"/>
+ <mkdir dir="${project.home}/src/${action.dir}"/>
+ <mkdir dir="${project.home}/src/${test.dir}"/>
<copy todir="${project.home}/src/test" file="${base.dir}/test/readme.txt" />
15 years, 8 months
Seam SVN: r9052 - branches/community/Seam_2_0/seam-gen.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 18:42:35 -0400 (Sat, 20 Sep 2008)
New Revision: 9052
Modified:
branches/community/Seam_2_0/seam-gen/build.xml
Log:
create the model, action, and test packages when setting up the project
Modified: branches/community/Seam_2_0/seam-gen/build.xml
===================================================================
--- branches/community/Seam_2_0/seam-gen/build.xml 2008-09-20 22:18:03 UTC (rev 9051)
+++ branches/community/Seam_2_0/seam-gen/build.xml 2008-09-20 22:42:35 UTC (rev 9052)
@@ -827,9 +827,9 @@
<filterset refid="project"/>
</copy>
- <mkdir dir="${project.home}/src/model"/>
- <mkdir dir="${project.home}/src/action"/>
- <mkdir dir="${project.home}/src/test"/>
+ <mkdir dir="${project.home}/src/${model.dir}"/>
+ <mkdir dir="${project.home}/src/${action.dir}"/>
+ <mkdir dir="${project.home}/src/${test.dir}"/>
<copy todir="${project.home}/src/test" file="${base.dir}/test/readme.txt" />
15 years, 8 months
Seam SVN: r9051 - in trunk/src: main/org/jboss/seam/international and 3 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 18:18:03 -0400 (Sat, 20 Sep 2008)
New Revision: 9051
Added:
trunk/src/main/org/jboss/seam/international/LocaleConfig.java
trunk/src/main/org/jboss/seam/mock/MockApplicationFactory.java
Modified:
trunk/src/main/org/jboss/seam/international-2.1.xsd
trunk/src/main/org/jboss/seam/mock/AbstractSeamTest.java
trunk/src/main/org/jboss/seam/mock/MockApplication.java
trunk/src/test/integration/resources/WEB-INF/components.xml
trunk/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java
Log:
JBSEAM-3088
Also, enhanced the BaseSeamTest to use FactoryFinder to locate the MockApplication
so that external code can locate the same Application instance
Added: trunk/src/main/org/jboss/seam/international/LocaleConfig.java
===================================================================
--- trunk/src/main/org/jboss/seam/international/LocaleConfig.java (rev 0)
+++ trunk/src/main/org/jboss/seam/international/LocaleConfig.java 2008-09-20 22:18:03 UTC (rev 9051)
@@ -0,0 +1,146 @@
+package org.jboss.seam.international;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.util.Strings;
+
+/**
+ * Configures the JSF locale support from the Seam container.
+ *
+ * <p>
+ * This component merely passes on configuration settings to the JSF runtime, so
+ * you still have to option of configure the locale support in the JSF
+ * configuration file. However, if you enable this component, it will overwrite
+ * any settings from that file.
+ * </p>
+ *
+ * <code>
+ * <i18n:locale-config default-locale="en" supported-locales="en fr de"/>
+ * </code>
+ *
+ * @author Dan Allen
+ */
+@Scope(APPLICATION)
+@BypassInterceptors
+@Startup
+@Name("org.jboss.seam.international.localeConfig")
+@Install(value = false, precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
+public class LocaleConfig
+{
+ private String defaultLocale;
+
+ private List<String> supportedLocales;
+
+ @Create
+ public void initLocaleConfig()
+ {
+ Application application = getApplication();
+ if (application == null)
+ {
+ return;
+ }
+
+ String defaultAsString = getDefaultLocale();
+ if (defaultAsString != null)
+ {
+ application.setDefaultLocale(getLocaleFromString(defaultAsString));
+ }
+
+ List<String> supportedAsStrings = getSupportedLocales();
+ int numSupported = supportedAsStrings != null ? supportedAsStrings.size() : 0;
+ if (numSupported > 0)
+ {
+ // use set to prevent duplicates, yet retain order just to be nice
+ Set<java.util.Locale> locales = new LinkedHashSet<java.util.Locale>(numSupported);
+ for (String supportedAsString : supportedAsStrings)
+ {
+ locales.add(getLocaleFromString(supportedAsString));
+ }
+ application.setSupportedLocales(locales);
+ }
+ }
+
+ public String getDefaultLocale()
+ {
+ return defaultLocale;
+ }
+
+ public void setDefaultLocale(String defaultLocale)
+ {
+ this.defaultLocale = defaultLocale;
+ }
+
+ public List<String> getSupportedLocales()
+ {
+ return supportedLocales;
+ }
+
+ public void setSupportedLocales(List<String> supportedLocales)
+ {
+ this.supportedLocales = supportedLocales;
+ }
+
+ public static LocaleConfig instance()
+ {
+ return (LocaleConfig) Component.getInstance(LocaleConfig.class, ScopeType.APPLICATION);
+ }
+
+ private java.util.Locale getLocaleFromString(String localeString)
+ {
+ if (localeString == null || localeString.length() < 2)
+ {
+ throw new IllegalArgumentException("Invalid locale string: " + localeString);
+ }
+
+ StringTokenizer tokens = new StringTokenizer(localeString, "-_");
+ String language = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ String country = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ String variant = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ if (!Strings.isEmpty(variant))
+ {
+ return new java.util.Locale(language, country, variant);
+ }
+ else if (!Strings.isEmpty(country))
+ {
+ return new java.util.Locale(language, country);
+ }
+ else
+ {
+ return new java.util.Locale(language);
+ }
+ }
+
+ private Application getApplication()
+ {
+ try
+ {
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
+ return factory.getApplication();
+ }
+ catch (IllegalStateException e)
+ {
+ // just in case, for units and the like
+ // if we can't do it, it just wan't meant to be
+ return null;
+ }
+ }
+}
Modified: trunk/src/main/org/jboss/seam/international-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/international-2.1.xsd 2008-09-20 22:16:57 UTC (rev 9050)
+++ trunk/src/main/org/jboss/seam/international-2.1.xsd 2008-09-20 22:18:03 UTC (rev 9051)
@@ -4,6 +4,27 @@
xmlns:components="http://jboss.com/products/seam/components" attributeFormDefault="unqualified">
<xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="components-2.1.xsd"/>
+ <xs:element name="locale-config">
+ <xs:annotation>
+ <xs:documentation>
+ Locale configuration component. An alternative to configuring
+ the locale in the JSF configuration file.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType mixed="true">
+ <xs:choice minOccurs="0" maxOccurs="1">
+ <xs:element name="supported-locales" type="components:multiValuedProperty"/>
+ </xs:choice>
+ <xs:attributeGroup ref="components:attlist.component"/>
+ <xs:attributeGroup ref="international:attlist.localeConfig"/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:attributeGroup name="attlist.localeConfig">
+ <xs:attribute name="default-locale" type="components:string"/>
+ <xs:attribute name="supported-locales" type="components:string"/>
+ </xs:attributeGroup>
+
<xs:element name="locale-selector">
<xs:annotation>
<xs:documentation>The locale selector component</xs:documentation>
Modified: trunk/src/main/org/jboss/seam/mock/AbstractSeamTest.java
===================================================================
--- trunk/src/main/org/jboss/seam/mock/AbstractSeamTest.java 2008-09-20 22:16:57 UTC (rev 9050)
+++ trunk/src/main/org/jboss/seam/mock/AbstractSeamTest.java 2008-09-20 22:18:03 UTC (rev 9051)
@@ -14,6 +14,7 @@
import javax.el.ValueExpression;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
@@ -914,6 +915,7 @@
startJbossEmbeddedIfNecessary();
this.servletContext = createServletContext();
ServletLifecycle.beginApplication(servletContext);
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
new Initialization(servletContext).create().init();
((Init) servletContext.getAttribute(Seam.getComponentName(Init.class))).setDebug(false);
}
@@ -933,6 +935,7 @@
*/
protected void stopSeam() throws Exception
{
+ ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).setApplication(null);
ServletLifecycle.endApplication();
}
@@ -944,7 +947,7 @@
protected void setupClass() throws Exception
{
servletContext = (MockServletContext) ServletLifecycle.getServletContext();
- application = new SeamApplication(new MockApplication());
+ application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
conversationViewRootAttributes = new HashMap<String, Map>();
seamFilter = createSeamFilter();
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, MockFacesContextFactory.class.getName());
Modified: trunk/src/main/org/jboss/seam/mock/MockApplication.java
===================================================================
--- trunk/src/main/org/jboss/seam/mock/MockApplication.java 2008-09-20 22:16:57 UTC (rev 9050)
+++ trunk/src/main/org/jboss/seam/mock/MockApplication.java 2008-09-20 22:18:03 UTC (rev 9051)
@@ -54,6 +54,7 @@
private javax.el.CompositeELResolver elResolver;
private javax.el.CompositeELResolver additionalResolvers;
+ private Collection locales;
public MockApplication()
{
@@ -374,13 +375,20 @@
@Override
public Iterator getSupportedLocales()
{
- return Collections.singleton(defaultLocale).iterator();
+ if (locales == null)
+ {
+ return Collections.singleton(defaultLocale).iterator();
+ }
+ else
+ {
+ return locales.iterator();
+ }
}
@Override
public void setSupportedLocales(Collection locales)
{
- throw new UnsupportedOperationException();
+ this.locales = locales;
}
private final Map<String, Validator> validatorsById = new HashMap<String, Validator>();
Added: trunk/src/main/org/jboss/seam/mock/MockApplicationFactory.java
===================================================================
--- trunk/src/main/org/jboss/seam/mock/MockApplicationFactory.java (rev 0)
+++ trunk/src/main/org/jboss/seam/mock/MockApplicationFactory.java 2008-09-20 22:18:03 UTC (rev 9051)
@@ -0,0 +1,41 @@
+package org.jboss.seam.mock;
+
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+import org.jboss.seam.jsf.SeamApplication;
+
+/**
+ * An mock implementation of the JSF ApplicationFactory which returns a mock
+ * Application wrapped in a SeamApplication. This class can be registered with
+ * JSF to allow JSF to be used formally in a test environment as follows:
+ *
+ * <code>
+ * FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+ * "org.jboss.seam.mock.MockApplicationFactory");
+ * Application application = ((ApplicationFactory) FactoryFinder
+ * .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ * </code>
+ *
+ * @author Dan Allen
+ */
+public class MockApplicationFactory extends ApplicationFactory
+{
+ private Application application;
+
+ @Override
+ public Application getApplication()
+ {
+ if (application == null) {
+ application = new SeamApplication(new MockApplication());
+ }
+ return application;
+ }
+
+ @Override
+ public void setApplication(Application application)
+ {
+ this.application = application;
+ }
+
+}
Modified: trunk/src/test/integration/resources/WEB-INF/components.xml
===================================================================
--- trunk/src/test/integration/resources/WEB-INF/components.xml 2008-09-20 22:16:57 UTC (rev 9050)
+++ trunk/src/test/integration/resources/WEB-INF/components.xml 2008-09-20 22:18:03 UTC (rev 9051)
@@ -2,6 +2,7 @@
<components xmlns="http://jboss.com/products/seam/components"
xmlns:bpm="http://jboss.com/products/seam/bpm"
xmlns:core="http://jboss.com/products/seam/core"
+ xmlns:i18n="http://jboss.com/products/seam/international"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:web="http://jboss.com/products/seam/web"
@@ -11,6 +12,7 @@
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
+ http://jboss.com/products/seam/international http://jboss.com/products/seam/international-2.1.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
@@ -23,6 +25,8 @@
<core:manager concurrent-request-timeout="500"
conversation-timeout="120000"
conversation-id-parameter="cid"/>
+
+ <i18n:locale-config default-locale="fr_CA" supported-locales="fr_CA fr_FR en"/>
<persistence:managed-persistence-context name="entityManager"
auto-create="true"
Modified: trunk/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java
===================================================================
--- trunk/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java 2008-09-20 22:16:57 UTC (rev 9050)
+++ trunk/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java 2008-09-20 22:18:03 UTC (rev 9051)
@@ -1,5 +1,8 @@
package org.jboss.seam.test.integration.i8ln;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import javax.faces.component.UIOutput;
@@ -20,6 +23,25 @@
@Override
protected void invokeApplication() throws Exception
{
+ // <i18:locale-config default-locale="fr_CA" supported-locales="fr_CA fr_FR en"/>
+ List<Locale> supportedLocales = new ArrayList<Locale>();
+ for (Iterator<Locale> iter = getFacesContext().getApplication().getSupportedLocales(); iter.hasNext();)
+ {
+ supportedLocales.add(iter.next());
+ }
+ assert supportedLocales.size() == 3;
+ assert supportedLocales.contains(Locale.CANADA_FRENCH);
+ assert supportedLocales.contains(Locale.ENGLISH);
+ assert supportedLocales.contains(Locale.FRANCE);
+ assert getFacesContext().getApplication().getDefaultLocale().equals(Locale.CANADA_FRENCH);
+
+ // why not? I guess be default locale means different things in different contexts (server vs user)
+ //assert org.jboss.seam.international.Locale.instance().equals(Locale.CANADA_FRENCH);
+
+ // reset the locale configuration (as it would be w/o <i18n:locale-config>)
+ getFacesContext().getApplication().setDefaultLocale(Locale.ENGLISH);
+ getFacesContext().getApplication().setSupportedLocales(null);
+
assert org.jboss.seam.international.Locale.instance().equals(Locale.getDefault());
LocaleSelector.instance().setLocale(Locale.UK);
15 years, 8 months
Seam SVN: r9050 - trunk/src/test/integration/src/org/jboss/seam/test/integration.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 18:16:57 -0400 (Sat, 20 Sep 2008)
New Revision: 9050
Modified:
trunk/src/test/integration/src/org/jboss/seam/test/integration/BeanA.java
trunk/src/test/integration/src/org/jboss/seam/test/integration/EntityPassivationTest.java
Log:
make conversation-scoped components implement Serializable
Modified: trunk/src/test/integration/src/org/jboss/seam/test/integration/BeanA.java
===================================================================
--- trunk/src/test/integration/src/org/jboss/seam/test/integration/BeanA.java 2008-09-20 21:53:28 UTC (rev 9049)
+++ trunk/src/test/integration/src/org/jboss/seam/test/integration/BeanA.java 2008-09-20 22:16:57 UTC (rev 9050)
@@ -1,5 +1,6 @@
package org.jboss.seam.test.integration;
+import java.io.Serializable;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
@@ -11,7 +12,7 @@
@Name("beanA")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
-public class BeanA {
+public class BeanA implements Serializable {
private String myValue;
@@ -34,4 +35,4 @@
Events.instance().raiseEvent("BeanA.valueModified");
}
-}
\ No newline at end of file
+}
Modified: trunk/src/test/integration/src/org/jboss/seam/test/integration/EntityPassivationTest.java
===================================================================
--- trunk/src/test/integration/src/org/jboss/seam/test/integration/EntityPassivationTest.java 2008-09-20 21:53:28 UTC (rev 9049)
+++ trunk/src/test/integration/src/org/jboss/seam/test/integration/EntityPassivationTest.java 2008-09-20 22:16:57 UTC (rev 9050)
@@ -1,5 +1,6 @@
package org.jboss.seam.test.integration;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -95,7 +96,7 @@
@Name("entitytest.someComponent")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
- public static class SomeComponent {
+ public static class SomeComponent implements Serializable {
@In EntityManager entityManager;
15 years, 8 months
Seam SVN: r9049 - in trunk/src/main/org/jboss/seam: navigation and 1 other directory.
by seam-commits@lists.jboss.org
Author: jacob.orshalick
Date: 2008-09-20 17:53:28 -0400 (Sat, 20 Sep 2008)
New Revision: 9049
Modified:
trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java
trunk/src/main/org/jboss/seam/core/Manager.java
trunk/src/main/org/jboss/seam/navigation/ConversationControl.java
Log:
JBSEAM-1943 abstracted endRoot logic into a convenience method on Manager
Modified: trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java 2008-09-20 21:43:49 UTC (rev 9048)
+++ trunk/src/main/org/jboss/seam/core/ConversationInterceptor.java 2008-09-20 21:53:28 UTC (rev 9049)
@@ -286,17 +286,14 @@
private void endConversation(boolean beforeRedirect, boolean endRoot)
{
- Manager manager = Manager.instance();
-
if(endRoot)
{
- if(manager.isNestedConversation())
- {
- manager.switchConversation(manager.getRootConversationId());
- }
+ Manager.instance().endRootConversation(beforeRedirect);
}
-
- manager.endConversation(beforeRedirect);
+ else
+ {
+ Manager.instance().endConversation(beforeRedirect);
+ }
}
public boolean isInterceptorEnabled()
Modified: trunk/src/main/org/jboss/seam/core/Manager.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/Manager.java 2008-09-20 21:43:49 UTC (rev 9048)
+++ trunk/src/main/org/jboss/seam/core/Manager.java 2008-09-20 21:53:28 UTC (rev 9049)
@@ -624,6 +624,19 @@
}
}
+ /**
+ * Make the root conversation in the current conversation stack temporary.
+ */
+ public void endRootConversation(boolean beforeRedirect)
+ {
+ if(isNestedConversation())
+ {
+ switchConversation(getRootConversationId());
+ }
+
+ endConversation(beforeRedirect);
+ }
+
protected void storeConversationToViewRootIfNecessary() {}
// two reasons for this:
Modified: trunk/src/main/org/jboss/seam/navigation/ConversationControl.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/ConversationControl.java 2008-09-20 21:43:49 UTC (rev 9048)
+++ trunk/src/main/org/jboss/seam/navigation/ConversationControl.java 2008-09-20 21:53:28 UTC (rev 9049)
@@ -46,20 +46,13 @@
{
if ( endConversation() )
{
- Conversation conversation = Conversation.instance();
-
- if (isEndRootConversation && conversation.isNested())
+ if(isEndRootConversation)
{
- conversation.root();
+ Manager.instance().endRootConversation(isEndConversationBeforeRedirect);
}
-
- if (isEndConversationBeforeRedirect)
- {
- conversation.endBeforeRedirect();
- }
else
{
- conversation.end();
+ Manager.instance().endConversation(isEndConversationBeforeRedirect);
}
}
if ( beginConversation() )
15 years, 8 months
Seam SVN: r9048 - branches/community/Seam_2_0/src/main/org/jboss/seam/mock.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 17:43:49 -0400 (Sat, 20 Sep 2008)
New Revision: 9048
Modified:
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
Log:
one more time, clean up application so that it parallel existing behavior (just loading it differently)
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 21:35:21 UTC (rev 9047)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 21:43:49 UTC (rev 9048)
@@ -938,7 +938,6 @@
initServletContext(servletContext.getInitParameters());
ServletLifecycle.beginApplication(servletContext);
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
- application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
new Initialization(servletContext).create().init();
((Init) servletContext.getAttribute(Seam.getComponentName(Init.class))).setDebug(false);
}
@@ -951,8 +950,6 @@
*/
protected void stopSeam() throws Exception
{
- FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
- ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).setApplication(null);
ServletLifecycle.endApplication();
}
@@ -964,6 +961,7 @@
protected void setupClass() throws Exception
{
servletContext = (MockServletContext) ServletLifecycle.getServletContext();
+ application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
phases = new SeamPhaseListener();
conversationViewRootAttributes = new HashMap<String, Map>();
seamFilter = createSeamFilter();
@@ -981,6 +979,7 @@
protected void cleanupClass() throws Exception
{
seamFilter.destroy();
+ ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).setApplication(null);
conversationViewRootAttributes = null;
}
15 years, 8 months
Seam SVN: r9047 - branches/community/Seam_2_0/src/main/org/jboss/seam/international.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 17:35:21 -0400 (Sat, 20 Sep 2008)
New Revision: 9047
Modified:
branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java
Log:
don't allow absense of JSF Application cause things to fail
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java 2008-09-20 21:33:28 UTC (rev 9046)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java 2008-09-20 21:35:21 UTC (rev 9047)
@@ -130,8 +130,16 @@
private Application getApplication()
{
- ApplicationFactory factory = (ApplicationFactory) FactoryFinder
- .getFactory(FactoryFinder.APPLICATION_FACTORY);
- return factory.getApplication();
+ try
+ {
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
+ return factory.getApplication();
+ }
+ catch (IllegalStateException e)
+ {
+ // just in case, for units and the like
+ return null;
+ }
}
}
\ No newline at end of file
15 years, 8 months
Seam SVN: r9046 - branches/community/Seam_2_0/src/main/org/jboss/seam/mock.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 17:33:28 -0400 (Sat, 20 Sep 2008)
New Revision: 9046
Modified:
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
Log:
oops, needed to initialize the JSF Application before starting Seam
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 20:53:01 UTC (rev 9045)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 21:33:28 UTC (rev 9046)
@@ -937,6 +937,8 @@
servletContext = new MockServletContext();
initServletContext(servletContext.getInitParameters());
ServletLifecycle.beginApplication(servletContext);
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
+ application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
new Initialization(servletContext).create().init();
((Init) servletContext.getAttribute(Seam.getComponentName(Init.class))).setDebug(false);
}
@@ -949,6 +951,8 @@
*/
protected void stopSeam() throws Exception
{
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
+ ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).setApplication(null);
ServletLifecycle.endApplication();
}
@@ -960,8 +964,6 @@
protected void setupClass() throws Exception
{
servletContext = (MockServletContext) ServletLifecycle.getServletContext();
- FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
- application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
phases = new SeamPhaseListener();
conversationViewRootAttributes = new HashMap<String, Map>();
seamFilter = createSeamFilter();
15 years, 8 months
Seam SVN: r9045 - branches/community/Seam_2_0/src/main/org/jboss/seam/mock.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 16:53:01 -0400 (Sat, 20 Sep 2008)
New Revision: 9045
Modified:
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
Log:
reference MockApplicationFactory class name in a type-safe way
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 20:35:39 UTC (rev 9044)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 20:53:01 UTC (rev 9045)
@@ -960,7 +960,7 @@
protected void setupClass() throws Exception
{
servletContext = (MockServletContext) ServletLifecycle.getServletContext();
- FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, "org.jboss.seam.mock.MockApplicationFactory");
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
phases = new SeamPhaseListener();
conversationViewRootAttributes = new HashMap<String, Map>();
15 years, 8 months
Seam SVN: r9044 - in branches/community/Seam_2_0/src: main/org/jboss/seam/international and 3 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2008-09-20 16:35:39 -0400 (Sat, 20 Sep 2008)
New Revision: 9044
Added:
branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplicationFactory.java
Modified:
branches/community/Seam_2_0/src/main/org/jboss/seam/international-2.0.xsd
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplication.java
branches/community/Seam_2_0/src/test/integration/resources/WEB-INF/components.xml
branches/community/Seam_2_0/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java
Log:
JBSEAM-3088
Also, enhanced the BaseSeamTest to use FactoryFinder to locate the MockApplication
so that external code can locate the same Application instance
Added: branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java (rev 0)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/international/LocaleConfig.java 2008-09-20 20:35:39 UTC (rev 9044)
@@ -0,0 +1,137 @@
+package org.jboss.seam.international;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.util.Strings;
+
+/**
+ * Configures the JSF locale support from the Seam container.
+ *
+ * <p>
+ * This component merely passes on configuration settings to the JSF runtime, so
+ * you still have to option of configure the locale support in the JSF
+ * configuration file. However, if you enable this component, it will overwrite
+ * any settings from that file.
+ * </p>
+ *
+ * <code>
+ * <i18n:locale-config default-locale="en" supported-locales="en fr de"/>
+ * </code>
+ *
+ * @author Dan Allen
+ */
+@Scope(APPLICATION)
+@BypassInterceptors
+@Startup
+@Name("org.jboss.seam.international.localeConfig")
+@Install(value = false, precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
+public class LocaleConfig
+{
+ private String defaultLocale;
+
+ private List<String> supportedLocales;
+
+ @Create
+ public void initLocaleConfig()
+ {
+ Application application = getApplication();
+ if (application == null)
+ {
+ return;
+ }
+
+ String defaultAsString = getDefaultLocale();
+ if (defaultAsString != null)
+ {
+ application.setDefaultLocale(getLocaleFromString(defaultAsString));
+ }
+
+ List<String> supportedAsStrings = getSupportedLocales();
+ int numSupported = supportedAsStrings != null ? supportedAsStrings.size() : 0;
+ if (numSupported > 0)
+ {
+ // use set to prevent duplicates, yet retain order just to be nice
+ Set<java.util.Locale> locales = new LinkedHashSet<java.util.Locale>(numSupported);
+ for (String supportedAsString : supportedAsStrings)
+ {
+ locales.add(getLocaleFromString(supportedAsString));
+ }
+ application.setSupportedLocales(locales);
+ }
+ }
+
+ public String getDefaultLocale()
+ {
+ return defaultLocale;
+ }
+
+ public void setDefaultLocale(String defaultLocale)
+ {
+ this.defaultLocale = defaultLocale;
+ }
+
+ public List<String> getSupportedLocales()
+ {
+ return supportedLocales;
+ }
+
+ public void setSupportedLocales(List<String> supportedLocales)
+ {
+ this.supportedLocales = supportedLocales;
+ }
+
+ public static LocaleConfig instance()
+ {
+ return (LocaleConfig) Component.getInstance(LocaleConfig.class, ScopeType.APPLICATION);
+ }
+
+ private java.util.Locale getLocaleFromString(String localeString)
+ {
+ if (localeString == null || localeString.length() < 2)
+ {
+ throw new IllegalArgumentException("Invalid locale string: " + localeString);
+ }
+
+ StringTokenizer tokens = new StringTokenizer(localeString, "-_");
+ String language = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ String country = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ String variant = tokens.hasMoreTokens() ? tokens.nextToken() : null;
+ if (!Strings.isEmpty(variant))
+ {
+ return new java.util.Locale(language, country, variant);
+ }
+ else if (!Strings.isEmpty(country))
+ {
+ return new java.util.Locale(language, country);
+ }
+ else
+ {
+ return new java.util.Locale(language);
+ }
+ }
+
+ private Application getApplication()
+ {
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
+ return factory.getApplication();
+ }
+}
\ No newline at end of file
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/international-2.0.xsd
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/international-2.0.xsd 2008-09-20 17:08:27 UTC (rev 9043)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/international-2.0.xsd 2008-09-20 20:35:39 UTC (rev 9044)
@@ -4,6 +4,21 @@
xmlns:components="http://jboss.com/products/seam/components" attributeFormDefault="unqualified">
<xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="components-2.0.xsd"/>
+ <xs:element name="locale-config">
+ <xs:complexType mixed="true">
+ <xs:choice minOccurs="0" maxOccurs="1">
+ <xs:element ref="international:supported-locales"/>
+ </xs:choice>
+ <xs:attributeGroup ref="components:attlist.component"/>
+ <xs:attributeGroup ref="international:attlist.localeConfig"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="supported-locales" type="components:multiValuedProperty"/>
+ <xs:attributeGroup name="attlist.localeConfig">
+ <xs:attribute name="default-locale" type="xs:string"/>
+ <xs:attribute name="supported-locales" type="xs:string"/>
+ </xs:attributeGroup>
+
<xs:element name="locale-selector">
<xs:complexType mixed="true">
<xs:attributeGroup ref="components:attlist.component"/>
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 17:08:27 UTC (rev 9043)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/BaseSeamTest.java 2008-09-20 20:35:39 UTC (rev 9044)
@@ -12,7 +12,9 @@
import javax.el.ELResolver;
import javax.el.ValueExpression;
+import javax.faces.FactoryFinder;
import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
@@ -47,7 +49,6 @@
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Renderer;
import org.jboss.seam.init.Initialization;
-import org.jboss.seam.jsf.SeamApplication;
import org.jboss.seam.jsf.SeamPhaseListener;
import org.jboss.seam.mail.MailSession;
import org.jboss.seam.pageflow.Pageflow;
@@ -959,7 +960,8 @@
protected void setupClass() throws Exception
{
servletContext = (MockServletContext) ServletLifecycle.getServletContext();
- application = new SeamApplication(new MockApplication());
+ FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, "org.jboss.seam.mock.MockApplicationFactory");
+ application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
phases = new SeamPhaseListener();
conversationViewRootAttributes = new HashMap<String, Map>();
seamFilter = createSeamFilter();
Modified: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplication.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplication.java 2008-09-20 17:08:27 UTC (rev 9043)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplication.java 2008-09-20 20:35:39 UTC (rev 9044)
@@ -54,6 +54,7 @@
private javax.el.CompositeELResolver elResolver;
private javax.el.CompositeELResolver additionalResolvers;
+ private Collection locales;
public MockApplication()
{
@@ -374,13 +375,20 @@
@Override
public Iterator getSupportedLocales()
{
- return Collections.singleton(defaultLocale).iterator();
+ if (locales == null)
+ {
+ return Collections.singleton(defaultLocale).iterator();
+ }
+ else
+ {
+ return locales.iterator();
+ }
}
@Override
public void setSupportedLocales(Collection locales)
{
- throw new UnsupportedOperationException();
+ this.locales = locales;
}
private final Map<String, Validator> validatorsById = new HashMap<String, Validator>();
Added: branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplicationFactory.java
===================================================================
--- branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplicationFactory.java (rev 0)
+++ branches/community/Seam_2_0/src/main/org/jboss/seam/mock/MockApplicationFactory.java 2008-09-20 20:35:39 UTC (rev 9044)
@@ -0,0 +1,41 @@
+package org.jboss.seam.mock;
+
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+import org.jboss.seam.jsf.SeamApplication;
+
+/**
+ * An mock implementation of the JSF ApplicationFactory which returns a mock
+ * Application wrapped in a SeamApplication. This class can be registered with
+ * JSF to allow JSF to be used formally in a test environment as follows:
+ *
+ * <code>
+ * FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+ * "org.jboss.seam.mock.MockApplicationFactory");
+ * Application application = ((ApplicationFactory) FactoryFinder
+ * .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ * </code>
+ *
+ * @author Dan Allen
+ */
+public class MockApplicationFactory extends ApplicationFactory
+{
+ private Application application;
+
+ @Override
+ public Application getApplication()
+ {
+ if (application == null) {
+ application = new SeamApplication(new MockApplication());
+ }
+ return application;
+ }
+
+ @Override
+ public void setApplication(Application application)
+ {
+ this.application = application;
+ }
+
+}
Modified: branches/community/Seam_2_0/src/test/integration/resources/WEB-INF/components.xml
===================================================================
--- branches/community/Seam_2_0/src/test/integration/resources/WEB-INF/components.xml 2008-09-20 17:08:27 UTC (rev 9043)
+++ branches/community/Seam_2_0/src/test/integration/resources/WEB-INF/components.xml 2008-09-20 20:35:39 UTC (rev 9044)
@@ -2,6 +2,7 @@
<components xmlns="http://jboss.com/products/seam/components"
xmlns:bpm="http://jboss.com/products/seam/bpm"
xmlns:core="http://jboss.com/products/seam/core"
+ xmlns:i18n="http://jboss.com/products/seam/international"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:web="http://jboss.com/products/seam/web"
@@ -11,6 +12,7 @@
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
+ http://jboss.com/products/seam/international http://jboss.com/products/seam/international-2.0.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
@@ -23,6 +25,8 @@
<core:manager concurrent-request-timeout="500"
conversation-timeout="120000"
conversation-id-parameter="cid"/>
+
+ <i18n:locale-config default-locale="fr_CA" supported-locales="fr_CA fr_FR en"/>
<persistence:managed-persistence-context name="entityManager"
auto-create="true"
Modified: branches/community/Seam_2_0/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java
===================================================================
--- branches/community/Seam_2_0/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java 2008-09-20 17:08:27 UTC (rev 9043)
+++ branches/community/Seam_2_0/src/test/integration/src/org/jboss/seam/test/integration/i8ln/LocaleTest.java 2008-09-20 20:35:39 UTC (rev 9044)
@@ -1,5 +1,8 @@
package org.jboss.seam.test.integration.i8ln;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import javax.faces.component.UIOutput;
@@ -20,6 +23,25 @@
@Override
protected void invokeApplication() throws Exception
{
+ // <i18:locale-config default-locale="fr_CA" supported-locales="fr_CA fr_FR en"/>
+ List<Locale> supportedLocales = new ArrayList<Locale>();
+ for (Iterator<Locale> iter = getFacesContext().getApplication().getSupportedLocales(); iter.hasNext();)
+ {
+ supportedLocales.add(iter.next());
+ }
+ assert supportedLocales.size() == 3;
+ assert supportedLocales.contains(Locale.CANADA_FRENCH);
+ assert supportedLocales.contains(Locale.ENGLISH);
+ assert supportedLocales.contains(Locale.FRANCE);
+ assert getFacesContext().getApplication().getDefaultLocale().equals(Locale.CANADA_FRENCH);
+
+ // why not? I guess be default locale means different things in different contexts (server vs user)
+ //assert org.jboss.seam.international.Locale.instance().equals(Locale.CANADA_FRENCH);
+
+ // reset the locale configuration (as it would be w/o <i18n:locale-config>)
+ getFacesContext().getApplication().setDefaultLocale(Locale.ENGLISH);
+ getFacesContext().getApplication().setSupportedLocales(null);
+
assert org.jboss.seam.international.Locale.instance().equals(Locale.getDefault());
LocaleSelector.instance().setLocale(Locale.UK);
15 years, 8 months