人們認識,即未接元件可被添加到XML右在servlet,不需要用於該特定目的爲羅馬所以附加模塊類:
公共無效的doGet(HttpServletRequest的REQ,HttpServletResponse的水庫)拋出IOException {嘗試{SyndFeed feed = getFeed(req,dataEntries,streamGauge);}
String feedType = req.getParameter(FEED_TYPE);
feedType = (feedType != null) ? feedType : _defaultFeedType;
feed.setFeedType(feedType);
res.setContentType(MIME_TYPE);
SyndFeedOutput output = new SyndFeedOutput();
Writer writer = new StringWriter();
output.output(feed, writer);
SAXBuilder db = null;
Document doc = null;
db = new SAXBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(writer.toString()));
try {
doc = db.build(is);
} catch (JDOMException e) {
e.printStackTrace();
}
Element root =
doc.getRootElement();
Element channel = root.getChild("channel");
FeedServlet.AtomNSModule atomNSModule = (FeedServlet.AtomNSModule) module;
root.addNamespaceDeclaration(ATOM_NS);
Element atomLink = new Element("link", ATOM_NS);
atomNSModule.setLink("http://volgalevel.appspot.com/feed");
atomLink.setAttribute("href", atomNSModule.getLink());
atomLink.setAttribute("rel", "self");
atomLink.setAttribute("type", "application/rss+xml");
channel.addContent(0, atomLink);
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, res.getWriter());
} catch (FeedException ex) {
String msg = COULD_NOT_GENERATE_FEED_ERROR;
log(msg, ex);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
}
}
注意進口:
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.Document;
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.XMLOutputter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
實際工作GAE的Servlet的RSS可以在那裏達到:https://github.com/Eljah/volgalevel/blob/master/src/main/java/com/appspot/FeedServlet.java
它還修正重複pubdate的問題