You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/05/02 03:29:02 UTC
svn commit: r940131 - in
/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces: component/
convert/ validator/
Author: lu4242
Date: Sun May 2 01:29:02 2010
New Revision: 940131
URL: http://svn.apache.org/viewvc?rev=940131&view=rev
Log:
MYFACES-2691 Enhance MessageUtils adding methods when custom library bundle should be scanned
Added:
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
Modified:
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_MessageUtils.java
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
Modified: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_MessageUtils.java?rev=940131&r1=940130&r2=940131&view=diff
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_MessageUtils.java (original)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_MessageUtils.java Sun May 2 01:29:02 2010
@@ -18,15 +18,14 @@
*/
package javax.faces.component;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
import java.lang.reflect.Method;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
/**
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
@@ -158,25 +157,14 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new FacesMessage(severity, summary, detail);
}
-
private static String getBundleString(ResourceBundle bundle, String key)
{
try
Added: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java?rev=940131&view=auto
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java Sun May 2 01:29:02 2010
@@ -0,0 +1,118 @@
+/*
+ * 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 javax.faces.component;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}
Modified: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_MessageUtils.java?rev=940131&r1=940130&r2=940131&view=diff
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_MessageUtils.java (original)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_MessageUtils.java Sun May 2 01:29:02 2010
@@ -18,13 +18,13 @@
*/
package javax.faces.convert;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
/**
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
@@ -87,7 +87,8 @@ class _MessageUtils
else
{
//Neither detail nor summary found
- return null;
+ facesContext.getExternalContext().log("No message with id " + messageId + " found in any bundle");
+ return new FacesMessage(severity, messageId, null);
}
}
}
@@ -95,22 +96,12 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new FacesMessage(severity, summary, detail);
}
Added: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java?rev=940131&view=auto
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java Sun May 2 01:29:02 2010
@@ -0,0 +1,118 @@
+/*
+ * 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 javax.faces.convert;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}
Modified: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_MessageUtils.java?rev=940131&r1=940130&r2=940131&view=diff
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_MessageUtils.java (original)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_MessageUtils.java Sun May 2 01:29:02 2010
@@ -18,13 +18,13 @@
*/
package javax.faces.validator;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
/**
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
@@ -96,22 +96,12 @@ class _MessageUtils
if (args != null && args.length > 0)
{
- MessageFormat format;
-
- if (summary != null)
- {
- format = new MessageFormat(summary, locale);
- summary = format.format(args);
- }
-
- if (detail != null)
- {
- format = new MessageFormat(detail, locale);
- detail = format.format(args);
- }
+ return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
+ }
+ else
+ {
+ return new FacesMessage(severity, summary, detail);
}
-
- return new FacesMessage(severity, summary, detail);
}
Added: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java?rev=940131&view=auto
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java (added)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java Sun May 2 01:29:02 2010
@@ -0,0 +1,118 @@
+/*
+ * 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 javax.faces.validator;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+class _ParametrizableFacesMessage extends FacesMessage
+{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7792947730961657948L;
+
+ private final Object _args[];
+ private String _evaluatedDetail;
+ private String _evaluatedSummary;
+ private transient Object _evaluatedArgs[];
+ private Locale _locale;
+
+ public _ParametrizableFacesMessage(
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity,
+ String summary, String detail, Object[] args, Locale locale)
+ {
+ super(severity, summary, detail);
+ if(locale == null) throw new NullPointerException("locale");
+ _locale = locale;
+ _args = args;
+ }
+
+ public String getDetail()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedDetail == null)
+ {
+ MessageFormat format = new MessageFormat(super.getDetail(), _locale);
+ _evaluatedDetail = format.format(_evaluatedArgs);
+ }
+ return _evaluatedDetail;
+ }
+
+ public String getSummary()
+ {
+ if (_evaluatedArgs == null && _args != null)
+ {
+ evaluateArgs();
+ }
+ if (_evaluatedSummary == null)
+ {
+ MessageFormat format = new MessageFormat(super.getSummary(), _locale);
+ _evaluatedSummary = format.format(_evaluatedArgs);
+ }
+ return _evaluatedSummary;
+ }
+
+ private void evaluateArgs()
+ {
+ _evaluatedArgs = new Object[_args.length];
+ FacesContext facesContext = null;
+ for (int i = 0; i < _args.length; i++)
+ {
+ if (_args[i] == null)
+ {
+ continue;
+ }
+ else if (_args[i] instanceof ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ else
+ {
+ _evaluatedArgs[i] = _args[i];
+ }
+ }
+ }
+}