100% found this document useful (3 votes)
80 views

Instant ebooks textbook Introducing Play Framework Java Web Application Development Second Edition Prem Kumar Karunakaran download all chapters

Karunakaran

Uploaded by

finnijoseyls
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
80 views

Instant ebooks textbook Introducing Play Framework Java Web Application Development Second Edition Prem Kumar Karunakaran download all chapters

Karunakaran

Uploaded by

finnijoseyls
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Introducing Play Framework Java Web Application


Development Second Edition Prem Kumar Karunakaran

https://textbookfull.com/product/introducing-play-framework-
java-web-application-development-second-edition-prem-kumar-
karunakaran/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Learn Java for Web Development Modern Java Web Development


Layka Vishal

https://textbookfull.com/product/learn-java-for-web-development-
modern-java-web-development-layka-vishal/

textboxfull.com

Methodologies and Application Issues of Contemporary


Computing Framework Jyotsna Kumar Mandal

https://textbookfull.com/product/methodologies-and-application-issues-
of-contemporary-computing-framework-jyotsna-kumar-mandal/

textboxfull.com

Building Web Apps with WordPress WordPress as an


Application Framework Brian Messenlehner

https://textbookfull.com/product/building-web-apps-with-wordpress-
wordpress-as-an-application-framework-brian-messenlehner/

textboxfull.com

PySide GUI Application Development - Second Edition


Gopinath Jaganmohan

https://textbookfull.com/product/pyside-gui-application-development-
second-edition-gopinath-jaganmohan/

textboxfull.com
Introducing Maven A Build Tool for Today s Java Developers
Second Edition Balaji Varanasi

https://textbookfull.com/product/introducing-maven-a-build-tool-for-
today-s-java-developers-second-edition-balaji-varanasi/

textboxfull.com

Java EE Development with Eclipse - Second Edition Ram


Kulkarni

https://textbookfull.com/product/java-ee-development-with-eclipse-
second-edition-ram-kulkarni/

textboxfull.com

Introducing Bootstrap 4: Create Powerful Web Applications


Using Bootstrap 4.5 - Second Edition Joerg Krause

https://textbookfull.com/product/introducing-bootstrap-4-create-
powerful-web-applications-using-bootstrap-4-5-second-edition-joerg-
krause/
textboxfull.com

Pro TypeScript: application-scale javascript development


Second Edition Fenton

https://textbookfull.com/product/pro-typescript-application-scale-
javascript-development-second-edition-fenton/

textboxfull.com

Pro Spring MVC with WebFlux Web Development in Spring


Framework 5 and Spring Boot 2 Second Edition Marten Deinum
Iuliana Cosmina
https://textbookfull.com/product/pro-spring-mvc-with-webflux-web-
development-in-spring-framework-5-and-spring-boot-2-second-edition-
marten-deinum-iuliana-cosmina/
textboxfull.com
Prem Kumar Karunakaran

Introducing Play Framework


Java Web Application Development
2nd ed.
Prem Kumar Karunakaran
Thiruvananthapuram, Kerala, India

Any source code or other supplementary material referenced by the


author in this book is available to readers on GitHub via the book’s
product page, located at www.​apress.​com/​9781484256442 . For more
detailed information, please visit www.​apress.​com/​source-code .

ISBN 978-1-4842-5644-2 e-ISBN 978-1-4842-5645-9


https://doi.org/10.1007/978-1-4842-5645-9

© Prem Kumar Karunakaran 2020

This work is subject to copyright. All rights are reserved by the


Publisher, whether the whole or part of the material is concerned,
specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other
physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book.


Rather than use a trademark symbol with every occurrence of a
trademarked name, logo, or image we use the names, logos, and images
only in an editorial fashion and to the benefit of the trademark owner,
with no intention of infringement of the trademark. The use in this
publication of trade names, trademarks, service marks, and similar
terms, even if they are not identified as such, is not to be taken as an
expression of opinion as to whether or not they are subject to
proprietary rights.

While the advice and information in this book are believed to be true
and accurate at the date of publication, neither the authors nor the
editors nor the publisher can accept any legal responsibility for any
errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained
herein.

Distributed to the book trade worldwide by Apress Media, LLC, 1 New


