Permalink
Browse files

add PrettyTime JSTL integration sample

  • Loading branch information...
1 parent f638627 commit ccffa079b061a6f05a0b8e6cdc620fd1d1fa13b8 @benas benas committed Feb 10, 2014
View
@@ -22,6 +22,7 @@
<module>jsf</module>
<module>jstl</module>
<module>nlp</module>
+ <module>samples</module>
</modules>
<properties>
View
@@ -0,0 +1,46 @@
+## This module contains PrettyTime integration samples
+
+### JSTL integration sample
+
+To use PrettyTime JSTL tag, you simply have to :
+
+* Declare PrettyTime JSTL tag library in your JSP :
+
+```
+<%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>
+```
+
+* Use the tag in your JSP :
+
+```
+<ocpsoft:prettytime date="${myDate}" locale="en_US"/>
+```
+
+PrettyTime JSTL tag parameters are described in the table below :
+
+| Parameter | Required | Description | Default value |
+|:----------- |:--------:|:------------------------------------------ |:------------------------------|
+| date | yes | The date object to pretty print | N/A |
+| locale | no | The locale used to localize the message | default locale |
+
+This module provides a single JSP web application that shows how to use PrettyTime JSTL tag library.
+
+To launch the application, run the following command:
+
+<code>mvn install && mvn exec:java -PrunJstlSample</code>
+
+Then browse the following URL:
+
+<code>http://localhost:8080/index.do</code>
+
+You should see the following output:
+
+```
+PrettyTime JSTL Integration Sample
+
+PrettyTime date : moments ago
+```
+
+### JSF integration sample
+
+// TODO
View
@@ -0,0 +1,71 @@
+<?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/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <artifactId>prettytime-parent</artifactId>
+ <groupId>org.ocpsoft.prettytime</groupId>
+ <version>3.2.5-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>prettytime-samples</artifactId>
+ <name>PrettyTime - Integration - Samples</name>
+ <description>PrettyTime integration samples module</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>7.2.2.v20101205</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.2.2.v20101205</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-jsp-2.1</artifactId>
+ <version>7.2.2.v20101205</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jsp-2.1-glassfish</artifactId>
+ <version>2.1.v20100127</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ocpsoft.prettytime</groupId>
+ <artifactId>prettytime-integration-jstl</artifactId>
+ <version>3.2.5-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+
+ <!-- profile to run the JSTL integration sample -->
+ <profile>
+ <id>runJstlSample</id>
+ <build>
+ <defaultGoal>exec:java</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <configuration>
+ <mainClass>org.ocpsoft.prettytime.samples.jstl.JstlSampleLauncher</mainClass>
+ <arguments>
+ <argument>${project.basedir}/src/main/webapp/</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
@@ -0,0 +1,17 @@
+package org.ocpsoft.prettytime.samples.jstl;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Date;
+
+public class IndexServlet extends HttpServlet {
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ request.setAttribute("myDate", new Date());
+ request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
+ }
+
+}
@@ -0,0 +1,29 @@
+package org.ocpsoft.prettytime.samples.jstl;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+public class JstlSampleLauncher {
+
+ public static void main(String[] args) throws Exception {
+
+ String weppAppHome = args[0];
+ Integer port = 8080;
+
+ Server server = new Server(port);
+
+ WebAppContext webapp = new WebAppContext();
+ webapp.setContextPath("/");
+ webapp.setCompactPath(true);
+
+ webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml");
+ webapp.setResourceBase(weppAppHome);
+ webapp.setParentLoaderPriority(true);
+
+ server.setHandler(webapp);
+ server.start();
+ server.join();
+
+ }
+
+}
@@ -0,0 +1,16 @@
+<%@ taglib prefix="ocpsoft" uri="http://ocpsoft.org/prettytime/tags" %>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>PrettyTime JSTL Integration Sample</title>
+</head>
+<body>
+
+<h2>PrettyTime JSTL Integration Sample</h2>
+
+PrettyTime date : <ocpsoft:prettytime date="${myDate}" locale="en_US"/>
+
+</body>
+</html>
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ id="prettytime" version="3.0">
+
+ <servlet>
+ <servlet-name>index</servlet-name>
+ <servlet-class>org.ocpsoft.prettytime.samples.jstl.IndexServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>index</servlet-name>
+ <url-pattern>/index.do</url-pattern>
+ </servlet-mapping>
+
+</web-app>

0 comments on commit ccffa07

Please sign in to comment.