Skip to content

Commit 5c5c99c

Browse files
committed
Tabs to Spaces
1 parent 7bc3d7b commit 5c5c99c

11 files changed

+181
-182
lines changed

_posts/2015-03-17-modularity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class FreemarkerInitializer implements Initializer {
3434

3535
@Override
3636
public void init(Application application) {
37-
application.registerTemplateEngine(FreemarkerTemplateEngine.class);
37+
application.registerTemplateEngine(FreemarkerTemplateEngine.class);
3838
}
3939

4040
@Override

_posts/2015-03-17-security.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,43 @@ I will show you a simple implementation for a security filter.
1515
```java
1616
// authentication filter
1717
GET("/contact.*", routeContext -> {
18-
if (routeContext.getSession("username") == null) {
19-
routeContext.setSession("originalDestination", routeContext.getRequest().getContextUriWithQuery());
20-
routeContext.redirect("/login");
21-
} else {
22-
routeContext.next();
23-
}
18+
if (routeContext.getSession("username") == null) {
19+
routeContext.setSession("originalDestination", routeContext.getRequest().getContextUriWithQuery());
20+
routeContext.redirect("/login");
21+
} else {
22+
routeContext.next();
23+
}
2424
});
2525

2626
// show contacts page
2727
GET("/contacts", routeContext -> routeContext.render("contacts"));
2828

2929
// show contact page for the contact with id specified as path parameter
3030
GET("/contact/{id}", routeContext -> {
31-
int id = routeContext.getParameter("id").toInt(0);
32-
Contact contact = (id > 0) ? contactService.getContact(id) : new Contact();
31+
int id = routeContext.getParameter("id").toInt(0);
32+
Contact contact = (id > 0) ? contactService.getContact(id) : new Contact();
3333
routeContext.setLocal("contact", contact);
3434

35-
routeContext.render("contact")
35+
routeContext.render("contact")
3636
});
3737

3838
// show login page
3939
GET("/login", routeContext -> response.render("login"));
4040

4141
// process login submit
4242
POST("/login", routeContext -> {
43-
String username = routeContext.getParameter("username").toString();
44-
String password = routeContext.getParameter("password").toString();
45-
if (authenticate(username, password)) {
46-
String originalDestination = routeContext.removeSession("originalDestination");
47-
routeContext.resetSession();
48-
49-
routeContext.setSession("username", username);
50-
routeContext.redirect(originalDestination != null ? originalDestination : "/contacts");
51-
} else {
52-
routeContext.flashError("Authentication failed");
53-
routeContext.redirect("/login");
54-
}
43+
String username = routeContext.getParameter("username").toString();
44+
String password = routeContext.getParameter("password").toString();
45+
if (authenticate(username, password)) {
46+
String originalDestination = routeContext.removeSession("originalDestination");
47+
routeContext.resetSession();
48+
49+
routeContext.setSession("username", username);
50+
routeContext.redirect(originalDestination != null ? originalDestination : "/contacts");
51+
} else {
52+
routeContext.flashError("Authentication failed");
53+
routeContext.redirect("/login");
54+
}
5555
});
5656

5757
// a dump implementation for authenticate method
@@ -103,12 +103,12 @@ ALL("/books.*", new CSRFHandler());
103103

104104
```html
105105
<html>
106-
<body>
107-
<form method="post" action="/books/5/rename">
108-
<input type="hidden" name="_csrf_token" value="${csrfToken}">
109-
<input placeholder="Enter a new book title" name="bookTitle">
110-
<input type="submit" value="Rename">
111-
</form>
112-
</body>
106+
<body>
107+
<form method="post" action="/books/5/rename">
108+
<input type="hidden" name="_csrf_token" value="${csrfToken}">
109+
<input placeholder="Enter a new book title" name="bookTitle">
110+
<input type="submit" value="Rename">
111+
</form>
112+
</body>
113113
</html>
114114
```

_posts/2015-03-17-spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ContactsController extends Controller {
2020
private ContactService contactService;
2121

2222
public void index() {
23-
List<Contact> contacts = contactService.getContacts()
23+
List<Contact> contacts = contactService.getContacts()
2424
getResponse().bind("contacts", contacts).render("contacts");
2525
}
2626

_posts/2015-03-17-under-the-hood.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You can see a filter as a RouteHandler that does not commit the response. A filt
5252
```java
5353
// audit filter
5454
GET("/.*", routeContext -> {
55-
Request request = routeContext.getRequest();
55+
Request request = routeContext.getRequest();
5656
System.out.println("Url: '" + request.getUrl());
5757
System.out.println("Uri: '" + request.getUri());
5858
System.out.println("Parameters: " + request.getParameters());
@@ -68,19 +68,19 @@ Let's see some code that shows in action this feature:
6868

6969
```java
7070
POST("/contact", routeContext -> {
71-
String action = routeContext.getParameter("action").toString();
72-
if ("save".equals(action)) {
73-
Contact contact = routeContext.createEntityFromParameters(Contact.class);
74-
contactService.save(contact);
75-
routeContext.redirect("/contacts");
76-
}
71+
String action = routeContext.getParameter("action").toString();
72+
if ("save".equals(action)) {
73+
Contact contact = routeContext.createEntityFromParameters(Contact.class);
74+
contactService.save(contact);
75+
routeContext.redirect("/contacts");
76+
}
7777
});
7878
```
7979
The old version has:
8080

8181
```java
8282
POST("/contact", routeContext -> {
83-
String action = routeContext.getParameter("action").toString();
83+
String action = routeContext.getParameter("action").toString();
8484
if ("save".equals(action)) {
8585
Contact contact = new Contact();
8686
contact.setId(request.getParameter("id").toInt(-1));

_posts/2015-03-27-flash.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,36 @@ Bellow you see a snipet code that put an error message in Flash object:
2222

2323
```java
2424
POST("/login", routeContext -> {
25-
String username = routeContext.getParameter("username").toString();
26-
String password = routeContext.getParameter("password").toString();
27-
if (authenticate(username, password)) {
28-
routeContext.resetSession();
29-
30-
routeContext.setSession("username", username);
31-
routeContext.redirect("/contacts");
32-
} else {
33-
routeContext.flashError("Authentication failed"); // <-- here
34-
routeContext.redirect("/login");
35-
}
25+
String username = routeContext.getParameter("username").toString();
26+
String password = routeContext.getParameter("password").toString();
27+
if (authenticate(username, password)) {
28+
routeContext.resetSession();
29+
30+
routeContext.setSession("username", username);
31+
routeContext.redirect("/contacts");
32+
} else {
33+
routeContext.flashError("Authentication failed"); // <-- here
34+
routeContext.redirect("/login");
35+
}
3636
});
3737

3838
GET("/login", routeContext -> {
39-
// we already have the flash object in the template model (injected by framework via Response.locals)
40-
routeContext.render("login");
39+
// we already have the flash object in the template model (injected by framework via Response.locals)
40+
routeContext.render("login");
4141
});
4242
```
4343

4444
The snippet for login template (freemarker engine) can be:
4545

4646
```html
4747
<#if flash.hasError()>
48-
<div class="alert alert-danger">
49-
${flash.getError()}
50-
</div>
48+
<div class="alert alert-danger">
49+
${flash.getError()}
50+
</div>
5151
</#if>
5252

5353
<form>
54-
<!-- login form components here -->
54+
<!-- login form components here -->
5555
</form>
5656
```
5757

@@ -69,21 +69,21 @@ Are situation when we want to put a flash message directly in incoming (see Vali
6969

7070
```java
7171
POST("/", routeContext -> {
72-
Contact contact = routeContext.createEntityFromParameters(Contact.class);
73-
74-
// check for validation
75-
Set<ConstraintViolation<Contact>> violations = validator.validate(contact);
76-
if (violations.isEmpty()) {
77-
routeContext.send(contact.toString());
78-
} else {
79-
// makes violations available to template via flash (response.getLocals().get("flash"))
80-
Flash flash = routeContext.getResponse().getFlash();
81-
for (ConstraintViolation<Contact> violation : violations) {
82-
flash.error(violation.getPropertyPath() + " " + violation.getMessage());
83-
}
84-
85-
routeContext.setLocal("contact", contact); // <-- here
86-
routeContext.render("contact");
87-
}
72+
Contact contact = routeContext.createEntityFromParameters(Contact.class);
73+
74+
// check for validation
75+
Set<ConstraintViolation<Contact>> violations = validator.validate(contact);
76+
if (violations.isEmpty()) {
77+
routeContext.send(contact.toString());
78+
} else {
79+
// makes violations available to template via flash (response.getLocals().get("flash"))
80+
Flash flash = routeContext.getResponse().getFlash();
81+
for (ConstraintViolation<Contact> violation : violations) {
82+
flash.error(violation.getPropertyPath() + " " + violation.getMessage());
83+
}
84+
85+
routeContext.setLocal("contact", contact); // <-- here
86+
routeContext.render("contact");
87+
}
8888
});
8989
```

_posts/2015-03-27-session.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ See below a snipet code about how to work with session in Pippo:
1414
```java
1515
// authentication filter
1616
GET("/contact.*", routeContext -> {
17-
if (routeContext.getSession("username") == null) {
18-
routeContext.setSession("originalDestination", routeContext.getRequest().getContextUriWithQuery());
19-
routeContext.redirect("/login");
20-
} else {
21-
routeContext.next();
22-
}
17+
if (routeContext.getSession("username") == null) {
18+
routeContext.setSession("originalDestination", routeContext.getRequest().getContextUriWithQuery());
19+
routeContext.redirect("/login");
20+
} else {
21+
routeContext.next();
22+
}
2323
});
2424

2525
// process login submit
2626
POST("/login", routeContext -> {
27-
String username = routeContext.getParameter("username").toString();
28-
String password = routeContext.getParameter("password").toString();
29-
if (authenticate(username, password)) {
30-
String originalDestination = routeContext.removeSession("originalDestination");
31-
routeContext.resetSession();
32-
33-
routeContext.setSession("username", username);
34-
routeContext.redirect(originalDestination != null ? originalDestination : "/contacts");
35-
} else {
36-
routeContext.flashError("Authentication failed");
37-
routeContext.redirect("/login");
38-
}
27+
String username = routeContext.getParameter("username").toString();
28+
String password = routeContext.getParameter("password").toString();
29+
if (authenticate(username, password)) {
30+
String originalDestination = routeContext.removeSession("originalDestination");
31+
routeContext.resetSession();
32+
33+
routeContext.setSession("username", username);
34+
routeContext.redirect(originalDestination != null ? originalDestination : "/contacts");
35+
} else {
36+
routeContext.flashError("Authentication failed");
37+
routeContext.redirect("/login");
38+
}
3939
});
4040
```
4141

@@ -56,7 +56,7 @@ public class MyApplication extends Application {
5656

5757
@Override
5858
protected void onInit() {
59-
// add routes here
59+
// add routes here
6060
}
6161

6262
@Override
@@ -82,7 +82,7 @@ A session is available automatically to templates for the rendering page process
8282

8383
```
8484
<#if (session)??>
85-
<div>${session.id}</div>
85+
<div>${session.id}</div>
8686
<div>${session.username}</div>
8787
<#else>
8888
```

_posts/2015-04-02-content-types.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public class XstreamEngine implements ContentTypeEngine {
2929
return HttpConstants.ContentType.APPLICATION_XML; // "application/xml"
3030
}
3131

32-
@Override
33-
public String toString(Object object) {
34-
return new XStream().toXML(object);
35-
}
32+
@Override
33+
public String toString(Object object) {
34+
return new XStream().toXML(object);
35+
}
3636

37-
@Override
38-
public <T> T fromString(String content, Class<T> classOfT) {
39-
return (T) new XStream().fromXML(content);
40-
}
37+
@Override
38+
public <T> T fromString(String content, Class<T> classOfT) {
39+
return (T) new XStream().fromXML(content);
40+
}
4141

42-
@Override
43-
public void init(Application application) {
44-
// do nothing
45-
}
42+
@Override
43+
public void init(Application application) {
44+
// do nothing
45+
}
4646

4747
}
4848
```
@@ -64,7 +64,7 @@ public class XstreamInitializer implements Initializer {
6464

6565
@Override
6666
public void destroy(Application application) {
67-
// do nothing
67+
// do nothing
6868
}
6969

7070
}
@@ -79,18 +79,18 @@ public class BasicApplication extends Application {
7979
protected void onInit() {
8080
// send xml as response
8181
GET("/xml", routeContext -> {
82-
Contact contact = createContact();
83-
routeContext.xml().send(contact);
82+
Contact contact = createContact();
83+
routeContext.xml().send(contact);
8484
});
8585
}
8686

87-
private Contact createContact() {
88-
return new Contact()
89-
.setId(12345)
90-
.setName("John")
91-
.setPhone("0733434435")
92-
.setAddress("Sunflower Street, No. 6");
93-
}
87+
private Contact createContact() {
88+
return new Contact()
89+
.setId(12345)
90+
.setName("John")
91+
.setPhone("0733434435")
92+
.setAddress("Sunflower Street, No. 6");
93+
}
9494

9595
}
9696
```
@@ -110,10 +110,10 @@ public class BasicApplication extends Application {
110110
protected void onInit() {
111111
// send an object and negotiate the Response content-type, default to XML
112112
GET("/negotiate", routeContext -> {
113-
Contact contact = createContact();
114-
routeContext.xml().negotiateContentType().send(contact);
115-
});
116-
}
113+
Contact contact = createContact();
114+
routeContext.xml().negotiateContentType().send(contact);
115+
});
116+
}
117117

118118
}
119119
```

0 commit comments

Comments
 (0)