York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax
(201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the
sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
To my wife, Teena, and my daughters, Nayana and Nandana. My
gratitude to my parents for their support during all these years. Thanks
to all my friends for their support and encouragement.
Preface
Software developers need to have a number of traits in order to
practice their jobs well. A developer’s primary job is to create software
that solves business problems. Customers are operating in a dynamic
business environment and they need to change their business
solutions fast enough to retain and attract new customers. Hence,
rapid application development is a critical aspect of today’s software
development methodology. You need better frameworks and tools that
can help in developing quality software faster.
Play Framework is the new and impressive framework in web
application development. By breaking the existing standards, it tries
not to abstract away from HTTP, as with most web frameworks, but to
tightly integrate with it.
Play Framework is a revolution in rapid application programming
for Java web development. It has changed the rules of the game for Java
web development. Java web development was a tedious, time
consuming activity and there were many frameworks offering the
benefits of MVC architecture. But there were hardly any frameworks
capable of providing true rapid application development capabilities.
Play has changed all that.
Play is a clean alternative to the existing Java Enterprise stacks for
web development. Play focuses on developer productivity, scalability,
adherence to modern web standards (REST, JSON, Web Sockets, and
Comet, to name a few) and efficiency.
Using Play Framework, you just need to code your changes and hit
the browser refresh button to test your changes. Play will automatically
compile and deploy your changes. If there are any errors in your code,
Play shows them nicely in the browser. You are no longer required to
scan long exception traces to find out the cause of the error. Above all,
Play comes packaged with its own application server, which is
lightweight, fast, and easy to use. In a single sentence, Play is the single
framework you will need to start your Java web development. Java web
development is a lot easier, more fun, and more powerful thanks to Play
Framework.
This book is all you need to learn and use the new version of Play
Framework, Play 2. You will be taken through all layers of Play
Framework and you’ll get in-depth knowledge via as many examples
and applications as possible.

Further References
Play Framework official docs: www.playframework.com/
Google groups for Play:
https://groups.google.com/forum/#!forum/play-
framework
Questions related to Play:
http://stackoverflow.com/tags/playframework
Ebeans: www.avaje.org/
Twirl: https://github.com/playframework/twirl
Table of Contents
Chapter 1:​Getting Started with Play 2
Getting Ready
Installation
Prerequisites
Installing sbt
Installing conscript
Installing Giter8
Setting Up Play
Using Play Example Projects
Using sbt
Creating Your First Project
app
conf
build.​sbt
project
public
lib
test
Configuring Play to Work with Your Preferred IDE
Setting Up in Eclipse
Setting Up in IntelliJ
Hello World Application
Configuration
Controller and View
Testing Play Applications
Testing Views
Testing Controllers
Chapter 2:​Build System
Scala Build Tool/​Simple Build Tool
Core Principles
Benefits of sbt
Project Structure
Using sbt
Setting Definition
Resolvers
Complete build.​sbt
Complete plugins.​sbt
Quick Recap of SBT Commands
Chapter 3:​Play Controllers and HTTP Routing
MVC Programming Model
Model
View
Controller
HTTP Routing
Static Definition
Dynamic Parts in a URL
Passing Fixed Values
Optional Parameters
Application Configuration Using application.​conf
Controllers
Finishing the Bookshop Controller
saveComment Method
Testing the saveComment Action
Models
Scoped Objects
Session Scope
Flash Scope
Chapter 4:​Play Views and Templating with Scala
Composite Views
Designing a General Template
Code Snippets Templating Basics
Comments
Template Parameters
Import Statement
Iterating a List
Iterating a Map
If Blocks
Escaping Dynamic Contents
Chapter 5:​Concurrency and Asynchronous Programming
What Is Concurrency?​
Executor
Example 1:​Using Runnable
Example 2:​Using Callable
Asynchronous Programming with Play
Writing an Asynchronous App
Configuring Asynchronous Scheduled Jobs
Akka Basics
Chapter 6:​Web Services, JSON, and XML
Consuming Web Services
Processing Large Responses
Handling JSON
Consuming JSON Request
Producing a JSON Response
Handling XML
Example 1:​Simple XML Parsing
Example 2:​XML Parsing Using JAXB
Chapter 7:​Accessing Databases
Configuring Database Support
Working with an ORM
ORM Concepts
Key Terms
Relationship Direction
Configuring JPA
Using Ebean in Play
Ebean Query
Common Select Query Constructs in Ebean
Using RawSql
Relationships in Ebean
Chapter 8:​Complete Example
Chapter 9:​Using Play Modules
Creating a Module
Third-Party Modules
Chapter 10:​Application Settings and Error Handling
Filters
Action Composition
Error Handlers
Client Errors
Server Errors
How Global Settings Were Done Before Play 2.​6.​x
Chapter 11:​Working with Cache
Configuring Caffeine
Adding Caffeine to a Project
Configuring EhCache
Using the Cache API
Chapter 12:​Production Deployment
Configuring Apache httpd for Play
Load Balancing Using mod_​proxy_​balancer
Configuring Play with Nginx
Index
About the Author
Prem Kumar Karunakaran
is an enterprise architect with about 20 years of industry experience.
He holds a M.Tech in Software Systems from BITS Pilani and a
bachelor’s degree in electronics engineering from Cochin University of
Science and Technology. He is also an Oracle Certified Java Enterprise
Edition Master. He was involved in the architecture and design of many
cutting-edge products used by clients around the globe. He has worked
with organizations such as Infosys and IBS as an architect and has
worked in many projects spanning airlines, logistics, travel, and retail
domain. He is passionate about Java, Machine Learning, BigData
processing and Cloud and loves to learn new technologies; he
contributes his time to open source initiatives as well.
About the Technical Reviewer
Satheesh Madhavan
has nearly 20 years of experience in the software industry and
currently serves as a digital consultant in one of India’s largest IT firms.
He has experience working in Java and JEE technologies in providing
enterprise solutions under various capacities. His qualifications
include an M.S in software systems from BITS Pilani and a B.Tech in
chemical engineering from the University of Kerala. His hobbies
include reading fiction and non-fiction, Philately, technical blogs and
podcasts, and astrophysics and pure sciences.
© Prem Kumar Karunakaran 2020
P. K. Karunakaran, Introducing Play Framework
https://doi.org/10.1007/978-1-4842-5645-9_1

1. Getting Started with Play 2


Prem Kumar Karunakaran1
(1) Thiruvananthapuram, Kerala, India

After reading the introductory section on Play 2, you should now have an idea of the capabilities of Play
Framework and how it can accelerate Java web development. This chapter is about
Installing Play Framework
Setting up Play Framework on your machine
Configuring Play Framework
Creating the first sample project
Setting up the IDE

Getting Ready
All you need is a browser and Internet connectivity. You can install Play on a wide variety of operating
systems, including Microsoft Windows, Linux, and Mac. The operating system should have Java installed.

Installation
Play just needs the Play jars available at runtime to work, hence you can include the Play jars in any
application using Maven or any such build tool.
But the recommended way to use Play is to install it using either sbt or Gradle because Play provides
a better development experience when using sbt or Gradle.

Prerequisites
Play 2.x requires JDK 1.8 or later to be installed on the machine. Please note that JRE is not enough; you
need JDK Version 8 or higher. You should ensure that the PATH variable points to the JDK bin directory
and that javac and Java are accessible from everywhere.
You can check this by typing javac -version in the command prompt or shell and verify that the
version is 1.8 or above.
You can get Java SE from the Oracle website at
www.oracle.com/technetwork/java/javase/downloads/index.html.
Play also works with Open JDK version 1.8 and above. But you should make sure that any dependency
you use in the project is compatible with the Open JDK.

Installing sbt
sbt (Scala build tool) is available for all OS versions at the scala-sbt website at www.scala-
sbt.org/download.html. Please follow the instructions in the installation guide at www.scala-
sbt.org/1.x/docs/Setup.html to install sbt.

Installing conscript
To install Play using sbt, you need to install conscript. Please follow the instructions at
www.foundweekends.org/conscript/setup.html to install conscript. The instructions are
available for Mac, Linux, and Windows.
The cross-platform installation using a jar is simple. Download the conscript jar from the
foundweekends Maven release repo (https://dl.bintray.com/foundweekends/maven-
releases/org/foundweekends/conscript/conscript_2.11/0.5.2/conscript_2.11-
0.5.2-proguard.jar) and run the following from the command prompt:

java -jar /conscript_2.11-0.5.2-proguard.jar

This will start a splash screen and will install conscript. Ignore any error related to not finding ‘cs.’
Typically, conscript will get installed in the C:\Users\username\.conscript folder in Windows,
where username is the home folder of the logged-in user in Windows. This location will be shown in the
splash screen.
Now let’s set up the environment variables for conscript:

export CONSCRIPT_HOME=" C:\Users\username\.conscript"


export CONSCRIPT_OPTS="-XX:MaxPermSize=512M -Dfile.encoding=UTF-8"
export PATH=%PATH%;%CONSCRIPT_HOME%\bin

CONSCRIPT_HOME is where conscript will download various files. For example, in Windows, it will
be C:\Users\username\.
PATH is your OS’s path variable. This will make the command cs available from everywhere.

Installing Giter8
After installing conscript, Giter8 can be installed using conscript itself. Giter8 is a command-line tool to
generate files and directories from templates published on GitHub or any other git repository.
Go to a command prompt and type

cs foundweekends/giter8

This will download and install Giter8. More details of the installation is available from the
foundweekends website for Giter8 (www.foundweekends.org/giter8/setup.html).

Setting Up Play
There are multiple ways to install Play. Let’s look at the two most common ways:
Using Play example projects: Use any of the example projects provided by Lightbend Tech Hub
(https://developer.lightbend.com/start/?group=play).
Using sbt: This approach depends on Giter8 templates for sbt. This method creates a fresh Play
project without any example code. This is the preferred mode for a clean, lean project structure.

Using Play Example Projects


Play provides many example projects for making the installation easier. If you follow this path,
installation of sbt is not required because the template provides sbt launchers for the Unix and Windows
environments.
Let’s try the first approach: installing the Play example project in Scala.
1. Go to https://developer.lightbend.com/start/?group=play.

2. Choose the project PLAY SCALA HELLO WORLD TUTORIAL.

3. Click the “Create a project for me” button (this will download the example project to your system).

4. Unzip the archive (play-samples-play-scala-hello-world-tutorial.zip).


5. Go to the folder named play-samples-play-scala-hello-world-tutorial and double-
click the sbt.bat file if on Windows. If you are on a Mac or Unix-based system, run the sbt file.
It will take a while to download the sbt and all dependencies.
Once the sbt build is successful, you will see the message

sbt server started at local:sbt-server-f50b441db70fa47676ba

Note that the last part of the message (f50b441db70fa47676ba) might be different for you
but that is okay. You are now good to go and you will see the prompt as

[play-scala-seed] $

6. Type the run command to start the application:

[play-scala-seed] $ run

As soon as this step completes, the prompt will display

(Server started, use Enter to stop and go back to the console...)

7. Go to http://localhost:9000. If all is good, you should see the Play documentation displayed
in the browser.

Now let’s see how to install a Play example project using Java.
1. Go to https://developer.lightbend.com/start/?group=play.

2. Choose the project PLAY JAVA HELLO WORLD TUTORIAL.

3. Click the “Create a project for me” button (this will download the example project to your system).

4. Unzip the archive (play-samples-play-java-hello-world-tutorial.zip).

5. Go to the folder named play-samples-play-java-hello-world-tutorial and double-


click the sbt.bat file if on Windows. If you are on a Mac or Unix-based system, run the sbt file.

6. This will download all the dependencies and perform the build. Please note that it might take a while
to download all the dependencies.

7. Once the build is over, the command prompt will show

[play-java-hello-world-tutorial] $

8. Type the run command to start the play application:

[play-java-hello-world-tutorial] $ run

Using sbt
Now you’ll learn how to install Play using sbt to get the basic Play application structure and dependent
jars but not the example projects.
To use sbt to create a Play project, the following needs to be completed:
1. Install SBT.

2. Install conscript.

3. Install Giter8.

You can find instructions for installing the above software in the Installation section of this chapter.
Once the above software is installed, you can proceed with creating a Play project using sbt. Play
supports Java and Scala as programming languages, so I will show examples for both using sbt.

Installing a Java Project Using sbt


Take a command prompt, change to the directory where you want the project to be created, and type

sbt new playframework/play-java-seed.g8

This will install a Java starter project structure.


The wizard will ask for the project name and organization. (By convention, this is a reverse domain
name that you own, typically one specific to your project. It is used as a namespace for projects.) Once
these names are supplied, the project will get created.

Installing a Scala Project Using sbt


Here is the command:

sbt new playframework/play-scala-seed.g8

Provide the project name and organization, and the project will get created.
You have now learned multiple ways to install a Play project for both Scala and Java:
Using Play examples
Using sbt
In this book, I use Java as the programming language for Play, so when you create your first project (a
bookshop) in the next section, you will be using sbt and the Java seed.

Creating Your First Project


Let’s create a new project called bookshop to explore Play in detail. Name your project bookshop and,
for the ease of explanation, let’s make it an online retail application selling books, a domain familiar to
everybody.
From a command prompt or shell, type

sbt new playframework/play-java-seed.g8

See Figure 1-1.


Figure 1-1 Creating a project
Provide the following for the project name and organization:

name [play-java-seed]: bookshop


organization [com.example]: com.stackrules.example

For the organization name, you can give another domain name if you want to do so.
Go to the directory where you created project. For instance, in my machine, the project directory is
E:\workarea\bookshop.
Let’s look at the folder structure and its relevance in the overall project organization. See Figure 1-2.

Figure 1-2 Project structure

app
The app folder contains all your server-side source files. This includes all your Java code, Scala code,
dynamic Scala HTML templates, database access-related code, etc. By default, Play creates two folders,
controllers and views, inside the app folder. The names are self-explanatory. The controllers
folder holds your controller classes and views holds the dynamic screens (the HTML and Scala code
snippets).
You are free to create subdirectories inside the app folder for better organization of your files. For
example, you can create a models folder to hold all your ORM mapped POJOs, a folder named helper to
hold your helper classes, etc.
Most of the project will have the following structure under the app folder:
app
└ assets: Compiled asset sources
└ stylesheets: For CSS source code (less CSS sources)
└ javascripts: Typically this is the folder where coffeescript sources are placed.
└ controllers: Application controllers
└ models: Application business layer
└ views: Templates

conf
The conf folder holds the configurations used by the Play application. It contains all the HTTP
mappings, orm configurations, environmental variables, logging, etc.
Basically, the conf directory contains configuration and internationalization files, whereas the app
folder has a subdirectory for its model definitions.
The most important files in this directory are
application.conf: The main configuration file for the application, it contains standard
configuration parameters.
routes: Maps HTTP URL paths to methods in the controller. Handles all HTTP routing configurations.
logback: Play uses logback for all logging configuration and this is the file you need to change to
configure logback.

build.sbt
Play’s build configuration is defined in two places: the build.sbt file in the project root and two files
found inside the /project folder. The build.sbt files contain the build configuration.

project
The project folder contains project build configurations:
plugins.sbt: Defines the sbt plugins used by this project
build.properties: Contains the sbt versions to use to build your app and related sbt build
information.
I will discuss more about sbt going forward. A basic understanding of sbt is good when you work
with Play.

public
The public folder hosts all static files like Javascripts, images, and CSS style sheets that are directly
served by the web server. The public folder has three subfolders, images, javascripts, and
stylesheets, for storing these assets:
public
└ stylesheets: CSS files (.css extension)
└ javascripts: JavaScript files (.js files)
└ images: Images
lib
The lib folder is not created by default. But you can create this folder and put any jar into it. All jars in
this folder will be added to the application class path. It’s ideal for including third-party dependencies
that need to be managed out of the Play build system.

test
The test folder is a holder for storing all unit and functional test cases.

Configuring Play to Work with Your Preferred IDE


Since you have finished setting up the project structure and have generated a project template, let’s now
integrate the project with an IDE to make the development process easier and more rapid.
You don’t need a sophisticated IDE to work with Play because Play compiles and refreshes the
modifications you make to your source files automatically. This gives you the flexibility to use a simple
editor like Notepad or a vi editor to work with Play. But this is not a practical case for real-world
projects. You need an IDE that provides better navigation, autocompletion, debugging, refactoring, etc.
By default, Play supports most of the popular IDEs like Eclipse, IntelliJ, NetBeans, and ENSIME.
For this book, I will use Eclipse as the IDE .You can use any IDE of your choice to try out the samples.

Setting Up in Eclipse
As an example, let’s configure Play for Eclipse. To use Play with Eclipse, you need to first integrate
sbteclipse to your project. To do this, open plugins.sbt (project/plugins.sbt) and add the
following:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.2")

You want to compile the project before you run the eclipse command to generate the eclipse import
settings for the bookshop project. The manual way is to run sbt compile first and then do the
generate eclipse project part. But you can do it in a better and automated way; you can instruct it to run
compilation first whenever you generate eclipse project settings. For this, open the build.sbt file and
add the following:

EclipseKeys.preTasks := Seq(compile in Compile, compile in Test)


EclipseKeys.projectFlavor := EclipseProjectFlavor.Java
EclipseKeys.createSrc :=
EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses,
EclipseCreateSrc.ManagedResources)

Please note the above is only for Java projects. If you have Scala sources, then you should use Scala
IDE instead of the regular Eclipse IDE.
Save the build.sbt file and go to the sbt prompt by taking a command prompt, moving to the
project root directory (E:\workarea\bookshop) and typing sbt.
This initializes the sbt prompt. This can take few minutes to complete because sbt will download the
plugins and all related dependencies. Once the sbt prompt gets initialized, you should see the prompt as

[bookshop] $

Type eclipse with-source=false and press Enter. If you need all the source jars of the
dependencies, you can issue eclipse with-source=true instead.
After the successful execution of the above command, start eclipse and import the project. See Figure
1-3.
Figure 1-3 Import Wizard
1. Open Eclipse.

2. Click File ➤ Import ➤ General ➤ Existing Projects into Workspace.

3. Browse and choose the root project folder (bookshop).

4. Click Finish.

Setting Up in IntelliJ
Importing a Play project to Intellij is pretty straightforward. The only precondition is that the Scala
plugin for Intellij should be installed, even when using Java as the language. This is because the Scala
plugin for Intellij is required to resolve the sbt dependencies. So go ahead and install the Scala plugin for
Intellij if you have not done so. Open Intellij and go to File ➤ Settings ➤ Plugins and search for Scala in
the Marketplace tab. From the plugins listed, select the Scala plugin from JetBrains and click Install. See
Figure 1-4.
Figure 1-4 Importing the Scala plugin
After installing the Scala plugin, import the bookshop Play project to IntelliJ. See Figure 1-5.

Figure 1-5 Importing a project


1. Open File ➤ New ➤ Project from Existing Sources.

2. Browse to the bookshop project root folder (E:\workarea\bookshop).

3. Select Import project from the external model.

4. Choose sbt.

5. Click Finish.

Wait for the build to sync and you will see that the project is imported to Intellij.

Hello World Application


You have your project ready and you have imported the IDE of your choice. Let’s add some files to it and
create the Hello World program. From there you will add more features to it and expand it.
Let’s start the Play server and try the default application.
1. Open a command prompt.

2. Go to the project root folder (E:\workarea\bookshop).

3. Go to the Play console by typing sbt in the root folder.

4. This will open up the Play console prompt ([bookshop] $).

5. Type run to start the Play server. See Figure 1-6.

(If the server started, use Enter to stop, and go back to the console.)

You can even combine the commands together to start Play by using

sbt run
Figure 1-6 Application console
Open the browser and access http://localhost:9000/ to access the home page. See Figure 1-
7.

Figure 1-7 Welcome page

Configuration
Go to the conf folder and open the routes file. This is where all the URL mappings of the project need
to be defined. You will examine URL mappings and routes configuration in detail in the next chapter.
When you open up the routes file, you should see an entry like this:

GET / controllers.HomeController.index

This means the root of the application points to the index method defined in the
HomeController class.
If you type localhost:portnumber in the browser, the request will be routed to the index
method defined in the app/controllers/HomeController.java file.
This is how Play routes the URL paths or URL patterns to the specific methods of the controller
classes.
Open the HomeController.java file and you can see the method

public Result index() {


return ok(views.html.index.render());
}

This method returns a Twirl template file and this template file generates the HTML output. Open the
index.scala.html file found inside the views folder. Let’s examine the contents of this file to
understand what is happening in it.

@()

@main("Welcome to Play") {
<h1>Welcome to Play!</h1>
}

Before we take a look at each element, it is important to understand what Twirl is and how it can be
used.
What is Twirl?
Twirl is the template engine developed for Play Framework. But it can also be used outside the Play
environment. By default, Twirl is included as part of Play but if there is a need to use Twirl outside
Play, then the sbt plugin for Scala can be installed. For example adding the below entry in the
plugins.sbt file will make Twirl available to any sbt-based project:

addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "LATEST_VERSION")

