Skip to content

Commit

Permalink
Add format=json support to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 14, 2024
1 parent 1aa103e commit 2e8bdff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/com/difegue/doujinsoft/CollectionServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ private Collection initCollection(HttpServletRequest request) throws FileNotFoun
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html; charset=UTF-8");
if (request.getParameterMap().containsKey("format") && request.getParameter("format").equals("json"))
response.setContentType("application/json; charset=UTF-8");
else
response.setContentType("text/html; charset=UTF-8");

ServletContext application = getServletConfig().getServletContext();
String output = "Collection doesn't exist!";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public String doStandardPageCollection(Collection c) throws Exception {
result.close();
statement.close();
connection.close();

// JSON hijack if specified in the parameters
if (request.getParameterMap().containsKey("format") && request.getParameter("format").equals("json")) {
Gson gson = new Gson();
return gson.toJson(context);
}

return writeToTemplate();
}

Expand Down

0 comments on commit 2e8bdff

Please sign in to comment.