Skip to content

Commit f2a389b

Browse files
committed
API change: rename Body.Parser to BodyParser & Body.Formatter to BodyFormatter fix #53
1 parent a5d3d6c commit f2a389b

39 files changed

+595
-578
lines changed

coverage-report/src/test/java/org/jooby/BodyConverters.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@
22

33
import java.util.List;
44

5-
import org.jooby.Body;
6-
import org.jooby.MediaType;
7-
import org.jooby.View;
8-
95
import com.google.common.collect.ImmutableList;
106
import com.google.common.io.CharStreams;
117
import com.google.inject.TypeLiteral;
128

139
public class BodyConverters {
1410

15-
public static final Body.Parser fromJson = new Body.Parser() {
11+
public static final BodyParser fromJson = new BodyParser() {
1612

1713
@Override
1814
public boolean canParse(final TypeLiteral<?> type) {
1915
return true;
2016
}
2117

2218
@Override
23-
public <T> T parse(final TypeLiteral<T> type, final Body.Reader reader) throws Exception {
24-
return reader.text(r -> CharStreams.toString(r));
19+
public <T> T parse(final TypeLiteral<T> type, final BodyParser.Context ctx) throws Exception {
20+
return ctx.text(r -> CharStreams.toString(r));
2521
}
2622

2723
@Override
@@ -31,15 +27,15 @@ public List<MediaType> types() {
3127

3228
};
3329

34-
public static final Body.Formatter toJson = new Body.Formatter() {
30+
public static final BodyFormatter toJson = new BodyFormatter() {
3531

3632
@Override
3733
public boolean canFormat(final Class<?> type) {
3834
return true;
3935
}
4036

4137
@Override
42-
public void format(final Object body, final Body.Writer writer)
38+
public void format(final Object body, final BodyFormatter.Context writer)
4339
throws Exception {
4440
writer.text(w -> w.write("{\"body\": \"" + body + "\"}"));
4541
}
@@ -50,9 +46,9 @@ public List<MediaType> types() {
5046
}
5147
};
5248

53-
public static final Body.Formatter toHtml = new View.Engine() {
49+
public static final BodyFormatter toHtml = new View.Engine() {
5450
@Override
55-
public void render(final View viewable, final Body.Writer writer) throws Exception {
51+
public void render(final View viewable, final BodyFormatter.Context writer) throws Exception {
5652
writer.text(w -> w.write("<html><body>" + viewable + "</body></html>"));
5753
}
5854
};

coverage-report/src/test/java/org/jooby/BodyParamFeature.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.jooby;
22

33
import java.io.IOException;
4-
import java.io.Writer;
54
import java.util.List;
65

7-
import org.jooby.Body;
8-
import org.jooby.MediaType;
96
import org.jooby.mvc.POST;
107
import org.jooby.mvc.Path;
118
import org.jooby.test.ServerFeature;
@@ -49,13 +46,13 @@ public Bean body(final Bean param) throws IOException {
4946
return ctx.convert(type, values);
5047
});
5148

52-
use(new Body.Formatter() {
49+
use(new BodyFormatter() {
5350

5451
@Override
55-
public void format(final Object body, final Body.Writer writer) throws Exception {
52+
public void format(final Object body, final BodyFormatter.Context writer) throws Exception {
5653
writer.text(out -> new CharSink() {
5754
@Override
58-
public Writer openStream() throws IOException {
55+
public java.io.Writer openStream() throws IOException {
5956
return out;
6057
}
6158
}.write(body.toString()));

coverage-report/src/test/java/org/jooby/ExceptionHandlingFeature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jooby;
22

3-
import org.jooby.Body;
43
import org.jooby.Env;
54
import org.jooby.mvc.GET;
65
import org.jooby.mvc.Path;
@@ -27,8 +26,8 @@ public String error() {
2726
{
2827

2928
use((final Env mode, final Config config, final Binder binder) -> {
30-
Multibinder<Body.Formatter> converters = Multibinder.newSetBinder(binder,
31-
Body.Formatter.class);
29+
Multibinder<BodyFormatter> converters = Multibinder.newSetBinder(binder,
30+
BodyFormatter.class);
3231
converters.addBinding().toInstance(BodyConverters.toHtml);
3332
converters.addBinding().toInstance(BodyConverters.toJson);
3433
});

coverage-report/src/test/java/org/jooby/HandlersFeature.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import java.util.List;
44
import java.util.Optional;
55

6-
import org.jooby.Body;
7-
import org.jooby.MediaType;
8-
import org.jooby.Request;
96
import org.jooby.mvc.Consumes;
107
import org.jooby.mvc.DELETE;
118
import org.jooby.mvc.GET;
@@ -46,15 +43,15 @@ public Object get(final Request req) {
4643

4744
{
4845

49-
use(new Body.Formatter() {
46+
use(new BodyFormatter() {
5047

5148
@Override
5249
public List<MediaType> types() {
5350
return ImmutableList.of(MediaType.text);
5451
}
5552

5653
@Override
57-
public void format(final Object body, final Body.Writer writer) throws Exception {
54+
public void format(final Object body, final BodyFormatter.Context writer) throws Exception {
5855
writer.text(w -> w.write(body.toString()));
5956

6057
}

coverage-report/src/test/java/org/jooby/TemplateEngineFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public View view() throws IOException {
2424

2525
{
2626
use((mode, config, binder) -> {
27-
Multibinder<Body.Formatter> converters = Multibinder.newSetBinder(binder,
28-
Body.Formatter.class);
27+
Multibinder<BodyFormatter> converters = Multibinder.newSetBinder(binder,
28+
BodyFormatter.class);
2929
converters.addBinding().toInstance(BodyConverters.toHtml);
3030
});
3131

coverage-report/src/test/java/org/jooby/ViewWithExplicitEngineFeature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jooby;
22

3-
import org.jooby.Body.Writer;
43
import org.jooby.test.ServerFeature;
54
import org.junit.Test;
65

@@ -16,7 +15,7 @@ public String name() {
1615
}
1716

1817
@Override
19-
public void render(final View viewable, final Writer writer) throws Exception {
18+
public void render(final View viewable, final BodyFormatter.Context writer) throws Exception {
2019
writer.text(w -> w.write(name()));
2120
}
2221
});
@@ -29,7 +28,7 @@ public String name() {
2928
}
3029

3130
@Override
32-
public void render(final View viewable, final Writer writer) throws Exception {
31+
public void render(final View viewable, final Context writer) throws Exception {
3332
writer.text(w -> w.write(name()));
3433
}
3534
});

coverage-report/src/test/java/org/jooby/issues/Issue26.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.List;
77
import java.util.concurrent.CountDownLatch;
88

9-
import org.jooby.Body;
9+
import org.jooby.BodyFormatter;
1010
import org.jooby.MediaType;
1111
import org.jooby.test.ServerFeature;
1212
import org.junit.Test;
@@ -20,15 +20,15 @@ public class Issue26 extends ServerFeature {
2020
private static final CountDownLatch latch = new CountDownLatch(1);
2121

2222
{
23-
use(new Body.Formatter() {
23+
use(new BodyFormatter() {
2424

2525
@Override
2626
public List<MediaType> types() {
2727
return ImmutableList.of(MediaType.html);
2828
}
2929

3030
@Override
31-
public void format(final Object body, final Body.Writer writer) throws Exception {
31+
public void format(final Object body, final BodyFormatter.Context writer) throws Exception {
3232
Config config = (Config) writer.locals().get("config");
3333
assertNotNull(config);
3434
writer.text(out -> CharStreams.copy(new StringReader(body.toString()), out));

coverage-report/src/test/java/org/jooby/jackson/JsonAccessFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.net.URISyntaxException;
44

5-
import org.jooby.Body;
5+
import org.jooby.BodyFormatter;
66
import org.jooby.test.ServerFeature;
77
import org.junit.Test;
88

@@ -14,9 +14,9 @@ public class JsonAccessFeature extends ServerFeature {
1414
{
1515
use(new Json());
1616

17-
get("/formatter", req -> req.require(Key.get(Body.Formatter.class, Names.named("json"))));
17+
get("/formatter", req -> req.require(Key.get(BodyFormatter.class, Names.named("json"))));
1818

19-
get("/parser", req -> req.require(Key.get(Body.Formatter.class, Names.named("json"))));
19+
get("/parser", req -> req.require(Key.get(BodyFormatter.class, Names.named("json"))));
2020
}
2121

2222
@Test

jooby-ftl/src/main/java/org/jooby/ftl/Ftl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.util.Properties;
2424
import java.util.function.BiConsumer;
2525

26-
import org.jooby.Body;
2726
import org.jooby.Env;
27+
import org.jooby.BodyFormatter;
2828
import org.jooby.Jooby;
2929
import org.jooby.View;
3030
import org.jooby.internal.ftl.Engine;
@@ -47,7 +47,7 @@
4747
import freemarker.template.TemplateException;
4848

4949
/**
50-
* Exposes a {@link Configuration} and a {@link Body.Formatter}.
50+
* Exposes a {@link Configuration} and a {@link BodyFormatter}.
5151
*
5252
* <h1>usage</h1>
5353
* <p>
@@ -199,7 +199,7 @@ public void configure(final Env env, final Config config, final Binder binder) {
199199

200200
Engine engine = new Engine(freemarker, prefix, suffix);
201201

202-
Multibinder.newSetBinder(binder, Body.Formatter.class)
202+
Multibinder.newSetBinder(binder, BodyFormatter.class)
203203
.addBinding().toInstance(engine);
204204

205205
// direct access

jooby-ftl/src/main/java/org/jooby/internal/ftl/Engine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.Map;
2525

26-
import org.jooby.Body.Writer;
26+
import org.jooby.BodyFormatter;
2727
import org.jooby.View;
2828

2929
import freemarker.template.Configuration;
@@ -46,7 +46,7 @@ public Engine(final Configuration freemarker, final String prefix, final String
4646
}
4747

4848
@Override
49-
public void render(final View viewable, final Writer writer) throws Exception {
49+
public void render(final View viewable, final BodyFormatter.Context writer) throws Exception {
5050
// template
5151
String name = prefix + viewable.name() + suffix;
5252

0 commit comments

Comments
 (0)