Search in sources :

Example 6 with PageManager

use of org.apache.wiki.pages.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 Engine 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.
 */
public List<Page> findBlogEntries(final Engine engine, String baseName, final Date start, final Date end) {
    final PageManager mgr = engine.getManager(PageManager.class);
    final Set<String> allPages = engine.getManager(ReferenceManager.class).findCreated();
    final ArrayList<Page> result = new ArrayList<>();
    baseName = makeEntryPage(baseName);
    for (final String pageName : allPages) {
        if (pageName.startsWith(baseName)) {
            try {
                final Page firstVersion = mgr.getPageInfo(pageName, 1);
                final Date d = firstVersion.getLastModified();
                if (d.after(start) && d.before(end)) {
                    result.add(firstVersion);
                }
            } catch (final 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.pages.PageManager) ArrayList(java.util.ArrayList) Page(org.apache.wiki.api.core.Page) Date(java.util.Date) PluginException(org.apache.wiki.api.exceptions.PluginException) ParseException(java.text.ParseException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) ReferenceManager(org.apache.wiki.references.ReferenceManager)

Example 7 with PageManager

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

the class VersioningFileProviderTest method testDelete.

@Test
public void testDelete() throws Exception {
    engine.saveText(NAME1, "v1");
    engine.saveText(NAME1, "v2");
    engine.saveText(NAME1, "v3");
    final PageManager mgr = engine.getManager(PageManager.class);
    final PageProvider provider = mgr.getProvider();
    provider.deletePage(NAME1);
    final File f = new File(files, NAME1 + AbstractFileProvider.FILE_EXT);
    Assertions.assertFalse(f.exists(), "file exists");
}
Also used : PageManager(org.apache.wiki.pages.PageManager) PageProvider(org.apache.wiki.api.providers.PageProvider) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with PageManager

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

the class VersioningFileProviderTest method testDeleteVersion.

@Test
public void testDeleteVersion() throws Exception {
    engine.saveText(NAME1, "v1\r\n");
    engine.saveText(NAME1, "v2\r\n");
    engine.saveText(NAME1, "v3\r\n");
    final PageManager mgr = engine.getManager(PageManager.class);
    final PageProvider provider = mgr.getProvider();
    List<Page> l = provider.getVersionHistory(NAME1);
    Assertions.assertEquals(3, l.size(), "wrong # of versions");
    provider.deleteVersion(NAME1, 2);
    l = provider.getVersionHistory(NAME1);
    Assertions.assertEquals(2, l.size(), "wrong # of versions");
    Assertions.assertEquals("v1\r\n", provider.getPageText(NAME1, 1), "v1");
    Assertions.assertEquals("v3\r\n", provider.getPageText(NAME1, 3), "v3");
    try {
        provider.getPageText(NAME1, 2);
        Assertions.fail("v2");
    } catch (final NoSuchVersionException e) {
    // This is expected
    }
}
Also used : PageManager(org.apache.wiki.pages.PageManager) PageProvider(org.apache.wiki.api.providers.PageProvider) WikiPage(org.apache.wiki.WikiPage) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Aggregations

PageManager (org.apache.wiki.pages.PageManager)8 Page (org.apache.wiki.api.core.Page)4 PageLock (org.apache.wiki.pages.PageLock)3 Test (org.junit.jupiter.api.Test)3 ProviderException (org.apache.wiki.api.exceptions.ProviderException)2 PageProvider (org.apache.wiki.api.providers.PageProvider)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 ResourceBundle (java.util.ResourceBundle)1 Matcher (java.util.regex.Matcher)1 HttpSession (javax.servlet.http.HttpSession)1 WikiPage (org.apache.wiki.WikiPage)1 WikiSessionTest (org.apache.wiki.WikiSessionTest)1 Context (org.apache.wiki.api.core.Context)1 Engine (org.apache.wiki.api.core.Engine)1 Session (org.apache.wiki.api.core.Session)1 PluginException (org.apache.wiki.api.exceptions.PluginException)1