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/08/15 20:44:59 UTC
svn commit: r232849 - in /beehive/trunk/netui:
src/core/org/apache/beehive/netui/core/urltemplates/
src/pageflow/org/apache/beehive/netui/pageflow/internal/
test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/
Author: rich
Date: Mon Aug 15 11:44:42 2005
New Revision: 232849
URL: http://svn.apache.org/viewcvs?rev=232849&view=rev
Log:
This is a contribution from Carlin Rogers to address http://issues.apache.org/jira/browse/BEEHIVE-884 : Change URLTemplate.verify() to log template errors rather than throw IllegalStateException
tests: bvt in netui (WinXP)
BB: self (linux)
Modified:
beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/URLTemplate.java
beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java
Modified: beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/URLTemplate.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/URLTemplate.java?rev=232849&r1=232848&r2=232849&view=diff
==============================================================================
--- beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/URLTemplate.java (original)
+++ beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/URLTemplate.java Mon Aug 15 11:44:42 2005
@@ -18,6 +18,7 @@
package org.apache.beehive.netui.core.urltemplates;
import org.apache.beehive.netui.util.internal.InternalStringBuilder;
+import org.apache.beehive.netui.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collection;
@@ -31,6 +32,8 @@
*/
public class URLTemplate
{
+ private static final Logger _log = Logger.getInstance( URLTemplate.class );
+
private static final char BEGIN_TOKEN_QUALIFIER = '{';
private static final char END_TOKEN_QUALIFIER = '}';
@@ -107,21 +110,24 @@
* for known tokens and contains the required tokens. It will also parse
* the tokens and literal data into a list to improve the replacement
* performance when constructing the final URL string.
-
+ *
* <p> Allow clients to define a set of required and known tokens for the
* template verification. Tokens are expected to be qualified
* in braces. E.g. {url:path} </p>
*
- * <p> The template verification will ensure the URL template conforms to
- * a valid format for known tokens and contains the required tokens. </p>
+ * <p> If the template does not contain the required tokens or if the
+ * format of a known token is incorrect, this method will log the error
+ * and return false. </p>
*
* <p> Should call verify after creating a new template. </p>
*
* @param knownTokens the collection of known tokens (Strings) for a valid template.
* @param requiredTokens the collection of required tokens (Strings) in a valid template.
+ * @return true if the template conforms to a valid format, otherwise return false.
*/
- public void verify( Collection knownTokens, Collection requiredTokens ) throws IllegalStateException
+ public boolean verify( Collection knownTokens, Collection requiredTokens )
{
+ boolean valid = true;
// For each known token, make sure there is a leading and trailing brace
if ( knownTokens != null )
{
@@ -138,8 +144,9 @@
if ( _template.charAt( index - 1 ) != BEGIN_TOKEN_QUALIFIER
|| _template.charAt( index + token.length() ) != END_TOKEN_QUALIFIER )
{
- throw new IllegalStateException( "Template token, " + token
+ _log.error( "Template token, " + token
+ ", is not correctly enclosed with braces in template: " + _template );
+ valid = false;
}
}
}
@@ -159,11 +166,13 @@
if ( !_parsedTemplate.contains( requiredItem ) )
{
- throw new IllegalStateException( "Required token, " + token
- + ", not found in template: " + _template );
+ _log.error( "Required token, " + token + ", not found in template: " + _template );
+ valid = false;
}
}
}
+
+ return valid;
}
private void parseTemplate()
Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java?rev=232849&r1=232848&r2=232849&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java (original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java Mon Aug 15 11:44:42 2005
@@ -200,8 +200,10 @@
_log.debug( "[URLTemplate] " + name + " = " + value );
}
URLTemplate urlTemplate = new URLTemplate( value );
- urlTemplate.verify( _knownTokens, _requiredTokens );
- urlTemplates.addTemplate( name, urlTemplate );
+ if ( urlTemplate.verify( _knownTokens, _requiredTokens ) )
+ {
+ urlTemplates.addTemplate( name, urlTemplate );
+ }
}
else
{
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java?rev=232849&r1=232848&r2=232849&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java Mon Aug 15 11:44:42 2005
@@ -68,8 +68,9 @@
{
String temp = "{url:scheme}://{url:domain}:{url:port}/{url:path}?{url:queryString}";
URLTemplate urlTemplate = new URLTemplate( temp );
- urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
+ boolean valid = urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
assertEquals( temp, urlTemplate.getTemplate() );
+ assertTrue( valid );
}
public void testVerifyBadTemplate()
@@ -77,44 +78,20 @@
// badly formatted known token, {uri:domain}
String temp = "{url:scheme}://url:domain}:{url:port}/{url:path}?{url:queryString}";
URLTemplate urlTemplate = new URLTemplate( temp );
- boolean threw = false;
- try
- {
- urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
- }
- catch ( IllegalStateException e )
- {
- threw = true;
- }
- assertTrue( threw );
+ boolean valid = urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
+ assertFalse( valid );
// missing required token
temp = "{url:scheme}://{url:domain}:{url:port}/{url:path}";
urlTemplate = new URLTemplate( temp );
- threw = false;
- try
- {
- urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
- }
- catch ( IllegalStateException e )
- {
- threw = true;
- }
- assertTrue( threw );
+ valid = urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
+ assertFalse( valid );
// another missing required token
temp = "{url:scheme}://{url:domain}:{url:port}/?{url:queryString}";
urlTemplate = new URLTemplate( temp );
- threw = false;
- try
- {
- urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
- }
- catch ( IllegalStateException e )
- {
- threw = true;
- }
- assertTrue( threw );
+ valid = urlTemplate.verify( KNOWN_TEMPLATE_TOKENS, REQUIRED_TEMPLATE_TOKENS );
+ assertFalse( valid );
}
public void testSubstitute()