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 2015/03/08 09:04:31 UTC

[2/3] camel git commit: [CAMEL-8381] Wraps documentation for easier read in raw file.

[CAMEL-8381] Wraps documentation for easier read in raw file.


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

Branch: refs/heads/master
Commit: 785efef16a2d87b9e07b4b6a49cf5a004ee77b01
Parents: cfab63a
Author: nkukhar <ku...@gmail.com>
Authored: Sat Mar 7 18:08:15 2015 -0800
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 8 08:51:38 2015 +0100

----------------------------------------------------------------------
 .../pom.xml                                     |  5 +++
 .../java/org/apache/camel/maven/Constants.java  |  6 ++--
 .../camel/maven/DocumentationEnricher.java      | 37 ++++++++++++++++----
 3 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
index 19574cc..68295ea 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
@@ -68,6 +68,11 @@
       <artifactId>maven-artifact</artifactId>
       <version>2.2.1</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.3.2</version>
+    </dependency>
 
     <!-- add some logging to the classpath -->
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/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 224e6a8..e6e3fbe 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
@@ -23,6 +23,8 @@ public final class Constants {
 
     // Camel core constants.
     public static final String PATH_TO_MODEL_DIR = "target/classes/org/apache/camel/model";
+    public static final String DEFAULT_XML_INTEMSION = "  ";
+    public static final int WRAP_LENGTH = 80;
 
     // XML constants.
     public static final String NAME_ATTRIBUTE_NAME = "name";
@@ -36,7 +38,5 @@ public final class Constants {
     public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
     public static final String MODEL_ATTRIBUTE_NAME = "model";
 
-    private Constants() {
-    }
-
+    private Constants() {}
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/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 7aa1d86..c7054e6 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
@@ -16,16 +16,19 @@
  */
 package org.apache.camel.maven;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
+import org.apache.camel.util.JsonSchemaHelper;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.WordUtils;
+import org.w3c.dom.CDATASection;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.camel.util.JsonSchemaHelper;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Enriches xml document with documentation from json files.
@@ -78,7 +81,8 @@ public class DocumentationEnricher {
         Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME);
         Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME);
         documentation.setAttribute("xml:lang", "en");
-        documentation.setTextContent(textContent);
+        CDATASection cdataDocumentationText = document.createCDATASection(formatTextContent(item, textContent));
+        documentation.appendChild(cdataDocumentationText);
         annotation.appendChild(documentation);
         if (item.getFirstChild() != null) {
             item.insertBefore(annotation, item.getFirstChild());
@@ -86,4 +90,23 @@ public class DocumentationEnricher {
             item.appendChild(annotation);
         }
     }
+
+    private String formatTextContent(Element item, String textContent) {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append(System.lineSeparator())
+                .append(WordUtils.wrap(textContent, Constants.WRAP_LENGTH))
+                .append(System.lineSeparator())
+                // Fix closing tag intention.
+                .append(StringUtils.repeat(Constants.DEFAULT_XML_INTEMSION, getNodeDepth(item)));
+        return stringBuilder.toString();
+    }
+
+    private int getNodeDepth(Node item) {
+        int depth = 1;
+        while (item.getParentNode() != null) {
+            depth++;
+            item = item.getParentNode();
+        }
+        return depth;
+    }
 }