Template files must be named {name}.scala.{ext} where ext can be html, js, xml, or txt.
The templates can be used to generate various types of markup like HTML, XML, or TXT and are
totally decoupled from the controller. Various kinds of markup can be plugged in as needed.
The Twirl template is just a normal text file that contains small blocks of Scala code. Templates
help to create composite views and help in a component-based view generation.
The @ character marks the beginning of the dynamic code in the template. Chapter 4 of this book
provides detailed explanation of views and Twirl templates.

For the time being, let’s understand what is defined in the index.scala.html file:

@main("Welcome to Play") {
<h1>Welcome to Play!</h1>
}

@main("Welcome to Play") calls another template, main.scala.html and passes it the page
title “Welcome to Play” and the HTML content in the second parameter, enclosed within the {}.
Hence you can infer that main template file should take two parameters: a string for the title and
HTML content as the second parameter.
Open the main.scala.html to validate this. The file starts with @(title: String)
(content: Html); this is just like any normal method that accepts two parameters.

@*
* This template is called from the `index` template. This template
* handles the rendering of the page header and body tags. It takes
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
*@

@(title: String)(content: Html)

<!DOCTYPE html>
<html lang="en">
<head>
@* Here's where we render the page title `String`. *@
<title>@title</title>
<link rel="stylesheet" media="screen"
href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png"
href="@routes.Assets.versioned("images/favicon.png")">
</head>
<body>
@* And here's where we render the `Html` object containing
* the page content. *@
@content

