KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > transform > BaseTest


1 /**
2  * Copyright 2001-2005 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.services.xml.transform;
6
7 import junit.framework.TestCase;
8 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
9 import org.xml.sax.InputSource JavaDoc;
10 import org.xml.sax.XMLReader JavaDoc;
11
12 import org.exoplatform.container.PortalContainer;
13 import org.exoplatform.container.RootContainer;
14 import java.io.InputStream JavaDoc;
15 import java.util.Date JavaDoc;
16
17 import java.text.SimpleDateFormat JavaDoc;
18 import java.text.DateFormat JavaDoc;
19 import org.apache.commons.logging.Log ;
20 import org.exoplatform.services.log.LogService;
21 import org.exoplatform.services.xml.resolving.XMLResolvingService;
22
23
24 /**
25  * Created by the Exo Development team.
26  *
27  * Base transformer test
28  */

29 public class BaseTest extends TestCase {
30     private final String JavaDoc DATE_PATTERN = "yy-MM-DD_HH-mm-ss";
31     private DateFormat JavaDoc dateFormat;
32
33 // protected Log log;
34

35   protected String JavaDoc getTimeStamp(){
36       return dateFormat.format(new Date JavaDoc());
37   }
38
39   protected Log getLog(){
40       Log log= null;
41       try {
42           LogService service = (LogService) RootContainer.getInstance().
43                                getComponentInstanceOfType(LogService.class);
44           log = service.getLog("org.exoplatform.services.xml");
45           service.setLogLevel("org.exoplatform.services.xml",
46                               LogService.DEBUG, true);
47           log = service.getLog(this.getClass());
48 // log.debug("Test class name is "+this.getClass().getName());
49
} catch (Exception JavaDoc ex) {
50
51       }
52       return log;
53 }
54
55
56   public BaseTest(){
57       dateFormat = new SimpleDateFormat JavaDoc(DATE_PATTERN);
58   }
59
60
61     protected void validateXML(InputStream JavaDoc input) throws Exception JavaDoc {
62         XMLResolvingService resolvingService =
63                 (XMLResolvingService) PortalContainer.getInstance().
64                 getComponentInstanceOfType(XMLResolvingService.class);
65         assertNotNull("XMLResolvingService", resolvingService);
66
67         XMLReader JavaDoc xmlReader = XMLReaderFactory.createXMLReader();
68         xmlReader.setEntityResolver(resolvingService.getEntityResolver());
69         assertNotNull("resolvingService.getEntityResolver()",
70                       resolvingService.getEntityResolver());
71         getLog().debug("resolvingService class is "+resolvingService.getClass().getName());
72
73         InputSource JavaDoc src = resolvingService.getEntityResolver().
74                      resolveEntity("-//W3C//DTD XHTML 1.0 Transitional//EN",
75                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
76         assertNotNull("Not resolved InputSource entity", src);
77
78         xmlReader.setFeature("http://xml.org/sax/features/validation",
79                              true); //validation on
80
//transform
81
try {
82             xmlReader.parse(new InputSource JavaDoc(input));
83         } catch (org.xml.sax.SAXParseException JavaDoc ex) {
84             fail("Document is not valid XML. See: \n" + ex.getMessage());
85         }
86     }
87
88 }
89
Popular Tags