Index: .classpath =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/.classpath,v retrieving revision 1.1 diff -u -r1.1 .classpath --- .classpath 15 Nov 2004 06:06:40 -0000 1.1 +++ .classpath 13 Jan 2005 23:08:22 -0000 @@ -1,7 +1,7 @@ - + @@ -9,6 +9,8 @@ + + @@ -21,7 +23,7 @@ - + @@ -31,6 +33,6 @@ - + Index: .project =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/.project,v retrieving revision 1.1 diff -u -r1.1 .project --- .project 15 Nov 2004 06:06:40 -0000 1.1 +++ .project 13 Jan 2005 23:08:22 -0000 @@ -1,7 +1,7 @@ - apa-rss + rss Jetspeed-2 Language Selector Portlet Index: project.xml =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/project.xml,v retrieving revision 1.2 diff -u -r1.2 project.xml --- project.xml 2 Dec 2004 05:22:12 -0000 1.2 +++ project.xml 13 Jan 2005 23:08:22 -0000 @@ -3,150 +3,141 @@ $Id: project.xml,v 1.2 2004/12/02 05:22:12 taylor Exp $ --> - ${basedir}/./../project.xml - rss - Jetspeed-2 Language Selector Portlet - Jetspeed-2 Language Selector Portlet - Language Selector Portlet - - - scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-jetspeed-2/applications/rss - http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/applications/rss/ - - - - - portlet-api - portlet-api - 1.0 - - false - - - - servletapi - 2.3 - - false - - - - - springframework:spring-core - 1.1.1 - - true - - - - jdom - jdom - 1.0 - - true - - - - commons-digester - commons-digester - 1.5 - jar - http://jakarta.apache.org/commons/digester.html - - true - - - - commons-beanutils - commons-beanutils - 1.6.1 - jar - http://jakarta.apache.org/commons/beanutils.html - - true - - - - - rome - rome - 0.4 - jar - - true - - - - - portals-bridges - portals-bridges-common - 0.1 - - true - - - - - velocity - 1.4 - - true - - - - velocity-tools - 1.1 - http://jakarta.apache.org/velocity - - true - - - - portals-bridges - portals-bridges-velocity - 0.1 - - true - - - - xml-apis - 2.0.2 - - true - - - - - - - - - src/java - - - ${basedir}/src/java/ - - **/*.properties - - - - - - - maven-jdepend-plugin - - maven-pmd-plugin - maven-changelog-plugin - maven-file-activity-plugin - maven-developer-activity-plugin - maven-license-plugin - maven-javadoc-plugin - maven-jxr-plugin - maven-junit-report-plugin - maven-linkcheck-plugin - maven-tasklist-plugin - - + maven-pmd-plugin + maven-changelog-plugin + maven-file-activity-plugin + maven-developer-activity-plugin + maven-license-plugin + maven-javadoc-plugin + maven-jxr-plugin + maven-junit-report-plugin + maven-linkcheck-plugin + maven-tasklist-plugin + + \ No newline at end of file Index: src/java/org/apache/portals/applications/rss/AbstractRssPortlet.java =================================================================== RCS file: src/java/org/apache/portals/applications/rss/AbstractRssPortlet.java diff -N src/java/org/apache/portals/applications/rss/AbstractRssPortlet.java --- src/java/org/apache/portals/applications/rss/AbstractRssPortlet.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.rss; - -import java.io.IOException; - -import javax.portlet.ActionRequest; -import javax.portlet.ActionResponse; -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; - -import org.apache.portals.applications.rss.servlets.SpringInitServlet; -import org.apache.portals.applications.transform.Transform; -import org.apache.portals.applications.transform.TransformCache; -import org.apache.portals.bridges.velocity.GenericVelocityPortlet; -import org.springframework.beans.factory.BeanFactory; - - -/** - * AbstractRssPortlet - * - * @author David Sean Taylor - * @version $Id: AbstractRssPortlet.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public abstract class AbstractRssPortlet extends GenericVelocityPortlet -{ - protected TransformCache cache; - protected Transform transform; - - public void init(PortletConfig config) throws PortletException - { - super.init(config); - BeanFactory factory = SpringInitServlet.getSpringFactory(); - cache = (TransformCache)factory.getBean("transformCache"); - transform = (Transform)factory.getBean("transform"); - } - - public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException - { - response.setContentType("text/html"); - doPreferencesEdit(request, response); - } - - /** - * Save the prefs - */ - public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, - IOException - { - processPreferencesAction(request, actionResponse); - String url = request.getPreferences().getValue("url", "http://www.npr.org/rss/rss.php?topicId=4"); - String stylesheet = getPortletConfig().getInitParameter("stylesheet"); - String key = cache.constructKey(url, stylesheet); // TODO: use the entire parameter list - cache.remove(key); - } - -} Index: src/java/org/apache/portals/applications/rss/RSSPortlet.java =================================================================== RCS file: src/java/org/apache/portals/applications/rss/RSSPortlet.java diff -N src/java/org/apache/portals/applications/rss/RSSPortlet.java --- src/java/org/apache/portals/applications/rss/RSSPortlet.java 26 Dec 2004 11:08:00 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,201 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.rss; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URL; -import java.net.URLConnection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; - -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; -import javax.portlet.PortletPreferences; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.portals.applications.transform.TransformCacheEntry; -import org.apache.portals.applications.util.Streams; -import org.w3c.dom.Document; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - - -/** - * RSSPortlet - * - * @author David Sean Taylor - * @version $Id: RSSPortlet.java,v 1.3 2004/12/26 11:08:00 shinsuke Exp $ - */ -public class RSSPortlet extends AbstractRssPortlet implements EntityResolver -{ - - private Document document = null; - - private Map stylesheets = null; - - public void init(PortletConfig config) throws PortletException - { - super.init(config); - - // load stylesheets available - stylesheets = new HashMap(); - - Enumeration e = this.getPortletConfig().getInitParameterNames(); - while (e.hasMoreElements()) - { - String name = (String) e.nextElement(); - String base = "text/html"; - - if (name.startsWith("stylesheet")) - { - int idx = -1; - if ((idx = name.indexOf(".")) > -1) - { - base = name.substring(idx + 1, name.length()); - } - stylesheets.put(base, getPortletConfig().getInitParameter(name)); - } - } - } - - public InputSource resolveEntity(String publicId, String systemId) - { - try - { - //access Jetspeed cache and get a java.io.Reader - Reader rdr = openURL(publicId); - InputSource is = new InputSource(rdr); - is.setPublicId(publicId); - is.setSystemId(systemId); - return is; - } - catch (IOException x) - { - System.err.println("Entity Resolution error: ( " + publicId + " Taking " + systemId + " from cache throwed Exception: " + x); - - } - return null; - } - - private Reader openURL(String urlPath) throws IOException - { - URL url = new URL(urlPath); - URLConnection conn = url.openConnection(); - - String enc = conn.getContentEncoding(); - if (enc == null) - { - enc = "ISO-8859-1"; - } - - BufferedInputStream is = new BufferedInputStream(conn.getInputStream()); - is.mark(20480); - BufferedReader asciiReader = new BufferedReader(new InputStreamReader(is, "ASCII")); - String decl = asciiReader.readLine(); - String key = "encoding=\""; - if (decl != null) - { - int off = decl.indexOf(key); - if (off > 0) - { - enc = decl.substring(off + key.length(), decl.indexOf('"', off + key.length())); - } - } - //Reset the bytes read - is.reset(); - Reader rdr = new InputStreamReader(is, enc); - return rdr; - } - - public Document getDocument(String url) - throws Exception - { - DocumentBuilder parser = null; - - // read content, clean it, parse it and cache the DOM try { final - DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance(); //Have it non-validating - docfactory.setValidating(false); - parser = docfactory.newDocumentBuilder(); - parser.setEntityResolver(this); - - URL u = new URL(url); - InputSource isrc = new InputSource(u.openStream()); - isrc.setSystemId(url); - isrc.setEncoding("UTF-8"); - this.document = parser.parse(isrc); - return document; - } - - - public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException - { - response.setContentType("text/html"); - - - PortletPreferences prefs = request.getPreferences(); - - // TODO: use stylesheet based on mimetype - String stylesheet = getPortletConfig().getInitParameter("stylesheet"); - String realStylesheet = getPortletConfig().getPortletContext().getRealPath(stylesheet); - String url = prefs.getValue("url", "http://news.bbc.co.uk/rss/sportonline_uk_edition/football/internationals/england/squad_profiles/rss091.xml"); - - String key = cache.constructKey(url, stylesheet); // TODO: use the entire parameter list - TransformCacheEntry entry = cache.get(key); - if (entry != null) - { - byte[] bytes = (byte[])entry.getDocument(); - Streams.drain(new StringReader(new String(bytes,"UTF-8")), response.getWriter()); - } - else - { - try - { - Document document = getDocument(url); - InputSource source = new InputSource(url); - source.setSystemId(url); - source.setEncoding("UTF-8"); - - Map parameters = new HashMap(); - parameters.put("itemdisplayed", prefs.getValue("itemdisplayed", "15")); - parameters.put("openinpopup", prefs.getValue("openinpopup", "true")); - parameters.put("showdescription", prefs.getValue("showdescription", "true")); - parameters.put("showtitle", prefs.getValue("showtitle", "true")); - parameters.put("showtextinput", prefs.getValue("showtextinput", "true")); - - StringWriter sw= new StringWriter(); - transform.transform(realStylesheet, source, sw, parameters); //response.getPortletOutputStream(), parameters); - Streams.drain(new StringReader(sw.toString()), response.getWriter()); - - cache.put(key, sw.toString().getBytes("UTF-8"), 15); - } - catch (Exception ex) - { - response.getPortletOutputStream().write(new String("Failed to process RSS Feed: " + url + ", " + ex).getBytes()); - } - } - } - -} \ No newline at end of file Index: src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java,v retrieving revision 1.2 diff -u -r1.2 RomeRSSPortlet.java --- src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java 19 Nov 2004 21:59:09 -0000 1.2 +++ src/java/org/apache/portals/applications/rss/RomeRSSPortlet.java 13 Jan 2005 23:08:23 -0000 @@ -15,100 +15,106 @@ */ package org.apache.portals.applications.rss; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; import java.util.HashMap; import java.util.Map; +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; +import javax.portlet.PortletContext; import javax.portlet.PortletException; import javax.portlet.PortletPreferences; +import javax.portlet.PortletRequestDispatcher; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import org.apache.portals.applications.transform.TransformCacheEntry; -import org.apache.portals.applications.util.Streams; -import org.w3c.dom.Document; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.portals.bridges.velocity.GenericVelocityPortlet; + +import org.apache.velocity.context.Context; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; -import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.io.XmlReader; /** * Rome RSS Portlet * * @author David Sean Taylor - * @version $Id: RomeRSSPortlet.java,v 1.2 2004/11/19 21:59:09 taylor Exp $ + * @version $Id: Exp $ */ -public class RomeRSSPortlet extends AbstractRssPortlet +public class RomeRSSPortlet extends GenericVelocityPortlet { + + protected Log log = LogFactory.getLog(RomeRSSPortlet.class); + + /** + * @see javax.portlet.Portlet#init(javax.portlet.PortletConfig) + */ public void init(PortletConfig config) throws PortletException { super.init(config); + } - - /* - * (non-Javadoc) - * - * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, - * javax.portlet.RenderResponse) + + /** + * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse) */ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); - - PortletPreferences prefs = request.getPreferences(); + Context velocityContext = this.getContext(request); + PortletPreferences prefs = request.getPreferences(); String url = prefs.getValue("url", "http://www.npr.org/rss/rss.php?topicId=4"); - String stylesheet = getPortletConfig().getInitParameter("stylesheet"); - String realStylesheet = getPortletConfig().getPortletContext().getRealPath(stylesheet); + try + { + URL feedUrl = new URL(url); + SyndFeedInput input = new SyndFeedInput(); + + SyndFeed feed = input.build(new XmlReader(feedUrl)); + + RssInfo rssInfo = new RssInfo(feed, new Integer(prefs.getValue("itemdisplayed", "15")).intValue(), new Boolean(prefs + .getValue("openinpopup", "true")).booleanValue(), new Boolean(prefs.getValue("showdescription", "true")) + .booleanValue(), new Boolean(prefs.getValue("showtitle", "true")).booleanValue(), new Boolean(prefs.getValue( + "showtextinput", "true")).booleanValue()); - URL xslt = getPortletConfig().getPortletContext().getResource(stylesheet); - - String key = cache.constructKey(url, stylesheet); // TODO: use the entire parameter list - TransformCacheEntry entry = cache.get(key); - if (entry != null) + velocityContext.put("rssInfo", rssInfo); + + super.doView(request, response); + + } + catch (Exception e) { - byte[] bytes = (byte[])entry.getDocument(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - Streams.drain(bais, response.getPortletOutputStream()); - bais.close(); + throw new PortletException(new String("Failed to process RSS Feed: " + url + ", " + e)); } - else - { - try - { - URL feedUrl = new URL(url); - SyndFeedInput input = new SyndFeedInput(); - SyndFeed feed = input.build(new XmlReader(feedUrl)); - SyndFeedOutput output = new SyndFeedOutput(); - //output.output(feed, response.getWriter()); - Document document = output.outputW3CDom(feed); - - Map parameters = new HashMap(); - - parameters.put("itemdisplayed", prefs.getValue("itemdisplayed", "15")); - parameters.put("openinpopup", prefs.getValue("openinpopup", "true")); - parameters.put("showdescription", prefs.getValue("showdescription", "true")); - parameters.put("showtitle", prefs.getValue("showtitle", "true")); - parameters.put("showtextinput", prefs.getValue("showtextinput", "true")); - - - // TODO: don't use a transform, instead use Velocity template and populate via Rome model - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - transform.transform(realStylesheet, document, baos, parameters); - byte[] bytes = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - Streams.drain(bais, response.getPortletOutputStream()); - cache.put(key, bytes, 15); - } - catch (Exception e) - { - response.getPortletOutputStream().write(new String("Failed to process RSS Feed: " + url + ", " + e).getBytes()); - } + + } + + /** + * + * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse) + */ + public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + response.setContentType("text/html"); + doPreferencesEdit(request, response); + } + + /** + * + * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse) + */ + public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, java.io.IOException + { + String add = request.getParameter("Save"); + if (add != null) + { + processPreferencesAction(request, actionResponse); } } + } Index: src/java/org/apache/portals/applications/rss/servlets/SpringInitServlet.java =================================================================== RCS file: src/java/org/apache/portals/applications/rss/servlets/SpringInitServlet.java diff -N src/java/org/apache/portals/applications/rss/servlets/SpringInitServlet.java --- src/java/org/apache/portals/applications/rss/servlets/SpringInitServlet.java 15 Nov 2004 06:06:42 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,82 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.rss.servlets; - -import java.io.InputStream; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.xml.XmlBeanFactory; - - -/** - * SpringInitServlet - * - * @author David Sean Taylor - * @version $Id: SpringInitServlet.java,v 1.1 2004/11/15 06:06:42 taylor Exp $ - */ -public class SpringInitServlet extends HttpServlet -{ - /** - * Init Parameter: default spring configuration property - */ - private static final String INITPARAM_SPRING_CONFIG = "spring-configuration"; - private static Object semaphore = new Object(); - - /** - * Spring Factory - */ - private static XmlBeanFactory springFactory = null; - - - /** - * Intialize Servlet. - */ - public final void init( ServletConfig config ) throws ServletException - { - super.init(config); - String springConfig = getInitParameter(INITPARAM_SPRING_CONFIG); - if (springConfig == null) { throw new ServletException("Spring Configuration file not specified"); } - - // load Spring - try - { - synchronized (semaphore) - { - if (null == springFactory) - { - InputStream is = this.getServletContext().getResourceAsStream(springConfig); - springFactory = new XmlBeanFactory(is); - is.close(); - } - } - } - catch (Exception e) - { - throw new ServletException("Failed to load spring configuration.", e); - } - - } - - public static final BeanFactory getSpringFactory() - { - return springFactory; - } - -} Index: src/java/org/apache/portals/applications/transform/Transform.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/Transform.java diff -N src/java/org/apache/portals/applications/transform/Transform.java --- src/java/org/apache/portals/applications/transform/Transform.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,73 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform; - -import java.io.OutputStream; -import java.io.Writer; -import java.util.Map; - -import org.w3c.dom.Document; -import org.xml.sax.InputSource; - - -/** - * This interface is a facade for all Transformation related operations. - * Transformation service abstracts the XSL Transform manipulation, maintenance, - * caching and transformation resolution algorithms. - * - * @author David Sean Taylor - * @version $Id: Transform.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public interface Transform -{ - - /** - * Performs a transform on an input stream, writing the transformed content to a Writer - * - * @param xsltPath The path to a local XSLT file - * @param inputSource The input stream and description containing content to be transformed. - * @param writer The output stream receiving the transformed content. - * @param properties Map of XSLT properties passed into transformer - */ - public void transform(String xsltPath, InputSource inputSource, Writer writer, Map properties) - throws TransformException; - - /** - * Performs a transform on an input stream, writing the transformed content to a Writer - * - * @param xsltPath The path to a local XSLT file - * @param inputSource The input stream and description containing content to be transformed. - * @param outputStream The output stream receiving the transformed content. - * @param properties Map of XSLT properties passed into transformer - */ - public void transform(String xsltPath, InputSource inputSource, OutputStream os, Map properties) - throws TransformException; - - - /** - * Performs a transform on an input stream, writing the transformed content to a Writer - * - * @param xsltPath The path to a local XSLT file - * @param document The W3C document to be transformed. - * @param outputStream The output stream receiving the transformed content. - * @param properties Map of XSLT properties passed into transformer - */ - public TransformObjectPublisher getPublisher(); - - public void transform(String xsltPath, Document document, OutputStream os, Map parameters) - throws TransformException; - -} Index: src/java/org/apache/portals/applications/transform/TransformCache.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/TransformCache.java diff -N src/java/org/apache/portals/applications/transform/TransformCache.java --- src/java/org/apache/portals/applications/transform/TransformCache.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,103 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform; - -import java.util.Comparator; -import java.util.Observer; - - -/** - * TransformCache - * - * @author David Sean Taylor - * @version $Id: TransformCache.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public interface TransformCache extends Observer, Comparator -{ - /** - * Get the maximum size of the cache - * - * @return the current maximum size of the cache - */ - public int getMaxSize(); - - /** - * Set the new maximum size of the cache - * - * @param maxSize the maximum size of the cache - */ - public void setMaxSize(int maxSize); - - /** - * Get the eviction percentage of the cache - * - * @return the eviction percentage of the cache - */ - public int getEvictionPercentage(); - - /** - * Find out if TransformCache is enables - * - * @return the enable flag of the cache - */ - public boolean isEnabled(); - - - /** - * Put a value in the TransformCache keyed off with the TransformId and the - * DocumentId. - * @param key - * @param document - */ - public void put(String key, Object document, long timeToLive); - - /** - * Remove a unique value keyed off with the TransformId and DocumentId from the - * cache. - * @param key - * @return Object - */ - public Object remove(String key); - - /** - * Retrieve the unique TransformCacheEntry keyed off with key - * @param key - * @return TransformCacheEntry - */ - public TransformCacheEntry get(String key); - - /** - * Retrieve the byte[] storing the transformed content for the transfomId - * and the documentId combination. - * @param transformId - * @param documentId - * @return Object - */ - public Object getDocument(String key); - - /** - * Construct the key for the TransformDocumentTreeMap cache - * @return String - */ - public String constructKey(String url, String stylesheet); - - - /** - * Clear the Transform Cache - */ - public void clearCache(); - -} Index: src/java/org/apache/portals/applications/transform/TransformCacheEntry.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/TransformCacheEntry.java diff -N src/java/org/apache/portals/applications/transform/TransformCacheEntry.java --- src/java/org/apache/portals/applications/transform/TransformCacheEntry.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,123 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform; - -import java.util.Date; - - -/** - * TransformCacheEntry - * - * @author David Sean Taylor - * @version $Id: TransformCacheEntry.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class TransformCacheEntry -{ - protected String key; - protected Object document; - protected long lastAccessed; - protected long timeToLive = 15 * 60 * 1000; // in seconds, 15 minutes - - private TransformCacheEntry() - { - } - - /** - * Constructs a TransformCacheEntry object - * - * @param key - * @param timeToLive seconds to keep this in the cache - * @param document The user specific content being cached - */ - public TransformCacheEntry(String key, Object document, long timeToLive) - { - this.key = key; - this.document = document; - this.timeToLive = timeToLive; - this.lastAccessed = new Date().getTime(); - } - - - /** - * Set the cache's last accessed stamp - * - * @param lastAccessed the cache's last access stamp - */ - public void setLastAccessed(long lastAccessed) - { - this.lastAccessed = lastAccessed; - } - - /** - * Get the cache's lastAccessed stamp - * - * @return the cache's last accessed stamp - */ - public long getLastAccessed() - { - return this.lastAccessed; - } - - /** - * Set the Document in the cache - * - * @param document the document being cached - */ - public void setDocument(Object document) - { - this.document = document; - } - - /** - * Get the Document - * - * @return the document being cached - */ - public Object getDocument() - { - return this.document; - } - - - /** - * @return Returns the key. - */ - public String getKey() - { - return key; - } - /** - * @param key The key to set. - */ - public void setKey(String key) - { - this.key = key; - } - /** - * @return Returns the timeToLive. - */ - public long getTimeToLive() - { - return timeToLive; - } - /** - * @param timeToLive The timeToLive in seconds - */ - public void setTimeToLive(long timeToLive) - { - this.timeToLive = timeToLive; - } -} Index: src/java/org/apache/portals/applications/transform/TransformException.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/TransformException.java diff -N src/java/org/apache/portals/applications/transform/TransformException.java --- src/java/org/apache/portals/applications/transform/TransformException.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform; - - -/** - * TransformException - * - * @author David Sean Taylor - * @version $Id: TransformException.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class TransformException extends Exception -{ - /** - * Constructs a new TransformException without specified detail - * message. - */ - public TransformException() - { - } - - /** - * Constructs a new TransformException with specified detail - * message. - * - * @param msg the error message. - */ - public TransformException(String msg) - { - super(msg); - } - - /** - * Constructs a new TransformException with specified nested - * Throwable. - * - * @param nested the exception or error that caused this exception - * to be thrown. - */ - public TransformException(Throwable nested) - { - super(nested); - } - - /** - * Constructs a new TransformException with specified detail - * message and nested Throwable. - * - * @param msg the error message. - * @param nested the exception or error that caused this exception - * to be thrown. - */ - public TransformException(String msg, Throwable nested) - { - super(msg, nested); - } -} Index: src/java/org/apache/portals/applications/transform/TransformObjectPublisher.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/TransformObjectPublisher.java diff -N src/java/org/apache/portals/applications/transform/TransformObjectPublisher.java --- src/java/org/apache/portals/applications/transform/TransformObjectPublisher.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,52 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform; - -import java.util.Observable; - - -/** - * Transform Object Publisher base implementation. - * - * The Transform Object Publisher notifies observers by publishing messages when - * the transforms have been updated. - * - * @author David Sean Taylor - * @version $Id: TransformObjectPublisher.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class TransformObjectPublisher extends Observable -{ - /** - * Constructor - * - */ - public TransformObjectPublisher() - { - } - /** - * Notify all observers that object has changed. - * @see java.util.Observable#notifyObservers(Object ob) - * @param transform - */ - public void publish(Transform transform) - { - setChanged(); - notifyObservers(transform); - } - - - -} Index: src/java/org/apache/portals/applications/transform/impl/JetspeedTransform.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/impl/JetspeedTransform.java diff -N src/java/org/apache/portals/applications/transform/impl/JetspeedTransform.java --- src/java/org/apache/portals/applications/transform/impl/JetspeedTransform.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,372 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform.impl; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.Writer; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TemplatesHandler; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; - -import org.apache.portals.applications.transform.Transform; -import org.apache.portals.applications.transform.TransformException; -import org.apache.portals.applications.transform.TransformObjectPublisher; -import org.apache.portals.applications.util.Streams; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -/** - * TransformComponent - * - * @author David Sean Taylor - * @version $Id: JetspeedTransform.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class JetspeedTransform implements Transform -{ - public JetspeedTransform() - { - // TODO: make all JAX factories configurable - synchronized (mutex) - { - if (transformerFactory == null) - { - System.setProperty(JAX_TRANSFORM_PROPERTY, jaxTransformFactoryProp); - System.setProperty(JAX_SAX_PARSER_PROPERTY, jaxSaxFactoryProp); - System.setProperty(JAX_DOM_PARSER_PROPERTY, jaxDomFactoryProp); - - TransformerFactory tFactory = TransformerFactory.newInstance(); - domFactory = DocumentBuilderFactory.newInstance(); - domFactory.setValidating(false); - saxFactory = SAXParserFactory.newInstance(); - saxFactory.setValidating(false); - //if (!tFactory.getFeature(SAXTransformerFactory.FEATURE)) { throw new TransformException( - // "Invalid SAX Tranformer. Doesn't support SAX"); } - transformerFactory = ((SAXTransformerFactory) tFactory); - } - } - - publisher = new TransformObjectPublisher(); - } - - private static DocumentBuilderFactory domFactory = null; - - private static SAXParserFactory saxFactory = null; - - private static SAXTransformerFactory transformerFactory = null; - - // - // JAXP Service Configuration - // - private final static String CONFIG_JAX_FACTORY_SAX = "jax.factory.sax"; - - private final static String jaxSaxFactoryProp = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; - - private final static String CONFIG_JAX_FACTORY_DOM = "jax.factory.dom"; - - private final static String jaxDomFactoryProp = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; - - private final static String CONFIG_JAX_FACTORY_TRANSFORM = "jax.factory.transform"; - - private final static String jaxTransformFactoryProp = "org.apache.xalan.processor.TransformerFactoryImpl"; - - private final static Object mutex = new Object(); - - // - // JAXP System Wide Properties - // - private static final String JAX_TRANSFORM_PROPERTY = "javax.xml.transform.TransformerFactory"; - - private static final String JAX_SAX_PARSER_PROPERTY = "javax.xml.parsers.SAXParserFactory"; - - private static final String JAX_DOM_PARSER_PROPERTY = "javax.xml.parsers.DocumentBuilderFactory"; - - // DTD Map - static private Map dtds = new HashMap(); - - private TransformObjectPublisher publisher = null; - - public void transform(String xslt, InputSource inputSource, OutputStream os, Map parameters) - throws TransformException - { - if (xslt == null) - { - try - { // if no stylesheet specified simply drain the stream - Streams.drain(inputSource.getByteStream(), os); - } - catch (IOException e) - { - throw new TransformException(e); - } - } - else - { - transformStream(xslt, inputSource, new StreamResult(os), parameters); - } - } - - public void transform(String xslt, InputSource inputSource, Writer writer, Map parameters) - throws TransformException - { - if (xslt == null) - { - try - { // if no stylesheet specified simply drain the stream - Streams.drain(inputSource.getByteStream(), writer); - } - catch (IOException e) - { - throw new TransformException(e); - } - } - else - { - transformStream(xslt, inputSource, new StreamResult(writer), parameters); - } - } - - private static void transformStream(String xslt, InputSource inputSource, StreamResult streamResult, Map parameters) - throws TransformException - { - if (xslt == null) { throw new TransformException("Invalid Transform, no stylesheet set!"); } - - // - // create a new document builder to load the XML file for transformation - // - DocumentBuilder docBuilder = null; - try - { - docBuilder = domFactory.newDocumentBuilder(); - docBuilder.setEntityResolver(new TransformDTDEntityResolver(dtds)); - - } - catch (ParserConfigurationException e) - { - throw new TransformException("Failed to load JAX Document Builder: " + e.toString()); - } - - try - { - // Create a ContentHandler to handle parsing of the stylesheet. - TemplatesHandler templatesHandler = transformerFactory.newTemplatesHandler(); - - // Create an XMLReader and set its ContentHandler. - XMLReader reader = XMLReaderFactory.createXMLReader(); - reader.setContentHandler(templatesHandler); - - // Set it to solve Entities via cache - reader.setEntityResolver(new TransformDTDEntityResolver(dtds)); - - // - // Get the stylesheet's content from the deployment - // - java.io.FileInputStream is = new java.io.FileInputStream(xslt); - InputStreamReader ssreader = new InputStreamReader(is); - - // Parse the stylesheet. - final InputSource xstyle = new InputSource(ssreader); - xstyle.setSystemId(xslt); - reader.parse(xstyle); - - //Get the Templates object from the ContentHandler. - Templates templates = templatesHandler.getTemplates(); - - // Create a ContentHandler to handle parsing of the XML source. - TransformerHandler handler = transformerFactory.newTransformerHandler(templates); - - // Reset the XMLReader's ContentHandler. - reader.setContentHandler(handler); - - // - // Parse the Document into a DOM tree - // - // - org.w3c.dom.Document doc = docBuilder.parse(inputSource); - - // reader.setProperty("http://xml.org/sax/properties/lexical-handler", - // handler); - - final Transformer processor = handler.getTransformer(); - - // - // Get the transform variables (parameters) - // - Iterator keys = parameters.keySet().iterator(); - while (keys.hasNext()) - { - String name = (String) keys.next(); - String value = (String) parameters.get(name); - processor.setParameter(name, value); - } - - // - // do the transformation now - // - processor.transform(new DOMSource(doc), streamResult); - - } - catch (Exception e) - { - throw new TransformException("Error in Transformation: " + e.toString()); - } - } - - private static void transformStream(String xslt, Document document, StreamResult streamResult, Map parameters) - throws TransformException - { - if (xslt == null) { throw new TransformException("Invalid Transform, no stylesheet set!"); } - - synchronized (mutex) - { - if (transformerFactory == null) - { - System.setProperty(JAX_TRANSFORM_PROPERTY, jaxTransformFactoryProp); - System.setProperty(JAX_SAX_PARSER_PROPERTY, jaxSaxFactoryProp); - System.setProperty(JAX_DOM_PARSER_PROPERTY, jaxDomFactoryProp); - - TransformerFactory tFactory = TransformerFactory.newInstance(); - domFactory = DocumentBuilderFactory.newInstance(); - domFactory.setValidating(false); - saxFactory = SAXParserFactory.newInstance(); - saxFactory.setValidating(false); - if (!tFactory.getFeature(SAXTransformerFactory.FEATURE)) { throw new TransformException( - "Invalid SAX Tranformer. Doesn't support SAX"); } - transformerFactory = ((SAXTransformerFactory) tFactory); - } - } - - // - // create a new document builder to load the XML file for transformation - // - DocumentBuilder docBuilder = null; - try - { - docBuilder = domFactory.newDocumentBuilder(); - docBuilder.setEntityResolver(new TransformDTDEntityResolver(dtds)); - - } - catch (ParserConfigurationException e) - { - throw new TransformException("Failed to load JAX Document Builder: " + e.toString()); - } - - try - { - // Create a ContentHandler to handle parsing of the stylesheet. - TemplatesHandler templatesHandler = transformerFactory.newTemplatesHandler(); - - // Create an XMLReader and set its ContentHandler. - XMLReader reader = XMLReaderFactory.createXMLReader(); - reader.setContentHandler(templatesHandler); - - // Set it to solve Entities via cache - reader.setEntityResolver(new TransformDTDEntityResolver(dtds)); - - // - // Get the stylesheet's content from the deployment - // - java.io.FileInputStream is = new java.io.FileInputStream(xslt); - InputStreamReader ssreader = new InputStreamReader(is); - - // Parse the stylesheet. - final InputSource xstyle = new InputSource(ssreader); - xstyle.setSystemId(xslt); - reader.parse(xstyle); - - //Get the Templates object from the ContentHandler. - Templates templates = templatesHandler.getTemplates(); - - // Create a ContentHandler to handle parsing of the XML source. - TransformerHandler handler = transformerFactory.newTransformerHandler(templates); - - // Reset the XMLReader's ContentHandler. - reader.setContentHandler(handler); - - // - // Parse the Document into a DOM tree - // - // - // org.w3c.dom.Document doc = docBuilder.parse(inputSource); - - // reader.setProperty("http://xml.org/sax/properties/lexical-handler", - // handler); - - final Transformer processor = handler.getTransformer(); - - // - // Get the transform variables (parameters) - // - Iterator keys = parameters.keySet().iterator(); - while (keys.hasNext()) - { - String name = (String) keys.next(); - String value = (String) parameters.get(name); - processor.setParameter(name, value); - } - - // - // do the transformation now - // - processor.transform(new DOMSource(document), streamResult); - - } - catch (Exception e) - { - throw new TransformException("Error in Transformation: " + e.toString()); - } - - } - - public void transform(String xslt, Document document, OutputStream os, Map parameters) - throws TransformException - { - if (xslt == null) - { - throw new TransformException("xslt is null"); - } - else - { - transformStream(xslt, document, new StreamResult(os), parameters); - } - } - - /* (non-Javadoc) - * @see org.apache.jetspeed.syndication.services.transform.TransformService#getPublisher() - */ - public TransformObjectPublisher getPublisher() - { - return publisher; - } - - -} \ No newline at end of file Index: src/java/org/apache/portals/applications/transform/impl/MemoryTransformCache.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/impl/MemoryTransformCache.java diff -N src/java/org/apache/portals/applications/transform/impl/MemoryTransformCache.java --- src/java/org/apache/portals/applications/transform/impl/MemoryTransformCache.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,231 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform.impl; - -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Observable; -import java.util.TreeMap; - -import org.apache.portals.applications.transform.Transform; -import org.apache.portals.applications.transform.TransformCache; -import org.apache.portals.applications.transform.TransformCacheEntry; - - -/** - * TransformCacheComponent - * - * @author David Sean Taylor - * @version $Id: MemoryTransformCache.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class MemoryTransformCache implements TransformCache -{ - private boolean debug = true; - private int maxSize = 100; - private int evictionPercentage = 10; - private boolean enable = true; - - private Transform transform = null; - private TreeMap cache = null; - private Object lock = new Object(); - - /** - * Spring constructor injection - * - */ - public MemoryTransformCache(Transform transform, int maxSize, int evictionPercentage, boolean enable, boolean debug) - { - this.transform = transform; - cache = new TreeMap(); - this.maxSize = maxSize; - this.evictionPercentage = evictionPercentage; - - transform.getPublisher().addObserver(this); - } - - public int getMaxSize() - { - return maxSize; - } - - public void setMaxSize(int maxSize) - { - this.maxSize = maxSize; - } - - public int getEvictionPercentage() - { - return this.evictionPercentage; - } - - public boolean isEnabled() - { - return enable; - } - - public void put(String key, Object document, long timeToLive) - { - TransformCacheEntry entry = new TransformCacheEntry(key, document, timeToLive); - if (cache.size() > getMaxSize()) - { - evict(); - } - synchronized(lock) - { - cache.put(key, entry); - } - if (debug) - { - System.out.println("Transformed content put in cache! Transform: " - + key); - } - } - - /** - * The eviction policy will keep n items in the cache, and then start evicting - * x items ordered-by least used first. - * n = max size of cache - * x = (eviction_percentage/100) * n - * - */ - protected void evict() - { - if (debug) - { - System.out.println("Calling evict... cacheSize: "+ - cache.size()+" maxSize: "+getMaxSize()); - } - synchronized (lock) - { - if (this.getMaxSize() >= cache.size()) - { - return; - } - - List list = new LinkedList( cache.values()); - Collections.sort(list, this); - - int count = 0; - int limit = (getMaxSize() * getEvictionPercentage())/100 ; - if (limit <= 0) limit = 1; - - for (Iterator it = list.iterator(); it.hasNext(); ) - { - if (count >= limit) - { - break; - } - - TransformCacheEntry entry = (TransformCacheEntry) it.next(); - if (debug) - { - System.out.println("Evicting: "+ entry.getKey()); - } - cache.remove(entry.getKey()); - - count++; - } - } - } - - - /* (non-Javadoc) - * @see org.apache.jetspeed.syndication.services.transform.TransformCacheService#remove(java.lang.String, java.lang.String) - */ - public Object remove(String key) - { - TransformCacheEntry entry = (TransformCacheEntry)cache.get(key); - if (entry == null) - { - return null; - } - synchronized(lock) - { - entry = (TransformCacheEntry)cache.remove(key); - } - return entry; - - } - - /* (non-Javadoc) - * @see org.apache.jetspeed.syndication.services.transform.TransformCacheService#get(java.lang.String, java.lang.String) - */ - public TransformCacheEntry get(String key) - { - TransformCacheEntry entry = (TransformCacheEntry)cache.get(key); - if (entry == null) - { - return null; - } - long now = new Date().getTime(); - long lifeTime = entry.getTimeToLive() * 1000; - if ((entry.getLastAccessed() + lifeTime) < now) - { - return null; // expire it - } - if (debug) - { - System.out.println("Transformed content found in cache! Transform: " - + key); - } - return entry; - } - - public Object getDocument(String key) - { - TransformCacheEntry entry = (TransformCacheEntry)get(key); - if (entry != null) - { - return entry.getDocument(); - } - return null; - } - - public int compare(Object o1, Object o2) - { - TransformCacheEntry e1 = (TransformCacheEntry)o1; - TransformCacheEntry e2 = (TransformCacheEntry)o2; - if (e1.getLastAccessed() < e2.getLastAccessed()) - { - return -1; - } - else if (e1.getLastAccessed() == e2.getLastAccessed()) - { - return 0; - } - return 1; - } - - public String constructKey(String url, String stylesheet) - { - return url + ":" + stylesheet; - } - - public void clearCache() - { - cache.clear(); - } - - public void update(Observable o, Object arg) - { - // TODO: write me - } - -} - Index: src/java/org/apache/portals/applications/transform/impl/TransformDTDEntityResolver.java =================================================================== RCS file: src/java/org/apache/portals/applications/transform/impl/TransformDTDEntityResolver.java diff -N src/java/org/apache/portals/applications/transform/impl/TransformDTDEntityResolver.java --- src/java/org/apache/portals/applications/transform/impl/TransformDTDEntityResolver.java 15 Nov 2004 06:06:41 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,87 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.transform.impl; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Map; - -import org.apache.portals.applications.util.Streams; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - - -/** - * TransformDTDEntityResolver - * - * @author David Sean Taylor - * @version $Id: TransformDTDEntityResolver.java,v 1.1 2004/11/15 06:06:41 taylor Exp $ - */ -public class TransformDTDEntityResolver implements EntityResolver -{ - private Map dtds; - - public TransformDTDEntityResolver(Map dtds) - { - this.dtds = dtds; - } - - /* (non-Javadoc) - * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String) - */ - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException - { - try - { - // System.out.println("TSER: ( " + publicId + " Taking " + systemId + " from cache"); - - byte[] dtd = (byte[])dtds.get(systemId); - if (dtd == null) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - URL url = new URL(systemId); - Streams.drain(url.openStream(), baos); - dtd = baos.toByteArray(); - synchronized(dtds) - { - dtds.put(systemId, dtd); - } - } - - if (dtd != null) - { - ByteArrayInputStream bais = new ByteArrayInputStream(dtd); - InputSource is = new InputSource(bais); - is.setPublicId( publicId ); - is.setSystemId( systemId ); - - return is; - } - - } - catch(Throwable t ) // java.io.IOException x - { - t.printStackTrace(); - } - - return null; - - } -} Index: src/java/org/apache/portals/applications/util/Streams.java =================================================================== RCS file: src/java/org/apache/portals/applications/util/Streams.java diff -N src/java/org/apache/portals/applications/util/Streams.java --- src/java/org/apache/portals/applications/util/Streams.java 15 Nov 2004 06:06:42 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,140 +0,0 @@ -/* - * Copyright 2000-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.portals.applications.util; - -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.io.InputStreamReader; - -/** - * Utility functions related to Streams. - * - * @author David Sean Taylor - * @version $Id: Streams.java,v 1.1 2004/11/15 06:06:42 taylor Exp $ - */ -public class Streams -{ - static final int BLOCK_SIZE=4096; - - public static void drain(InputStream r,OutputStream w) throws IOException - { - byte[] bytes=new byte[BLOCK_SIZE]; - try - { - int length=r.read(bytes); - while(length!=-1) - { - if(length!=0) - { - w.write(bytes,0,length); - } - length=r.read(bytes); - } - } - finally - { - bytes=null; - } - - } - - public static void drain(Reader r,Writer w) throws IOException - { - char[] bytes=new char[BLOCK_SIZE]; - try - { - int length=r.read(bytes); - while(length!=-1) - { - if(length!=0) - { - w.write(bytes,0,length); - } - length=r.read(bytes); - } - } - finally - { - bytes=null; - } - - } - - public static void drain(Reader r,OutputStream os) throws IOException - { - Writer w=new OutputStreamWriter(os); - drain(r,w); - w.flush(); - } - - public static void drain(InputStream is, Writer w) throws IOException - { - Reader r = new InputStreamReader(is); - drain(r,w); - w.flush(); - } - - public static byte[] drain(InputStream r) throws IOException - { - ByteArrayOutputStream bytes=new ByteArrayOutputStream(); - drain(r,bytes); - return bytes.toByteArray(); - } - - public static String getAsString(InputStream is) - { - int c=0; - char lineBuffer[]=new char[128], buf[]=lineBuffer; - int room= buf.length, offset=0; - try - { - loop: while (true) - { - // read chars into a buffer which grows as needed - switch (c = is.read() ) - { - case -1: break loop; - - default: if (--room < 0) - { - buf = new char[offset + 128]; - room = buf.length - offset - 1; - System.arraycopy(lineBuffer, 0, - buf, 0, offset); - lineBuffer = buf; - } - buf[offset++] = (char) c; - break; - } - } - } - catch(IOException ioe) - { - ioe.printStackTrace(); - } - if ((c == -1) && (offset == 0)) - { - return null; - } - return String.copyValueOf(buf, 0, offset); - } - -} Index: src/webapp/WEB-INF/jetspeed-portlet.xml =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/jetspeed-portlet.xml,v retrieving revision 1.1 diff -u -r1.1 jetspeed-portlet.xml --- src/webapp/WEB-INF/jetspeed-portlet.xml 15 Nov 2004 06:06:41 -0000 1.1 +++ src/webapp/WEB-INF/jetspeed-portlet.xml 13 Jan 2005 23:08:23 -0000 @@ -23,4 +23,10 @@ RSS Portlets J2 Team + + + RomeRSS + Rome Rss + J2 Team + Index: src/webapp/WEB-INF/portlet.xml =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/portlet.xml,v retrieving revision 1.1 diff -u -r1.1 portlet.xml --- src/webapp/WEB-INF/portlet.xml 15 Nov 2004 06:06:41 -0000 1.1 +++ src/webapp/WEB-INF/portlet.xml 13 Jan 2005 23:08:23 -0000 @@ -13,148 +13,65 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + --> - - - - HelpPage - /WEB-INF/view/rss-help.html - - - EditPage - /WEB-INF/view/edit-prefs.vm - - - stylesheet - /WEB-INF/xsl/rss.xsl - Default RSS Transform XSLT - - - stylesheet.text/html - /WEB-INF/xsl/rss.xsl - HTML RSS Transform XSLT - - - stylesheet.text/vnd.wap.wml - /WEB-INF/xsl/rss-wml.xsl - WML RSS Transform XSLT - - RSS - RSS Portlet - RSS Portlet - org.apache.portals.applications.rss.RSSPortlet - 15 - - text/html - VIEW - EDIT - HELP - - - text/vnd.wap.wml - VIEW - - en - fr - org.apache.portals.applications.rss.resources.RssResources - - RSS Portlet - RSS - RSS,syndication - - - - url - http://www.npr.org/rss/rss.php?topicId=2 - - - itemdisplayed - 15 - - - openinpopup - true - - - showdescription - true - - - showtitle - true - - - showtextinput - true - - - - - - - HelpPage - /WEB-INF/view/rss-help.html - - - EditPage - /WEB-INF/view/edit-prefs.vm - - - stylesheet - /WEB-INF/xsl/rss.xsl - Default RSS Transform XSLT - - RomeRSS - Rome RSS Portlet - Rome RSS Portlet - org.apache.portals.applications.rss.RomeRSSPortlet - 15 - - text/html - VIEW - EDIT - HELP - - - text/vnd.wap.wml - VIEW - - en - fr - org.apache.portals.applications.rss.resources.RssResources - - Rome RSS Portlet - Rome RSS - RSS,atom,syndication - - - - url - http://www.npr.org/rss/rss.php?topicId=4 - - - itemdisplayed - 15 - - - openinpopup - true - - - showdescription - true - - - showtitle - true - - - showtextinput - true - - - - - - + + Rome RSS Portlet + RomeRSS + Rss Portlet + org.apache.portals.applications.rss.RomeRSSPortlet + + AllowPreferences + true + + + ViewPage + /WEB-INF/view/view.vm + + + EditPage + /WEB-INF/view/edit-prefs.vm + + + HelpPage + /WEB-INF/view/rss-help.html + + 0 + + text/html + VIEW + EDIT + HELP + + en + fr + org.apache.portals.applications.rss.resources.RssResources + + + url + http://www.npr.org/rss/rss.php?topicId=4 + + + itemdisplayed + 15 + + + openinpopup + true + + + showdescription + true + + + showtitle + true + + + showtextinput + false + + + + \ No newline at end of file Index: src/webapp/WEB-INF/web.xml =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/web.xml,v retrieving revision 1.1 diff -u -r1.1 web.xml --- src/webapp/WEB-INF/web.xml 15 Nov 2004 06:06:41 -0000 1.1 +++ src/webapp/WEB-INF/web.xml 13 Jan 2005 23:08:23 -0000 @@ -14,13 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - + - RSS Portlet Application - Apache Portals Applications: RSS PA - - + velocity org.apache.portals.bridges.velocity.BridgesVelocityViewServlet @@ -34,23 +30,10 @@ 10 - - - - springinit - org.apache.portals.applications.rss.servlets.SpringInitServlet - - spring-configuration - /WEB-INF/spring/spring-portlet-configuration.xml - - 1 - - - + + velocity *.vm - - - - + + \ No newline at end of file Index: src/webapp/WEB-INF/spring/spring-portlet-configuration.xml =================================================================== RCS file: src/webapp/WEB-INF/spring/spring-portlet-configuration.xml diff -N src/webapp/WEB-INF/spring/spring-portlet-configuration.xml --- src/webapp/WEB-INF/spring/spring-portlet-configuration.xml 15 Nov 2004 06:06:42 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,32 +0,0 @@ - - - - - Spring Portlet Components - - - - - - - - - - - 100 - - 10 - - true - - true - - - - - \ No newline at end of file Index: src/webapp/WEB-INF/view/edit-prefs.vm =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed-2/applications/rss/src/webapp/WEB-INF/view/edit-prefs.vm,v retrieving revision 1.2 diff -u -r1.2 edit-prefs.vm --- src/webapp/WEB-INF/view/edit-prefs.vm 15 Nov 2004 18:40:44 -0000 1.2 +++ src/webapp/WEB-INF/view/edit-prefs.vm 13 Jan 2005 23:08:23 -0000 @@ -1,10 +1,33 @@ +#* +Copyright 2004 The Apache Software Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*# + +#** + +@author Christophe Lombart +@version $Id: Exp $ + +*#

