Search in sources :

Example 46 with Context

use of org.apache.wiki.api.core.Context 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)

Example 47 with Context

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

the class RPCHandler 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", toRPCString(link));
        ht.put("type", LINK_LOCAL);
        if (m_engine.getManager(PageManager.class).wikiPageExists(link)) {
            ht.put("href", context.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), 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", toRPCString(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 48 with Context

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

the class TestEngine method saveTextAsJanne.

public void saveTextAsJanne(final String pageName, final String content) throws WikiException {
    // Build new request and associate our Janne session
    final MockHttpServletRequest request = newHttpRequest();
    final Session wikiSession = SessionMonitor.getInstance(this).find(request.getSession());
    this.getManager(AuthenticationManager.class).login(wikiSession, request, Users.JANNE, Users.JANNE_PASS);
    // Create page and wiki context
    final Page page = Wiki.contents().page(this, pageName);
    page.setAuthor(Users.JANNE);
    final Context context = Wiki.context().create(this, request, page);
    getManager(PageManager.class).saveText(context, content);
}
Also used : AuthenticationManager(org.apache.wiki.auth.AuthenticationManager) Context(org.apache.wiki.api.core.Context) MockServletContext(net.sourceforge.stripes.mock.MockServletContext) ServletContext(javax.servlet.ServletContext) PageManager(org.apache.wiki.pages.PageManager) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) Page(org.apache.wiki.api.core.Page) MockHttpSession(net.sourceforge.stripes.mock.MockHttpSession) Session(org.apache.wiki.api.core.Session)

Example 49 with Context

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

the class TestEngine method saveText.

/**
 * Convenience method that saves a wiki page by constructing a fake WikiContext and HttpServletRequest. We always want to do this
 * using a WikiContext whose subject contains Role.ADMIN. Note: the WikiPage author will have the default value of "Guest".
 *
 * @param pageName page name
 * @param content page content
 * @throws WikiException associated login operation or page save had some trouble
 */
public void saveText(final String pageName, final String content) throws WikiException {
    // Build new request and associate our admin session
    final MockHttpServletRequest request = newHttpRequest();
    final Session wikiSession = SessionMonitor.getInstance(this).find(request.getSession());
    this.getManager(AuthenticationManager.class).login(wikiSession, request, Users.ADMIN, Users.ADMIN_PASS);
    // Create page and wiki context
    final Page page = Wiki.contents().page(this, pageName);
    final Context context = Wiki.context().create(this, request, page);
    getManager(PageManager.class).saveText(context, content);
}
Also used : AuthenticationManager(org.apache.wiki.auth.AuthenticationManager) Context(org.apache.wiki.api.core.Context) MockServletContext(net.sourceforge.stripes.mock.MockServletContext) ServletContext(javax.servlet.ServletContext) PageManager(org.apache.wiki.pages.PageManager) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) Page(org.apache.wiki.api.core.Page) MockHttpSession(net.sourceforge.stripes.mock.MockHttpSession) Session(org.apache.wiki.api.core.Session)

Example 50 with Context

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

the class UserManagerTest method testSetCollidingUserProfile.

@Test
public void testSetCollidingUserProfile() throws Exception {
    // First, count the number of users in the db now.
    final int oldUserCount = m_db.getWikiNames().length;
    // Create a new user with random name
    final Context context = Wiki.context().create(m_engine, m_engine.newHttpRequest(), "");
    final String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
    final UserProfile profile = m_db.newProfile();
    profile.setEmail("jspwiki.tests@mailinator.com");
    profile.setLoginName(loginName);
    profile.setFullname("FullName" + loginName);
    profile.setPassword("password");
    // Set the login name to collide with Janne's: should prohibit saving
    profile.setLoginName("janne");
    try {
        m_mgr.setUserProfile(context, profile);
        Assertions.fail("UserManager allowed saving of user with login name 'janne', but it shouldn't have.");
    } catch (final DuplicateUserException e) {
        // Good! That's what we expected; reset for next test
        profile.setLoginName(loginName);
    }
    // Set the login name to collide with Janne's: should prohibit saving
    profile.setFullname("Janne Jalkanen");
    try {
        m_mgr.setUserProfile(context, profile);
        Assertions.fail("UserManager allowed saving of user with login name 'janne', but it shouldn't have.");
    } catch (final DuplicateUserException e) {
    // Good! That's what we expected
    }
    // There shouldn't have been any users added
    Assertions.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
Also used : Context(org.apache.wiki.api.core.Context) UserProfile(org.apache.wiki.auth.user.UserProfile) DuplicateUserException(org.apache.wiki.auth.user.DuplicateUserException) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.jupiter.api.Test)

Aggregations

Context (org.apache.wiki.api.core.Context)81 Page (org.apache.wiki.api.core.Page)46 PageManager (org.apache.wiki.pages.PageManager)42 Test (org.junit.jupiter.api.Test)40 RenderingManager (org.apache.wiki.render.RenderingManager)15 PageContext (javax.servlet.jsp.PageContext)11 Engine (org.apache.wiki.api.core.Engine)9 ReferenceManager (org.apache.wiki.references.ReferenceManager)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 ServletContext (javax.servlet.ServletContext)6 ProviderException (org.apache.wiki.api.exceptions.ProviderException)6 WikiContext (org.apache.wiki.WikiContext)5 StringReader (java.io.StringReader)4 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiSessionTest (org.apache.wiki.WikiSessionTest)4 Attachment (org.apache.wiki.api.core.Attachment)4 SearchResult (org.apache.wiki.api.search.SearchResult)4