1   package org.portletbridge.portlet;
2   
3   import java.io.FileNotFoundException;
4   import java.io.FileReader;
5   import java.io.InputStream;
6   import java.io.StringWriter;
7   import java.net.URL;
8   
9   import javax.xml.transform.Transformer;
10  import javax.xml.transform.TransformerException;
11  import javax.xml.transform.TransformerFactory;
12  import javax.xml.transform.sax.SAXSource;
13  import javax.xml.transform.stream.StreamResult;
14  import javax.xml.transform.stream.StreamSource;
15  
16  import junit.framework.TestCase;
17  
18  import org.cyberneko.html.parsers.SAXParser;
19  import org.portletbridge.mock.MockBridgeFunctions;
20  import org.xml.sax.InputSource;
21  import org.xml.sax.SAXNotRecognizedException;
22  import org.xml.sax.SAXNotSupportedException;
23  
24  public class PortletBridgeXslTest extends TestCase {
25      public void testXsl() throws TransformerException, SAXNotRecognizedException, SAXNotSupportedException, FileNotFoundException {
26          TransformerFactory tfactory = TransformerFactory.newInstance();
27          URL resource = this.getClass().getResource("/org/portletbridge/xsl/default.xsl");
28          Transformer transformer = tfactory.newTransformer(new StreamSource(resource.toExternalForm()));
29          StringWriter writer = new StringWriter();
30          SAXParser parser = new SAXParser();
31          transformer.setParameter("bridge", new MockBridgeFunctions());
32          FileReader inputReader = new FileReader("./src/test/org/portletbridge/portlet/slashdot.html");
33          assertNotNull(inputReader);
34          transformer.transform(new SAXSource(parser, new InputSource(inputReader)), new StreamResult(writer));
35          writer.flush();
36          System.out.println(writer.getBuffer().toString());
37          
38      }
39  }