Author: nbelaevski
Date: 2010-07-23 13:49:26 -0400 (Fri, 23 Jul 2010)
New Revision: 18222
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/
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/ResourceFactory.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/ResourceWriter.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/
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/faces/naming/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/
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/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/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/richfaces/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/richfaces/cdk/
Log:
dynamic-resources-prerenderer initial check-in
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
(rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml 2010-07-23 17:49:26 UTC
(rev 18222)
@@ -0,0 +1,84 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>dynamic-resources-prerenderer</artifactId>
+
+ <!--
+ <packaging>maven-plugin</packaging>
+ -->
+ <version>4.0.0-SNAPSHOT</version>
+ <name>dynamic-resources-processor</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>reflections-repo</id>
+ <name>Reflections Maven2 Repository</name>
+ <
url>http://reflections.googlecode.com/svn/repo</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>2.0.3-b03</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>richfaces-components-ui</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>2.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <version>0.9.5-RC2</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>google-collections</artifactId>
+ <groupId>com.google.collections</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,42 @@
+/*
+ * 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 interface Faces {
+
+ public void start();
+
+ public void stop();
+
+ public void setSkin(String skinName);
+
+ public String getSkin();
+
+ public void startRequest();
+
+ public void stopRequest();
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,32 @@
+/*
+ * 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 interface FileNameMapper {
+
+ public String createName(String mimeType, String resourceName);
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -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;
+
+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 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.naming.FileNameMapperImpl;
+import org.richfaces.cdk.resource.ResourceFactoryImpl;
+import org.richfaces.cdk.resource.ResourceWriterImpl;
+import org.richfaces.cdk.resource.ResourcesScannerImpl;
+import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class Main {
+
+ private static ExecutorService createExecutorService() {
+ return Executors.newSingleThreadExecutor();
+ }
+
+ public static void main(String[] args) throws Exception {
+ String dstDir = args[0];
+
+ ResourcesScanner resourcesScanner = new ResourcesScannerImpl();
+ resourcesScanner.scan();
+
+ ResourceFactory resourceFactory = new ResourceFactoryImpl();
+
+ Iterable<Resource> resources = filter(concat(
+ transform(resourcesScanner.getClassResources(),
resourceFactory.getClassResourceFactory()),
+ transform(resourcesScanner.getURLResources(),
resourceFactory.getURLResourceFactory())), notNull());
+
+ ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(new
ResourceWriterImpl(dstDir, new FileNameMapperImpl()));
+
+ taskFactory.setResources(resources);
+ taskFactory.setSkins(Lists.newArrayList("blueSky", "ruby",
"classic"));
+
+ ExecutorService executorService = createExecutorService();
+ ExecutorCompletionService<Object> completionService = new
ExecutorCompletionService<Object>(executorService);
+
+ try {
+ int tasksCounter = 0;
+ for (Callable<Object> task : taskFactory.createTasks()) {
+ completionService.submit(task);
+ tasksCounter++;
+ }
+
+ while (tasksCounter > 0){
+ try {
+ completionService.take().get();
+ } catch (ExecutionException e) {
+ // TODO: handle exception
+ e.getCause().printStackTrace();
+ }
+ tasksCounter--;
+ }
+ } finally {
+ executorService.shutdown();
+ }
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,40 @@
+/*
+ * 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/ResourceTaskFactory.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,41 @@
+/*
+ * 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.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 setResources(Iterable<Resource> resources);
+
+ public Collection<Callable<Object>> createTasks();
+
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -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 java.io.IOException;
+
+import javax.faces.application.Resource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceWriter {
+
+ public void writeResource(String skinName, Resource resource) throws IOException;
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,40 @@
+/*
+ * 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 java.util.Collection;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourcesScanner {
+
+ //TODO inclusions/exclusions
+
+ public void scan();
+
+ public Collection<Class<?>> getClassResources();
+
+ public Collection<URL> getURLResources();
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,62 @@
+/*
+ * 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.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ELContextImpl extends ELContext {
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getELResolver()
+ */
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getFunctionMapper()
+ */
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getVariableMapper()
+ */
+ @Override
+ public VariableMapper getVariableMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,351 @@
+/*
+ * 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.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ExternalContextImpl extends ExternalContext {
+
+ private Map<String, String> initParamsMap = new HashMap<String,
String>();
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
+ */
+ @Override
+ public void dispatch(String path) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
+ */
+ @Override
+ public String encodeActionURL(String url) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
+ */
+ @Override
+ public String encodeNamespace(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
+ */
+ @Override
+ public String encodeResourceURL(String url) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getApplicationMap()
+ */
+ @Override
+ public Map<String, Object> getApplicationMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getAuthType()
+ */
+ @Override
+ public String getAuthType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getContext()
+ */
+ @Override
+ public Object getContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ */
+ @Override
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return initParamsMap.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getInitParameterMap()
+ */
+ @Override
+ public Map getInitParameterMap() {
+ // TODO Auto-generated method stub
+ return initParamsMap;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRemoteUser()
+ */
+ @Override
+ public String getRemoteUser() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequest()
+ */
+ @Override
+ public Object getRequest() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestContextPath()
+ */
+ @Override
+ public String getRequestContextPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestCookieMap()
+ */
+ @Override
+ public Map<String, Object> getRequestCookieMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
+ */
+ @Override
+ public Map<String, String> getRequestHeaderMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestHeaderValuesMap()
+ */
+ @Override
+ public Map<String, String[]> getRequestHeaderValuesMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestLocale()
+ */
+ @Override
+ public Locale getRequestLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestLocales()
+ */
+ @Override
+ public Iterator<Locale> getRequestLocales() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestMap()
+ */
+ @Override
+ public Map<String, Object> getRequestMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterMap()
+ */
+ @Override
+ public Map<String, String> getRequestParameterMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterNames()
+ */
+ @Override
+ public Iterator<String> getRequestParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
+ */
+ @Override
+ public Map<String, String[]> getRequestParameterValuesMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestPathInfo()
+ */
+ @Override
+ public String getRequestPathInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestServletPath()
+ */
+ @Override
+ public String getRequestServletPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ */
+ @Override
+ public URL getResource(String path) throws MalformedURLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ */
+ @Override
+ public InputStream getResourceAsStream(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ */
+ @Override
+ public Set<String> getResourcePaths(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResponse()
+ */
+ @Override
+ public Object getResponse() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getSession(boolean)
+ */
+ @Override
+ public Object getSession(boolean create) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getSessionMap()
+ */
+ @Override
+ public Map<String, Object> getSessionMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getUserPrincipal()
+ */
+ @Override
+ public Principal getUserPrincipal() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#isUserInRole(java.lang.String)
+ */
+ @Override
+ public boolean isUserInRole(String role) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#log(java.lang.String)
+ */
+ @Override
+ public void log(String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#log(java.lang.String,
java.lang.Throwable)
+ */
+ @Override
+ public void log(String message, Throwable exception) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#redirect(java.lang.String)
+ */
+ @Override
+ public void redirect(String url) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,239 @@
+/*
+ * 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.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FacesContextImpl extends FacesContext {
+
+ private Map<Object, Object> attributes = new HashMap<Object, Object>();
+
+ private ELContext elContext = new ELContextImpl();
+
+ private ExternalContext externalContext = new ExternalContextImpl();
+
+ public FacesContextImpl() {
+ setCurrentInstance(this);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getApplication()
+ */
+ @Override
+ public Application getApplication() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getClientIdsWithMessages()
+ */
+ @Override
+ public Iterator<String> getClientIdsWithMessages() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getExternalContext()
+ */
+ @Override
+ public ExternalContext getExternalContext() {
+ // TODO Auto-generated method stub
+ return externalContext;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMaximumSeverity()
+ */
+ @Override
+ public Severity getMaximumSeverity() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMessages()
+ */
+ @Override
+ public Iterator<FacesMessage> getMessages() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMessages(java.lang.String)
+ */
+ @Override
+ public Iterator<FacesMessage> getMessages(String clientId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getRenderKit()
+ */
+ @Override
+ public RenderKit getRenderKit() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getRenderResponse()
+ */
+ @Override
+ public boolean getRenderResponse() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseComplete()
+ */
+ @Override
+ public boolean getResponseComplete() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseStream()
+ */
+ @Override
+ public ResponseStream getResponseStream() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.context.FacesContext#setResponseStream(javax.faces.context.ResponseStream)
+ */
+ @Override
+ public void setResponseStream(ResponseStream responseStream) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseWriter()
+ */
+ @Override
+ public ResponseWriter getResponseWriter() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.context.FacesContext#setResponseWriter(javax.faces.context.ResponseWriter)
+ */
+ @Override
+ public void setResponseWriter(ResponseWriter responseWriter) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getViewRoot()
+ */
+ @Override
+ public UIViewRoot getViewRoot() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.context.FacesContext#setViewRoot(javax.faces.component.UIViewRoot)
+ */
+ @Override
+ public void setViewRoot(UIViewRoot root) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#addMessage(java.lang.String,
javax.faces.application.FacesMessage)
+ */
+ @Override
+ public void addMessage(String clientId, FacesMessage message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#release()
+ */
+ @Override
+ public void release() {
+ setCurrentInstance(null);
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#renderResponse()
+ */
+ @Override
+ public void renderResponse() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#responseComplete()
+ */
+ @Override
+ public void responseComplete() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getAttributes()
+ */
+ @Override
+ public Map<Object, Object> getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public ELContext getELContext() {
+ return elContext;
+ }
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -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 java.util.Collections;
+
+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.skin.SkinFactory;
+import org.richfaces.skin.SkinFactoryImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FacesImpl implements Faces {
+
+ public void start() {
+ final SkinFactoryImpl skinFactory = new SkinFactoryImpl();
+
+ final ServicesFactoryImpl serviceFactory = new ServicesFactoryImpl();
+ Module module = new Module() {
+
+ public void configure(ServicesFactory factory) {
+ serviceFactory.setInstance(SkinFactory.class, skinFactory);
+ serviceFactory.setInstance(InitParametersStorage.class, new
InitParametersStorage());
+ }
+ };
+ serviceFactory.init(Collections.singleton(module));
+ ServiceTracker.setFactory(serviceFactory);
+ }
+
+ public void stop() {
+ ServiceTracker.release();
+ }
+
+ public void setSkin(String skinName) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
facesContext.getExternalContext().getInitParameterMap().put(ContextInitParameters.SKIN,
skinName);
+ }
+
+ public String getSkin() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return (String)
facesContext.getExternalContext().getInitParameterMap().get(ContextInitParameters.SKIN);
+ }
+
+ public void startRequest() {
+ new FacesContextImpl();
+ assert FacesContext.getCurrentInstance() != null;
+ }
+
+ public void stopRequest() {
+ FacesContext.getCurrentInstance().release();
+ assert FacesContext.getCurrentInstance() == null;
+ }
+
+}
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java
===================================================================
---
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,50 @@
+/*
+ * 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.naming;
+
+import org.richfaces.cdk.FileNameMapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileNameMapperImpl implements FileNameMapper {
+
+ private String stripContentClassifier(String mimeType) {
+ int idx = mimeType.lastIndexOf('/');
+ if (idx < 0) {
+ return mimeType;
+ } else {
+ return mimeType.substring(idx + 1);
+ }
+ }
+
+ public String createName(String mimeType, String resourceName) {
+ String fileName = resourceName.toLowerCase().replace('.', '_');
+ String fileExt = stripContentClassifier(mimeType);
+ if (fileExt != null && fileExt.length() != 0) {
+ fileName += ("." + fileExt);
+ }
+
+ return fileName;
+ }
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,114 @@
+/*
+ * 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;
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -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.resource;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.faces.application.Resource;
+
+import org.richfaces.cdk.FileNameMapper;
+import org.richfaces.cdk.ResourceWriter;
+
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceWriterImpl implements ResourceWriter {
+
+ private File baseDir;
+
+ private FileNameMapper fileNameMapper;
+
+ public ResourceWriterImpl(String baseDirectoryName, FileNameMapper fileNameMapper) {
+ baseDir = new File(baseDirectoryName);
+ baseDir.mkdirs();
+
+ this.fileNameMapper = fileNameMapper;
+ }
+
+ 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()));
+ outFile.createNewFile();
+
+ fos = new FileOutputStream(outFile);
+ ByteStreams.copy(is, fos);
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,101 @@
+/*
+ * 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 java.util.Collection;
+import java.util.Set;
+
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.scanners.TypeAnnotationsScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+import org.reflections.vfs.Vfs;
+import org.reflections.vfs.Vfs.Dir;
+import org.reflections.vfs.Vfs.File;
+import org.reflections.vfs.ZipDir;
+import org.richfaces.cdk.ResourcesScanner;
+import org.richfaces.resource.DynamicResource;
+
+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 Predicate<File> IS_FACES_CONFIG = new
Predicate<File>() {
+
+ public boolean apply(File input) {
+ return
input.getRelativePath().endsWith("META-INF/faces-config.xml");
+ }
+
+ };
+
+ private static boolean containsFacesConfig(Dir dir) {
+ return Iterators.any(dir.getFiles().iterator(), IS_FACES_CONFIG);
+ }
+
+ private static final Predicate<URL> FACES_URL = new Predicate<URL>() {
+
+ public boolean apply(URL input) {
+ Dir dir = Vfs.fromURL(input);
+ if (dir instanceof ZipDir) {
+ return containsFacesConfig(dir);
+ } else {
+ return true;
+ }
+ }
+ };
+
+ private Collection<Class<?>> classResources = Sets.newHashSet();
+
+ private Collection<URL> urlResources = Sets.newHashSet();
+
+ public void scan() {
+ Collection<URL> urls =
Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
+
+ Reflections refl = new Reflections(new
ConfigurationBuilder().setUrls(urls).setScanners(new SubTypesScanner(), new
TypeAnnotationsScanner()));
+
+ Set<Class<?>> resources =
refl.getTypesAnnotatedWith(DynamicResource.class);
+
+ //TODO - reflections doesn't handle @Inherited correctly
+ for (Class<?> resourceClass : resources) {
+ classResources.add(resourceClass);
+ classResources.addAll(refl.getSubTypesOf(resourceClass));
+ }
+ }
+
+ public Collection<Class<?>> getClassResources() {
+ return classResources;
+ }
+
+ public Collection<URL> getURLResources() {
+ return urlResources;
+ }
+
+}
Added:
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
(rev 0)
+++
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-23
17:49:26 UTC (rev 18222)
@@ -0,0 +1,135 @@
+/*
+ * 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.task;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.faces.application.Resource;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.Faces;
+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;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceTaskFactoryImpl implements ResourceTaskFactory {
+
+ private class ResourcesRendererCallable implements Callable<Object> {
+
+ private Faces faces;
+
+ private String skinName;
+
+ private Iterable<Resource> resources;
+
+ ResourcesRendererCallable(String skinName, Iterable<Resource> resources) {
+ this.skinName = skinName;
+ this.resources = resources;
+ }
+
+ private void renderResource(Resource resource) throws Exception {
+ try {
+ faces.startRequest();
+ faces.setSkin(skinName);
+
+ if (resource instanceof StateHolderResource) {
+ StateHolderResource stateHolderResource = (StateHolderResource)
resource;
+ ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
+ stateHolderResource.writeState(FacesContext.getCurrentInstance(),
dataOutput);
+
+ //TODO use collected data
+ } else if (resource instanceof StateHolder) {
+ StateHolder stateHolder = (StateHolder) resource;
+ if (!stateHolder.isTransient()) {
+ Object savedData =
stateHolder.saveState(FacesContext.getCurrentInstance());
+ //TODO use collected data
+ }
+ }
+
+ resourceWriter.writeResource(faces.getSkin(), resource);
+ } finally {
+ faces.stopRequest();
+ }
+ }
+
+ public Object call() throws Exception {
+ try {
+ faces = new FacesImpl();
+ faces.start();
+
+ for (Resource resource : resources) {
+ renderResource(resource);
+ }
+
+ } finally {
+ faces.stop();
+ faces = null;
+ }
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+
+ private ResourceWriter resourceWriter;
+
+ private Iterable<Resource> resources = Collections.emptySet();
+
+ private Iterable<String> skins = Collections.emptySet();
+
+ public ResourceTaskFactoryImpl(ResourceWriter resourceWriter) {
+ super();
+ this.resourceWriter = resourceWriter;
+ }
+
+ public void setResources(Iterable<Resource> resources) {
+ this.resources = resources;
+ }
+
+ public void setSkins(Iterable<String> skins) {
+ this.skins = skins;
+ }
+
+ public Collection<Callable<Object>> createTasks() {
+ List<Callable<Object>> result = Lists.newArrayList();
+
+ for (String skin : skins) {
+ result.add(new ResourcesRendererCallable(skin, resources));
+ }
+
+ return result;
+ }
+}