Skip to content

Commit 50613bc

Browse files
committed
fix up some incompatible issues
1 parent 2a6773e commit 50613bc

3 files changed

Lines changed: 48 additions & 30 deletions

File tree

handlebar/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<parent>
33
<groupId>com.github.spullara.mustache.java</groupId>
44
<artifactId>mustache.java</artifactId>
5-
<version>0.6.4-SNAPSHOT</version>
5+
<version>0.7.0-SNAPSHOT</version>
66
</parent>
77
<modelVersion>4.0.0</modelVersion>
88

@@ -26,13 +26,13 @@
2626
</dependency>
2727
<dependency>
2828
<groupId>com.github.spullara.mustache.java</groupId>
29-
<artifactId>builder</artifactId>
30-
<version>0.6.4-SNAPSHOT</version>
29+
<artifactId>compiler</artifactId>
30+
<version>0.7.0-SNAPSHOT</version>
3131
</dependency>
3232
<dependency>
33-
<groupId>com.github.spullara.mustache.java</groupId>
34-
<artifactId>jackson-support</artifactId>
35-
<version>0.6.4-SNAPSHOT</version>
33+
<groupId>org.codehaus.jackson</groupId>
34+
<artifactId>jackson-mapper-asl</artifactId>
35+
<version>1.9.4</version>
3636
</dependency>
3737

3838
<!-- Jetty -->

handlebar/src/main/java/com/sampullara/mustache/Handlebar.java

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
package com.sampullara.mustache;
22

3-
import java.io.BufferedInputStream;
4-
import java.io.BufferedReader;
5-
import java.io.File;
6-
import java.io.FileInputStream;
7-
import java.io.IOException;
8-
import java.io.InputStreamReader;
9-
import java.io.OutputStream;
10-
import java.util.HashMap;
11-
import java.util.Map;
12-
import javax.servlet.ServletException;
13-
import javax.servlet.http.HttpServletRequest;
14-
import javax.servlet.http.HttpServletResponse;
15-
3+
import com.github.mustachejava.DefaultMustacheFactory;
4+
import com.github.mustachejava.Mustache;
5+
import com.github.mustachejava.MustacheException;
6+
import com.github.mustachejava.MustacheFactory;
167
import com.sampullara.cli.Args;
178
import com.sampullara.cli.Argument;
18-
import com.sampullara.mustache.json.JsonObjectHandler;
19-
import com.sampullara.util.FutureWriter;
209
import org.codehaus.jackson.JsonFactory;
2110
import org.codehaus.jackson.JsonNode;
2211
import org.codehaus.jackson.JsonParser;
@@ -26,6 +15,15 @@
2615
import org.eclipse.jetty.server.Server;
2716
import org.eclipse.jetty.server.handler.AbstractHandler;
2817

18+
import javax.servlet.ServletException;
19+
import javax.servlet.http.HttpServletRequest;
20+
import javax.servlet.http.HttpServletResponse;
21+
import java.io.*;
22+
import java.util.ArrayList;
23+
import java.util.HashMap;
24+
import java.util.Iterator;
25+
import java.util.Map;
26+
2927
/**
3028
* Run a local server and merge .js and .html files using mustache.
3129
* <p/>
@@ -51,15 +49,37 @@ public class Handlebar {
5149
mimeTypes.put("css" , "text/css");
5250
}
5351

52+
public static Object toObject(final JsonNode node) {
53+
if (node.isArray()) {
54+
return new ArrayList() {{
55+
for (JsonNode jsonNodes : node) {
56+
add(toObject(jsonNodes));
57+
}
58+
}};
59+
} else if (node.isObject()) {
60+
return new HashMap() {{
61+
for (Iterator<Map.Entry<String, JsonNode>> i = node.getFields(); i.hasNext(); ) {
62+
Map.Entry<String, JsonNode> next = i.next();
63+
Object o = toObject(next.getValue());
64+
put(next.getKey(), o);
65+
}
66+
}};
67+
} else if (node.isNull()) {
68+
return null;
69+
} else {
70+
return node.asText();
71+
}
72+
}
73+
74+
5475
public static void main(String[] args) throws Exception {
5576
try {
5677
Args.parse(Handlebar.class, args);
5778
} catch (IllegalArgumentException e) {
5879
Args.usage(Handlebar.class);
5980
System.exit(1);
6081
}
61-
Scope.setDefaultObjectHandler(new JsonObjectHandler());
62-
final MustacheBuilder mc = new MustacheBuilder(new File("."));
82+
final MustacheFactory mc = new DefaultMustacheFactory(new File("."));
6383
final JsonFactory jf = new MappingJsonFactory();
6484
Handler handler = new AbstractHandler() {
6585
public void handle(String s, Request r, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
@@ -73,8 +93,7 @@ public void handle(String s, Request r, HttpServletRequest req, HttpServletRespo
7393
// Handle like a template
7494
String filename = pathInfo.endsWith("/") ? pathInfo + "index.html" : pathInfo.substring(1);
7595
try {
76-
Mustache mustache = mc.parseFile(filename);
77-
FutureWriter fw = new FutureWriter(res.getWriter());
96+
Mustache mustache = mc.compile(filename);
7897
File file = new File(mocks, base + ".json");
7998
res.setStatus(HttpServletResponse.SC_OK);
8099
Map parameters = new HashMap<Object, Object>(req.getParameterMap()) {
@@ -96,11 +115,10 @@ public Object get(Object o) {
96115
JsonParser parser = jf.createJsonParser(br);
97116
JsonNode json = parser.readValueAsTree();
98117
br.close();
99-
mustache.execute(fw, new Scope(json, new Scope(parameters)));
118+
mustache.execute(res.getWriter(), new Object[] { toObject(json), parameters });
100119
} else {
101-
mustache.execute(fw, new Scope(parameters));
120+
mustache.execute(res.getWriter(), parameters);
102121
}
103-
fw.flush();
104122
r.setHandled(true);
105123
} catch (MustacheException e) {
106124
e.printStackTrace(res.getWriter());

indy/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>mustache.java</artifactId>
77
<groupId>com.github.spullara.mustache.java</groupId>
8-
<version>0.6.3-SNAPSHOT</version>
8+
<version>0.7.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>com.github.spullara.mustache.java</groupId>
4646
<artifactId>compiler</artifactId>
47-
<version>0.6.3-SNAPSHOT</version>
47+
<version>0.7.0-SNAPSHOT</version>
4848
</dependency>
4949

5050
<!-- ASM -->

0 commit comments

Comments
 (0)