jakarta-ecs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-ecs/test/java/org/apache/ecs BasicECSComparitor.java ECSFlatteningWalker.java HTMLToken.java HTMLTokenizer.java InternationalCharTest.java icechar.txt
Date Wed, 25 Jul 2001 23:06:58 GMT
rdonkin     01/07/25 16:06:58

  Modified:    build    build-ecs.xml
               docs/apidocs .cvsignore
  Added:       build    ant-1.3.1.jar testcases.xml
               lib      jakarta-ant-1.3-optional.jar junit-3.2.jar
               test/java/org/apache/ecs BasicECSComparitor.java
                        ECSFlatteningWalker.java HTMLToken.java
                        HTMLTokenizer.java InternationalCharTest.java
                        icechar.txt
  Removed:     build    ant-1.2.jar
  Log:
  added junit testing framework and test for international character bug
  
  Revision  Changes    Path
  1.19      +5 -0      jakarta-ecs/build/build-ecs.xml
  
  Index: build-ecs.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/build/build-ecs.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- build-ecs.xml	2001/01/09 17:51:50	1.18
  +++ build-ecs.xml	2001/07/25 23:06:58	1.19
  @@ -217,4 +217,9 @@
           </copy>
       </target>
   
  +    <target name="test-ecs" depends="jar">
  +        <ant antfile="testcases.xml" target="everything">
  +            <property name="ecs.jar" value="${build.dir}/${final.name}.jar"/>
  +        </ant>
  +    </target>
   </project>
  
  
  
  1.1                  jakarta-ecs/build/ant-1.3.1.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ecs/build/testcases.xml
  
  Index: testcases.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- Testcases for ECS -->
  <!-- The basic ecs-build does not build test classes -->
  <!-- So we must build these before running our tests -->
  <project name="test-ecs" default="everything">
  
      <!-- Calling scripts should overide this -->
      <property name="ecs.jar" value="ecs.jar"/>
  
      <!-- Calling scripts might like to overide -->
      <property name="build.compiler" value="classic"/>
      <property name="build.dir" value="../bin"/>
      <property name="debug" value="off"/>
      <property name="optimize" value="on"/>
      <property name="deprecation" value="off"/>
      
      
      <!-- Calling script probably shouldn't be overriding these -->
      <property name="test.base" value="../test/java"/>
      <property name="test.build.dir" value="${build.dir}/test"/>
      <property name="test.build.jar" value="${build.dir}/ecs-test.jar"/>
      <property name="test.build.src" value="${test.build.dir}/src" />
      <property name="test.build.dest" value="${test.build.dir}/classes" />
  
  
      <path id="classpath">
          <fileset dir="../lib">
              <include name="**/*.jar"/>
          </fileset>
          <pathelement location="${test.build.jar}"/>
          <pathelement location="${ecs.jar}"/>
      </path>
      
  
      <!-- Copy java files over -->
      <target name="copy-test">
          <mkdir dir="${test.build.src}"/>
          <mkdir dir="${test.build.dest}"/>
          <copy toDir="${test.build.src}">
               <fileset dir="${test.base}"/>
          </copy>
      </target >
      
       <!-- Compile test classes -->
      <target name="compile-test" depends="copy-test">
          <javac srcdir="${test.build.src}"
              destdir="${test.build.dest}"
              excludes="**/package.html"
              debug="${debug}"
              deprecation="${deprecation}"
              optimize="${optimize}">
  
              <classpath refid="classpath"/>
          </javac>
          
          <copy todir="${test.build.dest}/org" filtering="yes">
              <fileset dir="${test.build.src}/org">
                  <include name="**/*.txt"/>
              </fileset>
          </copy>
      </target>  
      
      <!-- Create ecs-test jar -->
      <target name="jar-test" depends="compile-test">
          <jar jarfile="${test.build.jar}"
              basedir="${test.build.dest}"
              excludes="**/package.html"
          />    
      </target>
      
      <target name="test-int-chars" depends="jar-test">
          <echo message="testing international characters"/>
          <junit printsummary="no" haltonfailure="yes" fork="false">
              <classpath refid="classpath"/>
              <formatter type="plain" usefile="false" />
              <test name="org.apache.ecs.InternationalCharTest" />
          </junit>
      </target>
  
      <target name="test-all" depends="
                                  jar-test,
                                  test-int-chars">
          <echo message="Completed tests"/>
      </target>
  
      <target name="everything" depends="test-all"/>
  
  </project>
  
  
  
  1.3       +1 -0      jakarta-ecs/docs/apidocs/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/docs/apidocs/.cvsignore,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- .cvsignore	2001/03/19 23:00:22	1.2
  +++ .cvsignore	2001/07/25 23:06:58	1.3
  @@ -0,0 +1 @@
  +*
  
  
  
  1.1                  jakarta-ecs/lib/jakarta-ant-1.3-optional.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ecs/lib/junit-3.2.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/BasicECSComparitor.java
  
  Index: BasicECSComparitor.java
  ===================================================================
  /*
   * Copyright (c) 1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *
   * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called 
   *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
   *    in their names without prior written permission of the 
   *    Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Project. For more information
   * on the Java Apache Project please see <http://java.apache.org/>.
   *
   */
  
  
  package org.apache.ecs;
  
  import java.util.*;
  
  import org.apache.ecs.html.*;
  
  /**
   * <p> Compares an ecs element to a string.
   *
   * <p> The HTMLTokenizer is used to tokenize the string.
   * A walker then walks the ECS tree comparing the element type 
   * of each element to the tokens produced by the tokenizer.
   * 
   * <p> This makes only the most basic check ie. that the flattened order of the element
   * is equivalent. The flattened order ignores the tree structure. 
   * For example, the following are equivalent according to flattened order:
   * <pre><code>
   *	<ul><li>Item. <strong>This is a line.</strong></li></ul>
   *	<ul><li>Item. </li></ul><strong>This is a line.</strong>
   * </code></pre>
   */
  
  public class BasicECSComparitor 
  {
      public static void main(String [] args)
      {
          Document doc=new Document();
          doc.setDoctype(new Doctype.Html40Strict());
          doc.setTitle(new Title("The Title"));
          doc.appendBody(new Comment("This is a comment"));
          doc.appendBody(new HR());
          doc.appendBody("This is the body");
          doc.appendBody(new HR());
  
          String test="<?xml version=\"1.0\"?><!DOCTYPE HTML PUBLIC \"-//W3C//DTD
HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>The
Title</title></head><body><!--This is a comment--><hr/>This
is the body<hr/></body></html>";
      
          BasicECSComparitor comp=new BasicECSComparitor();
          System.out.println();
          System.out.println("EQUIVALENT? " + comp.compare(doc.getHtml(),test));
      
      }
          
  
      private boolean silent=true;
  
      public BasicECSComparitor() {}
      
      public BasicECSComparitor(boolean isSilent) 
      {}
      
      public boolean isSilent()
      {
          return silent;
      }
                  
      public void isSilent(boolean silent)
      {
          this.silent=silent;
      }
              
      public boolean compare(Element e,String s)
      {
          ECSFlatteningWalker walker=new ECSFlatteningWalker(e);
          HTMLTokenizer tokens=new HTMLTokenizer(s);
          
          int atECS=0;
          int atTokens=0;
          
          while (atECS<walker.getElementList().size())
          {
              if (!silent)
              {
                  System.out.println(
                      atTokens + "(" + tokens.getTokens().size() + ")" + ":" + 
                      atECS + "(" + walker.getElementList().size() + ")");
              }
                  
              if (atTokens>=tokens.getTokens().size())
              {
                  System.out.println("[DIFFERENCE] Too few tokens.");
                  return false;
              }
              
              HTMLToken token=(HTMLToken)tokens.getTokens().get(atTokens++);
              if (!silent)
              {
                  System.out.println("[TOKEN]" + token);
              }
              
              if (token.isProcessingInstruction() || token.isDeclaration())
              {
                  if (!silent)
                  {
                      System.out.println("Ignoring " + token);
                  }
                  
              } else if (token.isEndTag() && !token.isStartTag()) {
                  if (!silent)
                  {
                      System.out.println("End tag " + token);
                  }
              
              } else {
                  ConcreteElement element=(ConcreteElement)walker.getElementList().get(atECS++);
                  if (!silent)
                  {
                      System.out.println("[ELEMENT]" + element.getClass());
                  }
                  
                  if (element instanceof Comment)
                  {
                      if (!token.isComment())
                      {
                          System.out.println("[DIFFERENCE] Missing Comment");
                          return false;
                      }
                      if (walker.getElementList().get(atECS) instanceof StringElement)
                          atECS++;
                          
                  } else if (element instanceof StringElement)
                  {
                      if (!token.isText())
                      {
                          System.out.println("[DIFFERENCE] Missing Text");
                          return false;
                      }
                  } else {
                      if (!element.getElementType().equalsIgnoreCase(token.getTokenName()))
                      {
                          System.out.println("[DIFFERENCE] Element type mismatch.");
                          return false;
                      }
                  }
              }
          }
  
          // All remaining tokens must be simple end tags
          for (int i=atTokens;i<tokens.getTokens().size();i++)
          {
              HTMLToken token=(HTMLToken)tokens.getTokens().get(i);
              if (!token.isEndTag())
              {
                  System.out.println("[DIFFERENCE] Too many tokens.");
                  return false;
              }
              if (token.isStartTag())
              {
                  System.out.println("[DIFFERENCE] Too many tokens.");
                  return false;
              }
          }
          
          return true;
      }
  }
  
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/ECSFlatteningWalker.java
  
  Index: ECSFlatteningWalker.java
  ===================================================================
  /*
   * Copyright (c) 1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *
   * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called 
   *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
   *    in their names without prior written permission of the 
   *    Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Project. For more information
   * on the Java Apache Project please see <http://java.apache.org/>.
   *
   */
  
  
  package org.apache.ecs;
  
  import java.util.*;
  
  import org.apache.ecs.html.*;
  
  public class ECSFlatteningWalker 
  {
      public static void main(String args[])
      {
          Document doc=new Document();
          doc.setDoctype(new Doctype.Html40Strict());
          doc.setTitle(new Title("The Title"));
          doc.appendBody(new Comment("This is a comment"));
          doc.appendBody(new HR());
          doc.appendBody("This is the body");
          doc.appendBody(new HR());
  
          ECSFlatteningWalker walker= new ECSFlatteningWalker(doc.getHtml());
          walker.printTest();
      
      }
  
  
  
      private List elements;
      
      
      public ECSFlatteningWalker() {}
      
      
      public ECSFlatteningWalker(Element e)
      {
          flatten(e);
      }
      
      
      public List getElementList()
      {	
          return elements;
      }
          
      public void clearElementList()
      {
          elements=new ArrayList();
      }
      
      public void flatten(Element e)
      {
          clearElementList();
          add(e);
      }
      
      protected void add(Element e)
      {
          elements.add(e);
          
          if (e instanceof ConcreteElement)
          {
              ConcreteElement ce=(ConcreteElement)e;
              for (Enumeration en=ce.keys();en.hasMoreElements();)
              {
                  add(ce.getElement((String)en.nextElement()));
              }
          }
      }
  
  
      public void printTest()
      {
          System.out.println();
          System.out.println();
          for (Iterator it=elements.iterator();it.hasNext();)
          {
              Object n=it.next();
              
              System.out.println(n.getClass());
              System.out.println(n);
              System.out.println(((ConcreteElement)n).getElementType());
          }
      }
  }
  
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/HTMLToken.java
  
  Index: HTMLToken.java
  ===================================================================
  /*
   * Copyright (c) 1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *
   * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called 
   *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
   *    in their names without prior written permission of the 
   *    Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Project. For more information
   * on the Java Apache Project please see <http://java.apache.org/>.
   *
   */
  
  
  package org.apache.ecs;
  
  
  
  /**
   * <p> Tokenizer - not a parser! - for HTML
   *
   * <p> This is a tokenizer not a parser.
   */
  public class HTMLToken
  {
      private String content;
      private String tokenName;
      private boolean text=false;
      private boolean endTag=false;
      private boolean startTag=false;
      private boolean comment=false;
      /** is processing instruction */
      private boolean pi=false;
      /** is declaration */
      private boolean decl=false;
      
      public HTMLToken(String content)
      {
          setTokenContent(content);
      }
      
      protected void setTokenContent(String tokenContent)
      {
          if (tokenContent.startsWith(">"))
          {
          
              this.content=tokenContent.substring(1);
              text=true;
              endTag=false;
              startTag=false;
              
          } else if (tokenContent.startsWith("</"))
          {
          
              this.content=tokenContent.substring(2).trim();
              text=false;
              endTag=true;
              startTag=false;
              tokenName=content;
           } else if (tokenContent.startsWith("<?"))
          {
          
              this.content=tokenContent.substring(2,tokenContent.length()-1).trim();
              pi=true;
              tokenName=getFirstWord(content);
                         
          } else if (tokenContent.startsWith("<!--"))
          {
          
              this.content=tokenContent.substring(4,tokenContent.length()-2).trim();
              comment=true;
  
          } else if (tokenContent.startsWith("<!"))
          {
          
              this.content=tokenContent.substring(2).trim();
              decl=true;
              tokenName=getFirstWord(content);
              
          } else if (tokenContent.startsWith("<"))
          {
              if (tokenContent.endsWith("/"))
              {
                  this.content=tokenContent.substring(1,tokenContent.length()-1).trim();
                  text=false;
                  endTag=true;
                  startTag=true;            
              } else {
                  this.content=tokenContent.substring(1).trim();
                  text=false;
                  endTag=false;
                  startTag=true;
              }
              
              tokenName=getFirstWord(content);
  
          } else {        
              System.out.println("Bad token!");
              this.content=tokenContent;
          }
      }
              
      private String getFirstWord(String phrase)
      {
          int at=content.indexOf(' ');
          if (at==-1)
          {
              return phrase;
          } else 
          {
              return phrase.substring(0,at);
          }            
      }
      
      public String getTokenContent()
      {	
          return content;
      }
      
      public String getTokenName()
      {
          return tokenName;
      }
      
      public boolean isDeclaration()
      {
          return decl;
      }
      
      public boolean isProcessingInstruction()
      {
          return pi;
      }
      
      public boolean isText()
      {
          return text;
      }
      
      public boolean isEndTag()
      {
          return endTag;
      }
      
      public boolean isStartTag()
      {
          return startTag;
      }
      
      public boolean isComment()
      {
          return comment;
      }
      
      
      public String toString()
      {
          String tokType="[UNK]";
          if (isComment())
          {
              tokType="[COMMENT]";
          } else if (isProcessingInstruction())
          {
              tokType="[PI]";
          } else if (isDeclaration())
          {
              tokType="[DECL]";
          } else if (isStartTag())
          {
              if (isEndTag())
              {
                  tokType="[START-END]";
              } else {
                  tokType="[START]";
              }
              
          } else if (isEndTag())
          {
              tokType="[END]";
          } else if (isText())
          {
              tokType="[TEXT]";
          }
          
          if (tokenName!=null)
          {
              tokType=tokType+"(" + tokenName + ")";
          }
          return tokType + getTokenContent();
      }
  }
  
  
  
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/HTMLTokenizer.java
  
  Index: HTMLTokenizer.java
  ===================================================================
  /*
   * Copyright (c) 1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *
   * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called 
   *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
   *    in their names without prior written permission of the 
   *    Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Project. For more information
   * on the Java Apache Project please see <http://java.apache.org/>.
   *
   */
  
  
  package org.apache.ecs;
  
  import java.util.*;
  
  /**
   * <p> Tokenizer - not a parser! - for HTML
   *
   * <p> This is a tokenizer not a parser.
   */
  public class HTMLTokenizer 
  {
      public static void main(String [] args)
      {
          String test="<?xml version=\"1.0\"?><!DOCTYPE HTML PUBLIC \"-//W3C//DTD
HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>The
Title</title></head><body><!--This is a comment--><hr/>This
is the body<hr/></body></html>";
          System.out.println(test);
          HTMLTokenizer ht=new HTMLTokenizer(test);
      }
  
      private List tokens;
      
      public HTMLTokenizer() {}
      
      public HTMLTokenizer(String html)
      {
          tokenize(html);
      }
      
      public void clearTokens()
      {
          tokens=new ArrayList();
      }
      
      public void tokenize(String html)
      {
          clearTokens();
          
          StringTokenizer tokenizer=new StringTokenizer(html);
          boolean leftTag=false;
          boolean more=true;
          
          while (more)
          {	
              try {
                  String tok=null;
                  if (leftTag)
                  {
                      tok=tokenizer.nextToken("<");
                      
                  } else 
                  {
                      tok=tokenizer.nextToken(">");
                  }
                  
                  leftTag=!leftTag;
                  addToken(tok);
                  
              } catch (NoSuchElementException ex) {
                  more=false;
              }
          }
      }
      
      
      public List getTokens()
      {
          return tokens;
      }
      
      
      public void addToken(String token)
      {
          if (!token.equals(">"))
          {
              tokens.add(new HTMLToken(token));
          }
      }
  }
  
  
  
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/InternationalCharTest.java
  
  Index: InternationalCharTest.java
  ===================================================================
  /*
   * Copyright (c) 1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *
   * 4. The names "Java Apache Element Construction Set", "Java Apache ECS" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called 
   *    "Java Apache Element Construction Set" nor "Java Apache ECS" appear 
   *    in their names without prior written permission of the 
   *    Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project. <http://java.apache.org/>"
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Project. For more information
   * on the Java Apache Project please see <http://java.apache.org/>.
   *
   */
  
  package org.apache.ecs;
  
  import java.io.*;
  import java.util.StringTokenizer;
  
  import org.apache.ecs.*;
  import org.apache.ecs.html.*;
  
  import junit.framework.TestCase;
  import junit.framework.Test;
  
  /**
  * <p> Test application for a problem in 1.4.1 concerning international characters.
  * <p> This creates two files representing the same document 
  * using the <code>output</code> and the <code>toString</code> methods.
  * These should be identical.
  *
  * @author Magnśs Ţ—r Torfason
  * @author Robert Burrell Donkin
  */
  public class InternationalCharTest extends TestCase
  {
      /**
       * Application tests internation character by generation two files on the basis of
       * a resource file containing international characters.
       */
      public static void main(String[] args)
              throws Exception
      {
          InternationalCharTest charTest=new InternationalCharTest();
          System.out.println("Passes test? " + charTest.resourcePassesTest("org/apache/ecs/icechar.txt"));
      }
      
      
      public static junit.framework.Test suite()
      {
          return new InternationalCharTest();
      }
      
      
      public InternationalCharTest() 
      {
          super("InternationalCharacterTestCase");
      }
  
      public void runTest()
      {
          runResourceEncodingTest();
      }
  
      public void runResourceEncodingTest()
      {
          try 
          {
              assert(resourcePassesTest("org/apache/ecs/icechar.txt"));
          } catch (IOException ex)
          {
              fail(ex.toString());
          }
      }
      
      /** 
       *  
       */
      protected boolean resourcePassesTest(String named) throws IOException
      {
  
          // load file as resource
          InputStream is=this.getClass().getClassLoader().getResourceAsStream(named);
          
          if (is!=null)
          {	
              // read from the stream and us it to generate html.
              InputStreamReader isr=new InputStreamReader(is);
              
              StringWriter sw = new StringWriter();
              int cnt;
              char[] buf = new char[1024];
              while ( (cnt = isr.read(buf)) != -1 )
              {
                      sw.write(buf,0,cnt);
              }
              String str = sw.toString();
  
              StringTokenizer st = new StringTokenizer(str,";\n");
  
              int count = st.countTokens()/2;
              Option[] options = new Option[count+1];
              options[0] = new Option("NoPerson","NoPerson")
                      .addElement("NoPersonSelected");
              for (int i = 0; i < count; i++ )
              {
                      String value = st.nextToken();
                      String description = st.nextToken();
                      options[i+1] = new Option( description,value)
                              .addElement(description);
              }
              Select select = new Select("val",options);
              
              org.apache.ecs.Document doc=wrap(select);
              return toStringPassesTest(doc);
              
          } else {
              System.err.println("Cannot load required resource.");
              return false;
  
          }
      }
    
  
      /**
       * Utility method wraps an <code>Element<code> in a html document.
       */
      protected org.apache.ecs.Document wrap(org.apache.ecs.Element e)
      {
          return new org.apache.ecs.Document().appendTitle("Test").appendBody(e);
      }
      
      /**
       * <p> Output document two ways to two different files.
       * 
       * <p> Outputs using the <code>toString</code> method to the <code>toString</code>
file.
       * Outputs using the <code>output</code> method to the <code>toString</code>
file.
       * These two files should be identical.
       */
      protected boolean toStringPassesTest(org.apache.ecs.Document doc)
      {
          BasicECSComparitor compare=new BasicECSComparitor();
          boolean result=compare.compare(doc.getHtml(),doc.toString());
          return result;
      }
  }
  
  
  1.1                  jakarta-ecs/test/java/org/apache/ecs/icechar.txt
  
  Index: icechar.txt
  ===================================================================
  123123-1239;Prófunargaur
  0902773-3919;Dađi Árnason
  111176-9999;Magnús Torfason
  222276-8889;Davíđ Gudjónsson
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


Mime
View raw message