Search in sources :

Example 96 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class RPCHandlerUTF8 method getAllPages.

public Vector<String> getAllPages() {
    checkPermission(PagePermission.VIEW);
    final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
    final Vector<String> result = new Vector<>();
    for (final Page p : pages) {
        if (!(p instanceof Attachment)) {
            result.add(p.getName());
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Vector(java.util.Vector)

Example 97 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class RPCHandlerUTF8 method parsePageCheckCondition.

/**
 *  Simple helper method, turns the incoming page name into
 *  normal Java string, then checks page condition.
 *
 *  @param pagename Page Name as an RPC string (URL-encoded UTF-8)
 *  @return Real page name, as Java string.
 *  @throws XmlRpcException, if there is something wrong with the page.
 */
private String parsePageCheckCondition(final String pagename) throws XmlRpcException {
    if (!m_engine.getManager(PageManager.class).wikiPageExists(pagename)) {
        throw new XmlRpcException(ERR_NOPAGE, "No such page '" + pagename + "' found, o master.");
    }
    final Page p = m_engine.getManager(PageManager.class).getPage(pagename);
    checkPermission(PermissionFactory.getPagePermission(p, PagePermission.VIEW_ACTION));
    return pagename;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 98 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class RPCHandlerUTF8 method listLinks.

public Vector<Hashtable<String, String>> listLinks(String pagename) throws XmlRpcException {
    pagename = parsePageCheckCondition(pagename);
    final Page page = m_engine.getManager(PageManager.class).getPage(pagename);
    final String pagedata = m_engine.getManager(PageManager.class).getPureText(page);
    final LinkCollector localCollector = new LinkCollector();
    final LinkCollector extCollector = new LinkCollector();
    final LinkCollector attCollector = new LinkCollector();
    final Context context = Wiki.context().create(m_engine, page);
    m_engine.getManager(RenderingManager.class).textToHTML(context, pagedata, localCollector, extCollector, attCollector);
    final Vector<Hashtable<String, String>> result = new Vector<>();
    // 
    for (final String link : localCollector.getLinks()) {
        final Hashtable<String, String> ht = new Hashtable<>();
        ht.put("page", link);
        ht.put("type", LINK_LOCAL);
        if (m_engine.getManager(PageManager.class).wikiPageExists(link)) {
            ht.put("href", context.getViewURL(link));
        } else {
            ht.put("href", context.getURL(ContextEnum.PAGE_EDIT.getRequestContext(), link));
        }
        result.add(ht);
    }
    // 
    for (final String link : attCollector.getLinks()) {
        final Hashtable<String, String> ht = new Hashtable<>();
        ht.put("page", link);
        ht.put("type", LINK_LOCAL);
        ht.put("href", context.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), link));
        result.add(ht);
    }
    // 
    for (final String link : extCollector.getLinks()) {
        final Hashtable<String, String> ht = new Hashtable<>();
        ht.put("page", link);
        ht.put("type", LINK_EXTERNAL);
        ht.put("href", link);
        result.add(ht);
    }
    return result;
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) Hashtable(java.util.Hashtable) Page(org.apache.wiki.api.core.Page) LinkCollector(org.apache.wiki.LinkCollector) Vector(java.util.Vector)

Example 99 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class WikiEngineTest method testOldVersionVars.

/**
 *  Tests BugReadingOfVariableNotWorkingForOlderVersions
 */
@Test
public void testOldVersionVars() throws Exception {
    final Properties props = TestEngine.getTestProperties("/jspwiki-vers-custom.properties");
    props.setProperty(CachingManager.PROP_CACHE_ENABLE, "true");
    final TestEngine engine = new TestEngine(props);
    engine.saveText(NAME1, "[{SET foo=bar}]");
    engine.saveText(NAME1, "[{SET foo=notbar}]");
    final Page v1 = engine.getManager(PageManager.class).getPage(NAME1, 1);
    final Page v2 = engine.getManager(PageManager.class).getPage(NAME1, 2);
    Assertions.assertEquals("bar", v1.getAttribute("foo"), "V1");
    Assertions.assertEquals("notbar", v2.getAttribute("foo"), "V2");
    engine.getManager(PageManager.class).deletePage(NAME1);
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 100 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class WikiEngineTest method testChangeNoteOldVersion2.

@Test
public void testChangeNoteOldVersion2() throws Exception {
    final Page p = Wiki.contents().page(m_engine, NAME1);
    final Context context = Wiki.context().create(m_engine, p);
    context.getPage().setAttribute(Page.CHANGENOTE, "Test change");
    m_engine.getManager(PageManager.class).saveText(context, "test");
    for (int i = 0; i < 5; i++) {
        final Page p2 = m_engine.getManager(PageManager.class).getPage(NAME1).clone();
        p2.removeAttribute(Page.CHANGENOTE);
        context.setPage(p2);
        m_engine.getManager(PageManager.class).saveText(context, "test" + i);
    }
    final Page p3 = m_engine.getManager(PageManager.class).getPage(NAME1, -1);
    Assertions.assertNull(p3.getAttribute(Page.CHANGENOTE));
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8