Search in sources :

Example 41 with Page

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;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) HttpSession(javax.servlet.http.HttpSession) Page(org.apache.wiki.api.core.Page) PageLock(org.apache.wiki.pages.PageLock) Engine(org.apache.wiki.api.core.Engine)

Example 42 with Page

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;
}
Also used : Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Engine(org.apache.wiki.api.core.Engine)

Example 43 with Page

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());
        }
    }
}
Also used : WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) Page(org.apache.wiki.api.core.Page) Acl(org.apache.wiki.api.core.Acl) AclManager(org.apache.wiki.auth.acl.AclManager)

Example 44 with Page

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");
}
Also used : Context(org.apache.wiki.api.core.Context) ArrayList(java.util.ArrayList) Page(org.apache.wiki.api.core.Page) SearchResult(org.apache.wiki.api.search.SearchResult) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.jupiter.api.Test)

Example 45 with 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");
}
Also used : Context(org.apache.wiki.api.core.Context) ArrayList(java.util.ArrayList) Page(org.apache.wiki.api.core.Page) SearchResult(org.apache.wiki.api.search.SearchResult) TestEngine(org.apache.wiki.TestEngine) 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