myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r935183 [3/4] - in /myfaces/extensions/cdi/trunk: ./ jse-modules/ jse-modules/message-module/ jse-modules/message-module/api/ jse-modules/message-module/api/src/ jse-modules/message-module/api/src/main/ jse-modules/message-module/api/src/ma...
Date Sat, 17 Apr 2010 14:53:43 GMT
Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/NumberedArgumentAwareMessageInterpolator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/NumberedArgumentAwareMessageInterpolator.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/NumberedArgumentAwareMessageInterpolator.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/NumberedArgumentAwareMessageInterpolator.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl;
+
+import org.apache.myfaces.extensions.cdi.message.api.NamedArgument;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Manfred Geiler
+ */
+public class NumberedArgumentAwareMessageInterpolator extends AbstractFormatterAwareMessageInterpolator
+{
+    private static final long serialVersionUID = 8699632465559596371L;
+
+    public String interpolate(String messageTemplate, Serializable... arguments)
+    {
+        Serializable[] numberedArguments = addNumberedArguments(arguments);
+
+        if (numberedArguments.length > 0)
+        {
+            return formatMessage(messageTemplate, numberedArguments);
+        }
+
+        return messageTemplate;
+    }
+
+    private Serializable[] addNumberedArguments(Serializable[] arguments)
+    {
+        List<Serializable> result = new ArrayList<Serializable>();
+
+        for (Serializable argument : arguments)
+        {
+            if (!(argument instanceof NamedArgument))
+            {
+                result.add(argument);
+            }
+        }
+
+        return result.toArray(new Serializable[result.size()]);
+    }
+
+    //TODO add warning for unused arguments,...
+    private String formatMessage(String messageTemplate, Serializable[] arguments)
+    {
+        Object[] localizedArguments = null;
+        Object argument;
+        Object localizedArgument;
+
+        for (int i = 0; i < arguments.length; i++)
+        {
+            argument = arguments[i];
+            localizedArgument = formatAsString(argument);
+
+            if (localizedArgument != argument)
+            {
+                if (localizedArguments == null)
+                {
+                    //TODO
+                    localizedArguments = copyArguments(arguments);
+                }
+                localizedArguments[i] = localizedArgument;
+            }
+        }
+
+        MessageFormat messageFormat = new MessageFormat(
+                messageTemplate, this.messageContext.getLocale());
+
+        if (localizedArguments == null)
+        {
+            return messageFormat.format(arguments);
+        }
+        else
+        {
+            return messageFormat.format(localizedArguments);
+        }
+    }
+
+    private Object[] copyArguments(Object[] arguments)
+    {
+        Object[] result = new Object[arguments.length];
+        System.arraycopy(arguments, 0, result, 0, arguments.length);
+        return result;
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContext.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContext.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContext.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl;
+
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContextConfig;
+import org.apache.myfaces.extensions.cdi.message.api.MessageFilter;
+
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ */
+class UnmodifiableMessageContext implements MessageContext
+{
+    private static final long serialVersionUID = -4730350864157813259L;
+    private MessageContext messageContext;
+
+    UnmodifiableMessageContext(MessageContext messageContext)
+    {
+        this.messageContext = messageContext;
+    }
+
+    public MessageContextConfig config()
+    {
+        return new UnmodifiableMessageContextConfig(messageContext.config());
+    }
+
+    public <T extends MessageContext> T typed(Class<T> contextType)
+    {
+        throw new IllegalStateException(UnmodifiableMessageContext.class.getName() +
+                "is readonly after the call of MessageContext#message");
+
+        //alternative:
+        /*
+        if(this.messageContext instanceof UnmodifiableMessageContext)
+        {
+            return (T)((UnmodifiableMessageContext)this.messageContext).getWrappedMessageContext();
+        }
+        return (T)this.messageContext;
+        */
+    }
+
+    /*
+    MessageContext getWrappedMessageContext()
+    {
+        if(this.messageContext instanceof UnmodifiableMessageContext) {
+            return ((UnmodifiableMessageContext)this.messageContext).getWrappedMessageContext();
+        }
+        return messageContext;
+    }
+    */
+
+    /*
+     * generated
+     */
+
+    public MessageBuilder message()
+    {
+        return messageContext.message();
+    }
+
+    public MessageContext cloneContext()
+    {
+        return messageContext.cloneContext();
+    }
+
+    public String getMessageText(Message message)
+    {
+        return messageContext.getMessageText(message);
+    }
+
+    public void addMessage(Message message)
+    {
+        messageContext.addMessage(messageContext, message);
+    }
+
+    public Locale getLocale()
+    {
+        return messageContext.getLocale();
+    }
+
+    public void addMessage(MessageContext messageContext, Message message)
+    {
+        this.messageContext.addMessage(messageContext, message);
+    }
+
+    public void addMessageFilter(MessageFilter... messageFilters)
+    {
+        messageContext.addMessageFilter(messageFilters);
+    }
+
+    public Set<MessageFilter> getMessageFilters()
+    {
+        return messageContext.getMessageFilters();
+    }
+
+    public void removeMessage(Message message)
+    {
+        messageContext.removeMessage(message);
+    }
+
+    public void removeAllMessages()
+    {
+        messageContext.removeAllMessages();
+    }
+
+    public List<Message> getMessages()
+    {
+        return messageContext.getMessages();
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContextConfig.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContextConfig.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/UnmodifiableMessageContextConfig.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl;
+
+import org.apache.myfaces.extensions.cdi.message.api.MessageContextConfig;
+import org.apache.myfaces.extensions.cdi.message.api.LocaleResolver;
+import org.apache.myfaces.extensions.cdi.message.api.MessageResolver;
+import org.apache.myfaces.extensions.cdi.message.api.MessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.api.MessageHandler;
+import org.apache.myfaces.extensions.cdi.message.api.FormatterFactory;
+
+/**
+ * generated
+ *
+ * @author Gerhard Petracek
+ */
+class UnmodifiableMessageContextConfig implements MessageContextConfig
+{
+    private static final long serialVersionUID = -3167585556698594193L;
+    private MessageContextConfig messageContextConfig;
+
+    UnmodifiableMessageContextConfig(MessageContextConfig messageContextConfig)
+    {
+        this.messageContextConfig = messageContextConfig;
+    }
+
+    public MessageContextBuilder use()
+    {
+        //it's ok to delegate - the call of #use creates a new instance of the context - the old context is untouched
+        return this.messageContextConfig.use();
+    }
+
+
+    public MessageContextBuilder change()
+    {
+        throw new IllegalStateException(MessageContextConfig.class.getName() +
+                "is readonly after the call of MessageContext#message");
+    }
+
+    /*
+     * generated
+     */
+    public MessageInterpolator getMessageInterpolator()
+    {
+        return messageContextConfig.getMessageInterpolator();
+    }
+
+    public MessageResolver getMessageResolver()
+    {
+        return messageContextConfig.getMessageResolver();
+    }
+
+    public LocaleResolver getLocaleResolver()
+    {
+        return messageContextConfig.getLocaleResolver();
+    }
+
+    public MessageHandler getMessageHandler()
+    {
+        return messageContextConfig.getMessageHandler();
+    }
+
+    public FormatterFactory getFormatterFactory()
+    {
+        return messageContextConfig.getFormatterFactory();
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/DefaultNumberFormatter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/DefaultNumberFormatter.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/DefaultNumberFormatter.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/DefaultNumberFormatter.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.formatter;
+
+import org.apache.myfaces.extensions.cdi.message.api.Formatter;
+import org.apache.myfaces.extensions.cdi.message.api.GenericConfig;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * @author Manfred Geiler
+ * @author Gerhard Petracek
+ */
+class DefaultNumberFormatter implements Formatter<Number>
+{
+    private Character groupingSeparator;
+    private Character decimalSeparator;
+    private Integer minimumFractionDigits;
+    private Integer minimumIntegerDigits;
+
+    DefaultNumberFormatter()
+    {
+    }
+
+    public boolean isResponsibleFor(Class<?> type)
+    {
+        return Number.class.isAssignableFrom(type);
+    }
+
+    public String format(MessageContext messageContext, Number valueToFormat)
+    {
+        GenericConfig formatterConfig = messageContext.config().getFormatterFactory()
+                .findFormatterConfig(Number.class, messageContext.config().getLocaleResolver().getLocale());
+
+        if (formatterConfig != null)
+        {
+            useCustomConfig(formatterConfig);
+        }
+        else
+        {
+            resetConfig();
+        }
+
+        Locale locale = messageContext.config().getLocaleResolver().getLocale();
+
+        if (valueToFormat instanceof BigDecimal || valueToFormat instanceof Double || valueToFormat instanceof Float)
+        {
+            return getDecimalFormat(locale).format(valueToFormat);
+        }
+        else
+        {
+            return getNumberFormat(locale).format(valueToFormat);
+        }
+    }
+
+    private void resetConfig()
+    {
+        this.groupingSeparator = null;
+        this.decimalSeparator = null;
+        this.minimumFractionDigits = null;
+        this.minimumIntegerDigits = null;
+    }
+
+    private void useCustomConfig(GenericConfig formatterConfig)
+    {
+        if (formatterConfig.containsProperty(NumberFormatterConfigKeys.GROUPING_SEPARATOR_KEY))
+        {
+            this.groupingSeparator = formatterConfig
+                    .getProperty(NumberFormatterConfigKeys.GROUPING_SEPARATOR_KEY, Character.class);
+        }
+
+        if (formatterConfig.containsProperty(NumberFormatterConfigKeys.DECIMAL_SEPARATOR_KEY))
+        {
+            this.decimalSeparator = formatterConfig
+                    .getProperty(NumberFormatterConfigKeys.DECIMAL_SEPARATOR_KEY, Character.class);
+        }
+
+        if (formatterConfig.containsProperty(NumberFormatterConfigKeys.MINIMUM_FRACTION_DIGITS_KEY))
+        {
+            this.minimumFractionDigits = formatterConfig
+                    .getProperty(NumberFormatterConfigKeys.MINIMUM_FRACTION_DIGITS_KEY, Integer.class);
+        }
+
+        if (formatterConfig.containsProperty(NumberFormatterConfigKeys.MINIMUM_INTEGER_DIGITS_KEY))
+        {
+            this.minimumIntegerDigits = formatterConfig
+                    .getProperty(NumberFormatterConfigKeys.MINIMUM_INTEGER_DIGITS_KEY, Integer.class);
+        }
+    }
+
+    private NumberFormat getNumberFormat(Locale locale)
+    {
+        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
+
+        if (this.groupingSeparator != null)
+        {
+            symbols.setGroupingSeparator(this.groupingSeparator);
+        }
+        if (this.decimalSeparator != null)
+        {
+            symbols.setDecimalSeparator(this.decimalSeparator);
+        }
+        return new DecimalFormat("", symbols);
+    }
+
+    private NumberFormat getDecimalFormat(Locale locale)
+    {
+        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
+
+        if (this.groupingSeparator != null)
+        {
+            symbols.setGroupingSeparator(this.groupingSeparator);
+        }
+        if (this.decimalSeparator != null)
+        {
+            symbols.setDecimalSeparator(this.decimalSeparator);
+        }
+
+        DecimalFormat format = new DecimalFormat("", symbols);
+
+        if (this.minimumFractionDigits != null)
+        {
+            format.setMinimumFractionDigits(this.minimumFractionDigits);
+        }
+        if (this.minimumIntegerDigits != null)
+        {
+            format.setMinimumIntegerDigits(this.minimumIntegerDigits);//for 0.**
+        }
+        return format;
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/FormatterBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/FormatterBuilder.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/FormatterBuilder.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/FormatterBuilder.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.formatter;
+
+import org.apache.myfaces.extensions.cdi.message.api.Formatter;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class FormatterBuilder
+{
+    public static Formatter createFormatter(Class<?> type)
+    {
+        if (Number.class.isAssignableFrom(type))
+        {
+            return new DefaultNumberFormatter();
+        }
+        return new ToStringFormatter(type);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/NumberFormatterConfigKeys.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/NumberFormatterConfigKeys.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/NumberFormatterConfigKeys.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/NumberFormatterConfigKeys.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.formatter;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface NumberFormatterConfigKeys
+{
+    static final String GROUPING_SEPARATOR_KEY = "grouping_separator";
+
+    static final String DECIMAL_SEPARATOR_KEY = "decimal_separator";
+
+    static final String MINIMUM_FRACTION_DIGITS_KEY = "minimum_fraction_digits";
+
+    static final String MINIMUM_INTEGER_DIGITS_KEY = "minimum_integer_digits";
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/ToStringFormatter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/ToStringFormatter.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/ToStringFormatter.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/formatter/ToStringFormatter.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.formatter;
+
+import org.apache.myfaces.extensions.cdi.message.api.Formatter;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+class ToStringFormatter implements Formatter<Object>, Serializable
+{
+    private static final long serialVersionUID = 3529715901768617301L;
+
+    private Class responsibleFor;
+
+    ToStringFormatter(Class type)
+    {
+        this.responsibleFor = type;
+    }
+
+    public boolean isResponsibleFor(Class<?> type)
+    {
+        return type.isAssignableFrom(this.responsibleFor);
+    }
+
+    public String format(MessageContext i18nContext, Object valueToFormat)
+    {
+        return valueToFormat != null ? valueToFormat.toString() : "";
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/ELProvider.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/ELProvider.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/ELProvider.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/ELProvider.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.spi;
+
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ELProvider
+{
+    ExpressionFactory createExpressionFactory();
+
+    SimpleELContext createELContext(ELResolver elResolver);
+
+    ELResolver createELResolver();
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/SimpleELContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/SimpleELContext.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/SimpleELContext.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/message/impl/spi/SimpleELContext.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.impl.spi;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+
+/**
+ * @author Gerhard Petracek
+ */
+public abstract class SimpleELContext extends ELContext
+{
+    public abstract ValueExpression setVariable(String variable, ValueExpression valueExpression);
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/LICENSE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/LICENSE.txt?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/LICENSE.txt (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/LICENSE.txt Sat Apr 17 14:53:40 2010
@@ -0,0 +1,174 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/NOTICE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/NOTICE.txt?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/NOTICE.txt (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/main/resources/NOTICE.txt Sat Apr 17 14:53:40 2010
@@ -0,0 +1,9 @@
+Apache MyFaces Extensions CDI (aka MyFaces CODI)
+Copyright 2010 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+------------------------------------------------------------------------
+See the file LICENSE.txt
+------------------------------------------------------------------------
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AbstractTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AbstractTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AbstractTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AbstractTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+import org.apache.myfaces.extensions.cdi.message.impl.DefaultMessageContext;
+import org.junit.Before;
+
+/**
+ * @author Gerhard Petracek
+ */
+public abstract class AbstractTest
+{
+    protected MessageContext messageContext;
+
+    @Before
+    public void setupFactory()
+    {
+        this.messageContext = new DefaultMessageContext().config().use()
+                .messageResolver(new TestMessageResolver())
+                .create();
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AllTests.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AllTests.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AllTests.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/AllTests.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import junit.framework.TestCase;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Gerhard Petracek
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+        SimpleMessageTest.class,
+        MessageSeverityTest.class,
+        ParametrizedMessageInterpolationTest.class,
+        FormattedMessageArgumentTest.class,
+        PayloadTest.class,
+        ExtensibilityTest.class,
+        MessageFilterTest.class,
+        HelperTest.class})
+public class AllTests extends TestCase
+{
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ExtensibilityTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ExtensibilityTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ExtensibilityTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ExtensibilityTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.LocaleResolver;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+import java.util.Locale;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ExtensibilityTest extends AbstractTest
+{
+    @Test
+    public void messageHandlerTest()
+    {
+        this.messageContext.config()
+                .change().addMessageHandler(new TestInMemoryMessageHandler())
+                .create().message().text("{hello}").add();
+
+        assertEquals(1, this.messageContext.getMessages().size());
+        assertEquals(this.messageContext.message().text("{hello}").create(),
+                this.messageContext.getMessages().iterator().next());
+    }
+
+    @Test
+    public void newContextTest()
+    {
+        MessageContext newMessageContext = this.messageContext.cloneContext();
+
+        this.messageContext.config().change().localeResolver(createLocalResolver1());
+        newMessageContext.config().change().localeResolver(createLocalResolver2());
+
+        if (newMessageContext.equals(this.messageContext))
+        {
+            fail("different context expected - old context: " + this.messageContext.toString() + " new context: " + newMessageContext.toString());
+        }
+
+        assertEquals(Locale.GERMAN, this.messageContext.config().getLocaleResolver().getLocale());
+        assertEquals(Locale.ENGLISH, newMessageContext.config().getLocaleResolver().getLocale());
+    }
+
+    private LocaleResolver createLocalResolver1()
+    {
+        return new LocaleResolver()
+        {
+            Locale locale = Locale.GERMAN;
+
+            public Locale getLocale()
+            {
+                return locale;
+            }
+        };
+    }
+
+    private LocaleResolver createLocalResolver2()
+    {
+        return new LocaleResolver()
+        {
+            Locale locale = Locale.ENGLISH;
+
+            public Locale getLocale()
+            {
+                return locale;
+            }
+        };
+    }
+
+    @Test
+    public void usedMessageResolverTest()
+    {
+        MessageContext newMessageContext = this.messageContext.config().use().localeResolver(createGermanLocaleResolver()).create();
+
+        if (newMessageContext.equals(this.messageContext))
+        {
+            fail("different context expected - old context: " + this.messageContext.toString() + " new context: " + newMessageContext.toString());
+        }
+    }
+
+    @Test
+    public void changedMessageResolverTest()
+    {
+        MessageContext messageContext = this.messageContext.config().change().localeResolver(createGermanLocaleResolver()).create();
+
+        assertEquals(this.messageContext, messageContext);
+    }
+
+    @Test
+    public void cloneMessageContextTest()
+    {
+        MessageContext messageContext = this.messageContext.cloneContext();
+        messageContext.message().text("{hello}").create();
+
+        this.messageContext.config().change().addMessageHandler(new TestInMemoryMessageHandler());
+
+        assertFalse(messageContext.config().getMessageHandler().equals(this.messageContext.config().getMessageHandler()));
+    }
+
+    @Test
+    public void customMessageContextTest()
+    {
+        MessageContext messageContext = new TestCustomMessageContext();
+
+        assertTrue(messageContext.typed(TestCustomMessageContext.class).isReachable());
+    }
+
+    private LocaleResolver createGermanLocaleResolver()
+    {
+        return new LocaleResolver()
+        {
+            public Locale getLocale()
+            {
+                return Locale.GERMAN;
+            }
+        };
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/FormattedMessageArgumentTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/FormattedMessageArgumentTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/FormattedMessageArgumentTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/FormattedMessageArgumentTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.GenericConfig;
+import org.apache.myfaces.extensions.cdi.message.api.LocaleResolver;
+import org.apache.myfaces.extensions.cdi.message.impl.NumberedArgumentAwareMessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.impl.formatter.NumberFormatterConfigKeys;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class FormattedMessageArgumentTest extends AbstractTest
+{
+    @Test
+    public void createFormattedMessageGermanTest()
+    {
+        String messageText = this.messageContext.config().use().messageInterpolator(new NumberedArgumentAwareMessageInterpolator())
+                .localeResolver(getGermanLocaleResolver())
+                .addFormatterConfig(Number.class, getGermanNumberConfig()).create()
+                .message().text("{formatted_number}").argument(new BigDecimal("7654.3210")).toText();
+
+        assertEquals("value: 7.654,321", messageText);
+    }
+
+    @Test
+    public void createFormattedMessageEnglishTest()
+    {
+        String messageText = this.messageContext.config().use().messageInterpolator(new NumberedArgumentAwareMessageInterpolator())
+                .localeResolver(getEnglishLocaleResolver())
+                .addFormatterConfig(Number.class, getGermanNumberConfig(), Locale.GERMAN)
+                .addFormatterConfig(Number.class, getEnglishNumberConfig(), Locale.ENGLISH)
+                .create()
+                .message().text("{formatted_number}").argument(new BigDecimal("7654.3210")).toText();
+
+        assertEquals("value: 7,654.321", messageText);
+    }
+
+    private LocaleResolver getGermanLocaleResolver()
+    {
+        return new LocaleResolver()
+        {
+            public Locale getLocale()
+            {
+                return Locale.GERMAN;
+            }
+        };
+    }
+
+    private GenericConfig getGermanNumberConfig()
+    {
+        return new GenericConfig()
+        {
+            private Map<String, Serializable> properties = new HashMap<String, Serializable>();
+            private static final long serialVersionUID = 1581606533032801390L;
+
+            {
+                this.properties.put(NumberFormatterConfigKeys.GROUPING_SEPARATOR_KEY, ".");
+                this.properties.put(NumberFormatterConfigKeys.DECIMAL_SEPARATOR_KEY, ",");
+                this.properties.put(NumberFormatterConfigKeys.MINIMUM_FRACTION_DIGITS_KEY, 2);
+                this.properties.put(NumberFormatterConfigKeys.MINIMUM_INTEGER_DIGITS_KEY, 1);
+            }
+
+            public GenericConfig addProperty(String key, Serializable value)
+            {
+                this.properties.put(key, value);
+                return this;
+            }
+
+            public Serializable getProperty(String key)
+            {
+                return this.properties.get(key);
+            }
+
+            public <T extends Serializable> T getProperty(String key, Class<T> targetType)
+            {
+                //noinspection unchecked
+                return (T) getProperty(key);
+            }
+
+            public boolean containsProperty(String key)
+            {
+                return this.properties.containsKey(key);
+            }
+        };
+    }
+
+    private LocaleResolver getEnglishLocaleResolver()
+    {
+        return new LocaleResolver()
+        {
+            public Locale getLocale()
+            {
+                return Locale.ENGLISH;
+            }
+        };
+    }
+
+    private GenericConfig getEnglishNumberConfig()
+    {
+        return new GenericConfig()
+        {
+            private Map<String, Serializable> properties = new HashMap<String, Serializable>();
+            private static final long serialVersionUID = 547837293567706390L;
+
+            {
+                this.properties.put(NumberFormatterConfigKeys.GROUPING_SEPARATOR_KEY, ",");
+                this.properties.put(NumberFormatterConfigKeys.DECIMAL_SEPARATOR_KEY, ".");
+                this.properties.put(NumberFormatterConfigKeys.MINIMUM_FRACTION_DIGITS_KEY, 2);
+                this.properties.put(NumberFormatterConfigKeys.MINIMUM_INTEGER_DIGITS_KEY, 1);
+            }
+
+            public GenericConfig addProperty(String key, Serializable value)
+            {
+                this.properties.put(key, value);
+                return this;
+            }
+
+            public Serializable getProperty(String key)
+            {
+                return this.properties.get(key);
+            }
+
+            public <T extends Serializable> T getProperty(String key, Class<T> targetType)
+            {
+                //noinspection unchecked
+                return (T) getProperty(key);
+            }
+
+            public boolean containsProperty(String key)
+            {
+                return this.properties.containsKey(key);
+            }
+        };
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/HelperTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/HelperTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/HelperTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/HelperTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.impl.DefaultMessage;
+import org.apache.myfaces.extensions.cdi.message.impl.ELAwareMessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.impl.NamedArguments;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class HelperTest extends AbstractTest
+{
+    @Test
+    public void namedArgumentBuilderTest()
+    {
+        this.messageContext.config().change().messageInterpolator(new ELAwareMessageInterpolator(new TestELProvider()));
+
+        Number arg1 = new BigDecimal("123.4567");
+        Date arg2 = new Date();
+        String text = "#1: {arg1} and #2: {arg2}";
+        Message message1 = this.messageContext.message().text(text)
+                .namedArgument("arg1", arg1).namedArgument("arg2", arg2).create();
+
+        Message message2 = new DefaultMessage(text, NamedArguments.add("arg1", arg1).add("arg2", arg2).create());
+
+        assertEquals(message1, message2);
+        assertEquals(message1.toString(), message2.toString());
+        assertEquals(message1.toString(this.messageContext), message2.toString(this.messageContext));
+    }
+
+    @Test
+    public void convertNamedArgumentTest()
+    {
+        this.messageContext.config().change().messageInterpolator(new ELAwareMessageInterpolator(new TestELProvider()));
+
+        Number arg1 = new BigDecimal("123.4567");
+        Date arg2 = new Date();
+        String text = "#1: {arg1} and #2: {arg2}";
+        Message message1 = this.messageContext.message().text(text)
+                .namedArgument("arg1", arg1).namedArgument("arg2", arg2).create();
+
+        Map<String, Serializable> arguments = new HashMap<String, Serializable>();
+        arguments.put("arg1", arg1);
+        arguments.put("arg2", arg2);
+        Message message2 = new DefaultMessage(text, NamedArguments.convert(arguments));
+
+        assertEquals(message1, message2);
+        assertEquals(message1.toString(), message2.toString());
+        assertEquals(message1.toString(this.messageContext), message2.toString(this.messageContext));
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageFilterTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageFilterTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageFilterTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageFilterTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.api.MessageContext;
+import org.apache.myfaces.extensions.cdi.message.api.MessageFilter;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class MessageFilterTest extends AbstractTest
+{
+    @Test
+    public void messageFilterTest()
+    {
+        this.messageContext.config().change().addMessageHandler(new TestInMemoryMessageHandler()).create()
+                .message().text("hello open message").add();
+
+        assertEquals(1, this.messageContext.config().getMessageHandler().getMessages().size());
+
+        this.messageContext.removeAllMessages();
+
+        assertEquals(0, this.messageContext.config().getMessageHandler().getMessages().size());
+
+        //TODO
+        this.messageContext.config().getMessageHandler().addMessageFilter(createBlockingMessageFilter());
+        this.messageContext.message().text("hello open message").add();
+
+        assertEquals(0, this.messageContext.config().getMessageHandler().getMessages().size());
+    }
+
+    private MessageFilter createBlockingMessageFilter()
+    {
+        return new MessageFilter()
+        {
+            public boolean processMessage(MessageContext messageContext, Message message)
+            {
+                return false;
+            }
+        };
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageSeverityTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageSeverityTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageSeverityTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/MessageSeverityTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.api.MessageWithSeverity;
+import org.apache.myfaces.extensions.cdi.message.api.payload.MessageSeverity;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class MessageSeverityTest extends AbstractTest
+{
+    @Test
+    public void createMessageWithDefaultSeverityTest()
+    {
+        Message message = this.messageContext.message().text("hello open message").create();
+
+        assertNotNull(message);
+        assertTrue(message.getPayload().containsKey(MessageSeverity.class));
+        assertTrue(message.getPayload().containsValue(MessageSeverity.Info.class));
+
+        assertTrue(message instanceof MessageWithSeverity);
+        assertEquals(MessageSeverity.Info.class, ((MessageWithSeverity) message).getSeverity());
+    }
+
+    @Test
+    public void createMessageWithSeverityWarnTest()
+    {
+        Message message = this.messageContext.message().text("hello open message").payload(MessageSeverity.Warn.class).create();
+
+        assertNotNull(message);
+        assertTrue(message.getPayload().containsKey(MessageSeverity.class));
+        assertTrue(message.getPayload().containsValue(MessageSeverity.Warn.class));
+
+        assertTrue(message instanceof MessageWithSeverity);
+        assertEquals(MessageSeverity.Warn.class, ((MessageWithSeverity) message).getSeverity());
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ParametrizedMessageInterpolationTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ParametrizedMessageInterpolationTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ParametrizedMessageInterpolationTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/ParametrizedMessageInterpolationTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.MessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.impl.CompositeMessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.impl.ELAwareMessageInterpolator;
+import org.apache.myfaces.extensions.cdi.message.impl.NumberedArgumentAwareMessageInterpolator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
+import java.io.Serializable;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ParametrizedMessageInterpolationTest extends AbstractTest
+{
+    @Test
+    public void createElAwareMessageTest()
+    {
+        String messageText = this.messageContext.config().change().messageInterpolator(createELAwareInterpolator()).create()
+                .message().text("hello {person.name}").namedArgument("person", new TestPerson()).toText();
+
+        assertEquals("hello Thomas", messageText);
+    }
+
+    @Test
+    public void createNumberedArgumentAwareMessageTest()
+    {
+        MessageInterpolator messageInterpolator = new CompositeMessageInterpolator(createELAwareInterpolator(), new NumberedArgumentAwareMessageInterpolator());
+        String messageText = this.messageContext.config().change().messageInterpolator(messageInterpolator).create()
+                .message().text("\\{0} greets {1}")
+                .argument("Gerhard", "Manfred").argument(new TestPerson()).toText();
+
+        assertEquals("Gerhard greets Manfred", messageText);
+    }
+
+    @Test
+    public void createNamedArgumentAwareMessageTest()
+    {
+        String messageText = this.messageContext.config().change().messageInterpolator(createELAwareInterpolator()).create()
+                .message().text("\\{p1} and {p2} greet {p3.name}")
+                .namedArgument("p2", "Gerhard").namedArgument("p1", "Manfred").namedArgument("p3", new TestPerson())
+                .toText();
+
+        assertEquals("Manfred and Gerhard greet Thomas", messageText);
+    }
+
+    @Test
+    public void overrideNamedArgumentTest()
+    {
+        try
+        {
+            this.messageContext.config().change().messageInterpolator(createELAwareInterpolator()).create()
+                    .message().text("\\{p1} and {p2} greet {p3.name}")
+                    .namedArgument("p2", "Gerhard").namedArgument("p2", "Manfred").namedArgument("p3", new TestPerson())
+                    .toText();
+        }
+        catch (UnsupportedOperationException e)
+        {
+            return;
+        }
+
+        fail();
+    }
+
+    private ELAwareMessageInterpolator createELAwareInterpolator()
+    {
+        return new ELAwareMessageInterpolator(new TestELProvider());
+    }
+
+    @Test
+    public void createMixedArgumentAwareMessageTest()
+    {
+        MessageInterpolator messageInterpolator = new CompositeMessageInterpolator(createELAwareInterpolator(), new NumberedArgumentAwareMessageInterpolator());
+        String messageText = this.messageContext.config().change().messageInterpolator(messageInterpolator).create()
+                .message().text("[hello] {0} and {firstName} ({1} and {lastName}) greet {person.name}")
+                .argument("Gerhard", "Petracek")
+                .namedArgument("person", new TestPerson())
+                .namedArgument("lastName", "Geiler").namedArgument("firstName", "Manfred").toText();
+
+        assertEquals("[hello] Gerhard and Manfred (Petracek and Geiler) greet Thomas", messageText);
+    }
+
+    private class TestPerson implements Serializable
+    {
+        private static final long serialVersionUID = 1505396194005924707L;
+
+        public String getName()
+        {
+            return "Thomas";
+        }
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/PayloadTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/PayloadTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/PayloadTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/PayloadTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.api.payload.InternalMessage;
+import org.apache.myfaces.extensions.cdi.message.impl.DefaultInternalMessage;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class PayloadTest extends AbstractTest
+{
+    @Test
+    public void internalMessageAwareMessageHandlerTest()
+    {
+        this.messageContext.config().change().addMessageHandler(new TestInternalMessageAwareMessageHandler());
+
+        this.messageContext.message().text("test msg 1").add();
+        this.messageContext.message().text("test msg 2").payload(InternalMessage.class).add();
+
+        assertEquals(1, this.messageContext.getMessages().size());
+        assertEquals(this.messageContext.message().text("test msg 1").create(),
+                this.messageContext.getMessages().iterator().next());
+    }
+
+    @Test
+    public void manuallyCreatedInternalMessageTest()
+    {
+        this.messageContext.config().change().addMessageHandler(new TestInternalMessageAwareMessageHandler());
+
+        this.messageContext.message().text("test msg 1").add();
+
+        Message internalMessage = new DefaultInternalMessage("test msg 2").setMessageContextConfig(this.messageContext.config());
+        this.messageContext.addMessage(internalMessage);
+
+        assertEquals(1, this.messageContext.getMessages().size());
+        assertEquals(this.messageContext.message().text("test msg 1").create(),
+                this.messageContext.getMessages().iterator().next());
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/SimpleMessageTest.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.api.LocaleResolver;
+import org.apache.myfaces.extensions.cdi.message.api.Message;
+import org.apache.myfaces.extensions.cdi.message.impl.DefaultMessage;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import java.util.Locale;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class SimpleMessageTest extends AbstractTest
+{
+    @Test
+    public void resolveInlineMessageTest()
+    {
+        Message message = this.messageContext.message().text("hello open message").create();
+
+        assertEquals("hello open message", message.toString(this.messageContext));
+    }
+
+    @Test
+    public void resolveMessageTest()
+    {
+        Message message = this.messageContext.message().text("{hello}").create();
+
+        checkDefaultHelloMessage(message.toString(this.messageContext));
+    }
+
+    @Test
+    public void resolveMessageTextTest()
+    {
+        Message message = this.messageContext.message().text("{hello}").create();
+
+        String messageText = this.messageContext.message().toText(message); //TODO use a different config
+
+        checkDefaultHelloMessage(messageText);
+    }
+
+    @Test
+    public void resolveGermanMessageTextTest()
+    {
+        String messageText = this.messageContext.config()
+                .use().localeResolver(createGermanLocaleResolver())
+                .create().message().text("{hello}").toText();
+
+        checkGermanHelloMessage(messageText);
+    }
+
+    @Test
+    public void directMessage2TextResolvingTest()
+    {
+        Message message = new DefaultMessage("inline message");
+
+        assertEquals("inline message", message.toString());
+    }
+
+    @Test
+    public void manuallyCreateInlineMessageTest()
+    {
+        Message message = new DefaultMessage("inline message");
+
+        assertEquals("inline message", message.toString(this.messageContext));
+    }
+
+    @Test
+    public void manuallyCreateMessageWithConfigTest()
+    {
+        Message message = manuallyCreateDefaultMessage();
+        checkDefaultHelloMessage(message.toString());
+    }
+
+    private Message manuallyCreateDefaultMessage()
+    {
+        return new DefaultMessage("{hello}").setMessageContextConfig(this.messageContext.config());
+    }
+
+    @Test
+    public void createInvalidMessageTest()
+    {
+        String messageText = this.messageContext.message().text("{xyz123}").toText();
+
+        assertEquals("???xyz123???", messageText);
+    }
+
+    @Test
+    public void resolveTextTest()
+    {
+        String messageText = this.messageContext.message().text("{hello}").toText();
+
+        checkDefaultHelloMessage(messageText);
+    }
+
+    @Test
+    public void directTextResolvingTest()
+    {
+        Message message = this.messageContext.message().text("{hello}").create();
+        String messageText = this.messageContext.getMessageText(message);
+
+        checkDefaultHelloMessage(messageText);
+    }
+
+    private LocaleResolver createGermanLocaleResolver()
+    {
+        return new LocaleResolver()
+        {
+            public Locale getLocale()
+            {
+                return Locale.GERMAN;
+            }
+        };
+    }
+
+    private void checkDefaultHelloMessage(String messageText)
+    {
+        assertEquals("test message", messageText);
+    }
+
+    private void checkGermanHelloMessage(String messageText)
+    {
+        assertEquals("Test Nachricht", messageText);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestCustomMessageContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestCustomMessageContext.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestCustomMessageContext.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestCustomMessageContext.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import org.apache.myfaces.extensions.cdi.message.impl.DefaultMessageContext;
+
+/**
+ * @author Gerhard Petracek
+ */
+class TestCustomMessageContext extends DefaultMessageContext
+{
+    private static final long serialVersionUID = -7766499957864546190L;
+
+    public boolean isReachable()
+    {
+        return true;
+    }
+}

Added: myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestELContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestELContext.java?rev=935183&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestELContext.java (added)
+++ myfaces/extensions/cdi/trunk/jse-modules/message-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/message/test/TestELContext.java Sat Apr 17 14:53:40 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.extensions.cdi.message.test;
+
+import de.odysseus.el.util.SimpleContext;
+import org.apache.myfaces.extensions.cdi.message.impl.spi.SimpleELContext;
+
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+
+/**
+ * @author Manfred Geiler
+ */
+class TestELContext extends SimpleELContext
+{
+    private SimpleContext simpleContext;
+
+    public TestELContext(ELResolver elResolver)
+    {
+        this.simpleContext = new SimpleContext(elResolver);
+    }
+
+    /*
+     * generated
+     */
+    public ValueExpression setVariable(String s, ValueExpression valueExpression)
+    {
+        return simpleContext.setVariable(s, valueExpression);
+    }
+
+    public FunctionMapper getFunctionMapper()
+    {
+        return simpleContext.getFunctionMapper();
+    }
+
+    public VariableMapper getVariableMapper()
+    {
+        return simpleContext.getVariableMapper();
+    }
+
+    public ELResolver getELResolver()
+    {
+        return simpleContext.getELResolver();
+    }
+}



Mime
View raw message