Author: nbelaevski
Date: 2009-07-02 12:14:22 -0400 (Thu, 02 Jul 2009)
New Revision: 14772
Removed:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodecAware.java
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceImpl.java
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/TestResource.java
branches/jsf2.0/framework/impl/src/main/resources/META-INF/resource-handler.faces-config.xml
Log:
Resources:
1. faces-config.xml containing ResourceHandler has got its name
2. ResourceCodec and related classes refactoring
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -7,6 +7,12 @@
class DefaultResourceCodec implements ResourceCodec {
+ private static final ResourceCodec CODEC = new DefaultResourceCodec();
+
+ private DefaultResourceCodec() {
+
+ }
+
public String encodeResource(String resourceName, Object resourceData) {
return Util.encodeResourceData(resourceName, resourceData);
}
@@ -18,4 +24,9 @@
public Object decodeResourceData(String resourceKey) {
return Util.getResourceData(resourceKey);
}
+
+ public static ResourceCodec getInstance() {
+ return CODEC;
+ }
+
}
\ No newline at end of file
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -14,4 +14,5 @@
public String decodeResourceName(String resourceKey);
public Object decodeResourceData(String resourceKey);
+
}
Deleted:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodecAware.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodecAware.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceCodecAware.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -1,14 +0,0 @@
-/**
- *
- */
-package org.richfaces.resource;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-public interface ResourceCodecAware {
-
- public void setResourceCodec(ResourceCodec codec);
-
-}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Map.Entry;
+import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.component.StateHolder;
@@ -48,18 +49,33 @@
private ResourceHandler defaultHandler;
- private ResourceCodec codec;
-
public ResourceHandlerImpl(ResourceHandler defaultHandler) {
- this(defaultHandler, new DefaultResourceCodec());
+ this.defaultHandler = defaultHandler;
}
- public ResourceHandlerImpl(ResourceHandler defaultHandler, ResourceCodec resourceCodec)
{
- super();
-
- this.defaultHandler = defaultHandler;
- this.codec = resourceCodec;
+ private static final String RESOURCE_CODEC_ATTRIBUTE_NAME =
+ ResourceHandlerImpl.class.getName() + ":ResourceCodec";
+
+ protected static void setResourceCodec(ResourceCodec codec) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Map<String, Object> applicationMap =
facesContext.getExternalContext().getApplicationMap();
+ Object oldCodec = applicationMap.put(RESOURCE_CODEC_ATTRIBUTE_NAME, codec);
+
+ if (oldCodec != null && codec != null && !oldCodec.equals(codec)
&&
+ ProjectStage.Development.equals(facesContext.getApplication().getProjectStage())) {
+
+ //TODO log "codec should be typically set once per application lifetime"
+ }
}
+
+ public static ResourceCodec getResourceCodec(FacesContext context) {
+ Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
+ ResourceCodec resourceCodec = (ResourceCodec)
applicationMap.get(RESOURCE_CODEC_ATTRIBUTE_NAME);
+ if (resourceCodec == null) {
+ resourceCodec = DefaultResourceCodec.getInstance();
+ }
+ return resourceCodec;
+ }
protected String getResourceKey(FacesContext context) {
String resourceName = Util.decodeResourceURL(context);
@@ -108,7 +124,7 @@
return;
}
- ResourceCodec resourceCodec = getResourceCodec();
+ ResourceCodec resourceCodec = ResourceHandlerImpl.getResourceCodec(context);
String resourceName = resourceCodec.decodeResourceName(resourceKey);
if (resourceName == null) {
sendNotFound(context);
@@ -187,10 +203,6 @@
resource = (Resource) resourceClass.newInstance();
resource.setResourceName(resourceName);
}
-
- if (resource instanceof ResourceCodecAware) {
- ((ResourceCodecAware) resource).setResourceCodec(getResourceCodec());
- }
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
} catch (InstantiationException e1) {
@@ -233,8 +245,4 @@
public boolean libraryExists(String libraryName) {
return defaultHandler.libraryExists(libraryName);
}
-
- protected ResourceCodec getResourceCodec() {
- return codec;
- }
}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceImpl.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceImpl.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/ResourceImpl.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -47,7 +47,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public abstract class ResourceImpl extends Resource implements ResourceCodecAware {
+public abstract class ResourceImpl extends Resource {
public static final String URL_PROTOCOL = "jsfResource";
@@ -57,8 +57,6 @@
private boolean useLocalLastModified = false;
- private ResourceCodec resourceCodec;
-
/**
* @param resourceContext current {@link ResourceContext}
* @return Returns the contentLength.
@@ -153,6 +151,7 @@
}
}
+ ResourceCodec resourceCodec = ResourceHandlerImpl.getResourceCodec(context);
String resourceUri = ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER +
resourceCodec.encodeResource(getResourceName(), resourceData);
@@ -321,7 +320,4 @@
return userCopyIsStale(context);
}
- public void setResourceCodec(ResourceCodec codec) {
- this.resourceCodec = codec;
- }
}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/TestResource.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/TestResource.java 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/java/org/richfaces/resource/TestResource.java 2009-07-02
16:14:22 UTC (rev 14772)
@@ -13,7 +13,6 @@
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.resource.ResourceImpl;
import org.richfaces.VersionBean;
import org.richfaces.VersionBean.Version;
Modified:
branches/jsf2.0/framework/impl/src/main/resources/META-INF/resource-handler.faces-config.xml
===================================================================
---
branches/jsf2.0/framework/impl/src/main/resources/META-INF/resource-handler.faces-config.xml 2009-07-02
16:04:40 UTC (rev 14771)
+++
branches/jsf2.0/framework/impl/src/main/resources/META-INF/resource-handler.faces-config.xml 2009-07-02
16:14:22 UTC (rev 14772)
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
+ <name>richfaces</name>
+
<application>
<resource-handler>org.richfaces.resource.ResourceHandlerImpl</resource-handler>
</application>