You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/07/02 00:02:46 UTC

svn commit: r208805 - in /incubator/beehive/trunk/netui: src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java

Author: rich
Date: Fri Jul  1 15:02:40 2005
New Revision: 208805

URL: http://svn.apache.org/viewcvs?rev=208805&view=rev
Log:
This is a contribution from Carlin Rogers to address http://issues.apache.org/jira/browse/BEEHIVE-838 : Add a toString(boolean) method to support optional cleanup of unknown tokens in URLTemplate class.  Thanks Carlin -- all caught up with everything you submitted during the last week.

tests: bvt in netui (WinXP)
BB: self (linux)


Modified:
    incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java
    incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java

Modified: incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java?rev=208805&r1=208804&r2=208805&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java (original)
+++ incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java Fri Jul  1 15:02:40 2005
@@ -221,13 +221,31 @@
     }
 
     /**
-     * Return the String representation of the template after
-     * replacing all tokens with their associated values. If there
-     * is no value for the token, the token is discarded.
+     * Return the String representation of the URL after replacing
+     * the tokens in the template with their associated values. If
+     * there is no value for a token, the token is discarded/removed.
      * I.E. It will not be part of the returned String.
+     *
+     * @return the url
      */
     public String toString()
     {
+        return toString( true );
+    }
+
+    /**
+     * Return the String representation of the URL after replacing
+     * the tokens in the template with their associated values.
+     * If the boolean argument is <code>true</code>, then the unset
+     * template tokens are removed. Otherwise, do not cleanup
+     * the unset tokens.
+     *
+     * @param removeUnsetTokens flag to tell URLTemplate to remove
+     *        or leave the unset tokens in the URL.
+     * @return the url
+     */
+    public String toString( boolean removeUnsetTokens )
+    {
         // template should already have been parsed with a call to
         if ( !_isParsed )
         {
@@ -247,7 +265,12 @@
                 }
                 else
                 {
-                    // No value for the token. Discard this item.
+                    // No value for the token.
+                    if ( !removeUnsetTokens )
+                    {
+                        // treat the token as a literal
+                        appendToResult( result, item.getValue() );
+                    }
                 }
             }
             else

Modified: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java?rev=208805&r1=208804&r2=208805&view=diff
==============================================================================
--- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java (original)
+++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java Fri Jul  1 15:02:40 2005
@@ -121,6 +121,7 @@
     {
         String temp = "{url:scheme}://{url:domain}:{url:port}/{url:path}?{url:queryString}{url:currentPage}";
         String intermediateResult = "https://myhost.com:8443/my/path?param1=true&amp;foo";
+        String intermediateResultWithToken = "https://myhost.com:8443/my/path?param1=true&amp;foo{url:currentPage}";
         String result = "https://myhost.com:8443/my/path?param1=true&amp;foo&cur=arb";
         URLTemplate urlTemplate = new URLTemplate( temp );
         urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
@@ -132,6 +133,7 @@
         tokensAndValues.put( "{url:queryString}", "param1=true&amp;foo" );
         urlTemplate.substitute( tokensAndValues );
         assertEquals( intermediateResult, urlTemplate.toString() );
+        assertEquals( intermediateResultWithToken, urlTemplate.toString( false ) );
         urlTemplate.substitute( "{url:currentPage}", "&cur=arb" );
         assertEquals( result, urlTemplate.toString() );
     }