KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > FileServerPortlet


1 /*
2  * Copyright 2000-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
17 package org.apache.jetspeed.portal.portlets;
18
19
20 //Jetspeed stuff
21
import org.apache.jetspeed.portal.*;
22 import org.apache.jetspeed.util.*;
23 import org.apache.jetspeed.cache.disk.*;
24
25 //standard java stuff
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         // first make sure we propagate init
42
super.init();
43         
44         PortletConfig config = this.getPortletConfig();
45         
46         //fetch the URL as a String...
47

48         try {
49
50             this.setContent( new JetspeedClearElement( this.getURL( this.getPortletConfig().getURL() ) ) );
51
52         } catch (Exception JavaDoc e) {
53             throw new PortletException( e.getMessage() );
54         }
55             
56        
57     }
58
59     /**
60     */

61     private String JavaDoc getURL(String JavaDoc url) throws IOException {
62
63         int CAPACITY = 1024;
64
65         Reader rdr = JetspeedDiskCache.getInstance()
66             .getEntry( url ).getReader();
67         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
68
69         //now process the Reader...
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 }
87
Popular Tags