You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/08/11 11:04:49 UTC

[2/2] camel git commit: CAMEL-9842: Include default value in XSD documentation

CAMEL-9842: Include default value in XSD documentation


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2e00ccd9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e00ccd9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e00ccd9

Branch: refs/heads/master
Commit: 2e00ccd9e9efc3d0fbc3d9215d1144d7c40884a9
Parents: a9d10c2
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Aug 11 12:59:42 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Aug 11 13:04:40 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/maven/Constants.java  |  1 +
 .../camel/maven/DocumentationEnricher.java      | 24 ++++++++++++++------
 .../java/org/apache/camel/maven/XmlHelper.java  |  5 ++++
 3 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2e00ccd9/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
index 586d9a0..20de72c 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
@@ -37,6 +37,7 @@ public final class Constants {
     public static final String PROPERTIES_ATTRIBUTE_NAME = "properties";
     public static final String JSON_SUFIX = ".json";
     public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
+    public static final String DEFAULT_VALUE_ATTRIBUTE_NAME = "defaultValue";
     public static final String MODEL_ATTRIBUTE_NAME = "model";
 
     private Constants() { }

http://git-wip-us.apache.org/repos/asf/camel/blob/2e00ccd9/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
index 86f2d1b..a0df87a 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
@@ -31,6 +31,8 @@ import org.apache.camel.util.JsonSchemaHelper;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.WordUtils;
 
+import static org.apache.camel.maven.XmlHelper.isNullOrEmpty;
+
 /**
  * Enriches xml document with documentation from json files.
  */
@@ -70,17 +72,25 @@ public class DocumentationEnricher {
     }
 
     private void addAttributeDocumentation(Element item, File jsonFile) throws IOException {
+        String descriptionText = null;
+        String defaultValueText = null;
+
         List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(Constants.PROPERTIES_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), true);
         for (Map<String, String> row : rows) {
-            if (item.getAttribute(Constants.NAME_ATTRIBUTE_NAME)
-                    .equals(row.get(Constants.NAME_ATTRIBUTE_NAME))) {
-                String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
-                if (descriptionText != null) {
-                    addDocumentation(item, descriptionText);
-                    break;
-                }
+            if (item.getAttribute(Constants.NAME_ATTRIBUTE_NAME).equals(row.get(Constants.NAME_ATTRIBUTE_NAME))) {
+                descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
+                defaultValueText = row.get(Constants.DEFAULT_VALUE_ATTRIBUTE_NAME);
             }
         }
+
+        if (!isNullOrEmpty(descriptionText)) {
+            String text = descriptionText;
+            if (!isNullOrEmpty(defaultValueText)) {
+                text += ". Default value: " + defaultValueText;
+            }
+            addDocumentation(item, text);
+        }
+
     }
 
     private void addDocumentation(Element item, String textContent) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2e00ccd9/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/XmlHelper.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/XmlHelper.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/XmlHelper.java
index 7136c5c..af6b528 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/XmlHelper.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/XmlHelper.java
@@ -32,6 +32,7 @@ import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
 public final class XmlHelper {
+
     private XmlHelper() { }
 
     public static Document buildNamespaceAwareDocument(File xml) throws SAXException, ParserConfigurationException, IOException {
@@ -52,4 +53,8 @@ public final class XmlHelper {
         xPath.setNamespaceContext(namespaceContext);
         return xPath;
     }
+
+    public static boolean isNullOrEmpty(String text) {
+        return text == null || text.isEmpty();
+    }
 }