1 16 17 package org.apache.jetspeed.portal.portlets; 18 19 import org.apache.ecs.ConcreteElement; 21 22 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 import org.xml.sax.SAXException ; 35 36 import java.io.IOException ; 38 39 40 46 public class JetspeedContent extends FileWatchPortlet 47 { 48 49 52 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedContent.class.getName()); 53 54 public static final String PROVIDER_NAME_KEY = "provider-name"; 55 56 59 private String provider = ""; 60 61 64 private String stylesheet = ""; 65 66 69 private String url = null; 70 71 74 private long lastModified; 75 76 77 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 93 this.url = JetspeedResources.getString( "content.provider." + provider + ".url" ); 94 95 this.stylesheet = JetspeedResources.getString( "content.provider." + provider + ".stylesheet.url" ); 96 97 String title = JetspeedResources.getString( "content.provider." + provider + ".title" ); 98 99 String 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 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 119 try { 120 this.lastModified = JetspeedDiskCache.getInstance() 121 .getEntry( this.url ).getLastModified(); 122 } catch ( IOException e ) { 123 logger.error("Exception", e); 124 } 125 126 } 127 128 131 private ConcreteElement parse( String url ) throws PortletException { 132 133 134 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 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 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 |