View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling 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. 
3   	$Id
4   */
5   package com.hack23.cia.web.service;
6   
7   import java.util.ArrayList;
8   import java.util.Date;
9   import java.util.List;
10  
11  import javax.servlet.http.HttpServletRequest;
12  import javax.servlet.http.HttpServletResponse;
13  
14  import org.springframework.web.servlet.ModelAndView;
15  import org.springframework.web.servlet.mvc.AbstractController;
16  
17  import com.hack23.cia.model.application.dto.common.ApplicationProperties;
18  import com.hack23.cia.service.api.application.ApplicationManager;
19  import com.sun.syndication.feed.synd.SyndContent;
20  import com.sun.syndication.feed.synd.SyndContentImpl;
21  import com.sun.syndication.feed.synd.SyndEntry;
22  import com.sun.syndication.feed.synd.SyndEntryImpl;
23  import com.sun.syndication.feed.synd.SyndFeed;
24  import com.sun.syndication.feed.synd.SyndFeedImpl;
25  import com.sun.syndication.io.SyndFeedOutput;
26  
27  /***
28   * The Class RssFeedService.
29   */
30  public class RssFeedService extends AbstractController {
31  
32  	/*** The application manager. */
33  	private final ApplicationManager applicationManager;
34  	
35  	
36      /***
37       * Instantiates a new rss feed service.
38       *
39       * @param applicationManager the application manager
40       */
41      public RssFeedService(final ApplicationManager applicationManager) {
42  		super();
43  		this.applicationManager = applicationManager;
44  	}
45  
46  	/* (non-Javadoc)
47       * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
48       */
49      @Override
50      protected final ModelAndView handleRequestInternal(final HttpServletRequest request,
51              final HttpServletResponse response) throws Exception {
52  
53      	final ApplicationProperties applicationProperties = new ApplicationProperties();
54      	final String feedType = "rss_2.0";
55  
56      	final SyndFeed feed = new SyndFeedImpl();
57      	feed.setFeedType(feedType);
58  
59      	feed.setTitle(applicationProperties.getName());
60      	feed.setLink("http://localhost:8080/services/rss.xml");
61      	feed.setDescription(applicationProperties.getVersion());
62  
63      	final List entries = new ArrayList();
64      	SyndEntry entry;
65      	SyndContent description;
66  
67      	entry = new SyndEntryImpl();
68      	entry.setTitle("My first RSS example with Rome");
69      	entry.setLink(applicationProperties.getUrl());
70      	entry.setPublishedDate(new Date());
71      	description = new SyndContentImpl();
72      	description.setType("text/html");
73      	description.setValue("<p>sample</p>");
74      	entry.setDescription(description);
75      	entries.add(entry);
76  
77      	feed.setEntries(entries);
78  
79      	final SyndFeedOutput output = new SyndFeedOutput();
80      	response.setContentType("application/xml; charset=UTF-8"); 
81      	output.output(feed,response.getWriter());        
82          
83          return null;
84      }
85  
86  }