use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class AtomFeed method getItems.
private Collection getItems() {
ArrayList<Element> list = new ArrayList<Element>();
WikiEngine engine = m_wikiContext.getEngine();
ServletContext servletContext = null;
if (m_wikiContext.getHttpRequest() != null)
servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
for (Iterator i = m_entries.iterator(); i.hasNext(); ) {
Entry e = (Entry) i.next();
WikiPage p = e.getPage();
Element entryEl = getElement("entry");
//
// Mandatory elements
//
entryEl.addContent(getElement("id").setText(getEntryID(e)));
entryEl.addContent(getElement("title").setAttribute("type", "html").setText(e.getTitle()));
entryEl.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(p.getLastModified(), RFC3339FORMAT)));
//
// Optional elements
//
entryEl.addContent(getElement("author").addContent(getElement("name").setText(e.getAuthor())));
entryEl.addContent(getElement("link").setAttribute("rel", "alternate").setAttribute("href", e.getURL()));
entryEl.addContent(getElement("content").setAttribute("type", "html").setText(e.getContent()));
if (engine.getAttachmentManager().hasAttachments(p) && servletContext != null) {
try {
Collection c = engine.getAttachmentManager().listAttachments(p);
for (Iterator a = c.iterator(); a.hasNext(); ) {
Attachment att = (Attachment) a.next();
Element attEl = getElement("link");
attEl.setAttribute("rel", "enclosure");
attEl.setAttribute("href", engine.getURL(WikiContext.ATTACH, att.getName(), null, true));
attEl.setAttribute("length", Long.toString(att.getSize()));
attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
entryEl.addContent(attEl);
}
} catch (ProviderException ex) {
// FIXME: log.info("Can't get attachment data",ex);
}
}
list.add(entryEl);
}
return list;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class RSSGenerator method generateBlogRSS.
/**
* Creates RSS from modifications as if this page was a blog (using the WeblogPlugin).
*
* @param wikiContext The WikiContext, as usual.
* @param changed A list of the changed pages.
* @param feed A valid Feed object. The feed will be used to create the RSS/Atom, depending
* on which kind of an object you want to put in it.
* @return A String of valid RSS or Atom.
* @throws ProviderException If reading of pages was not possible.
*/
@SuppressWarnings("unchecked")
protected String generateBlogRSS(WikiContext wikiContext, List changed, Feed feed) throws ProviderException {
if (log.isDebugEnabled())
log.debug("Generating RSS for blog, size=" + changed.size());
String ctitle = m_engine.getVariable(wikiContext, PROP_CHANNEL_TITLE);
if (ctitle != null)
feed.setChannelTitle(ctitle);
else
feed.setChannelTitle(m_engine.getApplicationName() + ":" + wikiContext.getPage().getName());
feed.setFeedURL(wikiContext.getViewURL(wikiContext.getPage().getName()));
String language = m_engine.getVariable(wikiContext, PROP_CHANNEL_LANGUAGE);
if (language != null)
feed.setChannelLanguage(language);
else
feed.setChannelLanguage(m_channelLanguage);
String channelDescription = m_engine.getVariable(wikiContext, PROP_CHANNEL_DESCRIPTION);
if (channelDescription != null) {
feed.setChannelDescription(channelDescription);
}
Collections.sort(changed, new PageTimeComparator());
int items = 0;
for (Iterator i = changed.iterator(); i.hasNext() && items < 15; items++) {
WikiPage page = (WikiPage) i.next();
Entry e = new Entry();
e.setPage(page);
String url;
if (page instanceof Attachment) {
url = m_engine.getURL(WikiContext.ATTACH, page.getName(), null, true);
} else {
url = m_engine.getURL(WikiContext.VIEW, page.getName(), null, true);
}
e.setURL(url);
//
// Title
//
String pageText = m_engine.getPureText(page.getName(), WikiProvider.LATEST_VERSION);
String title = "";
int firstLine = pageText.indexOf('\n');
if (firstLine > 0) {
title = pageText.substring(0, firstLine).trim();
}
if (title.length() == 0)
title = page.getName();
// Remove wiki formatting
while (title.startsWith("!")) title = title.substring(1);
e.setTitle(title);
if (firstLine > 0) {
int maxlen = pageText.length();
if (maxlen > MAX_CHARACTERS)
maxlen = MAX_CHARACTERS;
if (maxlen > 0) {
pageText = m_engine.textToHTML(wikiContext, pageText.substring(firstLine + 1, maxlen).trim());
if (maxlen == MAX_CHARACTERS)
pageText += "...";
e.setContent(pageText);
} else {
e.setContent(title);
}
} else {
e.setContent(title);
}
e.setAuthor(getAuthor(page));
feed.addEntry(e);
}
return feed.getString();
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class AttachmentsIteratorTag method doAfterBody.
/**
* {@inheritDoc}
*/
@Override
public final int doAfterBody() {
if (bodyContent != null) {
try {
JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
bodyContent.clearBody();
} catch (IOException e) {
log.error("Unable to get inner tag text", e);
// FIXME: throw something?
}
}
if (m_iterator != null && m_iterator.hasNext()) {
Attachment att = (Attachment) m_iterator.next();
WikiContext context = (WikiContext) m_wikiContext.clone();
context.setPage(att);
pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), att);
return EVAL_BODY_BUFFERED;
}
return SKIP_BODY;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class LinkToTag method doWikiStartTag.
public int doWikiStartTag() throws IOException {
String pageName = m_pageName;
boolean isattachment = false;
if (m_pageName == null) {
WikiPage p = m_wikiContext.getPage();
if (p != null) {
pageName = p.getName();
isattachment = p instanceof Attachment;
} else {
return SKIP_BODY;
}
}
JspWriter out = pageContext.getOut();
String url;
String linkclass;
if (isattachment) {
url = m_wikiContext.getURL(WikiContext.ATTACH, pageName, (getVersion() != null) ? "version=" + getVersion() : null);
linkclass = "attachment";
} else {
StringBuilder params = new StringBuilder();
if (getVersion() != null)
params.append("version=" + getVersion());
if (getTemplate() != null)
params.append((params.length() > 0 ? "&" : "") + "skin=" + getTemplate());
url = m_wikiContext.getURL(WikiContext.VIEW, pageName, params.toString());
linkclass = "wikipage";
}
switch(m_format) {
case ANCHOR:
out.print("<a class=\"" + linkclass + "\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
break;
case URL:
out.print(url);
break;
}
return EVAL_BODY_INCLUDE;
}
use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.
the class PageNameTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
if (page != null) {
if (page instanceof Attachment) {
pageContext.getOut().print(((Attachment) page).getFileName());
} else {
pageContext.getOut().print(engine.beautifyTitle(m_wikiContext.getName()));
}
}
return SKIP_BODY;
}
Aggregations