Search in sources :

Example 6 with PageManager

use of org.apache.wiki.PageManager in project jspwiki by apache.

the class WeblogPlugin method findBlogEntries.

/**
 *  Attempts to locate all pages that correspond to the
 *  blog entry pattern.  Will only consider the days on the dates; not the hours and minutes.
 *
 *  @param engine WikiEngine which is used to get the pages
 *  @param baseName The basename (e.g. "Main" if you want "Main_blogentry_xxxx")
 *  @param start The date which is the first to be considered
 *  @param end   The end date which is the last to be considered
 *  @return a list of pages with their FIRST revisions.
 *  @throws ProviderException If something goes wrong
 */
public List findBlogEntries(WikiEngine engine, String baseName, Date start, Date end) throws ProviderException {
    PageManager mgr = engine.getPageManager();
    Set allPages = engine.getReferenceManager().findCreated();
    ArrayList<WikiPage> result = new ArrayList<WikiPage>();
    baseName = makeEntryPage(baseName);
    for (Iterator i = allPages.iterator(); i.hasNext(); ) {
        String pageName = (String) i.next();
        if (pageName.startsWith(baseName)) {
            try {
                WikiPage firstVersion = mgr.getPageInfo(pageName, 1);
                Date d = firstVersion.getLastModified();
                if (d.after(start) && d.before(end)) {
                    result.add(firstVersion);
                }
            } catch (Exception e) {
                log.debug("Page name :" + pageName + " was suspected as a blog entry but it isn't because of parsing errors", e);
            }
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.PageManager) Set(java.util.Set) WikiPage(org.apache.wiki.WikiPage) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Date(java.util.Date) PluginException(org.apache.wiki.api.exceptions.PluginException) ParseException(java.text.ParseException) ProviderException(org.apache.wiki.api.exceptions.ProviderException)

Example 7 with PageManager

use of org.apache.wiki.PageManager in project jspwiki by apache.

the class ListLocksPlugin method execute.

/**
 *  {@inheritDoc}
 */
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
    StringBuilder result = new StringBuilder();
    PageManager mgr = context.getEngine().getPageManager();
    List<PageLock> locks = mgr.getActiveLocks();
    ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
    result.append("<table class=\"wikitable\">\n");
    result.append("<tr>\n");
    result.append("<th>" + rb.getString("plugin.listlocks.page") + "</th><th>" + rb.getString("plugin.listlocks.locked.by") + "</th><th>" + rb.getString("plugin.listlocks.acquired") + "</th><th>" + rb.getString("plugin.listlocks.expires") + "</th>\n");
    result.append("</tr>");
    if (locks.size() == 0) {
        result.append("<tr><td colspan=\"4\" class=\"odd\">" + rb.getString("plugin.listlocks.no.locks.exist") + "</td></tr>\n");
    } else {
        int rowNum = 1;
        for (Iterator<PageLock> i = locks.iterator(); i.hasNext(); ) {
            PageLock lock = i.next();
            result.append(rowNum % 2 != 0 ? "<tr class=\"odd\">" : "<tr>");
            result.append("<td>" + lock.getPage() + "</td>");
            result.append("<td>" + lock.getLocker() + "</td>");
            result.append("<td>" + Preferences.renderDate(context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME) + "</td>");
            result.append("<td>" + Preferences.renderDate(context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME) + "</td>");
            result.append("</tr>\n");
            rowNum++;
        }
    }
    result.append("</table>");
    return result.toString();
}
Also used : PageManager(org.apache.wiki.PageManager) ResourceBundle(java.util.ResourceBundle) PageLock(org.apache.wiki.PageLock)

Aggregations

PageManager (org.apache.wiki.PageManager)7 PageLock (org.apache.wiki.PageLock)3 WikiPage (org.apache.wiki.WikiPage)3 Test (org.junit.Test)3 ProviderException (org.apache.wiki.api.exceptions.ProviderException)2 File (java.io.File)1 Principal (java.security.Principal)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 HttpSession (javax.servlet.http.HttpSession)1 WikiEngine (org.apache.wiki.WikiEngine)1 WikiSession (org.apache.wiki.WikiSession)1 WikiSessionTest (org.apache.wiki.WikiSessionTest)1 PluginException (org.apache.wiki.api.exceptions.PluginException)1