use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class RSS10Feed method addItemList.
private void addItemList(Element root) {
SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
WikiEngine engine = m_wikiContext.getEngine();
for (Entry entry : m_entries) {
String url = entry.getURL();
Element item = new Element("item", NS_XMNLS);
item.setAttribute("about", url, NS_RDF);
item.addContent(new Element("title", NS_XMNLS).addContent(entry.getTitle()));
item.addContent(new Element("link", NS_XMNLS).addContent(url));
Element content = new Element("description", NS_XMNLS);
// TODO: Add a size limiter here
content.addContent(entry.getContent());
item.addContent(content);
WikiPage p = entry.getPage();
if (p.getVersion() != -1) {
item.addContent(new Element("version", NS_WIKI).addContent(Integer.toString(p.getVersion())));
}
if (p.getVersion() > 1) {
item.addContent(new Element("diff", NS_WIKI).addContent(engine.getURL(WikiContext.DIFF, p.getName(), "r1=-1", true)));
}
//
// Modification date.
Calendar cal = Calendar.getInstance();
cal.setTime(p.getLastModified());
cal.add(Calendar.MILLISECOND, -(cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(p.getLastModified()) ? cal.get(Calendar.DST_OFFSET) : 0)));
item.addContent(new Element("date", NS_DC).addContent(iso8601fmt.format(cal.getTime())));
//
// Author
String author = entry.getAuthor();
if (author == null) {
author = "unknown";
}
Element contributor = new Element("creator", NS_DC);
item.addContent(contributor);
/*
Element description = new Element("Description", NS_RDF);
if( m_wikiContext.getEngine().pageExists(author) ) {
description.setAttribute( "link", engine.getURL( WikiContext.VIEW, author, null, true ), NS_XMNLS );
}
description.addContent( new Element("value", NS_XMNLS).addContent( author) );
contributor.addContent( description );
*/
// Not too many aggregators seem to like this. Therefore we're just adding the name here.
contributor.addContent(author);
//
// PageHistory
item.addContent(new Element("history", NS_WIKI).addContent(engine.getURL(WikiContext.INFO, p.getName(), null, true)));
//
// Add to root
root.addContent(item);
}
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class RSS20Feed method getItems.
private List getItems() {
ArrayList<Element> list = new ArrayList<Element>();
SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
WikiEngine engine = m_wikiContext.getEngine();
ServletContext servletContext = null;
if (m_wikiContext.getHttpRequest() != null)
servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
for (Iterator<Entry> i = m_entries.iterator(); i.hasNext(); ) {
Entry e = i.next();
WikiPage p = e.getPage();
String url = e.getURL();
Element item = new Element("item");
item.addContent(new Element("link").setText(url));
item.addContent(new Element("title").setText(e.getTitle()));
item.addContent(new Element("description").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 = new Element("enclosure");
attEl.setAttribute("url", engine.getURL(WikiContext.ATTACH, att.getName(), null, true));
attEl.setAttribute("length", Long.toString(att.getSize()));
attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
item.addContent(attEl);
}
} catch (ProviderException ex) {
// FIXME: log.info("Can't get attachment data",ex);
}
}
//
// Modification date.
//
Calendar cal = Calendar.getInstance();
cal.setTime(p.getLastModified());
cal.add(Calendar.MILLISECOND, -(cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(p.getLastModified()) ? cal.get(Calendar.DST_OFFSET) : 0)));
item.addContent(new Element("pubDate").setText(fmt.format(cal.getTime())));
list.add(item);
}
return list;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class RSS20Feed method getString.
/**
* {@inheritDoc}
*/
@Override
public String getString() {
WikiEngine engine = m_wikiContext.getEngine();
Element root = new Element("rss");
root.setAttribute("version", "2.0");
Element channel = new Element("channel");
root.addContent(channel);
//
// Mandatory parts
//
channel.addContent(new Element("title").setText(getChannelTitle()));
channel.addContent(new Element("link").setText(engine.getBaseURL()));
channel.addContent(new Element("description").setText(getChannelDescription()));
//
// Optional
//
channel.addContent(new Element("language").setText(getChannelLanguage()));
channel.addContent(new Element("generator").setText("JSPWiki " + Release.VERSTR));
String mail = engine.getVariable(m_wikiContext, RSSGenerator.PROP_RSS_AUTHOREMAIL);
if (mail != null) {
String editor = engine.getVariable(m_wikiContext, RSSGenerator.PROP_RSS_AUTHOR);
if (editor != null)
mail = mail + " (" + editor + ")";
channel.addContent(new Element("managingEditor").setText(mail));
}
//
// Items
//
channel.addContent(getItems());
//
// aaand output
//
XMLOutputter output = new XMLOutputter();
output.setFormat(Format.getPrettyFormat());
try {
StringWriter res = new StringWriter();
output.output(root, res);
return res.toString();
} catch (IOException e) {
return null;
}
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class Groups method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
// Retrieve groups, and sort by name
WikiEngine engine = context.getEngine();
GroupManager groupMgr = engine.getGroupManager();
Principal[] groups = groupMgr.getRoles();
Arrays.sort(groups, COMPARATOR);
StringBuilder s = new StringBuilder();
for (int i = 0; i < groups.length; i++) {
String name = groups[i].getName();
// Make URL
String url = engine.getURLConstructor().makeURL(WikiContext.VIEW_GROUP, name, false, null);
// Create hyperlink
s.append("<a href=\"");
s.append(url);
s.append("\">");
s.append(name);
s.append("</a>");
// If not the last one, add a comma and space
if (i < (groups.length - 1)) {
s.append(',');
s.append(' ');
}
}
return s.toString();
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class Image method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
WikiEngine engine = context.getEngine();
String src = getCleanParameter(params, PARAM_SRC);
String align = getCleanParameter(params, PARAM_ALIGN);
String ht = getCleanParameter(params, PARAM_HEIGHT);
String wt = getCleanParameter(params, PARAM_WIDTH);
String alt = getCleanParameter(params, PARAM_ALT);
String caption = getCleanParameter(params, PARAM_CAPTION);
String link = getCleanParameter(params, PARAM_LINK);
String target = getCleanParameter(params, PARAM_TARGET);
String style = getCleanParameter(params, PARAM_STYLE);
String cssclass = getCleanParameter(params, PARAM_CLASS);
// String map = getCleanParameter( params, PARAM_MAP );
String border = getCleanParameter(params, PARAM_BORDER);
String title = getCleanParameter(params, PARAM_TITLE);
if (src == null) {
throw new PluginException("Parameter 'src' is required for Image plugin");
}
if (target != null && !validTargetValue(target)) {
// not a valid value so ignore
target = null;
}
try {
AttachmentManager mgr = engine.getAttachmentManager();
Attachment att = mgr.getAttachmentInfo(context, src);
if (att != null) {
src = context.getURL(WikiContext.ATTACH, att.getName());
}
} catch (ProviderException e) {
throw new PluginException("Attachment info failed: " + e.getMessage());
}
StringBuilder result = new StringBuilder();
result.append("<table border=\"0\" class=\"imageplugin\"");
if (title != null) {
result.append(" title=\"" + title + "\"");
}
if (align != null) {
if (align.equals("center")) {
result.append(" style=\"margin-left: auto; margin-right: auto; text-align:center; vertical-align:middle;\"");
} else {
result.append(" style=\"float:" + align + ";\"");
}
}
result.append(">\n");
if (caption != null) {
result.append("<caption>" + caption + "</caption>\n");
}
// move css class and style to the container of the image,
// so it doesn't affect the caption
result.append("<tr><td");
if (cssclass != null) {
result.append(" class=\"" + cssclass + "\"");
}
if (style != null) {
result.append(" style=\"" + style);
// Make sure that we add a ";" to the end of the style string
if (result.charAt(result.length() - 1) != ';')
result.append(";");
result.append("\"");
}
result.append(">");
if (link != null) {
result.append("<a href=\"" + link + "\"");
if (target != null) {
result.append(" target=\"" + target + "\"");
}
result.append(">");
}
result.append("<img src=\"" + src + "\"");
if (ht != null)
result.append(" height=\"" + ht + "\"");
if (wt != null)
result.append(" width=\"" + wt + "\"");
if (alt != null)
result.append(" alt=\"" + alt + "\"");
if (border != null)
result.append(" border=\"" + border + "\"");
// if( map != null ) result.append(" map=\""+map+"\"");
result.append(" />");
if (link != null)
result.append("</a>");
result.append("</td></tr>\n");
result.append("</table>\n");
return result.toString();
}
Aggregations