Edit Preferences

+
#foreach ($pref in $prefs) -#prefField($pref.Key $pref.Value "40") + #prefField($pref.Key $pref.Value "40") #end
Index: src/webapp/WEB-INF/xsl/rss-wml.xsl =================================================================== RCS file: src/webapp/WEB-INF/xsl/rss-wml.xsl diff -N src/webapp/WEB-INF/xsl/rss-wml.xsl --- src/webapp/WEB-INF/xsl/rss-wml.xsl 15 Nov 2004 06:06:40 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -

- -
-

- -
-
- - - -

- -
-

-
- - - - -

- -
-

- -
-
- - - -

- -
-

-
- - - - - - - - - - - - - - $$ - - - - - - - - - -
Index: src/webapp/WEB-INF/xsl/rss.xsl =================================================================== RCS file: src/webapp/WEB-INF/xsl/rss.xsl diff -N src/webapp/WEB-INF/xsl/rss.xsl --- src/webapp/WEB-INF/xsl/rss.xsl 15 Nov 2004 06:06:40 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,211 +0,0 @@ - - - - - - - - - - - - - - - -
- -
-
- - -
- -
-
- - - - -

- - -

-
-
    - -
- - - -
- - - - -

- - - - - - - - - - _blank - - - - - -

-
-
    - -
