Skip to content

Commit cae4641

Browse files
committed
even more jaavdoc
1 parent b9c8d70 commit cae4641

File tree

20 files changed

+1066
-159
lines changed

20 files changed

+1066
-159
lines changed

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
* Review decorator and responseHandler. Seems we kill decorator when a response handler is used it?
22
* Remove Route.Handler.next find another way of doing it
33
* Review and try to remove Route.Handler.execute
4+
* Review Value API try to hide Headers/Multipart/QueryString/Formdata
45
* check sendBytes implementation and don't set content-length if there is one already
6+
* Review what to do with Result class
7+
* Review unit test and document it
8+
* Review integration test and document it.
59

610
* doc
711
* api doc

jooby/src/main/java/io/jooby/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public interface Context {
128128
String value = pathMap().get(name);
129129
return value == null
130130
? new Value.Missing(name)
131-
: new Value.Simple(name, UrlParser.decodePath(value));
131+
: new Value.Single(name, UrlParser.decodePath(value));
132132
}
133133

134134
/**

jooby/src/main/java/io/jooby/EnvironmentOptions.java

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
import java.nio.file.Files;
2020
import java.nio.file.Path;
2121
import java.nio.file.Paths;
22+
import java.util.Arrays;
23+
import java.util.List;
2224

25+
/**
26+
* Available environment options.
27+
*
28+
* @author edgar
29+
* @since 2.0.0
30+
*/
2331
public class EnvironmentOptions {
2432
private static final String ENV = "application.env";
2533
private String basedir;
@@ -30,55 +38,117 @@ public class EnvironmentOptions {
3038

3139
private String[] activeNames;
3240

41+
/**
42+
* Creates environment options. Default application file name is: <code>application.conf</code>.
43+
*/
3344
public EnvironmentOptions() {
3445
setBasedir(defaultDir());
3546
setFilename("application.conf");
3647
}
3748

38-
public String[] getActiveNames() {
39-
return activeNames == null ? defaultEnvironmentNames() : activeNames;
49+
/**
50+
* Active environment names or fallback and read them from system property:
51+
* <code>application.env</code>.
52+
*
53+
* @return Active environment names.
54+
*/
55+
public List<String> getActiveNames() {
56+
return activeNames == null ? defaultEnvironmentNames() : Arrays.asList(activeNames);
4057
}
4158

59+
/**
60+
* Set active environment names.
61+
*
62+
* @param activeNames Active environment names.
63+
* @return This options.
64+
*/
4265
public @Nonnull EnvironmentOptions setActiveNames(@Nonnull String... activeNames) {
4366
this.activeNames = activeNames;
4467
return this;
4568
}
4669

47-
private static @Nonnull String[] defaultEnvironmentNames() {
48-
return System.getProperty(ENV, System.getenv().getOrDefault(ENV, "dev")).split(",");
70+
private static @Nonnull List<String> defaultEnvironmentNames() {
71+
return Arrays.asList(
72+
System.getProperty(ENV, System.getenv().getOrDefault(ENV, "dev")).split("\\s*,\\s*"));
4973
}
5074

75+
/**
76+
* Class loader.
77+
*
78+
* @return Class loader.
79+
*/
5180
public @Nonnull ClassLoader getClassLoader() {
5281
return classLoader == null ? getClass().getClassLoader() : classLoader;
5382
}
5483

84+
/**
85+
* Class loader.
86+
*
87+
* @param defaultClassLoader Default classloader is none was set.
88+
* @return Class loader.
89+
*/
5590
public @Nonnull ClassLoader getClassLoader(@Nonnull ClassLoader defaultClassLoader) {
5691
return classLoader == null ? defaultClassLoader : classLoader;
5792
}
5893

94+
/**
95+
* Set class loader.
96+
*
97+
* @param classLoader Class loader.
98+
* @return This options.
99+
*/
59100
public @Nonnull EnvironmentOptions setClassLoader(@Nonnull ClassLoader classLoader) {
60101
this.classLoader = classLoader;
61102
return this;
62103
}
63104

105+
/**
106+
* Base directory.
107+
*
108+
* @return Base directory.
109+
*/
64110
public @Nonnull String getBasedir() {
65111
return basedir;
66112
}
67113

114+
/**
115+
* Configuration file name.
116+
*
117+
* @return Configuration file name.
118+
*/
68119
public @Nonnull String getFilename() {
69120
return filename;
70121
}
71122

123+
/**
124+
* Set base dir.
125+
*
126+
* @param basedir Base dir. Classpath folder or file system directory.
127+
* @return This options.
128+
*/
72129
public @Nonnull EnvironmentOptions setBasedir(@Nonnull String basedir) {
73130
this.basedir = basedir;
74131
return this;
75132
}
76133

134+
/**
135+
* Set base dir.
136+
*
137+
* @param basedir Base dir.
138+
* @return This options.
139+
*/
77140
public @Nonnull EnvironmentOptions setBasedir(@Nonnull Path basedir) {
78141
this.basedir = basedir.toAbsolutePath().toString();
79142
return this;
80143
}
81144

145+
/**
146+
* Set file name.
147+
*
148+
* @param filename File name with extension. Supported extensions are: <code>.properties</code>,
149+
* <code>.conf</code> and <code>.json</code>.
150+
* @return This environment.
151+
*/
82152
public @Nonnull EnvironmentOptions setFilename(@Nonnull String filename) {
83153
this.filename = filename;
84154
return this;

jooby/src/main/java/io/jooby/FileUpload.java

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.jooby;
1717

1818
import javax.annotation.Nonnull;
19+
import javax.annotation.Nullable;
1920
import java.io.InputStream;
2021
import java.nio.charset.Charset;
2122
import java.nio.charset.StandardCharsets;
@@ -25,10 +26,38 @@
2526
import java.util.List;
2627
import java.util.Map;
2728

29+
/**
30+
* File upload class, file upload are available when request body is encoded as
31+
* {@link MediaType#MULTIPART_FORMDATA}. Example:
32+
*
33+
* <pre>{@code
34+
* {
35+
*
36+
* post("/submit", ctx -> {
37+
*
38+
* FileUpload file = ctx.file("myfile");
39+
*
40+
* });
41+
*
42+
* }
43+
* }</pre>
44+
*
45+
* @since 2.0.0
46+
* @author edgar
47+
*/
2848
public interface FileUpload extends Value {
29-
String getFileName();
49+
/**
50+
* Name of file upload.
51+
* @return Name of file upload.
52+
*/
53+
@Nonnull String getFileName();
3054

31-
String getContentType();
55+
/**
56+
* Content type of file upload.
57+
*
58+
* @return Content type of file upload.
59+
*/
60+
@Nullable String getContentType();
3261

3362
@Override default Value get(@Nonnull int index) {
3463
return index == 0 ? this : get(Integer.toString(index));
@@ -46,27 +75,61 @@ public interface FileUpload extends Value {
4675
return value(StandardCharsets.UTF_8);
4776
}
4877

49-
default @Nonnull String value(Charset charset) {
78+
/**
79+
* File upload content as string.
80+
*
81+
* @param charset Charset.
82+
* @return Content as string.
83+
*/
84+
default @Nonnull String value(@Nonnull Charset charset) {
5085
return new String(bytes(), charset);
5186
}
5287

53-
@Override default Map<String, List<String>> toMultimap() {
88+
/**
89+
* Multi-value map with field name as key and file name as values.
90+
*
91+
* @return Multi-value map with field name as key and file name as values.
92+
*/
93+
@Override default @Nonnull Map<String, List<String>> toMultimap() {
5494
Map<String, List<String>> result = new HashMap<>(1);
5595
result.put(name(), Collections.singletonList(getFileName()));
5696
return result;
5797
}
5898

59-
InputStream stream();
99+
/**
100+
* Content as input stream.
101+
*
102+
* @return Content as input stream.
103+
*/
104+
@Nonnull InputStream stream();
60105

61-
byte[] bytes();
106+
/**
107+
* Content as byte array.
108+
*
109+
* @return Content as byte array.
110+
*/
111+
@Nonnull byte[] bytes();
62112

63-
Path path();
113+
/**
114+
* File system path to access file content.
115+
*
116+
* @return File system path to access file content.
117+
*/
118+
@Nonnull Path path();
64119

120+
/**
121+
* File size.
122+
*
123+
* @return File size.
124+
*/
65125
long getFileSize();
66126

67127
@Override default FileUpload fileUpload() {
68128
return this;
69129
}
70130

131+
/**
132+
* Free resources, delete temporary file.
133+
*/
71134
void destroy();
72135
}

jooby/src/main/java/io/jooby/Formdata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
*/
1616
package io.jooby;
1717

18-
public class Formdata extends Value.Object {
18+
public class Formdata extends Value.Hash {
1919
}

jooby/src/main/java/io/jooby/ModelAndView.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,64 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22+
/**
23+
* Used by template engines to renderer views.
24+
*
25+
* @since 2.0.0
26+
* @author edgar
27+
*/
2228
public class ModelAndView {
2329

30+
/** View name. */
2431
public final String view;
2532

33+
/** View data. */
2634
public final Map<String, Object> model;
2735

36+
/**
37+
* Creates a new model and view.
38+
*
39+
* @param view View name.
40+
* @param model View model.
41+
*/
2842
public ModelAndView(@Nonnull String view, @Nonnull Map<String, Object> model) {
2943
this.view = view;
3044
this.model = model;
3145
}
3246

47+
/**
48+
* Creates a new model and view.
49+
*
50+
* @param view View name.
51+
*/
3352
public ModelAndView(@Nonnull String view) {
3453
this(view, new HashMap<>());
3554
}
3655

56+
/**
57+
* Put a model attribute.
58+
*
59+
* @param name Name.
60+
* @param value Value.
61+
* @return This model and view.
62+
*/
3763
public ModelAndView put(@Nonnull String name, Object value) {
3864
model.put(name, value);
3965
return this;
4066
}
4167

68+
/**
69+
* Copy all the attributes into the model.
70+
*
71+
* @param attributes Attributes.
72+
* @return This model and view.
73+
*/
4274
public ModelAndView put(@Nonnull Map<String, Object> attributes) {
4375
model.putAll(attributes);
4476
return this;
4577
}
78+
79+
@Override public String toString() {
80+
return view;
81+
}
4682
}

jooby/src/main/java/io/jooby/Multipart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
*/
1616
package io.jooby;
1717

18+
/**
19+
* Multipart class, mainly for MVC parameter provisioning.
20+
*/
1821
public class Multipart extends Formdata {
1922
}

jooby/src/main/java/io/jooby/QueryString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.jooby;
1717

18-
public class QueryString extends Value.Object {
18+
public class QueryString extends Value.Hash {
1919
public static final QueryString EMPTY = new QueryString("");
2020

2121
private final String queryString;

0 commit comments

Comments
 (0)