Skip to content

Commit ccffa07

Browse files
author
benas
committed
add PrettyTime JSTL integration sample
1 parent f638627 commit ccffa07

7 files changed

Lines changed: 195 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<module>jsf</module>
2323
<module>jstl</module>
2424
<module>nlp</module>
25+
<module>samples</module>
2526
</modules>
2627

2728
<properties>

‎samples/README.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## This module contains PrettyTime integration samples
2+
3+
### JSTL integration sample
4+
5+
To use PrettyTime JSTL tag, you simply have to :
6+
7+
* Declare PrettyTime JSTL tag library in your JSP :
8+
9+
```
10+
<%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>
11+
```
12+
13+
* Use the tag in your JSP :
14+
15+
```
16+
<ocpsoft:prettytime date="${myDate}" locale="en_US"/>
17+
```
18+
19+
PrettyTime JSTL tag parameters are described in the table below :
20+
21+
| Parameter | Required | Description | Default value |
22+
|:----------- |:--------:|:------------------------------------------ |:------------------------------|
23+
| date | yes | The date object to pretty print | N/A |
24+
| locale | no | The locale used to localize the message | default locale |
25+
26+
This module provides a single JSP web application that shows how to use PrettyTime JSTL tag library.
27+
28+
To launch the application, run the following command:
29+
30+
<code>mvn install && mvn exec:java -PrunJstlSample</code>
31+
32+
Then browse the following URL:
33+
34+
<code>http://localhost:8080/index.do</code>
35+
36+
You should see the following output:
37+
38+
```
39+
PrettyTime JSTL Integration Sample
40+
41+
PrettyTime date : moments ago
42+
```
43+
44+
### JSF integration sample
45+
46+
// TODO

‎samples/pom.xml‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<parent>
7+
<artifactId>prettytime-parent</artifactId>
8+
<groupId>org.ocpsoft.prettytime</groupId>
9+
<version>3.2.5-SNAPSHOT</version>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>prettytime-samples</artifactId>
14+
<name>PrettyTime - Integration - Samples</name>
15+
<description>PrettyTime integration samples module</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.eclipse.jetty</groupId>
20+
<artifactId>jetty-server</artifactId>
21+
<version>7.2.2.v20101205</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.eclipse.jetty</groupId>
25+
<artifactId>jetty-webapp</artifactId>
26+
<version>7.2.2.v20101205</version>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.eclipse.jetty</groupId>
31+
<artifactId>jetty-jsp-2.1</artifactId>
32+
<version>7.2.2.v20101205</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.mortbay.jetty</groupId>
36+
<artifactId>jsp-2.1-glassfish</artifactId>
37+
<version>2.1.v20100127</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.ocpsoft.prettytime</groupId>
42+
<artifactId>prettytime-integration-jstl</artifactId>
43+
<version>3.2.5-SNAPSHOT</version>
44+
</dependency>
45+
</dependencies>
46+
47+
<profiles>
48+
49+
<!-- profile to run the JSTL integration sample -->
50+
<profile>
51+
<id>runJstlSample</id>
52+
<build>
53+
<defaultGoal>exec:java</defaultGoal>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.codehaus.mojo</groupId>
57+
<artifactId>exec-maven-plugin</artifactId>
58+
<version>1.2.1</version>
59+
<configuration>
60+
<mainClass>org.ocpsoft.prettytime.samples.jstl.JstlSampleLauncher</mainClass>
61+
<arguments>
62+
<argument>${project.basedir}/src/main/webapp/</argument>
63+
</arguments>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</profile>
69+
</profiles>
70+
71+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.ocpsoft.prettytime.samples.jstl;
2+
3+
import javax.servlet.ServletException;
4+
import javax.servlet.http.HttpServlet;
5+
import javax.servlet.http.HttpServletRequest;
6+
import javax.servlet.http.HttpServletResponse;
7+
import java.io.IOException;
8+
import java.util.Date;
9+
10+
public class IndexServlet extends HttpServlet {
11+
12+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
13+
request.setAttribute("myDate", new Date());
14+
request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
15+
}
16+
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.ocpsoft.prettytime.samples.jstl;
2+
3+
import org.eclipse.jetty.server.Server;
4+
import org.eclipse.jetty.webapp.WebAppContext;
5+
6+
public class JstlSampleLauncher {
7+
8+
public static void main(String[] args) throws Exception {
9+
10+
String weppAppHome = args[0];
11+
Integer port = 8080;
12+
13+
Server server = new Server(port);
14+
15+
WebAppContext webapp = new WebAppContext();
16+
webapp.setContextPath("/");
17+
webapp.setCompactPath(true);
18+
19+
webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml");
20+
webapp.setResourceBase(weppAppHome);
21+
webapp.setParentLoaderPriority(true);
22+
23+
server.setHandler(webapp);
24+
server.start();
25+
server.join();
26+
27+
}
28+
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>
2+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>PrettyTime JSTL Integration Sample</title>
8+
</head>
9+
<body>
10+
11+
<h2>PrettyTime JSTL Integration Sample</h2>
12+
13+
PrettyTime date : <ocpsoft:prettytime date="${myDate}" locale="en_US"/>
14+
15+
</body>
16+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
4+
id="prettytime" version="3.0">
5+
6+
<servlet>
7+
<servlet-name>index</servlet-name>
8+
<servlet-class>org.ocpsoft.prettytime.samples.jstl.IndexServlet</servlet-class>
9+
</servlet>
10+
<servlet-mapping>
11+
<servlet-name>index</servlet-name>
12+
<url-pattern>/index.do</url-pattern>
13+
</servlet-mapping>
14+
15+
</web-app>

0 commit comments

Comments
 (0)