- - - -
- - - -
  • - - - - _blank - - - - -
    -
    -
  • -
    - - - -
  • - - - - _blank - - - - -
    -
    -
  • -
    - - - -
    - - - -
    - - -
    -
    - - - -
    - - - - - - _blank - - - right - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _blank - - - right - 0 - - - - - - - - - - - - - - - - - - - - -
    - - - Index: todo.txt =================================================================== RCS file: todo.txt diff -N todo.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ todo.txt 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +* Cache ? Index: src/java/org/apache/portals/applications/rss/RssInfo.java =================================================================== RCS file: src/java/org/apache/portals/applications/rss/RssInfo.java diff -N src/java/org/apache/portals/applications/rss/RssInfo.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/java/org/apache/portals/applications/rss/RssInfo.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,103 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.portals.applications.rss; + +import com.sun.syndication.feed.synd.SyndFeed; + +/** + * + * @author Lombart Christophe + * @version $Id: Exp $ + */ +public class RssInfo +{ + private SyndFeed feed; + private int itemdisplayed; + private boolean openinpopup; + private boolean showdescription; + private boolean showtitle; + private boolean showtextinput; + + + + /** + * @param feed + * @param itemdisplayed + * @param openinpopup + * @param showdescription + * @param showtitle + * @param showtextinput + */ + public RssInfo(SyndFeed feed, int itemdisplayed, boolean openinpopup, boolean showdescription, boolean showtitle, + boolean showtextinput) + { + this.feed = feed; + this.itemdisplayed = itemdisplayed; + this.openinpopup = openinpopup; + this.showdescription = showdescription; + this.showtitle = showtitle; + this.showtextinput = showtextinput; + } + + public SyndFeed getFeed() + { + return feed; + } + public void setFeed(SyndFeed feed) + { + this.feed = feed; + } + public int getItemdisplayed() + { + return itemdisplayed; + } + public void setItemdisplayed(int itemdisplayed) + { + this.itemdisplayed = itemdisplayed; + } + public boolean isOpeninpopup() + { + return openinpopup; + } + public void setOpeninpopup(boolean openinpopup) + { + this.openinpopup = openinpopup; + } + public boolean isShowdescription() + { + return showdescription; + } + public void setShowdescription(boolean showdescription) + { + this.showdescription = showdescription; + } + public boolean isShowtextinput() + { + return showtextinput; + } + public void setShowtextinput(boolean showtextinput) + { + this.showtextinput = showtextinput; + } + public boolean isShowtitle() + { + return showtitle; + } + public void setShowtitle(boolean showtitle) + { + this.showtitle = showtitle; + } +} Index: src/webapp/WEB-INF/veltag.tld =================================================================== RCS file: src/webapp/WEB-INF/veltag.tld diff -N src/webapp/WEB-INF/veltag.tld --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/webapp/WEB-INF/veltag.tld 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,51 @@ + + + + + + 1.0 + 1.2 + vel + /tags/velocity + Velocity + Velocity + + + velocity + org.apache.taglibs.velocity.VelocityTag + JSP + Velocity and JSP, together at last + + strictaccess + false + + + + Index: src/webapp/WEB-INF/view/view.vm =================================================================== RCS file: src/webapp/WEB-INF/view/view.vm diff -N src/webapp/WEB-INF/view/view.vm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/webapp/WEB-INF/view/view.vm 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,62 @@ +#* +Copyright 2004 The Apache Software Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*# + +#** + +@author Christophe Lombart +@version $Id: Exp $ + +*# +#set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale)) + +#set ($syncFeed = $rssInfo.getFeed()) + +#if ($rssInfo.isShowtitle()) + $syncFeed.getTitle() + #set ($feedImage = $syncFeed.getImage()) + #if($feedImage) + + $feedImage.getTitle() + + #end + + #set ($syncEntries = $syncFeed.getEntries()) + + #if($rssInfo.isShowtextinput()) +
    + $syncFeed.getDescription() +
    + + +
    + #end +#end