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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.portal.portlets;
1819//Element Construction Set20import org.apache.ecs.ConcreteElement;
2122//Jetspeed stuff23import org.apache.jetspeed.portal.PortletConfig;
24import org.apache.jetspeed.portal.PortletException;
25import org.apache.jetspeed.util.JetspeedClearElement;
26import org.apache.jetspeed.util.SimpleTransform;
27import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
28import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29import org.apache.jetspeed.services.logging.JetspeedLogger;
30import org.apache.jetspeed.services.resources.JetspeedResources;
313233//XML stuff34import org.xml.sax.SAXException;
3536//java stuff37import java.io.IOException;
383940/***41Provides a content publication system (like Slashdot).4243@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*/46publicclassJetspeedContentextendsFileWatchPortlet47 {
4849/***50 * Static initialization of the logger for this class51 */52privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedContent.class.getName());
5354publicstaticfinal String PROVIDER_NAME_KEY = "provider-name";
5556/***57 The name of the JPC provider.58 */59private String provider = "";
6061/***62 The stylesheet for using with this provider63 */64private String stylesheet = "";
6566/***67 The url that was specified by the provider68 */69private String url = null;
7071/***72 Return the last time the provider's URL has been changed.73 */74privatelong lastModified;
757677/***78 Init this Portlet, set it's title, description, etc.79 */80publicvoid init() throws PortletException {
8182PortletConfig config = this.getPortletConfig();
8384 provider = config.getInitParameter( PROVIDER_NAME_KEY );
8586if ( provider == null ) {
87thrownewPortletException( "You need to specify " + PROVIDER_NAME_KEY );
88 }
8990//NOTE: There are no HARD keys here in JetspeedResources. If you change91//this format of this it will break at runtime. CAREFULL!9293this.url = JetspeedResources.getString( "content.provider." + provider + ".url" );
9495this.stylesheet = JetspeedResources.getString( "content.provider." + provider + ".stylesheet.url" );
9697 String title = JetspeedResources.getString( "content.provider." + provider + ".title" );
9899 String description = JetspeedResources.getString( "content.provider." + provider + ".description" );
100101this.setTitle( title );
102this.setDescription( description );
103104this.setContent( this.parse( url ) );
105106//now make sure all the above 4 values are define within JetspeedResources107if ( url == null ||
108 stylesheet == null ||
109 title == null ||
110 description == null ) {
111thrownewPortletException( "Not all properties defined in JetspeedResources. See JetspeedResources.properties notes." );
112 }
113114this.getPortletConfig().setURL( url );
115116//set the last modification date for this file so that if it is 117//modified this portlet can be expired from the cache.118119try {
120this.lastModified = JetspeedDiskCache.getInstance()
121 .getEntry( this.url ).getLastModified();
122 } catch ( IOException e ) {
123 logger.error("Exception", e);
124 }
125126 }
127128/***129 Parse out the JCP URL and return it as a concrete element130 */131private ConcreteElement parse( String url ) throws PortletException {
132133134//now get the url and stylesheet from the JetspeedDiskCache store...135136try {
137138 url = JetspeedDiskCache.getInstance()
139 .getEntry( url ).getURL();
140141this.stylesheet = JetspeedDiskCache.getInstance()
142 .getEntry( this.stylesheet ).getURL();
143 } catch (IOException e) {
144 logger.error( "Couldn't transform content.", e );
145thrownewPortletException( "Couldn't transform content. Please see error log" );
146 }
147148149try {
150151returnnewJetspeedClearElement( SimpleTransform.transform( url, stylesheet ) );
152153 } catch (SAXException e) {
154 logger.error( "Couldn't transform content.", e );
155thrownewPortletException( "Couldn't transform content. Please see error log" );
156 }
157158159 }
160161 }