KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2000-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 //Element Construction Set
20
import org.apache.ecs.ConcreteElement;
21
22 //Jetspeed stuff
23
import org.apache.jetspeed.portal.PortletConfig;
24 import org.apache.jetspeed.portal.PortletException;
25 import org.apache.jetspeed.util.JetspeedClearElement;
26 import org.apache.jetspeed.util.SimpleTransform;
27 import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29 import org.apache.jetspeed.services.logging.JetspeedLogger;
30 import org.apache.jetspeed.services.resources.JetspeedResources;
31
32
33 //XML stuff
34
import org.xml.sax.SAXException JavaDoc;
35
36 //java stuff
37
import java.io.IOException JavaDoc;
38
39
40 /**
41 Provides a content publication system (like Slashdot).
42
43 @author <a HREF="mailto:burton@apache.org">Kevin A. Burton</a>
44 @version $Id: JetspeedContent.java,v 1.26 2004/02/23 04:03:34 jford Exp $
45 */

46 public class JetspeedContent extends FileWatchPortlet
47 {
48
49     /**
50      * Static initialization of the logger for this class
51      */

52     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedContent.class.getName());
53     
54     public static final String JavaDoc PROVIDER_NAME_KEY = "provider-name";
55
56     /**
57     The name of the JPC provider.
58     */

59     private String JavaDoc provider = "";
60
61     /**
62     The stylesheet for using with this provider
63     */

64     private String JavaDoc stylesheet = "";
65
66     /**
67     The url that was specified by the provider
68     */

69     private String JavaDoc url = null;
70     
71     /**
72     Return the last time the provider's URL has been changed.
73     */

74     private long lastModified;
75     
76     
77     /**
78     Init this Portlet, set it's title, description, etc.
79     */

80     public void init() throws PortletException {
81
82         PortletConfig config = this.getPortletConfig();
83         
84         provider = config.getInitParameter( PROVIDER_NAME_KEY );
85         
86         if ( provider == null ) {
87             throw new PortletException( "You need to specify " + PROVIDER_NAME_KEY );
88         }
89
90         //NOTE: There are no HARD keys here in JetspeedResources. If you change
91
//this format of this it will break at runtime. CAREFULL!
92

93         this.url = JetspeedResources.getString( "content.provider." + provider + ".url" );
94         
95         this.stylesheet = JetspeedResources.getString( "content.provider." + provider + ".stylesheet.url" );
96         
97         String JavaDoc title = JetspeedResources.getString( "content.provider." + provider + ".title" );
98
99         String JavaDoc description = JetspeedResources.getString( "content.provider." + provider + ".description" );
100
101         this.setTitle( title );
102         this.setDescription( description );
103        
104         this.setContent( this.parse( url ) );
105             
106         //now make sure all the above 4 values are define within JetspeedResources
107
if ( url == null ||
108              stylesheet == null ||
109              title == null ||
110              description == null ) {
111             throw new PortletException( "Not all properties defined in JetspeedResources. See JetspeedResources.properties notes." );
112         }
113         
114         this.getPortletConfig().setURL( url );
115         
116         //set the last modification date for this file so that if it is
117
//modified this portlet can be expired from the cache.
118

119         try {
120             this.lastModified = JetspeedDiskCache.getInstance()
121                 .getEntry( this.url ).getLastModified();
122         } catch ( IOException JavaDoc e ) {
123             logger.error("Exception", e);
124         }
125         
126     }
127     
128     /**
129     Parse out the JCP URL and return it as a concrete element
130     */

131     private ConcreteElement parse( String JavaDoc url ) throws PortletException {
132  
133             
134         //now get the url and stylesheet from the JetspeedDiskCache store...
135

136         try {
137         
138         url = JetspeedDiskCache.getInstance()
139             .getEntry( url ).getURL();
140
141         this.stylesheet = JetspeedDiskCache.getInstance()
142             .getEntry( this.stylesheet ).getURL();
143         } catch (IOException JavaDoc e) {
144             logger.error( "Couldn't transform content.", e );
145             throw new PortletException( "Couldn't transform content. Please see error log" );
146         }
147
148         
149         try {
150             
151             return new JetspeedClearElement( SimpleTransform.transform( url, stylesheet ) );
152             
153         } catch (SAXException JavaDoc e) {
154             logger.error( "Couldn't transform content.", e );
155             throw new PortletException( "Couldn't transform content. Please see error log" );
156         }
157
158        
159     }
160     
161 }
162
Popular Tags