使用 ROME 创建 Atom feed 并发布它们

发布于 2024-08-29 03:07:34 字数 1168 浏览 3 评论 0原文

我是这个发布/订阅协议的新手。抱歉,如果我的问题很天真。 你能帮助我回答我的问题吗? 我开始使用 ROME API 创建一个 Atom feed其 wiki 上给出的示例。

SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://www.example.com");
feed.setDescription("This feed has been created using ROME";

List entries = new ArrayList();
SyndEntry entry;
SyndContent description;

entry = new SyndEntryImpl();
entry.setTitle("ROME v1.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
entry.setPublishedDate(DATE_PARSER.parse("2010-04-09"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of ROME");
entry.setDescription(description);
entries.add(entry);

feed.setEntries(entries);

我将其写入文件atomfeed.xml。标签中默认的 rel 属性是 。如何使用 SyndFeed 或 SyndEntry 的 setLink() 方法设置不同的相对属性?

我应该如何将此atomfeed.xml feed发布到网络上(而不是任何博客上)。我可以在我的public_html文件夹中创建一个目录,然后在我的URL中使用该目录发布它吗?这是正确的做法吗?每次我想添加新条目时,我可以更新它并继续在网络上发布它吗?

发布者客户端与发布者有何不同?

感谢您的时间和帮助

I am a newbie to this pub/sub protocol. Sorry if my questions are very naive.
Could you help me by answering my questions.
I started off creating an atom feed using ROME API looking at the example given on its wiki.

SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://www.example.com");
feed.setDescription("This feed has been created using ROME";

List entries = new ArrayList();
SyndEntry entry;
SyndContent description;

entry = new SyndEntryImpl();
entry.setTitle("ROME v1.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
entry.setPublishedDate(DATE_PARSER.parse("2010-04-09"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of ROME");
entry.setDescription(description);
entries.add(entry);

feed.setEntries(entries);

I am writing this into a file atomfeed.xml. The default rel-attribute in the tag is . How do I set different rel-attributes using this SyndFeed's or SyndEntry's setLink() method ?

How should I publish this atomfeed.xml feed onto the web(not on any blog).Can I create a directory in my public_html folder and just publish it with that dir in my URL ? Is this the correct way of doing it ? And every time I want to add a new entry can I just update this and keep publishing it on the web ?

How is Publisher Client different from Publisher ?

Thanks for your time and help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2024-09-05 03:07:34

您可以创建一个 SyndLink,例如

SyndLink link = new SyndLinkImpl();
link.setRel("alternative");
link.setHref("http://something.com/entry/something.xml");

然后在您的条目上设置

entry.setLink(link);

然后对于多个链接,创建 SyndLinks 列表并使用 setLinks(list) 在条目上设置。

http://www.jarvana.com/jarvana/view/net/java/dev/rome/rome/1.0.0/rome-1.0.0-javadoc。 jar!/com/sun/syndicate/feed/synd/SyndLink.html

You can make a SyndLink, eg

SyndLink link = new SyndLinkImpl();
link.setRel("alternative");
link.setHref("http://something.com/entry/something.xml");

Then on your entry set that

entry.setLink(link);

Then for multiple links, create a List of SyndLinks and set on the entry with setLinks(list).

http://www.jarvana.com/jarvana/view/net/java/dev/rome/rome/1.0.0/rome-1.0.0-javadoc.jar!/com/sun/syndication/feed/synd/SyndLink.html

枕梦 2024-09-05 03:07:34

应该这样实现:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType("rss_2.0");
        feed.setTitle("Rss Title");
        feed.setDescription("Rss Description");
        feed.setAuthor("Rss Author");
        feed.setLink("http://www.rss.link.com");

        ArrayList<SyndEntry> entries = new ArrayList<>();
        // TODO: Access DB to add entries
        for(int i=0;i<3;i++){
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Entry Title " +i);
            entry.setLink("http://entry.link");
            SyndContent description = new SyndContentImpl();
            description.setType(MediaType.TEXT_PLAIN);
            description.setValue("Entry description "+i);
            entry.setDescription(description);
            entries.add(entry);
        }
        feed.setEntries(entries);

        response.setContentType(MediaType.APPLICATION_XML);
        SyndFeedOutput output = new SyndFeedOutput();
        try {
            output.output(feed,response.getWriter());
        } catch (FeedException e) {
            e.printStackTrace();
        }
    }

Should be realized like this:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType("rss_2.0");
        feed.setTitle("Rss Title");
        feed.setDescription("Rss Description");
        feed.setAuthor("Rss Author");
        feed.setLink("http://www.rss.link.com");

        ArrayList<SyndEntry> entries = new ArrayList<>();
        // TODO: Access DB to add entries
        for(int i=0;i<3;i++){
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Entry Title " +i);
            entry.setLink("http://entry.link");
            SyndContent description = new SyndContentImpl();
            description.setType(MediaType.TEXT_PLAIN);
            description.setValue("Entry description "+i);
            entry.setDescription(description);
            entries.add(entry);
        }
        feed.setEntries(entries);

        response.setContentType(MediaType.APPLICATION_XML);
        SyndFeedOutput output = new SyndFeedOutput();
        try {
            output.output(feed,response.getWriter());
        } catch (FeedException e) {
            e.printStackTrace();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文