Search in sources :

Example 61 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class WikiEngine method deletePage.

/**
 *  Deletes a page or an attachment completely, including all versions.  If the page
 *  does not exist, does nothing.
 *
 * @param pageName The name of the page.
 * @throws ProviderException If something goes wrong.
 */
public void deletePage(String pageName) throws ProviderException {
    WikiPage p = getPage(pageName);
    if (p != null) {
        if (p instanceof Attachment) {
            m_attachmentManager.deleteAttachment((Attachment) p);
        } else {
            Collection<String> refTo = m_referenceManager.findRefersTo(pageName);
            if (m_attachmentManager.hasAttachments(p)) {
                Collection attachments = m_attachmentManager.listAttachments(p);
                for (Iterator atti = attachments.iterator(); atti.hasNext(); ) {
                    Attachment attachment = (Attachment) atti.next();
                    refTo.remove(attachment.getName());
                    m_attachmentManager.deleteAttachment(attachment);
                }
            }
            m_pageManager.deletePage(p);
            firePageEvent(WikiPageEvent.PAGE_DELETED, pageName);
        }
    }
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) Attachment(org.apache.wiki.attachment.Attachment)

Example 62 with Attachment

use of org.apache.wiki.attachment.Attachment in project jspwiki by apache.

the class DefaultAclManager method getPermissions.

/**
 * Returns the access control list for the page.
 * If the ACL has not been parsed yet, it is done
 * on-the-fly. If the page has a parent page, then that is tried also.
 * This method was moved from Authorizer;
 * it was consolidated with some code from AuthorizationManager.
 * This method is guaranteed to return a non-<code>null</code> Acl.
 *
 * @param page the page
 * @return the Acl representing permissions for the page
 * @since 2.2.121
 */
public Acl getPermissions(WikiPage page) {
    // 
    // Does the page already have cached ACLs?
    // 
    Acl acl = page.getAcl();
    log.debug("page=" + page.getName() + "\n" + acl);
    if (acl == null) {
        // 
        if (page instanceof Attachment) {
            WikiPage parent = m_engine.getPage(((Attachment) page).getParentName());
            acl = getPermissions(parent);
        } else {
            // 
            // Or, try parsing the page
            // 
            WikiContext ctx = new WikiContext(m_engine, page);
            ctx.setVariable(RenderingManager.VAR_EXECUTE_PLUGINS, Boolean.FALSE);
            m_engine.getHTML(ctx, page);
            if (page.getAcl() == null) {
                page.setAcl(new AclImpl());
            }
            acl = page.getAcl();
        }
    }
    return acl;
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment)

Aggregations

Attachment (org.apache.wiki.attachment.Attachment)62 WikiPage (org.apache.wiki.WikiPage)26 Test (org.junit.Test)23 File (java.io.File)20 ProviderException (org.apache.wiki.api.exceptions.ProviderException)17 Collection (java.util.Collection)13 Date (java.util.Date)11 Iterator (java.util.Iterator)10 WikiEngine (org.apache.wiki.WikiEngine)10 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)7 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 List (java.util.List)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)5 Hashtable (java.util.Hashtable)4 Element (net.sf.ehcache.Element)4 PagePermission (org.apache.wiki.auth.permissions.PagePermission)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3