Added: struts/sandbox/trunk/tiles/tiles-factory/pom.xml
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/pom.xml?view=auto&rev=468525
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-factory/pom.xml (added)
+++ struts/sandbox/trunk/tiles/tiles-factory/pom.xml Fri Oct 27 13:33:53 2006
@@ -0,0 +1,114 @@
+<?xml version="1.0"?>
+<!--
+/* 
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+-->
+<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/maven-v4_0_0.xsd";>
+
+    <parent>
+        <groupId>org.apache.struts.tiles</groupId>
+        <artifactId>tiles-parent</artifactId>
+        <version>2.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>tiles-factory</artifactId>
+    <packaging>jar</packaging>
+    <name>Tiles - Factories</name>
+
+    <build>
+
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+            <resource>
+                <directory>.</directory>
+                <includes>
+                    <include>LICENSE.txt</include>
+                    <include>NOTICE.txt</include>
+                </includes>
+                <targetPath>META-INF</targetPath>
+            </resource>
+        </resources>
+
+        <testResources>
+            <testResource>
+                <directory>src/test/java</directory>
+                <includes>
+                    <include>**/*.xml</include>
+                    <include>**/*.properties</include>
+                </includes>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+
+    </build>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.struts.tiles</groupId>
+            <artifactId>tiles-core</artifactId>
+            <version>${pom.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.3</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.portlet</groupId>
+            <artifactId>portlet-api</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.2</version>
+            <scope>test></scope>
+        </dependency>
+        
+    </dependencies>
+</project>

Propchange: struts/sandbox/trunk/tiles/tiles-factory/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/sandbox/trunk/tiles/tiles-factory/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java?view=auto&rev=468525
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java
 Fri Oct 27 13:33:53 2006
@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tiles.factory;
+
+/**
+ *
+ * 
+ */
+public class ConfigurationNotSupportedException extends Exception {
+
+
+    public ConfigurationNotSupportedException() {
+    }
+
+    public ConfigurationNotSupportedException(String string) {
+        super(string);
+    }
+
+    public ConfigurationNotSupportedException(String string, Throwable 
throwable) {
+        super(string, throwable);
+    }
+
+    public ConfigurationNotSupportedException(Throwable throwable) {
+        super(throwable);
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/ConfigurationNotSupportedException.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java?view=auto&rev=468525
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
 Fri Oct 27 13:33:53 2006
@@ -0,0 +1,55 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tiles.factory;
+
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesConfig;
+import org.apache.tiles.definition.UrlDefinitionsFactory;
+import org.apache.tiles.impl.BasicTilesContainer;
+
+/**
+ * Factory provided for convenience.
+ * This factory creates a default implementation of
+ * the container, initializes, and puts it into service.
+ *
+ * @since 2.0
+ * @version $Rev$
+ *
+ */
+public class TilesContainerFactory {
+
+    public static TilesContainer createContainer(Object context)
+        throws ConfigurationNotSupportedException {
+
+        TilesContainer container = new BasicTilesContainer();
+
+        TilesApplicationContext tilesContext =
+            TilesContextFactory.createApplicationContext(context);
+
+        TilesConfig config = new TilesConfig();
+        config.setApplicationContext(tilesContext);
+        config.setInitParameter(
+            TilesConfig.DEFINITIONS_FACTORY_CLASS_NAME_ATTR_KEY,
+            UrlDefinitionsFactory.class.getName()
+        );
+
+        container.init(config);
+        return container;
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java?view=auto&rev=468525
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java
 Fri Oct 27 13:33:53 2006
@@ -0,0 +1,71 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.factory;
+
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesRequestContext;
+import org.apache.tiles.context.servlet.ServletTilesApplicationContext;
+import org.apache.tiles.context.servlet.ServletTilesRequestContext;
+import org.apache.tiles.context.portlet.PortletTilesApplicationContext;
+import org.apache.tiles.context.portlet.PortletTilesRequestContext;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+
+public class TilesContextFactory {
+
+    public static TilesApplicationContext createApplicationContext(Object 
context)
+        throws ConfigurationNotSupportedException {
+        if (context instanceof ServletContext) {
+            ServletContext servletContext = (ServletContext) context;
+            return new ServletTilesApplicationContext(servletContext);
+
+        } else if (context instanceof PortletContext) {
+            PortletContext portletContext = (PortletContext) context;
+            return new PortletTilesApplicationContext(portletContext);
+        } else {
+            throw new ConfigurationNotSupportedException("Invalid context 
specified. "
+                    + context.getClass().getName());
+        }
+    }
+
+    public static TilesRequestContext 
createRequestContext(TilesApplicationContext context,
+                                                    Object request,
+                                                    Object response)
+        throws ConfigurationNotSupportedException {
+        if (context instanceof ServletTilesApplicationContext) {
+            ServletTilesApplicationContext app = 
(ServletTilesApplicationContext) context;
+            return new ServletTilesRequestContext(app.getServletContext(),
+                    (HttpServletRequest) request,
+                    (HttpServletResponse) response);
+        } else if (context instanceof PortletContext) {
+            PortletTilesApplicationContext app = 
(PortletTilesApplicationContext) context;
+            return new PortletTilesRequestContext(app.getPortletContext(),
+                    (PortletRequest) request,
+                    (PortletResponse) response);
+        } else {
+            throw new ConfigurationNotSupportedException("Invalid context 
specified. "
+                    + context.getClass().getName());
+        }
+    }
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/main/java/org/apache/tiles/factory/TilesContextFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java?view=auto&rev=468525
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java
 Fri Oct 27 13:33:53 2006
@@ -0,0 +1,40 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tiles.factory;
+
+import junit.framework.TestCase;
+
+import javax.servlet.ServletContext;
+
+import org.easymock.EasyMock;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.context.servlet.ServletTilesApplicationContext;
+import org.apache.tiles.impl.BasicTilesContainer;
+
+
+public class TilesContainerFactoryTest extends TestCase {
+
+    public void testCreateContainer() throws 
ConfigurationNotSupportedException {
+        ServletContext context = 
(ServletContext)EasyMock.createMock(ServletContext.class);
+        TilesContainer container = 
TilesContainerFactory.createContainer(context);
+
+        assertEquals(BasicTilesContainer.class, container.getClass());
+        assertEquals(ServletTilesApplicationContext.class, 
container.getApplicationContext().getClass());
+    }
+
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Added: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java?view=auto&rev=468525
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java
 Fri Oct 27 13:33:53 2006
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tiles.factory;
+
+import org.easymock.EasyMock;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.context.servlet.ServletTilesApplicationContext;
+import org.apache.tiles.context.portlet.PortletTilesApplicationContext;
+
+import javax.servlet.ServletContext;
+import javax.portlet.PortletContext;
+
+import junit.framework.TestCase;
+
+public class TilesContextFactoryTest extends TestCase {
+
+    public void testCreateApplicationContext() throws 
ConfigurationNotSupportedException {
+        Object context = EasyMock.createMock(ServletContext.class);
+
+        TilesApplicationContext tac = 
TilesContextFactory.createApplicationContext(context);
+        assertEquals(ServletTilesApplicationContext.class, tac.getClass());
+
+        context = EasyMock.createMock(PortletContext.class);
+        tac = TilesContextFactory.createApplicationContext(context);
+        assertEquals(PortletTilesApplicationContext.class, tac.getClass());
+    }
+
+}

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/sandbox/trunk/tiles/tiles-factory/src/test/java/org/apache/tiles/factory/TilesContextFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date


Reply via email to