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/24 19:24:00 UTC

svn commit: r328096 [1/2] - in /beehive/trunk/netui: src/testRecorder/ src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/ src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ src/testRecorder/org/apache/beehive/n...

Author: ekoneil
Date: Mon Oct 24 10:23:45 2005
New Revision: 328096

URL: http://svn.apache.org/viewcvs?rev=328096&view=rev
Log:
Start decoupling the test recorder from XMLBeans.

BB: self
Test: NetUI pass


Added:
    beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/
    beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java   (with props)
    beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java   (with props)
Modified:
    beehive/trunk/netui/src/testRecorder/build.xml
    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/PlaybackSessionBean.java
    beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/RecordSessionBean.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/Util.java
    beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
    beehive/trunk/netui/test/ant/build.xml

Modified: beehive/trunk/netui/src/testRecorder/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/build.xml?rev=328096&r1=328095&r2=328096&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/build.xml (original)
+++ beehive/trunk/netui/src/testRecorder/build.xml Mon Oct 24 10:23:45 2005
@@ -42,13 +42,13 @@
                <include name="**/*.java"/>
         </javac>
 
-        <!-- make testRecorder output directory -->
-        <mkdir dir="${testRecorder.dir}"/>
-        <copy todir="${testRecorder.dir}/jsp">
-            <fileset dir="${module.dir}/jsp"/>
+        <copy todir="${module.classes.dir}/org/apache/beehive/netui/tools/testrecorder/shared/schemas">
+            <fileset dir="${module.dir}/schema"/>
         </copy>
-        <copy-junit todir="${testRecorder.dir}/lib"/>
-        <copy-testrecorder-deps todir="${testRecorder.dir}"/>
+
+        <mkdir dir="${testRecorder.dir}"/>
+        <mkdir dir="${testRecorder.dir}/lib"/>
+
         <jar jarfile="${module.jar}" basedir="${module.classes.dir}">
             <manifest>
                 <attribute name="Extension-Name" value="Beehive NetUI Test Recorder"/>
@@ -61,11 +61,19 @@
                 <attribute name="Beehive-Version" value="${beehive.version}"/>
             </manifest>
         </jar>
+
+        <!-- make testRecorder output directory -->
+        <copy todir="${testRecorder.dir}/jsp">
+            <fileset dir="${module.dir}/jsp"/>
+        </copy>
+
+        <copy-junit todir="${testRecorder.dir}/lib"/>
+        <copy-testrecorder-deps todir="${testRecorder.dir}"/>
     </target>
 
     <target name="clean">
         <delete dir="${module.classes.dir}"/>
-        <delete file="${module.jar}" failonerror="false"/>
+        <delete dir="${testRecorder.dir}"/>
     </target>
 
 </project>

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=328096&r1=328095&r2=328096&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 Mon Oct 24 10:23:45 2005
@@ -15,21 +15,27 @@
  *
  * $Header:$
  */
-
 package org.apache.beehive.netui.tools.testrecorder.shared;
 
 /**
- * User: ozzy
- * Date: Mar 20, 2003
- * Time: 4:00:54 PM
+ *
  */
