You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2014/11/25 13:50:11 UTC
[06/19] portals-pluto git commit: Renamed PortletHubDemo directory.
Started work on Ajax Action demo portlets.
Renamed PortletHubDemo directory. Started work on Ajax Action demo portlets.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/921477ca
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/921477ca
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/921477ca
Branch: refs/heads/PortletHub
Commit: 921477cab05aa504ba9b4bf2e4b84dbf2e11279b
Parents: ae45017
Author: Scott Nicklous <ms...@apache.org>
Authored: Fri Nov 21 19:19:17 2014 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Fri Nov 21 19:19:17 2014 +0100
----------------------------------------------------------------------
PortletHubDemo/pom.xml | 145 ++++++++++++
.../java/basic/portlet/ColorSelPortlet.java | 203 ++++++++++++++++
.../src/main/java/basic/portlet/Constants.java | 46 ++++
.../java/basic/portlet/ImageSelPortlet.java | 234 +++++++++++++++++++
.../java/basic/portlet/MessageBoxPortlet.java | 181 ++++++++++++++
.../java/basic/portlet/ResourcePortlet.java | 202 ++++++++++++++++
.../src/main/webapp/WEB-INF/jsp/view.jsp | 27 +++
.../src/main/webapp/WEB-INF/portlet.xml | 109 +++++++++
PortletHubDemo/src/main/webapp/WEB-INF/web.xml | 4 +
.../src/main/webapp/resources/css/styles.css | 16 ++
.../main/webapp/resources/images/FullMoon.gif | Bin 0 -> 38190 bytes
.../webapp/resources/images/baseball-trans.gif | Bin 0 -> 8307 bytes
.../webapp/resources/images/fussball-trans.gif | Bin 0 -> 8733 bytes
.../webapp/resources/images/golfball-trans.gif | Bin 0 -> 9359 bytes
pluto-PortletHubDemo/pom.xml | 145 ------------
.../java/basic/portlet/ColorSelPortlet.java | 140 -----------
.../src/main/java/basic/portlet/Constants.java | 32 ---
.../java/basic/portlet/ImageSelPortlet.java | 234 -------------------
.../java/basic/portlet/ResourcePortlet.java | 202 ----------------
.../src/main/webapp/WEB-INF/jsp/view.jsp | 27 ---
.../src/main/webapp/WEB-INF/portlet.xml | 77 ------
.../src/main/webapp/WEB-INF/web.xml | 4 -
.../src/main/webapp/resources/css/styles.css | 16 --
.../main/webapp/resources/images/FullMoon.gif | Bin 38190 -> 0 bytes
.../webapp/resources/images/baseball-trans.gif | Bin 8307 -> 0 bytes
.../webapp/resources/images/fussball-trans.gif | Bin 8733 -> 0 bytes
.../webapp/resources/images/golfball-trans.gif | Bin 9359 -> 0 bytes
pom.xml | 2 +-
28 files changed, 1168 insertions(+), 878 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/pom.xml
----------------------------------------------------------------------
diff --git a/PortletHubDemo/pom.xml b/PortletHubDemo/pom.xml
new file mode 100644
index 0000000..9f5efb4
--- /dev/null
+++ b/PortletHubDemo/pom.xml
@@ -0,0 +1,145 @@
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.portals.pluto</groupId>
+ <artifactId>pluto</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>PortletHubDemo</artifactId>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.portlet</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- for eclipse JSP tooling purposes -->
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.portals.pluto</groupId>
+ <artifactId>pluto-taglib</artifactId>
+ <version>2.1.0-M3</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>PortletHubDemo</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <archiveClasses>true</archiveClasses>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>pluto</id>
+ <activation>
+ <property>
+ <name>!alwaysActivate</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>taglibs</groupId>
+ <artifactId>standard</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
+ </configuration>
+ </plugin>
+ <!-- bind 'pluto:assemble' goal to 'generate-resources' lifecycle -->
+ <plugin>
+ <groupId>org.apache.portals.pluto</groupId>
+ <artifactId>maven-pluto-plugin</artifactId>
+ <version>${project.version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.portals.pluto</groupId>
+ <artifactId>pluto-util</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>assemble</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- workaround for war processing of m-r-r-plugin causing the generated NOTICE and LICENSE file to be put under WEB-INF/classes/META-INF -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
+ <attached>false</attached>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java b/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
new file mode 100644
index 0000000..d0a7667
--- /dev/null
+++ b/PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
@@ -0,0 +1,203 @@
+/* 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 basic.portlet;
+
+import static basic.portlet.Constants.*;
+
+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.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.xml.namespace.QName;
+
+
+/**
+ * A management portlet that displays the current deep link configuraion
+ */
+public class ColorSelPortlet extends GenericPortlet {
+
+ // Set up logging
+ // private static final String LOG_CLASS = ColorSelPortlet.class.getName();
+ // private final Logger logger = Logger.getLogger(LOG_CLASS);
+
+ protected void doView(RenderRequest req, RenderResponse resp)
+ throws PortletException, IOException {
+
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.write("<h3>Color Selector & Message Sender</h3><hr/>\n");
+
+ String pid = resp.getNamespace();
+
+ String msg = req.getParameter(PARAM_ERRMSG);
+ String clr = req.getParameter(PARAM_COLOR);
+ clr = (clr == null) ? "#FFFFFF" : clr;
+
+ String[] vals = req.getParameterValues(PARAM_FG_COLOR);
+ String r = "";
+ String g = "";
+ String b = "";
+ if (vals != null) {
+ for (String v : vals) {
+ if (v.equals(PARAM_FG_RED)) r = "checked";
+ if (v.equals(PARAM_FG_GREEN)) g = "checked";
+ if (v.equals(PARAM_FG_BLUE)) b = "checked";
+ }
+ }
+
+ writer.write("<FORM id='" + pid + "-setParams' onsubmit='return false;'>");
+ writer.write(" <table><tr><td align='left'>");
+
+ writer.write(" Enter background color (public param):");
+ writer.write(" </td><td colspan=3>");
+ writer.write(" <input name='" + PARAM_COLOR + "' type='text' value='" + clr + "' size='10' maxlength='10'>");
+ writer.write(" </td><td>");
+ if (msg != null) {
+ writer.write(msg);
+ }
+ writer.write(" </td></tr><tr><td>");
+
+ writer.write(" Select active foreground colors:");
+ writer.write(" </td><td>");
+ writer.write(" <input name='" + PARAM_FG_COLOR + "' value='" + PARAM_FG_RED + "' type='checkbox' " + r + ">");
+ writer.write(" </td><td>Red");
+ writer.write(" </td><td>");
+ writer.write(" <input name='" + PARAM_FG_COLOR + "' value='" + PARAM_FG_GREEN + "' type='checkbox' " + g + ">");
+ writer.write(" </td><td>Green");
+ writer.write(" </td><td>");
+ writer.write(" <input name='" + PARAM_FG_COLOR + "' value='" + PARAM_FG_BLUE + "' type='checkbox' " + b + ">");
+ writer.write(" </td><td>Blue");
+
+ writer.write(" </td></tr><tr><td>");
+ writer.write(" Enter message:");
+ writer.write(" </td><td colspan=6>");
+ writer.write(" <input name='" + PARAM_MSG_INPUT + "' type='text' value='' size='50' maxlength='50'>");
+ writer.write(" </td><td>");
+
+ writer.write(" </td></tr><tr><td>");
+ writer.write(" <INPUT VALUE='send' CLASS='portlet-form-button' TYPE='submit'>");
+ writer.write(" </td></tr></table>");
+ writer.write("</FORM>");
+ writer.write("<p><hr/></p>\n");
+
+ writer.write("<script>\n");
+ writer.write("(function () {\n");
+ writer.write(" var pid = '" + pid + "',\n");
+ writer.write(" colorEntry = '" + pid + "-color',\n");
+ writer.write(" msgdiv = '" + pid + "-putMsgHere',\n");
+ writer.write(" currState,\n");
+ writer.write(" portletInit;\n");
+
+ writer.write(" var update = function (type, state) {\n");
+ writer.write(" var oldColor = ((currState === undefined) || (currState.parameters.color === undefined)) ? '#FFFFFF' : currState.parameters.color[0];\n");
+ writer.write(" var newColor = (state.parameters.color === undefined) ? '#FFFFFF' : state.parameters.color[0];\n");
+ writer.write(" console.log(\"CSP: state updated. color=\" + newColor);\n");
+ writer.write(" if ((currState === undefined) || (newColor !== oldColor)) {\n");
+ writer.write(" document.getElementById(msgdiv).innerHTML = '';\n");
+ writer.write(" document.getElementById(colorEntry).value = newColor;\n");
+ writer.write(" }\n");
+ writer.write(" currState = state;\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+
+ writer.write(" var handleEntry = function () {\n");
+ writer.write(" var oldColor = ((currState === undefined) || (currState.parameters.color === undefined)) ? '#FFFFFF' : currState.parameters.color[0];\n");
+ writer.write(" var newColor = this.value;\n");
+ writer.write(" console.log(\"CSP: entry field updated. color=\" + newColor);\n");
+ writer.write(" if ((newColor === undefined) || (newColor === null) || !newColor.match(\"^#(?:[A-Fa-f0-9]{3}){1,2}$\")) {\n");
+ writer.write(" document.getElementById(msgdiv).innerHTML = 'Bad color. Enter #xxxxxx or #xxx.';\n");
+ writer.write(" } else {\n");
+ writer.write(" var newState = portletInit.cloneState(currState);\n");
+ writer.write(" newState.parameters.color = [newColor];\n");
+ writer.write(" portletInit.setPortletState(newState);\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" document.getElementById(colorEntry).onchange = handleEntry;\n");
+ writer.write(" \n");
+
+ writer.write(" portlet.register(pid).then(function (pi) {\n");
+ writer.write(" console.log(\"CSP Color Selection Portlet: registered: \" + pid);\n");
+ writer.write(" portletInit = pi;\n");
+ writer.write(" portletInit.addEventListener(\"portlet.onStateChange\", update);\n");
+ writer.write(" });\n");
+ writer.write(" \n");
+ writer.write(" \n");
+ writer.write("})();\n");
+ writer.write("</script>\n");
+}
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
+ */
+ @Override
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, IOException {
+ }
+
+ public void processAction(ActionRequest req, ActionResponse resp)
+ throws PortletException, IOException {
+
+ // pass the action params from the form submission as render parameters
+ resp.setRenderParameter(PARAM_ERRMSG, "");
+ String val = req.getParameter(PARAM_COLOR);
+ if (val != null) {
+ if (val.matches("^#(?:[A-Fa-f0-9]{3}){1,2}$")) {
+ resp.setRenderParameter(PARAM_COLOR, val);
+ } else {
+ resp.setRenderParameter(PARAM_ERRMSG, "bad color. try again.");
+ }
+ } else {
+ resp.setRenderParameter(PARAM_ERRMSG, "enter color #xxxxxx or #xxx.");
+ }
+
+ String[] vals = req.getParameterValues(PARAM_FG_COLOR);
+ String r = "0";
+ String g = "0";
+ String b = "0";
+ if (vals != null) {
+ for (String v : vals) {
+ if (v.equals(PARAM_FG_RED)) r = "F";
+ if (v.equals(PARAM_FG_GREEN)) g = "F";
+ if (v.equals(PARAM_FG_BLUE)) b = "F";
+ }
+ }
+
+ if (vals != null) {
+ resp.setRenderParameter(PARAM_FG_COLOR, vals);
+ }
+
+ String clr = "#" + r + g + b;
+ val = req.getParameter(PARAM_MSG_INPUT);
+
+ String msg = val + DELIM + clr;
+ QName qn = new QName(EVENT_NAMESPACE, EVENT_NAME);
+ resp.setEvent(qn, msg);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/java/basic/portlet/Constants.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/Constants.java b/PortletHubDemo/src/main/java/basic/portlet/Constants.java
new file mode 100644
index 0000000..7b3ee48
--- /dev/null
+++ b/PortletHubDemo/src/main/java/basic/portlet/Constants.java
@@ -0,0 +1,46 @@
+package basic.portlet;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Constants {
+
+ // maps the names of the images to the paths to the images -
+ public final static Map<String, String> imgMap = new HashMap<String, String>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put("baseball", "/resources/images/baseball-trans.gif");
+ put("golfball", "/resources/images/golfball-trans.gif");
+ put("fussball", "/resources/images/fussball-trans.gif");
+ }};
+
+ public final static String DEFAULT_IMAGE = "/resources/images/FullMoon.gif";
+
+ public final static String PARAM_SELTYPE = "selType";
+ public final static String PARAM_SELTYPE_RADIO = "radio";
+ public final static String PARAM_SELTYPE_DROPDOWN = "dropdown";
+
+ public final static String PARAM_IMGNAME = "imgName";
+ public final static String PARAM_COLOR = "color";
+ public final static String PARAM_ERRMSG = "errmsg";
+ public final static String PARAM_BORDER = "bo";
+ public final static String PARAM_BORDER_COLOR = "border";
+ public final static String PARAM_CACHE = "ca";
+ public final static String PARAM_CACHE_PAGE = "pa";
+ public final static String PARAM_CACHE_PORTLET = "po";
+ public final static String PARAM_CACHE_FULL = "fu";
+
+ public final static String PARAM_FG_COLOR = "fgcolor";
+ public final static String PARAM_FG_RED = "red";
+ public final static String PARAM_FG_GREEN = "green";
+ public final static String PARAM_FG_BLUE = "blue";
+ public final static String PARAM_MSG_INPUT = "imsg";
+
+ public final static String PARAM_NUM_MSGS = "numMsgs";
+ public final static String ATTRIB_MSGS = "msgs";
+
+ public final static String EVENT_NAMESPACE = "http://www.apache.org/portals/pluto/pub-render-params/ResourcePortlet";
+ public final static String EVENT_NAME = "Message";
+
+ public final static String DELIM = ";%;";
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java b/PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
new file mode 100644
index 0000000..4ed5c7b
--- /dev/null
+++ b/PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
@@ -0,0 +1,234 @@
+/* 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 basic.portlet;
+
+import static basic.portlet.Constants.PARAM_IMGNAME;
+import static basic.portlet.Constants.PARAM_SELTYPE;
+import static basic.portlet.Constants.PARAM_SELTYPE_RADIO;
+import static basic.portlet.Constants.imgMap;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+
+
+/**
+ * A management portlet that displays the current deep link configuraion
+ */
+public class ImageSelPortlet extends GenericPortlet {
+
+ // Set up logging
+ private static final String LOG_CLASS = ImageSelPortlet.class.getName();
+ private final Logger logger = Logger.getLogger(LOG_CLASS);
+
+ protected void doView(RenderRequest req, RenderResponse resp)
+ throws PortletException, IOException {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.logp(Level.FINE, this.getClass().getName(), "doView", "Entry");
+ }
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.write("<h3>Image Selector</h3><hr/>\n");
+
+ String pid = resp.getNamespace();
+ String selType = req.getParameter(PARAM_SELTYPE);
+ selType = (selType == null) ? PARAM_SELTYPE_RADIO : selType;
+ String imgName = req.getParameter(PARAM_IMGNAME);
+ imgName = (imgName == null) ? "default" : imgName;
+
+ writer.write("<FORM id='" + pid + "-setParams' onsubmit='return false;'>");
+ writer.write(" <table><tr><td align='left'>");
+ writer.write(" Selection type (private param):");
+ writer.write(" </td><td>");
+ writer.write(" <input id='" + pid + "-radio' type='radio' name='selType' value='radio'>Radio Button");
+ writer.write(" <input id='" + pid + "-dropdown' type='radio' name='selType' value='dropdown'>Drop Down");
+ writer.write(" </td></tr><tr><td>");
+ writer.write(" Select Image (public param):");
+ writer.write(" </td><td>");
+
+ writer.write(" <div id='" + pid + "-putResourceHere'></div>\n");
+
+ writer.write(" </td></tr></table>");
+ writer.write("</FORM>");
+ writer.write("<p><hr/></p>\n");
+
+ writer.write("<script>\n");
+ writer.write("(function () {\n");
+ writer.write(" var pid = '" + pid + "',\n");
+ writer.write(" fid = '" + pid + "-setParams',\n");
+ writer.write(" resdiv = '" + pid + "-putResourceHere',\n");
+ writer.write(" st_radio = '" + pid + "-radio',\n");
+ writer.write(" st_dropdown = '" + pid + "-dropdown',\n");
+ writer.write(" selBox = '" + pid + "-selBox',\n");
+ writer.write(" \n");
+ writer.write(" last_st = 'radio',\n");
+ writer.write(" lastImg = 'default',\n");
+ writer.write(" currState,\n");
+ writer.write(" portletInit;\n");
+ writer.write(" \n");
+ writer.write(" // Set image name PRP if radio button clicked - \n");
+ writer.write(" var handleImgRadio = function () {\n");
+ writer.write(" console.log(\"ISP: image selected (radio): \" + this.value);\n");
+ writer.write(" \n");
+ writer.write(" if (currState.parameters.imgName !== this.value) {\n");
+ writer.write(" var newState = portletInit.cloneState(currState);\n");
+ writer.write(" newState.parameters.imgName = [this.value];\n");
+ writer.write(" portletInit.setPortletState(newState);\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+ writer.write(" // Set image name PRP if image selected in selection box - \n");
+ writer.write(" var handleImgDropdown = function () {\n");
+ writer.write(" console.log(\"ISP: image selected (dropdown): \" + this.value);\n");
+ writer.write(" \n");
+ writer.write(" if (currState.parameters.imgName !== this.value) {\n");
+ writer.write(" var newState = portletInit.cloneState(currState);\n");
+ writer.write(" newState.parameters.imgName = [this.value];\n");
+ writer.write(" portletInit.setPortletState(newState);\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+ writer.write(" var update = function (type, state) {\n");
+ writer.write(" var oldST = ((currState === undefined) || (currState.parameters.selType === undefined)) ? undefined : currState.parameters.selType[0];\n");
+ writer.write(" var newST = (state.parameters.selType === undefined) ? undefined : state.parameters.selType[0];\n");
+ writer.write(" var newImg = (state.parameters.imgName === undefined) ? undefined : state.parameters.imgName[0];\n");
+ writer.write(" console.log(\"ISP: state updated. selType=\" + newST + \", imgName=\" + newImg);\n");
+ writer.write(" \n");
+ writer.write(" if ((currState === undefined) || (oldST !== newST)) {");
+ writer.write(" portletInit.createResourceUrl({}).then(function (url) {\n");
+ writer.write(" console.log(\"ISP: got url: \" + url);\n");
+// writer.write(" document.getElementById(resdiv).innerHTML=\"Waiting for update.\";\n");
+ writer.write(" var xhr = new XMLHttpRequest();\n");
+ writer.write(" xhr.onreadystatechange=function() {\n");
+ writer.write(" if (xhr.readyState==4 && xhr.status==200) {\n");
+ writer.write(" document.getElementById(resdiv).innerHTML=xhr.responseText;\n");
+
+ writer.write(" // default is radio buttons\n");
+ writer.write(" var ii, f = document.getElementById(fid);\n");
+ writer.write(" if ((newST === undefined) || (newST === 'radio')) {\n");
+ writer.write(" for (ii=0; ii < f.imgName.length; ii++) {\n");
+ writer.write(" console.log(\"ISP: adding selection handler for: \" + f.imgName[ii].value);\n");
+ writer.write(" f.imgName[ii].onclick = handleImgRadio;\n");
+ writer.write(" if (f.imgName[ii].value === newImg) {\n");
+ writer.write(" console.log(\"ISP: image clicked: \" + newImg);\n");
+ writer.write(" f.imgName[ii].clicked = true;\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" } else if (newST === 'dropdown') {\n");
+ writer.write(" console.log(\"ISP: adding selection handler to dropdown list element: \" + selBox);\n");
+ writer.write(" document.getElementById(selBox).onchange = handleImgDropdown;\n");
+ writer.write(" for (ii=0; ii < f.imgName.length; ii++) {\n");
+ writer.write(" if (f.imgName[ii].value === newImg) {\n");
+ writer.write(" console.log(\"ISP: image selected: \" + newImg);\n");
+ writer.write(" f.imgName[ii].selected = true;\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+
+ writer.write(" }\n");
+ writer.write(" };\n");
+ writer.write(" xhr.open(\"GET\",url,true);\n");
+ writer.write(" xhr.send();\n");
+ writer.write(" });\n");
+ writer.write(" }\n");
+
+ writer.write(" if (newST === 'dropdown') {\n");
+ writer.write(" document.getElementById(st_dropdown).checked = true;\n");
+ writer.write(" } else {\n");
+ writer.write(" document.getElementById(st_radio).checked = true;\n");
+ writer.write(" }\n");
+
+ writer.write(" currState=state;\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+ writer.write(" // set private parameter selType to store the selection display type\n");
+ writer.write(" var handleST = function () {\n");
+ writer.write(" console.log(\"ISP: select display type clicked: \" + this.value);\n");
+ writer.write(" if (currState.parameters.selType !== this.value) {\n");
+ writer.write(" var newState = portletInit.cloneState(currState);\n");
+ writer.write(" newState.parameters.selType = [this.value];\n");
+ writer.write(" portletInit.setPortletState(newState);\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" document.getElementById(st_radio).onclick = handleST;\n");
+ writer.write(" document.getElementById(st_dropdown).onclick = handleST;\n");
+ writer.write(" \n");
+ writer.write(" portlet.register(pid).then(function (pi) {\n");
+ writer.write(" console.log(\"ISP Image Selection Portlet: registered: \" + pid);\n");
+ writer.write(" portletInit = pi;\n");
+ writer.write(" portletInit.addEventListener(\"portlet.onStateChange\", update);\n");
+ writer.write(" });\n");
+ writer.write(" \n");
+ writer.write(" \n");
+ writer.write("})();\n");
+ writer.write("</script>\n");
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
+ */
+ @Override
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, IOException {
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ String pid = resp.getNamespace();
+ Set<String> names = imgMap.keySet();
+ String selType = req.getParameter(PARAM_SELTYPE);
+ selType = (selType == null) ? PARAM_SELTYPE_RADIO : selType;
+ String imgName = req.getParameter(PARAM_IMGNAME);
+ imgName = (imgName == null) ? "default" : imgName;
+
+ if (selType.equals(PARAM_SELTYPE_RADIO)) {
+ for (String name : names) {
+ writer.write(" <input type='radio' name='" + PARAM_IMGNAME + "' value='" +
+ name + "'" + (name.equals(imgName) ? "checked" : "") + ">" + name);
+ }
+ } else {
+ writer.write("<select id='" + pid + "-selBox' name='" + PARAM_IMGNAME + "' size='1'>");
+ writer.write(" <option value='default' " +
+ ("default".equals(imgName) ? "selected" : "") + ">-</option>");
+ for (String name : names) {
+ writer.write(" <option value='" + name + "'" +
+ (name.equals(imgName) ? "selected" : "") + ">" + name + "</option>");
+ }
+ writer.write("</select>");
+ }
+ }
+
+ public void processAction(ActionRequest req, ActionResponse resp)
+ throws PortletException, IOException {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/java/basic/portlet/MessageBoxPortlet.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/MessageBoxPortlet.java b/PortletHubDemo/src/main/java/basic/portlet/MessageBoxPortlet.java
new file mode 100644
index 0000000..783c4e7
--- /dev/null
+++ b/PortletHubDemo/src/main/java/basic/portlet/MessageBoxPortlet.java
@@ -0,0 +1,181 @@
+/* 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 basic.portlet;
+
+import static basic.portlet.Constants.*;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
+
+/**
+ * A management portlet that displays the current deep link configuraion
+ */
+public class MessageBoxPortlet extends GenericPortlet {
+
+ // Set up logging
+ private static final String LOG_CLASS = MessageBoxPortlet.class.getName();
+ private final Logger logger = Logger.getLogger(LOG_CLASS);
+
+ protected void doView(RenderRequest req, RenderResponse resp)
+ throws PortletException, IOException {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.logp(Level.FINE, this.getClass().getName(), "doView", "Entry");
+ }
+
+ String pid = resp.getNamespace();
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ String style = "\"border-style:solid; border-width:3px; padding:4px; overflow:auto;" +
+ "border-color:#000088; min-height:70px; background:#E0E0E0;\"";
+
+ String aurl = resp.createActionURL().toString();
+
+ writer.write("<div style='clear:both;'>\n");
+ writer.write("<div style='float:left;'><h3>Image Viewer</h3></div>\n");
+ writer.write("<div style='float:right;'>\n");
+ writer.write("<form action='" + aurl + "' method='post'><input type='submit' name='action' value='clear' /></form>\n");
+ writer.write("</div>\n");
+ writer.write("</div><div style='clear:both;'><hr/>\n");
+ writer.write("<h3>Message Box Portlet</h3>\n");
+ writer.write("<p>Messages that arrive via events from other portlets are displayed in this box.</p>\n");
+ writer.write("<div id='" + pid + "-responseDiv' style=" + style + "></div>\n");
+ writer.write("</div>\n");
+
+ ResourceURL resurl = resp.createResourceURL();
+
+ writer.write("<script>\n");
+ writer.write("(function () {\n");
+ writer.write(" var xhr = new XMLHttpRequest();\n");
+ writer.write(" xhr.onreadystatechange=function() {\n");
+ writer.write(" if (xhr.readyState==4 && xhr.status==200) {\n");
+ writer.write(" document.getElementById('" + pid + "-responseDiv').innerHTML=xhr.responseText;\n");
+ writer.write(" }\n");
+ writer.write(" };\n");
+ writer.write(" xhr.open(\"GET\",\"" + resurl.toString() + "\",true);\n");
+ writer.write(" xhr.send();\n");
+ writer.write("})();\n");
+ writer.write("</script>\n");
+
+ }
+
+ @Override
+ public void processAction(ActionRequest req, ActionResponse resp)
+ throws PortletException, IOException {
+
+ // the only action for this portlet is to reset the stored messages
+
+ String actionName = req.getParameter("action");
+ if ("clear".equals(actionName)) {
+
+ ArrayList<String> msgs = new ArrayList<String>();
+ StringBuffer sb = new StringBuffer();
+ sb.append("<p style='margin:0px 5px 0px 5px; color:#00D;"
+ + " background-color:#AAF;'>");
+ sb.append("Reset - No messages.");
+ sb.append("</p>");
+ msgs.add(sb.toString());
+
+ resp.setRenderParameter(PARAM_NUM_MSGS, "0");
+ req.getPortletSession().setAttribute(ATTRIB_MSGS, msgs);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void processEvent(EventRequest req, EventResponse resp)
+ throws PortletException ,IOException {
+
+ ArrayList<String> msgs = (ArrayList<String>) req.getPortletSession().getAttribute(ATTRIB_MSGS);
+ if (msgs == null) {
+ msgs = new ArrayList<String>();
+ }
+
+ String[] msg;
+
+ try {
+ String val = (String) req.getEvent().getValue();
+ msg = val.split(DELIM);
+ } catch (Exception e) {
+ msg = new String[2];
+ msg[0] = "error getting message from event.";
+ msg[1] = "#D00";
+ }
+
+ String clr = req.getParameter(PARAM_COLOR);
+ clr = (clr == null) ? "#FFFFFF" : clr;
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("<p style='margin:0px 5px 0px 5px; color:" + msg[1]
+ + "; background-color:" + clr + ";'>");
+ sb.append("" + (msgs.size() + 1) + ": " + msg[0]);
+ sb.append("</p>");
+
+ msgs.add(sb.toString());
+
+ resp.setRenderParameter(PARAM_NUM_MSGS, Integer.toString(msgs.size()));
+ req.getPortletSession().setAttribute(ATTRIB_MSGS, msgs);
+ };
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, IOException {
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ ArrayList<String> msgs = (ArrayList<String>) req.getPortletSession().getAttribute(ATTRIB_MSGS);
+ if (msgs == null) {
+ msgs = new ArrayList<String>();
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("<p style='margin:0px 5px 0px 5px; color:#00D;"
+ + " background-color:#FFA;'>");
+ sb.append("No messages.");
+ sb.append("</p>");
+ msgs.add(sb.toString());
+ }
+
+ for (String msg : msgs) {
+ writer.write(msg);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/java/basic/portlet/ResourcePortlet.java
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/java/basic/portlet/ResourcePortlet.java b/PortletHubDemo/src/main/java/basic/portlet/ResourcePortlet.java
new file mode 100644
index 0000000..e9bcf63
--- /dev/null
+++ b/PortletHubDemo/src/main/java/basic/portlet/ResourcePortlet.java
@@ -0,0 +1,202 @@
+/* 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 basic.portlet;
+
+import static basic.portlet.Constants.PARAM_BORDER_COLOR;
+import static basic.portlet.Constants.PARAM_COLOR;
+import static basic.portlet.Constants.PARAM_IMGNAME;
+import static basic.portlet.Constants.imgMap;
+import static basic.portlet.Constants.DEFAULT_IMAGE;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+
+
+/**
+ * A management portlet that displays the current deep link configuraion
+ */
+public class ResourcePortlet extends GenericPortlet {
+
+ // Set up logging
+ private static final String LOG_CLASS = ResourcePortlet.class.getName();
+ private final Logger logger = Logger.getLogger(LOG_CLASS);
+
+
+ protected void doView(RenderRequest req, RenderResponse resp)
+ throws PortletException, IOException {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.logp(Level.FINE, this.getClass().getName(), "doView", "Entry");
+ }
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ String pid = resp.getNamespace();
+
+ writer.write("<div style='clear:both;'>\n");
+ writer.write("<div style='float:left;'><h3>Image Viewer</h3></div>\n");
+ writer.write("<div id=" + pid + "-counter style='float:right; font-size:250%; color:#0B0;'>1</div>\n");
+ writer.write("</div><div style='clear:both;'><hr/>\n");
+
+ writer.write("<FORM id='" + pid + "-setParams' onsubmit='return false;'>");
+ writer.write(" <table><tr><td align='left'>");
+ writer.write(" Cacheability setting:");
+ writer.write(" </td><td>");
+ writer.write(" <input id='" + pid + "-page' type='radio' name='cacheability' value='cacheLevelPage'>Page");
+ writer.write(" <input id='" + pid + "-portlet' type='radio' name='cacheability' value='cacheLevelPortlet'>Portlet");
+ writer.write(" <input id='" + pid + "-full' type='radio' name='cacheability' value='cacheLevelFull'>Full");
+ writer.write(" </td></tr><tr><td>");
+ writer.write(" Set border (resource parameter)");
+ writer.write(" </td><td>");
+ writer.write(" <input id='" + pid + "-border' type='checkbox' name='border' value='border'>");
+ writer.write(" </td></tr></table>");
+ writer.write("</FORM><hr/>");
+
+ writer.write("<div id='" + pid + "-putResourceHere'></div>\n");
+
+ writer.write("<script>\n");
+ writer.write("(function () {\n");
+ writer.write(" var pid = '" + pid + "',\n");
+ writer.write(" resdiv = '" + pid + "-putResourceHere',\n");
+ writer.write(" border = '" + pid + "-border',\n");
+ writer.write(" ca_page = '" + pid + "-page',\n");
+ writer.write(" ca_portlet = '" + pid + "-portlet',\n");
+ writer.write(" ca_full = '" + pid + "-full',\n");
+ writer.write(" \n");
+ writer.write(" state,\n");
+ writer.write(" resparms = {},\n");
+ writer.write(" cacheability = 'cacheLevelPage',\n");
+ writer.write(" portletInit;\n");
+ writer.write(" \n");
+ writer.write(" var update = function (type, state) {\n");
+ writer.write(" console.log(\"Resource Portlet: state updated.\");\n");
+ writer.write(" \n");
+ writer.write(" portletInit.createResourceUrl(resparms, cacheability).then(function (url) {\n");
+ writer.write(" var brdr = (resparms.border == undefined) ? undefined : resparms.border[0];\n");
+ writer.write(" console.log(\"Resource Portlet: got url: \" + url + \", res parm border=\" + brdr);\n");
+// writer.write(" document.getElementById(resdiv).innerHTML=\"Waiting for update.\";\n");
+ writer.write(" var xhr = new XMLHttpRequest();\n");
+ writer.write(" xhr.onreadystatechange=function() {\n");
+ writer.write(" if (xhr.readyState==4 && xhr.status==200) {\n");
+ writer.write(" document.getElementById(resdiv).innerHTML=xhr.responseText;\n");
+ writer.write(" }\n");
+ writer.write(" };\n");
+ writer.write(" xhr.open(\"GET\",url,true);\n");
+ writer.write(" xhr.send();\n");
+ writer.write(" });\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+ writer.write(" document.getElementById(border).checked = false;\n");
+ writer.write(" document.getElementById(border).onclick = function () {\n");
+ writer.write(" console.log(\"border checked: \" + this.checked);\n");
+ writer.write(" if (this.checked) {\n");
+ writer.write(" resparms.border = ['#00F'];\n");
+ writer.write(" } else {\n");
+ writer.write(" resparms = {};\n");
+ writer.write(" }\n");
+ writer.write(" update();\n");
+ writer.write(" }\n");
+ writer.write(" \n");
+ writer.write(" document.getElementById(ca_page).checked = true;\n");
+ writer.write(" var handleCA = function () {\n");
+ writer.write(" console.log(\"cacheability button clicked: \" + this.value);\n");
+ writer.write(" if (cacheability !== this.value) {\n");
+ writer.write(" cacheability = this.value;\n");
+ writer.write(" update();\n");
+ writer.write(" }\n");
+ writer.write(" }\n");
+ writer.write(" document.getElementById(ca_page).onclick = handleCA;\n");
+ writer.write(" document.getElementById(ca_portlet).onclick = handleCA;\n");
+ writer.write(" document.getElementById(ca_full).onclick = handleCA;\n");
+ writer.write(" \n");
+ writer.write(" portlet.register(pid).then(function (pi) {\n");
+ writer.write(" console.log(\"registered: \" + pid);\n");
+ writer.write(" portletInit = pi;\n");
+ writer.write(" portletInit.addEventListener(\"portlet.onStateChange\", update);\n");
+ writer.write(" });\n");
+ writer.write(" \n");
+ writer.write(" var cntrId = '" + pid + "-counter', cntr = 1;\n");
+ writer.write(" window.setInterval(function () {\n");
+ writer.write(" document.getElementById(cntrId).innerHTML = ++cntr;\n");
+ writer.write(" }, 1000);\n");
+ writer.write(" \n");
+ writer.write("})();\n");
+ writer.write("</script>\n");
+
+ writer.write("<p><hr/></p></div>\n");
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
+ */
+ @Override
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, IOException {
+
+ String key = req.getParameter(PARAM_IMGNAME);
+ String imgDir = DEFAULT_IMAGE;
+ if ((key != null) && imgMap.containsKey(key)) {
+ imgDir = imgMap.get(key);
+ }
+
+ String bc = req.getParameter(PARAM_BORDER_COLOR);
+ String imgStyle = "";
+ if (bc != null) {
+ imgStyle = " style='border:1px solid " + bc + ";' ";
+ }
+
+ String ctx = req.getContextPath();
+ String ca = req.getCacheability();
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ String clr = req.getParameter(PARAM_COLOR);
+ clr = (clr == null) ? "#FFFFFF" : clr;
+
+ writer.write("<div style='background-color:" + clr + ";'>\n");
+ writer.write(" <table style='background-color:" + clr + ";'>");
+ writer.write(" <tr><td align='center' style='background-color:" + clr + ";'>");
+ writer.write(" <img src='" + ctx + imgDir + "'" + imgStyle + ">\n");
+ writer.write(" </td><td style='background-color:" + clr + ";'>");
+ writer.write(" Cacheability: " + ca);
+ writer.write(" </td></tr>");
+ writer.write(" </table>");
+ writer.write("</div>\n");
+
+
+ }
+
+ public void processAction(ActionRequest req, ActionResponse resp)
+ throws PortletException, IOException {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view.jsp
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view.jsp b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view.jsp
new file mode 100644
index 0000000..b0ba96c
--- /dev/null
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/jsp/view.jsp
@@ -0,0 +1,27 @@
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<portlet:defineObjects />
+
+<H3>PRP Resource Portlet</H3>
+<P>Sample Resource Portlet application that demonstrates image loading based on a public render parameter.</P>
+
+<!-- Display a button that causes some parameters to be set -->
+<FORM METHOD="POST" ACTION="<portlet:actionURL/>">
+ <INPUT NAME='action' VALUE='setParms' TYPE="hidden">
+ <INPUT VALUE="Set Parameters" CLASS="portlet-form-button" TYPE="submit">
+</FORM>
+
+<!-- Display the parameters for the portlet -->
+<P>Parameters:</P>
+<UL>
+<c:forEach var="name" items="${renderRequest.getParameterNames()}">
+ <c:forEach var="value" items="${renderRequest.getParameterValues(name)}">
+ <LI>
+ Name: ${name}, Val: ${value}
+ </LI>
+ </c:forEach>
+</c:forEach>
+</UL>
+
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/WEB-INF/portlet.xml
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/portlet.xml b/PortletHubDemo/src/main/webapp/WEB-INF/portlet.xml
new file mode 100644
index 0000000..124964b
--- /dev/null
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/portlet.xml
@@ -0,0 +1,109 @@
+<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:rp="http://www.apache.org/portals/pluto/pub-render-params/ResourcePortlet"
+ 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"
+ id="ph.resource.portlet">
+ <portlet>
+ <portlet-name>PH-ResourcePortlet-PRP</portlet-name>
+ <display-name>PH Resource Portlet</display-name>
+
+ <portlet-class>basic.portlet.ResourcePortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>PH Resource Portlet</title>
+ </portlet-info>
+
+ <supported-public-render-parameter>imgName</supported-public-render-parameter>
+ <supported-public-render-parameter>color</supported-public-render-parameter>
+ </portlet>
+
+ <portlet>
+ <portlet-name>MessageBoxPortlet</portlet-name>
+ <display-name>Message Box Portlet</display-name>
+
+ <portlet-class>basic.portlet.MessageBoxPortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>PH Message Box Portlet</title>
+ </portlet-info>
+
+ <supported-processing-event>
+ <qname>rp:Message</qname>
+ </supported-processing-event>
+
+ <supported-public-render-parameter>color</supported-public-render-parameter>
+ </portlet>
+
+ <portlet>
+ <portlet-name>ImageSelPortlet</portlet-name>
+ <display-name>Image Selection Portlet</display-name>
+
+ <portlet-class>basic.portlet.ImageSelPortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>PH Image Selection Portlet</title>
+ </portlet-info>
+
+ <supported-public-render-parameter>imgName</supported-public-render-parameter>
+ </portlet>
+
+ <portlet>
+ <portlet-name>PH-ColorSelPortlet</portlet-name>
+ <display-name>PH Color Selection Portlet</display-name>
+
+ <portlet-class>basic.portlet.ColorSelPortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>HELP</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>PH Color Selection Portlet</title>
+ </portlet-info>
+
+ <supported-publishing-event>
+ <qname>rp:Message</qname>
+ </supported-publishing-event>
+ <supported-public-render-parameter>color</supported-public-render-parameter>
+ </portlet>
+
+ <event-definition>
+ <qname>rp:Message</qname>
+ <value-type>java.lang.String</value-type>
+ </event-definition>
+
+ <public-render-parameter>
+ <identifier>imgName</identifier>
+ <qname>rp:ph-imgName</qname>
+ </public-render-parameter>
+ <public-render-parameter>
+ <identifier>color</identifier>
+ <qname>rp:ph-color</qname>
+ </public-render-parameter>
+ </portlet-app>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/WEB-INF/web.xml b/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5cf9329
--- /dev/null
+++ b/PortletHubDemo/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>PRP Resource Portlet</display-name>
+</web-app>
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/resources/css/styles.css
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/resources/css/styles.css b/PortletHubDemo/src/main/webapp/resources/css/styles.css
new file mode 100644
index 0000000..9029874
--- /dev/null
+++ b/PortletHubDemo/src/main/webapp/resources/css/styles.css
@@ -0,0 +1,16 @@
+.emphasis {
+ font-style: italic;
+ font-size: 1.3em;
+}
+
+.basicJSFApp {
+ padding: 5px;
+ background-color: #DDFFDD;
+ border: thin solid #66DD66;
+}
+
+.infoBox {
+ padding: 5px;
+ background-color: #DDDDFF;
+ border: thin solid #6666DD;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/resources/images/FullMoon.gif
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/resources/images/FullMoon.gif b/PortletHubDemo/src/main/webapp/resources/images/FullMoon.gif
new file mode 100644
index 0000000..a85ee1a
Binary files /dev/null and b/PortletHubDemo/src/main/webapp/resources/images/FullMoon.gif differ
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/resources/images/baseball-trans.gif
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/resources/images/baseball-trans.gif b/PortletHubDemo/src/main/webapp/resources/images/baseball-trans.gif
new file mode 100644
index 0000000..31c2100
Binary files /dev/null and b/PortletHubDemo/src/main/webapp/resources/images/baseball-trans.gif differ
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/resources/images/fussball-trans.gif
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/resources/images/fussball-trans.gif b/PortletHubDemo/src/main/webapp/resources/images/fussball-trans.gif
new file mode 100644
index 0000000..97bde92
Binary files /dev/null and b/PortletHubDemo/src/main/webapp/resources/images/fussball-trans.gif differ
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/PortletHubDemo/src/main/webapp/resources/images/golfball-trans.gif
----------------------------------------------------------------------
diff --git a/PortletHubDemo/src/main/webapp/resources/images/golfball-trans.gif b/PortletHubDemo/src/main/webapp/resources/images/golfball-trans.gif
new file mode 100644
index 0000000..4ec86ce
Binary files /dev/null and b/PortletHubDemo/src/main/webapp/resources/images/golfball-trans.gif differ
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/pluto-PortletHubDemo/pom.xml
----------------------------------------------------------------------
diff --git a/pluto-PortletHubDemo/pom.xml b/pluto-PortletHubDemo/pom.xml
deleted file mode 100644
index 9f5efb4..0000000
--- a/pluto-PortletHubDemo/pom.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.portals.pluto</groupId>
- <artifactId>pluto</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>PortletHubDemo</artifactId>
- <packaging>war</packaging>
-
- <dependencies>
- <dependency>
- <groupId>javax.portlet</groupId>
- <artifactId>portlet-api</artifactId>
- <version>2.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <!-- for eclipse JSP tooling purposes -->
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.portals.pluto</groupId>
- <artifactId>pluto-taglib</artifactId>
- <version>2.1.0-M3</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <finalName>PortletHubDemo</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
- <archiveClasses>true</archiveClasses>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <profiles>
- <profile>
- <id>pluto</id>
- <activation>
- <property>
- <name>!alwaysActivate</name>
- </property>
- </activation>
-
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>jsp-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>taglibs</groupId>
- <artifactId>standard</artifactId>
- <scope>compile</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
- <webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
- </configuration>
- </plugin>
- <!-- bind 'pluto:assemble' goal to 'generate-resources' lifecycle -->
- <plugin>
- <groupId>org.apache.portals.pluto</groupId>
- <artifactId>maven-pluto-plugin</artifactId>
- <version>${project.version}</version>
- <dependencies>
- <dependency>
- <groupId>org.apache.portals.pluto</groupId>
- <artifactId>pluto-util</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <phase>generate-resources</phase>
- <goals>
- <goal>assemble</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <!-- workaround for war processing of m-r-r-plugin causing the generated NOTICE and LICENSE file to be put under WEB-INF/classes/META-INF -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-remote-resources-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>process</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
- <attached>false</attached>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
-</project>
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/pluto-PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
----------------------------------------------------------------------
diff --git a/pluto-PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java b/pluto-PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
deleted file mode 100644
index eecb659..0000000
--- a/pluto-PortletHubDemo/src/main/java/basic/portlet/ColorSelPortlet.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/* 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 basic.portlet;
-
-import static basic.portlet.Constants.PARAM_COLOR;
-import static basic.portlet.Constants.PARAM_ERRMSG;
-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.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-
-
-/**
- * A management portlet that displays the current deep link configuraion
- */
-public class ColorSelPortlet extends GenericPortlet {
-
- // Set up logging
- // private static final String LOG_CLASS = ColorSelPortlet.class.getName();
- // private final Logger logger = Logger.getLogger(LOG_CLASS);
-
- protected void doView(RenderRequest req, RenderResponse resp)
- throws PortletException, IOException {
-
-
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.write("<h3>Image Background Color Selector</h3><hr/>\n");
-
- String pid = resp.getNamespace();
-
- String clr = req.getParameter(PARAM_COLOR);
- clr = (clr == null) ? "#FFFFFF" : clr;
-
- writer.write("<FORM id='" + pid + "-setParams' onsubmit='return false;'>");
- writer.write(" <table><tr><td align='left'>");
- writer.write(" Enter color (public param):");
- writer.write(" </td><td>");
- writer.write(" <input id='" + pid + "-color' name='" + PARAM_COLOR + "' type='text' value='' size='10' maxlength='10'>");
- writer.write(" </td><td>");
- writer.write(" <div id='" + pid + "-putMsgHere' style='color: #B00'></div>\n");
- writer.write(" </td></tr></table>");
- writer.write("</FORM>");
- writer.write("<p><hr/></p>\n");
-
- writer.write("<script>\n");
- writer.write("(function () {\n");
- writer.write(" var pid = '" + pid + "',\n");
- writer.write(" colorEntry = '" + pid + "-color',\n");
- writer.write(" msgdiv = '" + pid + "-putMsgHere',\n");
- writer.write(" currState,\n");
- writer.write(" portletInit;\n");
-
- writer.write(" var update = function (type, state) {\n");
- writer.write(" var oldColor = ((currState === undefined) || (currState.parameters.color === undefined)) ? '#FFFFFF' : currState.parameters.color[0];\n");
- writer.write(" var newColor = (state.parameters.color === undefined) ? '#FFFFFF' : state.parameters.color[0];\n");
- writer.write(" console.log(\"CSP: state updated. color=\" + newColor);\n");
- writer.write(" if ((currState === undefined) || (newColor !== oldColor)) {\n");
- writer.write(" document.getElementById(msgdiv).innerHTML = '';\n");
- writer.write(" document.getElementById(colorEntry).value = newColor;\n");
- writer.write(" }\n");
- writer.write(" currState = state;\n");
- writer.write(" }\n");
- writer.write(" \n");
-
- writer.write(" var handleEntry = function () {\n");
- writer.write(" var oldColor = ((currState === undefined) || (currState.parameters.color === undefined)) ? '#FFFFFF' : currState.parameters.color[0];\n");
- writer.write(" var newColor = this.value;\n");
- writer.write(" console.log(\"CSP: entry field updated. color=\" + newColor);\n");
- writer.write(" if ((newColor === undefined) || (newColor === null) || !newColor.match(\"^#(?:[A-Fa-f0-9]{3}){1,2}$\")) {\n");
- writer.write(" document.getElementById(msgdiv).innerHTML = 'Bad color. Enter #xxxxxx or #xxx.';\n");
- writer.write(" } else {\n");
- writer.write(" var newState = portletInit.cloneState(currState);\n");
- writer.write(" newState.parameters.color = [newColor];\n");
- writer.write(" portletInit.setPortletState(newState);\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" document.getElementById(colorEntry).onchange = handleEntry;\n");
- writer.write(" \n");
-
- writer.write(" portlet.register(pid).then(function (pi) {\n");
- writer.write(" console.log(\"CSP Color Selection Portlet: registered: \" + pid);\n");
- writer.write(" portletInit = pi;\n");
- writer.write(" portletInit.addEventListener(\"portlet.onStateChange\", update);\n");
- writer.write(" });\n");
- writer.write(" \n");
- writer.write(" \n");
- writer.write("})();\n");
- writer.write("</script>\n");
-}
-
- /* (non-Javadoc)
- * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
- */
- @Override
- public void serveResource(ResourceRequest req, ResourceResponse resp)
- throws PortletException, IOException {
- }
-
- public void processAction(ActionRequest req, ActionResponse resp)
- throws PortletException, IOException {
-
- // pass the action params from the form submission as render parameters
- resp.setRenderParameter(PARAM_ERRMSG, "");
- String val = req.getParameter(PARAM_COLOR);
- if (val != null) {
- if (val.matches("^#(?:[A-Fa-f0-9]{3}){1,2}$")) {
- resp.setRenderParameter(PARAM_COLOR, val);
- } else {
- resp.setRenderParameter(PARAM_ERRMSG, "bad color. try again.");
- }
- } else {
- resp.setRenderParameter(PARAM_ERRMSG, "enter color #xxxxxx or #xxx.");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/pluto-PortletHubDemo/src/main/java/basic/portlet/Constants.java
----------------------------------------------------------------------
diff --git a/pluto-PortletHubDemo/src/main/java/basic/portlet/Constants.java b/pluto-PortletHubDemo/src/main/java/basic/portlet/Constants.java
deleted file mode 100644
index 367ffc5..0000000
--- a/pluto-PortletHubDemo/src/main/java/basic/portlet/Constants.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package basic.portlet;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Constants {
-
- // maps the names of the images to the paths to the images -
- public final static Map<String, String> imgMap = new HashMap<String, String>() {
- private static final long serialVersionUID = 1L;
- {
- put("baseball", "/resources/images/baseball-trans.gif");
- put("golfball", "/resources/images/golfball-trans.gif");
- put("fussball", "/resources/images/fussball-trans.gif");
- }};
-
- public final static String DEFAULT_IMAGE = "/resources/images/FullMoon.gif";
-
- public final static String PARAM_SELTYPE = "selType";
- public final static String PARAM_SELTYPE_RADIO = "radio";
- public final static String PARAM_SELTYPE_DROPDOWN = "dropdown";
-
- public final static String PARAM_IMGNAME = "imgName";
- public final static String PARAM_COLOR = "color";
- public final static String PARAM_ERRMSG = "errmsg";
- public final static String PARAM_BORDER = "bo";
- public final static String PARAM_BORDER_COLOR = "border";
- public final static String PARAM_CACHE = "ca";
- public final static String PARAM_CACHE_PAGE = "pa";
- public final static String PARAM_CACHE_PORTLET = "po";
- public final static String PARAM_CACHE_FULL = "fu";
-}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/921477ca/pluto-PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
----------------------------------------------------------------------
diff --git a/pluto-PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java b/pluto-PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
deleted file mode 100644
index 4ed5c7b..0000000
--- a/pluto-PortletHubDemo/src/main/java/basic/portlet/ImageSelPortlet.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/* 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 basic.portlet;
-
-import static basic.portlet.Constants.PARAM_IMGNAME;
-import static basic.portlet.Constants.PARAM_SELTYPE;
-import static basic.portlet.Constants.PARAM_SELTYPE_RADIO;
-import static basic.portlet.Constants.imgMap;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.GenericPortlet;
-import javax.portlet.PortletException;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-
-
-/**
- * A management portlet that displays the current deep link configuraion
- */
-public class ImageSelPortlet extends GenericPortlet {
-
- // Set up logging
- private static final String LOG_CLASS = ImageSelPortlet.class.getName();
- private final Logger logger = Logger.getLogger(LOG_CLASS);
-
- protected void doView(RenderRequest req, RenderResponse resp)
- throws PortletException, IOException {
-
- if (logger.isLoggable(Level.FINE)) {
- logger.logp(Level.FINE, this.getClass().getName(), "doView", "Entry");
- }
-
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.write("<h3>Image Selector</h3><hr/>\n");
-
- String pid = resp.getNamespace();
- String selType = req.getParameter(PARAM_SELTYPE);
- selType = (selType == null) ? PARAM_SELTYPE_RADIO : selType;
- String imgName = req.getParameter(PARAM_IMGNAME);
- imgName = (imgName == null) ? "default" : imgName;
-
- writer.write("<FORM id='" + pid + "-setParams' onsubmit='return false;'>");
- writer.write(" <table><tr><td align='left'>");
- writer.write(" Selection type (private param):");
- writer.write(" </td><td>");
- writer.write(" <input id='" + pid + "-radio' type='radio' name='selType' value='radio'>Radio Button");
- writer.write(" <input id='" + pid + "-dropdown' type='radio' name='selType' value='dropdown'>Drop Down");
- writer.write(" </td></tr><tr><td>");
- writer.write(" Select Image (public param):");
- writer.write(" </td><td>");
-
- writer.write(" <div id='" + pid + "-putResourceHere'></div>\n");
-
- writer.write(" </td></tr></table>");
- writer.write("</FORM>");
- writer.write("<p><hr/></p>\n");
-
- writer.write("<script>\n");
- writer.write("(function () {\n");
- writer.write(" var pid = '" + pid + "',\n");
- writer.write(" fid = '" + pid + "-setParams',\n");
- writer.write(" resdiv = '" + pid + "-putResourceHere',\n");
- writer.write(" st_radio = '" + pid + "-radio',\n");
- writer.write(" st_dropdown = '" + pid + "-dropdown',\n");
- writer.write(" selBox = '" + pid + "-selBox',\n");
- writer.write(" \n");
- writer.write(" last_st = 'radio',\n");
- writer.write(" lastImg = 'default',\n");
- writer.write(" currState,\n");
- writer.write(" portletInit;\n");
- writer.write(" \n");
- writer.write(" // Set image name PRP if radio button clicked - \n");
- writer.write(" var handleImgRadio = function () {\n");
- writer.write(" console.log(\"ISP: image selected (radio): \" + this.value);\n");
- writer.write(" \n");
- writer.write(" if (currState.parameters.imgName !== this.value) {\n");
- writer.write(" var newState = portletInit.cloneState(currState);\n");
- writer.write(" newState.parameters.imgName = [this.value];\n");
- writer.write(" portletInit.setPortletState(newState);\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" \n");
- writer.write(" // Set image name PRP if image selected in selection box - \n");
- writer.write(" var handleImgDropdown = function () {\n");
- writer.write(" console.log(\"ISP: image selected (dropdown): \" + this.value);\n");
- writer.write(" \n");
- writer.write(" if (currState.parameters.imgName !== this.value) {\n");
- writer.write(" var newState = portletInit.cloneState(currState);\n");
- writer.write(" newState.parameters.imgName = [this.value];\n");
- writer.write(" portletInit.setPortletState(newState);\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" \n");
- writer.write(" var update = function (type, state) {\n");
- writer.write(" var oldST = ((currState === undefined) || (currState.parameters.selType === undefined)) ? undefined : currState.parameters.selType[0];\n");
- writer.write(" var newST = (state.parameters.selType === undefined) ? undefined : state.parameters.selType[0];\n");
- writer.write(" var newImg = (state.parameters.imgName === undefined) ? undefined : state.parameters.imgName[0];\n");
- writer.write(" console.log(\"ISP: state updated. selType=\" + newST + \", imgName=\" + newImg);\n");
- writer.write(" \n");
- writer.write(" if ((currState === undefined) || (oldST !== newST)) {");
- writer.write(" portletInit.createResourceUrl({}).then(function (url) {\n");
- writer.write(" console.log(\"ISP: got url: \" + url);\n");
-// writer.write(" document.getElementById(resdiv).innerHTML=\"Waiting for update.\";\n");
- writer.write(" var xhr = new XMLHttpRequest();\n");
- writer.write(" xhr.onreadystatechange=function() {\n");
- writer.write(" if (xhr.readyState==4 && xhr.status==200) {\n");
- writer.write(" document.getElementById(resdiv).innerHTML=xhr.responseText;\n");
-
- writer.write(" // default is radio buttons\n");
- writer.write(" var ii, f = document.getElementById(fid);\n");
- writer.write(" if ((newST === undefined) || (newST === 'radio')) {\n");
- writer.write(" for (ii=0; ii < f.imgName.length; ii++) {\n");
- writer.write(" console.log(\"ISP: adding selection handler for: \" + f.imgName[ii].value);\n");
- writer.write(" f.imgName[ii].onclick = handleImgRadio;\n");
- writer.write(" if (f.imgName[ii].value === newImg) {\n");
- writer.write(" console.log(\"ISP: image clicked: \" + newImg);\n");
- writer.write(" f.imgName[ii].clicked = true;\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" } else if (newST === 'dropdown') {\n");
- writer.write(" console.log(\"ISP: adding selection handler to dropdown list element: \" + selBox);\n");
- writer.write(" document.getElementById(selBox).onchange = handleImgDropdown;\n");
- writer.write(" for (ii=0; ii < f.imgName.length; ii++) {\n");
- writer.write(" if (f.imgName[ii].value === newImg) {\n");
- writer.write(" console.log(\"ISP: image selected: \" + newImg);\n");
- writer.write(" f.imgName[ii].selected = true;\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" }\n");
-
- writer.write(" }\n");
- writer.write(" };\n");
- writer.write(" xhr.open(\"GET\",url,true);\n");
- writer.write(" xhr.send();\n");
- writer.write(" });\n");
- writer.write(" }\n");
-
- writer.write(" if (newST === 'dropdown') {\n");
- writer.write(" document.getElementById(st_dropdown).checked = true;\n");
- writer.write(" } else {\n");
- writer.write(" document.getElementById(st_radio).checked = true;\n");
- writer.write(" }\n");
-
- writer.write(" currState=state;\n");
- writer.write(" }\n");
- writer.write(" \n");
- writer.write(" // set private parameter selType to store the selection display type\n");
- writer.write(" var handleST = function () {\n");
- writer.write(" console.log(\"ISP: select display type clicked: \" + this.value);\n");
- writer.write(" if (currState.parameters.selType !== this.value) {\n");
- writer.write(" var newState = portletInit.cloneState(currState);\n");
- writer.write(" newState.parameters.selType = [this.value];\n");
- writer.write(" portletInit.setPortletState(newState);\n");
- writer.write(" }\n");
- writer.write(" }\n");
- writer.write(" document.getElementById(st_radio).onclick = handleST;\n");
- writer.write(" document.getElementById(st_dropdown).onclick = handleST;\n");
- writer.write(" \n");
- writer.write(" portlet.register(pid).then(function (pi) {\n");
- writer.write(" console.log(\"ISP Image Selection Portlet: registered: \" + pid);\n");
- writer.write(" portletInit = pi;\n");
- writer.write(" portletInit.addEventListener(\"portlet.onStateChange\", update);\n");
- writer.write(" });\n");
- writer.write(" \n");
- writer.write(" \n");
- writer.write("})();\n");
- writer.write("</script>\n");
-
- }
-
- /* (non-Javadoc)
- * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
- */
- @Override
- public void serveResource(ResourceRequest req, ResourceResponse resp)
- throws PortletException, IOException {
-
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
-
- String pid = resp.getNamespace();
- Set<String> names = imgMap.keySet();
- String selType = req.getParameter(PARAM_SELTYPE);
- selType = (selType == null) ? PARAM_SELTYPE_RADIO : selType;
- String imgName = req.getParameter(PARAM_IMGNAME);
- imgName = (imgName == null) ? "default" : imgName;
-
- if (selType.equals(PARAM_SELTYPE_RADIO)) {
- for (String name : names) {
- writer.write(" <input type='radio' name='" + PARAM_IMGNAME + "' value='" +
- name + "'" + (name.equals(imgName) ? "checked" : "") + ">" + name);
- }
- } else {
- writer.write("<select id='" + pid + "-selBox' name='" + PARAM_IMGNAME + "' size='1'>");
- writer.write(" <option value='default' " +
- ("default".equals(imgName) ? "selected" : "") + ">-</option>");
- for (String name : names) {
- writer.write(" <option value='" + name + "'" +
- (name.equals(imgName) ? "selected" : "") + ">" + name + "</option>");
- }
- writer.write("</select>");
- }
- }
-
- public void processAction(ActionRequest req, ActionResponse resp)
- throws PortletException, IOException {
- }
-
-}