Micha Kops avatar Micha Kops committed ef8991d

Initial release

Comments (0)

Files changed (17)

+<?xml version="1.0" encoding="UTF-8"?>
+
+<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>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>liferay-portlet-tutorial</artifactId>
+	<packaging>war</packaging>
+	<name>liferay-portlet-tutorial Portlet</name>
+	<version>0.0.1-SNAPSHOT</version>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>com.liferay.maven.plugins</groupId>
+				<artifactId>liferay-maven-plugin</artifactId>
+				<version>${liferay.version}</version>
+				<configuration>
+					<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
+				</configuration>
+			</plugin>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<encoding>UTF-8</encoding>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>com.liferay.portal</groupId>
+			<artifactId>portal-service</artifactId>
+			<version>${liferay.version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.liferay.portal</groupId>
+			<artifactId>util-bridges</artifactId>
+			<version>${liferay.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.liferay.portal</groupId>
+			<artifactId>util-taglib</artifactId>
+			<version>${liferay.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.liferay.portal</groupId>
+			<artifactId>util-java</artifactId>
+			<version>${liferay.version}</version>
+		</dependency>
+		<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>
+			<version>2.4</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet.jsp</groupId>
+			<artifactId>jsp-api</artifactId>
+			<version>2.0</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+	<properties>
+		<liferay.auto.deploy.dir>../bundles/liferay-portal-6.0/deploy</liferay.auto.deploy.dir>
+		<liferay.version>6.0.6</liferay.version>
+	</properties>
+</project>

src/main/java/com/hascode/tutorial/portlet/AdvancedEventReceiverPortlet.java

+package com.hascode.tutorial.portlet;
+
+import java.io.IOException;
+
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+public class AdvancedEventReceiverPortlet extends GenericPortlet {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * javax.portlet.GenericPortlet#processEvent(javax.portlet.EventRequest,
+	 * javax.portlet.EventResponse)
+	 */
+	@Override
+	public void processEvent(EventRequest req, EventResponse res) throws PortletException, IOException {
+		final CustomPortletMessage message = (CustomPortletMessage) req.getEvent().getValue();
+		res.setRenderParameter("message", message.getText());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
+	 * javax.portlet.RenderResponse)
+	 */
+	@Override
+	public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
+		final String message = req.getParameter("message");
+		res.getWriter().println("Message received from event: " + message);
+	}
+
+}

src/main/java/com/hascode/tutorial/portlet/AdvancedEventSenderPortlet.java

+package com.hascode.tutorial.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.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.xml.namespace.QName;
+
+public class AdvancedEventSenderPortlet extends GenericPortlet {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * javax.portlet.GenericPortlet#processAction(javax.portlet.ActionRequest,
+	 * javax.portlet.ActionResponse)
+	 */
+	@Override
+	public void processAction(ActionRequest req, ActionResponse res) throws PortletException, IOException {
+		final String text = req.getParameter("message");
+		if (text != null && !text.isEmpty()) {
+			CustomPortletMessage msg = new CustomPortletMessage();
+			msg.setText(text);
+			res.setEvent(new QName("http://www.hascode.com/portlet", "customMessage"), msg);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
+	 * javax.portlet.RenderResponse)
+	 */
+	@Override
+	public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
+		res.setContentType("text/html");
+		PrintWriter writer = res.getWriter();
+		PortletURL actionUrl = res.createActionURL();
+		final String output = String.format("<form action=\"%s\" method=\"post\"><label>Enter a message</label><input type=\"text\" name=\"message\"/><br/><input type=\"submit\"/></form>", actionUrl);
+		writer.println(output);
+
+	}
+
+}

src/main/java/com/hascode/tutorial/portlet/CustomPortletMessage.java

+package com.hascode.tutorial.portlet;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class CustomPortletMessage implements Serializable {
+	private static final long	serialVersionUID	= 1L;
+
+	private String				text;
+
+	public String getText() {
+		return text;
+	}
+
+	public void setText(String text) {
+		this.text = text;
+	}
+
+}

src/main/java/com/hascode/tutorial/portlet/EventReceiverPortlet.java

