use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class TranslateTag method doAfterBody.
public final int doAfterBody() throws JspException {
try {
WikiContext context = (WikiContext) pageContext.getAttribute(WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
//
// Because the TranslateTag should not affect any of the real page attributes
// we have to make a clone here.
//
context = context.deepClone();
//
// Get the page data.
//
BodyContent bc = getBodyContent();
String wikiText = bc.getString();
bc.clearBody();
if (wikiText != null) {
wikiText = wikiText.trim();
String result = context.getEngine().textToHTML(context, wikiText);
getPreviousOut().write(result);
}
} catch (Exception e) {
log.error("Tag failed", e);
throw new JspException("Tag failed, check logs: " + e.getMessage());
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class WeblogPlugin method addEntryHTML.
/**
* Generates HTML for an entry.
*
* @param context
* @param entryFormat
* @param hasComments True, if comments are enabled.
* @param buffer The buffer to which we add.
* @param entry
* @throws ProviderException
*/
private void addEntryHTML(WikiContext context, DateFormat entryFormat, boolean hasComments, StringBuilder buffer, WikiPage entry) throws ProviderException {
WikiEngine engine = context.getEngine();
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
buffer.append("<div class=\"weblogentry\">\n");
//
// Heading
//
buffer.append("<div class=\"weblogentryheading\">\n");
Date entryDate = entry.getLastModified();
buffer.append(entryFormat.format(entryDate));
buffer.append("</div>\n");
//
// Append the text of the latest version. Reset the
// context to that page.
//
WikiContext entryCtx = (WikiContext) context.clone();
entryCtx.setPage(entry);
String html = engine.getHTML(entryCtx, engine.getPage(entry.getName()));
// Extract the first h1/h2/h3 as title, and replace with null
buffer.append("<div class=\"weblogentrytitle\">\n");
Matcher matcher = HEADINGPATTERN.matcher(html);
if (matcher.find()) {
String title = matcher.group(2);
html = matcher.replaceFirst("");
buffer.append(title);
} else {
buffer.append(entry.getName());
}
buffer.append("</div>\n");
buffer.append("<div class=\"weblogentrybody\">\n");
buffer.append(html);
buffer.append("</div>\n");
//
// Append footer
//
buffer.append("<div class=\"weblogentryfooter\">\n");
String author = entry.getAuthor();
if (author != null) {
if (engine.pageExists(author)) {
author = "<a href=\"" + entryCtx.getURL(WikiContext.VIEW, author) + "\">" + engine.beautifyTitle(author) + "</a>";
}
} else {
author = "AnonymousCoward";
}
buffer.append(MessageFormat.format(rb.getString("weblogentryplugin.postedby"), author));
buffer.append("<a href=\"" + entryCtx.getURL(WikiContext.VIEW, entry.getName()) + "\">" + rb.getString("weblogentryplugin.permalink") + "</a>");
String commentPageName = TextUtil.replaceString(entry.getName(), "blogentry", "comments");
if (hasComments) {
int numComments = guessNumberOfComments(engine, commentPageName);
//
// We add the number of comments to the URL so that
// the user's browsers would realize that the page
// has changed.
//
buffer.append(" ");
String addcomment = rb.getString("weblogentryplugin.addcomment");
buffer.append("<a href=\"" + entryCtx.getURL(WikiContext.COMMENT, commentPageName, "nc=" + numComments) + "\">" + MessageFormat.format(addcomment, numComments) + "</a>");
}
buffer.append("</div>\n");
//
// Done, close
//
buffer.append("</div>\n");
}
use of org.apache.wiki.WikiContext 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.apache.wiki.WikiContext in project jspwiki by apache.
the class AtomAPIServlet method listBlogs.
/**
* Creates and outputs a full list of all available blogs
*/
private Feed listBlogs() throws ProviderException, IOException {
Collection pages = m_engine.getPageManager().getAllPages();
Feed feed = SyndicationFactory.newSyndicationFeed();
feed.setTitle("List of blogs at this site");
feed.setModified(new Date());
for (Iterator i = pages.iterator(); i.hasNext(); ) {
WikiPage p = (WikiPage) i.next();
//
// List only weblogs
// FIXME: Unfortunately, a weblog is not known until it has
// been executed once, because plugins are off during
// the initial startup phase.
//
log.debug(p.getName() + " = " + p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG));
if (!("true".equals(p.getAttribute(WeblogPlugin.ATTR_ISWEBLOG))))
continue;
String encodedName = TextUtil.urlEncodeUTF8(p.getName());
WikiContext context = new WikiContext(m_engine, p);
String title = TextUtil.replaceEntities(org.apache.wiki.rss.Feed.getSiteName(context));
Link postlink = createLink("service.post", m_engine.getBaseURL() + "atom/" + encodedName, title);
Link editlink = createLink("service.edit", m_engine.getBaseURL() + "atom/" + encodedName, title);
Link feedlink = createLink("service.feed", m_engine.getBaseURL() + "atom.jsp?page=" + encodedName, title);
feed.addLink(postlink);
feed.addLink(feedlink);
feed.addLink(editlink);
}
return feed;
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class RSSGenerator method generate.
/**
* Generates the RSS resource. You probably want to output this
* result into a file or something, or serve as output from a servlet.
*
* @return A RSS 1.0 feed in the "full" mode.
*/
public String generate() {
WikiContext context = new WikiContext(m_engine, new WikiPage(m_engine, "__DUMMY"));
context.setRequestContext(WikiContext.RSS);
Feed feed = new RSS10Feed(context);
String result = generateFullWikiRSS(context, feed);
result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + result;
return result;
}
Aggregations