Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 222f1542a385b594078ba734d3623f5d7872fdd7 @greenlaw110 committed Mar 28, 2010
@@ -0,0 +1,20 @@
+Copyright (c) 2010-2015 Gelin Luo
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 README
@@ -0,0 +1,17 @@
+Excel module for the Play! framework. This module help to create Excel report with predefined Excel templates.
+
+Copyright 2010
+
+ Green Luo - greenlaw110@gmail.com
+
+Licensed 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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,20 @@
+#{extends 'main.html' /}
+#{set title:'Contacts' /}
+
+<div id="header">
+<h1>Contacts</h1>
+</div>
+
+<div id="content">
+<table>
+<thead>
+<tr><th>Contact</th><th>Address</th><th>Email</th><th>Mobile</th><th>Action</th></tr>
+</thead>
+<tbody>
+#{list contacts, as: 'person'}
+<tr><td>${person}</td><td>${person.address}</td><td>${person.email}</td><td>${person.mobile}</td>
+<td><a href="@{Application.generateNameCard(person.id)}">generate namecard</a></td></tr>
+#{/list}
+</tbody>
+</table>
+</div>
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Not found</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ </head>
+ <body>
+ #{if play.mode.name() == 'DEV'}
+ #{404 result /}
+ #{/if}
+ #{else}
+ <h1>Not found</h1>
+ <p>
+ ${result.message}
+ </p>
+ #{/else}
+ </body>
+</html>
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Application error</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ </head>
+ <body>
+ #{if play.mode.name() == 'DEV'}
+ #{500 exception /}
+ #{/if}
+ #{else}
+ <h1>Oops, an error occured</h1>
+ <p>
+ This exception has been logged with id <strong>${exception.id}</strong>.
+ </p>
+ #{/else}
+ </body>
+</html>
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>#{get 'title' /}</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/main.css'}">
+ #{get 'moreStyles' /}
+ <link rel="shortcut icon" type="image/png" href="@{'/public/images/favicon.png'}">
+ <script src="@{'/public/javascripts/jquery-1.4.min.js'}" type="text/javascript" charset="utf-8"></script>
+ #{get 'moreScripts' /}
+ </head>
+ <body>
+ #{doLayout /}
+ </body>
+</html>
@@ -0,0 +1,2 @@
+#play.path=/usr/share/play
+play.path=../..
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Excel module" default="build" basedir=".">
+
+ <property file="./build.properties" />
+
+ <path id="project.classpath">
+ <pathelement path="${play.path}/framework/classes"/>
+ <fileset dir="${play.path}/framework/lib">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="lib">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <target name="build" depends="compile">
+
+ <copy todir="tmp/classes">
+ <fileset dir="src">
+ <include name="**/*.properties"/>
+ <include name="**/*.xml"/>
+ <include name="**/play.plugins"/>
+ <include name="**/play.static"/>
+ </fileset>
+ </copy>
+ <jar destfile="lib/play-excel.jar" basedir="tmp/classes">
+ <manifest>
+ <section name="Play">
+ <attribute name="Specification-Title" value="Excel module"/>
+ </section>
+ </manifest>
+ </jar>
+ <delete dir="tmp" />
+ </target>
+
+ <target name="compile">
+ <mkdir dir="tmp/classes" />
+ <javac srcdir="src" destdir="tmp/classes" target="1.5" debug="true">
+ <classpath refid="project.classpath" />
+ </javac>
+ </target>
+
+</project>
@@ -0,0 +1,28 @@
+h1. Excel module
+
+The Excel module allows you to render Excel document. It is rather simple to use as it only requires to import a static file.
+
+h2. <a>Enable the Excel module for the application</a>
+
+In the **/conf/application.conf** file, enable the Excel module by adding this line:
+
+bc. # The Excel module
+module.Excel=${play.path}/modules/Excel
+
+h2. <a>Using the Excel module</a>
+
+h3. <a>The renderExcel() method</a>:
+
+bc. import static play.modules.excel.Excel.*;
+
+And then use the renderExcel() method as you would use the render() method.
+
+The renderExcel() behavior is almost the same as that of render() except the following differences:
+# the template should be an excel file with ".xls" suffix rather than a text file with ".html"
+# You can use renderArgs.put("fileName", "your-file.xls") to indicate the name of the excel file to be generated
+
+h2. Known Issue
+
+* While using chrome and IE, the filename is not the one specified by "fileName" but the last string in the url. E.g. if the url is http://localhost:9000/1/namecard, the file name will be namecard instead of 1.xls which is specified in the program. There is not such problem in FF.
+
+Please refer to the sample for an example.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
+version=head
+frameworkVersions=1.0.1
@@ -0,0 +1,16 @@
+import models.Contact;
+import play.jobs.Job;
+import play.jobs.OnApplicationStart;
+import play.test.Fixtures;
+
+@OnApplicationStart
+public class Bootstrap extends Job {
+
+ public void doJob() {
+ // Check if the database is empty
+ if(Contact.count() == 0) {
+ Fixtures.load("initial-data.yml");
+ }
+ }
+
+}
@@ -0,0 +1,23 @@
+package controllers;
+
+import static play.modules.excel.Excel.renderExcel;
+
+import java.util.List;
+
+import models.Contact;
+import play.mvc.Controller;
+
+public class Application extends Controller {
+
+ public static void index() {
+ List<Contact> contacts = Contact.findAll();
+ render(contacts);
+ }
+
+ public static void generateNameCard(Long id) {
+ Contact person = Contact.findById(id);
+ renderArgs.put("fileName", person.getEntityId() + ".xls");
+ renderExcel(person);
+ }
+
+}
@@ -0,0 +1,22 @@
+package models;
+
+import javax.persistence.Entity;
+
+import play.db.jpa.Model;
+
+@Entity
+public class Contact extends Model {
+
+ private static final long serialVersionUID = -5806820381004668188L;
+
+ public String firstName;
+ public String lastName;
+ public String title;
+ public String address;
+ public String mobile;
+ public String email;
+
+ public String toString() {
+ return title + " " + firstName + " " + lastName;
+ }
+}
Binary file not shown.
@@ -0,0 +1,20 @@
+#{extends 'main.html' /}
+#{set title:'Contacts' /}
+
+<div id="header">
+<h1>Contacts</h1>
+</div>
+
+<div id="content">
+<table>
+<thead>
+<tr><th>Contact</th><th>Address</th><th>Email</th><th>Mobile</th><th>Action</th></tr>
+</thead>
+<tbody>
+#{list contacts, as: 'person'}
+<tr><td>${person}</td><td>${person.address}</td><td>${person.email}</td><td>${person.mobile}</td>
+<td><a href="@{Application.generateNameCard(person.id)}">generate namecard</a></td></tr>
+#{/list}
+</tbody>
+</table>
+</div>
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Not found</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ </head>
+ <body>
+ #{if play.mode.name() == 'DEV'}
+ #{404 result /}
+ #{/if}
+ #{else}
+ <h1>Not found</h1>
+ <p>
+ ${result.message}
+ </p>
+ #{/else}
+ </body>
+</html>
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Application error</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ </head>
+ <body>
+ #{if play.mode.name() == 'DEV'}
+ #{500 exception /}
+ #{/if}
+ #{else}
+ <h1>Oops, an error occured</h1>
+ <p>
+ This exception has been logged with id <strong>${exception.id}</strong>.
+ </p>
+ #{/else}
+ </body>
+</html>
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>#{get 'title' /}</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/main.css'}">
+ #{get 'moreStyles' /}
+ <link rel="shortcut icon" type="image/png" href="@{'/public/images/favicon.png'}">
+ <script src="@{'/public/javascripts/jquery-1.4.min.js'}" type="text/javascript" charset="utf-8"></script>
+ #{get 'moreScripts' /}
+ </head>
+ <body>
+ #{doLayout /}
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 222f154

Please sign in to comment.