Author: apetrelli
Date: Fri Sep 25 10:26:05 2009
New Revision: 818810

URL: http://svn.apache.org/viewvc?rev=818810&view=rev
Log:
TILES-436
Added example portlet in tiles-test.

Added:
    
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/
    
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
   (with props)
    
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
   (with props)
    tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/
    tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp   
(with props)
    
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
   (with props)
    tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml   
(with props)
Modified:
    tiles/framework/trunk/tiles-test/pom.xml

Modified: tiles/framework/trunk/tiles-test/pom.xml
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/pom.xml?rev=818810&r1=818809&r2=818810&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-test/pom.xml (original)
+++ tiles/framework/trunk/tiles-test/pom.xml Fri Sep 25 10:26:05 2009
@@ -42,6 +42,11 @@
          <artifactId>tiles-extras</artifactId>
          <version>${pom.version}</version>
       </dependency>
+      <dependency>
+         <groupId>${pom.groupId}</groupId>
+         <artifactId>tiles-portlet</artifactId>
+         <version>${pom.version}</version>
+      </dependency>
 
       <dependency>
         <groupId>org.slf4j</groupId>
@@ -62,6 +67,12 @@
          <scope>provided</scope>
       </dependency>
       <dependency>
+         <groupId>javax.portlet</groupId>
+         <artifactId>portlet-api</artifactId>
+         <version>2.0</version>
+         <scope>provided</scope>
+      </dependency>
+      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
@@ -88,6 +99,12 @@
           </exclusion>
         </exclusions>
       </dependency>
+      <dependency>
+       <groupId>org.apache.portals.pluto</groupId>
+       <artifactId>pluto-taglib</artifactId>
+       <version>2.0.0</version>
+       <scope>provided</scope>
+      </dependency>
    </dependencies>
 
    <build>

Added: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java?rev=818810&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
 (added)
+++ 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
 Fri Sep 25 10:26:05 2009
@@ -0,0 +1,102 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.test.portlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletSession;
+import javax.portlet.PortletURL;
+import javax.portlet.ProcessAction;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.portlet.context.PortletUtil;
+
+/**
+ * Test Portlet.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPortlet extends GenericPortlet {
+
+    /** {...@inheritdoc} */
+    @Override
+    protected void doView(RenderRequest request, RenderResponse response)
+            throws PortletException, IOException {
+        PortletSession portletSession = request.getPortletSession();
+        String definition = (String) portletSession.getAttribute("definition");
+        if (definition != null) {
+            portletSession.removeAttribute("definition");
+            TilesContainer container = PortletUtil.getCurrentContainer(request,
+                    getPortletContext());
+            if (container.isValidDefinition(definition, request, response,
+                    getPortletContext())) {
+                container.render(definition, request, response,
+                        getPortletContext());
+                addBackLink(response);
+            } else {
+                PortletRequestDispatcher dispatcher = getPortletContext()
+                        .getRequestDispatcher(
+                                "/WEB-INF/jsp/nosuchdefinition.jsp");
+                dispatcher.forward(request, response);
+                addBackLink(response);
+            }
+        } else {
+            PortletRequestDispatcher dispatcher = getPortletContext()
+                    .getRequestDispatcher("/WEB-INF/jsp/index.jsp");
+            dispatcher.forward(request, response);
+        }
+    }
+
+
+    /**
+     * Puts the definition name in a session attribue.
+     *
+     * @param request The portlet request.
+     * @param response The portlet response.
+     */
+    @ProcessAction(name = "showDefinition")
+    public void showDefinition(ActionRequest request, ActionResponse response) 
{
+        request.getPortletSession().setAttribute("definition",
+                request.getParameter("definition"));
+    }
+
+    /**
+     * Adds a link to the response to go back.
+     *
+     * @param response The portlet response.
+     * @throws IOException If something goes wrong.
+     */
+    private void addBackLink(RenderResponse response) throws IOException {
+        PrintWriter writer = response.getWriter();
+        writer.append("<a href=\"");
+        PortletURL url = response.createRenderURL();
+        writer.append(url.toString());
+        writer.append("\"> Back to definition selection</a>");
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/TestPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html?rev=818810&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
 (added)
+++ 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
 Fri Sep 25 10:26:05 2009
@@ -0,0 +1,30 @@
+<!--
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+-->
+<html>
+<head>
+    <title>Test portlets.</title>
+</head>
+<body>
+Test portlets for Tiles evaluation.
+</body>
+</html>
\ No newline at end of file

Propchange: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-test/src/main/java/org/apache/tiles/test/portlet/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp?rev=818810&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp 
(added)
+++ tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp Fri 
Sep 25 10:26:05 2009
@@ -0,0 +1,43 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%...@taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0"; %>
+<%--
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+--%>
+<portlet:defineObjects/>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+<p>Type a definition name to render it.</p>
+<form action="<portlet:actionURL name='showDefinition' />" method="post">
+       <label for="definitionName">Definition name:</label><input 
id="definitionName" type="text" name="definition" />
+       <input type="submit" value="Render" />
+</form>
+
+
+</body>
+</html>
\ No newline at end of file

Propchange: 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/index.jsp
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp?rev=818810&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
 (added)
+++ 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
 Fri Sep 25 10:26:05 2009
@@ -0,0 +1,35 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%--
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ *
+ */
+--%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+No definition here!
+</body>
+</html>
\ No newline at end of file

Propchange: 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/jsp/nosuchdefinition.jsp
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml?rev=818810&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml (added)
+++ tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml Fri 
Sep 25 10:26:05 2009
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+-->
+<portlet-app
+  xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd 
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd";
+  version="2.0">
+
+  <portlet>
+    <portlet-name>TestPortlet</portlet-name>
+    <display-name>TestPortlet</display-name>
+    <portlet-class>
+      org.apache.tiles.test.portlet.TestPortlet
+    </portlet-class>
+    <supports>
+      <mime-type>text/html</mime-type>
+      <portlet-mode>VIEW</portlet-mode>
+    </supports>
+    <portlet-info>
+      <title>TestPortlet</title>
+    </portlet-info>
+  </portlet>
+</portlet-app>

Propchange: tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-test/src/main/webapp/WEB-INF/portlet.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to