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));
}
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;
}
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);
}
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);
}
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);
}
Aggregations