cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r591788 - in /incubator/cxf/trunk/tools/common/src: main/java/org/apache/cxf/tools/common/ main/java/org/apache/cxf/tools/common/toolspec/parser/ test/java/org/apache/cxf/tools/common/toolspec/parser/
Date Sun, 04 Nov 2007 15:12:11 GMT
Author: ema
Date: Sun Nov  4 07:12:10 2007
New Revision: 591788

URL: http://svn.apache.org/viewvc?rev=591788&view=rev
Log:
CXF-1170: Improve the format of tooling help detailed usage, use the unix man style to print
help message 

Modified:
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
    incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java?rev=591788&r1=591787&r2=591788&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
Sun Nov  4 07:12:10 2007
@@ -92,12 +92,10 @@
                 System.out.println();
                 System.out.println("Options: ");
                 System.out.println();
-                System.out.println(parser.getDetailedUsage());
+                System.out.println(parser.getFromatedDetailedUsage());
                 String toolUsage = parser.getToolUsage();
-
                 if (toolUsage != null) {
                     System.out.println(toolUsage);
-                    System.out.println();
                 }
             } catch (Exception ex) {
                 System.err.println("Error : Could not output detailed usage");

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java?rev=591788&r1=591787&r2=591788&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
Sun Nov  4 07:12:10 2007
@@ -189,9 +189,91 @@
         // REVISIT: style usage document into a form more readily output as a
         // usage message
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
         toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
         return baos.toString();
+    }
+
+    public String getFromatedDetailedUsage() throws TransformerException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
+        String usage = baos.toString();
+        // we use the following pattern to format usage
+        // |-------|-options|------|description-----------------|
+        // before option white space size is 7
+        int beforeOptSpan = 3;
+        // option lenght is 8
+        int optSize = 12;
+        // after option white space size is 6
+        int afterOptLen = 6;
+        int totalLen = 80;
+        int optSpan = optSize + afterOptLen - 1;
+        int beforeDesSpan = beforeOptSpan + optSpan + 1;
+        String lineSeparator = System.getProperty("line.separator");
+        StringTokenizer st1 = new StringTokenizer(usage, lineSeparator);
+        int i = 0;
+        int length = st1.countTokens();
+        String[] orginalStrs = new String[length];
+        while (st1.hasMoreTokens()) {
+            String str = st1.nextToken();
+            orginalStrs[i] = str;
+            i++;
+        }
+        StringBuffer strbuffer = new StringBuffer();
+        for (int j = 0; j < length - 1; j = j + 2) {
+            int optionLen = orginalStrs[j].length();
+            addWhiteNamespace(strbuffer, beforeOptSpan);
+            if (optionLen <= optSpan) {
+                // && beforeOptSpan + optionLen + optSpan + desLen <= totalLen
-
+                // 1) {
+
+                strbuffer.append(orginalStrs[j]);
+                addWhiteNamespace(strbuffer, optSpan - orginalStrs[j].length());
+                strbuffer.append(" ");
+                if (orginalStrs[j + 1].length() > totalLen - beforeDesSpan) {
+                    String tmp = orginalStrs[j + 1].substring(0, totalLen - beforeDesSpan);
+                    strbuffer.append(tmp);
+                    orginalStrs[j + 1] = orginalStrs[j + 1].substring(totalLen - beforeDesSpan,

+                                                                      orginalStrs[j + 1].length());
+                    strbuffer.append(lineSeparator);
+                } else {
+                    strbuffer.append(orginalStrs[j + 1]);
+                    strbuffer.append(lineSeparator);
+                    orginalStrs[j + 1] = "";
+                }
+                
+                // strbuffer.append(orginalStrs[j + 1]);
+                // strbuffer.append(lineSeparator);
+                // strbuffer.append(lineSeparator);
+            } else {
+                // addWhiteNamespace(strbuffer, beforeOptSpan);
+                strbuffer.append(orginalStrs[j]);
+                strbuffer.append(lineSeparator);
+            }
+            String tmpStr = orginalStrs[j + 1];
+            
+            for (i = 0; i < tmpStr.length(); i = i + (totalLen - beforeDesSpan)) {
+                if (i + totalLen - beforeDesSpan < tmpStr.length()) {
+                    addWhiteNamespace(strbuffer, beforeDesSpan);
+                    strbuffer.append(tmpStr.substring(i, i + totalLen - beforeDesSpan));
+                    strbuffer.append(lineSeparator);
+                } else {
+                    addWhiteNamespace(strbuffer, beforeDesSpan);
+                    strbuffer.append(tmpStr.substring(i));
+                    strbuffer.append(lineSeparator);
+                }
+            }
+            strbuffer.append(lineSeparator);
+
+        }
+
+        return strbuffer.toString();
+    }
+
+    private void addWhiteNamespace(StringBuffer strbuffer, int count) {
+
+        for (int i = 0; i < count; i++) {
+            strbuffer.append(" ");
+        }
     }
 
     public String getDetailedUsage(String id) {

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl?rev=591788&r1=591787&r2=591788&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
Sun Nov  4 07:12:10 2007
@@ -1,25 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements. See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership. The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License. You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing,
-  software distributed under the License is distributed on an
-  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-  KIND, either express or implied. See the License for the
-  specific language governing permissions and limitations
-  under the License.
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
 -->
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ts="http://cxf.apache.org/Xutil/ToolSpecification">
-	<xsl:output method="text" omit-xml-declaration="yes"/>
-	<xsl:template match="/ts:toolspec/ts:usage">
+<xsl:stylesheet version="1.0"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:ts="http://cxf.apache.org/Xutil/ToolSpecification">
+	<xsl:output method="text" omit-xml-declaration="yes" />
+	<!--xsl:template match="/ts:toolspec/ts:usage">
 		<xsl:choose>
 			<xsl:when test="ts:form">
 				<xsl:text>Command can take one of a number of forms:-</xsl:text>
@@ -31,16 +33,13 @@
 				<xsl:apply-templates select="*"/>
 			</xsl:otherwise>
 		</xsl:choose>
-	</xsl:template>
-	<xsl:template match="ts:form">
-		<xsl:text>
-
-Form </xsl:text>
+	</xsl:template-->
+	<!--xsl:template match="ts:form">
+		<xsl:text>Form </xsl:text>
 		<xsl:value-of select="@value"/>
-		<xsl:text>...
-</xsl:text>
+		<xsl:text>...</xsl:text>
 		<xsl:apply-templates select="*"/>
-	</xsl:template>
+	</xsl:template-->
 	<xsl:template match="ts:optionGroup[not(@ref)]">
 		<xsl:apply-templates select="ts:option"/>
 	</xsl:template>
@@ -81,8 +80,9 @@
 	                        </xsl:if>
 				 <xsl:text>&#10;</xsl:text>
 		            <xsl:choose>
-		            <xsl:when xml:space="preserve" test="ts:annotation">				 
-	                    <xsl:value-of select="ts:annotation"/>
+		            <xsl:when test="ts:annotation">	
+		                <xsl:variable name="text1" select="ts:annotation"/>
+		                <xsl:value-of select = "normalize-space(translate($text1,'&#xa;',''))"/>
 			 
 			    </xsl:when>
 			    <xsl:otherwise>
 			    <xsl:value-of select="@id"/>
@@ -106,12 +106,13 @@
 				</xsl:if>
 				<xsl:text>&#10;</xsl:text>
 				<xsl:choose>
-			    <xsl:when xml:space="preserve" test="ts:annotation">
-			    <xsl:value-of select="ts:annotation"/>
+			    <xsl:when test="ts:annotation">
+			            <xsl:variable name="text2" select="ts:annotation"/>
+		                <xsl:value-of select = "normalize-space(translate($text2,'&#xa;',''))"/>

 			     </xsl:when>
-			     <xsl:otherwise>	
-			     </xsl:otherwise>
-			     </xsl:choose>
+			    <xsl:otherwise>	
+			    </xsl:otherwise>
+			    </xsl:choose>
 			</xsl:when>
 		</xsl:choose>
 	</xsl:template>

Modified: incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java?rev=591788&r1=591787&r2=591788&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
(original)
+++ incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
Sun Nov  4 07:12:10 2007
@@ -303,5 +303,14 @@
     public void testGetDetailedUsage() {
         assertTrue("Namespace".equals(parser.getDetailedUsage("namespace")));
     }
+    
+
+    @Test
+    public void testFormatedDetailedUsage() throws Exception {
+        String usage = parser.getFromatedDetailedUsage();
+        assertNotNull(usage);
+        StringTokenizer st1 = new StringTokenizer(usage, System.getProperty("line.separator"));
+        assertEquals(13, st1.countTokens());
+    }
 
 }



Mime
View raw message