⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rss.jsp

📁 HomePlayer is an extention of the FreePlayer software provided by the french internet provider Free
💻 JSP
字号:
<%@page contentType="text/html;charset=ISO-8859-15" pageEncoding="UTF-8"%>
<%@page import="com.sun.syndication.feed.synd.*"%>
<%@page import="org.homeplayer.util.*"%>
<%@page import="org.homeplayer.data.*"%>
<%@page import="org.homeplayer.web.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<jsp:useBean id="hppc" class="org.homeplayer.web.HPPageContext"
	scope="request">
	<jsp:setProperty name="hppc" property="request" value="<%=request%>" />
	<jsp:setProperty name="hppc" property="navLevel" value="5" />
</jsp:useBean>
<%
int maxInPage = 6;
int start = 0;
if (request.getParameter("start") != null) {
	start = Integer.parseInt(request.getParameter("start"));
}

String media = "";
if (request.getParameter("Media") != null) {
	media = request.getParameter("Media");
}

XMLChannel rssch = (XMLChannel) MediaManager.getCurrentMediaManager().getMediaItem(GUIDGenerator.makeGUID(media));
hppc.setServiceName( rssch instanceof RSSChannel ? "RSS" : "PODCAST" ) ;
int pos;

if (request.getParameter("pos") != null) {
	pos = Integer.parseInt(request.getParameter("pos"));
} else {
	rssch.load();
	pos = -1;
}

RSSEntity parsedFeed = rssch.getRSSEntity(); //get the parsed feed
if( parsedFeed.isValid() == false ) {
	hppc.setRefresh(1, hppc.getUpUrl());
	%>
	<html>
	    <head><jsp:include page="/WEB-INF/jsp/head.jsp"/></head>
		<body>
			<table width="95%" align="center">
				<tr><td height="30">&nbsp;</td></tr>
				<tr>
					<td align="center">
						<table width=300 heigth=20><tr><td align="center" bgcolor="#33333338">Flux invalide.</td></tr></table>
					</td>
				</tr>
			</table>
		</body>
	</html>
	<%
	return ;
}

List entries = parsedFeed.getEntries(); //get the entries

boolean prec = (start - maxInPage) >= 0;
boolean next = start + maxInPage < entries.size();
if (prec) {
	hppc.addMenuItem(new HPMenuPrevious(
			"rss.jsp?Media=" + WebUtil.urlEncode(media) + "&start=" + (start - maxInPage) + "&pos="
					+ (start - maxInPage)));
}

RSSHistoryManager rssHistManager = RSSHistoryManager.getInstance();
RSSHistory rssHist = rssHistManager.getRssHistory(rssch.getPath());

//open the content of an entry

SyndEntry thenews = null;
if (request.getParameter("open") != null) {
	thenews = (SyndEntry) entries.get(pos);
	rssHist.setAsVisited(thenews.getTitle(), thenews.getPublishedDate());
}

//Date utility
Date oldestDate = null;
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_YEAR, -30);
Date nextMonth = c.getTime();
Date lastpubdate = null ;

for (int i = 0; i < entries.size(); i++) {

	SyndEntry n = (SyndEntry) entries.get(i);
	Date d = n.getPublishedDate();

	if (oldestDate == null) {
		oldestDate = d;
		continue;
	}
	if (lastpubdate == null) {
		lastpubdate = d;
	} else {
		lastpubdate = d==null ? lastpubdate : d.after(lastpubdate) ? d : lastpubdate ;
	}
	if (d == null) {
		d = nextMonth;
	}
	if (d.before(oldestDate)) {
		oldestDate = d;
	}
}

if (oldestDate == null) {
	oldestDate = nextMonth;
} else {
	c = Calendar.getInstance();
	c.setTime(oldestDate);
	c.add(Calendar.DAY_OF_YEAR, -1);
	oldestDate = c.getTime();
}

rssHist.clear(oldestDate);

//display left block titles

for (int i = start; i < entries.size() && (i - start) < maxInPage; i++ ) {

	SyndEntry n = (SyndEntry) entries.get(i);
	String label = StringUtil.encodeHTML(n.getTitle());
	label = StringUtil.cut(label,60) ;
	if (rssHist.hasBeenVisited(n.getTitle())) {
		label = "<font color=\"#9999993F\"><i>" + label + "</i></font>";
	}
	hppc.addMenuItem(new HPMenuLink(label, "rss.jsp?Media=" + WebUtil.urlEncode(media) + "&start=" + start + "&pos="+ i + "&open=true", "/images/playpodcast.gif", pos==i));
}
if (next) {

	hppc.addMenuItem(new org.homeplayer.web.HPMenuNext(
			"rss.jsp?Media=" + WebUtil.urlEncode(media) + "&start="
					+ (start + maxInPage) + "&pos="
					+ (start + maxInPage)));
}

hppc.setHeaderTitle(rssch.getTitle() + " (" + (pos + 1) + "/" + entries.size() + ")");
String stopLink = "/action.jsp?next=" + WebUtil.urlEncode(hppc.getLocalURL())+"&control=stop";
hppc.setStopLink(stopLink);

