Aipoでは一つ一つのアプリをportletという子プロジェクトとしてコンパイルできるように設計されています。
今回は簡単なportletを作成する手順をご説明します。
まず、Aipoのソースでportletsというフォルダを開いてみましょう。
blog, todo, scheduleなどのフォルダがずらりと並んでいるかと思います。
これらのフォルダがそれぞれのportletに対応しています。
今回はtestというportletを追加するので、portletsフォルダの下に
testという名前のフォルダを作成してそこにアプリのファイルを追加してゆきます。
まず、アプリを作成後にマイページの設定から作成したアプリを選択できるようにする必要があります。
アプリ選択の一覧にアプリを表示させるためには、xregと呼ばれる設定ファイルを作成します。
【ファイル追加】
portletstestsrcmainwebappWEB-INFconftest.xreg
<?xml version="1.0" encoding="UTF-8"?>
<registry>
<portlet-entry name="Test" hidden="false" type="ref" parent="Velocity" application="false">
<security-ref parent="user-view"/>
<meta-info>
<title>Test</title>
<description>Testポートレット。</description>
</meta-info>
<classname>org.apache.jetspeed.portal.portlets.VelocityPortlet</classname>
<parameter name="template" value="test" hidden="true" cachedOnName="true" cachedOnValue="true"/>
<parameter name="action" value="test.TestAction" hidden="true" cachedOnName="true" cachedOnValue="true"/>
<media-type ref="html"/>
<url cachedOnURL="true"/>
</portlet-entry>
</registry>【ファイル追加】
test.xregの「<parameter name=”action”・・・」というタグで指定されているtest.TestActionというクラスが
このtestポートレットでメインにあたるJavaクラスになります。
今回は下記のようなクラスを作成して、testというテンプレートをただ表示させるActionクラスを定義します。
portletstestsrcmainjavacomaimluckeipmodulesactionstestTestAction.java
package com.aimluck.eip.modules.actions.test;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;
import com.aimluck.eip.modules.actions.common.ALBaseAction;
public class TestAction extends ALBaseAction {
@Override
protected void buildNormalContext(VelocityPortlet portlet, Context context,
RunData rundata) throws Exception {
setTemplate(rundata, "test");
}
}【ファイル追加】
AipoではJSPのようなテンプレートファイルとしてVelocityというテンプレートエンジンを採用しています。
TestActionのなかでsetTemplate(rundata, “test”)というメソッドを実行すると、
test.vmというテンプレートの内容が表示されます。
まずは、ためしにHello Worldと書かれたテンプレートファイルを作成してみましょう。
portletstestsrcmainwebappWEB-INFtemplatesvmportletshtmljatest.vm
Hello World!!
【ファイル追加】
maven2でこのポートレットをコンパイルできるようにpom.xmlを追加します。
portletstestpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>portlets</artifactId>
<groupId>com.aimluck.eip</groupId>
<!-- ①Aipoのバージョンがここに入ります -->
<version>7.0.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.aimluck.eip</groupId>
<!-- ②コンパイル後に生成されるポートレットごとのパッケージ名です -->
<artifactId>aipo-portlet-test</artifactId>
<version>${aipo.version}</version>
<packaging>jar</packaging>
<!-- ③コンパイル時に表示されるポートレット名です -->
<name>Aipo Test Portlet</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="../../war/target/aipo" verbose="false"
overwrite="true">
<fileset dir="./src/main/webapp" includes="**/*" excludes="**/*.js" />
</copy>
<copy todir="../../war/target/aipo/WEB-INF/lib"
verbose="false" overwrite="true">
<fileset dir="./target" includes="*-${aipo.version}.jar" />
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>./src/main/webapp/javascript</sourceDirectory>
<outputDirectory>../../war/target/aipo/javascript</outputDirectory>
<nosuffix>true</nosuffix>
<encoding>UTF-8</encoding>
<gzip>false</gzip>
<includes>
<include>**/*.js</include>
</includes>
<jswarn>false</jswarn>
<statistics>false</statistics>
<force>true</force>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.aimluck.eip</groupId>
<artifactId>aipo-portlet-fileupload</artifactId>
<version>${aipo.version}</version>
</dependency>
<dependency>
<groupId>com.aimluck.eip</groupId>
<artifactId>aipo-portlet-whatsnew</artifactId>
<version>${aipo.version}</version>
</dependency>
<dependency>
<groupId>com.aimluck.eip</groupId>
<artifactId>aipo-portlet-timeline</artifactId>
<version>${aipo.version}</version>
</dependency>
</dependencies>
</project>開発環境のTomcatを起動していたら一旦停止してください。
Tomcatが起動していない状態でportletstestフォルダをコマンドプロンプトで開いて下記のコマンドを実行します。
mvn install
mvnコマンド実行後にTomcatを起動してlocalhost:8080にアクセスしてみましょう。
Aipoにログイン後、マイページの設定でTestポートレットを追加して「Hello world」と表示されれば成功です。


