incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [29/29] git commit: Updating the csd property generator to have better names (they no longer all start with 'blur') and the installer will no longer be presented with every property during install.
Date Fri, 31 Jul 2015 18:05:35 GMT
Updating the csd property generator to have better names (they no longer all start with 'blur')
and the installer will no longer be presented with every property during install.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/8200840d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/8200840d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/8200840d

Branch: refs/heads/blur-0.2.4-parcel
Commit: 8200840db22d0a20e1bac507dce6490006fe667c
Parents: 7a63b8a
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Fri Jul 31 14:04:20 2015 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Fri Jul 31 14:04:20 2015 -0400

----------------------------------------------------------------------
 .../apache/blur/doc/JsonPropertyFormatter.java  | 54 +++++++++++++++-----
 1 file changed, 42 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/8200840d/blur-util/src/main/java/org/apache/blur/doc/JsonPropertyFormatter.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/doc/JsonPropertyFormatter.java b/blur-util/src/main/java/org/apache/blur/doc/JsonPropertyFormatter.java
index 395bc65..b0cee3c 100644
--- a/blur-util/src/main/java/org/apache/blur/doc/JsonPropertyFormatter.java
+++ b/blur-util/src/main/java/org/apache/blur/doc/JsonPropertyFormatter.java
@@ -17,27 +17,57 @@
 package org.apache.blur.doc;
 
 import org.apache.blur.doc.BlurPropertyParser.BlurProp;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.google.common.base.Splitter;
 
 public class JsonPropertyFormatter {
 
+  private static final String BLUR = "blur";
+  private static final String DEFAULT = "default";
+  private static final String TYPE = "type";
+  private static final String CONFIGURABLE_IN_WIZARD = "configurableInWizard";
+  private static final String REQUIRED = "required";
+  private static final String CONFIG_NAME = "configName";
+  private static final String DESCRIPTION = "description";
+  private static final String LABEL = "label";
+  private static final String NAME = "name";
+
   public String separator() {
     return ",";
   }
 
   public String format(BlurProp prop) {
-    return "    {\n" +
-        "      \"name\":\"" + prop.getName().replace(".", "_") + "\",\n" +
-        "      \"label\":\"" + prop.getName().replace(".", " ") + "\",\n" +
-        "      \"description\": \"" + escape(prop.getDescription()) + "\",\n" +
-        "      \"configName\":\"" + prop.getName() + "\",\n" +
-        "      \"required\":\"" + prop.isRequired() + "\",\n" +
-        "      \"type\":\"" + prop.getType() + "\",\n" +
-        "      \"default\":\"" + prop.getDefaultVal() + "\",\n" +
-        "      \"configurableInWizard\":true\n" +
-        "    }\n";
+    JSONObject jsonObject = new JSONObject();
+    try {
+      jsonObject.put(NAME, prop.getName().replace(".", "_"));
+      jsonObject.put(LABEL, pretty(prop.getName()));
+      jsonObject.put(DESCRIPTION, prop.getDescription());
+      jsonObject.put(CONFIG_NAME, prop.getName());
+      jsonObject.put(REQUIRED, prop.isRequired());
+      jsonObject.put(CONFIGURABLE_IN_WIZARD, prop.isRequired());
+      jsonObject.put(TYPE, prop.getType());
+      jsonObject.put(DEFAULT, prop.getDefaultVal());
+      return jsonObject.toString(1);
+    } catch (JSONException e) {
+      throw new RuntimeException(e);
+    }
   }
 
-  private String escape(String value) {
-    return value.replace("\"", "'");
+  private String pretty(String s) {
+    Splitter splitter = Splitter.on('.');
+    StringBuilder builder = new StringBuilder();
+    for (String split : splitter.split(s)) {
+      if (builder.length() == 0 && split.equals(BLUR)) {
+        // skip
+      } else {
+        if (builder.length() != 0) {
+          builder.append(' ');
+        }
+        builder.append(split.substring(0, 1).toUpperCase()).append(split.substring(1));
+      }
+    }
+    return builder.toString();
   }
 }


Mime
View raw message