//add to favorite
hppc.setFavorite(hppc.getServiceName(), rssch.getTitle(), StringUtil.gsub(hppc.getLocalURL(), "pos=", "dummy="));
if( request.getParameter("open") != null && rssch instanceof PodcastChannel ) {
	PodcastChannel podcast = (PodcastChannel)rssch ;
	int mediatype = podcast.getMediaType( thenews ) ;
	if( mediatype != PodcastChannel.MEDIATYPE_UNKNOW ) {
		String mediaurl = podcast.getMediaURL( thenews ) ;
		hppc.topCommandAppendLn( "<table border=0 cellpadding=0 cellspacing=0>");
		hppc.topCommandAppendLn( "<tr>");
		hppc.topCommandAppend( "<td width=30 align=center valign=center><img src=\"/images/playpodcast.gif\"></td>" ) ;
		hppc.topCommandAppend( "<td width=120 valign=center>" ) ;
		hppc.topCommandAppend( "<a href=\"playweburl.jsp?MediaURL="+WebUtil.urlEncode(mediaurl)+"&MediaTitle="+WebUtil.urlEncode(thenews.getTitle())+(mediatype==PodcastChannel.MEDIATYPE_AUDIO?("&next="+WebUtil.urlEncode(hppc.getLocalURL())):"")+"\">" ) ;
		hppc.topCommandAppend( mediatype==PodcastChannel.MEDIATYPE_AUDIO?"Ecouter":"Voir" ) ;
		hppc.topCommandAppend( "</a>" ) ;
		hppc.topCommandAppend( "</td>" ) ;
		hppc.topCommandAppend( "<td width=30 align=center valign=center><img src=\"/images/download.gif\"></td>" ) ;
		hppc.topCommandAppend( "<td width=120 valign=center>" ) ;
		hppc.topCommandAppend( "<a href=\"download.jsp?MediaURL="+WebUtil.urlEncode(mediaurl)+"&MediaTitle="+WebUtil.urlEncode(thenews.getTitle())+ "&MediaType="+mediatype+"&RSSName="+WebUtil.urlEncode(rssch.getTitle())+"&next="+WebUtil.urlEncode(hppc.getLocalURL())+"\">" ) ;
		hppc.topCommandAppend( "T&eacute;l&eacute;charger" ) ;
		hppc.topCommandAppend( "</a>" ) ;
		hppc.topCommandAppend( "</td>" ) ;	
		hppc.topCommandAppendLn( "</tr>");
		hppc.topCommandAppendLn( "</table>");
	}
}
SimpleDateFormat datef = new SimpleDateFormat( "dd/MM/yyyy HH:mm" ) ;
%>

<jsp:include page="<%= hppc.getSkin().getHeader() %>"/>
<TABLE width=406>
	<tr>
		<td><%if (request.getParameter("open") != null) {%>
		<table>
			<tr>
				<td><%=thenews.getTitle()%><%=thenews.getPublishedDate()==null?"":(" - <small>"+datef.format(thenews.getPublishedDate())+"</small>")%></td>
			</tr>
			<tr>
				<td><%
				String desc = thenews.getContents().size()>0 && ((SyndContent) thenews.getContents().get(0))!=null? ((SyndContent) thenews.getContents().get(0)).getValue() : thenews.getDescription()!=null ? thenews.getDescription().getValue() : "" ;
				
				if (desc == null) {
					desc = "";
				} else {
					// suppression des liens 
					desc = desc.replaceAll("<(a|A)\\b[^>]*>", "");
					desc = desc.replaceAll("</(a|A)[^>]*>", "");
					desc = desc.replaceAll("<im\\b[^>]*>", "");
					desc = desc.replaceAll("<object classid\\b[^>]*>", "");
					desc = desc.replaceAll("<param name\\b[^>]*>", "");
					desc = desc.replaceAll("<embed\\b[^>]*>", "");
					desc = desc.length() > 600 ? desc.substring(0, 600) + "..." : desc;
				} 
				// TODO : ameliorer l'affichage et la navigation dans les entrées
				%> <%=desc%>
				</td>
			</tr>
		</table>
		<%} else {%>
		<table>
			<tr>
				<td height=80 width=80 valign=center align=center bgcolor="#FFFFFFFF" >
					<%
					try {
						ImageUtil.ImageInfo img = ImageUtil.getCachedResizedImageInfo(ImageUtil.toUrl(rssch.getIcon()), 80, 80 ) ;
					%>
					<img width="<%=img.getWidth() %>" height="<%=img.getHeight() %>" src="<%= img.getPath() %>">
					<% } catch (ImageUtil.ImageException e) { %>
					<img width="32" height="32" src="/images/photos.gif">					
					<% } %>
				</td>
				<td valign=top><%=rssch.getTitle() %><BR><small>Dernière mise à jour : <%=lastpubdate==null?"Inconnu":(datef.format(lastpubdate)) %></small>
				</td>	
			</tr>
			<tr>
				<td colspan=2><%String desc = rssch.getRSSEntity()!=null ? rssch.getRSSEntity().getDescription() : "" ;
				if (desc == null) {
					desc = "";
				} else {
					// suppression des liens 
					desc = desc.replaceAll("<(a|A)\\b[^>]*>", "");
					desc = desc.replaceAll("</(a|A)[^>]*>", "");
					desc = desc.replaceAll("<im\\b[^>]*>", "");
					desc = desc.replaceAll("<object classid\\b[^>]*>", "");
					desc = desc.replaceAll("<param name\\b[^>]*>", "");
					desc = desc.replaceAll("<embed\\b[^>]*>", "");
					desc = desc.length() > 600 ? desc.substring(0, 600) + "..." : desc;
				}
				%> <%=desc%>
				</td>
			</tr>
		</table>
		<%} %>
		</td>
	</tr>
</table>
<jsp:include page="<%= hppc.getSkin().getFooter() %>"/>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -