move demo bundle to trunk

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@765777 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2009-04-16 21:47:17 +00:00
parent 5a3e61c67f
commit 71ceffdd95
11 changed files with 316 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
<?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>org.apache.struts.osgi</groupId>
<artifactId>struts2-demo-bundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Struts 2 OSGi Demo Bundle</name>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>velocity-tools</groupId>
<artifactId>velocity-tools</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.1.7-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.0.0</version>
<configuration>
<instructions>
<manifestLocation>META-INF</manifestLocation>
<Import-Package>*,com.opensymphony.xwork2</Import-Package>
<Spring-Context>*;create-asynchronously:=false</Spring-Context>
<Struts2-Enabled>true</Struts2-Enabled>
</instructions>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,57 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package actions.osgi;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Bundle;
import org.apache.struts2.osgi.interceptor.BundleContextAware;
import org.apache.struts2.osgi.interceptor.ServiceAware;
import org.apache.struts2.convention.annotation.ResultPath;
import org.springframework.context.ApplicationContext;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
/**
* This action shows how to interact with the OSGi container, using the OSGi interceptor
*/
@ResultPath("/content")
public class BundlesAction extends ActionSupport implements BundleContextAware, ServiceAware<ApplicationContext> {
private BundleContext bundleContext;
private List<ApplicationContext> services;
public void setServices(List<ApplicationContext> services) {
this.services = services;
}
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
public int getApplicationContextsCount() {
return services.size();
}
public Bundle[] getBundles() {
return bundleContext.getBundles();
}
}
@@ -0,0 +1,40 @@
package actions.osgi;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ResultPath;
import org.apache.struts2.osgi.interceptor.BundleContextAware;
import org.apache.struts2.osgi.interceptor.ServiceAware;
import org.osgi.framework.BundleContext;
import org.springframework.context.ApplicationContext;
import java.util.List;
@ResultPath("/content")
public class HelloWorldAction extends ActionSupport {
private Message message;
@Action("hello-convention")
public String execute() {
return SUCCESS;
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
public String getSimpleMessage() {
return "Hello!!!";
}
public String toString() {
StringBuilder sb = new StringBuilder("{message:");
sb.append(message != null ? message.getText() : "null");
sb.append("}");
return sb.toString();
}
}
@@ -0,0 +1,37 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package actions.osgi;
public class Message {
private String text;
public Message(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean class="actions.osgi.Message" id="message">
<constructor-arg type="java.lang.String" value="Welcome to the OSGi plugin. You can checkout any time you like, but can never leave"/>
</bean>
<bean class="actions.osgi.HelloWorldAction" id="helloWorldAction" scope="prototype">
<property name="message" ref="message" />
</bean>
</beans>
@@ -0,0 +1,18 @@
<html>
<head>
<title>OSGi integration</title>
</head>
<body>
This action was mapped by <b>Convention</b>, and shows how to get access to the <b>BundleContext</b>
and registered services
<br />
Spring Application Contexts: ${applicationContextsCount!}
<br>
Bundles List:
<ul>
<#list bundles as bundle>
<li>${bundle.symbolicName!}</li>
</#list>
</ul>
</body>
</html>
@@ -0,0 +1,10 @@
<html>
<head>
<title>Action mapped by the Convention plugin</title>
</head>
<body>
This is an action mapped by the Convention plugin, using a FreeMarker result.
<br />
Message from Action: ${simpleMessage}
</body>
</html>
@@ -0,0 +1,10 @@
<html>
<head>
<title>Action mapped by the XML configurationn</title>
</head>
<body>
This is an action mapped by XML configuration, using a <b>FreeMarker</b> result.
<br />
Message from Action: ${message.text}
</body>
</html>
@@ -0,0 +1,10 @@
<html>
<head>
<title>Action mapped by the XML configurationn</title>
</head>
<body>
This is an action mapped by XML configuration, using a <b>Velocity</b> result.
<br />
Message from Action: $message.text
</body>
</html>
@@ -0,0 +1,14 @@
<html>
<head>
<title>OSGi Demo Bundle</title>
</head>
<body>
This demo contains actions that will be packaged into an OSGi bundle and loaded by the Struts 2 OSGi plugin.
<br />
<ul>
<li><@s.a namespace="/osgi" action="hello-convention">Action mapped by the Convention plugin, with FreeMarker result</@s.a></li>
<li><@s.a namespace="/osgi" action="hello-freemarker">Action mapped by XML, with FreeMarker result</@s.a></li>
<li><@s.a namespace="/osgi" action="hello-velocity">Action mapped by XML, with Velocity result</@s.a></li>
</ul>
</body>
</html>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="bundle-demo" namespace="/osgi" extends="osgi-default">
<default-action-ref name="home" />
<action name="hello-velocity" class="helloWorldAction">
<result type="velocity">/content/osgi/hello.vm</result>
</action>
<action name="hello-freemarker" class="helloWorldAction">
<result type="freemarker">/content/osgi/hello.ftl</result>
</action>
<action name="home">
<result type="freemarker">/content/osgi/home.ftl</result>
</action>
</package>
</struts>