introduce a shared package and removed many duplicate code
diff --git a/api/src/main/java/javax/faces/component/UIComponent.java b/api/src/main/java/javax/faces/component/UIComponent.java
index d6d685f..2fd8426 100755
--- a/api/src/main/java/javax/faces/component/UIComponent.java
+++ b/api/src/main/java/javax/faces/component/UIComponent.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ClassUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
diff --git a/api/src/main/java/javax/faces/component/UIComponentBase.java b/api/src/main/java/javax/faces/component/UIComponentBase.java
index f02c74b..433de7b 100755
--- a/api/src/main/java/javax/faces/component/UIComponentBase.java
+++ b/api/src/main/java/javax/faces/component/UIComponentBase.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
diff --git a/api/src/main/java/javax/faces/component/UIData.java b/api/src/main/java/javax/faces/component/UIData.java
index 16cf882..4fb529c 100644
--- a/api/src/main/java/javax/faces/component/UIData.java
+++ b/api/src/main/java/javax/faces/component/UIData.java
@@ -18,6 +18,8 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ClassUtils;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
diff --git a/api/src/main/java/javax/faces/component/UIForm.java b/api/src/main/java/javax/faces/component/UIForm.java
index 09ed456..1e10c64 100755
--- a/api/src/main/java/javax/faces/component/UIForm.java
+++ b/api/src/main/java/javax/faces/component/UIForm.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
diff --git a/api/src/main/java/javax/faces/component/UIInput.java b/api/src/main/java/javax/faces/component/UIInput.java
index ebb2447..19b6743 100644
--- a/api/src/main/java/javax/faces/component/UIInput.java
+++ b/api/src/main/java/javax/faces/component/UIInput.java
@@ -18,6 +18,8 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SharedRendererUtils;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFListener;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
@@ -50,6 +52,9 @@
import java.util.List;
import java.util.Map;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFExclude;
+import org.apache.myfaces.core.api.shared._BeanValidationUtils;
+import org.apache.myfaces.core.api.shared._ExternalSpecifications;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* UICommand is a base abstraction for components that implement ActionSource.
diff --git a/api/src/main/java/javax/faces/component/UISelectMany.java b/api/src/main/java/javax/faces/component/UISelectMany.java
index 042ceef..89525f5 100644
--- a/api/src/main/java/javax/faces/component/UISelectMany.java
+++ b/api/src/main/java/javax/faces/component/UISelectMany.java
@@ -18,6 +18,9 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SharedRendererUtils;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,6 +40,8 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperties;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
+import org.apache.myfaces.core.api.shared._ExternalSpecifications;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* Base class for the various component classes that allow a user to select zero or more options from a set.
diff --git a/api/src/main/java/javax/faces/component/UISelectOne.java b/api/src/main/java/javax/faces/component/UISelectOne.java
index 9a6f638..c5e90f0 100644
--- a/api/src/main/java/javax/faces/component/UISelectOne.java
+++ b/api/src/main/java/javax/faces/component/UISelectOne.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -30,6 +31,7 @@
import javax.faces.model.SelectItem;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* Component for choosing one option out of a set of possibilities.
diff --git a/api/src/main/java/javax/faces/component/UIViewParameter.java b/api/src/main/java/javax/faces/component/UIViewParameter.java
index a3cc8da..a6b2f85 100644
--- a/api/src/main/java/javax/faces/component/UIViewParameter.java
+++ b/api/src/main/java/javax/faces/component/UIViewParameter.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ClassUtils;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
@@ -36,6 +37,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
*
@@ -196,9 +198,9 @@
}
else
{
- Object label = _MessageUtils.getLabel (context, this);
+ Object label = _MessageUtils.getLabel(context, this);
- message = _MessageUtils.getMessage (context, context.getViewRoot().getLocale(),
+ message = _MessageUtils.getMessage(context, context.getViewRoot().getLocale(),
FacesMessage.SEVERITY_ERROR, REQUIRED_MESSAGE_ID, new Object[] { label });
}
diff --git a/api/src/main/java/javax/faces/component/UIViewRoot.java b/api/src/main/java/javax/faces/component/UIViewRoot.java
index 17d91a6..4120b9b 100644
--- a/api/src/main/java/javax/faces/component/UIViewRoot.java
+++ b/api/src/main/java/javax/faces/component/UIViewRoot.java
@@ -18,6 +18,9 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ClassUtils;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
+import org.apache.myfaces.core.api.shared._LocaleUtils;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
diff --git a/api/src/main/java/javax/faces/component/_BeanValidationUtils.java b/api/src/main/java/javax/faces/component/_BeanValidationUtils.java
deleted file mode 100644
index 86f06e7..0000000
--- a/api/src/main/java/javax/faces/component/_BeanValidationUtils.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 javax.faces.validator.BeanValidator;
-import javax.faces.validator.Validator;
-
-/**
- *
- * @author lu4242
- */
-final class _BeanValidationUtils
-{
-
- public static boolean isBeanValidator(Validator v)
- {
- return v instanceof BeanValidator;
- }
-}
diff --git a/api/src/main/java/javax/faces/component/_ComponentFacetMap.java b/api/src/main/java/javax/faces/component/_ComponentFacetMap.java
index 71992c1..de2e189 100755
--- a/api/src/main/java/javax/faces/component/_ComponentFacetMap.java
+++ b/api/src/main/java/javax/faces/component/_ComponentFacetMap.java
@@ -30,7 +30,7 @@
{
private static final long serialVersionUID = -3456937594422167629L;
private UIComponent _component;
- private Map<String, V> _map = new _ArrayMap<String, V>(0,5);
+ private Map<String, V> _map = new _ArrayMap<>(0,5);
private Set<Entry<String, V>> _entrySet = null;
private Set<String> _keySet = null;
private Collection<V> _valueCollection = null;
diff --git a/api/src/main/java/javax/faces/component/_ExternalSpecifications.java b/api/src/main/java/javax/faces/component/_ExternalSpecifications.java
deleted file mode 100644
index a33abfa..0000000
--- a/api/src/main/java/javax/faces/component/_ExternalSpecifications.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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;
-
-/**
- * <p>
- * Package-private utility class for determining which specifications are available
- * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386
- * This is a stripped down version of: org.apache.myfaces.util.ExternalSpecifications
- * </p>
- * @since 2.0
- */
-final class _ExternalSpecifications
-{
- private static volatile Boolean beanValidationAvailable;
-
- /**
- * This method determines if Bean Validation is present.
- *
- * Eager initialization is used for performance. This means Bean Validation binaries
- * should not be added at runtime after this variable has been set.
- * @return true if Bean Validation is available, false otherwise.
- */
- public static boolean isBeanValidationAvailable()
- {
- if (beanValidationAvailable == null)
- {
- try
- {
- try
- {
- beanValidationAvailable = (Class.forName("javax.validation.Validation") != null);
- }
- catch (ClassNotFoundException e)
- {
- beanValidationAvailable = Boolean.FALSE;
- }
-
- if (beanValidationAvailable)
- {
- try
- {
- // Trial-error approach to check for Bean Validation impl existence.
- // If any Exception occurs here, we assume that Bean Validation is not available.
- // The cause may be anything, i.e. NoClassDef, config error...
- _ValidationUtils.tryBuildDefaultValidatorFactory();
- }
- catch (Throwable t)
- {
- beanValidationAvailable = false;
- }
- }
- }
- catch (Throwable t)
- {
- beanValidationAvailable = false;
- }
- }
- return beanValidationAvailable;
- }
-
- /**
- * this class should not be instantiated.
- */
- private _ExternalSpecifications()
- {
- }
-}
\ No newline at end of file
diff --git a/api/src/main/java/javax/faces/component/_LocaleUtils.java b/api/src/main/java/javax/faces/component/_LocaleUtils.java
deleted file mode 100644
index e95b9b7..0000000
--- a/api/src/main/java/javax/faces/component/_LocaleUtils.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * 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.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * <p>Operations to assist when working with a {@link Locale}.</p>
- *
- * <p>This class tries to handle {@code null} input gracefully.
- * An exception will not be thrown for a {@code null} input.
- * Each method documents its behaviour in more detail.</p>
- *
- * NOTE: This a copy of commons lang LocaleUtils, to use it inside MyFaces
- *
- * @since 2.2
- * @version $Id$
- */
-class _LocaleUtils
-{
-
- /** Concurrent map of language locales by country. */
- private static final ConcurrentMap<String, List<Locale>> LANGUAGES_BY_COUNTRY =
- new ConcurrentHashMap<String, List<Locale>>();
-
- /** Concurrent map of country locales by language. */
- private static final ConcurrentMap<String, List<Locale>> COUNTRIES_BY_LANGUAGE =
- new ConcurrentHashMap<String, List<Locale>>();
-
- /**
- * <p>{@code _LocaleUtils} instances should NOT be constructed in standard programming.
- * Instead, the class should be used as {@code _LocaleUtils.toLocale("en_GB");}.</p>
- *
- * <p>This constructor is public to permit tools that require a JavaBean instance
- * to operate.</p>
- */
- public _LocaleUtils()
- {
- super();
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Converts a String to a Locale.</p>
- *
- * <p>This method takes the string format of a locale and creates the
- * locale object from it.</p>
- *
- * <pre>
- * _LocaleUtils.toLocale("en") = new Locale("en", "")
- * _LocaleUtils.toLocale("en_GB") = new Locale("en", "GB")
- * _LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx") (#)
- * </pre>
- *
- * <p>(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4.
- * In JDK1.3, the constructor upper cases the variant, in JDK1.4, it doesn't.
- * Thus, the result from getVariant() may vary depending on your JDK.</p>
- *
- * <p>This method validates the input strictly.
- * The language code must be lowercase.
- * The country code must be uppercase.
- * The separator must be an underscore.
- * The length must be correct.
- * </p>
- *
- * @param str the locale String to convert, null returns null
- * @return a Locale, null if null input
- * @throws IllegalArgumentException if the string is an invalid format
- */
- public static Locale toLocale(String str)
- {
- if (str == null)
- {
- return null;
- }
- int len = str.length();
- if (len != 2 && len != 5 && len < 7)
- {
- throw new IllegalArgumentException("Invalid locale format: " + str);
- }
- char ch0 = str.charAt(0);
- char ch1 = str.charAt(1);
- if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z')
- {
- throw new IllegalArgumentException("Invalid locale format: " + str);
- }
- if (len == 2)
- {
- return new Locale(str, "");
- }
- else
- {
- if (str.charAt(2) != '_')
- {
- throw new IllegalArgumentException("Invalid locale format: " + str);
- }
- char ch3 = str.charAt(3);
- if (ch3 == '_')
- {
- return new Locale(str.substring(0, 2), "", str.substring(4));
- }
- char ch4 = str.charAt(4);
- if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z')
- {
- throw new IllegalArgumentException("Invalid locale format: " + str);
- }
- if (len == 5)
- {
- return new Locale(str.substring(0, 2), str.substring(3, 5));
- }
- else
- {
- if (str.charAt(5) != '_')
- {
- throw new IllegalArgumentException("Invalid locale format: " + str);
- }
- return new Locale(str.substring(0, 2), str.substring(3, 5), str.substring(6));
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains the list of locales to search through when performing
- * a locale search.</p>
- *
- * <pre>
- * localeLookupList(Locale("fr","CA","xxx"))
- * = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr")]
- * </pre>
- *
- * @param locale the locale to start from
- * @return the unmodifiable list of Locale objects, 0 being locale, not null
- */
- public static List<Locale> localeLookupList(Locale locale)
- {
- return localeLookupList(locale, locale);
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains the list of locales to search through when performing
- * a locale search.</p>
- *
- * <pre>
- * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
- * = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"]
- * </pre>
- *
- * <p>The result list begins with the most specific locale, then the
- * next more general and so on, finishing with the default locale.
- * The list will never contain the same locale twice.</p>
- *
- * @param locale the locale to start from, null returns empty list
- * @param defaultLocale the default locale to use if no other is found
- * @return the unmodifiable list of Locale objects, 0 being locale, not null
- */
- public static List<Locale> localeLookupList(Locale locale, Locale defaultLocale)
- {
- List<Locale> list = new ArrayList<Locale>(4);
- if (locale != null)
- {
- list.add(locale);
- if (locale.getVariant().length() > 0)
- {
- list.add(new Locale(locale.getLanguage(), locale.getCountry()));
- }
- if (locale.getCountry().length() > 0)
- {
- list.add(new Locale(locale.getLanguage(), ""));
- }
- if (!list.contains(defaultLocale))
- {
- list.add(defaultLocale);
- }
- }
- return Collections.unmodifiableList(list);
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains an unmodifiable list of installed locales.</p>
- *
- * <p>This method is a wrapper around {@link Locale#getAvailableLocales()}.
- * It is more efficient, as the JDK method must create a new array each
- * time it is called.</p>
- *
- * @return the unmodifiable list of available locales
- */
- public static List<Locale> availableLocaleList()
- {
- return SyncAvoid.AVAILABLE_LOCALE_LIST;
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains an unmodifiable set of installed locales.</p>
- *
- * <p>This method is a wrapper around {@link Locale#getAvailableLocales()}.
- * It is more efficient, as the JDK method must create a new array each
- * time it is called.</p>
- *
- * @return the unmodifiable set of available locales
- */
- public static Set<Locale> availableLocaleSet()
- {
- return SyncAvoid.AVAILABLE_LOCALE_SET;
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Checks if the locale specified is in the list of available locales.</p>
- *
- * @param locale the Locale object to check if it is available
- * @return true if the locale is a known locale
- */
- public static boolean isAvailableLocale(Locale locale)
- {
- return availableLocaleList().contains(locale);
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains the list of languages supported for a given country.</p>
- *
- * <p>This method takes a country code and searches to find the
- * languages available for that country. Variant locales are removed.</p>
- *
- * @param countryCode the 2 letter country code, null returns empty
- * @return an unmodifiable List of Locale objects, not null
- */
- public static List<Locale> languagesByCountry(String countryCode)
- {
- if (countryCode == null)
- {
- return Collections.emptyList();
- }
- List<Locale> langs = LANGUAGES_BY_COUNTRY.get(countryCode);
- if (langs == null)
- {
- langs = new ArrayList<Locale>();
- List<Locale> locales = availableLocaleList();
- for (int i = 0; i < locales.size(); i++)
- {
- Locale locale = locales.get(i);
- if (countryCode.equals(locale.getCountry()) &&
- locale.getVariant().length() == 0)
- {
- langs.add(locale);
- }
- }
- langs = Collections.unmodifiableList(langs);
- LANGUAGES_BY_COUNTRY.putIfAbsent(countryCode, langs);
- langs = LANGUAGES_BY_COUNTRY.get(countryCode);
- }
- return langs;
- }
-
- //-----------------------------------------------------------------------
-
- /**
- * <p>Obtains the list of countries supported for a given language.</p>
- *
- * <p>This method takes a language code and searches to find the
- * countries available for that language. Variant locales are removed.</p>
- *
- * @param languageCode the 2 letter language code, null returns empty
- * @return an unmodifiable List of Locale objects, not null
- */
- public static List<Locale> countriesByLanguage(String languageCode)
- {
- if (languageCode == null)
- {
- return Collections.emptyList();
- }
- List<Locale> countries = COUNTRIES_BY_LANGUAGE.get(languageCode);
- if (countries == null)
- {
- countries = new ArrayList<Locale>();
- List<Locale> locales = availableLocaleList();
- for (int i = 0; i < locales.size(); i++)
- {
- Locale locale = locales.get(i);
- if (languageCode.equals(locale.getLanguage()) &&
- locale.getCountry().length() != 0 &&
- locale.getVariant().length() == 0)
- {
- countries.add(locale);
- }
- }
- countries = Collections.unmodifiableList(countries);
- COUNTRIES_BY_LANGUAGE.putIfAbsent(languageCode, countries);
- countries = COUNTRIES_BY_LANGUAGE.get(languageCode);
- }
- return countries;
- }
-
- //-----------------------------------------------------------------------
- // class to avoid synchronization
- static class SyncAvoid
- {
- /** Unmodifiable list of available locales. */
- private static final List<Locale> AVAILABLE_LOCALE_LIST;
- /** Unmodifiable set of available locales. */
- private static final Set<Locale> AVAILABLE_LOCALE_SET;
-
- static
- {
- List<Locale> list = new ArrayList<Locale>(Arrays.asList(Locale.getAvailableLocales())); // extra safe
- AVAILABLE_LOCALE_LIST = Collections.unmodifiableList(list);
- AVAILABLE_LOCALE_SET = Collections.unmodifiableSet(new HashSet<Locale>(availableLocaleList()));
- }
- }
-
-}
diff --git a/api/src/main/java/javax/faces/component/_MessageUtils.java b/api/src/main/java/javax/faces/component/_MessageUtils.java
deleted file mode 100755
index 558bcbf..0000000
--- a/api/src/main/java/javax/faces/component/_MessageUtils.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * 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 javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-class _MessageUtils
-{
- private static final String DETAIL_SUFFIX = "_detail";
-
- static void addErrorMessage(FacesContext facesContext,
- UIComponent component,
- String messageId)
- {
- facesContext.addMessage(component.getClientId(facesContext),
- getMessage(facesContext,
- facesContext.getViewRoot().getLocale(),
- FacesMessage.SEVERITY_ERROR,
- messageId,
- null));
- }
-
- static void addErrorMessage(FacesContext facesContext,
- UIComponent component,
- String messageId, Object[] args)
- {
- facesContext.addMessage(component.getClientId(facesContext),
- getMessage(facesContext,
- facesContext.getViewRoot().getLocale(),
- FacesMessage.SEVERITY_ERROR,
- messageId,
- args));
- }
-
- static void addErrorMessage(FacesContext facesContext,
- UIComponent component, Throwable cause)
- {
- facesContext.addMessage(component.getClientId(facesContext),
- new FacesMessage(FacesMessage.SEVERITY_ERROR, cause
- .getLocalizedMessage(), cause.getLocalizedMessage()));
- }
-
-
- static FacesMessage getMessage(FacesContext facesContext,
- Locale locale,
- FacesMessage.Severity severity,
- String messageId,
- Object args[])
- {
- ResourceBundle appBundle;
- ResourceBundle defBundle;
- String summary;
- String detail;
-
- appBundle = getApplicationBundle(facesContext, locale);
- summary = getBundleString(appBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- defBundle = getDefaultBundle(facesContext, locale);
- summary = getBundleString(defBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- //Try to find detail alone
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- //Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId
- + " found in any bundle");
- return new FacesMessage(severity, messageId, null);
- }
- }
- }
- }
-
- if (args != null && args.length > 0)
- {
- return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
- }
- else
- {
- return new FacesMessage(severity, summary, detail);
- }
- }
-
- private static String getBundleString(ResourceBundle bundle, String key)
- {
- try
- {
- if (bundle != null && bundle.containsKey(key))
- {
- return bundle.getString(key);
- }
- }
- catch (MissingResourceException e)
- {
- // NOOP
- }
-
- return null;
- }
-
-
- private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)
- {
- String bundleName = facesContext.getApplication().getMessageBundle();
- return bundleName != null ? getBundle(facesContext, locale, bundleName) : null;
- }
-
- private static ResourceBundle getDefaultBundle(FacesContext facesContext,
- Locale locale)
- {
- return getBundle(facesContext, locale, FacesMessage.FACES_MESSAGES);
- }
-
- private static ResourceBundle getBundle(FacesContext facesContext,
- Locale locale,
- String bundleName)
- {
- ResourceBundle.Control bundleControl = (ResourceBundle.Control) facesContext.getExternalContext()
- .getApplicationMap().get("org.apache.myfaces.RESOURCE_BUNDLE_CONTROL");
-
- try
- {
- //First we try the JSF implementation class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore1)
- {
- try
- {
- //Next we try the JSF API class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader());
- }
- else
- {
- //Next we try the JSF API class loader
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore2)
- {
- try
- {
- //Last resort is the context class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _ClassUtils.getContextClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _ClassUtils.getContextClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException damned)
- {
- facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");
- return null;
- }
- }
- }
- }
-
- static Object getLabel(FacesContext facesContext, UIComponent component)
- {
- Object label = component.getAttributes().get("label");
- ValueExpression expression = null;
- if (label != null &&
- label instanceof String && ((String)label).length() == 0 )
- {
- // Note component.getAttributes().get("label") internally try to
- // evaluate the EL expression for the label, but in some cases,
- // when PSS is disabled and f:loadBundle is used, when the view is
- // restored the bundle is not set to the EL expression returns an
- // empty String. It is not possible to check if there is a
- // hardcoded label, but we can check if there is
- // an EL expression set, so the best in this case is use that, and if
- // there is an EL expression set, use it, otherwise use the hardcoded
- // value. See MYFACES-3591 for details.
- expression = component.getValueExpression("label");
- if (expression != null)
- {
- // Set the label to null and use the EL expression instead.
- label = null;
- }
- }
-
- if(label != null)
- {
- return label;
- }
-
- expression = (expression == null) ? component.getValueExpression("label") : expression;
- if(expression != null)
- {
- return expression;
- }
-
- //If no label is not specified, use clientId
- return component.getClientId( facesContext );
- }
-}
diff --git a/api/src/main/java/javax/faces/component/_SelectItemsUtil.java b/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
index 4ef6ed3..c031ed9 100644
--- a/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
+++ b/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ClassUtils;
import java.util.Arrays;
import java.util.Iterator;
diff --git a/api/src/main/java/javax/faces/component/html/_HtmlInputFile.java b/api/src/main/java/javax/faces/component/html/_HtmlInputFile.java
index 4758314..d06eb68 100644
--- a/api/src/main/java/javax/faces/component/html/_HtmlInputFile.java
+++ b/api/src/main/java/javax/faces/component/html/_HtmlInputFile.java
@@ -23,18 +23,19 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* Renders a HTML input element.
*
*/
-@JSFComponent
-(name = "h:inputFile",
-clazz = "javax.faces.component.html.HtmlInputFile",template=true,
-tagClass = "org.apache.myfaces.taglib.html.HtmlInputFileTag",
-defaultRendererType = "javax.faces.File",
-implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
-defaultEventName = "valueChange"
+@JSFComponent(name = "h:inputFile",
+ clazz = "javax.faces.component.html.HtmlInputFile",
+ template = true,
+ tagClass = "org.apache.myfaces.taglib.html.HtmlInputFileTag",
+ defaultRendererType = "javax.faces.File",
+ implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
+ defaultEventName = "valueChange"
)
abstract class _HtmlInputFile extends UIInput implements _AccesskeyProperty,
_AltProperty, _UniversalProperties, _DisabledReadonlyProperties,
@@ -43,38 +44,37 @@
_RoleProperty
{
- static public final String COMPONENT_FAMILY =
- "javax.faces.Input";
- static public final String COMPONENT_TYPE =
- "javax.faces.HtmlInputFile";
+ static public final String COMPONENT_FAMILY = "javax.faces.Input";
+ static public final String COMPONENT_TYPE = "javax.faces.HtmlInputFile";
- /**
- * HTML: The maximum number of characters allowed to be entered.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getMaxlength();
+ /**
+ * HTML: The maximum number of characters allowed to be entered.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getMaxlength();
- /**
- * HTML: The initial width of this control, in characters.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getSize();
+ /**
+ * HTML: The initial width of this control, in characters.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getSize();
- /**
- * If the value of this attribute is "off", render "off" as the value of the attribute.
- * This indicates that the browser should disable its autocomplete feature for this component.
- * This is useful for components that perform autocompletion and do not want the browser interfering.
- * If this attribute is not set or the value is "on", render nothing.
- *
- * @return the new autocomplete value
- */
- @JSFProperty
- public abstract String getAutocomplete();
+ /**
+ * If the value of this attribute is "off", render "off" as the value of the attribute.
+ * This indicates that the browser should disable its autocomplete feature for this component.
+ * This is useful for components that perform autocompletion and do not want the browser interfering.
+ * If this attribute is not set or the value is "on", render nothing.
+ *
+ * @return the new autocomplete value
+ */
+ @JSFProperty
+ public abstract String getAutocomplete();
+ @Override
protected void validateValue(FacesContext context, Object convertedValue)
{
if (!isValid())
diff --git a/api/src/main/java/javax/faces/component/html/_HtmlInputText.java b/api/src/main/java/javax/faces/component/html/_HtmlInputText.java
index 430ba05..68802d0 100644
--- a/api/src/main/java/javax/faces/component/html/_HtmlInputText.java
+++ b/api/src/main/java/javax/faces/component/html/_HtmlInputText.java
@@ -27,13 +27,13 @@
* Renders a HTML input element.
*
*/
-@JSFComponent
-(name = "h:inputText",
-clazz = "javax.faces.component.html.HtmlInputText",template=true,
-tagClass = "org.apache.myfaces.taglib.html.HtmlInputTextTag",
-defaultRendererType = "javax.faces.Text",
-implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
-defaultEventName = "valueChange"
+@JSFComponent(name = "h:inputText",
+ clazz = "javax.faces.component.html.HtmlInputText",
+ template = true,
+ tagClass = "org.apache.myfaces.taglib.html.HtmlInputTextTag",
+ defaultRendererType = "javax.faces.Text",
+ implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
+ defaultEventName = "valueChange"
)
abstract class _HtmlInputText extends UIInput implements _AccesskeyProperty,
_AltProperty, _UniversalProperties, _DisabledReadonlyProperties,
@@ -42,36 +42,34 @@
_RoleProperty
{
- static public final String COMPONENT_FAMILY =
- "javax.faces.Input";
- static public final String COMPONENT_TYPE =
- "javax.faces.HtmlInputText";
+ static public final String COMPONENT_FAMILY = "javax.faces.Input";
+ static public final String COMPONENT_TYPE = "javax.faces.HtmlInputText";
- /**
- * HTML: The maximum number of characters allowed to be entered.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getMaxlength();
+ /**
+ * HTML: The maximum number of characters allowed to be entered.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getMaxlength();
- /**
- * HTML: The initial width of this control, in characters.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getSize();
+ /**
+ * HTML: The initial width of this control, in characters.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getSize();
- /**
- * If the value of this attribute is "off", render "off" as the value of the attribute.
- * This indicates that the browser should disable its autocomplete feature for this component.
- * This is useful for components that perform autocompletion and do not want the browser interfering.
- * If this attribute is not set or the value is "on", render nothing.
- *
- * @return the new autocomplete value
- */
- @JSFProperty
- public abstract String getAutocomplete();
+ /**
+ * If the value of this attribute is "off", render "off" as the value of the attribute.
+ * This indicates that the browser should disable its autocomplete feature for this component.
+ * This is useful for components that perform autocompletion and do not want the browser interfering.
+ * If this attribute is not set or the value is "on", render nothing.
+ *
+ * @return the new autocomplete value
+ */
+ @JSFProperty
+ public abstract String getAutocomplete();
}
diff --git a/api/src/main/java/javax/faces/component/html/_HtmlInputTextarea.java b/api/src/main/java/javax/faces/component/html/_HtmlInputTextarea.java
index 275123d..3e1a5ba 100644
--- a/api/src/main/java/javax/faces/component/html/_HtmlInputTextarea.java
+++ b/api/src/main/java/javax/faces/component/html/_HtmlInputTextarea.java
@@ -26,13 +26,13 @@
* Renders a HTML textarea element.
*
*/
-@JSFComponent
-(name = "h:inputTextarea",
-clazz = "javax.faces.component.html.HtmlInputTextarea",template=true,
-tagClass = "org.apache.myfaces.taglib.html.HtmlInputTextareaTag",
-defaultRendererType = "javax.faces.Textarea",
-implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
-defaultEventName = "valueChange"
+@JSFComponent(name = "h:inputTextarea",
+ clazz = "javax.faces.component.html.HtmlInputTextarea",
+ template = true,
+ tagClass = "org.apache.myfaces.taglib.html.HtmlInputTextareaTag",
+ defaultRendererType = "javax.faces.Textarea",
+ implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
+ defaultEventName = "valueChange"
)
abstract class _HtmlInputTextarea extends UIInput implements _AccesskeyProperty,
_UniversalProperties, _FocusBlurProperties, _ChangeProperty,
@@ -41,25 +41,23 @@
_RoleProperty
{
- static public final String COMPONENT_FAMILY =
- "javax.faces.Input";
- static public final String COMPONENT_TYPE =
- "javax.faces.HtmlInputTextarea";
+ static public final String COMPONENT_FAMILY = "javax.faces.Input";
+ static public final String COMPONENT_TYPE = "javax.faces.HtmlInputTextarea";
- /**
- * HTML: The width of this element, in characters.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getCols();
-
- /**
- * HTML: The height of this element, in characters.
- *
- * @JSFProperty
- * defaultValue = "Integer.MIN_VALUE"
- */
- public abstract int getRows();
+ /**
+ * HTML: The width of this element, in characters.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getCols();
+
+ /**
+ * HTML: The height of this element, in characters.
+ *
+ * @JSFProperty
+ * defaultValue = "Integer.MIN_VALUE"
+ */
+ public abstract int getRows();
}
diff --git a/api/src/main/java/javax/faces/component/html/_ParametrizableFacesMessage.java b/api/src/main/java/javax/faces/component/html/_ParametrizableFacesMessage.java
deleted file mode 100644
index bbef3f5..0000000
--- a/api/src/main/java/javax/faces/component/html/_ParametrizableFacesMessage.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.html;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-
-import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
-/**
- * This class encapsulates a FacesMessage to evaluate the label
- * expression on render response, where f:loadBundle is available
- */
-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;
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setDetail(String detail)
- {
- super.setDetail(detail);
- _evaluatedDetail = null;
- }
-
- public String getUnformattedDetail()
- {
- return super.getDetail();
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setSummary(String summary)
- {
- super.setSummary(summary);
- _evaluatedSummary = null;
- }
-
- public String getUnformattedSummary()
- {
- return super.getSummary();
- }
-
- 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 ValueExpression)
- {
- if (facesContext == null)
- {
- facesContext = FacesContext.getCurrentInstance();
- }
- _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
- }
- else
- {
- _evaluatedArgs[i] = _args[i];
- }
- }
- }
-}
diff --git a/api/src/main/java/javax/faces/convert/BigDecimalConverter.java b/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
index 91ab748..a40e53a 100755
--- a/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
+++ b/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
@@ -24,6 +24,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
import java.math.BigDecimal;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/BigIntegerConverter.java b/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
index a8f9d14..3607e36 100755
--- a/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
+++ b/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
@@ -24,6 +24,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
import java.math.BigInteger;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/BooleanConverter.java b/api/src/main/java/javax/faces/convert/BooleanConverter.java
index e011fa2..d2b0ddd 100755
--- a/api/src/main/java/javax/faces/convert/BooleanConverter.java
+++ b/api/src/main/java/javax/faces/convert/BooleanConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/ByteConverter.java b/api/src/main/java/javax/faces/convert/ByteConverter.java
index 84654a0..e63d198 100755
--- a/api/src/main/java/javax/faces/convert/ByteConverter.java
+++ b/api/src/main/java/javax/faces/convert/ByteConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/CharacterConverter.java b/api/src/main/java/javax/faces/convert/CharacterConverter.java
index 94067a1..87a372a 100755
--- a/api/src/main/java/javax/faces/convert/CharacterConverter.java
+++ b/api/src/main/java/javax/faces/convert/CharacterConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/DateTimeConverter.java b/api/src/main/java/javax/faces/convert/DateTimeConverter.java
index 3de25cd..ebc8947 100755
--- a/api/src/main/java/javax/faces/convert/DateTimeConverter.java
+++ b/api/src/main/java/javax/faces/convert/DateTimeConverter.java
@@ -42,6 +42,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* This tag associates a date time converter with the nearest parent UIComponent.
diff --git a/api/src/main/java/javax/faces/convert/DoubleConverter.java b/api/src/main/java/javax/faces/convert/DoubleConverter.java
index ad64c21..b75ec23 100755
--- a/api/src/main/java/javax/faces/convert/DoubleConverter.java
+++ b/api/src/main/java/javax/faces/convert/DoubleConverter.java
@@ -25,6 +25,7 @@
import java.text.DecimalFormatSymbols;
import java.util.Locale;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/EnumConverter.java b/api/src/main/java/javax/faces/convert/EnumConverter.java
index 941a142..2c724b1 100644
--- a/api/src/main/java/javax/faces/convert/EnumConverter.java
+++ b/api/src/main/java/javax/faces/convert/EnumConverter.java
@@ -25,6 +25,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/FloatConverter.java b/api/src/main/java/javax/faces/convert/FloatConverter.java
index 6c649c5..bd39757 100755
--- a/api/src/main/java/javax/faces/convert/FloatConverter.java
+++ b/api/src/main/java/javax/faces/convert/FloatConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/IntegerConverter.java b/api/src/main/java/javax/faces/convert/IntegerConverter.java
index f04e11f..f66086a 100755
--- a/api/src/main/java/javax/faces/convert/IntegerConverter.java
+++ b/api/src/main/java/javax/faces/convert/IntegerConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/LongConverter.java b/api/src/main/java/javax/faces/convert/LongConverter.java
index 019cc8f..50cd287 100755
--- a/api/src/main/java/javax/faces/convert/LongConverter.java
+++ b/api/src/main/java/javax/faces/convert/LongConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/NumberConverter.java b/api/src/main/java/javax/faces/convert/NumberConverter.java
index 4df5673..0d968aa 100755
--- a/api/src/main/java/javax/faces/convert/NumberConverter.java
+++ b/api/src/main/java/javax/faces/convert/NumberConverter.java
@@ -37,6 +37,7 @@
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* This tag creates a number formatting converter and associates it
diff --git a/api/src/main/java/javax/faces/convert/ShortConverter.java b/api/src/main/java/javax/faces/convert/ShortConverter.java
index b1ee397..0bba0c7 100755
--- a/api/src/main/java/javax/faces/convert/ShortConverter.java
+++ b/api/src/main/java/javax/faces/convert/ShortConverter.java
@@ -22,6 +22,7 @@
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.core.api.shared._MessageUtils;
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
diff --git a/api/src/main/java/javax/faces/convert/_MessageUtils.java b/api/src/main/java/javax/faces/convert/_MessageUtils.java
deleted file mode 100755
index d999341..0000000
--- a/api/src/main/java/javax/faces/convert/_MessageUtils.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * 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 javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-class _MessageUtils
-{
- private static final String DETAIL_SUFFIX = "_detail";
-
- static FacesMessage getErrorMessage(FacesContext facesContext,
- String messageId,
- Object args[])
- {
- return getMessage(facesContext,
- facesContext.getViewRoot().getLocale(),
- FacesMessage.SEVERITY_ERROR,
- messageId,
- args);
- }
-
- static FacesMessage getMessage(FacesContext facesContext,
- Locale locale,
- FacesMessage.Severity severity,
- String messageId,
- Object args[])
- {
- ResourceBundle appBundle;
- ResourceBundle defBundle;
- String summary;
- String detail;
-
- appBundle = getApplicationBundle(facesContext, locale);
- summary = getBundleString(appBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- defBundle = getDefaultBundle(facesContext, locale);
- summary = getBundleString(defBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- //Try to find detail alone
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- //Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId
- + " found in any bundle");
- return new FacesMessage(severity, messageId, null);
- }
- }
- }
- }
-
- if (args != null && args.length > 0)
- {
- return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
- }
- else
- {
- return new FacesMessage(severity, summary, detail);
- }
- }
-
- private static String getBundleString(ResourceBundle bundle, String key)
- {
- try
- {
- if (bundle != null && bundle.containsKey(key))
- {
- return bundle.getString(key);
- }
- }
- catch (MissingResourceException e)
- {
- // NOOP
- }
-
- return null;
- }
-
-
- private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)
- {
- String bundleName = facesContext.getApplication().getMessageBundle();
- return bundleName != null ? getBundle(facesContext, locale, bundleName) : null;
- }
-
- private static ResourceBundle getDefaultBundle(FacesContext facesContext,
- Locale locale)
- {
- return getBundle(facesContext, locale, FacesMessage.FACES_MESSAGES);
- }
-
- private static ResourceBundle getBundle(FacesContext facesContext,
- Locale locale,
- String bundleName)
- {
- ResourceBundle.Control bundleControl = (ResourceBundle.Control) facesContext.getExternalContext()
- .getApplicationMap().get("org.apache.myfaces.RESOURCE_BUNDLE_CONTROL");
-
- try
- {
- //First we try the JSF implementation class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore1)
- {
- try
- {
- //Next we try the JSF API class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore2)
- {
- try
- {
- //Last resort is the context class loader
- ClassLoader cl;
- if (System.getSecurityManager() == null)
- {
- cl = Thread.currentThread().getContextClassLoader();
- }
- else
- {
- cl = (ClassLoader) AccessController.doPrivileged(
- (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
- }
-
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName, locale, cl);
- }
- else
- {
- return ResourceBundle.getBundle(bundleName, locale, cl, bundleControl);
- }
- }
- catch(PrivilegedActionException pae)
- {
- throw new FacesException(pae);
- }
- catch (MissingResourceException damned)
- {
- facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");
- return null;
- }
- }
- }
- }
-
- static Object getLabel(FacesContext facesContext, UIComponent component)
- {
- Object label = component.getAttributes().get("label");
- ValueExpression expression = null;
- if (label != null &&
- label instanceof String && ((String)label).length() == 0 )
- {
- // Note component.getAttributes().get("label") internally try to
- // evaluate the EL expression for the label, but in some cases,
- // when PSS is disabled and f:loadBundle is used, when the view is
- // restored the bundle is not set to the EL expression returns an
- // empty String. It is not possible to check if there is a
- // hardcoded label, but we can check if there is
- // an EL expression set, so the best in this case is use that, and if
- // there is an EL expression set, use it, otherwise use the hardcoded
- // value. See MYFACES-3591 for details.
- expression = component.getValueExpression("label");
- if (expression != null)
- {
- // Set the label to null and use the EL expression instead.
- label = null;
- }
- }
-
- if(label != null)
- {
- return label;
- }
-
- expression = (expression == null) ? component.getValueExpression("label") : expression;
- if(expression != null)
- {
- return expression;
- }
-
- //If no label is not specified, use clientId
- return component.getClientId( facesContext );
- }
-}
diff --git a/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java b/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
deleted file mode 100644
index 1a4c4b9..0000000
--- a/api/src/main/java/javax/faces/convert/_ParametrizableFacesMessage.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
-/**
- * This class encapsulates a FacesMessage to evaluate the label
- * expression on render response, where f:loadBundle is available
- */
-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;
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setDetail(String detail)
- {
- super.setDetail(detail);
- _evaluatedDetail = null;
- }
-
- public String getUnformattedDetail()
- {
- return super.getDetail();
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setSummary(String summary)
- {
- super.setSummary(summary);
- _evaluatedSummary = null;
- }
-
- public String getUnformattedSummary()
- {
- return super.getSummary();
- }
-
- 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 ValueExpression)
- {
- if (facesContext == null)
- {
- facesContext = FacesContext.getCurrentInstance();
- }
- _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
- }
- else
- {
- _evaluatedArgs[i] = _args[i];
- }
- }
- }
-}
diff --git a/api/src/main/java/javax/faces/validator/BeanValidator.java b/api/src/main/java/javax/faces/validator/BeanValidator.java
index e377549..41f302e 100644
--- a/api/src/main/java/javax/faces/validator/BeanValidator.java
+++ b/api/src/main/java/javax/faces/validator/BeanValidator.java
@@ -18,6 +18,8 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
+import org.apache.myfaces.core.api.shared._ExternalSpecifications;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
diff --git a/api/src/main/java/javax/faces/validator/DoubleRangeValidator.java b/api/src/main/java/javax/faces/validator/DoubleRangeValidator.java
index 068fb8a..bdb01c8 100755
--- a/api/src/main/java/javax/faces/validator/DoubleRangeValidator.java
+++ b/api/src/main/java/javax/faces/validator/DoubleRangeValidator.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import javax.faces.component.PartialStateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
diff --git a/api/src/main/java/javax/faces/validator/LengthValidator.java b/api/src/main/java/javax/faces/validator/LengthValidator.java
index 22df8e4..ccb3d6e 100755
--- a/api/src/main/java/javax/faces/validator/LengthValidator.java
+++ b/api/src/main/java/javax/faces/validator/LengthValidator.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import javax.faces.component.PartialStateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
diff --git a/api/src/main/java/javax/faces/validator/LongRangeValidator.java b/api/src/main/java/javax/faces/validator/LongRangeValidator.java
index 2a4fc0e..9259923 100755
--- a/api/src/main/java/javax/faces/validator/LongRangeValidator.java
+++ b/api/src/main/java/javax/faces/validator/LongRangeValidator.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import javax.faces.component.PartialStateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
diff --git a/api/src/main/java/javax/faces/validator/RegexValidator.java b/api/src/main/java/javax/faces/validator/RegexValidator.java
index 4d930cb..8e3e412 100644
--- a/api/src/main/java/javax/faces/validator/RegexValidator.java
+++ b/api/src/main/java/javax/faces/validator/RegexValidator.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFValidator;
diff --git a/api/src/main/java/javax/faces/validator/RequiredValidator.java b/api/src/main/java/javax/faces/validator/RequiredValidator.java
index b0e974c..0514583 100644
--- a/api/src/main/java/javax/faces/validator/RequiredValidator.java
+++ b/api/src/main/java/javax/faces/validator/RequiredValidator.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
diff --git a/api/src/main/java/javax/faces/validator/_MessageUtils.java b/api/src/main/java/javax/faces/validator/_MessageUtils.java
deleted file mode 100755
index e8693bf..0000000
--- a/api/src/main/java/javax/faces/validator/_MessageUtils.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * 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.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-class _MessageUtils
-{
- private static final String DETAIL_SUFFIX = "_detail";
-
- static FacesMessage getErrorMessage(FacesContext facesContext,
- String messageId,
- Object args[])
- {
- return getMessage(facesContext,
- facesContext.getViewRoot().getLocale(),
- FacesMessage.SEVERITY_ERROR,
- messageId,
- args);
- }
-
- static FacesMessage getMessage(FacesContext facesContext,
- Locale locale,
- FacesMessage.Severity severity,
- String messageId,
- Object args[])
- {
- ResourceBundle appBundle;
- ResourceBundle defBundle;
- String summary;
- String detail;
-
- if(locale == null)
- {
- locale = Locale.getDefault();
- }
-
- appBundle = getApplicationBundle(facesContext, locale);
- summary = getBundleString(appBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- defBundle = getDefaultBundle(facesContext, locale);
- summary = getBundleString(defBundle, messageId);
- if (summary != null)
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- }
- else
- {
- //Try to find detail alone
- detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);
- if (detail != null)
- {
- summary = null;
- }
- else
- {
- //Neither detail nor summary found
- facesContext.getExternalContext().log("No message with id " + messageId
- + " found in any bundle");
- return new FacesMessage(severity, messageId, null);
- }
- }
- }
- }
-
- if (args != null && args.length > 0)
- {
- return new _ParametrizableFacesMessage(severity, summary, detail, args, locale);
- }
- else
- {
- return new FacesMessage(severity, summary, detail);
- }
- }
-
- private static String getBundleString(ResourceBundle bundle, String key)
- {
- try
- {
- if (bundle != null && bundle.containsKey(key))
- {
- return bundle.getString(key);
- }
- }
- catch (MissingResourceException e)
- {
- // NOOP
- }
-
- return null;
- }
-
-
- private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)
- {
- String bundleName = facesContext.getApplication().getMessageBundle();
- return bundleName != null ? getBundle(facesContext, locale, bundleName) : null;
- }
-
- private static ResourceBundle getDefaultBundle(FacesContext facesContext,
- Locale locale)
- {
- return getBundle(facesContext, locale, FacesMessage.FACES_MESSAGES);
- }
-
- private static ResourceBundle getBundle(FacesContext facesContext,
- Locale locale,
- String bundleName)
- {
- ResourceBundle.Control bundleControl = (ResourceBundle.Control) facesContext.getExternalContext()
- .getApplicationMap().get("org.apache.myfaces.RESOURCE_BUNDLE_CONTROL");
-
- try
- {
- //First we try the JSF implementation class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- facesContext.getClass().getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore1)
- {
- try
- {
- //Next we try the JSF API class loader
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader());
- }
- else
- {
- return ResourceBundle.getBundle(bundleName,
- locale,
- _MessageUtils.class.getClassLoader(), bundleControl);
- }
- }
- catch (MissingResourceException ignore2)
- {
- try
- {
- //Last resort is the context class loader
- ClassLoader cl;
- if (System.getSecurityManager() == null)
- {
- cl = Thread.currentThread().getContextClassLoader();
- }
- else
- {
- cl = (ClassLoader) AccessController.doPrivileged(
- (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
- }
-
- if (bundleControl == null)
- {
- return ResourceBundle.getBundle(bundleName, locale, cl);
- }
- else
- {
- return ResourceBundle.getBundle(bundleName, locale, cl, bundleControl);
- }
- }
- catch(PrivilegedActionException pae)
- {
- throw new FacesException(pae);
- }
- catch (MissingResourceException damned)
- {
- facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");
- return null;
- }
- }
- }
- }
-
- static Object getLabel(FacesContext facesContext, UIComponent component)
- {
- Object label = component.getAttributes().get("label");
- ValueExpression expression = null;
- if (label != null &&
- label instanceof String && ((String)label).length() == 0 )
- {
- // Note component.getAttributes().get("label") internally try to
- // evaluate the EL expression for the label, but in some cases,
- // when PSS is disabled and f:loadBundle is used, when the view is
- // restored the bundle is not set to the EL expression returns an
- // empty String. It is not possible to check if there is a
- // hardcoded label, but we can check if there is
- // an EL expression set, so the best in this case is use that, and if
- // there is an EL expression set, use it, otherwise use the hardcoded
- // value. See MYFACES-3591 for details.
- expression = component.getValueExpression("label");
- if (expression != null)
- {
- // Set the label to null and use the EL expression instead.
- label = null;
- }
- }
-
- if(label != null)
- {
- return label;
- }
-
- expression = (expression == null) ? component.getValueExpression("label") : expression;
- if(expression != null)
- {
- return expression;
- }
-
- //If no label is not specified, use clientId
- return component.getClientId( facesContext );
- }
-}
diff --git a/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java b/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
deleted file mode 100644
index 9bce767..0000000
--- a/api/src/main/java/javax/faces/validator/_ParametrizableFacesMessage.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
-/**
- * This class encapsulates a FacesMessage to evaluate the label
- * expression on render response, where f:loadBundle is available
- */
-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;
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setDetail(String detail)
- {
- super.setDetail(detail);
- _evaluatedDetail = null;
- }
-
- public String getUnformattedDetail()
- {
- return super.getDetail();
- }
-
- @Override
- 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;
- }
-
- @Override
- public void setSummary(String summary)
- {
- super.setSummary(summary);
- _evaluatedSummary = null;
- }
-
- public String getUnformattedSummary()
- {
- return super.getSummary();
- }
-
- 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 ValueExpression)
- {
- if (facesContext == null)
- {
- facesContext = FacesContext.getCurrentInstance();
- }
- _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
- }
- else
- {
- _evaluatedArgs[i] = _args[i];
- }
- }
- }
-}
diff --git a/api/src/main/java/javax/faces/validator/_ValidationUtils.java b/api/src/main/java/javax/faces/validator/_ValidationUtils.java
deleted file mode 100644
index 8bc631c..0000000
--- a/api/src/main/java/javax/faces/validator/_ValidationUtils.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 javax.validation.Validation;
-
-/**
- * Utility class that isolates javax.validation, to prevent ClassNotFoundException
- *
- * @since 2.0
- */
-final class _ValidationUtils
-{
-
- public static void tryBuildDefaultValidatorFactory()
- {
- Validation.buildDefaultValidatorFactory().getValidator();
- }
-}
diff --git a/api/src/main/java/javax/faces/component/_ValidationUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_BeanValidationUtils.java
similarity index 79%
rename from api/src/main/java/javax/faces/component/_ValidationUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_BeanValidationUtils.java
index 97cc864..a0d7da9 100644
--- a/api/src/main/java/javax/faces/component/_ValidationUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_BeanValidationUtils.java
@@ -16,8 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
+import javax.faces.validator.BeanValidator;
+import javax.faces.validator.Validator;
import javax.validation.Validation;
/**
@@ -25,8 +27,12 @@
*
* @since 2.0
*/
-final class _ValidationUtils
+public final class _BeanValidationUtils
{
+ public static boolean isBeanValidator(Validator v)
+ {
+ return v instanceof BeanValidator;
+ }
public static void tryBuildDefaultValidatorFactory()
{
diff --git a/api/src/main/java/javax/faces/component/_ClassUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_ClassUtils.java
similarity index 69%
rename from api/src/main/java/javax/faces/component/_ClassUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_ClassUtils.java
index 9a1ba1e..62eb765 100755
--- a/api/src/main/java/javax/faces/component/_ClassUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_ClassUtils.java
@@ -16,16 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
@@ -38,7 +40,7 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
-final class _ClassUtils
+public class _ClassUtils
{
// ~ Static fields/initializers -----------------------------------------------------------------
@@ -63,6 +65,15 @@
public static final Class<Double[]> DOUBLE_OBJECT_ARRAY_CLASS = Double[].class;
public static final Class<String[]> STRING_OBJECT_ARRAY_CLASS = String[].class;
+ protected static final String[] EMPTY_STRING = new String[0];
+
+ protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean", "byte", "char", "double", "float",
+ "int", "long", "short", "void" };
+
+ protected static final Class<?>[] PRIMITIVES = new Class[] { Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE,
+ Float.TYPE, Integer.TYPE, Long.TYPE, Short.TYPE,
+ Void.TYPE };
+
public static final Map<String, Class<?>> COMMON_TYPES = new HashMap<String, Class<?>>(64);
static
{
@@ -107,14 +118,6 @@
// array of void is not a valid type
}
- /** utility class, do not instantiate */
- private _ClassUtils()
- {
- // utility class, disable instantiation
- }
-
- // ~ Methods ------------------------------------------------------------------------------------
-
/**
* Tries a Class.loadClass with the context class loader of the current thread first and automatically falls back to
* the ClassUtils class loader (i.e. the loader of the myfaces.jar lib) if necessary.
@@ -126,7 +129,7 @@
* if type is null
* @throws ClassNotFoundException
*/
- public static Class<?> classForName(String type) throws ClassNotFoundException
+ public static <T> Class<T> classForName(String type) throws ClassNotFoundException
{
if (type == null)
{
@@ -135,14 +138,14 @@
try
{
// Try WebApp ClassLoader first
- return Class.forName(type,
+ return (Class<T>) Class.forName(type,
false, // do not initialize for faster startup
getContextClassLoader());
}
catch (ClassNotFoundException ignore)
{
// fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
- return Class.forName(type,
+ return (Class<T>) Class.forName(type,
false, // do not initialize for faster startup
_ClassUtils.class.getClassLoader());
}
@@ -158,17 +161,36 @@
* @throws FacesException
* if class not found
*/
- public static Class<?> simpleClassForName(String type)
+ public static Class simpleClassForName(String type)
{
+ return simpleClassForName(type, true);
+ }
+
+ /**
+ * Same as {link {@link #simpleClassForName(String)}, but will only
+ * log the exception and rethrow a RunTimeException if logException is true.
+ *
+ * @param type
+ * @param logException - true to log/throw FacesException, false to avoid logging/throwing FacesException
+ * @return the corresponding Class
+ * @throws FacesException if class not found and logException is true
+ */
+ public static Class simpleClassForName(String type, boolean logException)
+ {
+ Class returnClass = null;
try
{
- return classForName(type);
+ returnClass = classForName(type);
}
catch (ClassNotFoundException e)
{
- log.log(Level.SEVERE, "Class " + type + " not found", e);
- throw new FacesException(e);
+ if (logException)
+ {
+ log.log(Level.SEVERE, "Class " + type + " not found", e);
+ throw new FacesException(e);
+ }
}
+ return returnClass;
}
/**
@@ -231,6 +253,54 @@
throw new FacesException(e);
}
}
+
+ /**
+ * This method is similar to shared ClassUtils.javaTypeToClass,
+ * but the default package for the type is java.lang
+ *
+ * @param type
+ * @return
+ * @throws ClassNotFoundException
+ */
+ public static Class javaDefaultTypeToClass(String type)
+ throws ClassNotFoundException
+ {
+ if (type == null)
+ {
+ throw new NullPointerException("type");
+ }
+
+ // try common types and arrays of common types first
+ Class clazz = (Class) COMMON_TYPES.get(type);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+
+ int len = type.length();
+ if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
+ {
+ String componentType = type.substring(0, len - 2);
+ Class componentTypeClass = classForName(componentType);
+ return Array.newInstance(componentTypeClass, 0).getClass();
+ }
+
+ if (type.indexOf('.') == -1)
+ {
+ type = "java.lang." + type;
+ }
+ return classForName(type);
+ }
+
+ public static URL getResource(String resource)
+ {
+ URL url = getContextClassLoader().getResource(resource);
+ if (url == null)
+ {
+ url = _ClassUtils.class.getClassLoader().getResource(resource);
+ }
+ return url;
+ }
public static InputStream getResourceAsStream(String resource)
{
@@ -242,7 +312,7 @@
}
return stream;
}
-
+
/**
* @param resource
* Name of resource(s) to find in classpath
@@ -250,12 +320,12 @@
* The default object to use to determine the class loader (if none associated with current thread.)
* @return Iterator over URL Objects
*/
- public static Collection<? extends URL> getResources(String resource, Object defaultObject)
+ public static Collection<URL> getResources(String resource, Object defaultObject)
{
try
{
Enumeration<URL> resources = getCurrentLoader(defaultObject).getResources(resource);
- List<URL> lst = new ArrayList<URL>();
+ List<URL> lst = new ArrayList<>();
while (resources.hasMoreElements())
{
lst.add(resources.nextElement());
@@ -307,7 +377,7 @@
return newInstance(clazzForName);
}
- public static Object newInstance(Class<?> clazz) throws FacesException
+ public static <T> T newInstance(Class<T> clazz) throws FacesException
{
try
{
@@ -330,6 +400,30 @@
}
}
+ public static <T> T newInstance(Class<T> clazz,
+ Class<?>[] constructorArgClasses,
+ Object... constructorArgs) throws NoSuchMethodException
+ {
+ if (constructorArgs.length == 0)
+ {
+ // no args given - use normal newInstance()
+ return newInstance(clazz);
+ }
+
+ // try to get a fitting constructor (throws NoSuchMethodException)
+ Constructor constructor = clazz.getConstructor(constructorArgClasses);
+
+ try
+ {
+ // actually create instance
+ return (T) constructor.newInstance(constructorArgs);
+ }
+ catch (Exception e)
+ {
+ throw new FacesException(e);
+ }
+ }
+
public static Object convertToType(Object value, Class<?> desiredClass)
{
if (value == null)
@@ -370,10 +464,9 @@
* The default object to use to determine the class loader (if none associated with current thread.)
* @return ClassLoader
*/
- protected static ClassLoader getCurrentLoader(Object defaultObject)
+ public static ClassLoader getCurrentLoader(Object defaultObject)
{
ClassLoader loader = getContextClassLoader();
-
if (loader == null)
{
loader = defaultObject.getClass().getClassLoader();
@@ -387,7 +480,7 @@
*
* @return ClassLoader
*/
- protected static ClassLoader getContextClassLoader()
+ public static ClassLoader getContextClassLoader()
{
if (System.getSecurityManager() != null)
{
@@ -401,9 +494,93 @@
throw new FacesException(pae);
}
}
- else
- {
- return Thread.currentThread().getContextClassLoader();
- }
+
+ return Thread.currentThread().getContextClassLoader();
}
+
+ public static Class<?> forNamePrimitive(String name)
+ {
+ if (name.length() <= 8)
+ {
+ int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
+ if (p >= 0)
+ {
+ return PRIMITIVES[p];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Converts an array of Class names to Class types
+ *
+ * @param s
+ * @return
+ * @throws ClassNotFoundException
+ */
+ public static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException
+ {
+ if (s == null)
+ {
+ return null;
+ }
+
+ Class<?>[] c = new Class[s.length];
+ for (int i = 0; i < s.length; i++)
+ {
+ c[i] = forName(s[i]);
+ }
+
+ return c;
+ }
+
+ /**
+ * Converts an array of Class types to Class names
+ *
+ * @param c
+ * @return
+ */
+ public static String[] toTypeNameArray(Class<?>[] c)
+ {
+ if (c == null)
+ {
+ return null;
+ }
+
+ String[] s = new String[c.length];
+ for (int i = 0; i < c.length; i++)
+ {
+ s[i] = c[i].getName();
+ }
+
+ return s;
+ }
+
+ public static Class<?> forName(String name) throws ClassNotFoundException
+ {
+ if (name == null || name.isEmpty())
+ {
+ return null;
+ }
+
+ Class<?> c = forNamePrimitive(name);
+ if (c == null)
+ {
+ if (name.endsWith("[]"))
+ {
+ String nc = name.substring(0, name.length() - 2);
+ //we should route through our shared forName, due to plugins and due to better classloader resolution
+ c = classForName(nc);
+ c = Array.newInstance(c, 0).getClass();
+ }
+ else
+ {
+ c = classForName(name);
+ }
+ }
+
+ return c;
+ }
+
}
diff --git a/api/src/main/java/javax/faces/component/_ComponentUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_ComponentUtils.java
similarity index 90%
rename from api/src/main/java/javax/faces/component/_ComponentUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_ComponentUtils.java
index 5b2e8c5..5b5964d 100755
--- a/api/src/main/java/javax/faces/component/_ComponentUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_ComponentUtils.java
@@ -16,18 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import java.util.Collection;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIViewRoot;
/**
* A collection of static helper methods for locating UIComponents.
*/
-class _ComponentUtils
+public class _ComponentUtils
{
public static final String V_ID_PREFIX = "__v_";
public static final String RD_ID_PREFIX = "__rd_";
@@ -59,7 +63,7 @@
{
}
- static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
+ public static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
{
NamingContainer result = closest(NamingContainer.class, component);
if (result != null)
@@ -75,7 +79,7 @@
return null;
}
- static <T> T closest(Class<T> type, UIComponent base)
+ public static <T> T closest(Class<T> type, UIComponent base)
{
UIComponent parent = base.getParent();
@@ -92,7 +96,7 @@
return null;
}
- static UIComponent getRootComponent(UIComponent component)
+ public static UIComponent getRootComponent(UIComponent component)
{
UIComponent parent;
for (;;)
@@ -118,7 +122,7 @@
*
* @return findBase, a descendant of findBase, or null.
*/
- static UIComponent findComponent(UIComponent findBase, String id, final char separatorChar)
+ public static UIComponent findComponent(UIComponent findBase, String id, final char separatorChar)
{
if (!(findBase instanceof NamingContainer) && id.equals(findBase.getId()))
{
@@ -170,7 +174,7 @@
return null;
}
- static UIComponent findComponentChildOrFacetFrom(UIComponent parent, String id, String innerExpr)
+ public static UIComponent findComponentChildOrFacetFrom(UIComponent parent, String id, String innerExpr)
{
if (parent.getFacetCount() > 0)
{
@@ -234,7 +238,7 @@
return null;
}
- static void callValidators(FacesContext context, UIInput input, Object convertedValue)
+ public static void callValidators(FacesContext context, UIInput input, Object convertedValue)
{
// first invoke the list of validator components
Validator[] validators = input.getValidators();
@@ -275,7 +279,7 @@
}
}
- static String getPathToComponent(UIComponent component)
+ public static String getPathToComponent(UIComponent component)
{
StringBuilder buf = new StringBuilder();
@@ -299,7 +303,7 @@
* reads the isRendered property, call {@link
* UIComponent#popComponentFromEL} and returns the value of isRendered.
*/
- static boolean isRendered(FacesContext facesContext, UIComponent uiComponent)
+ public static boolean isRendered(FacesContext facesContext, UIComponent uiComponent)
{
// We must call pushComponentToEL here because ValueExpression may have
// implicit object "component" used.
@@ -314,7 +318,7 @@
}
}
- private static void getPathToComponent(UIComponent component, StringBuilder buf)
+ public static void getPathToComponent(UIComponent component, StringBuilder buf)
{
if (component == null)
{
diff --git a/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_ExternalSpecifications.java
similarity index 94%
rename from api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_ExternalSpecifications.java
index 991b328..c0936ec 100644
--- a/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_ExternalSpecifications.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.validator;
+package org.apache.myfaces.core.api.shared;
/**
* <p>
@@ -26,7 +26,7 @@
* </p>
* @since 2.0
*/
-final class _ExternalSpecifications
+public final class _ExternalSpecifications
{
private static volatile Boolean beanValidationAvailable;
@@ -59,7 +59,7 @@
// Trial-error approach to check for Bean Validation impl existence.
// If any Exception occurs here, we assume that Bean Validation is not available.
// The cause may be anything, i.e. NoClassDef, config error...
- _ValidationUtils.tryBuildDefaultValidatorFactory();
+ _BeanValidationUtils.tryBuildDefaultValidatorFactory();
}
catch (Throwable t)
{
diff --git a/impl/src/main/java/org/apache/myfaces/application/_LocaleUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_LocaleUtils.java
similarity index 98%
rename from impl/src/main/java/org/apache/myfaces/application/_LocaleUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_LocaleUtils.java
index afe8f60..3e25e65 100644
--- a/impl/src/main/java/org/apache/myfaces/application/_LocaleUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_LocaleUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.myfaces.application;
+package org.apache.myfaces.core.api.shared;
import java.util.ArrayList;
import java.util.Arrays;
@@ -40,7 +40,7 @@
* @since 2.2
* @version $Id$
*/
-class _LocaleUtils
+public class _LocaleUtils
{
/** Concurrent map of language locales by country. */
diff --git a/api/src/main/java/javax/faces/component/html/_MessageUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_MessageUtils.java
similarity index 83%
rename from api/src/main/java/javax/faces/component/html/_MessageUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_MessageUtils.java
index 17fff27..ab960fe 100755
--- a/api/src/main/java/javax/faces/component/html/_MessageUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_MessageUtils.java
@@ -16,22 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component.html;
+package org.apache.myfaces.core.api.shared;
-import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import javax.faces.component.UIComponent;
-class _MessageUtils
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+public class _MessageUtils
{
private static final String DETAIL_SUFFIX = "_detail";
- static void addErrorMessage(FacesContext facesContext,
+ public static void addErrorMessage(FacesContext facesContext,
UIComponent component,
String messageId)
{
@@ -43,7 +47,7 @@
null));
}
- static void addErrorMessage(FacesContext facesContext,
+ public static void addErrorMessage(FacesContext facesContext,
UIComponent component,
String messageId, Object[] args)
{
@@ -55,16 +59,26 @@
args));
}
- static void addErrorMessage(FacesContext facesContext,
+ public static void addErrorMessage(FacesContext facesContext,
UIComponent component, Throwable cause)
{
facesContext.addMessage(component.getClientId(facesContext),
new FacesMessage(FacesMessage.SEVERITY_ERROR, cause
.getLocalizedMessage(), cause.getLocalizedMessage()));
}
-
- static FacesMessage getMessage(FacesContext facesContext,
+ public static FacesMessage getErrorMessage(FacesContext facesContext,
+ String messageId,
+ Object args[])
+ {
+ return getMessage(facesContext,
+ facesContext.getViewRoot().getLocale(),
+ FacesMessage.SEVERITY_ERROR,
+ messageId,
+ args);
+ }
+
+ public static FacesMessage getMessage(FacesContext facesContext,
Locale locale,
FacesMessage.Severity severity,
String messageId,
@@ -75,6 +89,11 @@
String summary;
String detail;
+ if(locale == null)
+ {
+ locale = Locale.getDefault();
+ }
+
appBundle = getApplicationBundle(facesContext, locale);
summary = getBundleString(appBundle, messageId);
if (summary != null)
@@ -191,7 +210,6 @@
}
else
{
- //Next we try the JSF API class loader
return ResourceBundle.getBundle(bundleName,
locale,
_MessageUtils.class.getClassLoader(), bundleControl);
@@ -202,18 +220,29 @@
try
{
//Last resort is the context class loader
- if (bundleControl == null)
+ ClassLoader cl;
+ if (System.getSecurityManager() == null)
{
- return ResourceBundle.getBundle(bundleName,
- locale,
- _ClassUtils.getContextClassLoader());
+ cl = Thread.currentThread().getContextClassLoader();
}
else
{
- return ResourceBundle.getBundle(bundleName,
- locale,
- _ClassUtils.getContextClassLoader(), bundleControl);
+ cl = (ClassLoader) AccessController.doPrivileged(
+ (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
}
+
+ if (bundleControl == null)
+ {
+ return ResourceBundle.getBundle(bundleName, locale, cl);
+ }
+ else
+ {
+ return ResourceBundle.getBundle(bundleName, locale, cl, bundleControl);
+ }
+ }
+ catch(PrivilegedActionException pae)
+ {
+ throw new FacesException(pae);
}
catch (MissingResourceException damned)
{
@@ -224,7 +253,7 @@
}
}
- static Object getLabel(FacesContext facesContext, UIComponent component)
+ public static Object getLabel(FacesContext facesContext, UIComponent component)
{
Object label = component.getAttributes().get("label");
ValueExpression expression = null;
diff --git a/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_ParametrizableFacesMessage.java
similarity index 64%
rename from api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_ParametrizableFacesMessage.java
index bb1022b..4e06f77 100644
--- a/api/src/main/java/javax/faces/component/_ParametrizableFacesMessage.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_ParametrizableFacesMessage.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
import java.text.MessageFormat;
import java.util.Locale;
@@ -29,63 +29,59 @@
* This class encapsulates a FacesMessage to evaluate the label
* expression on render response, where f:loadBundle is available
*/
-class _ParametrizableFacesMessage extends FacesMessage
+public 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;
+ 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)
+ public _ParametrizableFacesMessage(String summary, String detail, Object[] args, Locale locale)
{
super(summary, detail);
- if(locale == null)
+ if (locale == null)
{
throw new NullPointerException("locale");
}
- _locale = locale;
- _args = args;
+ this.locale = locale;
+ this.args = args;
}
- public _ParametrizableFacesMessage(FacesMessage.Severity severity,
- String summary, String detail, Object[] args, Locale locale)
+ public _ParametrizableFacesMessage(FacesMessage.Severity severity, String summary, String detail, Object[] args,
+ Locale locale)
{
super(severity, summary, detail);
- if(locale == null)
+ if (locale == null)
{
throw new NullPointerException("locale");
}
- _locale = locale;
- _args = args;
+ this.locale = locale;
+ this.args = args;
}
@Override
public String getDetail()
{
- if (_evaluatedArgs == null && _args != null)
+ if (evaluatedArgs == null && args != null)
{
evaluateArgs();
}
- if (_evaluatedDetail == null)
+ if (evaluatedDetail == null)
{
- MessageFormat format = new MessageFormat(super.getDetail(), _locale);
- _evaluatedDetail = format.format(_evaluatedArgs);
+ MessageFormat format = new MessageFormat(super.getDetail(), locale);
+ evaluatedDetail = format.format(evaluatedArgs);
}
- return _evaluatedDetail;
+ return evaluatedDetail;
}
@Override
public void setDetail(String detail)
{
super.setDetail(detail);
- _evaluatedDetail = null;
+ evaluatedDetail = null;
}
public String getUnformattedDetail()
@@ -96,23 +92,23 @@
@Override
public String getSummary()
{
- if (_evaluatedArgs == null && _args != null)
+ if (evaluatedArgs == null && args != null)
{
evaluateArgs();
}
- if (_evaluatedSummary == null)
+ if (evaluatedSummary == null)
{
- MessageFormat format = new MessageFormat(super.getSummary(), _locale);
- _evaluatedSummary = format.format(_evaluatedArgs);
+ MessageFormat format = new MessageFormat(super.getSummary(), locale);
+ evaluatedSummary = format.format(evaluatedArgs);
}
- return _evaluatedSummary;
+ return evaluatedSummary;
}
@Override
public void setSummary(String summary)
{
super.setSummary(summary);
- _evaluatedSummary = null;
+ evaluatedSummary = null;
}
public String getUnformattedSummary()
@@ -122,25 +118,27 @@
private void evaluateArgs()
{
- _evaluatedArgs = new Object[_args.length];
FacesContext facesContext = null;
- for (int i = 0; i < _args.length; i++)
+
+ evaluatedArgs = new Object[args.length];
+ for (int i = 0; i < args.length; i++)
{
- if (_args[i] == null)
+ if (args[i] == null)
{
continue;
}
- else if (_args[i] instanceof ValueExpression)
+
+ if (args[i] instanceof ValueExpression)
{
if (facesContext == null)
{
facesContext = FacesContext.getCurrentInstance();
}
- _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
+ evaluatedArgs[i] = ((ValueExpression) args[i]).getValue(facesContext.getELContext());
}
else
{
- _evaluatedArgs[i] = _args[i];
+ evaluatedArgs[i] = args[i];
}
}
}
diff --git a/api/src/main/java/javax/faces/component/_SelectItemsIterator.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_SelectItemsIterator.java
similarity index 95%
rename from api/src/main/java/javax/faces/component/_SelectItemsIterator.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_SelectItemsIterator.java
index 4bebe5b..2dc6427 100644
--- a/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_SelectItemsIterator.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
import java.lang.reflect.Array;
import java.util.ArrayList;
@@ -30,6 +30,9 @@
import javax.el.ValueExpression;
import javax.faces.application.ProjectStage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
@@ -37,7 +40,7 @@
// This class is associated with org.apache.myfaces.util.SelectItemsIterator.
// Changes here should also be applied to this class.
-class _SelectItemsIterator implements Iterator<SelectItem>
+public class _SelectItemsIterator implements Iterator<SelectItem>
{
private static final Logger log = Logger.getLogger(_SelectItemsIterator.class.getName());
@@ -56,6 +59,7 @@
private SelectItem _nextItem;
private UIComponent _currentComponent;
private UISelectItems _currentUISelectItems;
+ private Object _currentValue;
private FacesContext _facesContext;
public _SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
@@ -66,8 +70,8 @@
_facesContext = facesContext;
}
- @Override
@SuppressWarnings("unchecked")
+ @Override
public boolean hasNext()
{
if (_nextItem != null)
@@ -82,6 +86,7 @@
}
_nestedItems = null;
_currentComponent = null;
+ _currentValue = null;
}
if (_children.hasNext())
{
@@ -131,10 +136,12 @@
ValueExpression expression = uiSelectItem.getValueExpression("value");
throw new IllegalArgumentException("ValueExpression '"
+ (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : "
- + _ComponentUtils.getPathToComponent(child) + " does not reference an Object of type SelectItem");
+ + _ComponentUtils.getPathToComponent(child)
+ + " does not reference an Object of type SelectItem");
}
_nextItem = (SelectItem) item;
_currentComponent = child;
+ _currentValue = item;
return true;
}
else if (child instanceof UISelectItems)
@@ -201,6 +208,7 @@
else
{
_currentComponent = null;
+ _currentValue = null;
}
}
return false;
@@ -229,6 +237,7 @@
// Note that according to the spec UISelectItems does not provide Getter and Setter
// methods for this values, so we have to use the attribute map
Map<String, Object> attributeMap = _currentUISelectItems.getAttributes();
+ _currentValue = item;
// write the current item into the request map under the key listed in var, if available
boolean wroteRequestMapVarValue = false;
@@ -310,6 +319,11 @@
{
return _currentComponent;
}
+
+ public Object getCurrentValue()
+ {
+ return _currentValue;
+ }
private boolean getBooleanAttribute(UIComponent component, String attrName, boolean defaultValue)
{
diff --git a/api/src/main/java/javax/faces/component/_SharedRendererUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/_SharedRendererUtils.java
similarity index 94%
rename from api/src/main/java/javax/faces/component/_SharedRendererUtils.java
rename to api/src/main/java/org/apache/myfaces/core/api/shared/_SharedRendererUtils.java
index a7a425a..6393cc9 100755
--- a/api/src/main/java/javax/faces/component/_SharedRendererUtils.java
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/_SharedRendererUtils.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package javax.faces.component;
+package org.apache.myfaces.core.api.shared;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
@@ -33,6 +33,8 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UISelectMany;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
@@ -44,12 +46,12 @@
* org.apache.myfaces.renderkit package. Please note: Any changes here must also apply to the class in the other
* package!
*/
-class _SharedRendererUtils
+public class _SharedRendererUtils
{
static final String COLLECTION_TYPE_KEY = "collectionType";
static final String VALUE_TYPE_KEY = "valueType";
- static Converter findUIOutputConverter(FacesContext facesContext, UIOutput component)
+ public static Converter findUIOutputConverter(FacesContext facesContext, UIOutput component)
{
// Attention!
// This code is duplicated in jsfapi component package.
@@ -90,7 +92,7 @@
}
}
- static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
+ public static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
String[] submittedValue) throws ConverterException
{
return getConvertedUISelectManyValue(facesContext, component, submittedValue, false);
@@ -108,7 +110,7 @@
* @return
* @throws ConverterException
*/
- static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
+ public static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
String[] submittedValue, boolean considerValueType) throws ConverterException
{
// Attention!
@@ -336,13 +338,9 @@
* @throws FacesException if the value is a String and the represented
* class cannot be found
*/
- static Class<?> getClassFromAttribute(FacesContext facesContext,
+ public static Class<?> getClassFromAttribute(FacesContext facesContext,
Object attribute) throws FacesException
{
- // Attention!
- // This code is duplicated in shared renderkit package.
- // If you change something here please do the same in the other class!
-
Class<?> type = null;
// if there is a value, it must be a ...
@@ -357,7 +355,7 @@
{
try
{
- type = Class.forName((String) attribute);
+ type = _ClassUtils.forName((String) attribute);
}
catch (ClassNotFoundException cnfe)
{
@@ -383,7 +381,7 @@
* @param component
* @return
*/
- static Converter getValueTypeConverter(FacesContext facesContext, UISelectMany component)
+ public static Converter getValueTypeConverter(FacesContext facesContext, UISelectMany component)
{
Converter converter = null;
@@ -409,10 +407,12 @@
if (converter == null)
{
- facesContext.getExternalContext().log("Found attribute valueType on component " +
+ log(facesContext,
+ "Found attribute valueType on component " +
_ComponentUtils.getPathToComponent(component) +
", but could not get a by-type converter for type " +
- valueType.getName());
+ valueType.getName(),
+ null);
}
}
@@ -426,7 +426,7 @@
* @param facesContext
* @return The first suitable Converter for the given SelectItems or null.
*/
- static Converter getSelectItemsValueConverter(Iterator<SelectItem> iterator, FacesContext facesContext)
+ public static Converter getSelectItemsValueConverter(Iterator<SelectItem> iterator, FacesContext facesContext)
{
// Attention!
// This code is duplicated in jsfapi component package.
diff --git a/api/src/main/resources/META-INF/componentClass20.vm b/api/src/main/resources/META-INF/componentClass20.vm
index 4a2b7fc..42e121d 100644
--- a/api/src/main/resources/META-INF/componentClass20.vm
+++ b/api/src/main/resources/META-INF/componentClass20.vm
@@ -36,6 +36,7 @@
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
import java.util.Collections;
+import org.apache.myfaces.core.api.shared._MessageUtils;
$utils.importTagClasses($component)
#if ($component.isTemplate())
diff --git a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
index 62f6440..d108e15 100644
--- a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
@@ -61,6 +61,7 @@
import javax.faces.application.ViewHandler;
import javax.faces.view.ViewDeclarationLanguage;
import org.apache.myfaces.config.MyfacesConfig;
+import org.apache.myfaces.core.api.shared._LocaleUtils;
import org.apache.myfaces.util.SharedStringBuilder;
import org.apache.myfaces.resource.ContractResource;
import org.apache.myfaces.resource.ContractResourceLoader;
diff --git a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
index 910cd6a..b1d0f51 100755
--- a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
+++ b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
@@ -896,8 +896,7 @@
{
try
{
- Class<Comparator<ELResolver>> clazz =
- (Class<Comparator<ELResolver>>) ClassUtils.classForName(elResolverComparatorClass);
+ Class<Comparator<ELResolver>> clazz = ClassUtils.classForName(elResolverComparatorClass);
Comparator<ELResolver> comparator = ClassUtils.newInstance(clazz);
runtimeConfig.setELResolverComparator(comparator);
}
diff --git a/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java b/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java
index 67293de..de85758 100644
--- a/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/config/LogMetaInfUtils.java
@@ -75,7 +75,7 @@
{
Map<String, List<JarInfo>> libs = new HashMap<>(30);
- Iterator<URL> it = ClassUtils.getResources("META-INF/MANIFEST.MF", LogMetaInfUtils.class);
+ Iterator<URL> it = ClassUtils.getResources("META-INF/MANIFEST.MF", LogMetaInfUtils.class).iterator();
while (it.hasNext())
{
URL url = it.next();
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java
index 895352a..2fd38f6 100755
--- a/impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java
@@ -48,10 +48,11 @@
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.model.SelectItem;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
+import org.apache.myfaces.core.api.shared._SharedRendererUtils;
import org.apache.myfaces.util.ComponentUtils;
import org.apache.myfaces.util.lang.HashMapUtils;
-import org.apache.myfaces.renderkit.html.util.SelectItemsIterator;
import org.apache.myfaces.renderkit.html.util.JSFAttr;
import org.apache.myfaces.util.lang.Assert;
@@ -442,7 +443,7 @@
if (considerValueType)
{
// try to get a converter from the valueType attribute
- converter = SharedRendererUtils.getValueTypeConverter(facesContext, component);
+ converter = _SharedRendererUtils.getValueTypeConverter(facesContext, component);
if (converter != null)
{
return converter;
@@ -472,8 +473,8 @@
if (Collection.class.isAssignableFrom(valueType) || Object.class.equals(valueType))
{
// try to get the by-type-converter from the type of the SelectItems
- return SharedRendererUtils.getSelectItemsValueConverter(
- new SelectItemsIterator(component, facesContext),
+ return _SharedRendererUtils.getSelectItemsValueConverter(
+ new _SelectItemsIterator(component, facesContext),
facesContext);
}
@@ -495,8 +496,8 @@
{
// There is no converter for Object class
// try to get the by-type-converter from the type of the SelectItems
- return SharedRendererUtils.getSelectItemsValueConverter(
- new SelectItemsIterator(component, facesContext),
+ return _SharedRendererUtils.getSelectItemsValueConverter(
+ new _SelectItemsIterator(component, facesContext),
facesContext);
}
@@ -586,9 +587,9 @@
private static List<SelectItem> internalGetSelectItemList(UIComponent uiComponent, FacesContext facesContext)
{
- List<SelectItem> list = new ArrayList<SelectItem>();
+ List<SelectItem> list = new ArrayList<>();
- for (SelectItemsIterator iter = new SelectItemsIterator(uiComponent, facesContext); iter.hasNext();)
+ for (_SelectItemsIterator iter = new _SelectItemsIterator(uiComponent, facesContext); iter.hasNext();)
{
list.add(iter.next());
}
@@ -848,7 +849,7 @@
+ ComponentUtils.getPathToComponent(selectMany) + "expected");
}
- return SharedRendererUtils.getConvertedUISelectManyValue(facesContext,
+ return _SharedRendererUtils.getConvertedUISelectManyValue(facesContext,
selectMany, (String[]) submittedValue, considerValueType);
}
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/SharedRendererUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/SharedRendererUtils.java
deleted file mode 100755
index 18ec48c..0000000
--- a/impl/src/main/java/org/apache/myfaces/renderkit/SharedRendererUtils.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * 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.renderkit;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.component.UISelectMany;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.model.SelectItem;
-import javax.faces.model.SelectItemGroup;
-import org.apache.myfaces.renderkit.html.util.SelectItemsIterator;
-
-import org.apache.myfaces.util.ComponentUtils;
-import org.apache.myfaces.util.lang.Assert;
-import org.apache.myfaces.util.lang.ClassUtils;
-
-/**
- * The util methods in this class are shared between the javax.faces.component package and
- * the org.apache.myfaces.renderkit package.
- * Please note: Any changes here must also apply to the class in the other package!
- */
-public class SharedRendererUtils
-{
- static final String COLLECTION_TYPE_KEY = "collectionType";
- static final String VALUE_TYPE_KEY = "valueType";
-
- static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
- String[] submittedValue) throws ConverterException
- {
- return getConvertedUISelectManyValue(facesContext, component,
- submittedValue, false);
- }
-
- /**
- * Gets the converted value of a UISelectMany component.
- * If the considerValueType is true, this method will also consider the
- * valueType attribute of Tomahawk UISelectMany components.
- *
- * @param facesContext
- * @param component
- * @param submittedValue
- * @param considerValueType
- * @return
- * @throws ConverterException
- */
- static Object getConvertedUISelectManyValue(FacesContext facesContext, UISelectMany component,
- String[] submittedValue, boolean considerValueType) throws ConverterException
- {
- // Attention!
- // This code is duplicated in jsfapi component package (except for considerValueType).
- // If you change something here please do the same in the other class!
-
- Assert.notNull(submittedValue, "submittedValue");
-
- ValueExpression expression = component.getValueExpression("value");
- Object targetForConvertedValues = null;
-
- // if the component has an attached converter, use it
- Converter converter = component.getConverter();
- if (converter == null && considerValueType)
- {
- // try to get a converter from the valueType attribute
- converter = getValueTypeConverter(facesContext, component);
- }
-
- if (expression != null)
- {
- Class<?> modelType = expression.getType(facesContext.getELContext());
- if (modelType == null)
- {
- // FIXME temporal workaround for MYFACES-2552
- return submittedValue;
- }
- else if (modelType.isArray())
- {
- // the target should be an array
- Class<?> componentType = modelType.getComponentType();
- // check for optimization if the target is
- // a string array --> no conversion needed
- if (String.class.equals(componentType))
- {
- return submittedValue;
- }
- if (converter == null)
- {
- // the compononent does not have an attached converter
- // --> try to get a registered-by-class converter
- converter = facesContext.getApplication().createConverter(componentType);
-
- if (converter == null)
- {
- // could not obtain a Converter
- // --> check if we maybe do not really have to convert
- if (!Object.class.equals(componentType))
- {
- // target is not an Object array
- // and not a String array (checked some lines above)
- // and we do not have a Converter
- throw new ConverterException("Could not obtain a Converter for "
- + componentType.getName());
- }
- }
- }
- // instantiate the array
- targetForConvertedValues = Array.newInstance(componentType,
- submittedValue.length);
- }
- else if (Collection.class.isAssignableFrom(modelType) || Object.class.equals(modelType))
- {
- if (converter == null)
- {
- // try to get the by-type-converter from the type of the SelectItems
- SelectItemsIterator iterator = new SelectItemsIterator(component, facesContext);
- converter = getSelectItemsValueConverter(iterator, facesContext);
- }
-
- Object collectionTypeAttr = component.getAttributes().get(COLLECTION_TYPE_KEY);
- if (collectionTypeAttr != null)
- {
- Class<?> collectionType = getClassFromAttribute(facesContext, collectionTypeAttr);
- if (collectionType == null)
- {
- throw new FacesException(
- "The attribute "
- + COLLECTION_TYPE_KEY
- + " of component "
- + component.getClientId(facesContext)
- + " does not evaluate to a "
- + "String, a Class object or a ValueExpression pointing "
- + "to a String or a Class object.");
- }
-
- // now we have a collectionType --> but is it really some kind of Collection
- if (!Collection.class.isAssignableFrom(collectionType))
- {
- throw new FacesException("The attribute "
- + COLLECTION_TYPE_KEY + " of component "
- + component.getClientId(facesContext)
- + " does not point to a valid type of Collection.");
- }
-
- // now we have a real collectionType --> try to instantiate it
- try
- {
- targetForConvertedValues = collectionType.newInstance();
- }
- catch (Exception e)
- {
- throw new FacesException("The Collection "
- + collectionType.getName()
- + "can not be instantiated.", e);
- }
- }
- else if (Collection.class.isAssignableFrom(modelType))
- {
- // component.getValue() will implement Collection at this point
- Collection<?> componentValue = (Collection<?>) component.getValue();
- // can we clone the Collection
- if (componentValue instanceof Cloneable)
- {
- // clone method of Object is protected --> use reflection
- try
- {
- Method cloneMethod = componentValue.getClass().getMethod("clone");
- Collection<?> clone = (Collection<?>) cloneMethod.invoke(componentValue);
- clone.clear();
- targetForConvertedValues = clone;
- }
- catch (Exception e)
- {
- log(facesContext, "Could not clone " + componentValue.getClass().getName(), e);
- }
- }
-
- // if clone did not work
- if (targetForConvertedValues == null)
- {
- // try to create the (concrete) collection from modelType
- // or with the class object of componentValue (if any)
- try
- {
- targetForConvertedValues = (componentValue != null
- ? componentValue.getClass()
- : modelType).newInstance();
- }
- catch (Exception e)
- {
- // this did not work either
- // use the standard concrete type
- if (SortedSet.class.isAssignableFrom(modelType))
- {
- targetForConvertedValues = new TreeSet();
- }
- else if (Queue.class.isAssignableFrom(modelType))
- {
- targetForConvertedValues = new LinkedList();
- }
- else if (Set.class.isAssignableFrom(modelType))
- {
- targetForConvertedValues = new HashSet(submittedValue.length);
- }
- else
- {
- targetForConvertedValues = new ArrayList(submittedValue.length);
- }
- }
- }
- }
- else /* if (Object.class.equals(modelType)) */
- {
- // a modelType of Object is also permitted, in order to support
- // managed bean properties of type Object
-
- // optimization: if we don't have a converter, we can return the submittedValue
- if (converter == null)
- {
- return submittedValue;
- }
-
- targetForConvertedValues = new Object[submittedValue.length];
- }
- }
- else
- {
- // the expression does neither point to an array nor to a collection
- throw new ConverterException(
- "ValueExpression for UISelectMany must be of type Collection or Array.");
- }
- }
- else
- {
- targetForConvertedValues = new Object[submittedValue.length];
- }
-
- // convert the values with the selected converter (if any)
- // and store them in targetForConvertedValues
- boolean isArray = (targetForConvertedValues.getClass().isArray());
- for (int i = 0; i < submittedValue.length; i++)
- {
- // get the value
- Object value;
- if (converter != null)
- {
- value = converter.getAsObject(facesContext, component, submittedValue[i]);
- }
- else
- {
- value = submittedValue[i];
- }
-
- // store it in targetForConvertedValues
- if (isArray)
- {
- Array.set(targetForConvertedValues, i, value);
- }
- else
- {
- ((Collection) targetForConvertedValues).add(value);
- }
- }
-
- return targetForConvertedValues;
- }
-
- /**
- * Gets a Class object from a given component attribute. The attribute can
- * be a ValueExpression (that evaluates to a String or a Class) or a
- * String (that is a fully qualified Java class name) or a Class object.
- *
- * @param facesContext
- * @param attribute
- * @return
- * @throws FacesException if the value is a String and the represented
- * class cannot be found
- */
- static Class<?> getClassFromAttribute(FacesContext facesContext,
- Object attribute) throws FacesException
- {
- // Attention!
- // This code is duplicated in jsfapi component package.
- // If you change something here please do the same in the other class!
-
- Class<?> type = null;
-
- // if there is a value, it must be a ...
- // ... a ValueExpression that evaluates to a String or a Class
- if (attribute instanceof ValueExpression)
- {
- // get the value of the ValueExpression
- attribute = ((ValueExpression) attribute).getValue(facesContext.getELContext());
- }
- // ... String that is a fully qualified Java class name
- if (attribute instanceof String)
- {
- try
- {
- type = ClassUtils.classForName((String) attribute);
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new FacesException("Unable to find class " + attribute + " on the classpath.", cnfe);
- }
-
- }
- // ... a Class object
- else if (attribute instanceof Class)
- {
- type = (Class<?>) attribute;
- }
-
- return type;
- }
-
- /**
- * Uses the valueType attribute of the given UISelectMany component to
- * get a by-type converter.
- *
- * @param facesContext
- * @param component
- * @return
- */
- static Converter getValueTypeConverter(FacesContext facesContext, UISelectMany component)
- {
- Converter converter = null;
-
- Object valueTypeAttr = component.getAttributes().get(VALUE_TYPE_KEY);
- if (valueTypeAttr != null)
- {
- // treat the valueType attribute exactly like the collectionType attribute
- Class<?> valueType = getClassFromAttribute(facesContext, valueTypeAttr);
- if (valueType == null)
- {
- throw new FacesException(
- "The attribute "
- + VALUE_TYPE_KEY
- + " of component "
- + component.getClientId(facesContext)
- + " does not evaluate to a "
- + "String, a Class object or a ValueExpression pointing "
- + "to a String or a Class object.");
- }
- // now we have a valid valueType
- // --> try to get a registered-by-class converter
- converter = facesContext.getApplication().createConverter(valueType);
-
- if (converter == null)
- {
- log.log(Level.WARNING, "Found attribute valueType on component " +
- ComponentUtils.getPathToComponent(component) +
- ", but could not get a by-type converter for type " +
- valueType.getName());
- }
- }
-
- return converter;
- }
-
- /**
- * Iterates through the SelectItems with the given Iterator and tries to obtain
- * a by-class-converter based on the Class of SelectItem.getValue().
- * @param iterator
- * @param facesContext
- * @return The first suitable Converter for the given SelectItems or null.
- */
- static Converter getSelectItemsValueConverter(Iterator<SelectItem> iterator, FacesContext facesContext)
- {
- // Attention!
- // This code is duplicated in jsfapi component package.
- // If you change something here please do the same in the other class!
-
- Converter converter = null;
- while (converter == null && iterator.hasNext())
- {
- SelectItem item = iterator.next();
- if (item instanceof SelectItemGroup)
- {
- Iterator<SelectItem> groupIterator = Arrays.asList(
- ((SelectItemGroup) item).getSelectItems()).iterator();
- converter = getSelectItemsValueConverter(groupIterator, facesContext);
- }
- else
- {
- Class<?> selectItemsType = item.getValue().getClass();
-
- // optimization: no conversion for String values
- if (String.class.equals(selectItemsType))
- {
- return null;
- }
-
- try
- {
- converter = facesContext.getApplication().createConverter(selectItemsType);
- }
- catch (FacesException e)
- {
- // nothing - try again
- }
- }
- }
- return converter;
- }
-
- private static final Logger log = Logger.getLogger(SharedRendererUtils.class.getName());
-
- /**
- * This method is different in the two versions of _SharedRendererUtils.
- */
- private static void log(FacesContext context, String msg, Exception e)
- {
- log.log(Level.SEVERE, msg, e);
- }
-}
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
deleted file mode 100644
index 1eb5b32..0000000
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsIterator.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * 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.renderkit.html.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.el.ValueExpression;
-import javax.faces.application.ProjectStage;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UISelectItem;
-import javax.faces.component.UISelectItems;
-import javax.faces.context.FacesContext;
-import javax.faces.model.SelectItem;
-
-import org.apache.myfaces.util.ComponentUtils;
-
-// ATTENTION
-// This class is associated with javax.faces.component._SelectItemsIterator.
-// Changes here should also be applied to this class.
-
-public class SelectItemsIterator implements Iterator<SelectItem>
-{
- private static final Logger log = Logger.getLogger(SelectItemsIterator.class.getName());
-
- private static final String VAR_PROP = JSFAttr.VAR_ATTR;
- private static final String ITEM_VALUE_PROP = JSFAttr.ITEM_VALUE_ATTR;
- private static final String ITEM_LABEL_PROP = JSFAttr.ITEM_LABEL_ATTR;
- private static final String ITEM_DESCRIPTION_PROP = JSFAttr.ITEM_DESCRIPTION_ATTR;
- private static final String ITEM_DISABLED_PROP = JSFAttr.ITEM_DISABLED_ATTR;
- private static final String ITEM_LABEL_ESCAPED_PROP = JSFAttr.ITEM_LABEL_ESCAPED_ATTR;
- private static final String NO_SELECTION_VALUE_PROP = JSFAttr.NO_SELECTION_VALUE_ATTR;
-
- private final Iterator<UIComponent> _children;
- private Iterator<? extends Object> _nestedItems;
- private SelectItem _nextItem;
- private UIComponent _currentComponent;
- private UISelectItems _currentUISelectItems;
- private Object _currentValue;
- private FacesContext _facesContext;
-
- public SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
- {
- _children = selectItemsParent.getChildCount() > 0
- ? selectItemsParent.getChildren().iterator()
- : Collections.<UIComponent>emptyIterator();
- _facesContext = facesContext;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public boolean hasNext()
- {
- if (_nextItem != null)
- {
- return true;
- }
- if (_nestedItems != null)
- {
- if (_nestedItems.hasNext())
- {
- return true;
- }
- _nestedItems = null;
- _currentComponent = null;
- _currentValue = null;
- }
- if (_children.hasNext())
- {
- UIComponent child = _children.next();
- // When there is other components nested that does
- // not extends from UISelectItem or UISelectItems
- // the behavior for this iterator is just skip this
- // element(s) until an element that extends from these
- // classes are found. If there is no more elements
- // that conform this condition, just return false.
- while (!(child instanceof UISelectItem) && !(child instanceof UISelectItems))
- {
- // Try to skip it
- if (_children.hasNext())
- {
- // Skip and do the same check
- child = _children.next();
- }
- else
- {
- // End loop, so the final result is return false,
- // since there are no more components to iterate.
- return false;
- }
- }
- if (child instanceof UISelectItem)
- {
- UISelectItem uiSelectItem = (UISelectItem) child;
- Object item = uiSelectItem.getValue();
- if (item == null)
- {
- // no value attribute --> create the SelectItem out of the other attributes
- Object itemValue = uiSelectItem.getItemValue();
- String label = uiSelectItem.getItemLabel();
- String description = uiSelectItem.getItemDescription();
- boolean disabled = uiSelectItem.isItemDisabled();
- boolean escape = uiSelectItem.isItemEscaped();
- boolean noSelectionOption = uiSelectItem.isNoSelectionOption();
- if (label == null && itemValue != null)
- {
- label = itemValue.toString();
- }
- item = new SelectItem(itemValue, label, description, disabled, escape, noSelectionOption);
- }
- else if (!(item instanceof SelectItem))
- {
- ValueExpression expression = uiSelectItem.getValueExpression("value");
- throw new IllegalArgumentException("ValueExpression '"
- + (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : "
- + ComponentUtils.getPathToComponent(child)
- + " does not reference an Object of type SelectItem");
- }
- _nextItem = (SelectItem) item;
- _currentComponent = child;
- _currentValue = item;
- return true;
- }
- else if (child instanceof UISelectItems)
- {
- _currentUISelectItems = ((UISelectItems) child);
- Object value = _currentUISelectItems.getValue();
- _currentComponent = child;
-
- if (value instanceof SelectItem)
- {
- _nextItem = (SelectItem) value;
- return true;
- }
- else if (value != null && value.getClass().isArray())
- {
- // value is any kind of array (primitive or non-primitive)
- // --> we have to use class Array to get the values
- final int length = Array.getLength(value);
- Collection<Object> items = new ArrayList<>(length);
- for (int i = 0; i < length; i++)
- {
- items.add(Array.get(value, i));
- }
- _nestedItems = items.iterator();
- return hasNext();
- }
- else if (value instanceof Iterable)
- {
- // value is Iterable --> Collection, DataModel,...
- _nestedItems = ((Iterable<?>) value).iterator();
- return hasNext();
- }
- else if (value instanceof Map)
- {
- Map<Object, Object> map = ((Map<Object, Object>) value);
- Collection<SelectItem> items = new ArrayList<>(map.size());
- for (Map.Entry<Object, Object> entry : map.entrySet())
- {
- items.add(new SelectItem(entry.getValue(), entry.getKey().toString()));
- }
-
- _nestedItems = items.iterator();
- return hasNext();
- }
- else
- {
- Level level = _facesContext.isProjectStage(ProjectStage.Production)
- ? Level.FINE
- : Level.WARNING;
- if (log.isLoggable(level))
- {
- ValueExpression expression = _currentUISelectItems.getValueExpression("value");
- log.log(level, "ValueExpression {0} of UISelectItems with component-path {1}"
- + " does not reference an Object of type SelectItem,"
- + " array, Iterable or Map, but of type: {2}",
- new Object[] {
- (expression == null ? null : expression.getExpressionString()),
- ComponentUtils.getPathToComponent(child),
- (value == null ? null : value.getClass().getName())
- });
- }
- }
- }
- else
- {
- _currentComponent = null;
- _currentValue = null;
- }
- }
- return false;
- }
-
- @Override
- public SelectItem next()
- {
- if (!hasNext())
- {
- throw new NoSuchElementException();
- }
- if (_nextItem != null)
- {
- SelectItem value = _nextItem;
- _nextItem = null;
- return value;
- }
- if (_nestedItems != null)
- {
- Object item = _nestedItems.next();
-
- if (!(item instanceof SelectItem))
- {
- // check new params of SelectItems (since 2.0): itemValue, itemLabel, itemDescription,...
- // Note that according to the spec UISelectItems does not provide Getter and Setter
- // methods for this values, so we have to use the attribute map
- Map<String, Object> attributeMap = _currentUISelectItems.getAttributes();
- _currentValue = item;
-
- // write the current item into the request map under the key listed in var, if available
- boolean wroteRequestMapVarValue = false;
- Object oldRequestMapVarValue = null;
- final String var = (String) attributeMap.get(VAR_PROP);
- if (var != null && !var.isEmpty())
- {
- // save the current value of the key listed in var from the request map
- oldRequestMapVarValue = _facesContext.getExternalContext().getRequestMap().put(var, item);
- wroteRequestMapVarValue = true;
- }
-
- // check the itemValue attribute
- Object itemValue = attributeMap.get(ITEM_VALUE_PROP);
- if (itemValue == null)
- {
- // the itemValue attribute was not provided
- // --> use the current item as the itemValue
- itemValue = item;
- }
-
- // Spec: When iterating over the select items, toString()
- // must be called on the string rendered attribute values
- Object itemLabel = attributeMap.get(ITEM_LABEL_PROP);
- if (itemLabel == null)
- {
- if (itemValue != null)
- {
- itemLabel = itemValue.toString();
- }
- }
- else
- {
- itemLabel = itemLabel.toString();
- }
- Object itemDescription = attributeMap.get(ITEM_DESCRIPTION_PROP);
- if (itemDescription != null)
- {
- itemDescription = itemDescription.toString();
- }
- Boolean itemDisabled = getBooleanAttribute(_currentUISelectItems, ITEM_DISABLED_PROP, false);
- Boolean itemLabelEscaped = getBooleanAttribute(_currentUISelectItems, ITEM_LABEL_ESCAPED_PROP, true);
- Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_PROP);
- item = new SelectItem(itemValue,
- (String) itemLabel,
- (String) itemDescription,
- itemDisabled,
- itemLabelEscaped,
- itemValue.equals(noSelectionValue));
-
- // remove the value with the key from var from the request map, if previously written
- if(wroteRequestMapVarValue)
- {
- // If there was a previous value stored with the key from var in the request map, restore it
- if (oldRequestMapVarValue != null)
- {
- _facesContext.getExternalContext().getRequestMap().put(var, oldRequestMapVarValue);
- }
- else
- {
- _facesContext.getExternalContext().getRequestMap().remove(var);
- }
- }
- }
- return (SelectItem) item;
- }
- throw new NoSuchElementException();
- }
-
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- public UIComponent getCurrentComponent()
- {
- return _currentComponent;
- }
-
- public Object getCurrentValue()
- {
- return _currentValue;
- }
-
- private boolean getBooleanAttribute(UIComponent component, String attrName, boolean defaultValue)
- {
- Object value = component.getAttributes().get(attrName);
- if (value == null)
- {
- return defaultValue;
- }
- else if (value instanceof Boolean)
- {
- return (Boolean) value;
- }
- else
- {
- // If the value is a String, parse the boolean.
- // This makes the following code work: <tag attribute="true" />,
- // otherwise you would have to write <tag attribute="#{true}" />.
- return Boolean.valueOf(value.toString());
- }
- }
-
-}
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsUtils.java
index 9702a49..c80e657 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/SelectItemsUtils.java
@@ -31,6 +31,7 @@
import javax.faces.convert.Converter;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
import org.apache.myfaces.renderkit.RendererUtils;
import static org.apache.myfaces.renderkit.html.util.HtmlRendererUtils.isHideNoSelectionOption;
@@ -43,9 +44,9 @@
public static List<SelectItemInfo> getSelectItemInfoList(UISelectMany uiSelectMany, FacesContext facesContext)
{
- List<SelectItemInfo> list = new ArrayList<SelectItemInfo>();
+ List<SelectItemInfo> list = new ArrayList<>();
- for (SelectItemsIterator iter = new SelectItemsIterator(uiSelectMany, facesContext); iter.hasNext();)
+ for (_SelectItemsIterator iter = new _SelectItemsIterator(uiSelectMany, facesContext); iter.hasNext();)
{
list.add(new SelectItemInfo(iter.next(), iter.getCurrentComponent(), iter.getCurrentValue()));
}
@@ -54,8 +55,8 @@
public static List<SelectItemInfo> getSelectItemInfoList(UISelectOne uiSelectOne, FacesContext facesContext)
{
- List<SelectItemInfo> list = new ArrayList<SelectItemInfo>();
- for (SelectItemsIterator iter = new SelectItemsIterator(uiSelectOne, facesContext); iter.hasNext();)
+ List<SelectItemInfo> list = new ArrayList<>();
+ for (_SelectItemsIterator iter = new _SelectItemsIterator(uiSelectOne, facesContext); iter.hasNext();)
{
list.add(new SelectItemInfo(iter.next(), iter.getCurrentComponent(), iter.getCurrentValue()));
}
@@ -81,7 +82,7 @@
writer.writeAttribute(HTML.LABEL_ATTR, selectItem.getLabel(), null);
SelectItem[] selectItems = ((SelectItemGroup) selectItem).getSelectItems();
- List<SelectItemInfo> selectItemsGroupList = new ArrayList<SelectItemInfo>(selectItems.length);
+ List<SelectItemInfo> selectItemsGroupList = new ArrayList<>(selectItems.length);
for (SelectItem item : selectItems)
{
selectItemsGroupList.add(new SelectItemInfo(item, null));
diff --git a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
index 87aeddc..4bbb9a0 100755
--- a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java
@@ -18,465 +18,21 @@
*/
package org.apache.myfaces.util.lang;
-import javax.el.ExpressionFactory;
import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.myfaces.core.api.shared._ClassUtils;
-public final class ClassUtils
+public final class ClassUtils extends _ClassUtils
{
//~ Static fields/initializers -----------------------------------------------------------------
private static final Logger log = Logger.getLogger(ClassUtils.class.getName());
- public static final Class BOOLEAN_ARRAY_CLASS = boolean[].class;
- public static final Class BYTE_ARRAY_CLASS = byte[].class;
- public static final Class CHAR_ARRAY_CLASS = char[].class;
- public static final Class SHORT_ARRAY_CLASS = short[].class;
- public static final Class INT_ARRAY_CLASS = int[].class;
- public static final Class LONG_ARRAY_CLASS = long[].class;
- public static final Class FLOAT_ARRAY_CLASS = float[].class;
- public static final Class DOUBLE_ARRAY_CLASS = double[].class;
- public static final Class OBJECT_ARRAY_CLASS = Object[].class;
- public static final Class BOOLEAN_OBJECT_ARRAY_CLASS = Boolean[].class;
- public static final Class BYTE_OBJECT_ARRAY_CLASS = Byte[].class;
- public static final Class CHARACTER_OBJECT_ARRAY_CLASS = Character[].class;
- public static final Class SHORT_OBJECT_ARRAY_CLASS = Short[].class;
- public static final Class INTEGER_OBJECT_ARRAY_CLASS = Integer[].class;
- public static final Class LONG_OBJECT_ARRAY_CLASS = Long[].class;
- public static final Class FLOAT_OBJECT_ARRAY_CLASS = Float[].class;
- public static final Class DOUBLE_OBJECT_ARRAY_CLASS = Double[].class;
- public static final Class STRING_OBJECT_ARRAY_CLASS = String[].class;
-
- protected static final String[] EMPTY_STRING = new String[0];
-
- protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean", "byte", "char", "double", "float",
- "int", "long", "short", "void" };
-
- protected static final Class<?>[] PRIMITIVES = new Class[] { Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE,
- Float.TYPE, Integer.TYPE, Long.TYPE, Short.TYPE,
- Void.TYPE };
-
- public static final Map COMMON_TYPES = new HashMap(64);
- static
- {
- COMMON_TYPES.put("byte", Byte.TYPE);
- COMMON_TYPES.put("char", Character.TYPE);
- COMMON_TYPES.put("double", Double.TYPE);
- COMMON_TYPES.put("float", Float.TYPE);
- COMMON_TYPES.put("int", Integer.TYPE);
- COMMON_TYPES.put("long", Long.TYPE);
- COMMON_TYPES.put("short", Short.TYPE);
- COMMON_TYPES.put("boolean", Boolean.TYPE);
- COMMON_TYPES.put("void", Void.TYPE);
- COMMON_TYPES.put("java.lang.Object", Object.class);
- COMMON_TYPES.put("java.lang.Boolean", Boolean.class);
- COMMON_TYPES.put("java.lang.Byte", Byte.class);
- COMMON_TYPES.put("java.lang.Character", Character.class);
- COMMON_TYPES.put("java.lang.Short", Short.class);
- COMMON_TYPES.put("java.lang.Integer", Integer.class);
- COMMON_TYPES.put("java.lang.Long", Long.class);
- COMMON_TYPES.put("java.lang.Float", Float.class);
- COMMON_TYPES.put("java.lang.Double", Double.class);
- COMMON_TYPES.put("java.lang.String", String.class);
-
- COMMON_TYPES.put("byte[]", BYTE_ARRAY_CLASS);
- COMMON_TYPES.put("char[]", CHAR_ARRAY_CLASS);
- COMMON_TYPES.put("double[]", DOUBLE_ARRAY_CLASS);
- COMMON_TYPES.put("float[]", FLOAT_ARRAY_CLASS);
- COMMON_TYPES.put("int[]", INT_ARRAY_CLASS);
- COMMON_TYPES.put("long[]", LONG_ARRAY_CLASS);
- COMMON_TYPES.put("short[]", SHORT_ARRAY_CLASS);
- COMMON_TYPES.put("boolean[]", BOOLEAN_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Object[]", OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Boolean[]", BOOLEAN_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Byte[]", BYTE_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Character[]", CHARACTER_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Short[]", SHORT_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Integer[]", INTEGER_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Long[]", LONG_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Float[]", FLOAT_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.Double[]", DOUBLE_OBJECT_ARRAY_CLASS);
- COMMON_TYPES.put("java.lang.String[]", STRING_OBJECT_ARRAY_CLASS);
- // array of void is not a valid type
- }
-
- /** utility class, do not instantiate */
- private ClassUtils()
- {
- // utility class, disable instantiation
- }
-
- //~ Methods ------------------------------------------------------------------------------------
-
- /**
- * Tries a Class.loadClass with the context class loader of the current thread first and
- * automatically falls back to the ClassUtils class loader (i.e. the loader of the
- * myfaces.jar lib) if necessary.
- *
- * @param type fully qualified name of a non-primitive non-array class
- * @return the corresponding Class
- * @throws NullPointerException if type is null
- * @throws ClassNotFoundException
- */
- public static Class classForName(String type) throws ClassNotFoundException
- {
- Assert.notNull(type, "type");
-
- try
- {
- // Try WebApp ClassLoader first
- return Class.forName(type,
- false, // do not initialize for faster startup
- getContextClassLoader());
- }
- catch (ClassNotFoundException ignore)
- {
- // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
- return Class.forName(type,
- false, // do not initialize for faster startup
- ClassUtils.class.getClassLoader());
- }
- }
-
- /**
- * Same as {@link #classForName(String)}, but throws a RuntimeException
- * (FacesException) instead of a ClassNotFoundException.
- *
- * @return the corresponding Class
- * @throws NullPointerException if type is null
- * @throws FacesException if class not found
- */
- public static Class simpleClassForName(String type)
- {
- return simpleClassForName(type, true);
- }
-
- /**
- * Same as {link {@link #simpleClassForName(String)}, but will only
- * log the exception and rethrow a RunTimeException if logException is true.
- *
- * @param type
- * @param logException - true to log/throw FacesException, false to avoid logging/throwing FacesException
- * @return the corresponding Class
- * @throws FacesException if class not found and logException is true
- */
- public static Class simpleClassForName(String type, boolean logException)
- {
- Class returnClass = null;
- try
- {
- returnClass = classForName(type);
- }
- catch (ClassNotFoundException e)
- {
- if (logException)
- {
- log.log(Level.SEVERE, "Class " + type + " not found", e);
- throw new FacesException(e);
- }
- }
- return returnClass;
- }
-
-
- /**
- * Similar as {@link #classForName(String)}, but also supports primitive types
- * and arrays as specified for the JavaType element in the JavaServer Faces Config DTD.
- *
- * @param type fully qualified class name or name of a primitive type, both optionally
- * followed by "[]" to indicate an array type
- * @return the corresponding Class
- * @throws NullPointerException if type is null
- * @throws ClassNotFoundException
- */
- public static Class javaTypeToClass(String type) throws ClassNotFoundException
- {
- Assert.notNull(type, "type");
-
- // try common types and arrays of common types first
- Class clazz = (Class) COMMON_TYPES.get(type);
- if (clazz != null)
- {
- return clazz;
- }
-
- int len = type.length();
- if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
- {
- String componentType = type.substring(0, len - 2);
- Class componentTypeClass = classForName(componentType);
- return Array.newInstance(componentTypeClass, 0).getClass();
- }
-
- return classForName(type);
-
- }
-
- /**
- * This method is similar to shared ClassUtils.javaTypeToClass,
- * but the default package for the type is java.lang
- *
- * @param type
- * @return
- * @throws ClassNotFoundException
- */
- public static Class javaDefaultTypeToClass(String type)
- throws ClassNotFoundException
- {
- Assert.notNull(type, "type");
-
- // try common types and arrays of common types first
- Class clazz = (Class) ClassUtils.COMMON_TYPES.get(type);
- if (clazz != null)
- {
- return clazz;
- }
-
- int len = type.length();
- if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
- {
- String componentType = type.substring(0, len - 2);
- Class componentTypeClass = ClassUtils.classForName(componentType);
- return Array.newInstance(componentTypeClass, 0).getClass();
- }
-
- if (type.indexOf('.') == -1)
- {
- type = "java.lang." + type;
- }
- return ClassUtils.classForName(type);
- }
-
- /**
- * Same as {@link #javaTypeToClass(String)}, but throws a RuntimeException
- * (FacesException) instead of a ClassNotFoundException.
- *
- * @return the corresponding Class
- * @throws NullPointerException if type is null
- * @throws FacesException if class not found
- */
- public static Class simpleJavaTypeToClass(String type)
- {
- try
- {
- return javaTypeToClass(type);
- }
- catch (ClassNotFoundException e)
- {
- log.log(Level.SEVERE, "Class " + type + " not found", e);
- throw new FacesException(e);
- }
- }
-
- public static URL getResource(String resource)
- {
- URL url = getContextClassLoader().getResource(resource);
- if (url == null)
- {
- url = ClassUtils.class.getClassLoader().getResource(resource);
- }
- return url;
- }
-
- public static InputStream getResourceAsStream(String resource)
- {
- InputStream stream = getContextClassLoader()
- .getResourceAsStream(resource);
- if (stream == null)
- {
- // fallback
- stream = ClassUtils.class.getClassLoader().getResourceAsStream(resource);
- }
- return stream;
- }
-
- /**
- * @param resource Name of resource(s) to find in classpath
- * @param defaultObject The default object to use to determine the class loader
- * (if none associated with current thread.)
- * @return Iterator over URL Objects
- */
- public static Iterator getResources(String resource, Object defaultObject)
- {
- try
- {
- Enumeration resources = getCurrentLoader(defaultObject).getResources(resource);
- List lst = new ArrayList();
- while (resources.hasMoreElements())
- {
- lst.add(resources.nextElement());
- }
- return lst.iterator();
- }
- catch (IOException e)
- {
- log.log(Level.SEVERE, e.getMessage(), e);
- throw new FacesException(e);
- }
- }
-
-
- public static Object newInstance(String type)
- throws FacesException
- {
- if (type == null)
- {
- return null;
- }
- return newInstance(simpleClassForName(type));
- }
-
- public static Object newInstance(String type, Class expectedType) throws FacesException
- {
- return newInstance(type, expectedType == null ? null : new Class[] {expectedType});
- }
-
- public static Object newInstance(String type, Class[] expectedTypes)
- {
- if (type == null)
- {
- return null;
- }
-
- Class clazzForName = simpleClassForName(type);
-
- if(expectedTypes != null)
- {
- for (int i = 0, size = expectedTypes.length; i < size; i++)
- {
- if (!expectedTypes[i].isAssignableFrom(clazzForName))
- {
- throw new FacesException('\'' + type + "' does not implement expected type '" + expectedTypes[i]
- + '\'');
- }
- }
- }
-
- return newInstance(clazzForName);
- }
-
- public static <T> T newInstance(Class<T> clazz)
- throws FacesException
- {
- try
- {
- return clazz.newInstance();
- }
- catch (NoClassDefFoundError | InstantiationException | IllegalAccessException e)
- {
- log.log(Level.SEVERE, e.getMessage(), e);
- throw new FacesException(e);
- }
- }
-
- public static <T> T newInstance(Class<T> clazz,
- Class<?>[] constructorArgClasses,
- Object... constructorArgs) throws NoSuchMethodException
- {
- if (constructorArgs.length == 0)
- {
- // no args given - use normal newInstance()
- return newInstance(clazz);
- }
-
- // try to get a fitting constructor (throws NoSuchMethodException)
- Constructor constructor = clazz.getConstructor(constructorArgClasses);
-
- try
- {
- // actually create instance
- return (T) constructor.newInstance(constructorArgs);
- }
- catch (Exception e)
- {
- throw new FacesException(e);
- }
- }
-
- public static Object convertToType(Object value, Class desiredClass)
- {
- if (value == null)
- {
- return null;
- }
-
- try
- {
- ExpressionFactory expFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
- return expFactory.coerceToType(value, desiredClass);
- }
- catch (Exception e)
- {
- String message = "Cannot coerce " + value.getClass().getName()
- + " to " + desiredClass.getName();
- log.log(Level.SEVERE, message, e);
- throw new FacesException(message, e);
- }
- }
-
- /**
- * Gets the ClassLoader associated with the current thread. Returns the class loader associated with
- * the specified default object if no context loader is associated with the current thread.
- *
- * @param defaultObject The default object to use to determine the class loader
- * (if none associated with current thread.)
- * @return ClassLoader
- */
- public static ClassLoader getCurrentLoader(Object defaultObject)
- {
- ClassLoader loader = getContextClassLoader();
- if (loader == null)
- {
- loader = defaultObject.getClass().getClassLoader();
- }
- return loader;
- }
-
- /**
- * Gets the ClassLoader associated with the current thread. Includes a check for priviledges
- * against java2 security to ensure no security related exceptions are encountered.
- *
- * @since 3.0.6
- * @return ClassLoader
- */
- public static ClassLoader getContextClassLoader()
- {
- if (System.getSecurityManager() != null)
- {
- try
- {
- return (ClassLoader) AccessController.doPrivileged(
- (PrivilegedExceptionAction) () -> Thread.currentThread().getContextClassLoader());
- }
- catch (PrivilegedActionException pae)
- {
- throw new FacesException(pae);
- }
- }
-
- return Thread.currentThread().getContextClassLoader();
- }
-
/**
* Creates ApplicationObjects like NavigationHandler or StateManager and creates
* the right wrapping chain of the ApplicationObjects known as the decorator pattern.
@@ -629,96 +185,7 @@
return current;
}
-
-
- public static Class<?> forName(String name) throws ClassNotFoundException
- {
- if (name == null || name.isEmpty())
- {
- return null;
- }
-
- Class<?> c = forNamePrimitive(name);
- if (c == null)
- {
- if (name.endsWith("[]"))
- {
- String nc = name.substring(0, name.length() - 2);
- //we should route through our shared forName, due to plugins and due to better classloader resolution
- c = ClassUtils.classForName(nc);
- //old code left for double checking
- //c = Class.forName(nc, false, ClassUtils.getContextClassLoader());
- c = Array.newInstance(c, 0).getClass();
- }
- else
- {
- c = ClassUtils.classForName(name);
- //old code left for double checking
- //c = Class.forName(name, false, ClassUtils.getContextClassLoader());
- }
- }
-
- return c;
- }
- protected static Class<?> forNamePrimitive(String name)
- {
- if (name.length() <= 8)
- {
- int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
- if (p >= 0)
- {
- return PRIMITIVES[p];
- }
- }
-
- return null;
- }
-
- /**
- * Converts an array of Class names to Class types
- *
- * @param s
- * @return
- * @throws ClassNotFoundException
- */
- public static Class<?>[] toTypeArray(String[] s) throws ClassNotFoundException
- {
- if (s == null)
- {
- return null;
- }
-
- Class<?>[] c = new Class[s.length];
- for (int i = 0; i < s.length; i++)
- {
- c[i] = forName(s[i]);
- }
-
- return c;
- }
-
- /**
- * Converts an array of Class types to Class names
- *
- * @param c
- * @return
- */
- public static String[] toTypeNameArray(Class<?>[] c)
- {
- if (c == null)
- {
- return null;
- }
-
- String[] s = new String[c.length];
- for (int i = 0; i < c.length; i++)
- {
- s[i] = c[i].getName();
- }
-
- return s;
- }
protected static final String paramString(Class<?>... types)
{
diff --git a/impl/src/test/java/javax/faces/component/UISelectItemsTest.java b/impl/src/test/java/javax/faces/component/UISelectItemsTest.java
index 20bcbba..06d4b42 100644
--- a/impl/src/test/java/javax/faces/component/UISelectItemsTest.java
+++ b/impl/src/test/java/javax/faces/component/UISelectItemsTest.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
import java.util.ArrayList;
import java.util.List;
diff --git a/impl/src/test/java/javax/faces/component/_ComponentUtilsTest.java b/impl/src/test/java/javax/faces/component/_ComponentUtilsTest.java
index dd83a99..5e437a5 100644
--- a/impl/src/test/java/javax/faces/component/_ComponentUtilsTest.java
+++ b/impl/src/test/java/javax/faces/component/_ComponentUtilsTest.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._ComponentUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
diff --git a/impl/src/test/java/javax/faces/component/_SelectItemsUtilTest.java b/impl/src/test/java/javax/faces/component/_SelectItemsUtilTest.java
index 6e36a75..b32506b 100644
--- a/impl/src/test/java/javax/faces/component/_SelectItemsUtilTest.java
+++ b/impl/src/test/java/javax/faces/component/_SelectItemsUtilTest.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SelectItemsIterator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
diff --git a/impl/src/test/java/javax/faces/component/_SharedRendererUtilsTest.java b/impl/src/test/java/javax/faces/component/_SharedRendererUtilsTest.java
index 9f391a5..bb62e47 100644
--- a/impl/src/test/java/javax/faces/component/_SharedRendererUtilsTest.java
+++ b/impl/src/test/java/javax/faces/component/_SharedRendererUtilsTest.java
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import org.apache.myfaces.core.api.shared._SharedRendererUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
diff --git a/impl/src/test/java/javax/faces/convert/MessageUtilsTest.java b/impl/src/test/java/javax/faces/convert/MessageUtilsTest.java
index 34876bc..4a10978 100644
--- a/impl/src/test/java/javax/faces/convert/MessageUtilsTest.java
+++ b/impl/src/test/java/javax/faces/convert/MessageUtilsTest.java
@@ -20,6 +20,7 @@
import javax.el.ValueExpression;
import javax.faces.component.html.HtmlInputText;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import org.apache.myfaces.test.base.AbstractJsfTestCase;
import org.apache.myfaces.test.el.MockValueExpression;
diff --git a/impl/src/test/java/javax/faces/validator/_MessageUtilsTest.java b/impl/src/test/java/javax/faces/validator/_MessageUtilsTest.java
index d9cb57c..29a8836 100644
--- a/impl/src/test/java/javax/faces/validator/_MessageUtilsTest.java
+++ b/impl/src/test/java/javax/faces/validator/_MessageUtilsTest.java
@@ -18,6 +18,7 @@
*/
package javax.faces.validator;
+import org.apache.myfaces.core.api.shared._MessageUtils;
import java.util.HashMap;
import static org.easymock.EasyMock.expect;