Forums

Home » Liferay Portal » English » Liferay Legacy

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Benjamin Bratkus
Adding myRssPortlet to Liferay
March 6, 2006 1:27 AM
Answer

Benjamin Bratkus

Rank: Junior Member

Posts: 61

Join Date: March 5, 2006

Recent Posts

Hello community, <br /><br />i want to deploy my own rss portlet into liferay but i get the following msg instead of my portlet &quot;RssPortlet is temporarily unavailable.&quot; actually i don&#39;t know whats wrong. can anyone give me some additional hints? i tryed to integrate the portlet via your doku &quot;hot deployment&quot; i &#39;ve used the ant task deply in the folder /myPortlets which i created in the root folder of liferay in one layer with the folders lib, client, bin, server.<br /><br />best regards,<br /><br />ben<br /><br />war-structure:<br /><br />/WEB-INF<br /> /tlds/taglib.tld<br /> /tld/portlet.tld<br /> /lib/xalan-2.4.1.jar<br /> /rss4j-0.9.2.jar<br /> /conf/html.xsl<br /> /Rss10.xsl<br /> /Rss20.xml<br /> /classes/....../RssPortlet.class<br /> /portlet.xml<br /> /web.xml<br />/pics<br />/META-INF<br />/jsp<br />/data<br /><br /><br /><br />portlet.xml<br /><br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;portlet-app xmlns=&quot;http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd&quot; <br /> version=&quot;1.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; <br /> xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd<br /><a href="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd&quot;&gt;" target="_blank">http://java.sun.com/xml/ns/portlet/portlet...0.xsd&quot;&gt;</a><br /> &lt;portlet&gt;<br /> &lt;portlet-name&gt;RssPortlet&lt;/portlet-name&gt;<br /> &lt;portlet-class&gt;de.oio.portlets.RssPortlet&lt;/portlet-class&gt;<br /> &#60;&#33;-- a xsl file for the rss version 1.0 --&#62;<br /> &lt;init-param&gt;<br /> &lt;name&gt;RSS10_XSL&lt;/name&gt;<br /> &lt;value&gt;/WEB-INF/conf/Rss10.xsl&lt;/value&gt;<br /> &lt;/init-param&gt;<br /> &#60;&#33;-- yet another xsl file for the rss version 2.0 --&#62;<br /> &lt;init-param&gt;<br /> &lt;name&gt;RSS20_XSL&lt;/name&gt;<br /> &lt;value&gt;/WEB-INF/conf/Rss20.xsl&lt;/value&gt;<br /> &lt;/init-param&gt;<br /> &#60;&#33;-- starting url for reading rss --&#62;<br /> &lt;init-param&gt;<br /> &lt;name&gt;url&lt;/name&gt;<br /> &lt;value&gt;http://www.oio.de/xml/feeds/oio-rss.xml&lt;/value&gt;<br /> &lt;/init-param&gt;<br /> &lt;expiration-cache&gt;30&lt;/expiration-cache&gt;<br /> &lt;supports&gt;<br /> &lt;mime-type&gt;text/html&lt;/mime-type&gt;<br /> &lt;portlet-mode&gt;edit&lt;/portlet-mode&gt;<br /> &lt;portlet-mode&gt;help&lt;/portlet-mode&gt;<br /> &lt;/supports&gt;<br /> &lt;supported-locale&gt;de-DE&lt;/supported-locale&gt;<br /> &lt;portlet-info&gt;<br /> &lt;title&gt;RssPortlet&lt;/title&gt;<br /> &lt;short-title&gt;RSS&lt;/short-title&gt;<br /> &lt;keywords&gt;RSS&lt;/keywords&gt;<br /> &lt;/portlet-info&gt;<br /> &lt;portlet-preferences&gt;<br /> &lt;preference&gt;<br /> &lt;name&gt;RssXml&lt;/name&gt;<br /> &lt;value&gt;http://www.oio.de/xml/feeds/oio-rss.xml&lt;/value&gt;<br /> &lt;value&gt;http://www.gnupg.org/news.en.rss&lt;/value&gt;<br /> &lt;value&gt;http://developers.sun.com/rss/sdn.xml&lt;/value&gt;<br /> &lt;value&gt;<br /> <a href="http://www.theserverside.com/rss/theserverside-0.9.rdf&lt;/value&gt;" target="_blank">http://www.theserverside.com/rss/theserver...f&lt;/value&gt;</a><br /> &lt;value&gt;http://rss.com.com/2547-12-0-20.xml&lt;/value&gt;<br /> &lt;value&gt;<br /> <a href="http://headlines.internet.com/internetnews/top-news/news.rss&lt;/value&gt;" target="_blank">http://headlines.internet.com/internetnews...s&lt;/value&gt;</a><br /> &lt;value&gt;http://www.sciencedaily.com/newsfeed.xml&lt;/value&gt;<br /> &lt;value&gt;http://www.heise.de/newsticker/heise.rdf&lt;/value&gt;<br /> &lt;value&gt;<br /> <a href="http://www.spiegel.de/schlagzeilen/rss/0,5291,,00.xml&lt;/value&gt;" target="_blank">http://www.spiegel.de/schlagzeilen/rss/0,5...l&lt;/value&gt;</a><br /> &lt;value&gt;http://www.javamagazin.de/rss/?version=2.0&lt;/value&gt;<br /> &lt;/preference&gt;<br /> &lt;/portlet-preferences&gt;<br /> &lt;/portlet&gt;<br />&lt;/portlet-app&gt;<br /><br />web.xml<br /><br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; <br /> &lt;&#33;DOCTYPE web-app (View Source for full doctype...)&gt; <br />- &lt;web-app&gt;<br /> &lt;display-name&gt;RssPortlet&lt;/display-name&gt; <br /> &lt;/web-app&gt;<br /><br />class <br /><br />package de.oio.portlets;<br /><br />import java.io.IOException;<br />import java.io.InputStream;<br />import java.io.PrintWriter;<br />import java.net.MalformedURLException;<br />import java.net.URL;<br />import java.util.Arrays;<br />import java.util.TreeSet;<br /><br />import javax.portlet.ActionRequest;<br />import javax.portlet.ActionResponse;<br />import javax.portlet.GenericPortlet;<br />import javax.portlet.PortletException;<br />import javax.portlet.PortletMode;<br />import javax.portlet.PortletPreferences;<br />import javax.portlet.PortletSecurityException;<br />import javax.portlet.PortletURL;<br /><br />import javax.portlet.RenderRequest;<br />import javax.portlet.RenderResponse;<br />import javax.portlet.UnavailableException;<br />import javax.xml.parsers.DocumentBuilder;<br />import javax.xml.parsers.DocumentBuilderFactory;<br />import javax.xml.parsers.ParserConfigurationException;<br />import javax.xml.transform.Source;<br />import javax.xml.transform.Templates;<br />import javax.xml.transform.Transformer;<br />import javax.xml.transform.TransformerConfigurationException;<br />import javax.xml.transform.TransformerException;<br />import javax.xml.transform.TransformerFactory;<br />import javax.xml.transform.dom.DOMSource;<br />import javax.xml.transform.stream.StreamResult;<br />import javax.xml.transform.stream.StreamSource;<br /><br />import org.w3c.dom.Document;<br />import org.w3c.dom.Element;<br />import org.xml.sax.SAXException;<br /><br />/**<br /> * <br /> * <br /> * @author Orientation in Objects<br /> * <br /> * <br /> * @version 1.0 <br /> *<br /> * <br /> */<br /><br />public class RssPortlet extends GenericPortlet {<br /><br /> /* content type? */<br /> private static final String CONTENT_TYPE = &quot;text/html;charset=UTF-8&quot;;<br /><br /> /* Rss preferences string */<br /> private static final String RSS_XML_PREFS = &quot;RssXml&quot;;<br /><br /> /* Rss preferences default */<br /> private static final String[] RSS_XML_DEFAULT = new String[] { &quot;http://www.oio.de/xml/feeds/oio-rss.xml&quot; };<br /><br /> /* the compiled xsl for the version 1.0 */<br /> private Templates template10;<br /><br /> /* the compiled xsl for the version 2.0 */<br /> private Templates template20;<br /><br /> /**<br /> * the init method compiling the xsl and put the xsl in the application<br /> * scope<br /> */<br /> public void init() {<br /> try {<br /> String rss10 = this.getInitParameter(&quot;RSS10_XSL&quot;);<br /> String rss20 = this.getInitParameter(&quot;RSS20_XSL&quot;);<br /> this.template10 = this.getTemplateFromFile(rss10);<br /> this.template20 = this.getTemplateFromFile(rss20);<br /> } catch (Exception e) {<br /> e.printStackTrace();<br /> }<br /> }<br /><br /> /**<br /> * the processAction method reacts on a portlet action<br /> * <br /> */<br /> public void processAction(ActionRequest request, ActionResponse response)<br /> throws UnavailableException, PortletSecurityException, PortletException, IOException {<br /><br /> String errorMessage = null;<br /> try {<br /> checkPreferences(request);<br /> } catch (Exception e) {<br /> throw new PortletException(e);<br /> }<br /><br /> String url = request.getParameter(&quot;inputXml&quot;);<br /><br /> if ((url &#33;= null) &amp;&amp; url.startsWith(&quot;http&quot;)) {<br /> try {<br /> new URL(url).openStream();<br /> PortletPreferences prefs = request.getPreferences();<br /> TreeSet existingPrefs = new TreeSet(Arrays.asList(prefs.getValues(RSS_XML_PREFS,<br /> RSS_XML_DEFAULT)));<br /> existingPrefs.add(url);<br /> prefs.setValues(RSS_XML_PREFS, (String[]) existingPrefs.toArray(new String[0]));<br /> prefs.store();<br /><br /> } catch (Exception e) {<br /> errorMessage = e.getMessage();<br /> }<br /><br /> response.setRenderParameter(&quot;selectXml&quot;, url);<br /> response.setRenderParameter(&quot;inputXml&quot;, url);<br /> response.setPortletMode(PortletMode.VIEW);<br /><br /> if (null &#33;= errorMessage) {<br /> response.setRenderParameter(&quot;errorMessage&quot;, errorMessage);<br /> }<br /><br /> }<br /><br /> String selectXml = request.getParameter(&quot;selectXml&quot;);<br /><br /> if (null &#33;= selectXml) {<br /> response.setRenderParameter(&quot;selectXml&quot;, selectXml);<br /> }<br /><br /> }<br /><br /><br /> private void checkPreferences(ActionRequest request) throws Exception {<br /><br /> String[] checkPrefs = request.getParameterValues(&quot;check&quot;);<br /> if (checkPrefs &#33;= null) {<br /> PortletPreferences prefs = request.getPreferences();<br /> TreeSet prefTreeSet = new TreeSet(Arrays.asList(checkPrefs));<br /> prefs.setValues(RSS_XML_PREFS, (String[]) prefTreeSet.toArray(new String[0]));<br /> prefs.store();<br /> }<br /> }<br /> <br /> /**<br /> * Allows the user to add more rss feeds, if edit-mode is supported<br /> * <br /> * @param request<br /> * the current action request<br /> * @throws Exception<br /> */<br /> protected void doEdit(RenderRequest request, RenderResponse response)<br /> throws UnavailableException, PortletSecurityException, PortletException, IOException {<br /><br /> response.setContentType(CONTENT_TYPE);<br /> StringBuffer content = new StringBuffer();<br /><br /> content.append(&quot;&lt;table&gt;&quot;);<br /> /* builds a form containing a portlet action URL for targeting itself */<br /> content.append(&quot;&lt;form name=&#092;&quot;inputForm&#092;&quot; target=&#092;&quot;_self&#092;&quot; &quot;);<br /> content.append(&quot;method=&#092;&quot;POST&#092;&quot; action=&#092;&quot;&quot;);<br /> content.append(response.createActionURL().toString() + &quot;&#092;&quot;&gt;&quot;);<br /><br /> /* get porlet preferences to request the rss feed destinations */<br /> PortletPreferences prefs = request.getPreferences();<br /> String[] rssSources = prefs.getValues(RSS_XML_PREFS, RSS_XML_DEFAULT);<br /><br /> for (int i = 0; i &lt; rssSources.length; i++) {<br /> content.append(&quot;&lt;tr&gt;&lt;td&gt;&quot;);<br /> content.append(&quot;&lt;input type=&#092;&quot;checkbox&#092;&quot; name=&#092;&quot;check&#092;&quot; &quot;);<br /> content.append(&quot;value=&#092;&quot;&quot; + rssSources + &quot;&#092;&quot; CHECKED &gt;&quot;);<br /> content.append(rssSources);<br /> content.append(&quot;&lt;/td&gt;&lt;/tr&gt;&quot;);<br /> }<br /><br /> content.append(&quot;&lt;tr&gt;&lt;td&gt;&quot;);<br /> content.append(&quot;Additional RSS Feed:&quot;);<br /> content.append(&quot;&lt;input type=&#092;&quot;text&#092;&quot; name=&#092;&quot;inputXml&#092;&quot; value=&#092;&quot;&#092;&quot;&gt;&quot;);<br /> content.append(&quot;&lt;input name=&#092;&quot;inputSubmit&#092;&quot; type=&#092;&quot;submit&#092;&quot; value=&#092;&quot;submit&#092;&quot;&gt;&quot;);<br /> content.append(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/form&gt;&lt;/table&gt;&quot;);<br /> response.getWriter().println(content.toString());<br /><br /> }<br /><br /> protected void doHelp(RenderRequest request, RenderResponse response)<br /> throws UnavailableException, PortletSecurityException, PortletException, IOException {<br /><br /> response.setContentType(CONTENT_TYPE);<br /> StringBuffer content = new StringBuffer();<br /><br /> content.append(&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot;);<br /> content.append(&quot;The RSS Portlet transforms newsfeed using a default stylesheet.&lt;BR/&gt;&quot;);<br /> content<br /> .append(&quot;Note that not all newsfeeds will transform correctly, but none should throw an error.&lt;BR/&gt;&quot;);<br /> content.append(&quot;To add or remove newfeeds, change the portlet preferences.&lt;BR/&gt;&quot;);<br /> PortletURL renderURL = response.createRenderURL();<br /> renderURL.setPortletMode(PortletMode.VIEW);<br /> content.append(&quot;&lt;a href=&#092;&quot;&quot; + renderURL.toString() + &quot;&#092;&quot;&gt;back&lt;/a&gt;&quot;);<br /> content.append(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;);<br /><br /> response.getWriter().println(content.toString());<br /> }<br /><br /> protected void doView(RenderRequest request, RenderResponse response)<br /> throws UnavailableException, PortletSecurityException, PortletException, IOException {<br /><br /> response.setProperty(&quot;expiration-cache&quot;, &quot;125&quot;);<br /> response.setContentType(CONTENT_TYPE);<br /> StringBuffer content = new StringBuffer();<br /> String selectedXml = null;<br /><br /> try {<br /> selectedXml = request.getParameter(&quot;selectXml&quot;);<br /> PrintWriter out = response.getWriter();<br /> String errorMessage = request.getParameter(&quot;errorMessage&quot;);<br /><br /> if (errorMessage &#33;= null) {<br /> addHTMLErrorMessage(content, errorMessage);<br /> }<br /><br /> content.append(&quot;&lt;table&gt;&quot;);<br /> content.append(&quot;&lt;form name=&#092;&quot;selectForm&#092;&quot; target=&#092;&quot;_self&#092;&quot; &quot;);<br /> content.append(&quot;method=&#092;&quot;POST&#092;&quot; action=&#092;&quot;&quot;);<br /> content.append(response.createActionURL().toString() + &quot;&#092;&quot;&gt;&quot;);<br /> content.append(&quot;&lt;tr&gt;&lt;td&gt;&quot;);<br /><br /> PortletURL renderURL = response.createRenderURL();<br /> renderURL.setPortletMode(PortletMode.HELP);<br /> content.append(&quot;&lt;a href=&#092;&quot;&quot; + renderURL + &quot;&#092;&quot;&gt;help&lt;/a&gt;&quot;);<br /> content.append(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;);<br /><br /> /* get porlet preferences to request the rss feed destinations */<br /> PortletPreferences prefs = request.getPreferences();<br /> String[] rssSources = prefs.getValues(RSS_XML_PREFS, RSS_XML_DEFAULT);<br /><br /> addHTMLSelectOption(content, &quot;selectXml&quot;, selectedXml, rssSources);<br /><br /> content.append(&quot;&lt;/td&gt;&lt;td&gt;&quot;);<br /> content.append(&quot;&lt;input name=&#092;&quot;selectSubmit&#092;&quot; type=&#092;&quot;submit&#092;&quot; value=&#092;&quot;go&#092;&quot;&gt;&quot;);<br /> content.append(&quot;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);<br /> content.append(&quot;&lt;/form&gt;&lt;/table&gt;&quot;);<br /> out.println(content.toString());<br /> addTransformedRSSContent(request, selectedXml, out);<br /><br /> } catch (Exception e) {<br /> throw new PortletException(e);<br /> }<br /><br /> }<br /><br /> /**<br /> * @param request<br /> * the current render request<br /> * @param selectedXml<br /> * the selected String value for the RSS XML source<br /> * @param out<br /> * the current writer object<br /> * @throws PortletException<br /> * @throws IOException<br /> */<br /> private void addTransformedRSSContent(RenderRequest request, String selectedXml, PrintWriter out)<br /> throws PortletException, IOException {<br /><br /> InputStream xmlInput = null;<br /> try {<br /> if (selectedXml == null) {<br /> selectedXml = request.getPreferences().getValue(RSS_XML_PREFS, RSS_XML_DEFAULT[0]);<br /> }<br /> xmlInput = new URL(selectedXml).openStream();<br /><br /> if (xmlInput == null) {<br /> throw new PortletException(&quot;No XML found.&quot;);<br /> }<br /><br /> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();<br /> DocumentBuilder builder = factory.newDocumentBuilder();<br /> Transformer transformer = this.template10.newTransformer();<br /><br /> Source source = null;<br /> try {<br /> Document document = builder.parse(xmlInput);<br /> Element element = document.getDocumentElement();<br /> if (element.hasAttribute(&quot;version&quot;)<br /> &amp;&amp; element.getAttribute(&quot;version&quot;).equals(&quot;2.0&quot;)) {<br /> transformer = this.template20.newTransformer();<br /> }<br /> source = new DOMSource(document);<br /> } catch (SAXException saxe) {<br /> source = new StreamSource(xmlInput);<br /> }<br /> StreamResult output = new StreamResult(out);<br /> transformer.transform(source, output);<br /> } catch (MalformedURLException e) {<br /> throw new PortletException(e);<br /> } catch (IOException e) {<br /> throw new PortletException(e);<br /> } catch (ParserConfigurationException e) {<br /> throw new PortletException(e);<br /> } catch (TransformerConfigurationException e) {<br /> throw new PortletException(e);<br /> } catch (TransformerException e) {<br /> throw new PortletException(e);<br /> } finally {<br /> if (xmlInput &#33;= null) {<br /> xmlInput.close();<br /> }<br /> }<br /> }<br /><br /> /**<br /> * @param content<br /> * the buffer to write in<br /> * @param name<br /> * the name for the HTML select element<br /> * @param selectedValue<br /> * the selected value<br /> * @param sources<br /> * a string array containing the strings for the option elements<br /> */<br /> private void addHTMLSelectOption(StringBuffer content, String name, String selectedValue,<br /> String[] sources) {<br /> content.append(&quot;&lt;select name=&#092;&quot;&quot; + name + &quot;&#092;&quot;&gt;&quot;);<br /> for (int i = 0; i &lt; sources.length; i++) {<br /> content.append(&quot;&lt;option value=&#092;&quot;&quot; + sources + &quot;&#092;&quot;&quot;);<br /> if ((selectedValue &#33;= null) &amp;&amp; sources.equals(selectedValue)) {<br /> content.append(&quot; SELECTED &quot;);<br /> }<br /> content.append(&quot;&gt;&quot; + sources + &quot;&lt;/option&gt;&quot;);<br /> }<br /> content.append(&quot;&lt;/select&gt;&quot;);<br /> }<br /><br /> /**<br /> * Adds a HTML error message to a specified string buffer<br /> * <br /> * @param content<br /> * the buffer to write in<br /> * @param errorMessage<br /> * the message that should be included in the response<br /> */<br /> private void addHTMLErrorMessage(StringBuffer content, String errorMessage) {<br /> content.append(&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot;);<br /> content.append(&quot;&lt;font color=&#092;&quot;red&#092;&quot;&gt;&quot; + errorMessage + &quot;&lt;/font&gt;&quot;);<br /> content.append(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;);<br /> }<br /><br /> /**<br /> * Reads the content from the given xsl filename and transforms it into a<br /> * new template object.<br /> * <br /> * @param filename<br /> * the filename of the RSS xsl source file<br /> * @return a new Templates object<br /> * @throws TransformerConfigurationException<br /> */<br /> private Templates getTemplateFromFile(String filename) throws TransformerConfigurationException {<br /> InputStream xslstream = this.getPortletContext().getResourceAsStream(filename);<br /> StreamSource source = new StreamSource(xslstream);<br /> TransformerFactory factory = TransformerFactory.newInstance();<br /> return factory.newTemplates(source);<br /> }<br />}<br /><br /><br />the war archive was too big to be added to the post .. sorry for that.
Tri www.VSSIC.com
Adding myRssPortlet to Liferay
March 26, 2006 7:49 PM
Answer

Tri www.VSSIC.com

Rank: Junior Member

Posts: 31

Join Date: June 8, 2005

Recent Posts

RSS producer and RSS customer also built-in LEP , so why you make your own ? . It&#39;s risky<br />