+package com.hascode.tutorial.portlet;
+
+import java.io.IOException;
+
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+public class EventReceiverPortlet extends GenericPortlet {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * javax.portlet.GenericPortlet#processEvent(javax.portlet.EventRequest,
+	 * javax.portlet.EventResponse)
+	 */
+	@Override
+	public void processEvent(EventRequest req, EventResponse res) throws PortletException, IOException {
+		final String message = (String) req.getEvent().getValue();
+		res.setRenderParameter("message", message);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
+	 * javax.portlet.RenderResponse)
+	 */
+	@Override
+	public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
+		final String message = req.getParameter("message");
+		res.getWriter().println("Message received from event: " + message);
+	}
+
+}

src/main/java/com/hascode/tutorial/portlet/EventSenderPortlet.java

+package com.hascode.tutorial.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.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.xml.namespace.QName;
+
+public class EventSenderPortlet extends GenericPortlet {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * javax.portlet.GenericPortlet#processAction(javax.portlet.ActionRequest,
+	 * javax.portlet.ActionResponse)
+	 */
+	@Override
+	public void processAction(ActionRequest req, ActionResponse res) throws PortletException, IOException {
+		final String message = req.getParameter("message");
+		if (message != null && !message.isEmpty()) {
+			res.setEvent(new QName("http://www.hascode.com/portlet", "message"), message);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
+	 * javax.portlet.RenderResponse)
+	 */
+	@Override
+	public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
+		res.setContentType("text/html");
+		PrintWriter writer = res.getWriter();
+		PortletURL actionUrl = res.createActionURL();
+		final String output = String.format("<form action=\"%s\" method=\"post\"><label>Enter a message</label><input type=\"text\" name=\"message\"/><br/><input type=\"submit\"/></form>", actionUrl);
+		writer.println(output);
+
+	}
+
+}

src/main/java/com/hascode/tutorial/portlet/HelloWorldPortlet.java

+package com.hascode.tutorial.portlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+public class HelloWorldPortlet extends GenericPortlet {
+	@Override
+	protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
+		response.setContentType("text/html");
+		PrintWriter writer = response.getWriter();
+		writer.println("<h1>Hello world</h1><br/><br/><div>This is a sample portlet from hasCode.com</div>");
+	}
+}

src/main/java/com/hascode/tutorial/portlet/SimplePreferencesReadingPortlet.java

+package com.hascode.tutorial.portlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+public class SimplePreferencesReadingPortlet extends GenericPortlet {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.portlet.GenericPortlet#render(javax.portlet.RenderRequest,
+	 * javax.portlet.RenderResponse)
+	 */
+	@Override
+	public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
+		res.setContentType("text/html");
+		PrintWriter writer = res.getWriter();
+
+		PortletPreferences prefs = req.getPreferences();
+		String[] tags = prefs.getValues("tags", null);
+		writer.println("<b>Tags:</b><br/><ul>");
+		for (String tag : tags) {
+			writer.println("<li>" + tag + "</li>");
+		}
+		writer.println("</ul>");
+	}
+
+}

src/main/webapp/WEB-INF/liferay-display.xml

+<?xml version="1.0"?>
+<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.0.0//EN" "http://www.liferay.com/dtd/liferay-display_6_0_0.dtd">
+
+<display>
+	<category name="category.sample">
+		<portlet id="hascode-liferay-portlet" />
+	</category>
+</display>

src/main/webapp/WEB-INF/liferay-plugin-package.properties

+name=hascode-liferay-portlet
+module-group-id=hasCode
+module-incremental-version=1
+tags=
+short-description=
+change-log=
+page-url=http://www.hascode.com
+author=Micha Kops
+licenses=LGPL

src/main/webapp/WEB-INF/liferay-portlet.xml

+<?xml version="1.0"?>
+<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.0.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd">
+
+<liferay-portlet-app>
+	<portlet>
+		<portlet-name>hascode-liferay-portlet</portlet-name>
+		<icon>/icon.png</icon>
+		<instanceable>true</instanceable>
+		<header-portlet-css>/css/main.css</header-portlet-css>
+		<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
+	</portlet>
+	<role-mapper>
+		<role-name>administrator</role-name>
+		<role-link>Administrator</role-link>
+	</role-mapper>
+	<role-mapper>
+		<role-name>guest</role-name>
+		<role-link>Guest</role-link>
+	</role-mapper>
+	<role-mapper>
+		<role-name>power-user</role-name>
+		<role-link>Power User</role-link>
+	</role-mapper>
+	<role-mapper>
+		<role-name>user</role-name>
+		<role-link>User</role-link>
+	</role-mapper>
+</liferay-portlet-app>

