Skip to content

Instantly share code, notes, and snippets.

View martinlau's full-sized avatar

Martin Lau martinlau

View GitHub Profile
@martinlau
martinlau / liferay-hook.xml
Created November 30, 2012 00:27
Basic liferay hook configuration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
@martinlau
martinlau / FakeService.java
Created November 30, 2012 00:24
A simple service using spring's @transactional and dependency injection.
package au.com.permeance.service;
public interface FakeService {
void doStuff() throws Exception;
}
@martinlau
martinlau / class-loader-swapper.clj
Created August 23, 2012 01:15
Classloader swapping in Clojure
(defmacro do-with-classloader
[classloader & body]
`(let [old-classloader# (.getContextClassLoader (Thread/currentThread))]
(.setContextClassLoader (Thread/currentThread) ~classloader)
(try ~@body
(finally (.setContextClassLoader (Thread/currentThread) old-classloader#)))))
@martinlau
martinlau / ClassLoaderSwapper.java
Created August 23, 2012 01:07
Classloader swapping in Java
public abstract class ClassLoaderSwapper {
public void doWithClassLoader(ClassLoader classLoader) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
try {
doInternal();
}
finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
@martinlau
martinlau / ClojurePortlet.clj
Created August 18, 2012 11:32
A simple clojure portlet
(ns au.com.permeance.clojure.ClojurePortlet
(:gen-class :implements [javax.portlet.Portlet]
:init construct
:main false
:state state)
(:import (javax.portlet ActionRequest PortletMode)))
(defn- include-path [this path request response]
(let [state @(.state this)
config (:config state)
@martinlau
martinlau / help.jsp
Created August 18, 2012 11:16
Portlet JSPs
<p>
/help.jsp
</p>
@martinlau
martinlau / portlet.xml
Created August 18, 2012 11:15
Portlet descriptor for a simple java portlet
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0">
<portlet>
<portlet-name>clojure-portlet</portlet-name>
@martinlau
martinlau / JavaPortlet.java
Created August 18, 2012 11:14
A simple java portlet
package au.com.permeance.clojure;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequestDispatcher;
@martinlau
martinlau / standard-form-with-liferay-action-url.html
Created August 14, 2012 12:08
HTML output of a portlet JSP illustrating liferay's actionURL and form
<form action="http://www.example.com/web/guest/home?p_auth=Ex7KuhQN&amp;p_p_id=samplegetformportlet_WAR_samplegetformportlet&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_count=2" method="get" id="aui_3_4_0_1_563">
<input name="p_auth" type="hidden" value="Ex7KuhQN">
<input name="p_p_id" type="hidden" value="samplegetformportlet_WAR_samplegetformportlet">
<input name="p_p_lifecycle" type="hidden" value="1">
<input name="p_p_state" type="hidden" value="normal">
<input name="p_p_mode" type="hidden" value="view">
<input name="p_p_col_id" type="hidden" value="column-1">
<input name="p_p_col_count" type="hidden" value="2">
<input type="text" name="query" class="" id="aui_3_4_0_1_562">
<input type="submit">
@martinlau
martinlau / standard-form-with-liferay-action-url.jsp
Created August 14, 2012 12:02
Portlet JSP illustrating liferay's actionURL and form
<%@ taglib prefix="liferay-portlet" uri="http://liferay.com/tld/portlet" %>
<liferay-portlet:actionURL varImpl="submitURL" />
<form action="${submitURL}" method="get">
<liferay-portlet:renderURLParams varImpl="submitURL" />
<input type="text" name="query" />
<input type="submit" />
</form>