[seam-commits] Seam SVN: r10668 - in modules/trunk: el/src and 25 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Apr 28 02:04:29 EDT 2009
Author: dan.j.allen
Date: 2009-04-28 02:04:29 -0400 (Tue, 28 Apr 2009)
New Revision: 10668
Added:
modules/trunk/el/src/main/java/org/jboss/seam/el/AbstractELResolver.java
modules/trunk/el/src/main/java/org/jboss/seam/el/SeamEL.java
modules/trunk/el/src/test/
modules/trunk/el/src/test/java/
modules/trunk/el/src/test/java/org/
modules/trunk/el/src/test/java/org/jboss/
modules/trunk/el/src/test/java/org/jboss/seam/
modules/trunk/el/src/test/java/org/jboss/seam/el/
modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java
modules/trunk/el/src/test/resources/
modules/trunk/el/src/test/resources/test-suite.xml
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesResourceLoader.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/LocaleConfig.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplication.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplicationFactory.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/el/
modules/trunk/faces/src/main/java/org/jboss/seam/faces/el/SeamFacesELResolver.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/StatusMessagesTranslator.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/
modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ArrayDataModel.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ListDataModel.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/MapDataModel.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/SetDataModel.java
modules/trunk/faces/src/main/resources/
modules/trunk/faces/src/main/resources/META-INF/
modules/trunk/faces/src/main/resources/META-INF/faces-config.xml
modules/trunk/international/src/main/java/org/jboss/seam/core/
modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java
modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java
modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceBundle.java
modules/trunk/international/src/test/java/org/
modules/trunk/international/src/test/java/org/jboss/
modules/trunk/international/src/test/java/org/jboss/seam/
modules/trunk/international/src/test/java/org/jboss/seam/international/
Removed:
modules/trunk/el/src/main/java/org/jboss/seam/el/EL.java
modules/trunk/el/src/main/java/org/jboss/seam/el/Interpolator.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/DateConverter.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManager.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesPage.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/HttpError.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/IsUserInRole.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Navigator.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Parameters.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Redirect.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Renderer.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/ResourceLoader.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Selector.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Switcher.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/UiComponent.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/UserPrincipal.java
modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleConfig.java
modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleSelector.java
modules/trunk/international/src/main/java/org/jboss/seam/international/SeamResourceBundle.java
modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java
Modified:
modules/trunk/el/pom.xml
modules/trunk/el/src/main/java/org/jboss/seam/el/Expressions.java
modules/trunk/el/src/main/java/org/jboss/seam/el/JBossELReferenceCache.java
modules/trunk/el/src/main/java/org/jboss/seam/el/SeamELResolver.java
modules/trunk/el/src/main/java/org/jboss/seam/el/SeamExpressionFactory.java
modules/trunk/el/src/main/java/org/jboss/seam/el/SeamFunctionMapper.java
modules/trunk/faces/pom.xml
modules/trunk/faces/src/main/java/org/jboss/seam/faces/DataModels.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesContextProducer.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesExpressions.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesMessages.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/Validation.java
modules/trunk/international/pom.xml
modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java
modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java
modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceLoader.java
modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessage.java
modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java
modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java
modules/trunk/parent/pom.xml
Log:
bring the el, international, and faces modules to a compilable state
several components had to be disabled to achieve, but they will be reintroduced as needed
Modified: modules/trunk/el/pom.xml
===================================================================
--- modules/trunk/el/pom.xml 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/pom.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,35 +1,61 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>seam-parent</artifactId>
- <groupId>org.jboss.seam</groupId>
+ <groupId>org.jboss.seam</groupId>
<version>3.0.0-SNAPSHOT</version>
- </parent>
-
+ </parent>
+
<artifactId>seam-el</artifactId>
<packaging>jar</packaging>
<version>3.0.0-SNAPSHOT</version>
- <name>Seam EL</name>
-
+ <name>Seam EL Module</name>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/test-suite.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
<dependencies>
+ <!-- TODO pull up -->
<dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+ <dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
- </dependency>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.el</groupId>
<artifactId>jboss-el</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>jsr299-api</artifactId>
- </dependency>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>webbeans-logging</artifactId>
+ <!-- provided? -->
</dependency>
</dependencies>
Added: modules/trunk/el/src/main/java/org/jboss/seam/el/AbstractELResolver.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/AbstractELResolver.java (rev 0)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/AbstractELResolver.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.el;
+
+import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+/**
+ * <p>An abstract {@link ELResolver} that provides default implementations for
+ * the methods which most implementations never care to override.</p>
+ *
+ * <p>The read operations mostly return <code>null</code> and the write
+ * operation performs no action. Subclasses are expected to provide an
+ * implementation for {@link ELResolver#getValue(javax.el.ELContext,
+ * java.lang.Object, java.lang.Object)}, the only really interesting method.
+ *
+ * @author Dan Allen
+ */
+public abstract class AbstractELResolver extends ELResolver {
+
+ /**
+ * A default implementation that returns <code>null</code> unconditionally.
+ *
+ * @see ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
+ return null;
+ }
+
+ /**
+ * A default implementation that returns <code>null</code> unconditionally.
+ *
+ * @see ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
+ return null;
+ }
+
+ /**
+ * A default implementation that returns <code>null</code> unconditionally.
+ *
+ * @see ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Class getType(ELContext context, Object base, Object property)
+ {
+ return null;
+ }
+
+ /**
+ * A default implementation that returns <code>false</code> unconditionally.
+ *
+ * @see ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ return false;
+ }
+
+ /**
+ * A default implementation that performs no operation.
+ *
+ * @see ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ {
+ }
+
+}
Deleted: modules/trunk/el/src/main/java/org/jboss/seam/el/EL.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/EL.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/EL.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,147 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Id$
- */
-package org.jboss.seam.el;
-
-import java.util.Locale;
-
-import javax.el.ArrayELResolver;
-import javax.el.BeanELResolver;
-import javax.el.CompositeELResolver;
-import javax.el.ELContext;
-import javax.el.ELResolver;
-import javax.el.ExpressionFactory;
-import javax.el.FunctionMapper;
-import javax.el.ListELResolver;
-import javax.el.MapELResolver;
-import javax.el.ResourceBundleELResolver;
-import javax.el.VariableMapper;
-
-import org.jboss.el.ExpressionFactoryImpl;
-import org.jboss.el.lang.FunctionMapperImpl;
-import org.jboss.el.lang.VariableMapperImpl;
-
-/**
- * An instance of JBoss EL.
- *
- * @author Gavin King
- */
-public class EL
-{
- public static final ELResolver EL_RESOLVER = createELResolver();
- public static final ExpressionFactory EXPRESSION_FACTORY = new ExpressionFactoryImpl();
-
- private static ELResolver createELResolver()
- {
- CompositeELResolver resolver = new CompositeELResolver();
- resolver.add(new MapELResolver());
- resolver.add(new ListELResolver());
- resolver.add(new ArrayELResolver());
- resolver.add(new ResourceBundleELResolver());
- resolver.add(new BeanELResolver());
- return resolver;
- }
-
- public static ELContext createELContext()
- {
- return createELContext(EL_RESOLVER, new FunctionMapperImpl());
- }
-
- public static ELContext createELContext(final ELResolver resolver, final FunctionMapper functionMapper)
- {
- return new ELContext()
- {
- final VariableMapperImpl variableMapper = new VariableMapperImpl();
-
- @Override
- public ELResolver getELResolver()
- {
- return resolver;
- }
-
- @Override
- public FunctionMapper getFunctionMapper()
- {
- return functionMapper;
- }
-
- @Override
- public VariableMapper getVariableMapper()
- {
- return variableMapper;
- }
- };
- }
-
- public static ELContext createELContext(final ELContext context, final ELResolver resolver)
- {
- return new ELContext()
- {
- @Override
- public Locale getLocale()
- {
- return context.getLocale();
- }
-
- @Override
- public void setPropertyResolved(boolean value)
- {
- super.setPropertyResolved(value);
- context.setPropertyResolved(value);
- }
-
- @Override
- public void putContext(Class clazz, Object object)
- {
- super.putContext(clazz, object);
- context.putContext(clazz, object);
- }
-
- @Override
- public Object getContext(Class clazz)
- {
- return context.getContext(clazz);
- }
-
- @Override
- public void setLocale(Locale locale)
- {
- super.setLocale(locale);
- context.setLocale(locale);
- }
-
- @Override
- public ELResolver getELResolver()
- {
- return resolver;
- }
-
- @Override
- public FunctionMapper getFunctionMapper()
- {
- return context.getFunctionMapper();
- }
-
- @Override
- public VariableMapper getVariableMapper()
- {
- return context.getVariableMapper();
- }
- };
- }
-}
Modified: modules/trunk/el/src/main/java/org/jboss/seam/el/Expressions.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/Expressions.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/Expressions.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
package org.jboss.seam.el;
import java.io.Serializable;
@@ -6,9 +29,6 @@
import javax.el.ELContext;
import javax.el.ExpressionFactory;
-import org.jboss.seam.el.EL;
-import org.jboss.seam.el.SeamExpressionFactory;
-
/**
* Factory for EL method and value expressions.
*
@@ -34,7 +54,7 @@
* use JSF's ELContext. Otherwise, use one that we create.
*/
public ELContext getELContext() {
- return EL.createELContext();
+ return SeamEL.createELContext();
}
/**
Deleted: modules/trunk/el/src/main/java/org/jboss/seam/el/Interpolator.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/Interpolator.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/Interpolator.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,171 +0,0 @@
-package org.jboss.seam.el;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-import javax.context.Dependent;
-import javax.inject.Current;
-
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-/**
- * Interpolates EL expressions in Strings
- *
- * @author Gavin King
- */
- at Dependent
-public class Interpolator
-{
- private static final LogProvider log = Logging.getLogProvider(Interpolator.class);
-
- @Current Expressions expressions;
- @Current Locale locale;
-
- /**
- * Replace all EL expressions in the form #{...} with their evaluated values.
- *
- * @param string
- * a template
- * @return the interpolated string
- */
- public String interpolate(String string, Object... params)
- {
- if (params == null)
- {
- params = new Object[0];
- }
-
- if (params.length > 10)
- {
- throw new IllegalArgumentException("more than 10 parameters");
- }
-
- if (string.indexOf('#') >= 0 || string.indexOf('{') >= 0)
- {
- string = interpolateExpressions(string, params);
- }
-
- return string;
- }
-
- private String interpolateExpressions(String string, Object... params)
- {
- StringTokenizer tokens = new StringTokenizer(string, "#{}", true);
- StringBuilder builder = new StringBuilder(string.length());
- try
- {
- while (tokens.hasMoreTokens())
- {
- String tok = tokens.nextToken();
-
- if ("#".equals(tok) && tokens.hasMoreTokens())
- {
- String nextTok = tokens.nextToken();
-
- while (nextTok.equals("#") && tokens.hasMoreTokens())
- {
- builder.append(tok);
- nextTok = tokens.nextToken();
- }
-
- if ("{".equals(nextTok))
- {
- String expression = "#{" + tokens.nextToken() + "}";
- try
- {
- Object value = expressions.createValueExpression(expression).getValue();
- if (value != null)
- builder.append(value);
- } catch (Exception e)
- {
- log.warn("exception interpolating string: " + string, e);
- }
- tokens.nextToken(); // the trailing "}"
-
- } else if (nextTok.equals("#"))
- {
- // could be trailing #
- builder.append("#");
-
- } else
- {
- int index;
- try
- {
- index = Integer.parseInt(nextTok.substring(0, 1));
- if (index >= params.length)
- {
- // log.warn("parameter index out of bounds: " + index +
- // " in: " + string);
- builder.append("#").append(nextTok);
- } else
- {
- builder.append(params[index]).append(
- nextTok.substring(1));
- }
- } catch (NumberFormatException nfe)
- {
- builder.append("#").append(nextTok);
- }
- }
- } else if ("{".equals(tok))
- {
- StringBuilder expr = new StringBuilder();
-
- expr.append(tok);
- int level = 1;
-
- while (tokens.hasMoreTokens())
- {
- String nextTok = tokens.nextToken();
- expr.append(nextTok);
-
- if (nextTok.equals("{"))
- {
- ++level;
- } else if (nextTok.equals("}"))
- {
- if (--level == 0)
- {
- try
- {
- if (params.length == 0)
- {
- builder.append(expr.toString());
- } else
- {
- String value = new MessageFormat(expr.toString(),
- locale).format(params);
- builder.append(value);
- }
- } catch (Exception e)
- {
- // if it is a bad message, use the expression itself
- builder.append(expr);
- }
- expr = null;
- break;
- }
- }
- }
-
- if (expr != null)
- {
- builder.append(expr);
- }
- } else
- {
- builder.append(tok);
- }
- }
- } catch (Exception e)
- {
- log.warn("exception interpolating string: " + string, e);
- }
-
- return builder.toString();
- }
-
-}
Modified: modules/trunk/el/src/main/java/org/jboss/seam/el/JBossELReferenceCache.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/JBossELReferenceCache.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/JBossELReferenceCache.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
package org.jboss.seam.el;
import javax.annotation.PreDestroy;
Copied: modules/trunk/el/src/main/java/org/jboss/seam/el/SeamEL.java (from rev 10658, modules/trunk/el/src/main/java/org/jboss/seam/el/EL.java)
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/SeamEL.java (rev 0)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/SeamEL.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.el;
+
+import java.util.Locale;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import javax.el.VariableMapper;
+
+import org.jboss.el.ExpressionFactoryImpl;
+import org.jboss.el.lang.FunctionMapperImpl;
+import org.jboss.el.lang.VariableMapperImpl;
+
+/**
+ * An instance of JBoss EL.
+ *
+ * @author Gavin King
+ */
+public class SeamEL
+{
+ public static final ELResolver EL_RESOLVER = createELResolver();
+ public static final ExpressionFactory EXPRESSION_FACTORY = new ExpressionFactoryImpl();
+
+ private static ELResolver createELResolver()
+ {
+ // I believe this resolver is for use in standalone (not JSF doing the resolving)
+ CompositeELResolver resolver = new CompositeELResolver();
+ resolver.add(new SeamELResolver());
+ resolver.add(new MapELResolver());
+ resolver.add(new ListELResolver());
+ resolver.add(new ArrayELResolver());
+ resolver.add(new ResourceBundleELResolver());
+ resolver.add(new BeanELResolver());
+ return resolver;
+ }
+
+ public static ELContext createELContext()
+ {
+ return createELContext(EL_RESOLVER);
+ }
+
+ public static ELContext createELContext(final ELResolver resolver)
+ {
+ return createELContext(resolver, new FunctionMapperImpl(), new VariableMapperImpl());
+ }
+
+ public static ELContext createELContext(final ELResolver resolver, final FunctionMapper functionMapper, final VariableMapper variableMapper)
+ {
+ return new ELContext()
+ {
+ @Override
+ public ELResolver getELResolver()
+ {
+ return resolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper()
+ {
+ return functionMapper;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper()
+ {
+ return variableMapper;
+ }
+ };
+ }
+
+ public static ELContext createELContext(final ELContext context, final ELResolver resolver)
+ {
+ return new ELContext()
+ {
+ @Override
+ public Locale getLocale()
+ {
+ return context.getLocale();
+ }
+
+ @Override
+ public void setPropertyResolved(boolean value)
+ {
+ super.setPropertyResolved(value);
+ context.setPropertyResolved(value);
+ }
+
+ @Override
+ public void putContext(Class clazz, Object object)
+ {
+ super.putContext(clazz, object);
+ context.putContext(clazz, object);
+ }
+
+ @Override
+ public Object getContext(Class clazz)
+ {
+ return context.getContext(clazz);
+ }
+
+ @Override
+ public void setLocale(Locale locale)
+ {
+ super.setLocale(locale);
+ context.setLocale(locale);
+ }
+
+ @Override
+ public ELResolver getELResolver()
+ {
+ return resolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper()
+ {
+ return context.getFunctionMapper();
+ }
+
+ @Override
+ public VariableMapper getVariableMapper()
+ {
+ return context.getVariableMapper();
+ }
+ };
+ }
+}
Modified: modules/trunk/el/src/main/java/org/jboss/seam/el/SeamELResolver.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/SeamELResolver.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/SeamELResolver.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,189 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
package org.jboss.seam.el;
-import org.jboss.seam.util.JSF;
-
import java.util.Collection;
-import java.util.Iterator;
import java.util.Map;
import javax.el.ELContext;
-import javax.el.ELResolver;
-import org.jboss.seam.Namespace;
-import org.jboss.seam.contexts.Context;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Init;
-
/**
- * Resolves Seam components and namespaces. Also
- * allows the use of #{dataModel.size}, #{dataModel.empty},
- * #{collection.size}, #{map.size}, #{map.values}, #{map.keySet},
- * and #{map.entrySet}. Also allows #{sessionContext['name']}.
- *
- * @author Gavin King
+ * <p>An {@link ELResolver} implementation that adds magic properties
+ * to collections and maps and (pending) supports resolving objects in Java EE
+ * contexts.</p>
*
+ * <p>The following is a list of the magic properties add to a collection:</p>
+ *
+ * <ul>
+ * <li>size - the size of the collection</li>
+ * </ul>
+ *
+ * <p>The following is a list of the magic properties add to a map:</p>
+ *
+ * <ul>
+ * <li>size - the size of the map</li>
+ * <li>values - a collection of the map values</li>
+ * <li>keySet - a set of the map keys</li>
+ * <li>entrySet - a set of the map entries (key and value)</li>
+ * </ul>
+ *
+ * <p>Assuming the variable <code>results</code> held a reference to a collection
+ * you could print out its size using the following expression:</p>
+ *
+ * <pre>#{results.size}</pre>
+ *
+ * @author Gavin King
+ * @author Dan Allen
*/
-public class SeamELResolver extends ELResolver
+public class SeamELResolver extends AbstractELResolver
{
-
@Override
- public Class getCommonPropertyType(ELContext context, Object base)
+ public Object getValue(ELContext context, Object base, Object property)
{
- return null;
- }
+ if (base instanceof Collection)
+ {
+ return resolveInCollection(context, (Collection) base, property);
+ }
+ else if (base instanceof Map)
+ {
+ return resolveInMap(context, (Map) base, property);
+ }
+// update JavaDoc after enabling
+// else if (base instanceof Context)
+// {
+// return resolveInContextObject(context, (Context) base, property);
+//
+// }
- @Override
- public Iterator getFeatureDescriptors(ELContext context, Object base)
- {
return null;
}
- @Override
- public Class getType(ELContext context, Object base, Object property)
+ /*
+ private Object resolveInContextObject(ELContext context, Context seamContext, Object property)
{
- return null;
- }
+ if (seamContext.isSet((String) property))
+ {
+ context.setPropertyResolved(true);
+ return seamContext.get((String) property);
+ }
+ else
+ {
+ return null;
+ }
+ }*/
- @Override
- public Object getValue(ELContext context, Object base, Object property)
+ private Object resolveInMap(ELContext context, Map map, Object property)
{
- if (base == null) {
- return resolveBase(context, property);
-
- } else if (base instanceof Namespace) {
- return resolveInNamespace(context, (Namespace) base, property);
-
- } else if (JSF.DATA_MODEL.isInstance(base)) {
- return resolveInDataModel(context, base, property);
-
- } else if (base instanceof Collection) {
- return resolveInCollection(context, (Collection) base, property);
-
- } else if (base instanceof Map) {
- return resolveInMap(context, (Map) base, property);
-
- } else if (base instanceof Context) {
- return resolveInContextObject(context, (Context) base, property);
-
- } else {
+ try
+ {
+ if (map.containsKey(property))
+ {
return null;
- }
- }
+ }
+ }
+ catch (UnsupportedOperationException e)
+ {
+ // eat it
+ }
- private Object resolveInContextObject(ELContext context, Context seamContext, Object property)
- {
- if (seamContext.isSet((String) property)) {
- context.setPropertyResolved(true);
- return seamContext.get((String) property);
- } else {
- return null;
- }
- }
+ if ("size".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return map.size();
+ }
+ else if ("values".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return map.values();
+ }
+ else if ("keySet".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return map.keySet();
+ }
+ else if ("entrySet".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return map.entrySet();
+ }
+ else
+ {
+ return null;
+ }
+ }
- private Object resolveInMap(ELContext context, Map map, Object property) {
- try {
- if (map.containsKey(property)) {
- return null;
- }
- } catch (UnsupportedOperationException e) {
- // eat it
- }
-
- if ("size".equals(property)) {
- context.setPropertyResolved(true);
- return map.size();
-
- } else if ("values".equals(property)) {
- context.setPropertyResolved(true);
- return map.values();
-
- } else if ("keySet".equals(property)) {
- context.setPropertyResolved(true);
- return map.keySet();
-
- } else if ("entrySet".equals(property)) {
- context.setPropertyResolved(true);
- return map.entrySet();
-
- } else {
- return null;
- }
- }
-
private Object resolveInCollection(ELContext context, Collection collection, Object property)
{
- if ("size".equals(property)) {
- context.setPropertyResolved(true);
- return collection.size();
- } else {
- return null;
- }
- }
+ if ("size".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return collection.size();
+ }
+ else
+ {
+ return null;
+ }
+ }
- private Object resolveInDataModel(ELContext context, Object base, Object property)
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
{
- if ("size".equals(property)) {
- context.setPropertyResolved(true);
- return JSF.getRowCount(base);
- } else if ("empty".equals(property)) {
- context.setPropertyResolved(true);
- return JSF.getRowCount(base) == 0;
- } else {
- return null;
- }
- }
-
- private Object resolveBase(ELContext context, Object property)
- {
- if (!Contexts.isApplicationContextActive()) {
- // if no Seam contexts, bypass straight through to JSF
- return null;
- }
-
- String key = (String) property;
- Init init = Init.instance();
-
- // look for a component in the root namespace
- Object result = init.getRootNamespace().getComponentInstance(key);
- if (result != null) {
- context.setPropertyResolved(true);
- return result;
- } else {
- // look for a component in the imported namespaces
- for (Namespace ns : init.getGlobalImports()) {
- result = ns.getComponentInstance(key);
- if (result != null) {
- context.setPropertyResolved(true);
- return result;
- }
- }
- }
-
- // look for a namespace
- Namespace namespace = init.getRootNamespace().getChild(key);
- if (namespace != null) {
- context.setPropertyResolved(true);
- }
- return namespace;
- }
-
- private Object resolveInNamespace(ELContext context, Namespace namespace, Object property) {
- Object result = namespace.get((String) property);
- // JBSEAM-3077 if the result is null, it means that there is no component instance bound to this qualified name
- context.setPropertyResolved(true);
- return result;
- }
-
- @Override
- public boolean isReadOnly(ELContext context, Object base, Object property)
- {
- return base != null
- && (JSF.DATA_MODEL.isInstance(base) || (base instanceof Collection) || (base instanceof Map));
- }
-
- @Override
- public void setValue(ELContext context, Object base, Object property, Object value)
- {
- }
-
+ return base instanceof Collection || base instanceof Map;
+ }
}
Modified: modules/trunk/el/src/main/java/org/jboss/seam/el/SeamExpressionFactory.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/SeamExpressionFactory.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/SeamExpressionFactory.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -4,16 +4,21 @@
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
*
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
* $Id$
*/
package org.jboss.seam.el;
@@ -30,7 +35,7 @@
*/
public class SeamExpressionFactory extends ExpressionFactory
{
- public static final ExpressionFactory INSTANCE = new SeamExpressionFactory(EL.EXPRESSION_FACTORY);
+ public static final ExpressionFactory INSTANCE = new SeamExpressionFactory(SeamEL.EXPRESSION_FACTORY);
private final ExpressionFactory expressionFactory;
Modified: modules/trunk/el/src/main/java/org/jboss/seam/el/SeamFunctionMapper.java
===================================================================
--- modules/trunk/el/src/main/java/org/jboss/seam/el/SeamFunctionMapper.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/el/src/main/java/org/jboss/seam/el/SeamFunctionMapper.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
package org.jboss.seam.el;
import java.lang.reflect.Method;
@@ -11,7 +34,7 @@
import org.jboss.el.lang.ExtendedFunctionMapper;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.seam.security.SecurityFunctions;
+//import org.jboss.seam.security.SecurityFunctions;
/**
* Resolves Seam Security EL functions, s:hasRole() and s:hasPermission()
@@ -34,12 +57,15 @@
static
{
+ /*
+ FIXME where should this class go so that these functions can be loaded?
cacheMethod("hasPermission", SecurityFunctions.class, "hasPermission",
new Class[] {String.class, String.class, Object.class});
cacheMethod("hasPermission", SecurityFunctions.class, "hasPermission",
new Class[] {Object.class, String.class});
cacheMethod("hasRole", SecurityFunctions.class, "hasRole",
- new Class[] { String.class });
+ new Class[] { String.class });
+ */
}
@Override
Added: modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java
===================================================================
--- modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java (rev 0)
+++ modules/trunk/el/src/test/java/org/jboss/seam/el/SeamELResolverUnitTest.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,132 @@
+package org.jboss.seam.el;
+
+import static org.testng.Assert.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+import org.testng.annotations.Test;
+
+/**
+ * Verify that the magic properties are properly resolved
+ * by the {@link SeamELResolver}.
+ *
+ * @author Dan Allen
+ * @see SeamELResolver
+ */
+public class SeamELResolverUnitTest
+{
+ @Test
+ public void testUnhandled()
+ {
+ ELContext ctx = new ELContextImpl(new SeamELResolver());
+
+ Object result = ctx.getELResolver().getValue(ctx, new Object(), "size");
+ assertNull(result);
+ assertFalse(ctx.isPropertyResolved());
+ }
+
+ @Test
+ public void testCollectionSizeProperty()
+ {
+ ELContext ctx = new ELContextImpl(new SeamELResolver());
+ Collection<String> c = createSampleCollection();
+
+ Object result = ctx.getELResolver().getValue(ctx, c, "size");
+ assertEquals(result, 2);
+ assertTrue(ctx.isPropertyResolved());
+
+ ctx = new ELContextImpl(new SeamELResolver());
+ c.add("three");
+
+ result = ctx.getELResolver().getValue(ctx, c, "size");
+ assertEquals(result, 3);
+ assertTrue(ctx.isPropertyResolved());
+ }
+
+ @Test
+ public void testCollectionBogusProperty()
+ {
+ ELContext ctx = new ELContextImpl(new SeamELResolver());
+ Collection<String> c = createSampleCollection();
+
+ Object result = ctx.getELResolver().getValue(ctx, c, "bogus");
+ assertNull(result);
+ assertFalse(ctx.isPropertyResolved());
+ }
+
+ @Test
+ public void testMapSize()
+ {
+ ELContext ctx = new ELContextImpl(new SeamELResolver());
+ Map<String, Integer> m = createSampleMap();
+
+ Object result = ctx.getELResolver().getValue(ctx, m, "size");
+ assertEquals(result, 2);
+ assertTrue(ctx.isPropertyResolved());
+
+ ctx = new ELContextImpl(new SeamELResolver());
+ m.put("three", 3);
+
+ result = ctx.getELResolver().getValue(ctx, m, "size");
+ assertEquals(result, 3);
+ assertTrue(ctx.isPropertyResolved());
+ }
+
+ @Test
+ public void testMapBogusProperty()
+ {
+ ELContext ctx = new ELContextImpl(new SeamELResolver());
+ Map<String, Integer> m = createSampleMap();
+
+ Object result = ctx.getELResolver().getValue(ctx, m, "bogus");
+ assertNull(result);
+ assertFalse(ctx.isPropertyResolved());
+ }
+
+ private Collection<String> createSampleCollection() {
+ Collection<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add("two");
+ return c;
+ }
+
+ private Map<String, Integer> createSampleMap() {
+ Map<String, Integer> m = new LinkedHashMap<String, Integer>();
+ m.put("one", 1);
+ m.put("two", 2);
+ return m;
+ }
+
+ private class ELContextImpl extends ELContext
+ {
+ private ELResolver resolver;
+
+ private ELContextImpl(ELResolver resolver)
+ {
+ this.resolver = resolver;
+ }
+
+ @Override
+ public ELResolver getELResolver()
+ {
+ return resolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper()
+ {
+ throw new AssertionError();
+ }
+
+ @Override
+ public VariableMapper getVariableMapper()
+ {
+ throw new AssertionError();
+ }
+ }
+}
Added: modules/trunk/el/src/test/resources/test-suite.xml
===================================================================
--- modules/trunk/el/src/test/resources/test-suite.xml (rev 0)
+++ modules/trunk/el/src/test/resources/test-suite.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,15 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Seam EL Module Unit Tests" verbose="1">
+ <test name="Seam EL Module Unit Tests">
+ <!--
+ <method-selectors>
+ <method-selector>
+ <selector-class name="org.jboss.testharness.impl.testng.DisableIntegrationTestsMethodSelector"/>
+ </method-selector>
+ </method-selectors>
+ -->
+ <packages>
+ <package name="org.jboss.seam.el"/>
+ </packages>
+ </test>
+</suite>
Modified: modules/trunk/faces/pom.xml
===================================================================
--- modules/trunk/faces/pom.xml 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/pom.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,36 +1,48 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
<parent>
<artifactId>seam-parent</artifactId>
- <groupId>org.jboss.seam</groupId>
+ <groupId>org.jboss.seam</groupId>
<version>3.0.0-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.seam</groupId>
+ </parent>
+
<artifactId>seam-faces</artifactId>
<packaging>jar</packaging>
<version>3.0.0-SNAPSHOT</version>
- <name>Seam Faces</name>
-
+ <name>Seam Faces Module</name>
+
<dependencies>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>seam-el</artifactId>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>seam-international</artifactId>
+ </dependency>
+ <dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
- </dependency>
+ <scope>provided</scope>
+ </dependency>
<dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>jsr299-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-api</artifactId>
- </dependency>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/DataModels.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/DataModels.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/DataModels.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -5,15 +5,12 @@
import java.util.Set;
import javax.faces.model.DataModel;
+import org.jboss.seam.faces.model.ArrayDataModel;
+import org.jboss.seam.faces.model.ListDataModel;
+import org.jboss.seam.faces.model.MapDataModel;
+import org.jboss.seam.faces.model.SetDataModel;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.framework.Query;
-import org.jboss.seam.jsf.ArrayDataModel;
-import org.jboss.seam.jsf.ListDataModel;
-import org.jboss.seam.jsf.MapDataModel;
-import org.jboss.seam.jsf.SetDataModel;
-
+//import org.jboss.seam.framework.Query;
/**
* Wraps a collection as a JSF {@link DataModel}. May be overridden
* and extended if you don't like the built in collections
@@ -23,7 +20,6 @@
*/
public class DataModels
{
-
/**
* Wrap the value in a DataModel
*
@@ -34,37 +30,30 @@
{
if (value instanceof List)
{
- return new ListDataModel( (List) value );
+ return new ListDataModel((List) value);
}
else if (value instanceof Object[])
{
- return new ArrayDataModel( (Object[]) value );
+ return new ArrayDataModel((Object[]) value);
}
else if (value instanceof Map)
{
- return new MapDataModel( (Map) value );
+ return new MapDataModel((Map) value);
}
else if (value instanceof Set)
{
- return new SetDataModel( (Set) value );
+ return new SetDataModel((Set) value);
}
else
{
throw new IllegalArgumentException("unknown collection type: " + value.getClass());
}
}
-
/**
* Wrap the the Seam Framework {@link Query} in a JSF DataModel
*/
- public DataModel getDataModel(Query query)
- {
- return getDataModel( query.getResultList() );
- }
-
- public static DataModels instance()
- {
- return (DataModels) Component.getInstance(DataModels.class, ScopeType.STATELESS);
- }
-
+// public DataModel getDataModel(Query query)
+// {
+// return getDataModel( query.getResultList() );
+// }
}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/DateConverter.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/DateConverter.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/DateConverter.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,120 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.ConverterException;
-
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.faces.Converter;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.log.Log;
-import org.jboss.seam.log.Logging;
-
-/**
- * Provides a default JSF converter for properties of type java.util.Date.
- *
- * <p>This converter is provided to save a developer from having to specify
- * a DateTimeConverter on an input field or page parameter. By default, it
- * assumes the type to be a date (as opposed to a time or date plus time) and
- * uses the short input style adjusted to the Locale of the user. For Locale.US,
- * the input pattern is mm/DD/yy. However, to comply with Y2K, the year is changed
- * from two digits to four (e.g., mm/DD/yyyy).</p>
- * <p>It's possible to override the input pattern globally using component configuration.
- * Here is an example of changing the style to both and setting the date and
- * time style to medium.</p>
- * <pre>
- * org.jboss.seam.faces.dateConverter.type=both
- * org.jboss.seam.faces.dateConverter.dateStyle=medium
- * org.jboss.seam.faces.dateConverter.timeStyle=medium
- * </pre>
- * <p>Alternatively, a fixed pattern can be specified.</p>
- * <pre>
- * org.jboss.seam.faces.dateConverter.pattern=yyyy-mm-DD
- * </pre>
- *
- * @author Dan Allen
- */
- at Converter(forClass = Date.class)
- at Name("org.jboss.seam.faces.dateConverter")
- at Install(precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
- at BypassInterceptors
-public class DateConverter extends javax.faces.convert.DateTimeConverter {
-
- private Log log = Logging.getLog(DateConverter.class);
-
- private static final String TYPE_DATE = "date";
- private static final String STYLE_SHORT = "short";
- private static final String TWO_DIGIT_YEAR_PATTERN = "yy";
- private static final String FOUR_DIGIT_YEAR_PATTERN = "yyyy";
-
- // constructor is used to initialize converter to allow these values to be overridden using component properties
- public DateConverter() {
- super();
- setType(TYPE_DATE);
- setDateStyle(STYLE_SHORT);
- setTimeStyle(STYLE_SHORT); // default in case developer overrides type to be time or both
- }
-
- @Create
- public void create() {
- // TODO make this work if using "both" for type; requires more analysis of time style
- if (TYPE_DATE.equals(getType()) && STYLE_SHORT.equals(getDateStyle()) && getPattern() == null) {
- // attempt to make the pattern Y2K compliant, which it isn't by default
- DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
- if (dateFormat instanceof SimpleDateFormat) {
- setPattern(((SimpleDateFormat) dateFormat).toPattern().replace(TWO_DIGIT_YEAR_PATTERN, FOUR_DIGIT_YEAR_PATTERN));
- }
- }
- // required since the superclass may access the fields directly
- setTimeZone(getTimeZone());
- setLocale(getLocale());
- }
-
- @Override
- public TimeZone getTimeZone() {
- if (Contexts.isApplicationContextActive()) {
- return org.jboss.seam.international.TimeZone.instance();
- } else {
- // we don't want to use JSF's braindead default (maybe in JSF 2)
- return TimeZone.getDefault();
- }
- }
-
- @Override
- public Locale getLocale() {
- if (Contexts.isApplicationContextActive()) {
- return org.jboss.seam.international.Locale.instance();
- } else {
- return super.getLocale();
- }
- }
-
- @Override
- public Object getAsObject(FacesContext context, UIComponent component,
- String value) throws ConverterException {
- if (log.isDebugEnabled()) {
- log.debug("Converting string '#0' to date for clientId '#1' using Seam's built-in JSF date converter", value, component.getClientId(context));
- }
- return super.getAsObject(context, component, value);
- }
-
- @Override
- public String getAsString(FacesContext context, UIComponent component,
- Object value) throws ConverterException {
- if (log.isDebugEnabled()) {
- log.debug("Converting date '#0' to string for clientId '#1' using Seam's built-in JSF date converter", value, component.getClientId(context));
- }
- return super.getAsString(context, component, value);
- }
-}
Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesContextProducer.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesContextProducer.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesContextProducer.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,8 +1,6 @@
//$Id: FacesContext.java 5350 2007-06-20 17:53:19Z gavin $
package org.jboss.seam.faces;
-import javax.annotation.Named;
-import javax.context.ApplicationScoped;
import javax.inject.Produces;
import javax.faces.context.FacesContext;
@@ -11,10 +9,11 @@
*
* @author Gavin King
*/
- at ApplicationScoped
public class FacesContextProducer
{
- @Produces @Named public FacesContext getContext()
+ public
+ @Produces
+ FacesContext getFacesContext()
{
return FacesContext.getCurrentInstance();
}
Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesExpressions.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesExpressions.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesExpressions.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -5,19 +5,18 @@
import javax.context.ApplicationScoped;
import javax.el.ELContext;
import javax.faces.context.FacesContext;
+import org.jboss.seam.el.Expressions;
-import org.jboss.seam.contexts.FacesLifecycle;
-import org.jboss.seam.core.Expressions;
-
/**
* Factory for method and value bindings in a JSF environment.
*
* @author Gavin King
*/
+public
@Named
@ApplicationScoped
-public class FacesExpressions extends Expressions
-{
+class FacesExpressions extends Expressions
+{
/**
* Get an appropriate ELContext. If there is an active JSF request,
* use JSF's ELContext. Otherwise, use one that we created.
@@ -30,8 +29,8 @@
@Override
protected boolean isFacesContextActive()
- {
- return FacesContext.getCurrentInstance() != null && FacesLifecycle.getPhaseId() != null;
+ {
+ return FacesContext.getCurrentInstance() != null && FacesContext.getCurrentInstance().getCurrentPhaseId() != null;
}
-
-}
+
+}
\ No newline at end of file
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManager.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManager.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesManager.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,316 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseId;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.contexts.FacesLifecycle;
-import org.jboss.seam.core.Conversation;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.core.Interpolator;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.navigation.ConversationIdParameter;
-import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.pageflow.Pageflow;
-
-/**
- * An extended conversation manager for the JSF environment.
- *
- * @author Gavin King
- * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- */
- at Scope(ScopeType.EVENT)
- at Name("org.jboss.seam.core.manager")
- at Install(precedence=FRAMEWORK, classDependencies="javax.faces.context.FacesContext")
- at BypassInterceptors
-public class FacesManager extends Manager
-{
- private static final LogProvider log = Logging.getLogProvider(FacesManager.class);
-
-
-
- private boolean controllingRedirect;
-
- /**
- * Temporarily promote a temporary conversation to
- * a long running conversation for the duration of
- * a browser redirect. After the redirect, the
- * conversation will be demoted back to a temporary
- * conversation. Handle any changes to the conversation
- * id, due to propagation via natural id.
- */
- public void beforeRedirect(String viewId)
- {
- beforeRedirect();
-
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String currentViewId = Pages.getViewId(facesContext);
- if ( viewId!=null && currentViewId!=null )
- {
- ConversationIdParameter currentPage = Pages.instance().getPage(currentViewId).getConversationIdParameter();
- ConversationIdParameter targetPage = Pages.instance().getPage(viewId).getConversationIdParameter();
- if ( isDifferentConversationId(currentPage, targetPage) )
- {
- updateCurrentConversationId( targetPage.getConversationId() );
- }
- }
- }
-
- public void interpolateAndRedirect(String url)
- {
- Map<String, Object> parameters = new HashMap<String, Object>();
- int loc = url.indexOf('?');
- if (loc>0)
- {
- StringTokenizer tokens = new StringTokenizer( url.substring(loc), "?=&" );
- while ( tokens.hasMoreTokens() )
- {
- String name = tokens.nextToken();
- String value = Interpolator.instance().interpolate( tokens.nextToken() );
- parameters.put(name, value);
- }
- url = url.substring(0, loc);
- }
- redirect(url, parameters, true, true);
- }
-
- @Override
- protected void storeConversationToViewRootIfNecessary()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( facesContext!=null && FacesLifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE )
- {
- FacesPage.instance().storeConversation();
- }
- }
-
- @Override
- protected String generateInitialConversationId()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String viewId = Pages.getViewId(facesContext);
- if ( viewId!=null )
- {
- return Pages.instance().getPage(viewId)
- .getConversationIdParameter()
- .getInitialConversationId( facesContext.getExternalContext().getRequestParameterMap() );
- }
- else
- {
- return super.generateInitialConversationId();
- }
- }
-
- public void redirectToExternalURL(String url) {
- try {
- FacesContext.getCurrentInstance().getExternalContext().redirect(url);
- } catch (IOException e) {
- throw new RedirectException(e);
- }
- }
-
- /**
- * Redirect to the given view id, encoding the conversation id
- * into the request URL.
- *
- * @param viewId the JSF view id
- */
- @Override
- public void redirect(String viewId)
- {
- redirect(viewId, null, true, true);
- }
-
- public void redirect(String viewId, Map<String, Object> parameters,
- boolean includeConversationId)
- {
- redirect(viewId, parameters, includeConversationId, true);
- }
-
- /**
- * Redirect to the given view id, after encoding parameters and conversation
- * id into the request URL.
- *
- * @param viewId the JSF view id
- * @param parameters request parameters to be encoded (possibly null)
- * @param includeConversationId determines if the conversation id is to be encoded
- */
- public void redirect(String viewId, Map<String, Object> parameters,
- boolean includeConversationId, boolean includePageParams)
- {
- if (viewId == null)
- {
- throw new RedirectException("cannot redirect to a null viewId");
- }
- FacesContext context = FacesContext.getCurrentInstance();
- String url = context.getApplication().getViewHandler().getActionURL(context, viewId);
- if (parameters!=null)
- {
- url = encodeParameters(url, parameters);
- }
-
- if (includePageParams)
- {
- url = Pages.instance().encodePageParameters(FacesContext.getCurrentInstance(),
- url, viewId, parameters==null ? Collections.EMPTY_SET : parameters.keySet());
- }
-
- if (includeConversationId)
- {
- beforeRedirect(viewId);
- url = encodeConversationId(url, viewId);
- }
- redirect(viewId, context, url);
- }
-
- /**
- * Redirect to the given view id, after encoding the given conversation
- * id into the request URL.
- *
- * @param viewId the JSF view id
- * @param conversationId an id of a long-running conversation
- */
- @Override
- public void redirect(String viewId, String conversationId)
- {
- if (viewId == null)
- {
- throw new RedirectException("cannot redirect to a null viewId");
- }
- FacesContext context = FacesContext.getCurrentInstance();
- String url = context.getApplication().getViewHandler().getActionURL(context, viewId);
- url = encodeConversationId(url, viewId, conversationId);
- redirect(viewId, context, url);
- }
-
- private void redirect(String viewId, FacesContext context, String url)
- {
- url = Pages.instance().encodeScheme(viewId, context, url);
- if ( log.isDebugEnabled() )
- {
- log.debug("redirecting to: " + url);
- }
- ExternalContext externalContext = context.getExternalContext();
- controllingRedirect = true;
- try
- {
- Contexts.getEventContext().set(REDIRECT_FROM_MANAGER, "");
- externalContext.redirect( externalContext.encodeActionURL(url) );
- }
- catch (IOException ioe)
- {
- throw new RedirectException(ioe);
- }
- finally
- {
- Contexts.getEventContext().remove(REDIRECT_FROM_MANAGER);
- controllingRedirect = false;
- }
- context.responseComplete();
- }
-
- /**
- * Called by the Seam Redirect Filter when a redirect is called.
- * Appends the conversationId parameter if necessary.
- *
- * @param url the requested URL
- * @return the resulting URL with the conversationId appended
- */
- public String appendConversationIdFromRedirectFilter(String url, String viewId)
- {
- boolean appendConversationId = !controllingRedirect;
- if (appendConversationId)
- {
- beforeRedirect(viewId);
- url = encodeConversationId(url, viewId);
- }
- return url;
- }
-
- /**
- * If a page description is defined, remember the description and
- * view id for the current page, to support conversation switching.
- * Called just before the render phase.
- */
- public void prepareBackswitch(FacesContext facesContext)
- {
-
- Conversation conversation = Conversation.instance();
-
- //stuff from jPDL takes precedence
- org.jboss.seam.pageflow.Page page =
- Manager.instance().isLongRunningConversation() &&
- Init.instance().isJbpmInstalled() &&
- Pageflow.instance().isInProcess() && Pageflow.instance().isStarted() ?
- Pageflow.instance().getPage() : null;
-
- if (page==null)
- {
- //handle stuff defined in pages.xml
- Pages pages = Pages.instance();
- if (pages!=null) //for tests
- {
- String viewId = Pages.getViewId(facesContext);
- org.jboss.seam.navigation.Page pageEntry = pages.getPage(viewId);
- if ( pageEntry.isSwitchEnabled() )
- {
- conversation.setViewId(viewId);
- }
- if ( pageEntry.hasDescription() )
- {
- conversation.setDescription( pageEntry.renderDescription() );
- }
- else if(pages.hasDescription(viewId))
- {
- conversation.setDescription( pages.renderDescription(viewId) );
- }
- conversation.setTimeout( pages.getTimeout(viewId) );
- conversation.setConcurrentRequestTimeout( pages.getConcurrentRequestTimeout(viewId) );
- }
- }
- else
- {
- //use stuff from the pageflow definition
- if ( page.isSwitchEnabled() )
- {
- conversation.setViewId( Pageflow.instance().getPageViewId() );
- }
- if ( page.hasDescription() )
- {
- conversation.setDescription( page.getDescription() );
- }
- conversation.setTimeout( page.getTimeout() );
- }
-
- flushConversationMetadata();
-
- }
-
- public static FacesManager instance()
- {
- return (FacesManager) Manager.instance();
- }
-
-}
Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesMessages.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesMessages.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesMessages.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,8 +1,5 @@
package org.jboss.seam.faces;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -11,16 +8,8 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.international.StatusMessages;
-import org.jboss.seam.util.Strings;
/**
* A Seam component that propagates FacesMessages across redirects
@@ -29,59 +18,43 @@
* @author Gavin King
* @author Pete Muir
*/
- at Scope(ScopeType.CONVERSATION)
- at Name(StatusMessages.COMPONENT_NAME)
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
- at BypassInterceptors
public class FacesMessages extends StatusMessages
{
-
/**
- * Called by Seam to transfer messages from FacesMessages to JSF
+ * Called by Seam to transfer messages from Seam status messages to real JSF messages
*/
- public void beforeRenderResponse()
+ public void beforeRenderView()
{
- for (StatusMessage statusMessage: getMessages())
+ for (StatusMessage statusMessage : getMessages())
{
- FacesContext.getCurrentInstance().addMessage( null, toFacesMessage(statusMessage) );
+ FacesContext.getCurrentInstance().addMessage(null, toFacesMessage(statusMessage));
}
- for ( Map.Entry<String, List<StatusMessage>> entry: getKeyedMessages().entrySet() )
+ for (Map.Entry<String, List<StatusMessage>> entry : getKeyedMessages().entrySet())
{
- for ( StatusMessage statusMessage: entry.getValue() )
+ for (StatusMessage statusMessage : entry.getValue())
{
String clientId = getClientId(entry.getKey());
- FacesContext.getCurrentInstance().addMessage( clientId, toFacesMessage(statusMessage) );
+ FacesContext.getCurrentInstance().addMessage(clientId, toFacesMessage(statusMessage));
}
}
clear();
}
-
+
/**
- * Called by Seam to transfer any messages added in the phase just processed
- * to the FacesMessages component.
- *
- * A task runner is used to allow the messages access to outjected values.
- */
- public static void afterPhase()
- {
- runTasks();
- }
-
- /**
* Convert a StatusMessage to a FacesMessage
*/
private static FacesMessage toFacesMessage(StatusMessage statusMessage)
{
- if (!Strings.isEmpty(statusMessage.getSummary()))
+ if (statusMessage.getSummary() != null && statusMessage.getSummary().length() > 0)
{
- return new FacesMessage(toSeverity(statusMessage.getSeverity()), statusMessage.getSummary(), statusMessage.getDetail() );
+ return new FacesMessage(toSeverity(statusMessage.getSeverity()), statusMessage.getSummary(), statusMessage.getDetail());
}
else
{
return null;
}
}
-
+
/**
* Convert a StatusMessage.Severity to a FacesMessage.Severity
*/
@@ -89,19 +62,19 @@
{
switch (severity)
{
- case ERROR:
- return FacesMessage.SEVERITY_ERROR;
- case FATAL:
- return FacesMessage.SEVERITY_FATAL;
- case INFO:
- return FacesMessage.SEVERITY_INFO;
- case WARN:
- return FacesMessage.SEVERITY_WARN;
- default:
- return null;
+ case ERROR:
+ return FacesMessage.SEVERITY_ERROR;
+ case FATAL:
+ return FacesMessage.SEVERITY_FATAL;
+ case INFO:
+ return FacesMessage.SEVERITY_INFO;
+ case WARN:
+ return FacesMessage.SEVERITY_WARN;
+ default:
+ return null;
}
}
-
+
/**
* Convert a FacesMessage.Severity to a StatusMessage.Severity
*/
@@ -128,229 +101,36 @@
return null;
}
}
-
+
/**
* Calculate the JSF client ID from the provided widget ID
*/
private String getClientId(String id)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
- return getClientId( facesContext.getViewRoot(), id, facesContext);
+ return getClientId(facesContext.getViewRoot(), id, facesContext);
}
private static String getClientId(UIComponent component, String id, FacesContext facesContext)
{
String componentId = component.getId();
- if (componentId!=null && componentId.equals(id))
+ if (componentId != null && componentId.equals(id))
{
return component.getClientId(facesContext);
}
else
{
Iterator iter = component.getFacetsAndChildren();
- while ( iter.hasNext() )
+ while (iter.hasNext())
{
UIComponent child = (UIComponent) iter.next();
String clientId = getClientId(child, id, facesContext);
- if (clientId!=null) return clientId;
+ if (clientId != null)
+ {
+ return clientId;
+ }
}
return null;
}
}
-
- /**
- * Get all faces messages that have already been added
- * to the context.
- *
- */
- public List<FacesMessage> getCurrentMessages()
- {
- List<FacesMessage> result = new ArrayList<FacesMessage>();
- Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
- while ( iter.hasNext() )
- {
- result.add( iter.next() );
- }
- return result;
- }
-
- /**
- * Get all faces global messages that have already been added
- * to the context.
- *
- */
- public List<FacesMessage> getCurrentGlobalMessages()
- {
- List<FacesMessage> result = new ArrayList<FacesMessage>();
- Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages(null);
- while ( iter.hasNext() )
- {
- result.add( iter.next() );
- }
- return result;
- }
-
- /**
- * Get all faces messages that have already been added
- * to the control.
- *
- */
- public List<FacesMessage> getCurrentMessagesForControl(String id)
- {
- String clientId = getClientId(id);
- List<FacesMessage> result = new ArrayList<FacesMessage>();
- Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages(clientId);
- while ( iter.hasNext() )
- {
- result.add( iter.next() );
- }
- return result;
- }
-
- /**
- * Utility method to create a FacesMessage from a Severity, messageTemplate
- * and params.
- *
- * This method interpolates the parameters provided
- */
- public static FacesMessage createFacesMessage(javax.faces.application.FacesMessage.Severity severity, String messageTemplate, Object... params)
- {
- return createFacesMessage(severity, null, messageTemplate, params);
- }
-
- /**
- * Utility method to create a FacesMessage from a Severity, key,
- * defaultMessageTemplate and params.
- *
- * This method interpolates the parameters provided
- */
- public static FacesMessage createFacesMessage(javax.faces.application.FacesMessage.Severity severity, String key, String defaultMessageTemplate, Object... params)
- {
- StatusMessage message = new StatusMessage(toSeverity(severity), key, null, defaultMessageTemplate, null);
- message.interpolate(params);
- return toFacesMessage(message);
- }
-
- /**
- * Add a FacesMessage that will be used
- * the next time a page is rendered.
- *
- * Deprecated, use a method in {@link StatusMessages} instead
- */
- @Deprecated
- public void add(FacesMessage facesMessage)
- {
- if (facesMessage!=null)
- {
- add(toSeverity(facesMessage.getSeverity()), null, null, facesMessage.getSummary(), facesMessage.getDetail());
- }
- }
-
- /**
- * Create a new status message, with the messageTemplate is as the message.
- *
- * You can also specify the severity, and parameters to be interpolated
- *
- * Deprecated, use {@link #add(org.jboss.seam.international.StatusMessage.Severity, String, Object...)}
- * instead
- */
- @Deprecated
- public void add(javax.faces.application.FacesMessage.Severity severity, String messageTemplate, Object... params)
- {
- add(toSeverity(severity), messageTemplate, params);
- }
-
-
- /**
- * Create a new status message, with the messageTemplate is as the message.
- *
- * A severity of INFO will be used, and you can specify paramters to be
- * interpolated
- *
- * Deprecated, use {@link #addToControl(String, org.jboss.seam.international.StatusMessage.Severity, String, Object...)}
- * instead
- */
- @Deprecated
- public void addToControl(String id, javax.faces.application.FacesMessage.Severity severity, String messageTemplate, Object... params)
- {
- addToControl(id, toSeverity(severity), messageTemplate, params);
- }
-
- /**
- * Add a status message, looking up the message in the resource bundle
- * using the provided key.
- *
- * You can also specify the severity, and parameters to be interpolated
- *
- * Deprecated, use {@link #addFromResourceBundle(org.jboss.seam.international.StatusMessage.Severity, String, Object...)}
- * instead
- */
- @Deprecated
- public void addFromResourceBundle(javax.faces.application.FacesMessage.Severity severity, String key, Object... params)
- {
- addFromResourceBundle(toSeverity(severity), key, params);
- }
-
- /**
- * Add a status message, looking up the message in the resource bundle
- * using the provided key.
- *
- * You can also specify the severity, and parameters to be interpolated
- *
- * Deprecated, use {@link #addFromResourceBundleOrDefault(javax.faces.application.FacesMessage.Severity, String, String, Object...)}
- * instead
- */
- @Deprecated
- public void addFromResourceBundleOrDefault(javax.faces.application.FacesMessage.Severity severity, String key, String defaultMessageTemplate, Object... params)
- {
- addFromResourceBundleOrDefault(toSeverity(severity), key, defaultMessageTemplate, params);
- }
-
- /**
- * Create a new status message, looking up the message in the resource bundle
- * using the provided key.
- *
- * The message will be added to the widget specified by the ID. The algorithm
- * used determine which widget the id refers to is determined by the view
- * layer implementation in use.
- *
- * You can also specify the severity, and parameters to be interpolated
- *
- * Deprecated, use {@link #addToControlFromResourceBundle(String, org.jboss.seam.international.StatusMessage.Severity, String, Object...)}
- * instead
- */
- @Deprecated
- public void addToControlFromResourceBundle(String id, javax.faces.application.FacesMessage.Severity severity, String key, Object... params)
- {
- addToControlFromResourceBundle(id, toSeverity(severity), key, params);
- }
-
- /**
- * Add a status message, looking up the message in the resource bundle
- * using the provided key. If the message is found, it is used, otherwise,
- * the defaultMessageTemplate will be used.
- *
- * The message will be added to the widget specified by the ID. The algorithm
- * used determine which widget the id refers to is determined by the view
- * layer implementation in use.
- *
- * You can also specify the severity, and parameters to be interpolated
- *
- * Deprecated, use {@link #addToControlFromResourceBundleOrDefault(String, org.jboss.seam.international.StatusMessage.Severity, String, String, Object...)}
- * instead
- */
- @Deprecated
- public void addToControlFromResourceBundleOrDefault(String id, javax.faces.application.FacesMessage.Severity severity, String key, String defaultMessageTemplate, Object... params)
- {
- addToControlFromResourceBundleOrDefault(id, toSeverity(severity), key, defaultMessageTemplate, params);
- }
-
- public static FacesMessages instance()
- {
- if ( !Contexts.isConversationContextActive() )
- {
- throw new IllegalStateException("No active conversation context");
- }
- return (FacesMessages) Component.getInstance(StatusMessages.COMPONENT_NAME, ScopeType.CONVERSATION);
- }
}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesPage.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesPage.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesPage.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,173 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.Serializable;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.pageflow.Pageflow;
-import org.jboss.seam.web.Session;
-
-/**
- * Book-keeping component that persists information
- * about the conversation associated with the current
- * page.
- *
- * @author Gavin King
- *
- */
- at Name("org.jboss.seam.faces.facesPage")
- at BypassInterceptors
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
- at Scope(ScopeType.PAGE)
-public class FacesPage implements Serializable
-{
- private static final long serialVersionUID = 4807114041808347239L;
- private String pageflowName;
- private Integer pageflowCounter;
- private String pageflowNodeName;
-
- private String conversationId;
- private boolean conversationIsLongRunning;
-
- //private Map<String, Object> pageParameters;
-
- public String getConversationId()
- {
- return conversationId;
- }
-
- public void discardTemporaryConversation()
- {
- conversationId = null;
- conversationIsLongRunning = false;
- }
-
- public void discardNestedConversation(String outerConversationId)
- {
- conversationId = outerConversationId;
- conversationIsLongRunning = true;
- }
-
- public void storeConversation(String conversationId)
- {
- this.conversationId = conversationId;
- conversationIsLongRunning = true;
- }
-
- public void storePageflow()
- {
- if ( Init.instance().isJbpmInstalled() )
- {
- Pageflow pageflow = Pageflow.instance();
- if ( pageflow.isInProcess() /*&& !pageflow.getProcessInstance().hasEnded()*/ && Manager.instance().isLongRunningConversation() )
- {
- pageflowName = pageflow.getSubProcessInstance().getProcessDefinition().getName();
- pageflowNodeName = pageflow.getNode().getName();
- pageflowCounter = pageflow.getPageflowCounter();
- }
- else
- {
- pageflowName = null;
- pageflowNodeName = null;
- pageflowCounter = null;
- }
- }
- }
-
- public static FacesPage instance()
- {
- if ( !Contexts.isPageContextActive() )
- {
- throw new IllegalStateException("No page context active");
- }
- return (FacesPage) Component.getInstance(FacesPage.class, ScopeType.PAGE);
- }
-
- public boolean isConversationLongRunning()
- {
- return conversationIsLongRunning;
- }
-
- public Integer getPageflowCounter()
- {
- return pageflowCounter;
- }
-
- public String getPageflowName()
- {
- return pageflowName;
- }
-
- public String getPageflowNodeName()
- {
- return pageflowNodeName;
- }
-
- public void storeConversation()
- {
- Manager manager = Manager.instance();
-
- //we only need to execute this code when we are in the
- //RENDER_RESPONSE phase, ie. not before redirects
-
- Session session = Session.getInstance();
- boolean sessionInvalid = session!=null && session.isInvalid();
- if ( !sessionInvalid && manager.isLongRunningConversation() )
- {
- storeConversation( manager.getCurrentConversationId() );
- }
- else if ( !sessionInvalid && manager.isNestedConversation() )
- {
- discardNestedConversation( manager.getParentConversationId() );
- }
- else
- {
- discardTemporaryConversation();
- }
-
- /*if ( !sessionInvalid && Init.instance().isClientSideConversations() )
- {
- // if we are using client-side conversations, put the
- // map containing the conversation context variables
- // into the view root (or remove it for a temp
- // conversation context)
- Contexts.getConversationContext().flush();
- }*/
-
- }
-
- /*public Map<String, Object> getPageParameters()
- {
- return pageParameters==null ? Collections.EMPTY_MAP : pageParameters;
- }
-
- public void setPageParameters(Map<String, Object> pageParameters)
- {
- this.pageParameters = pageParameters.isEmpty() ? null : pageParameters;
- }
-
- /**
- * Used by test harness
- *
- * @param name the page parameter name
- * @param value the value
- */
- /*public void setPageParameter(String name, Object value)
- {
- if (pageParameters==null)
- {
- pageParameters = new HashMap<String, Object>();
- }
- pageParameters.put(name, value);
- }*/
-
-}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesResourceLoader.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesResourceLoader.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/FacesResourceLoader.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,70 @@
+package org.jboss.seam.faces;
+
+import java.io.InputStream;
+import java.net.URL;
+import javax.faces.context.FacesContext;
+import javax.inject.Current;
+import javax.servlet.ServletContext;
+import org.jboss.seam.international.ResourceLoader;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Extend the standard {@link ResourceLoader} and attempt to first load
+ * the resource from the web context root.
+ *
+ * @author Dan Allen
+ */
+public class FacesResourceLoader extends ResourceLoader
+{
+ private static final LogProvider log = Logging.getLogProvider(FacesResourceLoader.class);
+ @Current
+ FacesContext facesContext;
+
+ @Override
+ protected URL getResource(String path, String relativePath)
+ {
+ ServletContext servletContext = getServletContext();
+ if (servletContext != null)
+ {
+ try
+ {
+ URL url = servletContext.getResource(path);
+ log.debug("Loaded resource from servlet context: " + url);
+ return url;
+ }
+ catch (Exception e)
+ {
+ // swallow
+ }
+ }
+
+ return super.getResource(path, relativePath);
+ }
+
+ @Override
+ protected InputStream getResourceAsStream(String path, String relativePath)
+ {
+ ServletContext servletContext = getServletContext();
+ if (servletContext != null)
+ {
+ try
+ {
+ InputStream stream = servletContext.getResourceAsStream(path);
+ log.debug("Loaded resource stream from servlet context: " + path);
+ return stream;
+ }
+ catch (Exception e)
+ {
+ // swallow
+ }
+ }
+
+ return super.getResourceAsStream(path, relativePath);
+ }
+
+ private ServletContext getServletContext()
+ {
+ return (ServletContext) facesContext.getExternalContext().getContext();
+ }
+}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/HttpError.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/HttpError.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/HttpError.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,76 +0,0 @@
-//$Id: HttpError.java 5350 2007-06-20 17:53:19Z gavin $
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-
-/**
- * Convenient HTTP errors
- *
- * @author Gavin King
- */
- at Scope(ScopeType.APPLICATION)
- at BypassInterceptors
- at Name("org.jboss.seam.faces.httpError")
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
-public class HttpError
-{
- /**
- * Send a HTTP error as the response
- */
- public void send(int code)
- {
- try
- {
- getResponse().sendError(code);
- }
- catch (IOException ioe)
- {
- throw new IllegalStateException(ioe);
- }
- FacesContext.getCurrentInstance().responseComplete();
- }
-
- /**
- * Send a HTTP error as the response
- */
- public void send(int code, String message)
- {
- try
- {
- getResponse().sendError(code, message);
- }
- catch (IOException ioe)
- {
- throw new IllegalStateException(ioe);
- }
- FacesContext.getCurrentInstance().responseComplete();
- }
-
- private static HttpServletResponse getResponse()
- {
- return (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
- }
-
- public static HttpError instance()
- {
- if ( !Contexts.isApplicationContextActive() )
- {
- throw new IllegalStateException("No active application scope");
- }
- return (HttpError) Component.getInstance(HttpError.class, ScopeType.APPLICATION);
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/IsUserInRole.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/IsUserInRole.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/IsUserInRole.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,37 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-
-/**
- * Manager component for a map of roles assigned
- * to the current user, as exposed via the JSF
- * ExternalContext.
- *
- * @author Gavin King
- */
- at Scope(ScopeType.APPLICATION)
- at BypassInterceptors
- at Name("org.jboss.seam.web.isUserInRole")
- at Install(precedence=FRAMEWORK, classDependencies="javax.faces.context.FacesContext")
-public class IsUserInRole extends org.jboss.seam.web.IsUserInRole
-{
- @Override
- protected Boolean isUserInRole(String role)
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( facesContext != null )
- {
- return facesContext.getExternalContext().isUserInRole(role);
- }
-
- return super.isUserInRole(role);
- }
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Navigator.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Navigator.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Navigator.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,109 +0,0 @@
-package org.jboss.seam.faces;
-
-import java.util.Map;
-
-import javax.faces.application.FacesMessage.Severity;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.util.Strings;
-
-public abstract class Navigator
-{
- private static final LogProvider log = Logging.getLogProvider(Navigator.class);
-
- /**
- * Send an error.
- */
- protected void error(int code, String message)
- {
- if ( log.isDebugEnabled() ) log.debug("sending error: " + code);
- org.jboss.seam.faces.HttpError httpError = org.jboss.seam.faces.HttpError.instance();
- if (message==null)
- {
- httpError.send(code);
- }
- else
- {
- httpError.send(code, message);
- }
- }
-
- protected void redirectExternal(String url) {
- FacesManager.instance().redirectToExternalURL(url);
- }
-
- protected void redirect(String viewId, Map<String, Object> parameters)
- {
- redirect(viewId, parameters, true);
- }
-
- /**
- * Redirect to the view id.
- */
- protected void redirect(String viewId, Map<String, Object> parameters, boolean includePageParams)
- {
- if ( Strings.isEmpty(viewId) )
- {
- viewId = Pages.getCurrentViewId();
- }
- if ( log.isDebugEnabled() ) log.debug("redirecting to: " + viewId);
- FacesManager.instance().redirect(viewId, parameters, true, includePageParams);
- }
-
- /**
- * Render the view id.
- */
- protected void render(String viewId)
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( !Strings.isEmpty(viewId) )
- {
- UIViewRoot viewRoot = facesContext.getApplication().getViewHandler()
- .createView(facesContext, viewId);
- facesContext.setViewRoot(viewRoot);
- }
- else
- {
- viewId = Pages.getViewId(facesContext); //just for the log message
- }
- if ( log.isDebugEnabled() ) log.debug("rendering: " + viewId);
- facesContext.renderResponse();
- }
-
- protected static String getDisplayMessage(Exception e, String message)
- {
- if ( Strings.isEmpty(message) && e.getMessage()!=null )
- {
- return e.getMessage();
- }
- else
- {
- return message;
- }
- }
-
- @SuppressWarnings("deprecation")
- protected static void addFacesMessage(String message, Severity severity, String control, Object... params)
- {
- if ( Contexts.isConversationContextActive() )
- {
- if ( !Strings.isEmpty(message) )
- {
- if ( Strings.isEmpty(control) )
- {
- FacesMessages.instance().add(severity, message, params);
- }
- else
- {
- FacesMessages.instance().addToControl(control, severity, message, params);
- }
- }
- }
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Parameters.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Parameters.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Parameters.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,67 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
-import java.util.Map;
-
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-
-/**
- * Access to request parameters in the JSF environment.
- *
- * @author Gavin King
- *
- */
- at Name("org.jboss.seam.web.parameters")
- at BypassInterceptors
- at Scope(ScopeType.STATELESS)
- at Install(precedence=FRAMEWORK, classDependencies="javax.faces.context.FacesContext")
-public class Parameters extends org.jboss.seam.web.Parameters
-{
-
- @Override
- protected Object convertRequestParameter(String requestParameter, Class type)
- {
- if ( String.class.equals(type) ) return requestParameter;
-
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if (facesContext==null)
- {
- throw new IllegalStateException("No FacesContext associated with current thread, cannot convert request parameter type");
- }
- else
- {
- Converter converter = facesContext.getApplication().createConverter(type);
- if (converter==null)
- {
- throw new IllegalArgumentException("no converter for type: " + type);
- }
- UIViewRoot viewRoot = facesContext.getViewRoot();
- return converter.getAsObject(
- facesContext,
- viewRoot==null ? new UIViewRoot() : viewRoot, //have to pass something here, or get a totally useless NPE from JSF
- requestParameter );
- }
- }
-
- @Override
- public Map<String, String[]> getRequestParameters()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( facesContext != null )
- {
- return facesContext.getExternalContext().getRequestParameterValuesMap();
- }
-
- return super.getRequestParameters();
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Redirect.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Redirect.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Redirect.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,204 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.PerNestedConversation;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.AbstractMutable;
-import org.jboss.seam.core.Conversation;
-import org.jboss.seam.navigation.Pages;
-
-/**
- * Convenient API for performing browser redirects with
- * parameters.
- *
- * @author Gavin King
- */
- at Name("org.jboss.seam.faces.redirect")
- at BypassInterceptors
- at Scope(ScopeType.CONVERSATION)
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
- at PerNestedConversation
-public class Redirect extends AbstractMutable implements Serializable
-{
- private static final long serialVersionUID = 6947384474861235210L;
- private String viewId;
- private Map<String, Object> parameters = new HashMap<String, Object>();
- private boolean conversationPropagationEnabled = true;
- private boolean conversationBegun;
-
- /**
- * Get the JSF view id to redirect to
- */
- public String getViewId()
- {
- return viewId;
- }
-
- /**
- * Set the JSF view id to redirect to
- *
- * @param viewId any JSF view id
- */
- public void setViewId(String viewId)
- {
- setDirty(this.viewId, viewId);
- this.viewId = viewId;
- }
-
- /**
- * Get all the request parameters that have been set
- */
- public Map<String, Object> getParameters()
- {
- return parameters;
- }
-
- /**
- * Set a request parameter value (to set a multi-valued
- * request parameter, pass an array or collection as
- * the value)
- */
- public void setParameter(String name, Object value)
- {
- Object old = parameters.put(name, value);
- setDirty(old, value);
- }
-
- /**
- * Capture the view id and request parameters from the
- * current request and squirrel them away so we can
- * return here later in the conversation.
- *
- * @deprecated use captureCurrentView()
- */
- public void captureCurrentRequest()
- {
- parameters.clear();
- FacesContext context = FacesContext.getCurrentInstance();
- parameters.putAll( context.getExternalContext().getRequestParameterMap() );
- viewId = Pages.getViewId(context);
- setDirty();
- }
-
- /**
- * Capture the view id, request parameters and page parameters (which take
- * precedence) from the current request and squirrel them away so we can
- * return here later in the conversation. If no conversation is active,
- * begin a conversation. The conversation is terminated by {@link
- * Redirect#returnToCapturedView()} if begun by this method.
- *
- * @see Redirect#returnToCapturedView()
- */
- public void captureCurrentView()
- {
- FacesContext context = FacesContext.getCurrentInstance();
-
- // If this isn't a faces request then just return
- if (context == null) return;
-
- // first capture all request parameters
- parameters.putAll( context.getExternalContext().getRequestParameterMap() );
- // then preserve page parameters, overwriting request parameters with same names
- parameters.putAll( Pages.instance().getStringValuesFromPageContext(context) );
-
- // special case only needed for actionMethod if decide not to capture all request parameters
- //if (context.getExternalContext().getRequestParameterMap().containsKey("actionMethod"))
- //{
- // parameters.put("actionMethod", context.getExternalContext().getRequestParameterMap().get("actionMethod"));
- //}
-
- viewId = Pages.getViewId(context);
- conversationBegun = Conversation.instance().begin(true, false);
- setDirty();
- //if the request ends with an exception,
- //the conversation context never gets
- //flushed....
- Contexts.getConversationContext().flush();
- }
-
- /**
- * Should the conversation be propagated across the redirect?
- * @return true by default
- */
- public boolean isConversationPropagationEnabled()
- {
- return conversationPropagationEnabled;
- }
-
- /**
- * Note that conversations are propagated by default
- */
- public void setConversationPropagationEnabled(boolean conversationPropagationEnabled)
- {
- this.conversationPropagationEnabled = conversationPropagationEnabled;
- }
-
- /**
- * Perform the redirect
- */
- public void execute()
- {
- FacesManager.instance().redirect(viewId, parameters, conversationPropagationEnabled, true);
- }
-
- /**
- * Redirect to the captured view, and end any conversation
- * that began in captureCurrentView().
- *
- *@see Redirect#captureCurrentView()
- */
- public boolean returnToCapturedView()
- {
- if (viewId!=null)
- {
- if (conversationBegun)
- {
- Conversation.instance().end();
- }
- execute();
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //TODO: replacement for Conversation.endAndRedirect()
- /*public boolean returnToParentView()
- {
- Manager manager = Manager.instance();
- String viewId = manager.getParentConversationViewId();
- if (viewId==null)
- {
- return false;
- }
- else
- {
- manager.redirect(viewId);
- return true;
- }
- }*/
-
- public static Redirect instance()
- {
- if ( !Contexts.isConversationContextActive() )
- {
- throw new IllegalStateException("No active conversation context");
- }
- return (Redirect) Component.getInstance(Redirect.class, ScopeType.CONVERSATION);
- }
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Renderer.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Renderer.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Renderer.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,23 +0,0 @@
-package org.jboss.seam.faces;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-
-/**
- * A component for direct rendering of
- * templates. Especially useful with
- * Seam Mail.
- *
- */
- at Name("org.jboss.seam.faces.renderer")
- at Install(false)
-public abstract class Renderer
-{
- public abstract String render(String viewId);
-
- public static Renderer instance()
- {
- return (Renderer) Component.getInstance(Renderer.class);
- }
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/ResourceLoader.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/ResourceLoader.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/ResourceLoader.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,56 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.FRAMEWORK;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.util.FacesResources;
-
-/**
- * Access to application resources in tye JSF environment.
- *
- * @author Gavin King
- *
- */
- at Scope(ScopeType.STATELESS)
- at BypassInterceptors
- at Install(precedence=FRAMEWORK, classDependencies="javax.faces.context.FacesContext")
- at Name("org.jboss.seam.core.resourceLoader")
-public class ResourceLoader extends org.jboss.seam.core.ResourceLoader
-{
-
- @Override
- public InputStream getResourceAsStream(String resource)
- {
- javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
- if (context!=null)
- {
- return FacesResources.getResourceAsStream( resource, context.getExternalContext() );
- }
- else
- {
- return super.getResourceAsStream(resource);
- }
- }
-
- @Override
- public URL getResource(String resource)
- {
- javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
- if (context!=null)
- {
- return FacesResources.getResource( resource, context.getExternalContext() );
- }
- else
- {
- return super.getResource(resource);
- }
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Selector.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Selector.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Selector.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,122 +0,0 @@
-package org.jboss.seam.faces;
-
-import java.io.Serializable;
-
-import javax.faces.context.FacesContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.core.AbstractMutable;
-
-/**
- * Support for selector objects which remember their selection as a cookie
- *
- * @author Gavin King
- */
-public abstract class Selector extends AbstractMutable implements Serializable
-{
- public static final int DEFAULT_MAX_AGE = 31536000; // 1 year in seconds
- private boolean cookieEnabled;
- private int cookieMaxAge = DEFAULT_MAX_AGE;
- private String cookiePath= "/";
-
- /**
- * Is the cookie enabled?
- * @return false by default
- */
- public boolean isCookieEnabled()
- {
- return cookieEnabled;
- }
- public void setCookieEnabled(boolean cookieEnabled)
- {
- setDirty(this.cookieEnabled, cookieEnabled);
- this.cookieEnabled = cookieEnabled;
- }
- /**
- * The max age of the cookie
- * @return 1 year by default
- */
- public int getCookieMaxAge()
- {
- return cookieMaxAge;
- }
- public void setCookieMaxAge(int cookieMaxAge)
- {
- this.cookieMaxAge = cookieMaxAge;
- }
-
- public String getCookiePath()
- {
- return cookiePath;
- }
-
- public void setCookiePath(String cookiePath)
- {
- this.cookiePath = cookiePath;
- }
-
- /**
- * Override to define the cookie name
- */
- protected abstract String getCookieName();
-
- /**
- * Get the value of the cookie
- */
- protected String getCookieValueIfEnabled()
- {
- return isCookieEnabled() ?
- getCookieValue() : null;
- }
-
- protected Cookie getCookie()
- {
- FacesContext ctx = FacesContext.getCurrentInstance();
- if (ctx != null)
- {
- return (Cookie) ctx.getExternalContext().getRequestCookieMap()
- .get( getCookieName() );
- }
- else
- {
- return null;
- }
- }
-
- protected String getCookieValue()
- {
- Cookie cookie = getCookie();
- return cookie==null ? null : cookie.getValue();
- }
-
- protected void clearCookieValue()
- {
- Cookie cookie = getCookie();
- if ( cookie!=null )
- {
- HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
- cookie.setValue(null);
- cookie.setPath(cookiePath);
- cookie.setMaxAge(0);
- response.addCookie(cookie);
- }
- }
-
- /**
- * Set the cookie
- */
- protected void setCookieValueIfEnabled(String value)
- {
- FacesContext ctx = FacesContext.getCurrentInstance();
-
- if ( isCookieEnabled() && ctx != null)
- {
- HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
- Cookie cookie = new Cookie( getCookieName(), value );
- cookie.setMaxAge( getCookieMaxAge() );
- cookie.setPath(cookiePath);
- response.addCookie(cookie);
- }
- }
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Switcher.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Switcher.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Switcher.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,125 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.faces.model.SelectItem;
-
-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.intercept.BypassInterceptors;
-import org.jboss.seam.core.ConversationEntries;
-import org.jboss.seam.core.ConversationEntry;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.web.Session;
-
-/**
- * Support for the conversation switcher drop-down menu.
- *
- * @author Gavin King
- */
- at Scope(ScopeType.PAGE)
- at Name("org.jboss.seam.faces.switcher")
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
- at BypassInterceptors
-public class Switcher implements Serializable
-{
-
- private static final long serialVersionUID = -6403911073853051938L;
- private List<SelectItem> selectItems;
- private String conversationIdOrOutcome;
- private String resultingConversationIdOrOutcome;
-
- @Create
- public void createSelectItems()
- {
- ConversationEntries conversationEntries = ConversationEntries.getInstance();
- if (conversationEntries==null)
- {
- selectItems = Collections.EMPTY_LIST;
- }
- else
- {
- Set<ConversationEntry> orderedEntries = new TreeSet<ConversationEntry>();
- orderedEntries.addAll( conversationEntries.getConversationEntries() );
- selectItems = new ArrayList<SelectItem>( conversationEntries.size() );
- for ( ConversationEntry entry: orderedEntries )
- {
- if ( entry.isDisplayable() && !Session.instance().isInvalid() )
- {
- selectItems.add( new SelectItem( entry.getId(), entry.getDescription() ) );
- }
- }
- }
- }
-
- public List<SelectItem> getSelectItems()
- {
- return selectItems;
- }
-
- private String getLongRunningConversationId()
- {
- Manager manager = Manager.instance();
- if ( manager.isLongRunningConversation() )
- {
- return manager.getCurrentConversationId();
- }
- else if ( manager.isNestedConversation() )
- {
- return manager.getParentConversationId();
- }
- else
- {
- //TODO: is there any way to set it to the current outcome, instead of null?
- return null;
- }
- }
-
- public String getConversationIdOrOutcome()
- {
- return resultingConversationIdOrOutcome==null ?
- getLongRunningConversationId() :
- resultingConversationIdOrOutcome;
- }
-
- public void setConversationIdOrOutcome(String selectedId)
- {
- this.conversationIdOrOutcome = selectedId;
- }
-
- public String select()
- {
-
- boolean isOutcome = conversationIdOrOutcome==null ||
- (!Character.isDigit(conversationIdOrOutcome.charAt(0)) && conversationIdOrOutcome.indexOf(':') < 0);
-
- String actualOutcome;
- if (isOutcome)
- {
- resultingConversationIdOrOutcome = conversationIdOrOutcome;
- actualOutcome = conversationIdOrOutcome;
- }
- else
- {
- ConversationEntry ce = ConversationEntries.instance().getConversationEntry(conversationIdOrOutcome);
- if (ce!=null)
- {
- resultingConversationIdOrOutcome = ce.getId();
- ce.redirect();
- }
- actualOutcome = null;
- }
- return actualOutcome;
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/UiComponent.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/UiComponent.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/UiComponent.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,81 +0,0 @@
-package org.jboss.seam.faces;
-
-import static org.jboss.seam.ScopeType.STATELESS;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.util.AbstractMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-
-/**
- * Access to UIComponents in the current view, by id.
- *
- * @author Gavin King
- *
- */
- at Name("org.jboss.seam.faces.uiComponent")
- at BypassInterceptors
- at Scope(STATELESS)
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
-public class UiComponent
-{
-
- @Unwrap
- public Map<String, UIComponent> getViewComponents()
- {
- return new AbstractMap<String, UIComponent>()
- {
-
- @Override
- public boolean containsKey(Object key) {
- return get(key) != null;
- }
-
-
- @Override
- public Set<Map.Entry<String, UIComponent>> entrySet()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public UIComponent get(Object key)
- {
- if ( !(key instanceof String) ) return null;
- try
- {
- FacesContext context = FacesContext.getCurrentInstance();
-
- if (context == null) {
- return null;
- }
-
- UIViewRoot viewRoot = context.getViewRoot();
-
- if (viewRoot == null)
- {
- return null;
- }
-
- return viewRoot.findComponent( (String) key );
- }
- catch (IllegalArgumentException iae)
- {
- return null;
- }
- }
-
- };
- }
-
-}
Deleted: modules/trunk/faces/src/main/java/org/jboss/seam/faces/UserPrincipal.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/UserPrincipal.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/UserPrincipal.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,30 +0,0 @@
-package org.jboss.seam.faces;
-
-import java.security.Principal;
-
-import javax.annotation.Named;
-import javax.context.ApplicationScoped;
-import javax.faces.context.FacesContext;
-
-/**
- * Manager component for the current user Principal
- * exposed via the JSF ExternalContext.
- *
- * @author Gavin King
- */
- at Named
- at ApplicationScoped
-public class UserPrincipal extends org.jboss.seam.web.UserPrincipal
-{
- @Unwrap @Override
- public Principal getUserPrincipal()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( facesContext != null )
- {
- return facesContext.getExternalContext().getUserPrincipal();
- }
-
- return super.getUserPrincipal();
- }
-}
Modified: modules/trunk/faces/src/main/java/org/jboss/seam/faces/Validation.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/Validation.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/Validation.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -10,10 +10,11 @@
/**
* Allows the application to determine whether the JSF validation
* phase completed successfully, or if a validation failure
- * occurred.
+ * occurred. This functionality is actually provided by JSF 2 now.
+ * What this class does is raise a {@link ValidationFailedEvent}
+ * so that observers can react accordingly.
*
* @author Gavin king
- *
*/
@Named
public class Validation
@@ -25,8 +26,8 @@
public void afterProcessValidations(FacesContext facesContext)
{
- failed = facesContext.getRenderResponse();
- if (failed)
+ failed = facesContext.isValidationFailed();
+ if (failed)
{
manager.fireEvent(new ValidationFailedEvent());
}
Copied: modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/LocaleConfig.java (from rev 10661, modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleConfig.java)
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/LocaleConfig.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/LocaleConfig.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,128 @@
+package org.jboss.seam.faces.application;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.context.ApplicationScoped;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.inject.Initializer;
+
+/**
+ * FIXME update docs
+ * 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
+ */
+ at ApplicationScoped
+public class LocaleConfig
+{
+ private String defaultLocale;
+
+ private List<String> supportedLocales;
+
+ @Initializer
+ 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;
+ }
+
+ 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 (variant != null && variant.length() > 0)
+ {
+ return new java.util.Locale(language, country, variant);
+ }
+ else if (country != null && country.length() > 0)
+ {
+ 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;
+ }
+ }
+
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplication.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplication.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplication.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.faces.application;
+
+import javax.el.ExpressionFactory;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationWrapper;
+import org.jboss.seam.el.SeamExpressionFactory;
+
+/**
+ * Proxies the JSF Application object, and adds all kinds
+ * of tasty extras.
+ *
+ * @author Gavin King
+ */
+public class SeamApplication extends ApplicationWrapper {
+
+ protected Application delegate;
+
+ public SeamApplication(Application delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public Application getWrapped() {
+ return delegate;
+ }
+
+ @Override
+ public ExpressionFactory getExpressionFactory() {
+ // TODO need to push SeamFacesELResolver into SeamEL composite resolver
+ return SeamExpressionFactory.INSTANCE;
+ }
+
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplicationFactory.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplicationFactory.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/application/SeamApplicationFactory.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.faces.application;
+
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+/**
+ * Factory for SeamApplication (how could you possibly
+ * have figured that out without JavaDoc?)
+ *
+ * @see SeamApplication
+ * @author Gavin King
+ */
+public class SeamApplicationFactory extends ApplicationFactory {
+
+ private final ApplicationFactory delegate;
+
+ public SeamApplicationFactory(ApplicationFactory delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public Application getApplication()
+ {
+ return new SeamApplication(delegate.getApplication());
+ }
+
+ @Override
+ public void setApplication(Application application)
+ {
+ this.delegate.setApplication(application);
+ }
+
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/el/SeamFacesELResolver.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/el/SeamFacesELResolver.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/el/SeamFacesELResolver.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * $Id$
+ */
+package org.jboss.seam.faces.el;
+
+import javax.el.ELContext;
+import javax.faces.model.DataModel;
+import org.jboss.seam.el.AbstractELResolver;
+
+/**
+ * <p>An {@link ELResolver} implementation that adds magic properties
+ * to a JSF DataModel object.</p>
+ *
+ * <p>The following is a list of the magic properties:</p>
+ *
+ * <ul>
+ * <li>size - the size of the wrapped data</li>
+ * <li>empty - a boolean indicating whether the wrapped data is empty</li>
+ * </ul>
+ *
+ * <p>Assuming the variable <code>results</code> held a reference to a JSF
+ * DataModel, you could print out its size using the following expression:</p>
+ *
+ * <pre>#{results.size}</pre>
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public class SeamFacesELResolver extends AbstractELResolver {
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ if (base instanceof DataModel)
+ {
+ return resolveInDataModel(context, base, property);
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ return (base instanceof DataModel);
+ }
+
+ private Object resolveInDataModel(ELContext context, Object base, Object property)
+ {
+ if ("size".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return ((DataModel) base).getRowCount();
+ }
+ else if ("empty".equals(property))
+ {
+ context.setPropertyResolved(true);
+ return ((DataModel) base).getRowCount() == 0;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/StatusMessagesTranslator.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/StatusMessagesTranslator.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/StatusMessagesTranslator.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,38 @@
+package org.jboss.seam.faces.lifecycle;
+
+import java.beans.Introspector;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.international.StatusMessages;
+
+/**
+ * A {@link ComponentSystemEventListener} that observes the PreRenderViewEvent and
+ * transposes Seam StatusMessage objects into FacesMessage objects
+ * and stores them in the FacesContext.
+ *
+ * @author Dan Allen
+ */
+public class StatusMessagesTranslator implements ComponentSystemEventListener {
+
+ public void processEvent(ComponentSystemEvent preRenderViewEvent) throws AbortProcessingException
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ FacesMessages facesMessages = (FacesMessages) context.getApplication().getExpressionFactory()
+ .createValueExpression(getBeanExpression(StatusMessages.class), FacesMessages.class).getValue(context.getELContext());
+ facesMessages.beforeRenderView();
+ }
+
+ private String getBeanName(Class beanClass)
+ {
+ return beanClass.getPackage() + "." + Introspector.decapitalize(beanClass.getSimpleName());
+ }
+
+ private String getBeanExpression(Class beanClass)
+ {
+ return "#{" + getBeanName(beanClass) + "}";
+ }
+
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ArrayDataModel.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ArrayDataModel.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ArrayDataModel.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,40 @@
+//$Id: ArrayDataModel.java 5372 2007-06-21 05:27:29Z gavin $
+package org.jboss.seam.faces.model;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+/**
+ * A JSF DataModel for arrays.
+ *
+ * @author Gavin King
+ */
+public class ArrayDataModel extends javax.faces.model.ArrayDataModel implements
+ Serializable
+{
+ private static final long serialVersionUID = -1369792328129853864L;
+
+ public ArrayDataModel()
+ {
+ }
+
+ public ArrayDataModel(Object[] array)
+ {
+ super(array);
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ oos.writeObject(getWrappedData());
+ oos.writeInt(getRowIndex());
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException,
+ ClassNotFoundException
+ {
+ this.setWrappedData(ois.readObject());
+ this.setRowIndex(ois.readInt());
+ }
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ListDataModel.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ListDataModel.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/ListDataModel.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,40 @@
+//$Id: ListDataModel.java 5372 2007-06-21 05:27:29Z gavin $
+package org.jboss.seam.faces.model;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * A JSF DataModel for lists - yes, I know, JSF has one, but its not
+ * serializable (go figure).
+ *
+ * @author Gavin King
+ */
+public class ListDataModel extends javax.faces.model.ListDataModel implements Serializable
+{
+ private static final long serialVersionUID = 5156131434571541698L;
+
+ public ListDataModel()
+ {
+ }
+
+ public ListDataModel(List list)
+ {
+ super(list);
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ oos.writeObject(getWrappedData());
+ oos.writeInt(getRowIndex());
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
+ {
+ this.setWrappedData(ois.readObject());
+ this.setRowIndex(ois.readInt());
+ }
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/MapDataModel.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/MapDataModel.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/MapDataModel.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,154 @@
+//$Id: MapDataModel.java 7579 2008-03-14 12:08:54Z pete.muir at jboss.org $
+package org.jboss.seam.faces.model;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.model.DataModelEvent;
+import javax.faces.model.DataModelListener;
+
+/**
+ * A JSF DataModel for maps.
+ *
+ * @author Gavin King
+ */
+public class MapDataModel extends javax.faces.model.DataModel implements
+ Serializable
+{
+ private static final long serialVersionUID = -4888962547222002402L;
+ private int rowIndex = -1;
+ private Map data;
+ private transient List<Map.Entry> entries;
+
+ public MapDataModel()
+ {
+ }
+
+ public MapDataModel(Map map)
+ {
+ if (map == null)
+ {
+ throw new IllegalArgumentException("null map data");
+ }
+ setWrappedData(map);
+ }
+
+ @Override
+ public int getRowCount()
+ {
+ if (entries == null)
+ {
+ return -1;
+ }
+ return entries.size();
+ }
+
+ /**
+ * Returns a Map.Entry
+ */
+ @Override
+ public Object getRowData()
+ {
+ if (entries == null)
+ {
+ return null;
+ }
+ if (!isRowAvailable())
+ {
+ throw new IllegalArgumentException("row is unavailable");
+ }
+ return entries.get(rowIndex);
+ }
+
+ @Override
+ public int getRowIndex()
+ {
+ return rowIndex;
+ }
+
+ @Override
+ public Object getWrappedData()
+ {
+ return new AbstractMap()
+ {
+ @Override
+ public Set entrySet()
+ {
+ return new AbstractSet()
+ {
+ @Override
+ public Iterator iterator()
+ {
+ return entries.iterator();
+ }
+
+ @Override
+ public int size()
+ {
+ return entries.size();
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public boolean isRowAvailable()
+ {
+ return entries != null &&
+ rowIndex >= 0 &&
+ rowIndex < entries.size();
+ }
+
+ @Override
+ public void setRowIndex(int newRowIndex)
+ {
+ if (newRowIndex < -1)
+ {
+ throw new IllegalArgumentException("illegal rowIndex " + newRowIndex);
+ }
+ int oldRowIndex = rowIndex;
+ rowIndex = newRowIndex;
+ if (entries != null && oldRowIndex != newRowIndex)
+ {
+ Object data = isRowAvailable() ? getRowData() : null;
+ DataModelEvent event = new DataModelEvent(this, newRowIndex, data);
+ DataModelListener[] listeners = getDataModelListeners();
+ for (int i = 0; i < listeners.length; i++)
+ {
+ listeners[i].rowSelected(event);
+ }
+ }
+ }
+
+ @Override
+ public void setWrappedData(Object data)
+ {
+ this.data = (Map) data;
+ entries = data == null ? null : new ArrayList(((Map) data).entrySet());
+ setRowIndex(data != null ? 0 : -1);
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ oos.writeInt(rowIndex);
+ oos.writeObject(data);
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException,
+ ClassNotFoundException
+ {
+ rowIndex = ois.readInt();
+ data = (Map) ois.readObject();
+ entries = data == null ? null : new ArrayList(data.entrySet());
+ }
+}
Added: modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/SetDataModel.java
===================================================================
--- modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/SetDataModel.java (rev 0)
+++ modules/trunk/faces/src/main/java/org/jboss/seam/faces/model/SetDataModel.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,139 @@
+//$Id: SetDataModel.java 7577 2008-03-14 11:47:09Z pete.muir at jboss.org $
+package org.jboss.seam.faces.model;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.model.DataModelEvent;
+import javax.faces.model.DataModelListener;
+
+/**
+ * A JSF DataModel for sets.
+ *
+ * @author Gavin King
+ */
+public class SetDataModel extends javax.faces.model.DataModel implements
+ Serializable
+{
+ private static final long serialVersionUID = -616367764778689337L;
+ private int rowIndex = -1;
+ private List entries;
+
+ public SetDataModel()
+ {
+ }
+
+ public SetDataModel(Set set)
+ {
+ if (set == null)
+ {
+ throw new IllegalArgumentException("null set data");
+ }
+ setWrappedData(set);
+ }
+
+ @Override
+ public int getRowCount()
+ {
+ if (entries == null)
+ {
+ return -1;
+ }
+ return entries.size();
+ }
+
+ @Override
+ public Object getRowData()
+ {
+ if (entries == null)
+ {
+ return null;
+ }
+ if (!isRowAvailable())
+ {
+ throw new IllegalArgumentException("row is unavailable");
+ }
+ return entries.get(rowIndex);
+ }
+
+ @Override
+ public int getRowIndex()
+ {
+ return rowIndex;
+ }
+
+ @Override
+ public Object getWrappedData()
+ {
+ return new AbstractSet()
+ {
+ @Override
+ public Iterator iterator()
+ {
+ return entries.iterator();
+ }
+
+ @Override
+ public int size()
+ {
+ return entries.size();
+ }
+ };
+ }
+
+ @Override
+ public boolean isRowAvailable()
+ {
+ return entries != null &&
+ rowIndex >= 0 &&
+ rowIndex < entries.size();
+ }
+
+ @Override
+ public void setRowIndex(int newRowIndex)
+ {
+ if (newRowIndex < -1)
+ {
+ throw new IllegalArgumentException("illegal rowIndex " + newRowIndex);
+ }
+ int oldRowIndex = rowIndex;
+ rowIndex = newRowIndex;
+ if (entries != null && oldRowIndex != newRowIndex)
+ {
+ Object data = isRowAvailable() ? getRowData() : null;
+ DataModelEvent event = new DataModelEvent(this, newRowIndex, data);
+ DataModelListener[] listeners = getDataModelListeners();
+ for (int i = 0; i < listeners.length; i++)
+ {
+ listeners[i].rowSelected(event);
+ }
+ }
+ }
+
+ @Override
+ public void setWrappedData(Object data)
+ {
+ entries = data == null ? null : new ArrayList((Set) data);
+ setRowIndex(data != null ? 0 : -1);
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ oos.writeInt(rowIndex);
+ oos.writeObject(entries);
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException,
+ ClassNotFoundException
+ {
+ rowIndex = ois.readInt();
+ entries = (List) ois.readObject();
+ }
+}
Added: modules/trunk/faces/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/trunk/faces/src/main/resources/META-INF/faces-config.xml (rev 0)
+++ modules/trunk/faces/src/main/resources/META-INF/faces-config.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0"
+ id="seam-faces">
+
+ <ordering>
+ <after>web-beans</after>
+ </ordering>
+
+ <factory>
+ <application-factory>org.jboss.seam.faces.application.SeamApplicationFactory</application-factory>
+ </factory>
+
+ <application>
+ <el-resolver>org.jboss.seam.el.SeamELResolver</el-resolver>
+ <el-resolver>org.jboss.seam.faces.el.SeamFacesELResolver</el-resolver>
+ <system-event-listener>
+ <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
+ <system-event-listener-class>org.jboss.seam.faces.lifecycle.StatusMessagesTranslator</system-event-listener-class>
+ </system-event-listener>
+ </application>
+
+</faces-config>
Modified: modules/trunk/international/pom.xml
===================================================================
--- modules/trunk/international/pom.xml 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/pom.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,48 +1,44 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>seam-parent</artifactId>
- <groupId>org.jboss.seam</groupId>
+ <groupId>org.jboss.seam</groupId>
<version>3.0.0-SNAPSHOT</version>
- </parent>
-
+ </parent>
+
<artifactId>seam-international</artifactId>
<packaging>jar</packaging>
<version>3.0.0-SNAPSHOT</version>
- <name>Seam Internationalization</name>
+ <name>Seam Internationalization Module</name>
<dependencies>
<dependency>
- <groupId>javax.faces</groupId>
- <artifactId>jsf-api</artifactId>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>seam-el</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>jsr299-api</artifactId>
- </dependency>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.webbeans</groupId>
<artifactId>webbeans-logging</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.seam</groupId>
- <artifactId>seam-faces</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.seam</groupId>
- <artifactId>seam-el</artifactId>
- </dependency>
+ <!-- provided? -->
+ </dependency>
</dependencies>
</project>
Added: modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java (rev 0)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/Interpolator.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,182 @@
+package org.jboss.seam.international;
+
+import org.jboss.seam.el.*;
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import javax.context.Dependent;
+import javax.inject.Current;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Interpolates EL expressions in Strings
+ *
+ * @author Gavin King
+ */
+ at Dependent
+public class Interpolator
+{
+ private static final LogProvider log = Logging.getLogProvider(Interpolator.class);
+
+ // QUESTION should this be Manager, then lookup by type?
+ @Current Expressions expressions;
+
+ @Current Locale locale;
+
+ /**
+ * Replace all EL expressions in the form #{...} with their evaluated
+ * values.
+ *
+ * @param string a template
+ * @return the interpolated string
+ */
+ public String interpolate(String string, Object... params)
+ {
+ if (params == null)
+ {
+ params = new Object[0];
+ }
+
+ if (params.length > 10)
+ {
+ throw new IllegalArgumentException("The number of parameters supplied (" + params.length + ") to the interpolator exceeds the limit of 10 parameters.");
+ }
+
+ if (string.indexOf('#') >= 0 || string.indexOf('{') >= 0)
+ {
+ string = interpolateExpressions(string, params);
+ }
+
+ return string;
+ }
+
+ private String interpolateExpressions(String string, Object... params)
+ {
+ StringTokenizer tokens = new StringTokenizer(string, "#{}", true);
+ StringBuilder builder = new StringBuilder(string.length());
+ try
+ {
+ while (tokens.hasMoreTokens())
+ {
+ String tok = tokens.nextToken();
+
+ if ("#".equals(tok) && tokens.hasMoreTokens())
+ {
+ String nextTok = tokens.nextToken();
+
+ while (nextTok.equals("#") && tokens.hasMoreTokens())
+ {
+ builder.append(tok);
+ nextTok = tokens.nextToken();
+ }
+
+ if ("{".equals(nextTok))
+ {
+ String expression = "#{" + tokens.nextToken() + "}";
+ try
+ {
+ Object value = expressions.createValueExpression(expression).getValue();
+ if (value != null)
+ {
+ builder.append(value);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("exception interpolating string: " + string, e);
+ }
+ tokens.nextToken(); // the trailing "}"
+
+ }
+ else if (nextTok.equals("#"))
+ {
+ // could be trailing #
+ builder.append("#");
+
+ }
+ else
+ {
+ int index;
+ try
+ {
+ index = Integer.parseInt(nextTok.substring(0, 1));
+ if (index >= params.length)
+ {
+ //log.warn("parameter index out of bounds: " + index + " in: " + string);
+ builder.append("#").append(nextTok);
+ }
+ else
+ {
+ builder.append(params[index]).append(nextTok.substring(1));
+ }
+ }
+ catch (NumberFormatException nfe)
+ {
+ builder.append("#").append(nextTok);
+ }
+ }
+ }
+ else if ("{".equals(tok))
+ {
+ StringBuilder expr = new StringBuilder();
+
+ expr.append(tok);
+ int level = 1;
+
+ while (tokens.hasMoreTokens())
+ {
+ String nextTok = tokens.nextToken();
+ expr.append(nextTok);
+
+ if (nextTok.equals("{"))
+ {
+ ++level;
+ }
+ else if (nextTok.equals("}"))
+ {
+ if (--level == 0)
+ {
+ try
+ {
+ if (params.length == 0)
+ {
+ builder.append(expr.toString());
+ }
+ else
+ {
+ String value = new MessageFormat(expr.toString(), locale).format(params);
+ builder.append(value);
+ }
+ }
+ catch (Exception e)
+ {
+ // if it is a bad message, use the expression itself
+ builder.append(expr);
+ }
+ expr = null;
+ break;
+ }
+ }
+ }
+
+ if (expr != null)
+ {
+ builder.append(expr);
+ }
+ }
+ else
+ {
+ builder.append(tok);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("exception interpolating string: " + string, e);
+ }
+
+ return builder.toString();
+ }
+}
Deleted: modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleConfig.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleConfig.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleConfig.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,128 +0,0 @@
-package org.jboss.seam.international;
-
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import javax.context.ApplicationScoped;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
-import javax.inject.Initializer;
-import org.jboss.seam.international.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
- */
- at ApplicationScoped
-public class LocaleConfig
-{
- private String defaultLocale;
-
- private List<String> supportedLocales;
-
- @Initializer
- 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;
- }
-
- 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;
- }
- }
-
-}
Added: modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java (rev 0)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleProducer.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,21 @@
+package org.jboss.seam.international;
+
+import javax.annotation.Named;
+import javax.inject.Produces;
+
+/**
+ * Producer component for the current locale. This base
+ * implementation simply returns the server default
+ * locale.
+ *
+ * @author Gavin King
+ */
+public class LocaleProducer
+{
+ public
+ @Produces
+ @Named java.util.Locale getLocale()
+ {
+ return java.util.Locale.getDefault();
+ }
+}
\ No newline at end of file
Deleted: modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleSelector.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleSelector.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/LocaleSelector.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,197 +0,0 @@
-package org.jboss.seam.international;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-import javax.annotation.Named;
-import javax.context.SessionScoped;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ValueChangeEvent;
-import javax.faces.model.SelectItem;
-import javax.inject.Current;
-import javax.inject.Initializer;
-import javax.inject.Produces;
-import javax.inject.manager.Manager;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-
-import org.jboss.seam.faces.Selector;
-import org.jboss.seam.international.events.LocaleSelectedEvent;
-import org.jboss.seam.international.util.Strings;
-
-/**
- * Selects the current user's locale
- *
- * @author Gavin King
- */
- at Named
- at SessionScoped
-public class LocaleSelector extends Selector
-{
- private static final long serialVersionUID = -6087667065688208261L;
-
- @Current Manager manager;
- @Current HttpServletRequest request;
-
- private String language;
- private String country;
- private String variant;
-
- @Initializer
- public void initLocale()
- {
- String localeString = getCookieValueIfEnabled();
- if (localeString!=null) setLocaleString(localeString);
- }
-
- @Override
- protected String getCookieName()
- {
- return "org.jboss.seam.core.Locale";
- }
-
- /**
- * Force the resource bundle to reload, using the current locale,
- * and raise the org.jboss.seam.localeSelected event.
- */
- public void select()
- {
- FacesContext.getCurrentInstance().getViewRoot().setLocale( getLocale() );
- //Contexts.removeFromAllContexts("org.jboss.seam.core.resourceBundle");
- Contexts.removeFromAllContexts("org.jboss.seam.international.messages");
-
- setCookieValueIfEnabled( getLocaleString() );
-
- manager.fireEvent(new LocaleSelectedEvent(getLocaleString()));
- }
-
- public void select(ValueChangeEvent event)
- {
- setLocaleString( (String) event.getNewValue() );
- select();
- }
-
- /**
- * Set the language and force resource bundle reload, useful for quick action links:
- * <tt><h:commandLink value="DE" action="#{localeSelector.selectLanguage('de')}"/>"/></tt>
- */
- public void selectLanguage(String language) {
- setLanguage(language);
- select();
- }
-
- public Locale calculateLocale(Locale jsfLocale)
- {
- 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 if ( !Strings.isEmpty(language) )
- {
- return new java.util.Locale(language);
- }
- else
- {
- return jsfLocale;
- }
- }
-
- public void setLocale(Locale locale)
- {
- language = Strings.nullIfEmpty( locale.getLanguage() );
- country = Strings.nullIfEmpty( locale.getCountry() );
- variant = Strings.nullIfEmpty( locale.getVariant() );
- }
-
- public String getLocaleString()
- {
- return getLocale().toString();
- }
-
- public void setLocaleString(String localeString)
- {
- StringTokenizer tokens = new StringTokenizer(localeString, "-_");
- language = tokens.hasMoreTokens() ? tokens.nextToken() : null;
- country = tokens.hasMoreTokens() ? tokens.nextToken() : null;
- variant = tokens.hasMoreTokens() ? tokens.nextToken() : null;
- }
-
- public List<SelectItem> getSupportedLocales()
- {
- List<SelectItem> selectItems = new ArrayList<SelectItem>();
- Iterator<Locale> locales = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
- while ( locales.hasNext() )
- {
- Locale locale = locales.next();
- if ( !Strings.isEmpty( locale.getLanguage() ) )
- {
- selectItems.add( new SelectItem( locale.toString(), locale.getDisplayName(locale) ) );
- }
- }
- return selectItems;
- }
-
- /**
- * Get the selected locale
- */
- @Produces public Locale getLocale()
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if (facesContext!=null)
- {
- //Note: this does a double dispatch back to LocaleSelector.calculateLocale()
- return facesContext.getApplication().getViewHandler().calculateLocale(facesContext);
- }
-
- if (request!=null)
- {
- return calculateLocale( request.getLocale() );
- }
-
- return calculateLocale( Locale.getDefault() );
- }
-
- public String getCountry()
- {
- if (country==null) return getLocale().getCountry();
- return country;
- }
-
- public void setCountry(String country)
- {
- setDirty(this.country, country);
- this.country = country;
- }
-
- public String getLanguage()
- {
- if (language==null) return getLocale().getLanguage();
- return language;
- }
-
- public void setLanguage(String language)
- {
- setDirty(this.language, language);
- this.language = language;
- }
-
- public String getVariant()
- {
- if (variant==null) return getLocale().getVariant();
- return variant;
- }
-
- public void setVariant(String variant)
- {
- setDirty(this.variant, variant);
- this.variant = variant;
- }
-
-}
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -25,5 +25,4 @@
@Inherited
public @interface Messages
{
-
}
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,108 +1,117 @@
-package org.jboss.seam.international;
-
-import java.util.AbstractMap;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-
-import javax.context.RequestScoped;
-import javax.inject.Current;
-import javax.inject.Produces;
-
-/**
- * Factory for a Map that contains interpolated messages defined in the
- * Seam ResourceBundle.
- *
- * @see org.jboss.seam.core.SeamResourceBundle
- *
- * @author Gavin King
- */
-public class MessagesProducer
-{
- //TODO: now we have ELResolver, it doesn't *have* to be a Map...
-
- @Current ResourceBundle bundle;
-
- protected Map createMap()
- {
- // AbstractMap uses the implementation of entrySet to perform all its
- // operations - for a resource bundle this is very inefficient for keys
- return new AbstractMap<String, String>()
- {
- @Override
- public String get(Object key)
- {
- if (key instanceof String)
- {
- String resourceKey = (String) key;
- String resource=null;
- if (bundle!=null)
- {
- try
- {
- resource = bundle.getString(resourceKey);
- }
- catch (MissingResourceException mre)
- {
- //Just swallow
- }
- }
- return resource==null ? resourceKey : resource;
- }
- else
- {
- return null;
- }
- }
-
- @Override
- public Set<Map.Entry<String, String>> entrySet()
- {
- Enumeration<String> keys = bundle.getKeys();
- Map<String, String> map = new HashMap<String, String>();
- while ( keys.hasMoreElements() )
- {
- String key = keys.nextElement();
- map.put( key, get(key) );
- }
- return Collections.unmodifiableSet(map.entrySet());
- }
-
- @Override
- public boolean containsKey(Object key)
- {
- return get(key) != null;
- }
-
- @Override
- public Set<String> keySet()
- {
- Enumeration<String> keys = bundle.getKeys();
- return new HashSet<String>(Collections.list(keys));
- }
-
- @Override
- public int size()
- {
- return keySet().size();
- }
-
- };
- }
-
- /**
- * Create the Map and cache it in the EVENT scope. No need to cache
- * it in the SESSION scope, since it is inexpensive to create.
- *
- * @return a Map that interpolates messages in the Seam ResourceBundle
- */
- @Produces @RequestScoped @Messages public Map<String, String> getMessages()
- {
- return createMap();
- }
-}
+package org.jboss.seam.international;
+
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.annotation.Named;
+import javax.context.RequestScoped;
+import javax.inject.Current;
+import javax.inject.Produces;
+
+/**
+ * Factory for a Map that contains interpolated messages defined in the
+ * Seam ResourceBundle.
+ *
+ * @see SeamResourceBundle
+ *
+ * @author Gavin King
+ */
+public class MessagesProducer
+{
+ //TODO: now we have ELResolver, it doesn't *have* to be a Map...
+
+ @Current ResourceBundle bundle;
+
+ protected Map createMap()
+ {
+ // AbstractMap uses the implementation of entrySet to perform all its
+ // operations - for a resource bundle this is very inefficient for keys
+ return new AbstractMap<String, String>()
+ {
+ // FIXME disable temporarily
+ //private java.util.ResourceBundle bundle = ResourceBundleProducer.getBundle();
+ private java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("messages");
+
+ @Override
+ public String get(Object key)
+ {
+ if (key instanceof String)
+ {
+ String resourceKey = (String) key;
+ String resource=null;
+ if (bundle!=null)
+ {
+ try
+ {
+ resource = bundle.getString(resourceKey);
+ }
+ catch (MissingResourceException mre)
+ {
+ //Just swallow
+ }
+ }
+ return resource==null ? resourceKey : resource;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public Set<Map.Entry<String, String>> entrySet()
+ {
+ Enumeration<String> keys = bundle.getKeys();
+ Map<String, String> map = new HashMap<String, String>();
+ while ( keys.hasMoreElements() )
+ {
+ String key = keys.nextElement();
+ map.put( key, get(key) );
+ }
+ return Collections.unmodifiableSet(map.entrySet());
+ }
+
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return get(key) != null;
+ }
+
+ @Override
+ public Set<String> keySet()
+ {
+ Enumeration<String> keys = bundle.getKeys();
+ return new HashSet<String>(Collections.list(keys));
+ }
+
+ @Override
+ public int size()
+ {
+ return keySet().size();
+ }
+
+ };
+ }
+
+ /**
+ * Create the Map and cache it in the request scope. No need to cache
+ * it in the session scope, since it is inexpensive to create.
+ *
+ * @return a Map that interpolates messages in the Seam ResourceBundle
+ */
+ @Produces
+ @Named("org.jboss.seam.international.messages")
+ @RequestScoped
+ @Messages public Map<String, String> getMessages()
+ {
+ return createMap();
+ }
+
+}
Added: modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceBundle.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceBundle.java (rev 0)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceBundle.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -0,0 +1,24 @@
+package org.jboss.seam.international;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.inject.BindingType;
+
+/**
+ * The binding type for the Seam resource bundle.
+ *
+ * @author Dan Allen
+ */
+public
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+ at Inherited
+ at interface ResourceBundle {
+}
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceLoader.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceLoader.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/ResourceLoader.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,89 +1,186 @@
-package org.jboss.seam.international;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Locale;
-import java.util.MissingResourceException;
-
-import javax.context.Dependent;
-import javax.inject.Current;
-import javax.servlet.ServletContext;
-
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-import org.jboss.seam.international.util.Resources;
-import org.jboss.seam.international.util.Strings;
-
-/**
- * Access to application resources and resource bundles.
- *
- * @author Gavin King
- *
- */
- at Dependent
-public class ResourceLoader
-{
- private static final LogProvider log = Logging.getLogProvider(ResourceLoader.class);
-
- private String[] bundleNames = {"messages"};
-
- @Current ServletContext servletContext;
- @Current Locale locale;
-
- /**
- * The configurable list of delegate resource bundle names
- *
- * @return an array of resource bundle names
- */
- public String[] getBundleNames()
- {
- return bundleNames;
- }
-
- public void setBundleNames(String[] bundleNames)
- {
- this.bundleNames = bundleNames;
- }
-
- public InputStream getResourceAsStream(String resource)
- {
- return Resources.getResourceAsStream( resource, servletContext );
- }
-
- public URL getResource(String resource)
- {
- return Resources.getResource( resource, servletContext );
- }
-
- /**
- * Load a resource bundle by name (may be overridden by subclasses
- * who want to use non-standard resource bundle types).
- *
- * @param bundleName the name of the resource bundle
- * @return an instance of java.util.ResourceBundle
- */
- public java.util.ResourceBundle loadBundle(String bundleName)
- {
- try
- {
- java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle(
- bundleName, locale,
- Thread.currentThread().getContextClassLoader()
- );
- log.debug("loaded resource bundle: " + bundleName);
- return bundle;
- }
- catch (MissingResourceException mre)
- {
- log.debug("resource bundle missing: " + bundleName);
- return null;
- }
- }
-
- @Override
- public String toString()
- {
- String concat = bundleNames==null ? "" : Strings.toString( ", ", (Object[]) bundleNames );
- return "ResourceBundle(" + concat + ")";
- }
-}
+package org.jboss.seam.international;
+
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import javax.context.Dependent;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * Access to application resources and resource bundles.
+ *
+ * @author Gavin King
+ */
+ at Dependent
+public class ResourceLoader
+{
+ private static final LogProvider log = Logging.getLogProvider(ResourceLoader.class);
+
+ private String[] bundleNames = { "messages" };
+
+ @Current Manager manager;
+
+ /**
+ * The configurable list of delegate resource bundle names
+ *
+ * @return an array of resource bundle names
+ */
+ public String[] getBundleNames()
+ {
+ return bundleNames;
+ }
+
+ public void setBundleNames(String[] bundleNames)
+ {
+ this.bundleNames = bundleNames;
+ }
+
+ public InputStream getResourceAsStream(String resource)
+ {
+ String relativePath = resource;
+ if (resource.startsWith("/"))
+ {
+ relativePath = resource.substring(1);
+ }
+ else
+ {
+ resource = "/" + resource;
+ }
+
+ return getResourceAsStream(resource, relativePath);
+ }
+
+ public URL getResource(String resource)
+ {
+ String relativePath = resource;
+ if (resource.startsWith("/"))
+ {
+ relativePath = resource.substring(1);
+ }
+ else
+ {
+ resource = "/" + resource;
+ }
+
+ return getResource(resource, relativePath);
+ }
+
+ /**
+ * Load a resource bundle by name (may be overridden by subclasses
+ * who want to use non-standard resource bundle types).
+ *
+ * @param bundleName the name of the resource bundle
+ * @return an instance of java.util.ResourceBundle
+ */
+ public java.util.ResourceBundle loadBundle(String bundleName)
+ {
+ try
+ {
+ java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle(
+ bundleName,
+ manager.getInstanceByType(Locale.class),
+ Thread.currentThread().getContextClassLoader()
+ );
+ log.debug("loaded resource bundle: " + bundleName);
+ return bundle;
+ }
+ catch (MissingResourceException mre)
+ {
+ log.debug("resource bundle missing: " + bundleName);
+ return null;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder report = new StringBuilder("bundleNames = {");
+ boolean first = true;
+ if (bundleNames != null)
+ {
+ for (Object bundleName : bundleNames)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ report.append(", ");
+ }
+ report.append(bundleName);
+ }
+ }
+ report.append("}");
+
+ return "ResourceBundle(" + report + ")";
+ }
+
+ protected InputStream getResourceAsStream(String path, String relativePath)
+ {
+ InputStream stream = null;
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader != null)
+ {
+ stream = classLoader.getResourceAsStream(relativePath);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from context classloader: " + relativePath);
+ return stream;
+ }
+ }
+
+ stream = getClass().getResourceAsStream(path);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + path);
+ return stream;
+ }
+
+ stream = getClass().getClassLoader().getResourceAsStream(relativePath);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + relativePath);
+ return stream;
+ }
+
+ return stream;
+ }
+
+ protected URL getResource(String path, String relativePath)
+ {
+ URL url = null;
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader != null)
+ {
+ url = classLoader.getResource(relativePath);
+ if (url != null)
+ {
+ log.debug("Loaded resource from context classloader: " + url);
+ return url;
+ }
+ }
+
+ url = getClass().getResource(path);
+ if (url != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ return url;
+ }
+
+ url = getClass().getClassLoader().getResource(relativePath);
+ if (url != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ return url;
+ }
+
+ return url;
+ }
+
+}
Deleted: modules/trunk/international/src/main/java/org/jboss/seam/international/SeamResourceBundle.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/SeamResourceBundle.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/SeamResourceBundle.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,158 +0,0 @@
-package org.jboss.seam.international;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.inject.Current;
-
-import org.jboss.seam.el.Interpolator;
-
-/**
- * The Seam resource bundle which searches for resources in delegate resource
- * bundles specified in pages.xml, and a configurable list of delegate resource
- * bundles specified in components.xml.
- *
- * @see ResourceLoader
- * @author Gavin King
- *
- */
-public class SeamResourceBundle extends java.util.ResourceBundle
-{
- private Map<Locale, List<ResourceBundle>> bundleCache = new ConcurrentHashMap<Locale, List<ResourceBundle>>();
-
- @Current Locale locale;
- @Current Interpolator interpolator;
- @Current ResourceLoader resourceLoader;
-
- /**
- * Get an instance for the current Seam Locale
- *
- * @see Locale
- *
- * @return a SeamResourceBundle
- */
- public java.util.ResourceBundle getBundle()
- {
- return java.util.ResourceBundle.getBundle(SeamResourceBundle.class.getName(), locale);
- }
-
-
- public java.util.ResourceBundle getBundleNamed(String bundleName)
- {
- return java.util.ResourceBundle.getBundle(bundleName, locale);
- }
-
-
- private List<java.util.ResourceBundle> getBundlesForCurrentLocale()
- {
- List<ResourceBundle> bundles = bundleCache.get(locale);
- if ( bundles==null )
- {
- bundles = loadBundlesForCurrentLocale();
- bundleCache.put(locale, bundles);
- }
- return bundles;
-
- }
-
- private List<ResourceBundle> loadBundlesForCurrentLocale()
- {
- List<ResourceBundle> bundles = new ArrayList<ResourceBundle>();
- for (String bundleName : resourceLoader.getBundleNames())
- {
- ResourceBundle bundle = resourceLoader.loadBundle(bundleName);
- if (bundle != null) bundles.add(bundle);
- }
- ResourceBundle bundle = resourceLoader.loadBundle("ValidatorMessages");
- if (bundle != null)
- {
- bundles.add(bundle);
- }
- bundle = resourceLoader.loadBundle("org/hibernate/validator/resources/DefaultValidatorMessages");
- if (bundle != null) bundles.add(bundle);
- bundle = resourceLoader.loadBundle("javax.faces.Messages");
- if (bundle != null) bundles.add(bundle);
- return Collections.unmodifiableList(bundles);
- }
-
- @Override
- public Enumeration<String> getKeys()
- {
- List<java.util.ResourceBundle> pageBundles = getPageResourceBundles();
- List<ResourceBundle> bundles = getBundlesForCurrentLocale();
- Enumeration<String>[] enumerations = new Enumeration[bundles.size() + pageBundles.size()];
-
- int i = 0;
- for (java.util.ResourceBundle bundle: pageBundles) {
- enumerations[i++] = bundle.getKeys();
- }
-
- for (ResourceBundle bundle: bundles) {
- enumerations[i++] = bundle.getKeys();
- }
-
- return new EnumerationEnumeration<String>(enumerations);
- }
-
- @Override
- protected Object handleGetObject(String key)
- {
- List<java.util.ResourceBundle> pageBundles = getPageResourceBundles();
- for (java.util.ResourceBundle pageBundle : pageBundles)
- {
- try
- {
- return interpolate(pageBundle.getObject(key));
- }
- catch (MissingResourceException mre) {}
- }
-
- for (java.util.ResourceBundle littleBundle : getBundlesForCurrentLocale())
- {
- try
- {
- return interpolate( littleBundle.getObject(key) );
- }
- catch (MissingResourceException mre) {}
- }
-
- return null; // superclass is responsible for throwing MRE
- }
-
- private Object interpolate(Object message)
- {
- return message!=null && message instanceof String ?
- interpolator.interpolate( (String) message ) :
- message;
- }
-
- private List<java.util.ResourceBundle> getPageResourceBundles()
- {
- // TODO: oops! A hard dependency to JSF!
- String viewId = Pages.getCurrentViewId();
- if (viewId != null)
- {
- // we can't cache these bundles, since the viewId
- // may change in the middle of a request
- return Pages.instance().getResourceBundles(viewId);
- }
- else
- {
- return Collections.EMPTY_LIST;
- }
- }
-
- @Override
- public Locale getLocale()
- {
- return locale;
- }
-
-}
\ No newline at end of file
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessage.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessage.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessage.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -4,10 +4,6 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import javax.inject.Current;
-
-import org.jboss.seam.el.Interpolator;
-import org.jboss.seam.core.SeamResourceBundle;
import org.jboss.seam.international.util.Strings;
/**
@@ -15,30 +11,26 @@
* in the view layer
*
* @author Pete Muir
- *
*/
public class StatusMessage implements Serializable
{
- @Current Interpolator interpolator;
-
/**
* The severity of the status message
*
*/
public enum Severity
{
- INFO,
- WARN,
- ERROR,
+ INFO,
+ WARN,
+ ERROR,
FATAL;
}
-
private String summaryTemplate;
private String summary;
private String detailTemplate;
private String detail;
private Severity severity = Severity.INFO;
-
+
/**
* Create a status message, looking up the message in the resource bundle
* using the provided key. If the message is found, it is used, otherwise,
@@ -49,18 +41,18 @@
{
this.summaryTemplate = getBundleMessage(key, defaultMessageTemplate);
this.detailTemplate = getBundleMessage(detailKey, defaultMessageDetailTemplate);
- if ( !Strings.isEmpty(summaryTemplate) )
+ if (!Strings.isEmpty(summaryTemplate))
{
this.severity = severity;
}
}
-
+
public boolean isEmpty()
{
return Strings.isEmpty(summary) && Strings.isEmpty(summaryTemplate);
}
-
- public void interpolate(Object... params)
+
+ public void interpolate(Interpolator interpolator, Object... params)
{
if (!Strings.isEmpty(summaryTemplate))
{
@@ -80,7 +72,7 @@
{
return summary;
}
-
+
/**
* Get the message severity
*/
@@ -88,38 +80,42 @@
{
return severity;
}
-
+
public String getDetail()
{
return detail;
}
-
+
public static String getBundleMessage(String key, String defaultMessageTemplate)
{
String messageTemplate = defaultMessageTemplate;
- if ( key!=null )
+ if (key != null)
{
- ResourceBundle resourceBundle = SeamResourceBundle.getBundle();
- if ( resourceBundle!=null )
+ //FIXME disable temporarily
+ //ResourceBundle resourceBundle = ResourceBundleProducer.getBundle();
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("messages");
+ if (resourceBundle != null)
{
try
{
String bundleMessage = resourceBundle.getString(key);
- if (bundleMessage!=null)
+ if (bundleMessage != null)
{
messageTemplate = bundleMessage;
}
}
- catch (MissingResourceException mre) {} //swallow
+ catch (MissingResourceException mre)
+ {
+ //swallow
+ }
}
}
return messageTemplate;
}
-
+
@Override
public String toString()
{
- return "[" + severity + "] " + summary + " (" + detail +")";
+ return "[" + severity + "] " + summary + " (" + detail + ")";
}
-
}
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/StatusMessages.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -9,6 +9,10 @@
import java.util.List;
import java.util.Map;
+import javax.annotation.Named;
+import javax.context.ConversationScoped;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
import javax.validation.ConstraintViolation;
import org.jboss.seam.international.StatusMessage.Severity;
@@ -17,29 +21,32 @@
* a concrete implementation.
*
* @author Pete Muir
- *
*/
-public abstract class StatusMessages implements Serializable
+public
+ at Named("org.jboss.seam.international.statusMessages")
+ at ConversationScoped
+class StatusMessages implements Serializable
{
private static final long serialVersionUID = -5395975397632138270L;
-
- public static final String COMPONENT_NAME = "org.jboss.seam.international.statusMessages";
-
+
private List<StatusMessage> messages = new ArrayList<StatusMessage>();
+
private Map<String, List<StatusMessage>> keyedMessages = new HashMap<String, List<StatusMessage>>();
-
+
private transient List<Runnable> tasks;
+ protected @Current Manager manager;
+
protected List<StatusMessage> getMessages()
{
return messages;
}
-
+
protected Map<String, List<StatusMessage>> getKeyedMessages()
{
return keyedMessages;
}
-
+
/**
* Clear all status messages
*/
@@ -48,17 +55,17 @@
messages.clear();
keyedMessages.clear();
}
-
+
public void clearKeyedMessages(String id)
{
keyedMessages.remove(id);
}
-
+
public void clearGlobalMessages()
{
messages.clear();
}
-
+
/**
* Add a status message, looking up the message in the resource bundle
* using the provided key. If the message is found, it is used, otherwise,
@@ -73,19 +80,16 @@
{
messages.add(message);
getTasks().add(
- new Runnable()
+ new Runnable()
+ {
+ public void run()
{
-
- public void run()
- {
- message.interpolate(params);
- }
-
+ message.interpolate(manager.getInstanceByType(Interpolator.class), params);
}
- );
+ });
}
}
-
+
/**
* Add a status message, looking up the message in the resource bundle
* using the provided key. If the message is found, it is used, otherwise,
@@ -102,7 +106,7 @@
{
final StatusMessage message = new StatusMessage(severity, key, null, messageTemplate, null);
if (!message.isEmpty())
- {
+ {
if (keyedMessages.containsKey(id))
{
keyedMessages.get(id).add(message);
@@ -114,17 +118,14 @@
keyedMessages.put(id, list);
}
getTasks().add(
- new Runnable()
+ new Runnable()
+ {
+ public void run()
{
-
- public void run()
- {
- message.interpolate(params);
- }
-
+ message.interpolate(manager.getInstanceByType(Interpolator.class), params);
}
- );
- }
+ });
+ }
}
/**
@@ -306,7 +307,7 @@
*/
public void add(ConstraintViolation[] cvs)
{
- for (ConstraintViolation cv: cvs)
+ for (ConstraintViolation cv : cvs)
{
add(cv);
}
@@ -320,7 +321,7 @@
*/
public void addToControls(ConstraintViolation[] cvs)
{
- for (ConstraintViolation cv: cvs)
+ for (ConstraintViolation cv : cvs)
{
addToControl(cv);
}
@@ -332,7 +333,7 @@
*/
public void add(ConstraintViolation cv)
{
- add( WARN, cv.getMessage() );
+ add(WARN, cv.getMessage());
}
/**
@@ -344,7 +345,7 @@
public void addToControl(ConstraintViolation cv)
{
String propertyName = cv.getPropertyPath().substring(cv.getPropertyPath().lastIndexOf(".") + 1);
- addToControl( propertyName, cv );
+ addToControl(propertyName, cv);
}
/**
@@ -355,9 +356,9 @@
*/
public void addToControl(String id, ConstraintViolation cv)
{
- addToControl( id, WARN, cv.getMessage() );
+ addToControl(id, WARN, cv.getMessage());
}
-
+
private List<Runnable> getTasks()
{
if (tasks == null)
@@ -366,14 +367,16 @@
}
return tasks;
}
-
+
protected void doRunTasks()
{
- if (tasks!=null)
+ if (tasks != null)
{
- for (Runnable task: tasks) task.run();
+ for (Runnable task : tasks)
+ {
+ task.run();
+ }
tasks.clear();
}
}
-
}
Deleted: modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -1,95 +0,0 @@
-package org.jboss.seam.international;
-
-import javax.annotation.Named;
-import javax.context.SessionScoped;
-import javax.faces.event.ValueChangeEvent;
-import javax.inject.Current;
-import javax.inject.Initializer;
-import javax.inject.Produces;
-import javax.inject.manager.Manager;
-
-import org.jboss.seam.faces.Selector;
-import org.jboss.seam.international.events.TimeZoneSelectedEvent;
-
-/**
- * Selects the current user's time zone, defaulting
- * to the server time zone.
- *
- * @author Gavin King
- */
- at SessionScoped
-public class TimeZoneSelector extends Selector
-{
- private static final long serialVersionUID = -5013819375360015369L;
-
- private String id;
-
- @Current Manager manager;
-
- @Initializer
- public void initTimeZone()
- {
- String timeZoneId = getCookieValueIfEnabled();
- if (timeZoneId!=null) setTimeZoneId(timeZoneId);
- }
-
- @Override
- protected String getCookieName()
- {
- return "org.jboss.seam.core.TimeZone";
- }
-
- /**
- * Force the resource bundle to reload, using the current locale,
- * and raise the org.jboss.seam.timeZoneSelected event
- */
- public void select()
- {
- setCookieValueIfEnabled( getTimeZoneId() );
-
- manager.fireEvent(new TimeZoneSelectedEvent(getTimeZoneId()));
- }
-
- public void select(ValueChangeEvent event)
- {
- selectTimeZone( (String) event.getNewValue() );
- }
-
- public void selectTimeZone(String timeZoneId)
- {
- setTimeZoneId(timeZoneId);
- select();
- }
-
- public void setTimeZone(java.util.TimeZone timeZone)
- {
- setTimeZoneId( timeZone.getID() );
- }
-
- public void setTimeZoneId(String id)
- {
- setDirty(this.id, id);
- this.id = id;
- }
-
- public String getTimeZoneId()
- {
- return id;
- }
-
- /**
- * Get the selected timezone
- */
- @Produces @Named public java.util.TimeZone getTimeZone()
- {
- if (id==null)
- {
- return java.util.TimeZone.getDefault();
- }
- else
- {
- return java.util.TimeZone.getTimeZone( getTimeZoneId() );
- }
- }
-
-}
Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java 2009-04-28 06:04:29 UTC (rev 10668)
@@ -52,7 +52,10 @@
});
}
- @Produces @ApplicationScoped @TimeZones public List<TimeZone> getTimeZones() {
+ @Produces
+ @ApplicationScoped
+ @TimeZones
+ public List<TimeZone> getTimeZones() {
return timeZones;
}
Modified: modules/trunk/parent/pom.xml
===================================================================
--- modules/trunk/parent/pom.xml 2009-04-28 05:40:43 UTC (rev 10667)
+++ modules/trunk/parent/pom.xml 2009-04-28 06:04:29 UTC (rev 10668)
@@ -2,11 +2,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
-
- <groupId>org.jboss.seam</groupId>
- <artifactId>seam-parent</artifactId>
- <packaging>pom</packaging>
- <version>3.0.0-SNAPSHOT</version>
<parent>
<groupId>org.jboss.seam</groupId>
@@ -14,6 +9,10 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
+ <artifactId>seam-parent</artifactId>
+ <packaging>pom</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+
<name>JBoss Seam</name>
<url>http://www.seamframework.org</url>
More information about the seam-commits
mailing list