use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class CheckLockTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null) {
final PageManager mgr = engine.getManager(PageManager.class);
final PageLock lock = mgr.getCurrentLock(page);
final HttpSession session = pageContext.getSession();
final PageLock userLock = (PageLock) session.getAttribute("lock-" + page.getName());
if ((lock != null && m_mode == LockState.LOCKED && lock != userLock) || (lock != null && m_mode == LockState.OWNED && lock == userLock) || (lock == null && m_mode == LockState.NOTLOCKED)) {
final String tid = getId();
if (tid != null && lock != null) {
pageContext.setAttribute(tid, lock);
}
return EVAL_BODY_INCLUDE;
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class PageNameTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null) {
if (page instanceof Attachment) {
pageContext.getOut().print(TextUtil.replaceEntities(((Attachment) page).getFileName()));
} else {
pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(m_wikiContext.getName()));
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class AccessRuleLinkNodePostProcessorState method process.
/**
* {@inheritDoc}
*
* @see NodePostProcessorState#process(NodeTracker, Node)
*/
@Override
public void process(final NodeTracker state, final JSPWikiLink link) {
String ruleLine = NodePostProcessorStateCommonOperations.inlineLinkTextOnWysiwyg(state, link, m_wysiwygEditorMode);
if (wikiContext.getEngine().getManager(RenderingManager.class).getParser(wikiContext, link.getUrl().toString()).isParseAccessRules()) {
final Page page = wikiContext.getRealPage();
if (ruleLine.startsWith("{")) {
ruleLine = ruleLine.substring(1);
}
if (ruleLine.endsWith("}")) {
ruleLine = ruleLine.substring(0, ruleLine.length() - 1);
}
LOG.debug("page=" + page.getName() + ", ACL = " + ruleLine);
try {
final Acl acl = wikiContext.getEngine().getManager(AclManager.class).parseAcl(page, ruleLine);
page.setAcl(acl);
link.unlink();
state.nodeRemoved(link);
LOG.debug(acl.toString());
} catch (final WikiSecurityException wse) {
NodePostProcessorStateCommonOperations.makeError(state, link, wse.getMessage());
}
}
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class SaveWikiPageTaskTest method testSaveWikiPageTask.
@Test
public void testSaveWikiPageTask() throws Exception {
final TestEngine engine = TestEngine.build(with("jspwiki.lucene.initialdelay", "0"), with("jspwiki.lucene.indexdelay", "1"));
final String pageName = "TestSaveWikiPageTestPage";
final Page page = Wiki.contents().page(engine, pageName);
engine.saveText(pageName, "initial text on first revision");
final Context context = Wiki.context().create(engine, engine.newHttpRequest(), page);
final SaveWikiPageTask task = new SaveWikiPageTask();
task.setWorkflow(1, new HashMap<>());
task.getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, "correct horse battery staple");
final Collection<SearchResult> res = new ArrayList<>();
Assertions.assertEquals(Outcome.STEP_COMPLETE, task.execute(context));
Awaitility.await("ensure page gets indexed").until(findsResultsFor(context, res, "horse"));
Assertions.assertEquals(1, res.size(), "no pages found");
Assertions.assertEquals(pageName, res.iterator().next().getPage().getName(), "page");
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class SaveWikiPageTaskTest method testSaveWikiPageTaskWithVersioningFileProvider.
@Test
public void testSaveWikiPageTaskWithVersioningFileProvider() throws Exception {
final TestEngine engine = TestEngine.build(with("jspwiki.pageProvider", "VersioningFileProvider"), with("jspwiki.lucene.initialdelay", "0"), with("jspwiki.lucene.indexdelay", "1"));
final String pageName = "TestSaveWikiPageTestPageWithVersioningFileProvider";
final Page page = Wiki.contents().page(engine, pageName);
engine.saveText(pageName, "initial text on first revision");
final Context context = Wiki.context().create(engine, engine.newHttpRequest(), page);
final SaveWikiPageTask task = new SaveWikiPageTask();
task.setWorkflow(1, new HashMap<>());
task.getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, "It is based on ties of history, culture, language, ethnicity, kinship and geography");
final Collection<SearchResult> res = new ArrayList<>();
Assertions.assertEquals(Outcome.STEP_COMPLETE, task.execute(context));
Awaitility.await("ensure latest version of page gets indexed").until(findsResultsFor(context, res, "kinship"));
Assertions.assertEquals(1, res.size(), "no pages found");
Assertions.assertEquals(pageName, res.iterator().next().getPage().getName(), "page");
}
Aggregations