Skip to content

Commit 44294c0

Browse files
committed
Reformatted code
1 parent a514b1e commit 44294c0

22 files changed

+258
-205
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.iml
22
.idea
3-
target
3+
target
4+
5+
# IntelliJ Linux bug
6+
.fuse_*

src/main/java/org/javawebstack/framework/WebApplication.java

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class WebApplication {
4141
private final Map<String, Seeder> seeders = new HashMap<>();
4242
private final I18N translation = new I18N();
4343

44-
public WebApplication(){
44+
public WebApplication() {
4545
injector = new SimpleInjector();
4646
injector.setInstance(Injector.class, injector);
4747
injector.setInstance(SimpleInjector.class, injector);
@@ -61,27 +61,27 @@ public WebApplication(){
6161
injector.setInstance(Crypt.class, crypt);
6262

6363
modules.forEach(m -> m.setupConfig(this, config));
64-
if(config.get("database.driver", "none").equalsIgnoreCase("sqlite")){
64+
if (config.get("database.driver", "none").equalsIgnoreCase("sqlite")) {
6565
sql = new SQLite(config.get("database.file", "db.sqlite"));
66-
}else if(config.get("database.driver", "none").equalsIgnoreCase("mysql")){
66+
} else if (config.get("database.driver", "none").equalsIgnoreCase("mysql")) {
6767
sql = new MySQL(
6868
config.get("database.host", "localhost"),
6969
config.getInt("database.port", 3306),
7070
config.get("database.name", "app"),
7171
config.get("database.user", "root"),
7272
config.get("database.password", "")
7373
);
74-
}else{
74+
} else {
7575
sql = null;
7676
}
77-
if(sql != null){
77+
if (sql != null) {
7878
try {
79-
for(Module m : modules)
79+
for (Module m : modules)
8080
m.beforeSetupModels(this, sql);
8181
setupModels(sql);
82-
for(Module m : modules)
82+
for (Module m : modules)
8383
m.setupModels(this, sql);
84-
}catch (ORMConfigurationException ex){
84+
} catch (ORMConfigurationException ex) {
8585
ex.printStackTrace();
8686
}
8787
}
@@ -98,9 +98,9 @@ public WebApplication(){
9898
injector.inject(this);
9999
server.beforeInterceptor(new CORSPolicy(config.get("http.server.cors", "*")));
100100
server.beforeInterceptor(new MultipartPolicy(config.get("http.server.tmp", null)));
101-
if(config.isEnabled("http.server.json", true))
101+
if (config.isEnabled("http.server.json", true))
102102
server.responseTransformer(new JsonResponseTransformer().ignoreStrings());
103-
if(sql != null)
103+
if (sql != null)
104104
server.routeParamTransformer(modelBindParamTransformer);
105105
modules.forEach(m -> m.beforeSetupServer(this, server));
106106
setupServer(server);
@@ -129,62 +129,63 @@ public WebApplication(){
129129
);
130130
}
131131

132-
public Map<String, Seeder> getSeeders(){
132+
public Map<String, Seeder> getSeeders() {
133133
return seeders;
134134
}
135135

136-
public void addTranslation(Locale locale, ClassLoader classLoader, String resource){
137-
if(!resource.endsWith(".json"))
136+
public void addTranslation(Locale locale, ClassLoader classLoader, String resource) {
137+
if (!resource.endsWith(".json"))
138138
resource += ".json";
139139
try {
140140
AbstractElement element = AbstractElement.fromJson(IO.readTextResource(classLoader, resource));
141-
if(element.isObject())
141+
if (element.isObject())
142142
translation.add(locale, element.object());
143-
if(element.isArray())
143+
if (element.isArray())
144144
translation.add(locale, element.array());
145-
} catch (IOException ignored) {}
145+
} catch (IOException ignored) {
146+
}
146147
}
147148

148-
public void addTranslation(Locale locale, String resource){
149+
public void addTranslation(Locale locale, String resource) {
149150
addTranslation(locale, ClassLoader.getSystemClassLoader(), resource);
150151
}
151152

152-
public WebApplication addModule(Module module){
153+
public WebApplication addModule(Module module) {
153154
modules.add(module);
154155
return this;
155156
}
156157

157-
public WebApplication setModelBindTransformer(ModelBindTransformer transformer){
158+
public WebApplication setModelBindTransformer(ModelBindTransformer transformer) {
158159
modelBindParamTransformer.setTransformer(transformer);
159160
return this;
160161
}
161162

162-
public WebApplication setAccessorAttribName(String name){
163+
public WebApplication setAccessorAttribName(String name) {
163164
modelBindParamTransformer.setAccessorAttribName(name);
164165
return this;
165166
}
166167

167-
public void addSeeder(String name, Seeder... seeder){
168-
if(seeder.length == 0)
168+
public void addSeeder(String name, Seeder... seeder) {
169+
if (seeder.length == 0)
169170
return;
170-
for(Seeder seed : seeder)
171+
for (Seeder seed : seeder)
171172
injector.inject(seed);
172-
if(seeder.length > 1){
173+
if (seeder.length > 1) {
173174
addSeeder(name, new MergedSeeder(seeder));
174175
return;
175176
}
176177
seeders.put(name, seeder[0]);
177178
}
178179

179-
public Seeder getSeeder(String name){
180+
public Seeder getSeeder(String name) {
180181
return seeders.get(name);
181182
}
182183

183-
public Logger getLogger(){
184+
public Logger getLogger() {
184185
return logger;
185186
}
186187

187-
public void setLogger(Logger logger){
188+
public void setLogger(Logger logger) {
188189
this.logger = logger;
189190
}
190191

@@ -204,33 +205,42 @@ public Config getConfig() {
204205
return config;
205206
}
206207

207-
public Crypt getCrypt(){
208+
public Crypt getCrypt() {
208209
return crypt;
209210
}
210211

211-
public I18N getTranslation(){
212+
public I18N getTranslation() {
212213
return translation;
213214
}
214215

215-
protected void setupModules(){}
216+
protected void setupModules() {
217+
}
218+
216219
protected abstract void setupConfig(Config config);
217-
protected void setupInjection(SimpleInjector injector){}
218-
protected void setupSeeding(){}
220+
221+
protected void setupInjection(SimpleInjector injector) {
222+
}
223+
224+
protected void setupSeeding() {
225+
}
226+
219227
protected abstract void setupModels(SQL sql) throws ORMConfigurationException;
228+
220229
protected abstract void setupServer(HTTPServer server);
230+
221231
protected abstract void setupCommands(CommandSystem system);
222232

223-
public void run(String[] args){
224-
if(args == null)
233+
public void run(String[] args) {
234+
if (args == null)
225235
args = new String[]{"start"};
226236
try {
227237
commandSystem.run(args);
228-
}catch (Throwable t){
238+
} catch (Throwable t) {
229239
t.printStackTrace();
230240
}
231241
}
232242

233-
public void start(){
243+
public void start() {
234244
server.start();
235245
server.join();
236246
}

src/main/java/org/javawebstack/framework/bind/ModelBind.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
@Retention(RetentionPolicy.RUNTIME)
1010
public @interface ModelBind {
1111
String value();
12+
1213
String field() default "";
1314
}

src/main/java/org/javawebstack/framework/bind/ModelBindParamTransformer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ public class ModelBindParamTransformer extends DefaultRouteParamTransformer {
1212
private ModelBindTransformer transformer;
1313
private String accessorAttribName;
1414

15-
public ModelBindParamTransformer(){
15+
public ModelBindParamTransformer() {
1616
super();
1717
this.transformer = (exchange, repo, fieldName, source) -> repo.accessible(accessorAttribName == null ? null : exchange.attrib(accessorAttribName)).where(fieldName, source).first();
18-
for(Class<? extends Model> model : ORM.getModels()){
18+
for (Class<? extends Model> model : ORM.getModels()) {
1919
ModelBind[] binds = model.getDeclaredAnnotationsByType(ModelBind.class);
20-
if(binds.length == 0)
20+
if (binds.length == 0)
2121
continue;
2222
Repo<?> repo = Repo.get(model);
2323
String fieldName = binds[0].field().length() > 0 ? binds[0].field() : repo.getInfo().getIdField();
2424
Class<?> fieldType = repo.getInfo().getField(fieldName).getType();
2525
String parent = "string";
26-
if(fieldType.equals(UUID.class))
26+
if (fieldType.equals(UUID.class))
2727
parent = "uuid";
28-
if(fieldType.equals(Integer.class))
28+
if (fieldType.equals(Integer.class))
2929
parent = "i+";
30-
if(fieldType.equals(Long.class))
30+
if (fieldType.equals(Long.class))
3131
parent = "l+";
3232
extend(parent, binds[0].value(), (exchange, source) -> transformer.transform(exchange, repo, fieldName, source));
3333
}
3434
}
3535

36-
public void setTransformer(ModelBindTransformer transformer){
36+
public void setTransformer(ModelBindTransformer transformer) {
3737
this.transformer = transformer;
3838
}
3939

src/main/java/org/javawebstack/framework/command/CryptDecryptCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CryptDecryptCommand implements Command {
1515
Crypt crypt;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(params.containsKey("l")){
18+
if (params.containsKey("l")) {
1919
System.out.println(crypt.decryptLaravel(args.size() > 0 ? args.get(0) : ""));
2020
return CommandResult.success();
2121
}

src/main/java/org/javawebstack/framework/command/CryptEncryptCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CryptEncryptCommand implements Command {
1515
Crypt crypt;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(params.containsKey("l")){
18+
if (params.containsKey("l")) {
1919
System.out.println(crypt.encryptLaravel(args.size() > 0 ? args.get(0) : ""));
2020
return CommandResult.success();
2121
}

src/main/java/org/javawebstack/framework/command/DBMigrateCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class DBMigrateCommand implements Command {
1616
private WebApplication app;
1717

1818
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
19-
if(params.containsKey("a")){
20-
if(params.containsKey("d")){
19+
if (params.containsKey("a")) {
20+
if (params.containsKey("d")) {
2121
ORM.autoDrop();
2222
System.out.println("Dropped all tables!");
2323
return CommandResult.success();
2424
}
2525
ORM.autoMigrate(params.containsKey("f"));
26-
if(params.containsKey("s"))
26+
if (params.containsKey("s"))
2727
app.getSeeder("all").seed();
2828
System.out.println("Auto-Migration successful!");
2929
return CommandResult.success();

src/main/java/org/javawebstack/framework/command/DBSeedCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class DBSeedCommand implements Command {
1515
private WebApplication application;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(args.size() == 0)
18+
if (args.size() == 0)
1919
return CommandResult.syntax("db seed [...seeds]");
20-
for(String name : args)
20+
for (String name : args)
2121
application.getSeeder(name).seed();
2222
System.out.println("Seeding done!");
2323
return CommandResult.success();

src/main/java/org/javawebstack/framework/command/GenerateKeyCommand.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public CommandResult execute(CommandSystem commandSystem, List<String> args, Map
2020
lines = new String[0];
2121
}
2222
boolean found = false;
23-
for(int i=0; i<lines.length; i++){
24-
if(lines[i].startsWith("CRYPT_KEY=")){
25-
if(lines[i].length() > 10 && !params.containsKey("f"))
23+
for (int i = 0; i < lines.length; i++) {
24+
if (lines[i].startsWith("CRYPT_KEY=")) {
25+
if (lines[i].length() > 10 && !params.containsKey("f"))
2626
return CommandResult.error("You already have a key. You might loose all your encrypted data if you regenerate it! Use -f to do it anyway.");
2727
lines[i] = "CRYPT_KEY=" + Crypt.generateKey();
2828
found = true;
2929
break;
3030
}
3131
}
32-
if(!found){
32+
if (!found) {
3333
String[] newLines = new String[lines.length + 3];
3434
System.arraycopy(lines, 0, newLines, 0, lines.length);
35-
newLines[newLines.length-3] = "";
36-
newLines[newLines.length-2] = "# Encryption Key";
37-
newLines[newLines.length-1] = "CRYPT_KEY=" + Crypt.generateKey();
35+
newLines[newLines.length - 3] = "";
36+
newLines[newLines.length - 2] = "# Encryption Key";
37+
newLines[newLines.length - 1] = "CRYPT_KEY=" + Crypt.generateKey();
3838
lines = newLines;
3939
}
4040
try {

src/main/java/org/javawebstack/framework/command/ShellCommand.java

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

3-
import bsh.ConsoleInterface;
43
import bsh.EvalError;
54
import bsh.Interpreter;
65
import org.javawebstack.command.Command;
@@ -17,6 +16,7 @@
1716
public class ShellCommand implements Command {
1817
@Inject
1918
private WebApplication application;
19+
2020
public CommandResult execute(CommandSystem system, List<String> list, Map<String, List<String>> map) {
2121
InputStreamReader reader = new InputStreamReader(System.in);
2222
Interpreter interpreter = new Interpreter();
@@ -25,7 +25,7 @@ public CommandResult execute(CommandSystem system, List<String> list, Map<String
2525
interpreter.getNameSpace().importClass("org.javawebstack.orm.Repo");
2626
ORM.getModels().forEach(m -> interpreter.getNameSpace().importClass(m.getName()));
2727
System.out.println("App Shell");
28-
while (true){
28+
while (true) {
2929
try {
3030
interpreter.eval(reader);
3131
} catch (EvalError error) {

0 commit comments

Comments
 (0)