<script src="@routes.Assets.versioned("javascripts/main.js")"
type="text/javascript"></script>
</body>
</html>
The title string is inserted to HTML <title> using @title and HTML content using @content
markup.
Now you know the different elements and how they are wired together. Let’s take this further by
writing a new action and a view.
Let’s create an entry for the Hello World method:

GET /hello controllers.HomeController.hello()

Save the routes file. The next step is to code your controller to handle the request.

Controller and View


Inside the app/controllers folder , you should find the HomeController.java file . This is your
default controller.

package controllers;

import play.mvc.*;
import views.html.*;

import java.time.LocalDate;

/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class HomeController extends Controller {

/**
* An action that renders an HTML page with a welcome message.
* The configuration in the <code>routes</code> file means that
* this method will be called when the application receives a
* <code>GET</code> request with a path of <code>/</code>.
*/
public Result index() {
return ok(views.html.index.render());
}
}
}

Let’s examine the HomeController class in detail to understand what is happening in it. First of
all, it extends from play.mvc.Controller. When you write a new controller, make sure you extend
from play.mvc.Controller.
You’ve seen the index method before: it is pretty simple and it just has a single line. But it does a lot
of smart things. The ok() method is closely related to HTTP status 200, or the success response. If you
want to return a HTTP not found, you can use the notFound method. This is the beauty of Play; it
closely resembles HTTP protocol and there is no need for any fancy code to convert your exceptions to
corresponding HTTP status codes. You can code and talk the language of HTTP.
The ok() method returns the HTML output generated by the render method, defined in the view
named index. You’ve seen this view in index.scala.html. Views in Play use Scala and follow the
naming convention of “viewname.scala.html”. This file gets compiled by the Play compiler into the
corresponding Java class, which can be directly used in the controller. This ensures type safety and less
bugs. Remember that in other frameworks like struts or Spring MVC, you typically return a string as view
name and the framework resolves that to a file. In Play, there is no need for that. The views are
straightaway available as Java class files and you can ensure compile-time type safety.
Since you have already added the routes entry for the hello method, let’s proceed with adding the
controller method and create the view.

