Skip to Content.
Sympa Menu

notify-dpml - r1567 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/http/war/src/main/net/dpml/test/http transit/core/src/main/net/dpml/util

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1567 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/http/war/src/main/net/dpml/test/http transit/core/src/main/net/dpml/util
  • Date: Sun, 16 Jul 2006 08:59:41 +0200

Author: mcconnell
Date: 2006-07-16 08:59:34 +0200 (Sun, 16 Jul 2006)
New Revision: 1567

Modified:

trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
trunk/main/planet/http/war/src/main/net/dpml/test/http/Dump.java
trunk/main/transit/core/src/main/net/dpml/util/Resolver.java
trunk/main/transit/core/src/main/net/dpml/util/SimpleResolver.java
Log:
checkstyle cleanup

Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
2006-07-16 04:49:02 UTC (rev 1566)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
2006-07-16 06:59:34 UTC (rev 1567)
@@ -196,82 +196,74 @@
"Missing classpathref or classpath argument.";
throw new BuildException( error, getLocation() );
}
- }
-
+ }
+
/**
* Task execution.
* @exception BuildException if a build error occurs.
*/
public void execute() throws BuildException
{
- final Project project = getProject();
- final String enabled = project.getProperty( TEST_ENABLED_KEY );
- if( ( null != enabled ) && enabled.equals( "false" ) )
+ if( !isTestingEnabled() )
{
return;
}
- Context context = getContext();
+
+ final Context context = getContext();
+ final Project project = getProject();
final File src = context.getTargetBuildTestDirectory();
if( src.exists() )
{
final File working = context.getTargetTestDirectory();
final Path classpath = getClasspath();
executeUnitTests( src, classpath, working );
- }
- final String error = project.getProperty( ERROR_KEY );
- if( null != error )
- {
- final String message =
- "One or more unit test errors occured.";
- if( getHaltOnErrorProperty() )
+ final String error = project.getProperty( ERROR_KEY );
+ if( null != error )
{
+ final String message =
+ "One or more unit test errors occured.";
+ if( getHaltOnErrorProperty() )
+ {
fail( message );
+ }
}
- }
- final String failure = project.getProperty( FAILURE_KEY );
- if( null != failure )
- {
- final String message =
- "One or more unit test failures occured.";
- if( getHaltOnFailureProperty() )
+ final String failure = project.getProperty( FAILURE_KEY );
+ if( null != failure )
{
- fail( message );
+ final String message =
+ "One or more unit test failures occured.";
+ if( getHaltOnFailureProperty() )
+ {
+ fail( message );
+ }
}
}
}
-
+
private void executeUnitTests( final File src, final Path classpath,
File working )
{
final Project project = getProject();
log( "Test classpath: " + classpath, Project.MSG_VERBOSE );
-
- final FileSet fileset = new FileSet();
- fileset.setDir( src );
- final String includes = getTestIncludes();
- final String excludes = getTestExcludes();
- createIncludes( fileset, includes );
- createExcludes( fileset, excludes );
- log( "Test filters: includes=" + includes + ", excludes=" +
excludes, Project.MSG_VERBOSE );
-
- final JUnitTask junit = (JUnitTask) getProject().createTask( "junit"
);
+ final FileSet fileset = createFileSet( src );
+ final JUnitTask junit = (JUnitTask) project.createTask( "junit" );
+ junit.setErrorProperty( ERROR_KEY );
+ junit.setFailureProperty( FAILURE_KEY );
+ junit.setTaskName( getTaskName() );
junit.init();

- final JUnitTask.SummaryAttribute summary = new
JUnitTask.SummaryAttribute();
- summary.setValue( "on" );
+ final JUnitTask.SummaryAttribute summary = getSummaryAttribute();
junit.setPrintsummary( summary );
+
junit.setShowOutput( true );
junit.setTempdir( working );
junit.setReloading( true );
junit.setFiltertrace( true );
junit.createClasspath().add( classpath );
- junit.setHaltonerror(
- getBooleanProperty(
- HALT_ON_ERROR_KEY, HALT_ON_ERROR_VALUE ) );
- junit.setHaltonfailure(
- getBooleanProperty(
- HALT_ON_FAILURE_KEY, HALT_ON_FAILURE_VALUE ) );
+ junit.setHaltonerror( getHaltOnError() );
+ junit.setHaltonfailure( getHaltOnFailure() );

- String verbose = getContext().getProperty( "project.test.verbose" );
+ Context context = getContext();
+ String verbose = getVerboseArgument();
if( null != verbose )
{
Commandline.Argument arg = junit.createJvmarg();
@@ -285,18 +277,12 @@
batch.addFileSet( fileset );
batch.setTodir( reports );

- final FormatterElement plainFormatter = new FormatterElement();
- final FormatterElement.TypeAttribute plain = new
FormatterElement.TypeAttribute();
- plain.setValue( "plain" );
- plainFormatter.setType( plain );
- junit.addFormatter( plainFormatter );
-
- final FormatterElement xmlFormatter = new FormatterElement();
- final FormatterElement.TypeAttribute xml = new
FormatterElement.TypeAttribute();
- xml.setValue( "xml" );
- xmlFormatter.setType( xml );
- junit.addFormatter( xmlFormatter );
-
+ final FormatterElement plain = newConfiguredFormatter( "plain" );
+ junit.addFormatter( plain );
+
+ final FormatterElement xml = newConfiguredFormatter( "xml" );
+ junit.addFormatter( xml );
+
final Environment.Variable work = new Environment.Variable();
work.setKey( WORK_DIR_KEY );
work.setValue( working.toString() );
@@ -306,7 +292,7 @@
testBaseDir.setKey( "project.test.dir" );
testBaseDir.setValue( working.toString() );
junit.addConfiguredSysproperty( testBaseDir );
-
+
final Environment.Variable targetDir = new Environment.Variable();
targetDir.setKey( "project.target.dir" );
targetDir.setValue( getContext().getTargetDirectory().toString() );
@@ -370,6 +356,45 @@
logging.setValue( "net.dpml.util.ConfigurationHandler" );
junit.addConfiguredSysproperty( logging );

+ configureDeliverableSysProperties( junit );
+ configureForExecution( junit );
+ junit.execute();
+ }
+
+ private void configureForExecution( JUnitTask task )
+ {
+ if( getForkProperty() )
+ {
+ task.setFork( true );
+ Project project = getProject();
+ task.setDir( project.getBaseDir() );
+ JUnitTask.ForkMode mode = getForkMode();
+ if( null == mode )
+ {
+ log( "Executing forked test." );
+ }
+ else
+ {
+ log( "Executing forked test with mode: '" + mode + "'." );
+ task.setForkMode( mode );
+ }
+ String mx = getContext().getProperty( MX_KEY );
+ if( null != mx )
+ {
+ task.setMaxmemory( mx );
+ }
+ }
+ else
+ {
+ log( "executing in local jvm" );
+ JUnitTask.ForkMode mode = new JUnitTask.ForkMode( "once" );
+ task.setForkMode( mode );
+ task.setFork( false );
+ }
+ }
+
+ private void configureDeliverableSysProperties( JUnitTask task )
+ {
try
{
Context context = getContext();
@@ -384,52 +409,53 @@
final Environment.Variable variable = new
Environment.Variable();
variable.setKey( "project.deliverable." + id + ".filename" );
variable.setValue( path );
- junit.addConfiguredSysproperty( variable );
+ task.addConfiguredSysproperty( variable );
}
}
catch( IOException ioe )
{
final String error =
"Unexpected IO error while building deliverable filename
properties.";
- throw new BuildException( error, ioe );
+ throw new BuildException( error, ioe, getLocation() );
}
-
- junit.setErrorProperty( ERROR_KEY );
- junit.setFailureProperty( FAILURE_KEY );
- junit.setTaskName( getTaskName() );
- if( getForkProperty() )
+ }
+
+ private FileSet createFileSet( File src )
+ {
+ final FileSet fileset = new FileSet();
+ fileset.setDir( src );
+ addIncludes( fileset );
+ addExcludes( fileset );
+ return fileset;
+ }
+
+ private void addIncludes( FileSet set )
+ {
+ String pattern = getTestIncludes();
+ log( "Test includes=" + pattern, Project.MSG_VERBOSE );
+ StringTokenizer tokenizer = new StringTokenizer( pattern, ", ",
false );
+ while( tokenizer.hasMoreTokens() )
{
- junit.setFork( true );
- junit.setDir( project.getBaseDir() );
- JUnitTask.ForkMode mode = getForkMode();
- if( null == mode )
- {
- log( "Executing forked test." );
- }
- else
- {
- log( "Executing forked test with mode: '" + mode + "'." );
- junit.setForkMode( mode );
- }
- String mx = getContext().getProperty( MX_KEY );
- if( null != mx )
- {
- junit.setMaxmemory( mx );
- }
+ String item = tokenizer.nextToken();
+ set.createInclude().setName( item );
}
- else
+ }
+
+ private void addExcludes( FileSet set )
+ {
+ String pattern = getTestExcludes();
+ log( "Test excludes=" + pattern, Project.MSG_VERBOSE );
+ StringTokenizer tokenizer = new StringTokenizer( pattern, ", ",
false );
+ while( tokenizer.hasMoreTokens() )
{
- log( "executing in local jvm" );
- JUnitTask.ForkMode mode = new JUnitTask.ForkMode( "once" );
- junit.setForkMode( mode );
- junit.setFork( false );
+ String item = tokenizer.nextToken();
+ set.createExclude().setName( item );
}
- junit.execute();
}

