1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portal.portlets;
18
19
20
21 import org.apache.jetspeed.portal.*;
22 import org.apache.jetspeed.util.*;
23 import org.apache.jetspeed.cache.disk.*;
24
25
26 import java.io.*;
27
28 /***
29 * <p>Serve a static URL (typically a HTML fragment)</p>
30 *
31 @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
32 @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
33 @version $Id: FileServerPortlet.java,v 1.27 2004/02/23 04:03:33 jford Exp $
34 */
35 public class FileServerPortlet extends FileWatchPortlet {
36
37 /***
38 */
39 public void init() throws PortletException {
40
41
42 super.init();
43
44 PortletConfig config = this.getPortletConfig();
45
46
47
48 try {
49
50 this.setContent( new JetspeedClearElement( this.getURL( this.getPortletConfig().getURL() ) ) );
51
52 } catch (Exception e) {
53 throw new PortletException( e.getMessage() );
54 }
55
56
57 }
58
59 /***
60 */
61 private String getURL(String url) throws IOException {
62
63 int CAPACITY = 1024;
64
65 Reader rdr = JetspeedDiskCache.getInstance()
66 .getEntry( url ).getReader();
67 StringBuffer buffer = new StringBuffer();
68
69
70 char[] chars = new char[CAPACITY];
71
72 int readCount = 0;
73 while( ( readCount = rdr.read( chars )) > 0 ) {
74
75 buffer.append( chars, 0, readCount);
76 }
77
78 rdr.close();
79
80
81 return buffer.toString();
82
83
84 }
85
86 }