View
Create a new file inside the app/views folder and name it hello.scala.html and add the following
contents:

@(message: String)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World </title>
</head>
<body>
<h1> @message </h1>
</body>
</html>

This template takes a single parameter and places that inside the HTML <h1> tags.

Controller
Now edit the HomeController:

package controllers;

import play.mvc.*;
import views.html.*;

import java.time.LocalDate;

/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class HomeController extends Controller {

/**
* An action that renders an HTML page with a welcome message.
* The configuration in the <code>routes</code> file means that
* this method will be called when the application receives a
* <code>GET</code> request with a path of <code>/</code>.
*/
public Result index() {
return ok(views.html.index.render());
}
public Result hello() {
return ok(views.html.hello.render("Today is "+LocalDate.now()));
}
}

Open your browser and go to

http://localhost:9000/hello
You will see the message “Today is” and the current date. See Figure 1-8.

Figure 1-8 The Hello page

Just change any HTML code in the view and refresh the browser. Play will perform on-the-fly
compilation and render the view.

Enhancing the View


Let’s now enhance the hello.scala.html file to reuse the main template already available in the
view folder. By using this template you will be able to get the common theming across pages because
main.scala.html defines the common layout and style sheets.
Go to the public/stylesheets folder and open main.css. This is the master style sheet for the
application. You will make the background black and the text white in color:

