You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2011/10/20 12:49:36 UTC
svn commit: r1186730 [17/22] - in /myfaces/commons/branches/jsf_20: examples/
examples/myfaces-commons-examples/src/main/java/org/apache/myfaces/commons/examples/
examples/myfaces-commons-examples/src/main/java/org/apache/myfaces/commons/examples/acces...
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ArrayUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/AttachedDeltaWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/AttachedDeltaWrapper.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/AttachedDeltaWrapper.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/AttachedDeltaWrapper.java Thu Oct 20 10:49:18 2011
@@ -1,52 +1,52 @@
-/*
- * 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.commons.util;
-
-import java.io.Serializable;
-
-/**
- * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
- * @version $Revision: 788877 $ $Date: 2009-06-26 16:30:38 -0500 (vie, 26 jun 2009) $
- */
-public class AttachedDeltaWrapper implements Serializable
-{
- private static final long serialVersionUID = 4732389964367986402L;
-
- private Object _wrappedStateObject;
-
- /**
- * @param clazz
- * null means wrappedStateObject is a List of state objects
- * @param wrappedStateObject
- */
- public AttachedDeltaWrapper(Class<?> clazz, Object wrappedStateObject)
- {
- if (wrappedStateObject != null && !(wrappedStateObject instanceof Serializable))
- {
- throw new IllegalArgumentException("Attached state for Object of type " + clazz + " (Class "
- + wrappedStateObject.getClass().getName() + ") is not serializable");
- }
- _wrappedStateObject = wrappedStateObject;
- }
-
- public Object getWrappedStateObject()
- {
- return _wrappedStateObject;
- }
-}
+/*
+ * 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.commons.util;
+
+import java.io.Serializable;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 788877 $ $Date: 2009-06-26 16:30:38 -0500 (vie, 26 jun 2009) $
+ */
+public class AttachedDeltaWrapper implements Serializable
+{
+ private static final long serialVersionUID = 4732389964367986402L;
+
+ private Object _wrappedStateObject;
+
+ /**
+ * @param clazz
+ * null means wrappedStateObject is a List of state objects
+ * @param wrappedStateObject
+ */
+ public AttachedDeltaWrapper(Class<?> clazz, Object wrappedStateObject)
+ {
+ if (wrappedStateObject != null && !(wrappedStateObject instanceof Serializable))
+ {
+ throw new IllegalArgumentException("Attached state for Object of type " + clazz + " (Class "
+ + wrappedStateObject.getClass().getName() + ") is not serializable");
+ }
+ _wrappedStateObject = wrappedStateObject;
+ }
+
+ public Object getWrappedStateObject()
+ {
+ return _wrappedStateObject;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/AttachedDeltaWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ComponentUtils.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ComponentUtils.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ComponentUtils.java Thu Oct 20 10:49:18 2011
@@ -1,77 +1,77 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.myfaces.commons.util;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-
-/**
- *
- * @since 1.0.2
- */
-public class ComponentUtils
-{
-
- /**
- * Return the parent NamingContainer of the component passed as argument.
- *
- * @param component
- * @return
- */
- public static UIComponent findParentNamingContainer(UIComponent component)
- {
- return findParentNamingContainer(component, true);
- }
-
- /**
- * Return the parent NamingContainer of the component passed as argument.
- *
- * @param component
- * @param returnRootIfNotFound
- * @return
- */
- public static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
- {
- UIComponent parent = component.getParent();
- if (returnRootIfNotFound && parent == null)
- {
- return component;
- }
- while (parent != null)
- {
- if (parent instanceof NamingContainer)
- return parent;
- if (returnRootIfNotFound)
- {
- UIComponent nextParent = parent.getParent();
- if (nextParent == null)
- {
- return parent; // Root
- }
- parent = nextParent;
- }
- else
- {
- parent = parent.getParent();
- }
- }
- return null;
- }
-}
+/*
+ * 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.commons.util;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+
+/**
+ *
+ * @since 1.0.2
+ */
+public class ComponentUtils
+{
+
+ /**
+ * Return the parent NamingContainer of the component passed as argument.
+ *
+ * @param component
+ * @return
+ */
+ public static UIComponent findParentNamingContainer(UIComponent component)
+ {
+ return findParentNamingContainer(component, true);
+ }
+
+ /**
+ * Return the parent NamingContainer of the component passed as argument.
+ *
+ * @param component
+ * @param returnRootIfNotFound
+ * @return
+ */
+ public static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
+ {
+ UIComponent parent = component.getParent();
+ if (returnRootIfNotFound && parent == null)
+ {
+ return component;
+ }
+ while (parent != null)
+ {
+ if (parent instanceof NamingContainer)
+ return parent;
+ if (returnRootIfNotFound)
+ {
+ UIComponent nextParent = parent.getParent();
+ if (nextParent == null)
+ {
+ return parent; // Root
+ }
+ parent = nextParent;
+ }
+ else
+ {
+ parent = parent.getParent();
+ }
+ }
+ return null;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ComponentUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/DebugUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/DebugUtils.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/DebugUtils.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/DebugUtils.java Thu Oct 20 10:49:18 2011
@@ -1,83 +1,83 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.util;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-
-/**
- *
- * @author Leonardo Uribe
- * @since 1.0.2
- *
- */
-public class DebugUtils
-{
- /**
- * Provide debug information about the path of a component
- *
- * @param component
- * @return
- */
- public static String getPathToComponent(UIComponent component)
- {
- StringBuffer buf = new StringBuffer();
-
- if(component == null)
- {
- buf.append("{Component-Path : ");
- buf.append("[null]}");
- return buf.toString();
- }
-
- getPathToComponent(component,buf);
-
- buf.insert(0,"{Component-Path : ");
- buf.append("}");
-
- return buf.toString();
- }
-
- private static void getPathToComponent(UIComponent component, StringBuffer buf)
- {
- if(component == null)
- return;
-
- StringBuffer intBuf = new StringBuffer();
-
- intBuf.append("[Class: ");
- intBuf.append(component.getClass().getName());
- if(component instanceof UIViewRoot)
- {
- intBuf.append(",ViewId: ");
- intBuf.append(((UIViewRoot) component).getViewId());
- }
- else
- {
- intBuf.append(",Id: ");
- intBuf.append(component.getId());
- }
- intBuf.append("]");
-
- buf.insert(0,intBuf.toString());
-
- getPathToComponent(component.getParent(), buf);
- }
-
-}
+/*
+ * 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.commons.util;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+
+/**
+ *
+ * @author Leonardo Uribe
+ * @since 1.0.2
+ *
+ */
+public class DebugUtils
+{
+ /**
+ * Provide debug information about the path of a component
+ *
+ * @param component
+ * @return
+ */
+ public static String getPathToComponent(UIComponent component)
+ {
+ StringBuffer buf = new StringBuffer();
+
+ if(component == null)
+ {
+ buf.append("{Component-Path : ");
+ buf.append("[null]}");
+ return buf.toString();
+ }
+
+ getPathToComponent(component,buf);
+
+ buf.insert(0,"{Component-Path : ");
+ buf.append("}");
+
+ return buf.toString();
+ }
+
+ private static void getPathToComponent(UIComponent component, StringBuffer buf)
+ {
+ if(component == null)
+ return;
+
+ StringBuffer intBuf = new StringBuffer();
+
+ intBuf.append("[Class: ");
+ intBuf.append(component.getClass().getName());
+ if(component instanceof UIViewRoot)
+ {
+ intBuf.append(",ViewId: ");
+ intBuf.append(((UIViewRoot) component).getViewId());
+ }
+ else
+ {
+ intBuf.append(",Id: ");
+ intBuf.append(component.getId());
+ }
+ intBuf.append("]");
+
+ buf.insert(0,intBuf.toString());
+
+ getPathToComponent(component.getParent(), buf);
+ }
+
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/DebugUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/LocaleUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/LocaleUtils.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/LocaleUtils.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/LocaleUtils.java Thu Oct 20 10:49:18 2011
@@ -1,140 +1,140 @@
-/*
- * 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.commons.util;
-
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * @since 1.0.1
- * @author Anton Koinov (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public final class LocaleUtils
-{
- private static final Log log = LogFactory.getLog(LocaleUtils.class);
-
- /** Utility class, do not instatiate */
- private LocaleUtils()
- {
- // utility class, do not instantiate
- }
-
- /**
- * Converts a locale string to <code>Locale</code> class. Accepts both
- * '_' and '-' as separators for locale components.
- *
- * @param localeString string representation of a locale
- * @return Locale instance, compatible with the string representation
- */
- public static Locale toLocale(String localeString)
- {
- if ((localeString == null) || (localeString.length() == 0))
- {
- Locale locale = Locale.getDefault();
- if(log.isWarnEnabled())
- log.warn("Locale name in faces-config.xml null or empty, setting locale to default locale : "+locale.toString());
- return locale;
- }
-
- int separatorCountry = localeString.indexOf('_');
- char separator;
- if (separatorCountry >= 0) {
- separator = '_';
- }
- else
- {
- separatorCountry = localeString.indexOf('-');
- separator = '-';
- }
-
- String language, country, variant;
- if (separatorCountry < 0)
- {
- language = localeString;
- country = variant = "";
- }
- else
- {
- language = localeString.substring(0, separatorCountry);
-
- int separatorVariant = localeString.indexOf(separator, separatorCountry + 1);
- if (separatorVariant < 0)
- {
- country = localeString.substring(separatorCountry + 1);
- variant = "";
- }
- else
- {
- country = localeString.substring(separatorCountry + 1, separatorVariant);
- variant = localeString.substring(separatorVariant + 1);
- }
- }
-
- return new Locale(language, country, variant);
- }
-
-
- /**
- * Convert locale string used by converter tags to locale.
- *
- * @param name name of the locale
- * @return locale specified by the given String
- */
- public static Locale converterTagLocaleFromString(String name)
- {
- try
- {
- Locale locale;
- StringTokenizer st = new StringTokenizer(name, "_");
- String language = st.nextToken();
-
- if(st.hasMoreTokens())
- {
- String country = st.nextToken();
-
- if(st.hasMoreTokens())
- {
- String variant = st.nextToken();
- locale = new Locale(language, country, variant);
- }
- else
- {
- locale = new Locale(language, country);
- }
- }
- else
- {
- locale = new Locale(language);
- }
-
-
- return locale;
- }
- catch(Exception e)
- {
- throw new IllegalArgumentException("Locale parsing exception - " +
- "invalid string representation '" + name + "'");
- }
- }
-}
+/*
+ * 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.commons.util;
+
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * @since 1.0.1
+ * @author Anton Koinov (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public final class LocaleUtils
+{
+ private static final Log log = LogFactory.getLog(LocaleUtils.class);
+
+ /** Utility class, do not instatiate */
+ private LocaleUtils()
+ {
+ // utility class, do not instantiate
+ }
+
+ /**
+ * Converts a locale string to <code>Locale</code> class. Accepts both
+ * '_' and '-' as separators for locale components.
+ *
+ * @param localeString string representation of a locale
+ * @return Locale instance, compatible with the string representation
+ */
+ public static Locale toLocale(String localeString)
+ {
+ if ((localeString == null) || (localeString.length() == 0))
+ {
+ Locale locale = Locale.getDefault();
+ if(log.isWarnEnabled())
+ log.warn("Locale name in faces-config.xml null or empty, setting locale to default locale : "+locale.toString());
+ return locale;
+ }
+
+ int separatorCountry = localeString.indexOf('_');
+ char separator;
+ if (separatorCountry >= 0) {
+ separator = '_';
+ }
+ else
+ {
+ separatorCountry = localeString.indexOf('-');
+ separator = '-';
+ }
+
+ String language, country, variant;
+ if (separatorCountry < 0)
+ {
+ language = localeString;
+ country = variant = "";
+ }
+ else
+ {
+ language = localeString.substring(0, separatorCountry);
+
+ int separatorVariant = localeString.indexOf(separator, separatorCountry + 1);
+ if (separatorVariant < 0)
+ {
+ country = localeString.substring(separatorCountry + 1);
+ variant = "";
+ }
+ else
+ {
+ country = localeString.substring(separatorCountry + 1, separatorVariant);
+ variant = localeString.substring(separatorVariant + 1);
+ }
+ }
+
+ return new Locale(language, country, variant);
+ }
+
+
+ /**
+ * Convert locale string used by converter tags to locale.
+ *
+ * @param name name of the locale
+ * @return locale specified by the given String
+ */
+ public static Locale converterTagLocaleFromString(String name)
+ {
+ try
+ {
+ Locale locale;
+ StringTokenizer st = new StringTokenizer(name, "_");
+ String language = st.nextToken();
+
+ if(st.hasMoreTokens())
+ {
+ String country = st.nextToken();
+
+ if(st.hasMoreTokens())
+ {
+ String variant = st.nextToken();
+ locale = new Locale(language, country, variant);
+ }
+ else
+ {
+ locale = new Locale(language, country);
+ }
+ }
+ else
+ {
+ locale = new Locale(language);
+ }
+
+
+ return locale;
+ }
+ catch(Exception e)
+ {
+ throw new IllegalArgumentException("Locale parsing exception - " +
+ "invalid string representation '" + name + "'");
+ }
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/LocaleUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ParametrizableFacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ParametrizableFacesMessage.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ParametrizableFacesMessage.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ParametrizableFacesMessage.java Thu Oct 20 10:49:18 2011
@@ -1,153 +1,153 @@
-/*
- * 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.commons.util;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-
-import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-
-/**
- * This class encapsulates a FacesMessage to evaluate the label
- * expression on render response, where f:loadBundle is available
- *
- * @author Leonardo Uribe (latest modification by $Author: skitching $)
- * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
- */
-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;
-
- 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 ValueBinding)
- {
- if (facesContext == null)
- {
- facesContext = FacesContext.getCurrentInstance();
- }
- _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
- }
- 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];
- }
- }
- }
-}
+/*
+ * 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.commons.util;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+
+import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * This class encapsulates a FacesMessage to evaluate the label
+ * expression on render response, where f:loadBundle is available
+ *
+ * @author Leonardo Uribe (latest modification by $Author: skitching $)
+ * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Dom, 13 Jul 2008) $
+ */
+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;
+
+ 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 ValueBinding)
+ {
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
+ }
+ 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];
+ }
+ }
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/ParametrizableFacesMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/RendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/RendererUtils.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/RendererUtils.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/RendererUtils.java Thu Oct 20 10:49:18 2011
@@ -1,69 +1,69 @@
-/*
- * 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.commons.util;
-
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-/**
- *
- * @author Leonardo Uribe
- * @since 1.0.1
- */
-public class RendererUtils
-{
-
- public static void renderChildren(FacesContext facesContext, UIComponent component)
- throws IOException
- {
- if (component.getChildCount() > 0)
- {
- for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
- {
- UIComponent child = (UIComponent)it.next();
- renderChild(facesContext, child);
- }
- }
- }
-
-
- public static void renderChild(FacesContext facesContext, UIComponent child)
- throws IOException
- {
- if (!child.isRendered())
- {
- return;
- }
-
- child.encodeBegin(facesContext);
- if (child.getRendersChildren())
- {
- child.encodeChildren(facesContext);
- }
- else
- {
- renderChildren(facesContext, child);
- }
- child.encodeEnd(facesContext);
- }
-
-}
+/*
+ * 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.commons.util;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * @author Leonardo Uribe
+ * @since 1.0.1
+ */
+public class RendererUtils
+{
+
+ public static void renderChildren(FacesContext facesContext, UIComponent component)
+ throws IOException
+ {
+ if (component.getChildCount() > 0)
+ {
+ for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
+ {
+ UIComponent child = (UIComponent)it.next();
+ renderChild(facesContext, child);
+ }
+ }
+ }
+
+
+ public static void renderChild(FacesContext facesContext, UIComponent child)
+ throws IOException
+ {
+ if (!child.isRendered())
+ {
+ return;
+ }
+
+ child.encodeBegin(facesContext);
+ if (child.getRendersChildren())
+ {
+ child.encodeChildren(facesContext);
+ }
+ else
+ {
+ renderChildren(facesContext, child);
+ }
+ child.encodeEnd(facesContext);
+ }
+
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/RendererUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/SelectItemsIterator.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/SelectItemsIterator.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/SelectItemsIterator.java Thu Oct 20 10:49:18 2011
@@ -1,325 +1,325 @@
-/*
- * 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.commons.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Collection;
-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.commons.util.renderkit.JsfProperties;
-
-// ATTENTION
-// This class is associated with javax.faces.component._SelectItemsIterator.
-// Changes here should also be applied to this class.
-
-/**
- * @author Mathias Broekelmann (latest modification by $Author$)
- * @author Jakob Korherr (jsf 2.0)
- * @version $Revision$ $Date$
- */
-public class SelectItemsIterator implements Iterator<SelectItem>
-{
- private static final Logger log = Logger.getLogger(SelectItemsIterator.class.getName());
-
- private static final String VAR_PROP = JsfProperties.VAR_PROP;
- private static final String ITEM_VALUE_PROP = JsfProperties.ITEM_VALUE_PROP;
- private static final String ITEM_LABEL_PROP = JsfProperties.ITEM_LABEL_PROP;
- private static final String ITEM_DESCRIPTION_PROP = JsfProperties.ITEM_DESCRIPTION_PROP;
- private static final String ITEM_DISABLED_PROP = JsfProperties.ITEM_DISABLED_PROP;
- private static final String ITEM_LABEL_ESCAPED_PROP = JsfProperties.ITEM_LABEL_ESCAPED_PROP;
- private static final String NO_SELECTION_VALUE_PROP = JsfProperties.NO_SELECTION_VALUE_PROP;
-
- private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = new _EmptyIterator<UIComponent>();
-
- private final Iterator<UIComponent> _children;
- private Iterator<? extends Object> _nestedItems;
- private SelectItem _nextItem;
- private UISelectItems _currentUISelectItems;
- private FacesContext _facesContext;
-
- public SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
- {
- _children = selectItemsParent.getChildCount() > 0 ? selectItemsParent.getChildren().iterator() : _EMPTY_UICOMPONENT_ITERATOR;
- _facesContext = facesContext;
- }
-
- @SuppressWarnings("unchecked")
- public boolean hasNext()
- {
- if (_nextItem != null)
- {
- return true;
- }
- if (_nestedItems != null)
- {
- if (_nestedItems.hasNext())
- {
- return true;
- }
- _nestedItems = 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)
- {
- 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 : "
- + DebugUtils.getPathToComponent(child) + " does not reference an Object of type SelectItem");
- }
- _nextItem = (SelectItem) item;
- return true;
- }
- else if (child instanceof UISelectItems)
- {
- _currentUISelectItems = ((UISelectItems) child);
- Object value = _currentUISelectItems.getValue();
-
- 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<Object>(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<SelectItem>(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 = Level.FINE;
- if (!_facesContext.isProjectStage(ProjectStage.Production))
- {
- level = 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()),
- DebugUtils.getPathToComponent(child),
- (value == null ? null : value.getClass().getName())
- });
- }
- }
- }
- }
- return false;
- }
-
- 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();
-
- // 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 && !"".equals(var))
- {
- // 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)
- {
- 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();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- 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());
- }
- }
-
-}
+/*
+ * 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.commons.util;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+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.commons.util.renderkit.JsfProperties;
+
+// ATTENTION
+// This class is associated with javax.faces.component._SelectItemsIterator.
+// Changes here should also be applied to this class.
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @author Jakob Korherr (jsf 2.0)
+ * @version $Revision$ $Date$
+ */
+public class SelectItemsIterator implements Iterator<SelectItem>
+{
+ private static final Logger log = Logger.getLogger(SelectItemsIterator.class.getName());
+
+ private static final String VAR_PROP = JsfProperties.VAR_PROP;
+ private static final String ITEM_VALUE_PROP = JsfProperties.ITEM_VALUE_PROP;
+ private static final String ITEM_LABEL_PROP = JsfProperties.ITEM_LABEL_PROP;
+ private static final String ITEM_DESCRIPTION_PROP = JsfProperties.ITEM_DESCRIPTION_PROP;
+ private static final String ITEM_DISABLED_PROP = JsfProperties.ITEM_DISABLED_PROP;
+ private static final String ITEM_LABEL_ESCAPED_PROP = JsfProperties.ITEM_LABEL_ESCAPED_PROP;
+ private static final String NO_SELECTION_VALUE_PROP = JsfProperties.NO_SELECTION_VALUE_PROP;
+
+ private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = new _EmptyIterator<UIComponent>();
+
+ private final Iterator<UIComponent> _children;
+ private Iterator<? extends Object> _nestedItems;
+ private SelectItem _nextItem;
+ private UISelectItems _currentUISelectItems;
+ private FacesContext _facesContext;
+
+ public SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
+ {
+ _children = selectItemsParent.getChildCount() > 0 ? selectItemsParent.getChildren().iterator() : _EMPTY_UICOMPONENT_ITERATOR;
+ _facesContext = facesContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean hasNext()
+ {
+ if (_nextItem != null)
+ {
+ return true;
+ }
+ if (_nestedItems != null)
+ {
+ if (_nestedItems.hasNext())
+ {
+ return true;
+ }
+ _nestedItems = 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)
+ {
+ 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 : "
+ + DebugUtils.getPathToComponent(child) + " does not reference an Object of type SelectItem");
+ }
+ _nextItem = (SelectItem) item;
+ return true;
+ }
+ else if (child instanceof UISelectItems)
+ {
+ _currentUISelectItems = ((UISelectItems) child);
+ Object value = _currentUISelectItems.getValue();
+
+ 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<Object>(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<SelectItem>(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 = Level.FINE;
+ if (!_facesContext.isProjectStage(ProjectStage.Production))
+ {
+ level = 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()),
+ DebugUtils.getPathToComponent(child),
+ (value == null ? null : value.getClass().getName())
+ });
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ 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();
+
+ // 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 && !"".equals(var))
+ {
+ // 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)
+ {
+ 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();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ 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());
+ }
+ }
+
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/SelectItemsIterator.java
------------------------------------------------------------------------------
svn:eol-style = native