1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.portletbridge.xsl;
17  
18  import java.io.File;
19  import java.io.FileReader;
20  
21  import javax.xml.transform.Templates;
22  import javax.xml.transform.TransformerFactory;
23  import javax.xml.transform.stream.StreamSource;
24  
25  import junit.framework.TestCase;
26  
27  import org.ccil.cowan.tagsoup.Parser;
28  import org.portletbridge.rewriter.DefaultUrlRewriter;
29  import org.xml.sax.InputSource;
30  
31  /***
32   * @author JMcCrindle
33   */
34  public class XslWithCustomSaxTest extends TestCase {
35  
36      /*
37       * @see TestCase#setUp()
38       */
39      protected void setUp() throws Exception {
40          super.setUp();
41      }
42      
43      public void testTransform() throws Exception {
44          Parser parser = new Parser();
45          parser.setFeature(Parser.namespacesFeature, false);
46          
47          TransformerFactory factory = TransformerFactory.newInstance();
48          Templates templates = factory.newTemplates(new StreamSource(new FileReader(new File("./src/test/org/portletbridge/xsl/test.xsl"))));
49  
50          XslFilter xslFilter = new XslFilter(templates);
51  
52          LinkRewriterXmlFilter filter = new LinkRewriterXmlFilter();
53          filter.setParent(parser);
54          filter.setContentHandler(xslFilter);
55          filter.setUrlRewriter(new DefaultUrlRewriter("/test/test.do", "/mytest/"));
56  
57          // parser.setContentHandler(handler1);
58  
59          // Parse the source XML, and send the parse events to the
60          // TransformerHandler.
61          filter.parse(new InputSource(
62                  new FileReader(new File(
63                  "./src/test/org/portletbridge/xsl/test.xml"))));
64      }
65  
66      /*
67       * @see TestCase#tearDown()
68       */
69      protected void tearDown() throws Exception {
70          super.tearDown();
71      }
72  
73      /***
74       * Constructor for XslTest.
75       * @param arg0
76       */
77      public XslWithCustomSaxTest(String arg0) {
78          super(arg0);
79      }
80  
81  }