KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > validator > WellFormedXhtmlValidator


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.test.web.validator;
6
7 import java.io.* ;
8 import org.dom4j.Document;
9 import org.dom4j.io.SAXReader;
10 import org.exoplatform.test.web.ExoWebClient;
11 import com.meterware.httpunit.*;
12 /**
13  * May 21, 2004
14  * @author: Tuan Nguyen
15  * @email: tuan08@users.sourceforge.net
16  * @version: $Id: WellFormedXhtmlValidator.java,v 1.1 2004/10/11 23:36:06 tuan08 Exp $
17  **/

18 public class WellFormedXhtmlValidator implements Validator {
19   
20   public boolean validate(WebResponse response, ExoWebClient client) throws Exception JavaDoc {
21     String JavaDoc xhtml = response.getText();
22     try {
23       ByteArrayInputStream is = new ByteArrayInputStream(xhtml.getBytes()) ;
24       SAXReader reader = new SAXReader();
25       Document document = reader.read(is);
26     } catch (Exception JavaDoc ex) {
27      System.out.println("Validate xhtml error: " + ex.getMessage()) ;
28      FileOutputStream out = new FileOutputStream("./target/output.html") ;
29      out.write(xhtml.getBytes()) ;
30      return false ;
31     }
32     return true ;
33   }
34   
35   public String JavaDoc getName() { return "WellFormedXhtmlValidator" ; }
36   
37   public String JavaDoc getDescription() {
38     return "Make sure that the return xhtml is well formed." ;
39   }
40 }
Popular Tags