Search in sources :

Example 51 with WikiEngine

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);
    }
}
Also used : Element(org.jdom2.Element) WikiPage(org.apache.wiki.WikiPage) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) WikiEngine(org.apache.wiki.WikiEngine)

Example 52 with WikiEngine

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;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) Element(org.jdom2.Element) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) ServletContext(javax.servlet.ServletContext) SimpleDateFormat(java.text.SimpleDateFormat) WikiEngine(org.apache.wiki.WikiEngine)

Example 53 with WikiEngine

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;
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) Element(org.jdom2.Element) IOException(java.io.IOException) WikiEngine(org.apache.wiki.WikiEngine)

Example 54 with WikiEngine

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();
}
Also used : WikiEngine(org.apache.wiki.WikiEngine) GroupManager(org.apache.wiki.auth.authorize.GroupManager) Principal(java.security.Principal)

Example 55 with WikiEngine

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();
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) PluginException(org.apache.wiki.api.exceptions.PluginException) Attachment(org.apache.wiki.attachment.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) WikiEngine(org.apache.wiki.WikiEngine)

Aggregations

WikiEngine (org.apache.wiki.WikiEngine)67 WikiPage (org.apache.wiki.WikiPage)29 ProviderException (org.apache.wiki.api.exceptions.ProviderException)15 Attachment (org.apache.wiki.attachment.Attachment)10 WikiContext (org.apache.wiki.WikiContext)9 Properties (java.util.Properties)8 JspWriter (javax.servlet.jsp.JspWriter)8 TestEngine (org.apache.wiki.TestEngine)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Calendar (java.util.Calendar)5 Date (java.util.Date)5 ResourceBundle (java.util.ResourceBundle)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 Before (org.junit.Before)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 InternalWikiException (org.apache.wiki.InternalWikiException)4 ArrayList (java.util.ArrayList)3