body {
background: black;
}
h1,h2 {
color: white;
}

Go to http://localhost:9000/ to the see the changes. But wait, if you go to


http://localhost:9000/hello, the display shows the white background! Why?
The reason is your style sheet definitions and all site-wide settings are defined in the
main.scala.html template but you never used it in the hello.scala.html file. Let’s fix that.
Edit the hello.scala.html and replace its contents as follows:

@(message: String)

@main("Hello World") {
<h2>@message</h2>
}

You want a common theme across the web application and all pages should inherit the site wide
settings as is. You don’t want to scatter the site-wide definitions across all pages, so put all common
settings like header, footer, style sheet definitions, JavaScript inclusions, etc. in a single file; that is what
main.scala.html is used for. It defines the common elements applicable to all pages.
The main.scala.html file is converted by Play into a method equivalent and can be invoked from
other pages using its name. The name doesn’t include the .scala.html part. For instance,
Random documents with unrelated
content Scribd suggests to you:
XXII

Helsingissä oli tullut tänäkin vuonna kevät niinkuin lehdet tulevat


Esplanaadien puihin, ja Albert Hakalalle se oli tullut suurine
sielullisine tulvineen ja suurine suruineen.

Hän, joka niin paljon rakasti nuorisoa ja joka koko sydämensä


lämmöllä todella toivoi nuorille parasta, oli vähitellen, varsinkin
kuluneen talven aikana, oppinut huomaamaan, että hän ei
sittenkään oikein sopinut nuorisonkasvattajaksi.

Mitä hän välitti siitä, että ilkeät kielet parjasivat häntä Lahja
Kaarion tähden. Olihan siitä puhuttu niin, että jutut olivat päässeet
hänenkin korviinsa. Itse hän parhaiten tiesi, kuinka paljon oli
kärsinyt tuon onnettoman suhteen takia. Ja täytyihän niiden juttujen
kerran vaieta, kun neiti Kaario nyt oli onnellisesti kihloissa. Mutta
enemmän koski häneen sittenkin tunto siitä, että opiskeleva nuoriso,
varsinkin osakunnassa, oli ymmärtänyt häntä väärin, pitäen häntä
ankarana tuomarina, joka itseltänsä vaati vähän, mutta muilta sitä
enemmän…

Kauan mietittyänsä asiaa hän oli vihdoin ilmoittanut osakunnan


virkailijoille luopuvansa kuraattorintoimestaan. Hänellä oli siitä
huolimatta, että niin suuri osa osakuntalaisia oli myötätunnolla
seurannut hänen pyrintöjään, kuitenkin vastustamaton halu jättää
koko osakunta, sillä varsinkin viimeisen suuren puheensa jälkeen hän
tunsi sanoneensa kaiken, mitä hänellä oli sydämellään, ja hän tahtoi
väistyä syrjään jättääksensä paikkansa jollekin toiselle. Hänen
eronsa kuului herättäneen suurta huomiota ja mielipahaa
osakunnassa. Mutta päivällisillä, jotka pidettiin eroavan kuraattorin
kunniaksi, hän kuitenkin huomasi tehneensä oikein jättäessään
asemansa jollekin toiselle…

Osanotto päivällisiin oli ollut harvinaisen suuri, katsoen siihen, että


oli kevät, jolloin osa ylioppilaista oli jo matkustanut maalle. Myöskin
puheet olivat olleet ystävällisiä ja lukuisia. Mutta siitä huolimatta hän
tunsi hermoillaan, että oli tehnyt viisaasti luopuessaan toimesta, joka
kuitenkin oli hänelle sanomattoman rakas. Häneltä ei jäänyt
huomaamatta, että monet osakunnan huomattavimmista
toimihenkilöistä, joiden hän tiesi kuuluvan hänen vastustajiinsa,
olivat jääneet pois.

