Search in sources :

Example 11 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class CommandResolver method resolvePage.

/**
 * Looks up and returns the correct, versioned WikiPage based on a supplied
 * page name and optional <code>version</code> parameter passed in an HTTP
 * request. If the <code>version</code> parameter does not exist in the
 * request, the latest version is returned.
 * @param request the HTTP request
 * @param page the name of the page to look up; this page <em>must</em> exist
 * @return the wiki page
 */
protected WikiPage resolvePage(HttpServletRequest request, String page) {
    // See if the user included a version parameter
    WikiPage wikipage;
    int version = WikiProvider.LATEST_VERSION;
    String rev = request.getParameter("version");
    if (rev != null) {
        try {
            version = Integer.parseInt(rev);
        } catch (NumberFormatException e) {
        // This happens a lot with bots or other guys who are trying
        // to test if we are vulnerable to e.g. XSS attacks.  We catch
        // it here so that the admin does not get tons of mail.
        }
    }
    wikipage = m_engine.getPage(page, version);
    if (wikipage == null) {
        page = MarkupParser.cleanLink(page);
        wikipage = new WikiPage(m_engine, page);
    }
    return wikipage;
}
Also used : WikiPage(org.apache.wiki.WikiPage)

Example 12 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class AccessRuleLinkNodePostProcessorState method process.

/**
 * {@inheritDoc}
 *
 * @see NodePostProcessorState#process(NodeTracker, JSPWikiLink)
 */
@Override
public void process(final NodeTracker state, final JSPWikiLink link) {
    String ruleLine = NodePostProcessorStateCommonOperations.inlineLinkTextOnWysiwyg(state, link, m_wysiwygEditorMode);
    if (wikiContext.getEngine().getRenderingManager().getParser(wikiContext, link.getUrl().toString()).isParseAccessRules()) {
        final WikiPage 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().getAclManager().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) WikiPage(org.apache.wiki.WikiPage) Acl(org.apache.wiki.auth.acl.Acl)

Example 13 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class WeblogEntryPlugin method findFreeEntry.

private int findFreeEntry(PageManager mgr, String baseName, String date) throws ProviderException {
    Collection everyone = mgr.getAllPages();
    int max = 0;
    String startString = WeblogPlugin.makeEntryPage(baseName, date, "");
    for (Iterator i = everyone.iterator(); i.hasNext(); ) {
        WikiPage p = (WikiPage) i.next();
        if (p.getName().startsWith(startString)) {
            try {
                String probableId = p.getName().substring(startString.length());
                int id = Integer.parseInt(probableId);
                if (id > max) {
                    max = id;
                }
            } catch (NumberFormatException e) {
                log.debug("Was not a log entry: " + p.getName());
            }
        }
    }
    // 
    // Find the first page that has no page lock.
    // 
    int idx = max + 1;
    while (idx < MAX_BLOG_ENTRIES) {
        WikiPage page = new WikiPage(mgr.getEngine(), WeblogPlugin.makeEntryPage(baseName, date, Integer.toString(idx)));
        PageLock lock = mgr.getCurrentLock(page);
        if (lock == null) {
            break;
        }
        idx++;
    }
    return idx;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Iterator(java.util.Iterator) Collection(java.util.Collection) PageLock(org.apache.wiki.PageLock)

Example 14 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class AbstractFileProvider method getPageInfo.

/**
 *  Always returns the latest version, since FileSystemProvider
 *  does not support versioning.
 *
 *  @param page {@inheritDoc}
 *  @param version {@inheritDoc}
 *  @return {@inheritDoc}
 *  @throws {@inheritDoc}
 */
public WikiPage getPageInfo(String page, int version) throws ProviderException {
    File file = findPage(page);
    if (!file.exists()) {
        return null;
    }
    WikiPage p = new WikiPage(m_engine, page);
    p.setLastModified(new Date(file.lastModified()));
    return p;
}
Also used : WikiPage(org.apache.wiki.WikiPage) File(java.io.File) Date(java.util.Date)

Example 15 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class BasicAttachmentProvider method listAllChanged.

/**
 *  {@inheritDoc}
 */
// FIXME: Very unoptimized.
public List listAllChanged(Date timestamp) throws ProviderException {
    File attDir = new File(m_storageDir);
    if (!attDir.exists()) {
        throw new ProviderException("Specified attachment directory " + m_storageDir + " does not exist!");
    }
    ArrayList<Attachment> list = new ArrayList<Attachment>();
    String[] pagesWithAttachments = attDir.list(new AttachmentFilter());
    for (int i = 0; i < pagesWithAttachments.length; i++) {
        String pageId = unmangleName(pagesWithAttachments[i]);
        pageId = pageId.substring(0, pageId.length() - DIR_EXTENSION.length());
        Collection c = listAttachments(new WikiPage(m_engine, pageId));
        for (Iterator it = c.iterator(); it.hasNext(); ) {
            Attachment att = (Attachment) it.next();
            if (att.getLastModified().after(timestamp)) {
                list.add(att);
            }
        }
    }
    Collections.sort(list, new PageTimeComparator());
    return list;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) WikiPage(org.apache.wiki.WikiPage) ArrayList(java.util.ArrayList) Attachment(org.apache.wiki.attachment.Attachment) Iterator(java.util.Iterator) Collection(java.util.Collection) File(java.io.File) PageTimeComparator(org.apache.wiki.util.comparators.PageTimeComparator)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7