Author: nbelaevski
Date: 2010-07-27 07:45:44 -0400 (Tue, 27 Jul 2010)
New Revision: 18242
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceInfo.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/CurrentResourceContext.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ReadOnlyValueExpression.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/VariableMapperImpl.java
Removed:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ClassResourceProducer.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResourceProducer.java
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
Log:
Dynamic resources prerenderer: latest changes check-in
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml 2010-07-27 11:43:27 UTC
(rev 18241)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml 2010-07-27 11:45:44 UTC
(rev 18242)
@@ -52,8 +52,6 @@
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
- <type>jar</type>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
@@ -67,6 +65,11 @@
</exclusions>
</dependency>
+ <dependency>
+ <groupId>com.sun.el</groupId>
+ <artifactId>el-ri</artifactId>
+ <version>1.0</version>
+ </dependency>
</dependencies>
<build>
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,6 +21,8 @@
*/
package org.richfaces.cdk;
+import javax.faces.context.FacesContext;
+
/**
* @author Nick Belaevski
*
@@ -33,7 +35,7 @@
public void setSkin(String skinName);
- public void startRequest();
+ public FacesContext startRequest();
public void stopRequest();
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,12 +21,14 @@
*/
package org.richfaces.cdk;
+import javax.faces.application.Resource;
+
/**
* @author Nick Belaevski
*
*/
public interface FileNameMapper {
- public String createName(String mimeType, String resourceName);
+ public String createName(Resource resource);
}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,12 +21,6 @@
*/
package org.richfaces.cdk;
-import static com.google.common.base.Predicates.notNull;
-import static com.google.common.collect.Collections2.filter;
-import static com.google.common.collect.Collections2.transform;
-
-import java.util.Collection;
-import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
@@ -35,7 +29,6 @@
import org.richfaces.cdk.faces.FacesImpl;
import org.richfaces.cdk.naming.FileNameMapperImpl;
-import org.richfaces.cdk.resource.ResourceProducerFactoryImpl;
import org.richfaces.cdk.resource.ResourceWriterImpl;
import org.richfaces.cdk.resource.ResourcesScannerImpl;
import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
@@ -49,22 +42,12 @@
public class Main {
private static ExecutorService createExecutorService() {
- return Executors.newFixedThreadPool(4);
+ return Executors.newSingleThreadExecutor();
}
- private static <T> Collection<T> concatCollections(Collection<?
extends T> firstCollection,
- Collection<? extends T> secondCollection) {
- List<T> result = Lists.newArrayList();
-
- result.addAll(firstCollection);
- result.addAll(secondCollection);
-
- return result;
- }
-
public static void main(String[] args) throws Exception {
// TODO set webroot
- Faces faces = new FacesImpl(null);
+ Faces faces = new FacesImpl(null, new FileNameMapperImpl());
faces.start();
String dstDir = args[0];
@@ -72,19 +55,10 @@
ResourcesScanner resourcesScanner = new ResourcesScannerImpl();
resourcesScanner.scan();
- ResourceProducerFactory resourceFactory = new ResourceProducerFactoryImpl();
-
- Collection<ResourceProducer> classResources = filter(
- transform(resourcesScanner.getClassResources(),
resourceFactory.getClassResourceProducerFactory()), notNull());
- Collection<ResourceProducer> urlResources = filter(
- transform(resourcesScanner.getURLResources(),
resourceFactory.getURLResourceProducerFactory()), notNull());
-
- Collection<ResourceProducer> resources = concatCollections(classResources,
urlResources);
-
- ResourceWriterImpl resourceWriter = new ResourceWriterImpl(dstDir, new
FileNameMapperImpl());
+ ResourceWriterImpl resourceWriter = new ResourceWriterImpl(dstDir);
ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(faces,
resourceWriter);
- taskFactory.setResources(resources);
+ taskFactory.setResources(resourcesScanner.getResources());
taskFactory.setSkins(Lists.newArrayList("blueSky", "ruby",
"classic"));
ExecutorService executorService = createExecutorService();
@@ -102,7 +76,7 @@
completionService.take().get();
} catch (ExecutionException e) {
// TODO: handle exception
- //e.getCause().printStackTrace();
+ e.getCause().printStackTrace();
}
tasksCounter--;
}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceInfo.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceInfo.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceInfo.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceInfo {
+
+ public static final String CLASSPATH_RESOURCES_LOCATION =
"META-INF/resources/";
+
+ private final String resourceName;
+
+ private final String libraryName;
+
+ public ResourceInfo(String resourceName) {
+ this(resourceName, null);
+ }
+
+ public ResourceInfo(String resourceName, String libraryName) {
+ super();
+ this.resourceName = resourceName;
+ this.libraryName = libraryName;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public String getLibraryName() {
+ return libraryName;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((libraryName == null) ? 0 : libraryName.hashCode());
+ result = prime * result + ((resourceName == null) ? 0 :
resourceName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ResourceInfo other = (ResourceInfo) obj;
+ if (libraryName == null) {
+ if (other.libraryName != null) {
+ return false;
+ }
+ } else if (!libraryName.equals(other.libraryName)) {
+ return false;
+ }
+ if (resourceName == null) {
+ if (other.resourceName != null) {
+ return false;
+ }
+ } else if (!resourceName.equals(other.resourceName)) {
+ return false;
+ }
+ return true;
+ }
+
+}
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk;
-
-import com.google.common.base.Function;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface ResourceProducerFactory {
-
- public Function<String, ResourceProducer> getURLResourceProducerFactory();
-
- public Function<Class<?>, ResourceProducer>
getClassResourceProducerFactory();
-
-}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -32,7 +32,7 @@
public void setSkins(Collection<String> skins);
- public void setResources(Collection<ResourceProducer> resources);
+ public void setResources(Collection<ResourceInfo> resources);
public Collection<Callable<Object>> createTasks();
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -33,7 +33,6 @@
public void scan();
- public Collection<Class<?>> getClassResources();
+ public Collection<ResourceInfo> getResources();
- public Collection<String> getURLResources();
}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ApplicationImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,488 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.NavigationHandler;
+import javax.faces.application.ProjectStage;
+import javax.faces.application.ResourceHandler;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.PropertyResolver;
+import javax.faces.el.ReferenceSyntaxException;
+import javax.faces.el.ValueBinding;
+import javax.faces.el.VariableResolver;
+import javax.faces.event.ActionListener;
+import javax.faces.validator.Validator;
+
+import com.sun.el.ExpressionFactoryImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ApplicationImpl extends Application {
+
+ private ExpressionFactory expressionFactory = createExpressionFactory();
+
+ private ResourceHandler resourceHandler = createResourceHandler();
+
+ private ExpressionFactory createExpressionFactory() {
+ return ExpressionFactoryImpl.newInstance();
+ }
+
+ private ResourceHandler createResourceHandler() {
+ return new ResourceHandlerImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getActionListener()
+ */
+ @Override
+ public ActionListener getActionListener() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setActionListener(javax.faces.event.ActionListener)
+ */
+ @Override
+ public void setActionListener(ActionListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getDefaultLocale()
+ */
+ @Override
+ public Locale getDefaultLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#setDefaultLocale(java.util.Locale)
+ */
+ @Override
+ public void setDefaultLocale(Locale locale) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getDefaultRenderKitId()
+ */
+ @Override
+ public String getDefaultRenderKitId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#setDefaultRenderKitId(java.lang.String)
+ */
+ @Override
+ public void setDefaultRenderKitId(String renderKitId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getMessageBundle()
+ */
+ @Override
+ public String getMessageBundle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#setMessageBundle(java.lang.String)
+ */
+ @Override
+ public void setMessageBundle(String bundle) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getNavigationHandler()
+ */
+ @Override
+ public NavigationHandler getNavigationHandler() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setNavigationHandler(javax.faces.application.NavigationHandler)
+ */
+ @Override
+ public void setNavigationHandler(NavigationHandler handler) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getPropertyResolver()
+ */
+ @Override
+ public PropertyResolver getPropertyResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setPropertyResolver(javax.faces.el.PropertyResolver)
+ */
+ @Override
+ public void setPropertyResolver(PropertyResolver resolver) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getVariableResolver()
+ */
+ @Override
+ public VariableResolver getVariableResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setVariableResolver(javax.faces.el.VariableResolver)
+ */
+ @Override
+ public void setVariableResolver(VariableResolver resolver) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getViewHandler()
+ */
+ @Override
+ public ViewHandler getViewHandler() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setViewHandler(javax.faces.application.ViewHandler)
+ */
+ @Override
+ public void setViewHandler(ViewHandler handler) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getStateManager()
+ */
+ @Override
+ public StateManager getStateManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setStateManager(javax.faces.application.StateManager)
+ */
+ @Override
+ public void setStateManager(StateManager manager) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#addComponent(java.lang.String,
java.lang.String)
+ */
+ @Override
+ public void addComponent(String componentType, String componentClass) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createComponent(java.lang.String)
+ */
+ @Override
+ public UIComponent createComponent(String componentType) throws FacesException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#createComponent(javax.faces.el.ValueBinding,
+ * javax.faces.context.FacesContext, java.lang.String)
+ */
+ @Override
+ public UIComponent createComponent(ValueBinding componentBinding, FacesContext
context, String componentType)
+ throws FacesException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getComponentTypes()
+ */
+ @Override
+ public Iterator<String> getComponentTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#addConverter(java.lang.String,
java.lang.String)
+ */
+ @Override
+ public void addConverter(String converterId, String converterClass) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#addConverter(java.lang.Class,
java.lang.String)
+ */
+ @Override
+ public void addConverter(Class<?> targetClass, String converterClass) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createConverter(java.lang.String)
+ */
+ @Override
+ public Converter createConverter(String converterId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createConverter(java.lang.Class)
+ */
+ @Override
+ public Converter createConverter(Class<?> targetClass) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getConverterIds()
+ */
+ @Override
+ public Iterator<String> getConverterIds() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getConverterTypes()
+ */
+ @Override
+ public Iterator<Class<?>> getConverterTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createMethodBinding(java.lang.String,
java.lang.Class<?>[])
+ */
+ @Override
+ public MethodBinding createMethodBinding(String ref, Class<?>[] params) throws
ReferenceSyntaxException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getSupportedLocales()
+ */
+ @Override
+ public Iterator<Locale> getSupportedLocales() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.application.Application#setSupportedLocales(java.util.Collection)
+ */
+ @Override
+ public void setSupportedLocales(Collection<Locale> locales) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#addValidator(java.lang.String,
java.lang.String)
+ */
+ @Override
+ public void addValidator(String validatorId, String validatorClass) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createValidator(java.lang.String)
+ */
+ @Override
+ public Validator createValidator(String validatorId) throws FacesException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getValidatorIds()
+ */
+ @Override
+ public Iterator<String> getValidatorIds() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#createValueBinding(java.lang.String)
+ */
+ @Override
+ public ValueBinding createValueBinding(String ref) throws ReferenceSyntaxException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ProjectStage getProjectStage() {
+ return ProjectStage.Development;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getExpressionFactory()
+ */
+ @Override
+ public ExpressionFactory getExpressionFactory() {
+ return expressionFactory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.Application#getResourceHandler()
+ */
+ @Override
+ public ResourceHandler getResourceHandler() {
+ return resourceHandler;
+ }
+
+ @Override
+ public <T> T evaluateExpressionGet(FacesContext context, String expression,
Class<? extends T> expectedType)
+ throws ELException {
+ ValueExpression ve =
getExpressionFactory().createValueExpression(context.getELContext(), expression,
+ expectedType);
+ return (T) (ve.getValue(context.getELContext()));
+ }
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/CurrentResourceContext.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/CurrentResourceContext.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/CurrentResourceContext.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO nested resources?
+public final class CurrentResourceContext {
+
+ private static final Class<CurrentResourceContext> CONTEXT_ATTRIBUTE_KEY =
CurrentResourceContext.class;
+
+ private Resource resource = null;
+
+ private CurrentResourceContext() {
+ }
+
+ public static CurrentResourceContext getInstance(FacesContext facesContext) {
+ Map<Object, Object> attributes = facesContext.getAttributes();
+ CurrentResourceContext stack = (CurrentResourceContext)
attributes.get(CONTEXT_ATTRIBUTE_KEY);
+ if (stack == null) {
+ stack = new CurrentResourceContext();
+ attributes.put(CONTEXT_ATTRIBUTE_KEY, stack);
+ }
+
+ return stack;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,24 +21,43 @@
*/
package org.richfaces.cdk.faces;
+import javax.el.CompositeELResolver;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.FunctionMapper;
import javax.el.VariableMapper;
+import org.richfaces.skin.SkinPropertiesELResolver;
+
/**
* @author Nick Belaevski
*
*/
public class ELContextImpl extends ELContext {
+ private VariableMapper variableMapper = createVariableMapper();
+
+ private ELResolver elResolver = createELResolver();
+
+ private VariableMapper createVariableMapper() {
+ return new VariableMapperImpl();
+ }
+
+ private ELResolver createELResolver() {
+ CompositeELResolver result = new CompositeELResolver();
+
+ result.add(new SkinPropertiesELResolver());
+ result.add(new ResourceELResolver());
+
+ return result;
+ }
+
/* (non-Javadoc)
* @see javax.el.ELContext#getELResolver()
*/
@Override
public ELResolver getELResolver() {
- // TODO Auto-generated method stub
- return null;
+ return elResolver;
}
/* (non-Javadoc)
@@ -50,13 +69,9 @@
return null;
}
- /* (non-Javadoc)
- * @see javax.el.ELContext#getVariableMapper()
- */
@Override
public VariableMapper getVariableMapper() {
- // TODO Auto-generated method stub
- return null;
+ return variableMapper;
}
}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -379,4 +379,8 @@
}
+ @Override
+ public String getResponseCharacterEncoding() {
+ return "UTF-8";
+ }
}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -43,21 +43,25 @@
private Map<Object, Object> attributes = new HashMap<Object, Object>();
- private ELContext elContext = new ELContextImpl();
+ private ELContext elContext = createELContext();
private ExternalContextImpl externalContext = new ExternalContextImpl();
+ private ApplicationImpl application = new ApplicationImpl();
+
public FacesContextImpl() {
setCurrentInstance(this);
}
- /* (non-Javadoc)
- * @see javax.faces.context.FacesContext#getApplication()
- */
+ private ELContext createELContext() {
+ ELContext result = new ELContextImpl();
+ result.putContext(FacesContext.class, this);
+ return result;
+ }
+
@Override
public Application getApplication() {
- // TODO Auto-generated method stub
- return null;
+ return application;
}
/* (non-Javadoc)
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -31,6 +31,7 @@
import org.richfaces.application.ServicesFactory;
import org.richfaces.application.ServicesFactoryImpl;
import org.richfaces.cdk.Faces;
+import org.richfaces.cdk.FileNameMapper;
import org.richfaces.cdk.skin.SkinFactoryImpl;
import org.richfaces.skin.SkinFactory;
@@ -42,9 +43,12 @@
private String webroot;
- public FacesImpl(String webroot) {
+ private FileNameMapper fileNameMapper;
+
+ public FacesImpl(String webroot, FileNameMapper fileNameMapper) {
super();
this.webroot = webroot;
+ this.fileNameMapper = fileNameMapper;
}
public void start() {
@@ -56,6 +60,7 @@
public void configure(ServicesFactory factory) {
serviceFactory.setInstance(SkinFactory.class, skinFactory);
serviceFactory.setInstance(InitParametersStorage.class, new
InitParametersStorage());
+ serviceFactory.setInstance(FileNameMapper.class, fileNameMapper);
}
};
serviceFactory.init(Collections.singleton(module));
@@ -70,10 +75,12 @@
SkinFactoryImpl.setSkinName(skinName);
}
- public void startRequest() {
+ public FacesContext startRequest() {
FacesContextImpl facesContextImpl = new FacesContextImpl();
facesContextImpl.getExternalContext().setWebRoot(webroot);
assert FacesContext.getCurrentInstance() != null;
+
+ return facesContextImpl;
}
public void stopRequest() {
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ReadOnlyValueExpression.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ReadOnlyValueExpression.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ReadOnlyValueExpression.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class ReadOnlyValueExpression extends ValueExpression {
+
+ @Override
+ public abstract Object getValue(ELContext context);
+
+ @Override
+ public void setValue(ELContext context, Object value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context) {
+ return true;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context) {
+ return null;
+ }
+
+ @Override
+ public Class<?> getExpectedType() {
+ return Object.class;
+ }
+
+ @Override
+ public String getExpressionString() {
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this;
+ }
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(this);
+ }
+
+ public boolean isLiteralText() {
+ return false;
+ }
+
+ protected FacesContext getFacesContext(ELContext elContext) {
+ return (FacesContext) elContext.getContext(FacesContext.class);
+ }
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import java.beans.FeatureDescriptor;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.cdk.FileNameMapper;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import com.sun.faces.util.Util;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceELResolver extends ELResolver {
+
+ private void checkBaseAndProperty(Object base, Object property) {
+ if (base == null && property == null) {
+ throw new PropertyNotFoundException("base & property are
null");
+ }
+ }
+
+ private String skipEqualPathSegments(Iterator<String> path,
Iterator<String> basePath) {
+ while (path.hasNext()) {
+ String pathSeg = path.next();
+ if (basePath.hasNext()) {
+ String basePathSeg = basePath.next();
+ if (basePathSeg.equals(pathSeg)) {
+ continue;
+ }
+ }
+
+ return pathSeg;
+ }
+
+ return null;
+ }
+
+ private String relativize(String path, String basePath) {
+ Iterator<String> pathItr =
Splitter.on('/').split(path).iterator();
+ Iterator<String> basePathItr =
Splitter.on('/').split(basePath).iterator();
+
+ List<String> resultPathSegments = Lists.newArrayList();
+ String firstNonMatchedSegment = skipEqualPathSegments(pathItr, basePathItr);
+ while (basePathItr.hasNext()) {
+ basePathItr.next();
+ resultPathSegments.add("..");
+ }
+
+ if (firstNonMatchedSegment != null) {
+ resultPathSegments.add(firstNonMatchedSegment);
+ }
+
+ while (pathItr.hasNext()) {
+ resultPathSegments.add(pathItr.next());
+ }
+
+ return Joiner.on('/').join(resultPathSegments);
+ }
+
+ public Object getValue(ELContext context, Object base, Object property) {
+ checkBaseAndProperty(base, property);
+
+ if (base instanceof ResourceHandler) {
+ ResourceHandler handler = (ResourceHandler) base;
+ String prop = (String) property;
+ Resource resource;
+ if (!prop.contains(":")) {
+ resource = handler.createResource(prop);
+ } else {
+ String[] parts = Util.split(prop, ":");
+ if (parts.length != 2) {
+ throw new ELException(MessageFormat.format("Invalid resource
format. Property {0} contains more than one colon (:)", prop));
+ }
+ resource = handler.createResource(parts[1], parts[0]);
+ }
+
+ context.setPropertyResolved(true);
+
+ if (resource != null) {
+ FileNameMapper fileNameMapper =
ServiceTracker.getService(FileNameMapper.class);
+ String name = fileNameMapper.createName(resource);
+
+ FacesContext facesContext = (FacesContext)
context.getContext(FacesContext.class);
+ Resource contextResource =
CurrentResourceContext.getInstance(facesContext).getResource();
+ if (contextResource != null) {
+ name = relativize(name, fileNameMapper.createName(contextResource));
+ }
+
+ return name;
+ }
+ }
+ return null;
+ }
+
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ checkBaseAndProperty(base, property);
+ return null;
+ }
+
+ public void setValue(ELContext context, Object base, Object property, Object value)
{
+ checkBaseAndProperty(base, property);
+ }
+
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ checkBaseAndProperty(base, property);
+
+ return true;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
+ return null;
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return String.class;
+ }
+
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ResourceHandlerImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.net.URL;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+import org.reflections.util.Utils;
+import org.richfaces.cdk.ResourceInfo;
+import org.richfaces.cdk.resource.URLResource;
+import org.richfaces.resource.CompiledCSSResource;
+import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.Java2DUserResourceWrapperImpl;
+import org.richfaces.resource.UserResource;
+import org.richfaces.resource.UserResourceWrapperImpl;
+
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceHandlerImpl extends ResourceHandler {
+
+ @Override
+ public Resource createResource(String resourceName) {
+ return createResource(resourceName, null);
+ }
+
+ @Override
+ public Resource createResource(String resourceName, String libraryName) {
+ return createResource(resourceName, libraryName, null);
+ }
+
+ @Override
+ public Resource createResource(String resourceName, String libraryName, String
contentType) {
+ Resource result = null;
+ if (Strings.isNullOrEmpty(libraryName)) {
+ try {
+ Class<?> resourceClass = Class.forName(resourceName, false,
Utils.getContextClassLoader());
+ if (resourceClass.isInterface() || (resourceClass.getModifiers() &
Modifier.ABSTRACT) != 0) {
+ return null;
+ }
+
+ Object resourceObject = resourceClass.newInstance();
+ if (resourceObject instanceof Java2DUserResource) {
+ result = new Java2DUserResourceWrapperImpl((Java2DUserResource)
resourceObject);
+ } else if (resourceObject instanceof UserResource) {
+ result = new UserResourceWrapperImpl((UserResource) resourceObject);
+ } else {
+ result = (Resource) resourceObject;
+ }
+ } catch (ClassNotFoundException e) {
+ //TODO ignore, but add to debug logs
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ if (result == null) {
+ String resourcePath;
+
+ if (libraryName != null && libraryName.length() != 0) {
+ resourcePath = libraryName + '/' + resourceName;
+ } else {
+ resourcePath = resourceName;
+ }
+
+ URL url =
Utils.getContextClassLoader().getResource(ResourceInfo.CLASSPATH_RESOURCES_LOCATION +
resourcePath);
+ if (url != null) {
+ result = new URLResource(url);
+
+ if (resourceName.endsWith(".ecss")) {
+ //TODO process CSS dependencies
+ result = new CompiledCSSResource(result);
+ }
+ }
+ }
+
+ if (result != null) {
+ //TODO detect content type
+ result.setContentType(contentType);
+ result.setResourceName(resourceName);
+ result.setLibraryName(libraryName);
+ }
+
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.application.ResourceHandler#libraryExists(java.lang.String)
+ */
+ @Override
+ public boolean libraryExists(String libraryName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void handleResourceRequest(FacesContext context) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isResourceRequest(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.ResourceHandler#getRendererTypeForResourceName(java.lang.String)
+ */
+ @Override
+ public String getRendererTypeForResourceName(String resourceName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/VariableMapperImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/VariableMapperImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/VariableMapperImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.faces;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class VariableMapperImpl extends VariableMapper {
+
+ private static final ValueExpression SKIN_VALUE_EXPRESSION = new
ReadOnlyValueExpression() {
+
+ private static final long serialVersionUID = 3552483406787835235L;
+
+ @Override
+ public Object getValue(ELContext elContext) {
+ FacesContext facesContext = getFacesContext(elContext);
+ return SkinFactory.getInstance(facesContext).getSkin(facesContext);
+ }
+ };
+
+ private static final ValueExpression RESOURCE_VALUE_EXPRESSION = new
ReadOnlyValueExpression() {
+
+ private static final long serialVersionUID = -8545250767102884398L;
+
+ @Override
+ public Object getValue(ELContext elContext) {
+ FacesContext facesContext = getFacesContext(elContext);
+ return facesContext.getApplication().getResourceHandler();
+ }
+ };
+
+
+ /* (non-Javadoc)
+ * @see javax.el.VariableMapper#resolveVariable(java.lang.String)
+ */
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ if ("richSkin".equals(variable)) {
+ return SKIN_VALUE_EXPRESSION;
+ } else if ("resource".equals(variable)) {
+ return RESOURCE_VALUE_EXPRESSION;
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.VariableMapper#setVariable(java.lang.String,
javax.el.ValueExpression)
+ */
+ @Override
+ public ValueExpression setVariable(String variable, ValueExpression expression) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,15 +21,36 @@
*/
package org.richfaces.cdk.naming;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.application.Resource;
+
import org.richfaces.cdk.FileNameMapper;
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+
/**
* @author Nick Belaevski
*
*/
public class FileNameMapperImpl implements FileNameMapper {
+ private Map<String, String> mappedPackages = Maps.newLinkedHashMap();
+
+ {
+
mappedPackages.put("^org\\.richfaces\\.renderkit\\.html\\.(images\\.)?",
"org.richfaces/images/");
+ mappedPackages.put("^css/", "org/richfaces/css/");
+ }
+
private String stripContentClassifier(String mimeType) {
+ if (mimeType == null) {
+ return null;
+ }
+
int idx = mimeType.lastIndexOf('/');
if (idx < 0) {
return mimeType;
@@ -38,13 +59,40 @@
}
}
- public String createName(String mimeType, String resourceName) {
- String fileName = resourceName.toLowerCase().replace('.', '_');
- String fileExt = stripContentClassifier(mimeType);
+ private String remapName(String name) {
+ if (name == null) {
+ return name;
+ }
+
+ for (Entry<String, String> mapping : mappedPackages.entrySet()) {
+ Matcher matcher = Pattern.compile(mapping.getKey()).matcher(name);
+ if (matcher.find()) {
+ return matcher.replaceAll(mapping.getValue());
+ }
+ }
+
+ return name;
+ }
+
+ @Override
+ public String createName(Resource resource) {
+ StringBuilder result = new StringBuilder();
+
+ String libraryName = resource.getLibraryName();
+ if (!Strings.isNullOrEmpty(libraryName)) {
+ result.append(libraryName);
+ result.append('/');
+ }
+
+ result.append(resource.getResourceName());
+
+ String fileExt = stripContentClassifier(resource.getContentType());
if (fileExt != null && fileExt.length() != 0) {
- fileName += ("." + fileExt);
+ result.append('.');
+ result.append(fileExt);
}
+
+ return remapName(result.toString());
+ }
- return fileName;
- }
}
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ClassResourceProducer.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ClassResourceProducer.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ClassResourceProducer.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.cdk.resource;
-
-import java.lang.reflect.Modifier;
-
-import javax.faces.FacesException;
-import javax.faces.application.Resource;
-
-import org.richfaces.cdk.ResourceProducer;
-import org.richfaces.resource.Java2DUserResource;
-import org.richfaces.resource.Java2DUserResourceWrapperImpl;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class ClassResourceProducer implements ResourceProducer {
-
- /**
- *
- */
- private final Class<?> from;
-
- /**
- * @param from
- * @param resourceProducerFactoryImpl TODO
- */
- ClassResourceProducer(Class<?> from) {
- this.from = from;
- }
-
- private static <T> T instantiate(Class<? extends T> clazz) {
- try {
- return clazz.newInstance();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (LinkageError e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- throw new FacesException(clazz.getName());
- }
-
- private Resource createResource(Class<?> classResource) {
- if (classResource.isInterface() || (classResource.getModifiers() &
Modifier.ABSTRACT) != 0) {
- return null;
- }
-
- if (Resource.class.isAssignableFrom(classResource)) {
- return instantiate(classResource.asSubclass(Resource.class));
- }
-
- if (Java2DUserResource.class.isAssignableFrom(classResource)) {
- Java2DUserResource java2dResource =
instantiate(classResource.asSubclass(Java2DUserResource.class));
- Resource wrapper = new Java2DUserResourceWrapperImpl(java2dResource);
- wrapper.setResourceName(classResource.getName());
- return wrapper;
- }
-
- return null;
- }
-
- @Override
- public Resource build() {
- return createResource(from);
- }
-}
\ No newline at end of file
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -23,6 +23,7 @@
import static com.google.common.collect.Collections2.filter;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -33,6 +34,7 @@
import org.reflections.Reflections;
import org.reflections.scanners.Scanner;
import org.reflections.util.Utils;
+import org.richfaces.cdk.ResourceInfo;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -46,7 +48,8 @@
private static final Predicate<String> ECSS_RESOURCE_PREDICATE = new
Predicate<String>() {
- private final Pattern PATH_PATTERN =
Pattern.compile("^META-INF/resources/.+\\.ecss$");
+ private final Pattern PATH_PATTERN =
Pattern.compile(MessageFormat.format("^{0}.+\\.ecss$",
+ ResourceInfo.CLASSPATH_RESOURCES_LOCATION));
@Override
public boolean apply(String input) {
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.resource;
-
-
-
-import org.richfaces.cdk.ResourceProducer;
-import org.richfaces.cdk.ResourceProducerFactory;
-
-import com.google.common.base.Function;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ResourceProducerFactoryImpl implements ResourceProducerFactory {
-
- private static Function<String, ResourceProducer> urlFunction = new
Function<String, ResourceProducer>() {
- public ResourceProducer apply(String from) {
- return new URLResourceProducer(from);
- }
- };
-
- private static Function<Class<?>, ResourceProducer> classFunction = new
Function<Class<?>, ResourceProducer>() {
-
- public ResourceProducer apply(final Class<?> from) {
- return new ClassResourceProducer(from);
- };
- };
-
- public Function<String, ResourceProducer> getURLResourceProducerFactory() {
- return urlFunction;
- }
-
- public Function<Class<?>, ResourceProducer>
getClassResourceProducerFactory() {
- return classFunction;
- }
-
-}
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -28,6 +28,7 @@
import javax.faces.application.Resource;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.FileNameMapper;
import org.richfaces.cdk.ResourceWriter;
@@ -41,30 +42,24 @@
private File baseDir;
- private FileNameMapper fileNameMapper;
-
- public ResourceWriterImpl(String baseDirectoryName, FileNameMapper fileNameMapper) {
+ public ResourceWriterImpl(String baseDirectoryName) {
baseDir = new File(baseDirectoryName);
baseDir.mkdirs();
-
- this.fileNameMapper = fileNameMapper;
}
+ private FileNameMapper getFileNameMapper() {
+ return ServiceTracker.getService(FileNameMapper.class);
+ }
+
public void writeResource(String skinName, Resource resource) throws IOException {
- File skinDir = new File(baseDir, skinName);
- skinDir.mkdirs();
-
- File destDir = skinDir;
- if (resource.getLibraryName() != null &&
resource.getLibraryName().length() != 0) {
- destDir = new File(destDir, resource.getLibraryName());
- destDir.mkdirs();
- }
-
FileOutputStream fos = null;
InputStream is = null;
try {
is = resource.getInputStream();
- File outFile = new File(destDir,
fileNameMapper.createName(resource.getContentType(), resource.getResourceName()));
+
+ File skinDir = new File(baseDir, skinName);
+ File outFile = new File(skinDir, getFileNameMapper().createName(resource));
+ outFile.getParentFile().mkdirs();
outFile.createNewFile();
fos = new FileOutputStream(outFile);
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -21,8 +21,11 @@
*/
package org.richfaces.cdk.resource;
+import static com.google.common.collect.Collections2.transform;
+
import java.net.URL;
import java.util.Collection;
+import java.util.Collections;
import java.util.Set;
import org.reflections.scanners.SubTypesScanner;
@@ -33,20 +36,62 @@
import org.reflections.vfs.Vfs.Dir;
import org.reflections.vfs.Vfs.File;
import org.reflections.vfs.ZipDir;
+import org.richfaces.cdk.ResourceInfo;
import org.richfaces.cdk.ResourcesScanner;
import org.richfaces.resource.DynamicResource;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
-
/**
* @author Nick Belaevski
*
*/
public class ResourcesScannerImpl implements ResourcesScanner {
+ private static final Function<Class<?>, ResourceInfo>
CLASS_RESOURCE_FUNCTION = new Function<Class<?>, ResourceInfo>() {
+
+ @Override
+ public ResourceInfo apply(Class<?> from) {
+ return new ResourceInfo(from.getName());
+ }
+ };
+
+ private static final Function<String, ResourceInfo> RELATIVE_PATH_FUNCTION =
new Function<String, ResourceInfo>() {
+
+ private String getResourceRelativePath(String path) {
+ return path.substring(ResourceInfo.CLASSPATH_RESOURCES_LOCATION.length());
+ }
+
+ private String getLibraryName(String relativePath) {
+ int idx = relativePath.lastIndexOf('/');
+ if (idx < 0) {
+ return null;
+ } else {
+ return relativePath.substring(0, idx);
+ }
+ }
+
+ private String getResourceName(String relativePath) {
+ int idx = relativePath.lastIndexOf('/');
+ if (idx < 0) {
+ return relativePath;
+ } else {
+ return relativePath.substring(idx + 1);
+ }
+ }
+
+ @Override
+ public ResourceInfo apply(String from) {
+ String relPath = getResourceRelativePath(from);
+ String libraryName = getLibraryName(relPath);
+ String resourceName = getResourceName(relPath);
+ return new ResourceInfo(resourceName, libraryName);
+ }
+ };
+
private static final Predicate<File> IS_FACES_CONFIG = new
Predicate<File>() {
public boolean apply(File input) {
@@ -71,11 +116,11 @@
}
};
- private Collection<Class<?>> classResources = Sets.newHashSet();
+ private Collection<ResourceInfo> resources = Sets.newHashSet();
- private Collection<String> urlResources = Sets.newHashSet();
-
public void scan() {
+ resources.clear();
+
Collection<URL> urls =
Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
ConfigurationBuilder configurationBuilder = new
ConfigurationBuilder().setUrls(urls);
@@ -84,24 +129,21 @@
ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
- Set<Class<?>> resources =
refl.getTypesAnnotatedWith(DynamicResource.class);
+ Set<Class<?>> classResources =
refl.getTypesAnnotatedWith(DynamicResource.class);
- // TODO - reflections doesn't handle @Inherited correctly
- for (Class<?> resourceClass : resources) {
- classResources.add(resourceClass);
- classResources.addAll(refl.getSubTypesOf(resourceClass));
+ // TODO - reflections library doesn't handle @Inherited correctly
+ for (Class<?> resourceClass : classResources) {
+ resources.addAll(transform(Collections.singleton(resourceClass),
CLASS_RESOURCE_FUNCTION));
+ resources.addAll(transform(refl.getSubTypesOf(resourceClass),
CLASS_RESOURCE_FUNCTION));
}
- classResources.addAll(refl.getMarkedClasses());
- urlResources.addAll(refl.getURLResources());
+ resources.addAll(transform(refl.getMarkedClasses(), CLASS_RESOURCE_FUNCTION));
+ resources.addAll(transform(refl.getURLResources(), RELATIVE_PATH_FUNCTION));
}
- public Collection<Class<?>> getClassResources() {
- return classResources;
+ @Override
+ public Collection<ResourceInfo> getResources() {
+ return resources;
}
-
- public Collection<String> getURLResources() {
- return urlResources;
- }
-
+
}
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResourceProducer.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResourceProducer.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResourceProducer.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -1,96 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.cdk.resource;
-
-import java.net.URL;
-
-import javax.faces.application.Resource;
-
-import org.reflections.util.Utils;
-import org.richfaces.cdk.ResourceProducer;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class URLResourceProducer implements ResourceProducer {
- /**
- *
- */
- private final String libraryName;
- /**
- *
- */
- private final URL url;
- /**
- *
- */
- private final String resourceName;
-
- /**
- * @param libraryName
- * @param url
- * @param resourceName
- */
- URLResourceProducer(String resPath) {
- String relPath = getResourceRelativePath(resPath);
-
- url = Utils.getContextClassLoader().getResource(resPath);
- libraryName = getLibraryName(relPath);
- resourceName = getResourceName(relPath);
- }
-
- private String getResourceRelativePath(String path) {
- return path.substring("META-INF/resources/".length());
- }
-
- private String getLibraryName(String relativePath) {
- int idx = relativePath.lastIndexOf('/');
- if (idx < 0) {
- return null;
- } else {
- return relativePath.substring(0, idx);
- }
- }
-
- private String getResourceName(String relativePath) {
- int idx = relativePath.lastIndexOf('/');
- if (idx < 0) {
- return relativePath;
- } else {
- return relativePath.substring(idx + 1);
- }
- }
-
- @Override
- public Resource build() {
- URLResource resource = new URLResource(url);
-
- resource.setContentType("text/css");
-
- resource.setLibraryName(libraryName);
- resource.setResourceName(resourceName);
-
- return resource;
- }
-}
\ No newline at end of file
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-27
11:43:27 UTC (rev 18241)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-27
11:45:44 UTC (rev 18242)
@@ -31,9 +31,10 @@
import javax.faces.context.FacesContext;
import org.richfaces.cdk.Faces;
-import org.richfaces.cdk.ResourceProducer;
+import org.richfaces.cdk.ResourceInfo;
import org.richfaces.cdk.ResourceTaskFactory;
import org.richfaces.cdk.ResourceWriter;
+import org.richfaces.cdk.faces.CurrentResourceContext;
import org.richfaces.resource.StateHolderResource;
import com.google.common.collect.Lists;
@@ -50,30 +51,42 @@
private String skinName;
- private ResourceProducer resourceBuilder;
+ private ResourceInfo resourceInfo;
- ResourcesRendererCallable(String skinName, ResourceProducer resourceBuilder) {
+ ResourcesRendererCallable(String skinName, ResourceInfo resourceInfo) {
this.skinName = skinName;
- this.resourceBuilder = resourceBuilder;
+ this.resourceInfo = resourceInfo;
}
+ private Resource createResource(FacesContext facesContext, ResourceInfo
resourceInfo) {
+ return
facesContext.getApplication().getResourceHandler().createResource(resourceInfo.getResourceName(),
+ resourceInfo.getLibraryName());
+ }
+
public Object call() throws Exception {
try {
faces.setSkin(skinName);
- faces.startRequest();
+ FacesContext facesContext = faces.startRequest();
- Resource resource = resourceBuilder.build();
+ Resource resource = createResource(facesContext, resourceInfo);
+ if (resource == null) {
+ //TODO log null resource
+ return null;
+ }
+
+ CurrentResourceContext.getInstance(facesContext).setResource(resource);
+
if (resource instanceof StateHolderResource) {
StateHolderResource stateHolderResource = (StateHolderResource)
resource;
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
- stateHolderResource.writeState(FacesContext.getCurrentInstance(),
dataOutput);
+ stateHolderResource.writeState(facesContext, dataOutput);
byte[] bs = dataOutput.toByteArray();
//TODO use collected data
} else if (resource instanceof StateHolder) {
StateHolder stateHolder = (StateHolder) resource;
if (!stateHolder.isTransient()) {
- Object savedData =
stateHolder.saveState(FacesContext.getCurrentInstance());
+ Object savedData = stateHolder.saveState(facesContext);
//TODO use collected data
}
}
@@ -95,7 +108,7 @@
private ResourceWriter resourceWriter;
- private Collection<ResourceProducer> resources = Collections.emptySet();
+ private Collection<ResourceInfo> resources = Collections.emptySet();
private Collection<String> skins = Collections.emptySet();
@@ -105,7 +118,7 @@
this.resourceWriter = resourceWriter;
}
- public void setResources(Collection<ResourceProducer> resources) {
+ public void setResources(Collection<ResourceInfo> resources) {
this.resources = resources;
}
@@ -117,8 +130,8 @@
List<Callable<Object>> result = Lists.newArrayList();
for (String skin : skins) {
- for (ResourceProducer resource : resources) {
- result.add(new ResourcesRendererCallable(skin, resource));
+ for (ResourceInfo resourceInfo : resources) {
+ result.add(new ResourcesRendererCallable(skin, resourceInfo));
}
}