Hän sai osakuntalaisilta kauniin hopeaisen maljakon, jonka kylkeen


oli kaiverrettu hänen nimensä, osakunnan nimi ja vuosiluvut, joina
hän oli ollut osakunnan kuraattorina, nuo rakkaat, vaiherikkaat
vuodet…

Hän oli kiitollinen nuorisolle siitä näkyväisestä lahjasta, joka oli


hänellä kotona aina muistuttamassa siitä, että suurin osa osakunnan
parhaimmistoa oli sittenkin ymmärtänyt häntä oikein, taikka ainakin
uskonut, että hän tarkoitti nuorison parasta. Erikoisesti hämmästytti
häntä se, että hänen kiivaan vastustajansa, tuomari Katajistonkin
käyntikortti oli korttien joukossa…
Erotessaan toimestaan ja pitäessään kiitos- ja
hyvästijättöpuheensa hänen kunniakseen pidetyillä päivällisillä hän
oli lopettanut lausumalla toivomuksen, että hän vielä muutenkin kuin
vain yliopiston opettajana voisi edelleen toimia nuorison herättäjänä
ja nuorison hyväksi…

Hän oli usein miettinyt, mitenkä voisi täyttää lupauksensa, ja


vihdoin se oli kirkastunut hänelle… Hän aikoi kerran kirjoittaa kirjan,
jossa käsittelisi nuorisokysymystä sen kaikilta mahdollisilta puolilta.
Saattoiko hän toteuttaa aikomuksensa, oli jäävä tulevaisuuden
ratkaistavaksi. Nyt hän ei vielä ainakaan sitä ehtinyt tehdä, sillä
suuri, tekeillä oleva taidehistoriallinen teos »Sadun moraali» ei ollut
vielä valmis…

*****

Kesä oli jo ehtinyt heinäkuun alkuun, ja yhä viipyi tohtori Hakala


perheineen kaupungissa. Heidän oma, tulipalon jälkeen korjattu
talonsa Kaivopuistossa oli kylläkin viileä ja sopiva vaikkapa
kesäasunnoksikin, sillä olihan sen yhteydessä, paitsi suurta
Kaivopuistoa, oma pienoinen puutarhansa. Ebba oli tahtonut jäädä
Annikin kanssa kaupunkiin, kun Albert joka tapauksessa yliopiston
kirjastossa käsillä olevien töidensä takia olisi jäänyt kaupunkiin.

Iltapäivisin, lopetettuaan työnsä kirjastossa, Albert kulki usein


Annikin kanssa kaupungilla. Aurinko paistoi helteisesti, ja kuumat
kadut ja korkeat kivimuurit huokuivat lämpöä, mutta hän ei kärsinyt
siitä, sillä hän iloitsi lämmöstä, jota tässä maassa ei suinkaan
koskaan saanut tarpeeksi, puhumattakaan liiasta…

Suloista oli nähdä, kuinka kivet kukkivat.


Ne, jotka eivät olleet voineet päästä maalle, näkyivät ikäänkuin
suurella kauneuden- ja tuoreudenjanolla hankkineen itsellensä
kukkia ja kasvavia kasveja. Avonaisissa akkunoissa näkyi
lukemattomia, kirkasvärisiä kukkia. Satojen akkunoiden eteen oli
ilmestynyt punaisia ja vihreitä, monivärisiä kukkia kantavia
multalaatikoita, akkunoiden riippuvia puutarhoja…

Kaupungin kaikki puistot ikäänkuin kilpailivat kukkasupeudessaan.


Esplanaadien istutukset olivat suorastaan ruhtinaalliset, Kappelin ja
Tähtitorninmäen hortensiat kerrassaan huimasivat upeudessaan
värijanoisia silmiä. Oopperakellarin edustalla ja yliopiston kirjaston
pihalla kukkivat suuret kastanjapuut niinkuin konsanaan Pariisin
bulevardeilla ja levittivät suurista, valkoisista kukistaan, jotka seisoa
törröttivät kuin kynttilät kuusen oksilla, huomaavaa tuoksuaan…
Siellä, missä Kaartinkalliot ennen olivat olleet, kukki nyt tuo talvisin
ja keväisin niin kovalta ja karulta vaikuttava »kalliokaupunki»
tuhansine kukkineen. Jokaisen talon akkunoilla, parvekkeilla,
seinävierillä, pihoilla ja aidoilla kasvoi sadoittain mitä erilaisimpia,
suloisesti tuoksuvia kukkia. Villiviini kierteli pilareita kuin konsanaan
etelässä, ja monen »huvilan» rautaportin takaa pilkisti paratiisillinen
piha niinkuin Rivieralla tai Italiassa. Nämä ennen kuivat ja karut
kalliot todella kukkivat…

Lähelle Eiran sairaalaa oli syntynyt pienoinen Luxembourgin puisto


valkoisine penkkeineen, satoine ruusuineen ja lukemattomine
leikkivine, iloisine lapsineen. Tämän puiston kauneudesta ei
puuttunut muuta kuin vilpoisesti soiva suihkulähde altaineen, jossa
lapset auringonpaisteessa olisivat uittaneet valkopurjeisia laivojaan.
Mutta puistoista ehkä kaunein ja ainakin luonnollisin oli suuri
Kaivopuisto, jossa lukemattomat sireenipensaat kukkivat kymmenin
värivivahduksin kuin maalaispappiloiden puutarhoissa, jossa
ruohokentät hymyilivät tuoreempina kuin missään muualla, ja jossa
ihmiset saivat niillä vapaasti istuskella ja loikoilla.

Lauvantai-iltoina oli liikettä ja menoa. Tuhansiin nousevat iloiset


