use of org.intabulas.sandler.elements.Entry in project jspwiki by apache.
the class AtomAPIServlet method doGet.
/**
* Handles HTTP GET. However, we do not respond to GET requests,
* other than to show an explanatory text.
*
* {@inheritDoc}
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
log.debug("Received HTTP GET to AtomAPIServlet");
String blogid = getPageName(request);
log.debug("Requested page " + blogid);
try {
if (blogid == null) {
Feed feed = listBlogs();
response.setContentType("application/x.atom+xml; charset=UTF-8");
response.getWriter().println(Sandler.marshallFeed(feed));
response.getWriter().flush();
} else {
Entry entry = getBlogEntry(blogid);
response.setContentType("application/x.atom+xml; charset=UTF-8");
response.getWriter().println(Sandler.marshallEntry(entry));
response.getWriter().flush();
}
} catch (Exception e) {
log.error("Unable to generate response", e);
throw new ServletException("Internal problem - whack Janne on the head to get a better error report", e);
}
}
use of org.intabulas.sandler.elements.Entry in project jspwiki by apache.
the class AtomAPIServlet method doPost.
/**
* Implements the PostURI of the Atom spec.
* <p>
* Implementation notes:
* <ul>
* <li>Only fetches the first content. All other contents are ignored.
* <li>Assumes that incoming code is plain text or WikiMarkup, not html.
* </ul>
*
* @param request {@inheritDoc}
* @param response {@inheritDoc}
* @throws ServletException {@inheritDoc}
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
log.debug("Received POST to AtomAPIServlet");
try {
String blogid = getPageName(request);
WikiPage page = m_engine.getPage(blogid);
if (page == null) {
throw new ServletException("Page " + blogid + " does not exist, cannot add blog post.");
}
// FIXME: Do authentication here
Entry entry = Sandler.unmarshallEntry(request.getInputStream());
//
// Fetch the obligatory parts of the content.
//
Content title = entry.getTitle();
Content content = entry.getContent(0);
Person author = entry.getAuthor();
// FIXME: Sandler 0.5 does not support generator
//
// Generate new blog entry.
//
WeblogEntryPlugin plugin = new WeblogEntryPlugin();
String pageName = plugin.getNewEntryPage(m_engine, blogid);
String username = author.getName();
WikiPage entryPage = new WikiPage(m_engine, pageName);
entryPage.setAuthor(username);
WikiContext context = new WikiContext(m_engine, request, entryPage);
StringBuilder text = new StringBuilder();
text.append("!" + title.getBody());
text.append("\n\n");
text.append(content.getBody());
log.debug("Writing entry: " + text);
m_engine.saveText(context, text.toString());
} catch (FeedMarshallException e) {
log.error("Received faulty Atom entry", e);
throw new ServletException("Faulty Atom entry", e);
} catch (IOException e) {
log.error("I/O exception", e);
throw new ServletException("Could not get body of request", e);
} catch (WikiException e) {
log.error("Provider exception while posting", e);
throw new ServletException("JSPWiki cannot save the entry", e);
}
}
use of org.intabulas.sandler.elements.Entry in project jspwiki by apache.
the class AtomAPIServlet method getBlogEntry.
private Entry getBlogEntry(String entryid) throws ProviderException {
WikiPage page = m_engine.getPage(entryid);
WikiPage firstVersion = m_engine.getPage(entryid, 1);
Entry entry = SyndicationFactory.newSyndicationEntry();
String pageText = m_engine.getText(page.getName());
String title = "";
int firstLine = pageText.indexOf('\n');
if (firstLine > 0) {
title = pageText.substring(0, firstLine);
}
if (title.trim().length() == 0)
title = page.getName();
// Remove wiki formatting
while (title.startsWith("!")) title = title.substring(1);
entry.setTitle(title);
entry.setCreated(firstVersion.getLastModified());
entry.setModified(page.getLastModified());
entry.setAuthor(SyndicationFactory.createPerson(page.getAuthor(), null, null));
entry.addContent(SyndicationFactory.createEscapedContent(pageText));
return entry;
}
Aggregations