📄 x9016.htm
字号:
<HTML
><HEAD
><TITLE
>RSS punter</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Extending Messages, Groupchat, Components, and Event Models"
HREF="c7982.htm"><LINK
REL="PREVIOUS"
TITLE="Any coffee left?"
HREF="x8561.htm"><LINK
REL="NEXT"
TITLE="Headline viewer"
HREF="x9991.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x8561.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Extending Messages, Groupchat, Components, and Event Models</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x9991.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-8-SECT-3"
>RSS punter</A
></H1
><P
>RSS—<I
CLASS="EMPHASIS"
>RDF Site Summary</I
>
<A
NAME="AEN9020"
HREF="#FTN.AEN9020"
>[1]</A
>
or alternatively <I
CLASS="EMPHASIS"
>Really Simple Syndication</I
>—is
an XML format used for describing the content of a web site, where
that site typically contains news items, diary entries, event information
or generally anything that grows, item by item, over time. A classic
application of RSS is to describe a news site such as JabberCentral.
<A
NAME="AEN9023"
HREF="#FTN.AEN9023"
>[2]</A
>
JabberCentral's main page (see <A
HREF="x9016.htm#JABTDG-CH-8-FIG-5"
>Figure 8-5</A
>) consists
of a number of news items—in the "Recent News" section—about
Jabber and the community (what else?). These items appear in reverse
chronological order, and each one is fairly succinct, sharing a common set
of properties: </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Title</DT
><DD
><P
>Each item has a title ("JabberCon Update 11:45am - Aug 20").</P
></DD
><DT
>Short description</DT
><DD
><P
>For each item, there's a short piece of text describing the content
and context of the news story ("Jabbercon Update - Monday Morning").</P
></DD
><DT
>Link to main story</DT
><DD
><P
>The short description should be enough to help the reader decide if
he wants to read the whole item. If he does, there's a link ("Read More")
to the news item itself.</P
></DD
></DL
></DIV
><DIV
CLASS="FIGURE"
><A
NAME="JABTDG-CH-8-FIG-5"
></A
><P
><B
>Figure 8-5. JabberCentral's main page</B
></P
><P
><IMG
SRC="CH-8-FIG-5.jpg"></P
></DIV
><P
>It is this collection of item-level properties that are summarized in an
RSS file. The formality of the XML structure makes it a straightforward
matter for automating the retrieval of story summaries for inclusion in
other sites (syndication), for the combination of these items with items
from other similar sources (aggregation), and for simply checking to see
if there is any new content (new items) since the last visit.</P
><P
><A
HREF="x9016.htm#JABTDG-CH-8-EX-6"
>Example 8-6</A
> shows what the RSS XML for the
JabberCentral news items shown in <A
HREF="x9016.htm#JABTDG-CH-8-FIG-5"
>Figure 8-5</A
>
looks like.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-8-EX-6"
></A
><P
><B
>Example 8-6. RSS source for JabberCentral</B
></P
><P
><PRE
CLASS="SCREEN"
><?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
"http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91">
<channel>
<title>JabberCentral</title>
<description>
JabberCentral is the premiere Jabber end-user news and support
site. Many Jabber developers are actively involved at JabberCentral
to provide fresh and authoritative information for users.
</description>
<language>en-us</language>
<link>http://www.jabbercentral.com/</link>
<copyright>Copyright 2000, Aspect Networks</copyright>
<image>
<url>http://jabbercentral.com/images/jc_button.gif</url>
<title>JabberCentral</title>
<link>http://www.jabbercentral.com/</link>
</image>
<item>
<title>JabberCon Update 11:45am - Aug 20</title>
<link>http://www.jabbercentral.com/news/view.php?news_id=998329970</link>
<description>JabberCon Update - Monday Morning</description>
</item>
<item>
<title>Jabcast Promises Secure Jabber Solutions</title>
<link>http://www.jabbercentral.com/news/view.php?news_id=998061331</link>
<description>
Jabcast announces their intention to release security
plugins with their line of products and services.
</description>
</item>
... (more items) ...
</channel>
</rss> </PRE
></P
></DIV
><P
>The structure is very straightforward. Each RSS file describes a
"channel" (<TT
CLASS="LITERAL"
><channel/></TT
>). Here's how a
channel is defined:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Channel Information</DT
><DD
><P
>The channel
in this case is JabberCentral. The channel header information
includes the channel's title (<TT
CLASS="LITERAL"
><title/></TT
>),
short description (<TT
CLASS="LITERAL"
><description/></TT
>), main
URL (<TT
CLASS="LITERAL"
><link/></TT
>) and so on.</P
></DD
><DT
>Channel Image</DT
><DD
><P
>Often RSS information is rendered into HTML to provide a concise
"current index" summary of the channel it describes. An image can
be used in that summary rendering, and its definition is held in
the <TT
CLASS="LITERAL"
><image/></TT
> section of the file.</P
></DD
><DT
>Channel Items</DT
><DD
><P
>The bulk of the RSS file content is made up of the individual
<TT
CLASS="LITERAL"
><item/></TT
> sections, each of which
reflect an item on the site that the channel represents. We can
see in <A
HREF="x9016.htm#JABTDG-CH-8-EX-6"
>Example 8-6</A
> that the first
<TT
CLASS="LITERAL"
><item/></TT
> tag:</P
><P
><PRE
CLASS="SCREEN"
><item>
<title>JabberCon Update 11:45am - Aug 20</title>
<link>http://www.jabbercentral.com/news/view.php?news_id=998329970</link>
<description>JabberCon Update - Monday Morning</description>
</item> </PRE
></P
><P
>describes the most recent news item shown on JabberCentral's main
page—"JabberCon Update 11:45am - Aug 20". Each of the news
item properties are contained within that
<TT
CLASS="LITERAL"
><item/></TT
> tag: the <I
CLASS="EMPHASIS"
>title</I
>
(<TT
CLASS="LITERAL"
><title/></TT
>),
<I
CLASS="EMPHASIS"
>short description</I
>
(<TT
CLASS="LITERAL"
><description/></TT
>), and
<I
CLASS="EMPHASIS"
>link to main story</I
>
(<TT
CLASS="LITERAL"
><link/></TT
>).</P
></DD
><DT
>Channel Interactive Feature</DT
><DD
><P
>There is a possibility for each channel to describe an interactive
feature on the site it represents; often this is a search engine which
is fronted by a text input field and submit button. The interactive
feature section of an RSS file is used to describe how that mechanism
is to work (the name of the input field and the submit button, and
the URL to invoke when the button is pressed, for example). This is
so that HTML renderings of the site can include the feature otherwise
only available on the original site. </P
><P
><I
CLASS="EMPHASIS"
>This interactive feature definition is not shown
in our RSS example.</I
></P
></DD
></DL
></DIV
><P
>RSS information lends itself very well to various methods of viewing.
There are custom "headline viewer" clients available—focused
applications that allow you to select from a vast array of RSS sources
and have links to items displayed on your desktop (so yes, the personal
newspaper—of sorts—is here!).
There are also possibilities for having
RSS items scroll by on your desktop control bar. </P
><P
>And then there's Jabber. As described in
<A
HREF="x4089.htm#JABTDG-CH-5-SECT-5.4.1"
>the section called <I
>The Message Element</I
> in Chapter 5</A
>, the Jabber
<TT
CLASS="LITERAL"
><message/></TT
> element can represent something
that looks suspiciously like an RSS item. The message type "headline"
defines a message that carries news headline information. In this case,
the <TT
CLASS="LITERAL"
><message/></TT
> element itself is usually
embellished with an <I
CLASS="EMPHASIS"
>extension</I
>, qualified by the
<TT
CLASS="LITERAL"
>jabber:x:oob</TT
> namespace, which is described in
<A
HREF="x6079.htm#JABTDG-CH-5A-SECT-3.8"
>the section called <I
><TT
CLASS="LITERAL"
>jabber:x:oob</TT
></I
> in Chapter 5a</A
>. If the first news item from
the JabberCentral site were to be carried in a headline message,
<A
HREF="x9016.htm#JABTDG-CH-8-EX-7"
>Example 8-7</A
> shows what the element would look like.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="JABTDG-CH-8-EX-7"
></A
><P
><B
>Example 8-7. A headline message carrying a JabberCentral news item</B
></P
><P
><PRE
CLASS="SCREEN"
><message type='headline' to='dj@qmacro.dyndns.org'>
<subject>JabberCon Update 11:45am - Aug 20</subject>
<body>JabberCon Update - Monday Morning</body>
<x xmlns='jabber:x:oob'>
<url>http://www.jabbercentral.com/news/view.php?news_id=998329970</url>
<desc>JabberCon Update - Monday Morning</desc>
</x>
</message> </PRE
></P
></DIV
><P
>It's the extension, qualified by the <TT
CLASS="LITERAL"
>jabber:x:oob</TT
>
namespace, that carries the crucial parts of the RSS item. And there are
off the shelf clients such as WinJab and Jarl that can understand this
extension and do something useful if a headline type message is
received: the item content is displayed in a clickable list of
lines, each one representing a single RSS item, akin to the headline
viewer clients mentioned earlier.</P
><P
>Of course, we could simply punt RSS items to clients in non-headline
type messages:</P
><P
><PRE
CLASS="SCREEN"
><message type='headline' to='dj@qmacro.dyndns.org'>
<subject>JabberCon Update 11:45am - Aug 20</subject>
<body>
JabberCon Update - Monday Morning
http://www.jabbercentral.com/news/view.php?news_id=998329970
</body>
</x>
</message> </PRE
></P
><P
>where the complete item information is transmitted in a combination
of the <TT
CLASS="LITERAL"
><subject/></TT
> and
<TT
CLASS="LITERAL"
><body/></TT
> tags. This works too, but has
the disadvantage of presenting no context within which the URL can
be interpreted by the receiving clients, meaning all they can do with
the message is display it as they would display any other message.
The key is that we can send formalized <I
CLASS="EMPHASIS"
>metadata</I
>
which increases the value of our message content enormously.
<A
HREF="x9016.htm#JABTDG-CH-8-FIG-9"
>Figure 8-7</A
> shows Jarl displaying RSS-sourced
news headlines.</P
><P
>Distributing RSS-sourced headlines over Jabber to standard Jabber clients
is a great combination of off the shelf technologies. In fact, we'll see
in the next section that it's not just standard Jabber clients that fit
the bill; we'll write a Jabber-based headline viewer to show that not all
Jabber clients are, nor should they be, made equal. But anyway, let's get
to it!</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-8-SECT-3.1"
>The plan</A
></H2
><P
>We're going to write an RSS punter. A mechanism that checks pre-defined
sources for
new RSS items, and punts (or pushes) them to people who are interested
in receiving them.
For the sake of simplicity, we'll define the list of RSS sources
in the script itself. See <A
HREF="x9016.htm#JABTDG-CH-8-SECT-3.4"
>the section called <I
>Further ideas</I
></A
>
for ideas on how to develop this recipe further. </P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="JABTDG-CH-8-SECT-3.1.1"
>The script as <I
CLASS="EMPHASIS"
>component</I
></A
></H3
><P
>Until now, the recipes we've written—such as the CVS Notification,
the Dialup System Watch, and the Keyword Assistant, all in
<A
HREF="c6941.htm"
>Chapter 7</A
>—have
all existed as Jabber <I
CLASS="EMPHASIS"
>clients</I
>. That is, they've
performed a service while connected to the Jabber server via the
JSM (Jabber Session Manager). There's nothing wrong with this, indeed it's
more than just fine to build Jabber-based mechanisms using a Jabber client
stub connection; that way, your script, through its
<I
CLASS="EMPHASIS"
>identity</I
>—the user JID— can avail itself
of all the IM-related functions that the JSM offers—presence,
storage and forwarding of messages, and so on. Perhaps even more interesting
is that the mechanism needs only an account, a username and password, on a
Jabber server to be part of the big connected picture. One can look at
this sort of client-connected mechanism as an effective and low-cost entry
to building
the 'A's in our Jabber-connected A2A, A2P and P2A world of acronyms (or
"acronym-qualified worlds"—you decide). </P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -