From d8af0bae55e6d32440cd9faa65674a0ae239968e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 14 Jul 2016 12:10:17 +0300 Subject: JSON: read X-Scheme header to set urls scheme, SQL queries refactoring --- .../src/main/java/com/juick/json/JSONSerializer.java | 19 +++++++++++++++++++ .../main/java/com/juick/json/MessageSerializer.java | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'juick-core/src/main/java/com/juick/json') diff --git a/juick-core/src/main/java/com/juick/json/JSONSerializer.java b/juick-core/src/main/java/com/juick/json/JSONSerializer.java index 142cacf0..3dc9e04e 100644 --- a/juick-core/src/main/java/com/juick/json/JSONSerializer.java +++ b/juick-core/src/main/java/com/juick/json/JSONSerializer.java @@ -17,6 +17,25 @@ import org.json.JSONObject; */ public abstract class JSONSerializer { + public enum URIScheme { + Plain, + Secure + } + + private URIScheme uriScheme; + + public URIScheme getUriScheme() { + return uriScheme; + } + + public void setUriScheme(URIScheme uriScheme) { + this.uriScheme = uriScheme; + } + + public JSONSerializer() { + this.uriScheme = URIScheme.Plain; + } + /** * * @param json diff --git a/juick-core/src/main/java/com/juick/json/MessageSerializer.java b/juick-core/src/main/java/com/juick/json/MessageSerializer.java index d5adfa6e..9da828c9 100644 --- a/juick-core/src/main/java/com/juick/json/MessageSerializer.java +++ b/juick-core/src/main/java/com/juick/json/MessageSerializer.java @@ -126,9 +126,10 @@ public class MessageSerializer extends JSONSerializer { if (msg.AttachmentType != null) { String fname = msg.getMID() + (msg.getRID() > 0 ? "-" + msg.getRID() : "") + "." + msg.AttachmentType; JSONObject photo = new JSONObject(); - photo.put("thumbnail", "http://i.juick.com/ps/" + fname); - photo.put("small", "http://i.juick.com/photos-512/" + fname); - photo.put("medium", "http://i.juick.com/photos-1024/" + fname); + String protocol = getUriScheme() == URIScheme.Plain ? "http:" : "https:"; + photo.put("thumbnail", protocol + "//i.juick.com/ps/" + fname); + photo.put("small", protocol + "//i.juick.com/photos-512/" + fname); + photo.put("medium", protocol + "//i.juick.com/photos-1024/" + fname); json.put("photo", photo); } } catch (JSONException e) { -- cgit v1.2.3