Author: nbelaevski
Date: 2010-07-26 08:06:45 -0400 (Mon, 26 Jul 2010)
New Revision: 18233
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducer.java
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/URLResource.java
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/skin/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/skin/SkinFactoryImpl.java
Removed:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java
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/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/FacesImpl.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/ResourcesScannerImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
Log:
Latest changes for resources prerenderer module
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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -33,8 +33,6 @@
public void setSkin(String skinName);
- public String getSkin();
-
public void startRequest();
public void stopRequest();
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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -22,20 +22,20 @@
package org.richfaces.cdk;
import static com.google.common.base.Predicates.notNull;
-import static com.google.common.collect.Iterables.concat;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.transform;
+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;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import javax.faces.application.Resource;
-
+import org.richfaces.cdk.faces.FacesImpl;
import org.richfaces.cdk.naming.FileNameMapperImpl;
-import org.richfaces.cdk.resource.ResourceFactoryImpl;
+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,25 +49,41 @@
public class Main {
private static ExecutorService createExecutorService() {
- return Executors.newSingleThreadExecutor();
+ return Executors.newFixedThreadPool(4);
}
+ 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.start();
+
String dstDir = args[0];
-
+
ResourcesScanner resourcesScanner = new ResourcesScannerImpl();
resourcesScanner.scan();
- ResourceFactory resourceFactory = new ResourceFactoryImpl();
+ ResourceProducerFactory resourceFactory = new ResourceProducerFactoryImpl();
- Iterable<Resource> resources = filter(concat(
- transform(resourcesScanner.getClassResources(),
resourceFactory.getClassResourceFactory()),
- transform(resourcesScanner.getURLResources(),
resourceFactory.getURLResourceFactory())), notNull());
+ 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());
- //TODO set webroot
- ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(resourceWriter,
null);
-
+ ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(faces,
resourceWriter);
+
taskFactory.setResources(resources);
taskFactory.setSkins(Lists.newArrayList("blueSky", "ruby",
"classic"));
@@ -81,18 +97,20 @@
tasksCounter++;
}
- while (tasksCounter > 0){
+ while (tasksCounter > 0) {
try {
completionService.take().get();
} catch (ExecutionException e) {
// TODO: handle exception
- e.getCause().printStackTrace();
+ //e.getCause().printStackTrace();
}
tasksCounter--;
}
} finally {
executorService.shutdown();
}
+
+ faces.stop();
}
}
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java 2010-07-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -1,40 +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 java.net.URL;
-
-import javax.faces.application.Resource;
-
-import com.google.common.base.Function;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface ResourceFactory {
-
- public Function<URL, Resource> getURLResourceFactory();
-
- public Function<Class<?>, Resource> getClassResourceFactory();
-
-}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducer.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducer.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducer.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,34 @@
+/*
+ * 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 javax.faces.application.Resource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceProducer {
+
+ public Resource build();
+
+}
Copied:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java
(from rev 18222,
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java)
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceProducerFactory.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,36 @@
+/*
+ * 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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -24,17 +24,15 @@
import java.util.Collection;
import java.util.concurrent.Callable;
-import javax.faces.application.Resource;
-
/**
* @author Nick Belaevski
*
*/
public interface ResourceTaskFactory {
- public void setSkins(Iterable<String> skins);
+ public void setSkins(Collection<String> skins);
- public void setResources(Iterable<Resource> resources);
+ public void setResources(Collection<ResourceProducer> 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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -21,7 +21,6 @@
*/
package org.richfaces.cdk;
-import java.net.URL;
import java.util.Collection;
/**
@@ -36,5 +35,5 @@
public Collection<Class<?>> getClassResources();
- public Collection<URL> getURLResources();
+ public Collection<String> getURLResources();
}
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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -25,15 +25,14 @@
import javax.faces.context.FacesContext;
-import org.ajax4jsf.context.ContextInitParameters;
import org.ajax4jsf.context.InitParametersStorage;
import org.richfaces.application.Module;
import org.richfaces.application.ServiceTracker;
import org.richfaces.application.ServicesFactory;
import org.richfaces.application.ServicesFactoryImpl;
import org.richfaces.cdk.Faces;
+import org.richfaces.cdk.skin.SkinFactoryImpl;
import org.richfaces.skin.SkinFactory;
-import org.richfaces.skin.SkinFactoryImpl;
/**
* @author Nick Belaevski
@@ -68,15 +67,9 @@
}
public void setSkin(String skinName) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
facesContext.getExternalContext().getInitParameterMap().put(ContextInitParameters.SKIN,
skinName);
+ SkinFactoryImpl.setSkinName(skinName);
}
- public String getSkin() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- return (String)
facesContext.getExternalContext().getInitParameterMap().get(ContextInitParameters.SKIN);
- }
-
public void startRequest() {
FacesContextImpl facesContextImpl = new FacesContextImpl();
facesContextImpl.getExternalContext().setWebRoot(webroot);
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ClassResourceProducer.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,93 @@
+/*
+ * 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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -21,32 +21,49 @@
*/
package org.richfaces.cdk.resource;
+import static com.google.common.collect.Collections2.filter;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
import org.reflections.Configuration;
import org.reflections.Reflections;
import org.reflections.scanners.Scanner;
import org.reflections.util.Utils;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.collect.Multimap;
/**
* @author Nick Belaevski
*
*/
-public class ReflectionsExt extends Reflections {
+class ReflectionsExt extends Reflections {
- ReflectionsExt() {
+ private static final Predicate<String> ECSS_RESOURCE_PREDICATE = new
Predicate<String>() {
+
+ private final Pattern PATH_PATTERN =
Pattern.compile("^META-INF/resources/.+\\.ecss$");
+
+ @Override
+ public boolean apply(String input) {
+ return PATH_PATTERN.matcher(input).matches();
+ }
+
+ };
+
+ public ReflectionsExt() {
super();
}
- ReflectionsExt(Configuration configuration) {
+ public ReflectionsExt(Configuration configuration) {
super(configuration);
}
- ReflectionsExt(String prefix, Scanner... scanners) {
+ public ReflectionsExt(String prefix, Scanner... scanners) {
super(prefix, scanners);
}
@@ -58,4 +75,9 @@
}
return Utils.forNames(scannerMMap.get(MarkerResourcesScanner.STORE_KEY));
}
+
+ public Collection<String> getURLResources() {
+ Set<String> allResources = getResources(Predicates.<String>
alwaysTrue());
+ return filter(allResources, ECSS_RESOURCE_PREDICATE);
+ }
}
Deleted:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java 2010-07-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -1,114 +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 java.net.URL;
-
-import javax.faces.FacesException;
-import javax.faces.application.Resource;
-
-import org.richfaces.cdk.ResourceFactory;
-import org.richfaces.resource.Java2DUserResource;
-import org.richfaces.resource.Java2DUserResourceWrapperImpl;
-
-import com.google.common.base.Function;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ResourceFactoryImpl implements ResourceFactory {
-
- private <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 Function<URL, Resource> urlFunction = new Function<URL,
Resource>() {
- public Resource apply(URL from) {
- // TODO Auto-generated method stub
- return null;
- }
- };
-
- private Function<Class<?>, Resource> classFunction = new
Function<Class<?>, Resource>() {
- 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;
- }
-
- private boolean isImageResource(Resource resource) {
- String contentType = resource.getContentType();
-
- if (contentType == null) {
- return false;
- }
-
- return contentType.contains("image/");
- }
-
- public Resource apply(Class<?> from) {
- Resource resource = createResource(from);
- if (resource != null && isImageResource(resource)) {
- return resource;
- }
-
- return null;
- };
- };
-
- public Function<URL, Resource> getURLResourceFactory() {
- return urlFunction;
- }
-
- public Function<Class<?>, Resource> getClassResourceFactory() {
- return classFunction;
- }
-
-}
Copied:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java
(from rev 18222,
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java)
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceProducerFactoryImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,58 @@
+/*
+ * 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/ResourcesScannerImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -73,13 +73,14 @@
private Collection<Class<?>> classResources = Sets.newHashSet();
- private Collection<URL> urlResources = Sets.newHashSet();
+ private Collection<String> urlResources = Sets.newHashSet();
public void scan() {
Collection<URL> urls =
Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
ConfigurationBuilder configurationBuilder = new
ConfigurationBuilder().setUrls(urls);
- configurationBuilder.setScanners(new SubTypesScanner(), new
TypeAnnotationsScanner(), new MarkerResourcesScanner());
+ configurationBuilder.setScanners(new SubTypesScanner(), new
TypeAnnotationsScanner(),
+ new MarkerResourcesScanner(), new
org.reflections.scanners.ResourcesScanner());
ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
@@ -92,13 +93,14 @@
}
classResources.addAll(refl.getMarkedClasses());
+ urlResources.addAll(refl.getURLResources());
}
public Collection<Class<?>> getClassResources() {
return classResources;
}
- public Collection<URL> getURLResources() {
+ public Collection<String> getURLResources() {
return urlResources;
}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResource.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResource.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResource.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,71 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.context.FacesContext;
+
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class URLResource extends Resource {
+
+ private URL resourceUrl;
+
+ public URLResource(URL resourceUrl) {
+ super();
+ this.resourceUrl = resourceUrl;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return resourceUrl.openStream();
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ return Maps.newHashMap();
+ }
+
+ @Override
+ public String getRequestPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public URL getURL() {
+ return resourceUrl;
+ }
+
+ @Override
+ public boolean userAgentNeedsUpdate(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/URLResourceProducer.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,96 @@
+/*
+ * 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
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/skin/SkinFactoryImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/skin/SkinFactoryImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/skin/SkinFactoryImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -0,0 +1,71 @@
+/*
+ * 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.skin;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.skin.AbstractSkinFactory;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.Theme;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SkinFactoryImpl extends AbstractSkinFactory {
+
+ private static ThreadLocal<String> skinNames = new
ThreadLocal<String>();
+
+ public static void setSkinName(String skinName) {
+ skinNames.set(skinName);
+ }
+
+ @Override
+ public Skin getDefaultSkin(FacesContext context) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Skin getSkin(FacesContext context) {
+ return getSkin(context, skinNames.get());
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.skin.SkinFactory#getBaseSkin(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Skin getBaseSkin(FacesContext facesContext) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.skin.SkinFactory#getTheme(javax.faces.context.FacesContext,
java.lang.String)
+ */
+ @Override
+ public Theme getTheme(FacesContext facesContext, String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
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-26
11:53:04 UTC (rev 18232)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-26
12:06:45 UTC (rev 18233)
@@ -31,9 +31,9 @@
import javax.faces.context.FacesContext;
import org.richfaces.cdk.Faces;
+import org.richfaces.cdk.ResourceProducer;
import org.richfaces.cdk.ResourceTaskFactory;
import org.richfaces.cdk.ResourceWriter;
-import org.richfaces.cdk.faces.FacesImpl;
import org.richfaces.resource.StateHolderResource;
import com.google.common.collect.Lists;
@@ -48,27 +48,27 @@
private class ResourcesRendererCallable implements Callable<Object> {
- private Faces faces;
-
private String skinName;
- private Iterable<Resource> resources;
+ private ResourceProducer resourceBuilder;
- ResourcesRendererCallable(String skinName, Iterable<Resource> resources) {
+ ResourcesRendererCallable(String skinName, ResourceProducer resourceBuilder) {
this.skinName = skinName;
- this.resources = resources;
+ this.resourceBuilder = resourceBuilder;
}
- private void renderResource(Resource resource) throws Exception {
+ public Object call() throws Exception {
try {
- faces.startRequest();
faces.setSkin(skinName);
+ faces.startRequest();
+ Resource resource = resourceBuilder.build();
+
if (resource instanceof StateHolderResource) {
StateHolderResource stateHolderResource = (StateHolderResource)
resource;
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
stateHolderResource.writeState(FacesContext.getCurrentInstance(),
dataOutput);
-
+ byte[] bs = dataOutput.toByteArray();
//TODO use collected data
} else if (resource instanceof StateHolder) {
StateHolder stateHolder = (StateHolder) resource;
@@ -78,25 +78,12 @@
}
}
- resourceWriter.writeResource(faces.getSkin(), resource);
+ //TODO check content type
+ resourceWriter.writeResource(skinName, resource);
} finally {
+ faces.setSkin(null);
faces.stopRequest();
}
- }
-
- public Object call() throws Exception {
- try {
- faces = new FacesImpl(webRoot);
- faces.start();
-
- for (Resource resource : resources) {
- renderResource(resource);
- }
-
- } finally {
- faces.stop();
- faces = null;
- }
// TODO Auto-generated method stub
return null;
@@ -104,25 +91,25 @@
}
- private String webRoot;
+ private Faces faces;
private ResourceWriter resourceWriter;
- private Iterable<Resource> resources = Collections.emptySet();
+ private Collection<ResourceProducer> resources = Collections.emptySet();
- private Iterable<String> skins = Collections.emptySet();
+ private Collection<String> skins = Collections.emptySet();
- public ResourceTaskFactoryImpl(ResourceWriter resourceWriter, String webRoot) {
+ public ResourceTaskFactoryImpl(Faces faces, ResourceWriter resourceWriter) {
super();
+ this.faces = faces;
this.resourceWriter = resourceWriter;
- this.webRoot = webRoot;
}
- public void setResources(Iterable<Resource> resources) {
+ public void setResources(Collection<ResourceProducer> resources) {
this.resources = resources;
}
-
- public void setSkins(Iterable<String> skins) {
+
+ public void setSkins(Collection<String> skins) {
this.skins = skins;
}
@@ -130,7 +117,9 @@
List<Callable<Object>> result = Lists.newArrayList();
for (String skin : skins) {
- result.add(new ResourcesRendererCallable(skin, resources));
+ for (ResourceProducer resource : resources) {
+ result.add(new ResourcesRendererCallable(skin, resource));
+ }
}
return result;