private String getTestIncludes()
{
- String includes = getProject().getProperty( TEST_INCLUDES_KEY );
+ String includes = getContext().getProperty( TEST_INCLUDES_KEY );
if( null != includes )
{
return includes;
@@ -442,7 +468,7 @@

private String getTestExcludes()
{
- String excludes = getProject().getProperty( TEST_EXCLUDES_KEY );
+ String excludes = getContext().getProperty( TEST_EXCLUDES_KEY );
if( null != excludes )
{
return excludes;
@@ -453,29 +479,9 @@
}
}

- private void createIncludes( FileSet set, String pattern )
- {
- StringTokenizer tokenizer = new StringTokenizer( pattern, ", ",
false );
- while( tokenizer.hasMoreTokens() )
- {
- String item = tokenizer.nextToken();
- set.createInclude().setName( item );
- }
- }
-
- private void createExcludes( FileSet set, String pattern )
- {
- StringTokenizer tokenizer = new StringTokenizer( pattern, ", ",
false );
- while( tokenizer.hasMoreTokens() )
- {
- String item = tokenizer.nextToken();
- set.createExclude().setName( item );
- }
- }
-
private String getCachePath()
{
- final String value = getProject().getProperty( CACHE_PATH_KEY );
+ final String value = getContext().getProperty( CACHE_PATH_KEY );
if( null != value )
{
return value;
@@ -509,7 +515,7 @@

private JUnitTask.ForkMode getForkMode()
{
- final String value = getProject().getProperty( TEST_FORK_MODE_KEY );
+ final String value = getContext().getProperty( TEST_FORK_MODE_KEY );
if( null == value )
{
return null;
@@ -522,7 +528,7 @@

private boolean getBooleanProperty( final String key, final boolean
fallback )
{
- final String value = getProject().getProperty( key );
+ final String value = getContext().getProperty( key );
if( null == value )
{
return fallback;
@@ -541,6 +547,47 @@
exit.execute();
}

+ private boolean isTestingEnabled()
+ {
+ final String enabled = getContext().getProperty( TEST_ENABLED_KEY,
"true" );
+ return "true".equals( enabled );
+ }
+
+ private JUnitTask.SummaryAttribute getSummaryAttribute()
+ {
+ final Project project = getProject();
+ final JUnitTask.SummaryAttribute summary = new
JUnitTask.SummaryAttribute();
+ summary.setValue( "on" );
+ return summary;
+ }
+
+ private boolean getHaltOnError()
+ {
+ return getBooleanProperty(
+ HALT_ON_ERROR_KEY, HALT_ON_ERROR_VALUE );
+ }
+
+ private boolean getHaltOnFailure()
+ {
+ return getBooleanProperty(
+ HALT_ON_FAILURE_KEY, HALT_ON_FAILURE_VALUE );
+ }
+
+ private String getVerboseArgument()
+ {
+ Context context = getContext();
+ return context.getProperty( "project.test.verbose" );
+ }
+
+ private FormatterElement newConfiguredFormatter( String type )
+ {
+ final FormatterElement formatter = new FormatterElement();
+ final FormatterElement.TypeAttribute attribute = new
FormatterElement.TypeAttribute();
+ attribute.setValue( type );
+ formatter.setType( attribute );
+ return formatter;
+ }
+
private static final String ERROR_KEY = "project.test.error";
private static final String FAILURE_KEY = "project.test.failure";


Modified: trunk/main/planet/http/war/src/main/net/dpml/test/http/Dump.java
===================================================================
--- trunk/main/planet/http/war/src/main/net/dpml/test/http/Dump.java
2006-07-16 04:49:02 UTC (rev 1566)
+++ trunk/main/planet/http/war/src/main/net/dpml/test/http/Dump.java
2006-07-16 06:59:34 UTC (rev 1567)
@@ -76,77 +76,18 @@
request.setAttribute( "Dump", this );
getServletContext().setAttribute( "Dump", this );
getServletContext().log( "dump " + request.getRequestURI() );
-
+
// Force a content length response
String length = request.getParameter( "length" );
if( ( length != null ) && ( length.length() > 0 ) )
{
response.setContentLength( Integer.parseInt( length ) );
}
-
- // Handle a dump of data
- String data = request.getParameter( "data" );
- String block = request.getParameter( "block" );
- if( ( data != null ) && ( data.length() > 0 ) )
- {
- int d = Integer.parseInt( data );
- int b = 50;
- if( block != null && block.length() > 0 )
- {
- b = Integer.parseInt( block );
- }
- byte[] buf = new byte[b];
- for( int i=0; i<b; i++ )
- {
- buf[i] = (byte) ( '0' + ( i%10 ) );
- if( i%10 == 9 )
- {
- buf[i] = (byte) '\n';
- }
- }
- buf[0] = 'o';
- OutputStream out = response.getOutputStream();
- response.setContentType( "text/plain" );
- while( d > 0 )
- {
- if( d >= b )
- {
- out.write( buf );
- d = d-b;
- }
- else
- {
- out.write( buf, 0, d );
- d = 0;
- }
- }
- return;
- }

- // handle an exception
- String info = request.getPathInfo();
- if( info != null && info.endsWith( "Exception" ) )
- {
- try
- {
- throw (Throwable)
Thread.currentThread().getContextClassLoader().loadClass( info.substring( 1 )
).newInstance();
- }
- catch( Throwable th )
- {
- throw new ServletException( th );
- }
- }
+ handleDataDump( request, response );
+ String info = handleException( request, response );
+ handleRedirect( request, response );

- // handle an redirect
- String redirect = request.getParameter( "redirect" );
- if( redirect != null && redirect.length() > 0 )
- {
- response.getOutputStream().println( "THIS SHOULD NOT BE SEEN!" );
- response.sendRedirect( redirect );
- response.getOutputStream().println( "THIS SHOULD NOT BE SEEN!" );
- return;
- }
-
// handle an error
String error= request.getParameter( "error" );
if( error != null && error.length() > 0 )
@@ -156,7 +97,7 @@
response.getOutputStream().println( "THIS SHOULD NOT BE SEEN!" );
return;
}
-
+
String buffer= request.getParameter( "buffer" );
if( buffer != null && buffer.length() > 0 )
{
@@ -165,7 +106,7 @@

request.setCharacterEncoding( "UTF-8" );
response.setContentType( "text/html" );
-
+
if( info != null && info.indexOf( "Locale/" ) >= 0 )
{
try
@@ -180,7 +121,7 @@
response.setLocale( Locale.getDefault() );
}
}
-
+
String cn = request.getParameter( "cookie" );
String cv =request.getParameter( "value" );
String v =request.getParameter( "version" );
@@ -196,7 +137,7 @@
}
response.addCookie( cookie );
}
-
+
String pi = request.getPathInfo();
if( pi != null && pi.startsWith( "/ex" ) )
{
@@ -218,7 +159,6 @@
}

PrintWriter pout = null;
-
try
{
pout = response.getWriter();
@@ -227,10 +167,125 @@
{
pout = new PrintWriter( response.getOutputStream() );
}
+ writeDumpContent( request, response, pout );
+ pout.close();

+ if( pi != null )
+ {
+ if( "/ex4".equals( pi ) )
+ {
+ throw new ServletException( "test ex4", new Throwable() );
+ }
+ if( "/ex5".equals( pi ) )
+ {
+ throw new IOException( "test ex5" );
+ }
+ if( "/ex6".equals( pi ) )
+ {
+ throw new UnavailableException( "test ex6" );
+ }
+ }
+ }
+
+ private void handleDataDump( HttpServletRequest request,
HttpServletResponse response )
+ throws IOException
+ {
+ // Handle a dump of data
+ String data = request.getParameter( "data" );
+ String block = request.getParameter( "block" );
+ if( ( data != null ) && ( data.length() > 0 ) )
+ {
+ int d = Integer.parseInt( data );
+ int b = 50;
+ if( block != null && block.length() > 0 )
+ {
+ b = Integer.parseInt( block );
+ }
+ byte[] buf = new byte[b];
+ for( int i=0; i<b; i++ )
+ {
+ buf[i] = (byte) ( '0' + ( i%10 ) );
+ if( i%10 == 9 )
+ {
+ buf[i] = (byte) '\n';
+ }
+ }
+ buf[0] = 'o';
+ OutputStream out = response.getOutputStream();
+ response.setContentType( "text/plain" );
+ while( d > 0 )
+ {
+ if( d >= b )
+ {
+ out.write( buf );
+ d = d-b;
+ }
+ else
+ {
+ out.write( buf, 0, d );
+ d = 0;
+ }
+ }
+ return;
+ }
+ }
+
+ private String handleException( HttpServletRequest request,
HttpServletResponse response )
+ throws ServletException
+ {
+ // handle an exception
+ String info = request.getPathInfo();
+ if( info != null && info.endsWith( "Exception" ) )
+ {
+ try
+ {
+ throw (Throwable)
Thread.currentThread().getContextClassLoader().loadClass( info.substring( 1 )
).newInstance();
+ }
+ catch( Throwable th )
+ {
+ throw new ServletException( th );
+ }
+ }
+ else
+ {
+ return info;
+ }
+ }
+
+ private void handleRedirect( HttpServletRequest request,
HttpServletResponse response )
+ throws IOException
+ {
+ // handle an redirect
+ String redirect = request.getParameter( "redirect" );
+ if( redirect != null && redirect.length() > 0 )
+ {
+ response.getOutputStream().println( "THIS SHOULD NOT BE SEEN!" );
+ response.sendRedirect( redirect );
+ response.getOutputStream().println( "THIS SHOULD NOT BE SEEN!" );
+ return;
+ }
+ }
+
+
+ private void writeDumpContent(
+ HttpServletRequest request, HttpServletResponse response, PrintWriter
pout )
+ {
try
{
- pout.write( "<html>\n<body>\n" );
+ pout.write( "<html>\n<body>\n" );
+ writeBasicContent( request, response, pout );
+ pout.write( "</body>\n</html>\n" );
+ }
+ catch( Exception e )
+ {
+ getServletContext().log( "dump", e );
+ }
+ }
+
+ private void writeBasicContent( HttpServletRequest request,
HttpServletResponse response, PrintWriter pout )
+ {
+ try
+ {
pout.write( "<h1>Dump Servlet</h1>\n" );
pout.write( "<table>" );
pout.write( "<tr>\n" );
@@ -311,7 +366,17 @@
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"right\">getLocale:&nbsp;</th>" );
pout.write( "<td>" + request.getLocale() + "</td>" );
-
+ }
+ catch( Exception e )
+ {
+ getServletContext().log( "dump", e );
+ }
+ }
+
+ private void writeExtendedContent( HttpServletRequest request,
HttpServletResponse response, PrintWriter pout )
+ {
+ try
+ {
Enumeration locales= request.getLocales();
while( locales.hasMoreElements() )
{
@@ -320,7 +385,6 @@
pout.write( "<td>" + locales.nextElement() + "</td>" );
}
pout.write( "</tr><tr>\n" );
-
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Other
HTTP Headers:</big></th>" );
Enumeration h= request.getHeaderNames();
String name;
@@ -337,8 +401,7 @@
pout.write( "<td>" + hv + "</td>" );
}
}
-
- pout.write( "</tr><tr>\n" );
+ pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Request
Parameters:</big></th>" );
h = request.getParameterNames();
while( h.hasMoreElements() )
@@ -364,18 +427,8 @@
}
}
}
-
pout.write( "</tr><tr>\n" );
- pout.write( "<th align=\"left\"
colspan=\"2\"><big><br/>Cookies:</big></th>" );
- Cookie[] cookies = request.getCookies();
- for( int i=0; cookies!=null && i<cookies.length; i++ )
- {
- Cookie cookie = cookies[i];
- pout.write( "</tr><tr>\n" );
- pout.write( "<th align=\"right\">" + cookie.getName() +
":&nbsp;</th>" );
- pout.write( "<td>" + cookie.getValue() + "</td>" );
- }
-
+ writeCookies( request, response, pout );
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Request
Attributes:</big></th>" );
Enumeration a = request.getAttributeNames();
@@ -386,7 +439,6 @@
pout.write( "<th align=\"right\">" + name + ":&nbsp;</th>" );
pout.write( "<td>" + "<pre>" + toString(
request.getAttribute( name ) ) + "</pre>"+"</td>" );
}
-
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Servlet
InitParameters:</big></th>" );
a = getInitParameterNames();
@@ -397,7 +449,6 @@
pout.write( "<th align=\"right\">" + name + ":&nbsp;</th>" );
pout.write( "<td>"+"<pre>" + toString( getInitParameter(
name ) ) + "</pre>"+"</td>" );
}
-
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Context
InitParameters:</big></th>" );
a = getServletContext().getInitParameterNames();
@@ -408,7 +459,6 @@
pout.write( "<th align=\"right\">" + name + ":&nbsp;</th>" );
pout.write( "<td>" + "<pre>" + toString(
getServletContext().getInitParameter( name ) ) + "</pre>" + "</td>" );
}
-
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"left\" colspan=\"2\"><big><br/>Context
Attributes:</big></th>" );
a = getServletContext().getAttributeNames();
@@ -418,9 +468,7 @@
pout.write( "</tr><tr>\n" );
pout.write( "<th align=\"right\">" + name + ":&nbsp;</th>" );
pout.write( "<td>"+"<pre>" + toString(
getServletContext().getAttribute( name ) ) + "</pre>" + "</td>" );
- }
-
-
+ }
String res= request.getParameter( "resource" );
if( res != null && res.length() > 0 )
{
@@ -450,87 +498,105 @@
pout.write( "<td>" + "" + e + "</td>" );
}
}
-
- pout.write( "</tr></table>\n" );
-
- pout.write( "<h2>Request Wrappers</h2>\n" );
- ServletRequest rw = request;
- int w=0;
- while( rw != null )
- {
- pout.write( ( w++ ) + ": " + rw.getClass().getName() +
"<br/>" );
- if( rw instanceof HttpServletRequestWrapper )
- {
- rw = ( (HttpServletRequestWrapper) rw ).getRequest();
- }
- else if( rw instanceof ServletRequestWrapper )
- {
- rw = ( (ServletRequestWrapper) rw ).getRequest();
- }
- else
- {
- rw=null;
- }
- }
-
+ pout.write( "</tr></table>\n" );
+ writeRequestWrappers( request, response, pout );
pout.write( "<br/>" );
- pout.write( "<h2>International Characters</h2>" );
- pout.write( "Directly encoced: Dürst<br/>" );
- pout.write( "HTML reference: D&uuml;rst<br/>" );
- pout.write( "Decimal (252) 8859-1: D&#252;rst<br/>" );
- pout.write( "Hex (xFC) 8859-1: D&#xFC;rst<br/>" );
- pout.write( "Javascript unicode (00FC) : <script
language='javascript'>document.write(\"D\u00FCrst\" );</script><br/>" );
+ writeInternationalCharacter( pout );
pout.write( "<br/>" );
- pout.write( "<h2>Form to generate GET content</h2>" );
- pout.write( "<form method=\"GET\" action=\"" +
response.encodeURL( getURI( request ) ) + "\">" );
- pout.write( "TextField: <input type=\"text\" name=\"TextField\"
value=\"value\"/><br/>\n" );
- pout.write( "<input type=\"submit\" name=\"Action\"
value=\"Submit\">" );
- pout.write( "</form>" );
-
+ writeGetForm( request, response, pout );
pout.write( "<br/>" );
- pout.write( "<h2>Form to generate POST content</h2>" );
- pout.write( "<form method=\"POST\" action=\"" +
response.encodeURL( getURI( request ) ) + "\">" );
- pout.write( "TextField: <input type=\"text\" name=\"TextField\"
value=\"value\"/><br/>\n" );
- pout.write( "Select: <select multiple name=\"Select\">\n" );
- pout.write( "<option>ValueA</option>" );
- pout.write( "<option>ValueB1,ValueB2</option>" );
- pout.write( "<option>ValueC</option>" );
- pout.write( "</select><br/>" );
- pout.write( "<input type=\"submit\" name=\"Action\"
value=\"Submit\"><br/>" );
- pout.write( "</form>" );
-
- pout.write( "<h2>Form to get Resource</h2>" );
- pout.write( "<form method=\"POST\" action=\"" +
response.encodeURL( getURI( request ) ) + "\">" );
- pout.write( "resource: <input type=\"text\" name=\"resource\"
/><br/>\n" );
- pout.write( "<input type=\"submit\" name=\"Action\"
value=\"getResource\">" );
- pout.write( "</form>\n" );
-
- pout.write( "</body>\n</html>\n" );
+ writePostForm( request, response, pout );
+ pout.write( "<br/>" );
+ writeResourceForm( request, response, pout );
}
catch( Exception e )
{
getServletContext().log( "dump", e );
- }
-
- pout.close();
-
- if( pi != null )
+ }
+ }
+
+ private void writeCookies( HttpServletRequest request,
HttpServletResponse response, PrintWriter pout )
+ throws IOException
+ {
+ pout.write( "<th align=\"left\"
colspan=\"2\"><big><br/>Cookies:</big></th>" );
+ Cookie[] cookies = request.getCookies();
+ for( int i=0; cookies!=null && i<cookies.length; i++ )
{
- if( "/ex4".equals( pi ) )
+ Cookie cookie = cookies[i];
+ pout.write( "</tr><tr>\n" );
+ pout.write( "<th align=\"right\">" + cookie.getName() +
":&nbsp;</th>" );
+ pout.write( "<td>" + cookie.getValue() + "</td>" );
+ }
+ }
+
+ private void writeRequestWrappers( HttpServletRequest request,
HttpServletResponse response, PrintWriter pout ) throws IOException
+ {
+ pout.write( "<h2>Request Wrappers</h2>\n" );
+ ServletRequest rw = request;
+ int w=0;
+ while( rw != null )
+ {
+ pout.write( ( w++ ) + ": " + rw.getClass().getName() + "<br/>" );
+ if( rw instanceof HttpServletRequestWrapper )
{
- throw new ServletException( "test ex4", new Throwable() );
+ rw = ( (HttpServletRequestWrapper) rw ).getRequest();
}
- if( "/ex5".equals( pi ) )
+ else if( rw instanceof ServletRequestWrapper )
{
- throw new IOException( "test ex5" );
+ rw = ( (ServletRequestWrapper) rw ).getRequest();
}
- if( "/ex6".equals( pi ) )
+ else
{
- throw new UnavailableException( "test ex6" );
+ rw=null;
}
}
}
+
+ private void writeInternationalCharacter( PrintWriter pout ) throws
IOException
+ {
+ pout.write( "<h2>International Characters</h2>" );
+ pout.write( "Directly encoced: Dürst<br/>" );
+ pout.write( "HTML reference: D&uuml;rst<br/>" );
+ pout.write( "Decimal (252) 8859-1: D&#252;rst<br/>" );
+ pout.write( "Hex (xFC) 8859-1: D&#xFC;rst<br/>" );
+ pout.write( "Javascript unicode (00FC) : <script
language='javascript'>document.write(\"D\u00FCrst\" );</script><br/>" );
+ }

+ private void writeGetForm(
+ HttpServletRequest request, HttpServletResponse response, PrintWriter
pout ) throws IOException
+ {
+ pout.write( "<h2>Form to generate GET content</h2>" );
+ pout.write( "<form method=\"GET\" action=\"" + response.encodeURL(
getURI( request ) ) + "\">" );
+ pout.write( "TextField: <input type=\"text\" name=\"TextField\"
value=\"value\"/><br/>\n" );
+ pout.write( "<input type=\"submit\" name=\"Action\"
value=\"Submit\">" );
+ pout.write( "</form>" );
+ }
+
+ private void writePostForm(
+ HttpServletRequest request, HttpServletResponse response, PrintWriter
pout ) throws IOException
+ {
+ pout.write( "<h2>Form to generate POST content</h2>" );
+ pout.write( "<form method=\"POST\" action=\"" + response.encodeURL(
getURI( request ) ) + "\">" );
+ pout.write( "TextField: <input type=\"text\" name=\"TextField\"
value=\"value\"/><br/>\n" );
+ pout.write( "Select: <select multiple name=\"Select\">\n" );
+ pout.write( "<option>ValueA</option>" );
+ pout.write( "<option>ValueB1,ValueB2</option>" );
+ pout.write( "<option>ValueC</option>" );
+ pout.write( "</select><br/>" );
+ pout.write( "<input type=\"submit\" name=\"Action\"
value=\"Submit\"><br/>" );
+ pout.write( "</form>" );
+ }
+
+ private void writeResourceForm(
+ HttpServletRequest request, HttpServletResponse response, PrintWriter
pout ) throws IOException
+ {
+ pout.write( "<h2>Form to get Resource</h2>" );
+ pout.write( "<form method=\"POST\" action=\"" + response.encodeURL(
getURI( request ) ) + "\">" );
+ pout.write( "resource: <input type=\"text\" name=\"resource\"
/><br/>\n" );
+ pout.write( "<input type=\"submit\" name=\"Action\"
value=\"getResource\">" );
+ pout.write( "</form>\n" );
+ }
+
/**
* Return the servlet info.
* @return the info

Modified: trunk/main/transit/core/src/main/net/dpml/util/Resolver.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/util/Resolver.java
2006-07-16 04:49:02 UTC (rev 1566)
+++ trunk/main/transit/core/src/main/net/dpml/util/Resolver.java
2006-07-16 06:59:34 UTC (rev 1567)
@@ -29,11 +29,43 @@
*/
public interface Resolver
{
+ /**
+ * Utility function supporting resolution of uris containing 'resource'
or
+ * 'alias' schemes. If the supplied uri scheme is 'resource' or 'alias'
the
+ * reference is resolved to a artifact type, group and name from which a
+ * resource is resolved and the uri returned. If the scheme is resource
+ * the usi of the resource is returned. If the scheme is 'alias' a
+ * link alias is returned. If the scheme is not 'resource' or 'alias'
+ * the argument will be evaluated as a normal transit artifact uri
+ * specification.
+ *
+ * @param ref the uri argument
+ * @return the uri value
+ * @exception URISyntaxException if an error occurs during uri creation
+ */
URI toURI( String ref ) throws URISyntaxException;

+ /**
+ * Return a property value.
+ * @param key the property key
+ * @return the property value
+ */
String getProperty( String key );

+ /**
+ * Return a property value.
+ * @param key the property key
+ * @param value the default value
+ * @return the property value
+ */
String getProperty( String key, String value );

+ /**
+ * Symbolic expansion of a supplied value.
+ * Replace any occurances of ${[key]} with the value of the property
+ * assigned to the [key] in system properties.
+ * @param value a string containing possibly multiple ${[value]} sequences
+ * @return the expanded string
+ */
String resolve( String value );
}

Modified: trunk/main/transit/core/src/main/net/dpml/util/SimpleResolver.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/util/SimpleResolver.java
2006-07-16 04:49:02 UTC (rev 1566)
+++ trunk/main/transit/core/src/main/net/dpml/util/SimpleResolver.java
2006-07-16 06:59:34 UTC (rev 1567)
@@ -26,22 +26,54 @@
*/
public class SimpleResolver implements Resolver
{
+ /**
+ * Utility function supporting resolution of uris containing 'resource'
or
+ * 'alias' schemes. If the supplied uri scheme is 'resource' or 'alias'
the
+ * reference is resolved to a artifact type, group and name from which a
+ * resource is resolved and the uri returned. If the scheme is resource
+ * the usi of the resource is returned. If the scheme is 'alias' a
+ * link alias is returned. If the scheme is not 'resource' or 'alias'
+ * the argument will be evaluated as a normal transit artifact uri
+ * specification.
+ *
+ * @param ref the uri argument
+ * @return the uri value
+ * @exception URISyntaxException if an error occurs during uri creation
+ */
public URI toURI( String ref ) throws URISyntaxException
{
String value = resolve( ref );
return new URI( value );
}

+ /**
+ * Return a property value.
+ * @param key the property key
+ * @return the property value
+ */
public String getProperty( String key )
{
return System.getProperty( key );
}

+ /**
+ * Return a property value.
+ * @param key the property key
+ * @param value the default value
+ * @return the property value
+ */
public String getProperty( String key, String value )
{
return System.getProperty( key, value );
}

+ /**
+ * Symbolic expansion of a supplied value.
+ * Replace any occurances of ${[key]} with the value of the property
+ * assigned to the [key] in system properties.
+ * @param value a string containing possibly multiple ${[value]} sequences
+ * @return the expanded string
+ */
public String resolve( String value )
{
return PropertyResolver.resolve( value );




  • r1567 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/http/war/src/main/net/dpml/test/http transit/core/src/main/net/dpml/util, mcconnell at BerliOS, 07/16/2006

Archive powered by MHonArc 2.6.24.

Top of Page