-public class Constants {
+public final class Constants {
 
-    // files in the classpath obtained via the classloader
+    /* files in the classpath obtained via the classloader */
     public static String CONFIG_FILE = "testRecorder-config.xml";
     public static String TESTS_FILE = "testRecorder-tests.xml";
     public static String WEBAPPS_FILE = "testRecorder-webapp.xml";
     public static String SERVER_FILE = "testRecorder-server.xml";
+
+    public static String SCHEMA_LOCATION = "org/apache/beehive/netui/tools/testrecorder/shared/schemas";
+
+    public static String CONFIG_SCHEMA_NAME = "testRecorderDefaultConfig.xsd";
+    public static String DIFF_SESSION_SCHEMA_NAME = "testRecorderDiffSession.xsd";
+    public static String SERVER_SCHEMA_NAME = "testRecorderServer.xsd";
+    public static String SESSION_SCHEMA_NAME = "testRecorderSession.xsd";
+    public static String TESTS_SCHEMA_NAME = "testRecorderTests.xsd";
+    public static String WEBAPPS_SCHEMA_NAME = "testRecorderWebapps.xsd";
 
     public static String FILE_TYPE_CONFIG = "config";
     public static String FILE_TYPE_WEBAPP = "webapp";

Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/PlaybackSessionBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/PlaybackSessionBean.java?rev=328096&r1=328095&r2=328096&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/PlaybackSessionBean.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/PlaybackSessionBean.java Mon Oct 24 10:23:45 2005
@@ -23,118 +23,106 @@
 import java.util.Collections;
 
 /**
- * User: ozzy
- * Date: Jun 15, 2004
- * Time: 9:19:12 AM
+ *
  */
-public class PlaybackSessionBean extends RecordSessionBean {
+public class PlaybackSessionBean
+    extends RecordSessionBean {
 
-    private static final Logger log = Logger.getInstance( PlaybackSessionBean.class );
+    private static final Logger LOGGER = Logger.getInstance(PlaybackSessionBean.class);
 
-    private int recordedTestCount = -1;
-    private int passedCount = 0;
-    private int failedCount = 0;
-    private List testResults;
+    private int _recordedTestCount = -1;
+    private int _passedCount = 0;
+    private int _failedCount = 0;
+    private List _testResults;
 
-    public PlaybackSessionBean( String sessionName ) {
-        this( sessionName, false );
+    public PlaybackSessionBean(String sessionName) {
+        this(sessionName, false);
     }
 
-    public PlaybackSessionBean( String sessionName, boolean error ) {
-        super( sessionName );
-        setError( error );
-        testResults = new ArrayList();
+    public PlaybackSessionBean(String sessionName, boolean error) {
+        super(sessionName);
+        setError(error);
+        _testResults = new ArrayList();
     }
 
     public int getRecordedTestCount() {
-        return recordedTestCount;
+        return _recordedTestCount;
     }
 
-    public void setRecordedTestCount( int recordedTestCount ) {
-        this.recordedTestCount = recordedTestCount;
+    public void setRecordedTestCount(int recordedTestCount) {
+        _recordedTestCount = recordedTestCount;
     }
 
     public int getTestCount() {
-        return testResults.size();
+        return _testResults.size();
     }
 
-    public TestResults getTestResults( int index ) {
-        return (TestResults) testResults.get( index );
+    public TestResults getTestResults(int index) {
+        return (TestResults) _testResults.get(index);
     }
 
     public List getTestResults() {
-        return Collections.unmodifiableList( testResults );
+        return Collections.unmodifiableList(_testResults);
     }
 
-    public void addTestResults( TestResults results ) {
-        if ( results.isTestPassed() ) {
+    public void addTestResults(TestResults results) {
+        if (results.isTestPassed()) {
             incrementPassedCount();
         }
         else {
             incrementFailedCount();
         }
-        testResults.add( results );
+        _testResults.add(results);
     }
 
     public boolean isError() {
-        if ( error ) {
-            return error;
-        }
-        return isErrorInternal();
+        return _error ? _error : isErrorInternal();
     }
 
     private boolean isErrorInternal() {
         boolean rtnVal = false;
-        if ( getRecordedTestCount() < 1 ) {
-            if ( log.isDebugEnabled() ) {
-                log.debug( "Invalid recorded test count(" + getRecordedTestCount() + ")" );
-            }
+        if (getRecordedTestCount() < 1) {
+            LOGGER.debug("Invalid recorded test count(" + getRecordedTestCount() + ")");
             rtnVal = true;
         }
-        else if ( ( getTestCount() ) != getRecordedTestCount() ) {
-            if ( log.isDebugEnabled() ) {
-                log.debug( "executed count(" + getTestCount() + ") does not equal recorded test count(" +
-                        getRecordedTestCount() + ")" );
-            }
+        else if ((getTestCount()) != getRecordedTestCount()) {
+            LOGGER.debug("executed count(" + getTestCount() + ") does not equal recorded test count(" + getRecordedTestCount() + ")");
             rtnVal = true;
         }
         return rtnVal;
     }
 
     public String getStatus() {
-        if ( isError() ) {
+        if (isError()) {
             return Constants.ERROR;
         }
-        if ( isSessionPassed() ) {
+        if (isSessionPassed()) {
             return Constants.PASS;
         }
         return Constants.FAIL;
     }
 
     public boolean isSessionPassed() {
-        if ( isError() ) {
-            return false;
-        }
-        if ( passedCount != getRecordedTestCount() ) {
+        if (isError())
             return false;
-        }
-        return true;
+        
+        return _passedCount == getRecordedTestCount();
     }
 
     public int incrementPassedCount() {
-        return ++passedCount;
+        return ++_passedCount;
     }
 
     public int getPassedCount() {
-        return passedCount;
+        return _passedCount;
     }
 
     public int incrementFailedCount() {
-        return ++failedCount;
+        return ++_failedCount;
     }
 
     public int getFailedCount() {
-        return failedCount;
+        return _failedCount;
     }
 
 }

Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/RecordSessionBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/RecordSessionBean.java?rev=328096&r1=328095&r2=328096&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/RecordSessionBean.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/RecordSessionBean.java Mon Oct 24 10:23:45 2005
@@ -24,48 +24,44 @@
 
 /**
  */
-public class RecordSessionBean extends SessionBean {
+public class RecordSessionBean
+    extends SessionBean {
 
-    private List requestData;
-    private List responseData;
-    // if true indicates an error has occured in the session
-    protected boolean error = false;
+    private List _requestData;
+    private List _responseData;
 
-    public RecordSessionBean( String sessionName ) {
-        this.sessionName = sessionName;
-        requestData = new ArrayList();
-        responseData = new ArrayList();
-    }
+    // if true indicates an error has occured in the session
+    protected boolean _error = false;
 
-    public void setError() {
-        error = true;
+    public RecordSessionBean(String sessionName) {
+        _sessionName = sessionName;
+        _requestData = new ArrayList();
+        _responseData = new ArrayList();
     }
 
-    public void setError( boolean error ) {
-        this.error = error;
+    public void setError(boolean error) {
+        _error = error;
     }
 
     public boolean isError() {
-        return error;
+        return _error;
     }
 
-
     public List getRequestData() {
-        return Collections.unmodifiableList( requestData );
+        return Collections.unmodifiableList(_requestData);
     }
 
     /**
-     *
      * @param index
      * @return
      * @throws IndexOutOfBoundsException
      */
-    public RequestData getRequestData( int index ) {
-        return (RequestData) requestData.get( index );
+    public RequestData getRequestData(int index) {
+        return (RequestData) _requestData.get(index);
     }
 
     public List getResponseData() {
-        return Collections.unmodifiableList( responseData );
+        return Collections.unmodifiableList(_responseData);
     }
 
     /**
@@ -73,42 +69,43 @@
      * @return
      * @throws IndexOutOfBoundsException
      */
-    public ResponseData getResponseData( int index ) {
-        return (ResponseData) responseData.get( index );
+    public ResponseData getResponseData(int index) {
+        return (ResponseData) _responseData.get(index);
     }
 
-    public void addRequestResponseData( RequestData request, ResponseData response ) {
-        requestData.add( request );
-        responseData.add( response );
+    public void addRequestResponseData(RequestData request, ResponseData response) {
+        _requestData.add(request);
+        _responseData.add(response);
     }
 
     /**
      * update the data for the most recent test
+     *
      * @param request
      * @param response
      */
-    public void updateRequestResponseData( RequestData request, ResponseData response ) {
-        if ( requestData.size() == 0 || responseData.size() == 0 ) {
-            throw new IllegalStateException( "data size is zero, unable to update");
+    public void updateRequestResponseData(RequestData request, ResponseData response) {
+        if (_requestData.size() == 0 || _responseData.size() == 0) {
+            throw new IllegalStateException("data size is zero, unable to update");
         }
-        requestData.set( requestData.size() -1, request );
-        responseData.add( responseData.size() -1, response );
+        _requestData.set(_requestData.size() - 1, request);
+        _responseData.add(_responseData.size() - 1, response);
     }
 
     public int getTestCount() {
-        return requestData.size();
+        return _requestData.size();
     }
 
     public String toString() {
-        StringBuffer sb = new StringBuffer( 256 );
-        sb.append( "[ " );
-        sb.append( "sessionName( " + getSessionName() + " )" );
-        sb.append( ", tester( " + getTester() + " )" );
-        sb.append( ", startDate( " + getStartDateString() + " )" );
-        sb.append( ", endDate( " + getEndDateString() + " )" );
-        sb.append( ", testCount( " + getTestCount() + " )" );
-        sb.append( ", description( " + getDescription() + " )" );
-        sb.append( " ]" );
+        StringBuffer sb = new StringBuffer(256);
+        sb.append("[ ");
+        sb.append("sessionName( " + getSessionName() + " )");
+        sb.append(", tester( " + getTester() + " )");
+        sb.append(", startDate( " + getStartDateString() + " )");
+        sb.append(", endDate( " + getEndDateString() + " )");
+        sb.append(", testCount( " + getTestCount() + " )");
+        sb.append(", description( " + getDescription() + " )");
+        sb.append(" ]");
         return sb.toString();
     }
 

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=328096&r1=328095&r2=328096&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 Mon Oct 24 10:23:45 2005
@@ -18,46 +18,44 @@
 
 package org.apache.beehive.netui.tools.testrecorder.shared;
 
-import org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper;
-
 import java.util.Calendar;
 import java.text.ParseException;
 
+import org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper;
+
 /**
- * User: ozzy
- * Date: Jun 20, 2004
- * Time: 10:23:02 AM
+ *
  */
 public class SessionBean {
 
-    protected String sessionName;
-    private String tester;
-    private Calendar startDate;
-    private Calendar endDate;
-    private String description;
+    protected String _sessionName;
+    private String _tester;
+    private Calendar _startDate;
+    private Calendar _endDate;
+    private String _description;
 
     public String getSessionName() {
-        return sessionName;
+        return _sessionName;
     }
 
     public String getTester() {
-        return tester;
+        return _tester;
     }
 
     public void setTester( String tester ) {
-        this.tester = tester;
+        _tester = tester;
     }
 
     protected Calendar getStartDate() {
-        return startDate;
+        return _startDate;
     }
 
     public void setStartDate( Calendar startDate ) {
-        this.startDate = startDate;
+        _startDate = startDate;
     }
 
     public void setStartDate( String date ) throws ParseException {
-        startDate = DateHelper.getCalendarInstance(date);
+        _startDate = DateHelper.getCalendarInstance(date);
     }
 
     public String getStartDateString() {
@@ -68,15 +66,15 @@
     }
 
     protected Calendar getEndDate() {
-        return endDate;
+        return _endDate;
     }
 
     public void setEndDate( Calendar endDate ) {
-        this.endDate = endDate;
+        _endDate = endDate;
     }
 
     public void setEndDate( String date ) throws ParseException {
-        endDate = DateHelper.getCalendarInstance(date);
+        _endDate = DateHelper.getCalendarInstance(date);
     }
 
     public String getEndDateString() {
@@ -87,11 +85,11 @@
     }
 
     public String getDescription() {
-        return description;
+        return _description;
     }
 
     public void setDescription( String description ) {
-        this.description = description;
+        _description = description;
     }
 
 }

Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Util.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Util.java?rev=328096&r1=328095&r2=328096&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Util.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Util.java Mon Oct 24 10:23:45 2005
@@ -18,23 +18,26 @@
 
 package org.apache.beehive.netui.tools.testrecorder.shared;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpSession;
 import java.util.Iterator;
-import java.util.Enumeration;
+//import java.util.Enumeration;
 import java.util.Map;
 import java.util.Set;
 import java.util.List;
 import java.util.ArrayList;
 
-public class Util {
+public final class Util {
 
+/*
     static final int REPORT_SESSION = 0;
     static final int REPORT_REQUEST = 1;
-
+*/
+/*
     private static final String LT = "<";
     private static final String LT_END = "</";
     private static final String GT = ">";
+*/
 
     private Util() {
     }
@@ -119,7 +122,7 @@
         sb.append( " ]" );
         return sb.toString();
     }
-
+/*
     public static final String genStartTag( final String tagName ) {
         return LT + tagName + GT;
     }
@@ -130,23 +133,31 @@
         }
         return LT + tagName + " " + attributes + GT;
     }
-
+*/
+/*
     public static final String genEndTag( final String tagName ) {
         return LT_END + tagName + GT;
     }
-
+*/
+/*
     public static StringBuffer reportSessionAttributes( StringBuffer sb,
             HttpServletRequest request, String id, String separator ) {
         return reportAttributes( sb, request, id, separator, REPORT_SESSION );
     }
+*/
 
+/*
     public static StringBuffer reportRequestAttributes( StringBuffer sb,
             HttpServletRequest request, String id, String separator ) {
         return reportAttributes( sb, request, id, separator, REPORT_REQUEST );
     }
-
+*/
+/*
     static StringBuffer reportAttributes( StringBuffer sb,
-            HttpServletRequest request, String id, String separator, int type ) {
+                                          HttpServletRequest request,
+                                          String id,
+                                          String separator,
+                                          int type ) {
         HttpSession session = request.getSession();
         Enumeration e = session.getAttributeNames();
         String key = null;
@@ -167,12 +178,13 @@
         }
         return sb;
     }
-
+*/
+/*
     public static StringBuffer reportAttribute( StringBuffer sb, String key,
             Object value, String id, String separator ) {
         sb.append( id + " [ key( " + key + " ), value(" + value.getClass().getName() + ")( " +
                 value + " ) ]" + separator );
         return sb;
     }
-
+*/
 }

Added: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java?rev=328096&view=auto
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java (added)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java Mon Oct 24 10:23:45 2005
@@ -0,0 +1,54 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Header:$
+ */
+package org.apache.beehive.netui.tools.testrecorder.shared.beans;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class ConfigBean {
+
+    private String _servletUri = null;
+    private String _baseDirectory = null;
+    private List _suffixList = null;
+
+    public String getServletUri() {
+        return _servletUri;
+    }
+
+    public void setServletUri(String servletUri) {
+        _servletUri = servletUri;
+    }
+
+    public String getBaseDirectory() {
+        return _baseDirectory;
+    }
+
+    public void setBaseDirectory(String baseDirectory) {
+        _baseDirectory = baseDirectory;
+    }
+
+    public List getSuffixList() {
+        return _suffixList;
+    }
+
+    public void setSuffixList(List suffixList) {
+        _suffixList = suffixList;
+    }
+}

Propchange: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/beans/ConfigBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=328096&view=auto
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java (added)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java Mon Oct 24 10:23:45 2005
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.tools.testrecorder.shared.util;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.w3c.dom.Node;
+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>
+ */
+public final class DomUtils {
+
+    /* do not construct */
+    private DomUtils() {}
+
+    /**
+     * <p>Returns the first child element with the given name. Returns
+     * <code>null</code> if not found.</p>
+     *
+     * @param parent parent element
+     * @param name name of the child element
+     * @return child element
+     */
+    public static Element getChildElementByName(Element parent, String name)
+    {
+        NodeList children = parent.getChildNodes();
+
+        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;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * <p>Returns a list of child elements with the given
+     * name. Returns an empty list if there are no such child
+     * elements.</p>
+     *
+     * @param parent parent element
+     * @param name name of the child element
+     * @return child elements
+     */
+    public static List getChildElementsByName(Element parent, String name)
+    {
+        List elements = new ArrayList();
+
+        NodeList children = parent.getChildNodes();
+
+        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);
+                }
+            }
+        }
+
+        return elements;
+    }
+
+    /**
+     * <p>Returns the text value 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 getChildElementText(Element parent, String name)
+    {
+        // Get children
+        List list = DomUtils.getChildElementsByName(parent, name);
+
+        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());
+                }
+            }
+
+            return buf.toString();
+        }
+        else {
+            return null;
+        }
+    }
+
+    /**
+     * <p>Returns the text value of a child element. Returns
+     * <code>null</code> if there is no child element found.</p>
+     *
+     * @param element element
+     * @return text value
+     */
+    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());
+            }
+        }
+
+        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();
+        }
+    }
+}

Propchange: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DomUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native