joukot työläisiä ja pikkuporvareita pyrkivät rautatieasemalle ja
satamiin merenrannalle. Illan tunnussanat olivat: maalle, saareen,
riippumattoihin ja kahvikesteihin ulkosalla.

Harva näky maailmassa oli Albertista niin iloinen, elämänhaluinen


ja värikäs kuin suuret ihmisjoukot Kaivopuiston, Kaisaniemen ja
Eläintarhan nurmilla. Vaaleita, keveitä pukuja, päivänvarjoja, vanhoja
ja nuoria ihmisiä, leikkiviä lapsia, sanomalehtiä lukevia perheenisiä,
riippumattoja, ruokakoreja, paloöljykeittiöillä kiehuvia kahvipannuja,
paukahtelevia virvoitusjuomapulloja, puhetta, huutoa, naurua,
soittoa, iloa ja ääntä…

Hän olisi itse mielellänsä sekoittunut tuohon kirjavaan joukkoon,


mutta hän ei sentään kehdannut…

Eräänä heinäkuun sunnuntain iltapäivänä Albert seisoo


Kaivopuiston korkealla, vanhalla vallilla. Hänen takanansa on
kesäinen kaupunki tuhansine iloisine ja kärsivine ihmisineen. Aurinko
paistaa jo laskussaan kaupungin takana, ja Viaporin suurimman
saaren kivirakennusten seinät hehkuvat valkean hohtavina niinkuin
unelmien valkeat kaupungit…

Meri näkyy laajana, rannattomana hänen edessään. Monet saaret


kukkivat vihreinä sen aaltoilevassa, vilpoisessa sylissä. On maatuuli,
joka tuo kukkivasta kaupungista suloisen, monesta kukasta
lähteneen lauhan tuoksun, niinkuin hyvin kallisarvoisen hajuveden
lemun, joka on puserrettu sadoista erilaisista kukista.
Annikki leikkii käytävällä loistavavärisellä gummipallolla. Albert on
istahtanut penkille ja katselee merelle päin. Lauhat, tuoksuvat
tuulenpuuskat nostattavat laineita, jotka pakenevat rannasta pois
ulappaa kohti. Albertin ajatukset kiitävät noiden laineitten lailla. Ne
syntyvät ja kuolevat samoinkuin hänen ajatuksenakin.

Hän on tavallaan epäonnistunut elämässään… Hän ei ole


onnistunut nuorison kasvattajana eikä myöskään avioliitossaan eikä
rakkaudessaan… Suurilla työn lupauksilla Ebba ja hän olivat
lähteneet elämän taipaleelle. Hän oli tehnyt paljon työtä heidän
yhteisen onnensa hyväksi, mutta onni oli ollut lyhytaikainen ja
epämääräinen… Hänessä itsessään oli piillyt paljon voimia, joiden
olemassaoloa hän tuskin oli osannut aavistaa, ja ne olivat särkeneet
heidän kauniin onnensa… Eräs jakso heidän elämässään oli taaskin
kulunut, mutta he eivät olleet oppineet senkään ajanjakson
taisteluista, myrskyistä ja kokemuksista mitään, sillä mitkään
tilanteet elämässä eivät uusiinnu samanlaisina, ja näin on elämä
koulua alusta loppuun saakka…

Hän oli kuvitellut voivansa opastaa elämän vaikeilla poluilla muita,


kokonaisia joukkoja, mutta kuinka hän voisi sitä, kun hän ei itsekään
osaa elää…

Albert katselee kauan edessään leikkivää Annikkia. Hänen suunsa


vetäytyy hymyyn.

Ihmiset etsivät helmeä aavan meren rantahiekasta eivätkä


huomaa, että se löytyy kätkettynä suljettuun simpukankuoreen…

Hän nousee seisomaan. Edessä loistavat valkeat kaupungit, ja


etäämmällä kukkivat saaret rannattomassa meressä. Hänen
takanansa hymyilee laskevan auringon valossa suorien katujen ja
kauniitten puistojen hurmaava kaupunki. Tuoksuva maatuuli käy
rajummaksi ja vierittää aaltoja ulapalle pois kauaksi merelle. Albertin
valtaa sanomaton halu niiden matkaan, pois kauaksi merien taa,
toisiin maihin, toisiin oloihin uusia vaikutelmia saamaan…

Loppuisipa vihdoinkin tämä hirvittävä sota, jossa toiset kuolevat,


toiset vanhenevat odottaessaan sen päättymistä… Yli noiden
vapaiden aaltojen, pois, kauaksi etelään, vain lyhyeksi aikaa, ja
sitten taas tänne takaisin uusin voimin, uusin innoin työhön…

Hän kutsuu Annikin syliinsä. Hän tahtoo kasvattaa edes yhdestä


olennosta onnellisen ihmisen.

Hän juttelee Annikille paljon hauskoja asioita. Annikki kuuntelee ja


leikkii hänen kellonsa vitjoilla. Hetkiseksi hän vaikenee ja katselee
Annikkia silmiin ja ajattelee itseksensä:

— Sinussa on minulla tarpeeksi nuorisoa. Olen onnellinen, jos


sinusta vihdoinkin löydän sen kalliin helmen, jota sieluni ikävöi. —
Mutta Annikille hän sanoo ääneen:

— Nyt me lähdemme kotiin äidin luo ja kerromme hänelle siitä,


mitä taaskin olemme kaupungilla nähneet.

Ja hän käveli taluttaen pientä Annikkia alas korkeita, puisia


portaita, jotka johtivat kaupungin puistoista kauneimpaan,
Kaivopuistoon, ja auringon laskussa kimaltelevat aallot vierivät pois
rannasta ulappaa kohti niinkuin hänen sielunsa salaisin kaipaus…
*** END OF THE PROJECT GUTENBERG EBOOK KOHTALON
TUULISSA ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like