src/main/webapp/WEB-INF/portlet.xml

+<?xml version="1.0"?>
+
+<portlet-app version="2.0"
+	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">
+	<portlet>
+		<portlet-name>hascode-liferay-portlet</portlet-name>
+		<display-name>hascode-liferay-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.HelloWorldPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-liferay-portlet</title>
+			<keywords>hascode-liferay-portlet-tutorial</keywords>
+		</portlet-info>
+		<security-role-ref>
+			<role-name>administrator</role-name>
+		</security-role-ref>
+		<security-role-ref>
+			<role-name>guest</role-name>
+		</security-role-ref>
+		<security-role-ref>
+			<role-name>power-user</role-name>
+		</security-role-ref>
+		<security-role-ref>
+			<role-name>user</role-name>
+		</security-role-ref>
+	</portlet>
+
+	<portlet>
+		<portlet-name>hascode-event-sender-portlet</portlet-name>
+		<display-name>hascode-event-sender-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.EventSenderPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-event-sender-portlet</title>
+			<keywords>hascode-event-sender-portlet</keywords>
+		</portlet-info>
+
+		<supported-publishing-event>
+			<qname xmlns:hc="http://www.hascode.com/portlet">hc:message</qname>
+		</supported-publishing-event>
+	</portlet>
+
+	<portlet>
+		<portlet-name>hascode-event-receiver-portlet</portlet-name>
+		<display-name>hascode-event-receiver-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.EventReceiverPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-event-receiver-portlet</title>
+			<keywords>hascode-event-receiver-portlet</keywords>
+		</portlet-info>
+
+		<supported-processing-event>
+			<qname xmlns:hc="http://www.hascode.com/portlet">hc:message</qname>
+		</supported-processing-event>
+	</portlet>
+
+	<portlet>
+		<portlet-name>hascode-advanced-event-sender-portlet</portlet-name>
+		<display-name>hascode-advanced-event-sender-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.AdvancedEventSenderPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-advanced-event-sender-portlet</title>
+			<keywords>hascode-advanced-event-sender-portlet</keywords>
+		</portlet-info>
+
+		<supported-publishing-event>
+			<qname xmlns:hc="http://www.hascode.com/portlet">hc:customMessage</qname>
+		</supported-publishing-event>
+	</portlet>
+
+	<portlet>
+		<portlet-name>hascode-advanced-event-receiver-portlet</portlet-name>
+		<display-name>hascode-advanced-event-receiver-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.AdvancedEventReceiverPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-advanced-event-receiver-portlet</title>
+			<keywords>hascode-advanced-event-receiver-portlet</keywords>
+		</portlet-info>
+
+		<supported-processing-event>
+			<qname xmlns:hc="http://www.hascode.com/portlet">hc:customMessage</qname>
+		</supported-processing-event>
+	</portlet>
+	
+		<portlet>
+		<portlet-name>hascode-preferences-portlet</portlet-name>
+		<display-name>hascode-preferences-portlet</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.SimplePreferencesReadingPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-preferences-portlet</title>
+			<keywords>hascode-preferences-portlet</keywords>
+		</portlet-info>
+		<portlet-preferences>
+			<preference>
+				<name>tags</name>
+				<value>portlet</value>
+				<value>tutorial</value>
+				<value>liferay</value>
+				<value>java</value>
+			</preference>
+		</portlet-preferences>
+	</portlet>
+
+	<event-definition>
+		<qname xmlns:hc="http://www.hascode.com/portlet">hc:message</qname>
+		<value-type>java.lang.String</value-type>
+	</event-definition>
+
+	<event-definition>
+		<qname xmlns:hc="http://www.hascode.com/portlet">hc:customMessage</qname>
+		<value-type>com.hascode.tutorial.portlet.CustomPortletMessage</value-type>
+	</event-definition>
+</portlet-app>

src/main/webapp/WEB-INF/web.xml

+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app 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">
+</web-app>
Add a comment to this file

src/main/webapp/css/main.css

Empty file added.

Add a comment to this file

src/main/webapp/icon.png

Added
New image
Add a comment to this file

src/main/webapp/js/main.js

Empty file added.

src/main/webapp/view.jsp

+<%
+/**
+ * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ */
+%>
+
+<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
+
+<portlet:defineObjects />
+
+This is the <b>liferay-portlet-tutorial</b>.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.