You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/10/31 20:20:53 UTC
svn commit: r709540 - in
/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified:
./ resolver/ resolver/implicitobject/
Author: lu4242
Date: Fri Oct 31 12:20:53 2008
New Revision: 709540
URL: http://svn.apache.org/viewvc?rev=709540&view=rev
Log:
MYFACES-2028 Implement Resource EL Resolver
Added:
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java (with props)
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java (with props)
Modified:
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ImplicitObjectResolver.java
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java?rev=709540&r1=709539&r2=709540&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java Fri Oct 31 12:20:53 2008
@@ -23,6 +23,7 @@
import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceResolver;
import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
@@ -59,6 +60,7 @@
elResolver.add(new ArrayELResolver());
elResolver.add(new BeanELResolver());
elResolver.add(new ScopedAttributeResolver());
+ elResolver.add(new ResourceResolver());
}
}
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java?rev=709540&r1=709539&r2=709540&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java Fri Oct 31 12:20:53 2008
@@ -18,13 +18,14 @@
*/
package org.apache.myfaces.el.unified;
+import javax.el.CompositeELResolver;
+
import org.apache.myfaces.config.RuntimeConfig;
import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceResolver;
import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
-import javax.el.CompositeELResolver;
-
/**
* build the el resolver for jsp. see 1.2 spec section 5.6.1
*
@@ -44,6 +45,7 @@
elResolver.add(ImplicitObjectResolver.makeResolverForJSP());
elResolver.add(new ManagedBeanResolver());
elResolver.add(new ResourceBundleResolver());
+ elResolver.add(new ResourceResolver());
addFromRuntimeConfig(elResolver);
}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java?rev=709540&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java Fri Oct 31 12:20:53 2008
@@ -0,0 +1,121 @@
+/*
+ * 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.el.unified.resolver;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+
+/**
+ * See JSF 2.0 spec section 5.6.1.3 and 5.6.2.4
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public final class ResourceResolver extends ELResolver
+{
+
+ /** Creates a new instance of ResourceBundleResolver */
+ public ResourceResolver()
+ {
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(final ELContext context,
+ final Object base)
+ {
+ return base == null ? Object.class : null;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(
+ final ELContext context, final Object base)
+ {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(final ELContext context, final Object base,
+ final Object property)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getValue(final ELContext context, final Object base,
+ final Object property)
+ {
+ if (base != null && property != null && base instanceof ResourceHandler)
+ {
+ String reference = (String) property;
+ int colonIndex = (reference).indexOf(':');
+ Resource resource = null;
+ if (colonIndex < 0)
+ {
+ if (reference.indexOf(':', colonIndex + 1) < 0
+ && colonIndex != 0
+ && colonIndex + 1 < reference.length())
+ {
+ resource = ((ResourceHandler) base).createResource(
+ reference.substring(0, colonIndex - 1), reference
+ .substring(colonIndex + 1));
+ }
+ else
+ {
+ throw new ELException(
+ "Malformed resource reference found when resolving "
+ + property);
+ }
+ }
+ else
+ {
+ resource = ((ResourceHandler) base).createResource(reference);
+ context.setPropertyResolved(true);
+ return resource.getRequestPath();
+ }
+ if (resource != null)
+ {
+ context.setPropertyResolved(true);
+ return resource.getRequestPath();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(final ELContext context, final Object base,
+ final Object property)
+ {
+ //Return false on all cases
+ return false;
+ }
+
+ @Override
+ public void setValue(final ELContext context, final Object base,
+ final Object property, final Object val)
+ {
+ //No action takes place
+ }
+
+}
Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/ResourceResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ImplicitObjectResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ImplicitObjectResolver.java?rev=709540&r1=709539&r2=709540&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ImplicitObjectResolver.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ImplicitObjectResolver.java Fri Oct 31 12:20:53 2008
@@ -83,7 +83,9 @@
ImplicitObject io14 = new ViewImplicitObject();
forFacesList.put(io14.getName(), io14);
ImplicitObject io15 = new ComponentImplicitObject();
- forFacesList.put(io15.getName(), io15);
+ forFacesList.put(io15.getName(), io15);
+ ImplicitObject io16 = new ResourceImplicitObject();
+ forFacesList.put(io16.getName(), io16);
return new ImplicitObjectResolver(forFacesList);
}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java?rev=709540&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java Fri Oct 31 12:20:53 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.el.unified.resolver.implicitobject;
+
+import java.beans.FeatureDescriptor;
+import javax.el.ELContext;
+
+/**
+ * Encapsulates information needed by the ImplicitObjectResolver
+ *
+ * @author Leonardo Uribe
+ */
+public class ResourceImplicitObject extends ImplicitObject
+{
+
+ private static final String NAME = "resource".intern();
+
+ /** Creates a new instance of ApplicationImplicitObject */
+ public ResourceImplicitObject()
+ {
+ }
+
+ @Override
+ public Object getValue(ELContext context)
+ {
+ return facesContext(context).getApplication().getResourceHandler();
+ }
+
+ @Override
+ public String getName()
+ {
+ return NAME;
+ }
+
+ @Override
+ public Class<?> getType()
+ {
+ return null;
+ }
+
+ @Override
+ public FeatureDescriptor getDescriptor()
+ {
+ return makeDescriptor(NAME, "Represents the current resource handler", Object.class);
+ }
+}
Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/resolver/implicitobject/ResourceImplicitObject.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL