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 import org.apache.ecs.ConcreteElement;
21
22
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
34 import org.xml.sax.SAXException;
35
36
37 import java.io.IOException;
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 PROVIDER_NAME_KEY = "provider-name";
55
56 /***
57 The name of the JPC provider.
58 */
59 private String provider = "";
60
61 /***
62 The stylesheet for using with this provider
63 */
64 private String stylesheet = "";
65
66 /***
67 The url that was specified by the provider
68 */
69 private String 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
91
92
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
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
117
118
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 /***
129 Parse out the JCP URL and return it as a concrete element
130 */
131 private ConcreteElement parse( String url ) throws PortletException {
132
133
134
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 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 }