You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/10/27 22:42:16 UTC
svn commit: r328947 [1/2] - in /beehive/trunk/netui/src/testRecorder: ./
org/apache/beehive/netui/tools/testrecorder/client/
org/apache/beehive/netui/tools/testrecorder/server/
org/apache/beehive/netui/tools/testrecorder/server/state/
org/apache/beehiv...
Author: ekoneil
Date: Thu Oct 27 13:42:00 2005
New Revision: 328947
URL: http://svn.apache.org/viewcvs?rev=328947&view=rev
Log:
Last bit of migration from XMLBeans to DOM in the test recorder.
This change adds namespace support to the DomUtils and removes all XMLBean build dependencies.
BB: self
Tests:
- record test with / without HTTP parameters works
- playback test works
- BVT / urlTemplates / JSF tests pass
Added:
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/schemas/testRecorderSession.xsd
- copied unchanged from r328474, beehive/trunk/netui/src/testRecorder/schema/testRecorderSession.xsd
Removed:
beehive/trunk/netui/src/testRecorder/schema/testRecorderSession.xsd
Modified:
beehive/trunk/netui/src/testRecorder/build.xml
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/PlaybackExecutor.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderServlet.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/State.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionXMLException.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
Modified: beehive/trunk/netui/src/testRecorder/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/build.xml?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/build.xml (original)
+++ beehive/trunk/netui/src/testRecorder/build.xml Thu Oct 27 13:42:00 2005
@@ -14,7 +14,6 @@
<path refid="servlet.dependency.path"/>
<path refid="log4j.dependency.path"/>
<path refid="junit.dependency.path"/>
- <path refid="xbean.dependency.path"/>
<path refid="testrecorder.build.dependency.path"/>
</path>
@@ -24,13 +23,6 @@
<mkdir dir="${module.classes.dir}"/>
- <ant antfile="${netui.ant.dir}/xmlBean.xml" target="ant.build.xmlbean">
- <property name="xsd.root.dir" value="${module.dir}/schema/"/>
- <property name="class.output.dir" value="${module.classes.dir}"/>
- <property name="xbean.inputs" value="schema/*.xsd*"/>
- <property name="xbean.output" value="${module.jar}"/>
- </ant>
-
<javac srcdir="${module.dir}"
destdir="${module.classes.dir}"
classpathref="module.classpath"
@@ -44,10 +36,6 @@
<copy todir="${module.classes.dir}">
<fileset dir="${module.dir}" includes="org/**/*.xsd"/>
- </copy>
-
- <copy todir="${module.classes.dir}/org/apache/beehive/netui/tools/testrecorder/shared/schemas">
- <fileset dir="${module.dir}/schema"/>
</copy>
<mkdir dir="${testRecorder.dir}"/>
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/PlaybackExecutor.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/PlaybackExecutor.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/PlaybackExecutor.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/PlaybackExecutor.java Thu Oct 27 13:42:00 2005
@@ -15,9 +15,15 @@
*
* $Header:$
*/
-
package org.apache.beehive.netui.tools.testrecorder.client;
+import java.io.File;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.List;
+
import org.apache.beehive.netui.tools.testrecorder.shared.Logger;
import org.apache.beehive.netui.tools.testrecorder.shared.RecordSessionBean;
import org.apache.beehive.netui.tools.testrecorder.shared.Constants;
@@ -34,21 +40,11 @@
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.GetMethod;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.util.Locale;
-import java.util.List;
-import java.io.File;
-import java.io.IOException;
-
/**
- * User: ozzy
- * Date: Jun 29, 2004
- * Time: 2:26:39 PM
*/
public class PlaybackExecutor {
- private static final Logger log = Logger.getInstance( PlaybackExecutor.class );
+ private static final Logger LOGGER = Logger.getInstance( PlaybackExecutor.class );
private static HttpClient controlClient = new HttpClient();
private static HttpClient testClient = new HttpClient();
@@ -75,15 +71,15 @@
private String testId;
private RecordSessionBean session;
-
public PlaybackExecutor( TestDefinition test,
- String description, String testUser ) {
+ String description,
+ String testUser ) {
this.test = test;
assert test != null : "the test definition name may not be null";
this.description = description;
- if ( description == null ) {
+ if ( description == null )
description = "No Description.";
- }
+
this.testUser = testUser;
setControlParams();
}
@@ -113,7 +109,8 @@
executeRequests();
}
catch ( Throwable e ) {
- log.error( "start failure", e );
+ e.printStackTrace();
+ LOGGER.error( "start failure", e );
exception = e;
}
finally {
@@ -127,70 +124,75 @@
exception = e;
}
else {
- log.error( "ERROR: possible spurious failure, failed to stop playback, exception( " +
- e.getMessage() + " )", e );
+ LOGGER.error( "ERROR: possible spurious failure, failed to stop playback, exception( " + e.getMessage() + " )", e );
}
}
}
+
if ( exception != null ) {
String msg = "ERROR: playback failed, exception( " + exception.getMessage() + " )";
- log.error( msg, exception );
- if ( exception instanceof PlaybackException ) {
- throw (PlaybackException) exception;
- }
- throw new PlaybackException( msg, exception );
+ LOGGER.error( msg, exception );
+ throw new PlaybackException(msg, exception);
}
}
return rtnVal;
}
- protected void startPlayback() throws PlaybackException {
- HttpMethod method = new GetMethod( RequestData.genUri( "http",
- getTest().getWebapp().getServer().getHostname(), getTest().getWebapp().getServer().getPort(),
- getTest().getWebapp().getServletURI() ) );
+ protected void startPlayback()
+ throws PlaybackException {
+
+ HttpMethod method = new GetMethod(
+ RequestData.genUri( "http",
+ getTest().getWebapp().getServer().getHostname(),
+ getTest().getWebapp().getServer().getPort(),
+ getTest().getWebapp().getServletURI() )
+ );
+
method.setQueryString( getStartParams() );
ResponseData response = null;
+
try {
response = execute( getControlClient(), method );
}
catch ( Exception e ) {
String msg = "Failed to execute start playback request, exception( " + e.getMessage() + " )";
- log.error( msg, e );
- if ( e instanceof PlaybackException ) {
- throw (PlaybackException) e;
- }
- throw new PlaybackException( msg, e );
+ LOGGER.error( msg, e );
+ throw new PlaybackException(msg, e);
}
+
String outcome = response.getHeader( Constants.OUTCOME_HEADER );
String testId = response.getHeader( Constants.TEST_ID_HEADER );
String testFileName = response.getHeader( Constants.RECORD_FILE_HEADER );
String startMsg = response.getHeader( Constants.MSG_ATTRIBUTE );
- // config the playback stop params
+
+ /* config the playback stop params */
setStopParam( 3, new NameValuePair( Constants.TEST_ID_HEADER, testId ) );
setTestId( testId );
- if ( log.isInfoEnabled() ) {
- log.info( "outcome( " + outcome + " )" );
- log.info( "testId( " + getTestId() + " )" );
- log.info( "testFileName( " + testFileName + " )" );
- }
- // failed
- if ( outcome == null || !outcome.equals( Constants.PASS ) ) {
- throw new PlaybackException(
- "ERROR: failed to start playback, server error message( " + startMsg + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "outcome( " + outcome + " )" );
+ LOGGER.info( "testId( " + getTestId() + " )" );
+ LOGGER.info( "testFileName( " + testFileName + " )" );
}
+
+ /* failed */
+ if ( outcome == null || !outcome.equals( Constants.PASS ) )
+ throw new PlaybackException("Failed to start playback, server error message( " + startMsg + " )" );
+
this.recordFile = new File( testFileName );
if ( !getRecordFile().canRead() ) {
- String msg = "ERROR: failed to start playback, lacking permissions to read record file( " +
- getRecordFile() + " )";
+ String msg = "ERROR: failed to start playback, lacking permissions to read record file( " + getRecordFile() + " )";
System.out.println( msg );
- log.error( msg );
+ LOGGER.error( msg );
throw new PlaybackException( msg );
}
+
+ /* parsexml */
RecordSessionBean session = createSession();
+
setSession( session );
- if ( log.isInfoEnabled() ) {
- log.info( "playback started for test( " + getTest().getName() + " )" );
- }
+
+ if ( LOGGER.isInfoEnabled() )
+ LOGGER.info( "playback started for test( " + getTest().getName() + " )" );
}
protected boolean stopPlayback() throws PlaybackException {
@@ -205,7 +207,7 @@
}
catch ( Exception e ) {
String msg = "Failed to execute stop playback request, exception( " + e.getMessage() + " )";
- log.error( msg, e );
+ LOGGER.error( msg, e );
if ( e instanceof PlaybackException ) {
throw (PlaybackException) e;
}
@@ -215,20 +217,20 @@
String resultsFileName = response.getHeader( Constants.RESULTS_FILE_HEADER );
String diffFileName = response.getHeader( Constants.RESULTS_DIFF_HEADER );
String stopMsg = response.getHeader( Constants.MSG_ATTRIBUTE );
- if ( log.isDebugEnabled() ) {
- log.debug( "stop outcome( " + outcome + " )" );
- log.debug( "stopMsg( " + stopMsg + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "stop outcome( " + outcome + " )" );
+ LOGGER.debug( "stopMsg( " + stopMsg + " )" );
}
if ( outcome != null && !outcome.equals( Constants.ERROR ) ) {
// requests successfully executed
- if ( log.isInfoEnabled() ) {
- log.info( "Results are stored in file( " + resultsFileName + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "Results are stored in file( " + resultsFileName + " )" );
}
setResultsFile( new File( resultsFileName ) );
// if there were errors then report them...
if ( outcome.equals( Constants.FAIL ) ) {
- if ( log.isInfoEnabled() ) {
- log.info( "Diff results are stored in file( " + diffFileName + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "Diff results are stored in file( " + diffFileName + " )" );
}
setDiffFile( new File( diffFileName ) );
rtnVal = false;
@@ -240,61 +242,62 @@
else {
String msg = "ERROR: error encountered executing test( " + getTest().getName() + " ), server msg( " +
stopMsg + " )";
- log.error( msg );
+ LOGGER.error( msg );
throw new PlaybackException( msg );
}
return rtnVal;
}
- private RecordSessionBean createSession() throws PlaybackException {
+ private RecordSessionBean createSession()
+ throws PlaybackException {
RecordSessionBean session = null;
try {
session = XMLHelper.getRecordSessionBean( getRecordFile() );
- if ( log.isDebugEnabled() ) {
- log.debug( "test( " + getTest().getName() + " ), testCount( " + session.getTestCount() + " )" );
- }
+ if(LOGGER.isDebugEnabled())
+ LOGGER.debug("test(" + getTest().getName() + "), testCount(" + session.getTestCount() + ")");
}
- catch ( Exception e ) {
- String msg = "ERROR: failed to process session file( " + getRecordFile().getAbsolutePath() + " )";
- log.error( msg, e );
- throw new PlaybackException( msg, e );
+ catch(Exception e) {
+ String msg = "ERROR: failed to process session file(" + getRecordFile().getAbsolutePath() + ")";
+ throw new PlaybackException(msg, e);
}
return session;
}
- private void executeRequests() throws PlaybackException {
+ private void executeRequests()
+ throws PlaybackException {
+
RequestData request = null;
int testNumber = 0;
try {
List requestList = getSession().getRequestData();
- if ( log.isDebugEnabled() ) {
- log.debug( "beginning test execution" );
- }
+ if ( LOGGER.isDebugEnabled() )
+ LOGGER.debug( "beginning test execution" );
+
for ( testNumber = 0; testNumber < requestList.size(); testNumber++ ) {
request = (RequestData) requestList.get( testNumber );
- if ( log.isDebugEnabled() ) {
- log.debug( "beginning execution for test number( " + ( testNumber + 1 ) + " )" );
- }
+
+ if ( LOGGER.isDebugEnabled() )
+ LOGGER.debug( "beginning execution for test number( " + ( testNumber + 1 ) + " )" );
+
HttpMethod method = createPlaybackMethod( request, getTest() );
- if ( log.isDebugEnabled() ) {
- log.debug( "playback URI( " + method.getURI() + " )" );
- }
+ if ( LOGGER.isDebugEnabled() )
+ LOGGER.debug( "playback URI( " + method.getURI() + " )" );
+
ResponseData response = execute( getTestClient(), method );
- if ( log.isDebugEnabled() ) {
- log.debug( "playback response, status code( " + response.getStatusCode() + " )" );
- log.debug( "playback response, body(\n" + response.getBody() + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "playback response, status code( " + response.getStatusCode() + " )" );
+ LOGGER.debug( "playback response, body(\n" + response.getBody() + " )" );
}
String outcome = response.getHeader( Constants.OUTCOME_HEADER );
- if ( log.isDebugEnabled() ) {
- log.debug( "outcome( " + outcome + " )" );
- }
+ if ( LOGGER.isDebugEnabled() )
+ LOGGER.debug( "outcome( " + outcome + " )" );
+
if ( response.getStatusCode() >= 400 ) {
- String msg = "WARNING: unable to access URI( " + method.getURI() +
- " ), status code( " + response.getStatusCode() + " ) returned";
+ String msg = "WARNING: unable to access URI( " + method.getURI() + "), status code( " + response.getStatusCode() + " ) returned";
System.out.println( msg );
- if ( log.isWarnEnabled() ) {
- log.warn( msg );
- }
+
+ if ( LOGGER.isWarnEnabled() )
+ LOGGER.warn( msg );
}
}
}
@@ -302,11 +305,8 @@
String msg = "ERROR: failed executing request for test( " + getTest().getName() +
" ), testNumber( " + testNumber + " ), path( " + request.getPath() + " ), exception( "
+ e.getMessage() + " )";
- log.error( msg, e );
- if ( e instanceof PlaybackException ) {
- throw (PlaybackException) e;
- }
- throw new PlaybackException( msg, e );
+ LOGGER.error( msg, e );
+ throw new PlaybackException(msg, e);
}
}
@@ -320,31 +320,31 @@
statusCode = client.executeMethod( method );
}
catch ( HttpRecoverableException e ) {
- if ( log.isWarnEnabled() ) {
+ if ( LOGGER.isWarnEnabled() ) {
String msg = "A recoverable exception occurred calling URI( " + method.getURI() +
" ), retrying. exception( " + e.getMessage() + " )";
- log.error( msg, e );
+ LOGGER.error( msg, e );
}
}
catch ( IOException e ) {
String msg = "Failed executing request( " + method.getURI() + " ), exception( " + e.getMessage() +
" )";
- log.error( msg, e );
+ LOGGER.error( msg, e );
throw e;
}
}
// Retries failed
if ( statusCode == -1 ) {
String msg = "Failed to execute request( " + method.getURI() + " )";
- log.error( msg );
+ LOGGER.error( msg );
throw new PlaybackException( msg );
}
response.setStatusCode( statusCode );
byte[] responseBody = method.getResponseBody();
response.setBody( new String( responseBody ) );
- if ( log.isDebugEnabled() ) {
- log.debug( "statusCode( " + statusCode + " )" );
-// log.debug( "response body:\n" + response.getBody() + "\n" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "statusCode( " + statusCode + " )" );
+// LOGGER.debug( "response body:\n" + response.getBody() + "\n" );
}
response.setHeaders( convertHeaders( method.getResponseHeaders() ) );
method.releaseConnection();
@@ -370,7 +370,7 @@
}
protected HttpMethod populatePlaybackPostMethod( final PostMethod method, final RequestData request ) {
- log.debug( "calling setRequestBody()" );
+ LOGGER.debug( "calling setRequestBody()" );
method.setRequestBody( convertNVPairs( request.getParameters() ) );
populatePlaybackMethod( method, request );
debugNameValuePairs( method.getParameters() );
@@ -379,7 +379,8 @@
protected HttpMethod populatePlaybackGetMethod( final GetMethod method, final RequestData request ) {
populatePlaybackMethod( method, request );
- method.setQueryString( convertNVPairs( request.getParameters() ) );
+ NameValuePair[] nvPairs = convertNVPairs(request.getParameters());
+ method.setQueryString( nvPairs != null ? nvPairs : new NameValuePair[0] );
return method;
}
@@ -404,7 +405,6 @@
* client during playback
*
* @param name
- * @return
*/
protected boolean skipPlaybackHeader( String name ) {
// fail mode header is for legacy record files
@@ -530,16 +530,16 @@
}
private static NVPair convertHeader( Header header ) {
- if ( log.isDebugEnabled() ) {
- log.debug( "header, name( " + header.getName() + " ), value( " + header.getValue() + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "header, name( " + header.getName() + " ), value( " + header.getValue() + " )" );
}
return new NVPair( header.getName(), header.getValue() );
}
private static NameValuePair[] convertNVPairs( NVPair[] pairs ) {
- if ( pairs == null ) {
+ if ( pairs == null )
return null;
- }
+
NameValuePair[] newPairs = new NameValuePair[pairs.length];
NameValuePair newPair = null;
for ( int i = 0; i < pairs.length; i++ ) {
@@ -550,19 +550,19 @@
}
private static NameValuePair convertNVPair( NVPair pair ) {
- if ( log.isDebugEnabled() ) {
- log.debug( "pair, name( " + pair.getName() + " ), value( " + pair.getValue() + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "pair, name( " + pair.getName() + " ), value( " + pair.getValue() + " )" );
}
return new NameValuePair( pair.getName(), pair.getValue() );
}
private static void debugNameValuePairs( NameValuePair[] pairs ) {
if ( pairs == null ) {
- log.debug( "pairs( " + pairs + " )" );
+ LOGGER.debug( "pairs( " + pairs + " )" );
return;
}
for ( int i = 0; i < pairs.length; i++ ) {
- log.debug(
+ LOGGER.debug(
"pair(" + i + ")[ name( " + pairs[i].getName() + " ), value( " + pairs[i].getValue() + " )" );
}
return;
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderServlet.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderServlet.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderServlet.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderServlet.java Thu Oct 27 13:42:00 2005
@@ -15,7 +15,6 @@
*
* $Header:$
*/
-
package org.apache.beehive.netui.tools.testrecorder.server;
import java.io.File;
@@ -47,23 +46,18 @@
import org.apache.beehive.netui.tools.testrecorder.server.state.SessionFailedException;
-public class TestRecorderServlet extends HttpServlet {
-
- private static final Logger log = Logger.getInstance( TestRecorderServlet.class );
+public class TestRecorderServlet
+ extends HttpServlet {
- public TestRecorderServlet() {
- }
+ private static final Logger LOGGER = Logger.getInstance( TestRecorderServlet.class );
public void init() {
- if ( log.isInfoEnabled() ) {
- log.warn( "initializing ..." );
- }
+ LOGGER.warn( "initializing ..." );
}
public void destroy() {
- if ( log.isInfoEnabled() ) {
- log.warn( "destroying ..." );
- }
+ LOGGER.warn( "destroying ..." );
+
super.destroy();
}
@@ -78,10 +72,8 @@
try {
mode = request.getParameter( Constants.MODE );
if ( mode == null ) {
- // fail
String msg = "mode( " + mode + " ) may not be null.";
forward( request, response, msg, Constants.ERROR_PAGE, true );
- return;
}
else if ( mode.equalsIgnoreCase( Constants.RECORD ) ) {
doRecord( request, response );
@@ -125,14 +117,14 @@
String testUser = request.getParameter( Constants.TEST_USER );
String description = request.getParameter( Constants.DESCRIPTION );
boolean overwrite = Boolean.valueOf( request.getParameter( Constants.OVERWRITE ) ).booleanValue();
- if ( log.isInfoEnabled() ) {
- log.debug( "record cmd( " + cmd + " )" );
- log.debug( "testName( " + testName + " )" );
- }
- if ( log.isDebugEnabled() ) {
- log.debug( "testUser( " + testUser + " )" );
- log.debug( "overwrite( " + overwrite + " )" );
- log.debug( "description( " + description + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.debug( "record cmd( " + cmd + " )" );
+ LOGGER.debug( "testName( " + testName + " )" );
+ }
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "testUser( " + testUser + " )" );
+ LOGGER.debug( "overwrite( " + overwrite + " )" );
+ LOGGER.debug( "description( " + description + " )" );
}
if ( cmd == null ) {
// fail
@@ -160,8 +152,8 @@
TestRecorderFilter filter = TestRecorderFilter.instance();
RecordSession session = filter.getState().getRecordingSession();
String msg = "ERROR: failed stopping recording session";
- if ( log.isDebugEnabled() ) {
- log.debug( "STOPPING: recording session( " + session + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "STOPPING: recording session( " + session + " )" );
}
try {
// this may take some time, this waits for recording threads to finish
@@ -169,15 +161,15 @@
if ( session == null ) {
// fail, not currently recording
msg = "ERROR: no recording session is currently started";
- if ( log.isWarnEnabled() ) {
- log.warn( msg );
+ if ( LOGGER.isWarnEnabled() ) {
+ LOGGER.warn( msg );
}
}
else {
request.setAttribute( Constants.RECORD_SESSION_ATTRIBUTE, session );
msg = "Recording session( " + session.getSessionName() + " ) stopped";
- if ( log.isInfoEnabled() ) {
- log.info( msg );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( msg );
}
}
forward( request, response, msg, Constants.RECORD_PAGE, false );
@@ -188,8 +180,8 @@
request.setAttribute( Constants.RECORD_SESSION_ATTRIBUTE, session );
forward( request, response, msg, Constants.RECORD_PAGE, true, ex );
}
- if ( log.isDebugEnabled() ) {
- log.debug( "STOPPED: recording session( " + session + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "STOPPED: recording session( " + session + " )" );
}
}
@@ -221,8 +213,8 @@
forward( request, response, msg, Constants.RECORD_PAGE, true, ex );
return;
}
- if ( log.isDebugEnabled() ) {
- log.debug( "attempting to start recording session( " + session + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "attempting to start recording session( " + session + " )" );
}
TestRecorderFilter filter = TestRecorderFilter.instance();
boolean start = false;
@@ -235,14 +227,14 @@
forward( request, response, msg, Constants.RECORD_PAGE, true, ex );
return;
}
- if ( log.isInfoEnabled() ) {
- log.info( "start( " + start + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "start( " + start + " )" );
}
if ( start ) {
String msg = "recording session( " + session.getSessionName() + " ) started.";
request.setAttribute( Constants.RECORD_SESSION_ATTRIBUTE, session );
- if ( log.isInfoEnabled() ) {
- log.info( msg );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( msg );
}
forward( request, response, msg, Constants.RECORD_PAGE, false );
}
@@ -257,8 +249,8 @@
public void doPlayback( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException, ConfigException {
String cmd = request.getParameter( Constants.CMD );
- if ( log.isInfoEnabled() ) {
- log.info( "playback cmd( " + cmd + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "playback cmd( " + cmd + " )" );
}
// any request forwards from here should skip the filter.
request.setAttribute( Constants.FILTER_SKIP_PARAM, Boolean.TRUE );
@@ -282,8 +274,8 @@
private void doPlaybackStop( HttpServletRequest request,
HttpServletResponse response ) throws IOException {
String testId = request.getParameter( Constants.TEST_ID_HEADER );
- if ( log.isInfoEnabled() ) {
- log.info( "playback stop testId( " + testId + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "playback stop testId( " + testId + " )" );
}
TestRecorderFilter filter = TestRecorderFilter.instance();
PlaybackSession session = null;
@@ -297,7 +289,7 @@
ex.getMessage() + " )";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
response.setHeader( Constants.OUTCOME_HEADER, Constants.ERROR );
- log.error( msg, ex );
+ LOGGER.error( msg, ex );
if ( ex instanceof IOException ) {
throw (IOException) ex;
}
@@ -308,8 +300,8 @@
throw new RuntimeException( msg, ex );
}
}
- if ( log.isInfoEnabled() ) {
- log.info( "STOP: playback session( " + session + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "STOP: playback session( " + session + " )" );
}
if ( session == null ) {
// fail, not currently doing playback
@@ -318,7 +310,7 @@
// set response headers for the client.
response.setHeader( Constants.OUTCOME_HEADER, Constants.ERROR );
response.setHeader( Constants.MSG_ATTRIBUTE, msg );
- log.error( msg );
+ LOGGER.error( msg );
}
else {
// gen playback summary
@@ -329,8 +321,8 @@
" ).";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
request.setAttribute( Constants.PLAYBACK_SESSION_ATTRIBUTE, session );
- if ( log.isInfoEnabled() ) {
- log.info( msg );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( msg );
}
// set response headers for the client.
response.setHeader( Constants.OUTCOME_HEADER, outcome );
@@ -351,8 +343,8 @@
throw new ConfigException(
"ERROR: playback start failed, unable to find a test for test name( " + testName + " )" );
}
- if ( log.isInfoEnabled() ) {
- log.info( "playback start test( " + test.getName() + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "playback start test( " + test.getName() + " )" );
}
PlaybackSession session = null;
try {
@@ -362,7 +354,7 @@
String msg = "ERROR: unable to start playback, unable to obtain session, exception( " +
ex.getMessage() + " )";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
- log.error( msg, ex );
+ LOGGER.error( msg, ex );
System.err.println( "\nPLAYBACK ERROR:\n" + msg );
if ( ex instanceof IOException ) {
throw (IOException) ex;
@@ -384,7 +376,7 @@
String msg = "ERROR: failed to start playback session( " + session + " ), exception( " +
ex.getMessage() + " )";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
- log.error( msg, ex );
+ LOGGER.error( msg, ex );
System.err.println( "\nPLAYBACK ERROR:\n" + msg );
if ( ex instanceof IOException ) {
throw (IOException) ex;
@@ -396,16 +388,16 @@
throw new RuntimeException( msg, ex );
}
}
- if ( log.isInfoEnabled() ) {
- log.info( "playback start( " + start + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "playback start( " + start + " )" );
}
if ( start ) {
String msg = "playback session( " +
session.getSessionName() + " ) started.";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
request.setAttribute( Constants.PLAYBACK_SESSION_ATTRIBUTE, session );
- if ( log.isInfoEnabled() ) {
- log.info( msg );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( msg );
}
// set response headers for the client.
response.setHeader( Constants.OUTCOME_HEADER,
@@ -421,7 +413,7 @@
session.getSessionName() + " )";
request.setAttribute( Constants.MSG_ATTRIBUTE, msg );
request.setAttribute( Constants.PLAYBACK_SESSION_ATTRIBUTE, session );
- log.error( msg );
+ LOGGER.error( msg );
// set response headers for the client.
response.setHeader( Constants.OUTCOME_HEADER,
Constants.FAIL );
@@ -471,7 +463,8 @@
}
public void doLink( HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException, ConfigException {
+ throws IOException, ServletException, ConfigException {
+
String sessionName = request.getParameter( Constants.FILE );
TestDefinition test = getTest( sessionName );
WebappConfig config = TestRecorderFilter.instance().getWebapp();
@@ -500,18 +493,18 @@
forward( request, response, msg, Constants.ERROR_PAGE, true );
return;
}
+
RequestData rd = bean.getRequestData( 0 );
if ( rd == null ) {
- String msg = "Unable to find the first request in the test ( " + test.getName() + " ), file( " +
- recFile.getAbsolutePath() + " )";
+ String msg = "Unable to find the first request in the test ( " + test.getName() + " ), file( " + recFile.getAbsolutePath() + " )";
forward( request, response, msg, Constants.ERROR_PAGE, true );
return;
}
+
String host = config.getServer().getHostname();
if ( host.equals( "localhost" ) )
- {
host = request.getServerName();
- }
+
response.sendRedirect( rd.getUri( host, config.getServer().getPort() ) );
return;
}
@@ -581,10 +574,10 @@
}
if ( error ) {
if ( ex != null ) {
- log.error( msg, ex );
+ LOGGER.error( msg, ex );
}
else {
- log.error( msg );
+ LOGGER.error( msg );
}
}
forward( request, response, page );
@@ -599,8 +592,8 @@
public void doAdmin( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException, ConfigException {
String cmd = request.getParameter( Constants.CMD );
- if ( log.isInfoEnabled() ) {
- log.info( "admin cmd( " + cmd + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "admin cmd( " + cmd + " )" );
}
// any request forwards from here should skip the filter.
request.setAttribute( Constants.FILTER_SKIP_PARAM, Boolean.TRUE );
@@ -637,8 +630,8 @@
private void doClean( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
IOException {
- if ( log.isInfoEnabled() ) {
- log.info( "clean up test recorder sessions" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "clean up test recorder sessions" );
}
TestRecorderFilter filter = TestRecorderFilter.instance();
filter.getState().stopAll();
@@ -647,8 +640,8 @@
private void doTestMode( HttpServletRequest request, HttpServletResponse response, boolean value )
throws ServletException, IOException {
- if ( log.isInfoEnabled() ) {
- log.info( "setting test mode to ( " + value + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "setting test mode to ( " + value + " )" );
}
TestRecorderFilter filter = TestRecorderFilter.instance();
filter.getState().setTestMode( value );
@@ -891,8 +884,8 @@
}
private static TestDefinition getTest( String name ) {
- if ( log.isInfoEnabled() ) {
- log.debug( "test name( " + name + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.debug( "test name( " + name + " )" );
}
if ( name == null ) {
return null;
@@ -904,8 +897,8 @@
private static RecordSession getRecordSession( TestDefinition test, boolean overwrite,
String testUser, String description ) throws SessionFailedException {
File file = getRecordSessionFile( test );
- if ( log.isInfoEnabled() ) {
- log.info( "record file( " + file.getAbsolutePath() + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "record file( " + file.getAbsolutePath() + " )" );
}
// may throw IOException or SecurityException (runtime)
RecordSession session = State.createRecordSession( test.getName(), file,
@@ -916,15 +909,16 @@
private static PlaybackSession getPlaybackSession( TestDefinition test )
throws IOException, SessionFailedException {
File playbackFile = getPlaybackSessionFile( test );
- if ( log.isInfoEnabled() ) {
- log.info( "playback file( " + playbackFile.getAbsolutePath() + " )" );
+ if ( LOGGER.isInfoEnabled() ) {
+ LOGGER.info( "playback file( " + playbackFile.getAbsolutePath() + " )" );
}
// may throw IOException or SecurityException (runtime)
File diffFile = getDiffFile( test );
File recordFile = getTestFile( test );
+
// may throw IOException or SecurityException (runtime)
- PlaybackSession session = State.createPlaybackSession( test.getName(), playbackFile,
- recordFile, diffFile );
+ PlaybackSession session = State.createPlaybackSession( test.getName(), playbackFile, recordFile, diffFile );
+
return session;
}
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java Thu Oct 27 13:42:00 2005
@@ -15,7 +15,6 @@
*
* $Header:$
*/
-
package org.apache.beehive.netui.tools.testrecorder.server.state;
import java.io.File;
@@ -32,10 +31,11 @@
import org.apache.beehive.netui.tools.testrecorder.server.FilterData;
import org.apache.beehive.netui.tools.testrecorder.server.DiffEngine;
+class PlaybackSessionImpl
+ extends SessionImpl
+ implements PlaybackSession {
-class PlaybackSessionImpl extends SessionImpl implements PlaybackSession {
-
- private static final Logger log = Logger.getInstance( PlaybackSessionImpl.class );
+ private static final Logger LOGGER = Logger.getInstance( PlaybackSessionImpl.class );
private UID uid;
private String stringUid;
@@ -43,12 +43,16 @@
private File playbackFile;
private File diffFile;
- // record bean is read only
+ /* record bean is read only */
private RecordSessionBean recordSessionBean;
private PlaybackSessionBean playbackSessionBean;
- PlaybackSessionImpl( String sessionName, File playbackFile, File recordFile,
- File diffFile ) throws SessionFailedException {
+ PlaybackSessionImpl(String sessionName,
+ File playbackFile,
+ File recordFile,
+ File diffFile)
+ throws SessionFailedException {
+
super( new PlaybackSessionBean( sessionName ) );
playbackSessionBean = (PlaybackSessionBean) getSessionBean();
if ( sessionName == null || sessionName.trim().length() <= 0 ) {
@@ -63,13 +67,14 @@
this.playbackFile = playbackFile;
this.diffFile = diffFile;
this.recordFile = recordFile;
- if ( !recordFile.exists() ) {
+ if ( !recordFile.exists() )
error( "record file( " + recordFile.getAbsolutePath() + " ) does NOT exist" );
- }
- if ( !recordFile.canRead() ) {
+
+ if ( !recordFile.canRead() )
error( "record file( " + recordFile.getAbsolutePath() + " ) is not readable" );
- }
+
recordSessionBean = parseRecordFile( recordFile );
+
playbackSessionBean.setRecordedTestCount( recordSessionBean.getTestCount() );
if ( playbackSessionBean.getTester() == null || playbackSessionBean.getTester().length() == 0 ) {
if ( recordSessionBean.getTester() == null || recordSessionBean.getTester().length() == 0 ) {
@@ -85,14 +90,14 @@
playbackSessionBean.setDescription( recordSessionBean.getTester() );
}
// if a version of this file exists, kill it
- if ( log.isDebugEnabled() ) {
- log.debug( "playbackFile( " + playbackFile.getAbsolutePath() + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "playbackFile( " + playbackFile.getAbsolutePath() + " )" );
}
if ( playbackFile.exists() ) {
boolean rtnVal = playbackFile.delete();
if ( rtnVal ) {
- if ( log.isDebugEnabled() ) {
- log.debug( "playback file exists, deleted(" + rtnVal + ")" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "playback file exists, deleted(" + rtnVal + ")" );
}
}
else {
@@ -102,8 +107,8 @@
if ( diffFile.exists() ) {
boolean rtnVal = diffFile.delete();
if ( rtnVal ) {
- if ( log.isDebugEnabled() ) {
- log.debug( "diff file exists, deleted(" + rtnVal + ")" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "diff file exists, deleted(" + rtnVal + ")" );
}
}
else {
@@ -233,8 +238,8 @@
// cleans up the session if getSessionState() == STOP and inProgressCnt() == 0
checkSessionComplete();
}
- if ( log.isDebugEnabled() ) {
- log.debug( "testCount( " + testCount() + " )" );
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "testCount( " + testCount() + " )" );
}
return testCount();
}
@@ -254,8 +259,8 @@
}
protected synchronized void closeSessionInternal() throws SessionFailedException {
- if ( log.isDebugEnabled() ) {
- log.debug( "closing session file ( " + getPlaybackFile() + " ), session status( " +
+ if ( LOGGER.isDebugEnabled() ) {
+ LOGGER.debug( "closing session file ( " + getPlaybackFile() + " ), session status( " +
playbackSessionBean.getStatus() +
" )" );
}
@@ -268,7 +273,7 @@
setSessionState( ERROR_END );
String msg = "ERROR: failed to create playback XML file( " + getPlaybackFile().getAbsolutePath() +
" ), exception( " + e.getMessage() + " )";
- log.error( msg, e );
+ LOGGER.error( msg, e );
caught = new SessionFailedException( msg, e );
}
if ( playbackSessionBean.getFailedCount() > 0 || playbackSessionBean.isError() ) {
@@ -283,7 +288,7 @@
setSessionState( ERROR_END );
String msg = "ERROR: failed to create diff XML file( " + getDiffFile().getAbsolutePath() +
" ), exception( " + e.getMessage() + " )";
- log.error( msg, e );
+ LOGGER.error( msg, e );
// don't hide previous error
if ( caught == null ) {
caught = new SessionFailedException( msg, e );
@@ -323,14 +328,15 @@
return playbackSessionBean.getTestCount();
}
- private RecordSessionBean parseRecordFile( File recordFile ) throws SessionFailedException {
+ private RecordSessionBean parseRecordFile(File recordFile)
+ throws SessionFailedException {
+
RecordSessionBean sessionBean = null;
try {
sessionBean = XMLHelper.getRecordSessionBean( recordFile );
}
catch ( Exception e ) {
- String msg = "ERROR: failed parsing record file( " + recordFile + " ), exception( " + e.getMessage() +
- " )";
+ String msg = "Exception parsing record file(" + recordFile + "), exception(" + e.getMessage() +")";
error( msg, e );
}
return sessionBean;
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/State.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/State.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/State.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/State.java Thu Oct 27 13:42:00 2005
@@ -271,18 +271,22 @@
}
}
- public static PlaybackSession createPlaybackSession( String sessionName,
- File playbackFile, File recordFile, File diffFile )
+ public static PlaybackSession createPlaybackSession(String sessionName,
+ File playbackFile,
+ File recordFile,
+ File diffFile )
throws SessionFailedException {
- return new PlaybackSessionImpl( sessionName, playbackFile,
- recordFile, diffFile );
+ return new PlaybackSessionImpl( sessionName, playbackFile, recordFile, diffFile );
}
- public static RecordSession createRecordSession( String sessionName,
- File recordFile, boolean overwrite, String testUser,
- String description ) throws SessionFailedException {
- return new RecordSessionImpl( sessionName, recordFile,
- overwrite, testUser, description );
+ public static RecordSession createRecordSession(String sessionName,
+ File recordFile,
+ boolean overwrite,
+ String testUser,
+ String description)
+ throws SessionFailedException {
+
+ return new RecordSessionImpl(sessionName, recordFile, overwrite, testUser, description);
}
boolean addPlaybackSession( PlaybackSession session ) {
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java Thu Oct 27 13:42:00 2005
@@ -116,5 +116,4 @@
public static final String PASS = "pass";
public static final String FAIL = "fail";
public static final String ERROR= "ERROR";
-
}
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java Thu Oct 27 13:42:00 2005
@@ -54,7 +54,8 @@
_startDate = startDate;
}
- public void setStartDate( String date ) throws ParseException {
+ public void setStartDate(String date)
+ throws ParseException {
_startDate = DateHelper.getCalendarInstance(date);
}
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionXMLException.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionXMLException.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionXMLException.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionXMLException.java Thu Oct 27 13:42:00 2005
@@ -20,7 +20,7 @@
/**
*/
public class SessionXMLException
- extends Exception {
+ extends RuntimeException {
public SessionXMLException() {
super();
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java Thu Oct 27 13:42:00 2005
@@ -78,9 +78,8 @@
* @return the parsed Calendar instance
* @throws ParseException thrown when the dateString can't be parsed
*/
- public static final Calendar getCalendarInstance(String dateString)
- throws ParseException
- {
+ public static Calendar getCalendarInstance(String dateString)
+ throws ParseException {
assert dateString != null;
Calendar calendar = Calendar.getInstance(DEFAULT_LOCALE);
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java?rev=328947&r1=328946&r2=328947&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java Thu Oct 27 13:42:00 2005
@@ -24,7 +24,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
-import org.w3c.dom.Attr;
/**
* <p>This class exists simply because DOM is so inconvenient to use.</p>
@@ -35,25 +34,25 @@
private DomUtils() {}
/**
- * <p>Returns the first child element with the given name. Returns
+ * <p>Returns the first child element with the given localName. Returns
* <code>null</code> if not found.</p>
*
* @param parent parent element
- * @param name name of the child element
+ * @param localName localName of the child element
* @return child element
*/
- public static Element getChildElementByName(Element parent, String name)
- {
- NodeList children = parent.getChildNodes();
+ public static Element getChildElementByName(Element parent, String localName) {
+ return getChildElementByName(parent, null, localName);
+ }
+
+ public static Element getChildElementByName(Element parent, String namespace, String localName) {
+ NodeList children = null;
+ children = (namespace != null ? parent.getElementsByTagNameNS(namespace, localName) : parent.getElementsByTagName(localName));
for(int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
- if(node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element) node;
- if(element.getTagName().equals(name)) {
- return element;
- }
- }
+ if(node.getNodeType() == Node.ELEMENT_NODE)
+ return (Element)node;
}
return null;
@@ -65,24 +64,21 @@
* elements.</p>
*
* @param parent parent element
- * @param name name of the child element
+ * @param localName name of the child element
* @return child elements
*/
- public static List getChildElementsByName(Element parent, String name)
- {
- List elements = new ArrayList();
-
- NodeList children = parent.getChildNodes();
+ public static List getChildElementsByName(Element parent, String localName) {
+ return getChildElementsByName(parent, null, localName);
+ }
- for(int i = 0; i < children.getLength(); i++) {
- Node node = children.item(i);
- if(node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element) node;
- if(element.getTagName().equals(name)) {
- elements.add(element);
- }
- }
- }
+ public static List getChildElementsByName(Element parent, String namespace, String localName) {
+ NodeList children =
+ (namespace != null ? parent.getElementsByTagNameNS(namespace, localName) : parent.getElementsByTagName(localName));
+
+ ArrayList elements = new ArrayList(children.getLength());
+ for(int i = 0; i < children.getLength(); i++)
+ if(children.item(i).getNodeType() == Node.ELEMENT_NODE)
+ elements.add((Element)children.item(i));
return elements;
}
@@ -92,34 +88,28 @@
* <code>null</code> if there is no child element found.</p>
*
* @param parent parent element
- * @param name name of the child element
+ * @param localName name of the child element
* @return text value
*/
- public static String getChildElementText(Element parent, String name)
- {
- // Get children
- List list = DomUtils.getChildElementsByName(parent, name);
+ public static String getChildElementText(Element parent, String localName) {
+ return getChildElementText(parent, null, localName);
+ }
+ public static String getChildElementText(Element parent, String namespace, String localName) {
+ List list = DomUtils.getChildElementsByName(parent, namespace, localName);
if(list.size() == 1) {
Element child = (Element) list.get(0);
-
StringBuffer buf = new StringBuffer();
-
NodeList children = child.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
- if(node.getNodeType() == Node.TEXT_NODE ||
- node.getNodeType() == Node.CDATA_SECTION_NODE) {
- Text text = (Text) node;
- buf.append(text.getData().trim());
+ if(node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
+ buf.append(((Text)node).getData());
}
}
-
return buf.toString();
}
- else {
- return null;
- }
+ else return null;
}
/**
@@ -129,75 +119,17 @@
* @param element element
* @return text value
*/
- public static String getElementText(Element element)
- {
+ public static String getElementText(Element element) {
StringBuffer buf = new StringBuffer();
NodeList children = element.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
- if(node.getNodeType() == Node.TEXT_NODE ||
- node.getNodeType() == Node.CDATA_SECTION_NODE) {
- Text text = (Text) node;
- buf.append(text.getData().trim());
+ if(node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
+ buf.append(((Text)node).getData());
}
}
return buf.toString();
- }
-
- /**
- * <p>Returns an array of text values of a child element. Returns
- * <code>null</code> if there is no child element found.</p>
- *
- * @param parent parent element
- * @param name name of the child element
- * @return text value
- */
- public static String[] getChildElementTextArr(Element parent, String name)
- {
- // Get all the elements
- List children = getChildElementsByName(parent, name);
-
- String str[] = new String[children.size()];
-
- for(int i = 0; i < children.size(); i++) {
- Node child = (Node) children.get(i);
-
- StringBuffer buf = new StringBuffer();
-
- NodeList nodes = child.getChildNodes();
- for(int j = 0; j < nodes.getLength(); j++) {
- Node node = nodes.item(j);
- if(node.getNodeType() == Node.TEXT_NODE ||
- node.getNodeType() == Node.CDATA_SECTION_NODE) {
- Text text = (Text) node;
- buf.append(text.getData().trim());
- }
- }
-
- str[i] = buf.toString();
- }
-
- return str;
- }
-
- /**
- * <p>Retutns the value of the named attribute of the given
- * element. If there is no such attribute, returns null.</p>
- *
- * @param element element
- * @param name name
- * @return value
- */
- public static String getAttributeValue(Element element, String name)
- {
- Attr attribute = element.getAttributeNode(name);
- if(attribute == null) {
- return null;
- }
- else {
- return attribute.getValue();
- }
}
}