RssFeed.java
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
*/
package com.day.cq.commons.feed;
import com.day.cq.commons.SimpleXml;
import com.day.cq.commons.feed.AbstractFeed;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.jcr.RepositoryException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
public class RssFeed
extends AbstractFeed {
public RssFeed(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws RepositoryException {
super(null, req, resp);
}
public RssFeed(Resource res, SlingHttpServletRequest req, SlingHttpServletResponse resp) throws RepositoryException {
super(res, req, resp);
}
@Override
public void printHeader() throws IOException {
this.initXml();
this.xml.openDocument();
this.xml.open("rss").attr("version", "2.0").attr("xmlns:atom", "http://www.w3.org/2005/Atom").open("channel").open("link", this.getHtmlLink(), false).close().open("atom:link").attr("rel", "self").attr("href", this.getHtmlLink()).close().open("title", this.getTitle(), false).close().open("description", this.getDescription(), false).close().open("pubDate", this.getPublishedDate(), false).close().open("generator", this.getGeneratorLink(), false).close();
if (!"".equals(this.getLanguage())) {
this.xml.open("language", this.getLanguage(), false).close();
}
}
@Override
public void printEntry() throws IOException {
String link = this.isFile() ? this.getFileLink() : this.getHtmlLink();
String comments = this.isFile() ? "" : this.getCommentsLink();
this.initXml();
this.xml.omitXmlDeclaration(true);
this.xml.open("item").open("link", link, false).close().open("comments", comments, false).close().open("guid", this.getFeedLink(), false).close().open("title", this.getTitle(), false).close().open("description", this.getDescription(), true).close().open("pubDate", this.getPublishedDate(), false).close().open("category", this.getTags(), false).close();
if (!"".equals(this.getAuthorEmail())) {
this.xml.open("author", this.getAuthorEmail(), false).close();
}
this.xml.tidyUp();
}
@Override
public String getContentType() {
return "application/rss+xml";
}
@Override
String getFeedEntryPath(Resource res) {
return res.getPath() + "." + "feedentry" + "." + "rss" + ".xml";
}
@Override
protected String getFeedLink() {
return this.getUrlPrefix() + this.getNodePath() + "." + "feed" + "." + "rss" + ".xml";
}
@Override
protected String formatDate(Calendar calendar) {
try {
return new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(calendar.getTime());
}
catch (Exception e) {
return "";
}
}
}