Search in sources :

Example 6 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class AbstractFileProvider method getPageInfo.

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

Example 7 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class VersioningFileProvider method getPageInfo.

/**
 *  {@inheritDoc}
 */
@Override
public Page getPageInfo(final String page, final int version) throws ProviderException {
    final int latest = findLatestVersion(page);
    final int realVersion;
    Page p = null;
    if (version == PageProvider.LATEST_VERSION || version == latest || (version == 1 && latest == -1)) {
        // 
        // Yes, we need to talk to the top level directory to get this version.
        // 
        // I am listening to Press Play On Tape's guitar version of the good old C64 "Wizardry" -tune at this moment.
        // Oh, the memories...
        // 
        realVersion = (latest >= 0) ? latest : 1;
        p = super.getPageInfo(page, PageProvider.LATEST_VERSION);
        if (p != null) {
            p.setVersion(realVersion);
        }
    } else {
        // The file is not the most recent, so we'll need to find it from the deep trenches of the "OLD" directory structure.
        realVersion = version;
        final File dir = findOldPageDir(page);
        if (!dir.exists() || !dir.isDirectory()) {
            return null;
        }
        final File file = new File(dir, version + FILE_EXT);
        if (file.exists()) {
            p = Wiki.contents().page(m_engine, page);
            p.setLastModified(new Date(file.lastModified()));
            p.setVersion(version);
        }
    }
    // Get author and other metadata information (Modification date has already been set.)
    if (p != null) {
        try {
            final Properties props = getPageProperties(page);
            String author = props.getProperty(realVersion + ".author");
            if (author == null) {
                // we might not have a versioned author because the old page was last maintained by FileSystemProvider
                final Properties props2 = getHeritagePageProperties(page);
                author = props2.getProperty(Page.AUTHOR);
            }
            if (author != null) {
                p.setAuthor(author);
            }
            final String changenote = props.getProperty(realVersion + ".changenote");
            if (changenote != null) {
                p.setAttribute(Page.CHANGENOTE, changenote);
            }
            // Set the props values to the page attributes
            setCustomProperties(p, props);
        } catch (final IOException e) {
            log.error("Cannot get author for page" + page + ": ", e);
        }
    }
    return p;
}
Also used : Page(org.apache.wiki.api.core.Page) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Date(java.util.Date)

Example 8 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class DefaultReferenceManager method buildKeyLists.

/**
 * When initially building a ReferenceManager from scratch, call this method BEFORE calling updateReferences() with
 * a full list of existing page names. It builds the refersTo and referredBy key lists, thus enabling updateReferences()
 * to function correctly.
 * <P>
 * This method should NEVER be called after initialization. It clears all mappings from the reference tables.
 *
 * @param pages a Collection containing WikiPage objects.
 */
private void buildKeyLists(final Collection<Page> pages) {
    m_refersTo.clear();
    m_referredBy.clear();
    if (pages == null) {
        return;
    }
    try {
        for (final Page page : pages) {
            // We add a non-null entry to referredBy to indicate the referred page exists
            m_referredBy.put(page.getName(), new TreeSet<>());
            // Just add a key to refersTo; the keys need to be in sync with referredBy.
            m_refersTo.put(page.getName(), new TreeSet<>());
        }
    } catch (final ClassCastException e) {
        LOG.fatal("Invalid collection entry in ReferenceManager.buildKeyLists().", e);
    }
}
Also used : Page(org.apache.wiki.api.core.Page)

Example 9 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class RecentChangesPlugin method execute.

/**
 * {@inheritDoc}
 */
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
    final int since = TextUtil.parseIntParameter(params.get("since"), DEFAULT_DAYS);
    String spacing = "4";
    boolean showAuthor = true;
    boolean showChangenote = true;
    String tablewidth = "4";
    final Engine engine = context.getEngine();
    // 
    if ("compact".equals(params.get(PARAM_FORMAT))) {
        spacing = "0";
        showAuthor = false;
        showChangenote = false;
        tablewidth = "2";
    }
    final Calendar sincedate = new GregorianCalendar();
    sincedate.add(Calendar.DAY_OF_MONTH, -since);
    log.debug("Calculating recent changes from " + sincedate.getTime());
    // FIXME: Should really have a since date on the getRecentChanges method.
    Collection<Page> changes = engine.getManager(PageManager.class).getRecentChanges();
    super.initialize(context, params);
    changes = filterWikiPageCollection(changes);
    if (changes != null) {
        Date olddate = new Date(0);
        final DateFormat fmt = getDateFormat(context, params);
        final DateFormat tfmt = getTimeFormat(context, params);
        final Element rt = XhtmlUtil.element(XHTML.table);
        rt.setAttribute(XHTML.ATTR_class, "recentchanges");
        rt.setAttribute(XHTML.ATTR_cellpadding, spacing);
        for (final Page pageref : changes) {
            final Date lastmod = pageref.getLastModified();
            if (lastmod.before(sincedate.getTime())) {
                break;
            }
            if (!isSameDay(lastmod, olddate)) {
                final Element row = XhtmlUtil.element(XHTML.tr);
                final Element col = XhtmlUtil.element(XHTML.td);
                col.setAttribute(XHTML.ATTR_colspan, tablewidth);
                col.setAttribute(XHTML.ATTR_class, "date");
                col.addContent(XhtmlUtil.element(XHTML.b, fmt.format(lastmod)));
                rt.addContent(row);
                row.addContent(col);
                olddate = lastmod;
            }
            final String href = context.getURL(pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName());
            Element link = XhtmlUtil.link(href, engine.getManager(RenderingManager.class).beautifyTitle(pageref.getName()));
            final Element row = XhtmlUtil.element(XHTML.tr);
            final Element col = XhtmlUtil.element(XHTML.td);
            col.setAttribute(XHTML.ATTR_width, "30%");
            col.addContent(link);
            // 
            if (pageref instanceof Attachment) {
                link = XhtmlUtil.link(context.getURL(WikiContext.INFO, pageref.getName()), null);
                link.setAttribute(XHTML.ATTR_class, "infolink");
                final Element img = XhtmlUtil.img(context.getURL(WikiContext.NONE, "images/attachment_small.png"), null);
                link.addContent(img);
                col.addContent(link);
            }
            row.addContent(col);
            rt.addContent(row);
            if (pageref instanceof Attachment) {
                final Element td = XhtmlUtil.element(XHTML.td, tfmt.format(lastmod));
                td.setAttribute(XHTML.ATTR_class, "lastchange");
                row.addContent(td);
            } else {
                final Element infocol = XhtmlUtil.element(XHTML.td);
                infocol.setAttribute(XHTML.ATTR_class, "lastchange");
                infocol.addContent(XhtmlUtil.link(context.getURL(WikiContext.DIFF, pageref.getName(), "r1=-1"), tfmt.format(lastmod)));
                row.addContent(infocol);
            }
            // 
            if (showAuthor) {
                final String author = pageref.getAuthor();
                final Element authorinfo = XhtmlUtil.element(XHTML.td);
                authorinfo.setAttribute(XHTML.ATTR_class, "author");
                if (author != null) {
                    if (engine.getManager(PageManager.class).wikiPageExists(author)) {
                        authorinfo.addContent(XhtmlUtil.link(context.getURL(WikiContext.VIEW, author), author));
                    } else {
                        authorinfo.addContent(author);
                    }
                } else {
                    authorinfo.addContent(Preferences.getBundle(context, InternationalizationManager.CORE_BUNDLE).getString("common.unknownauthor"));
                }
                row.addContent(authorinfo);
            }
            // Change note
            if (showChangenote) {
                final String changenote = pageref.getAttribute(Page.CHANGENOTE);
                final Element td_changenote = XhtmlUtil.element(XHTML.td, changenote);
                td_changenote.setAttribute(XHTML.ATTR_class, "changenote");
                row.addContent(td_changenote);
            }
        // Revert note
        /*                
                if( context.hasAdminPermissions() )
                {
                    row.addElement( new td("Revert") );
                }
 */
        }
        return XhtmlUtil.serialize(rt, XhtmlUtil.EXPAND_EMPTY_NODES);
    }
    return "";
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Element(org.jdom2.Element) GregorianCalendar(java.util.GregorianCalendar) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.attachment.Attachment) Date(java.util.Date) PageManager(org.apache.wiki.pages.PageManager) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Engine(org.apache.wiki.api.core.Engine)

Example 10 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class ReferredPagesPlugin method execute.

/**
 *  {@inheritDoc}
 */
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
    m_engine = context.getEngine();
    final Page page = context.getPage();
    if (page == null) {
        return "";
    }
    // parse parameters
    String rootname = params.get(PARAM_ROOT);
    if (rootname == null) {
        rootname = page.getName();
    }
    String format = params.get(PARAM_FORMAT);
    if (format == null) {
        format = "";
    }
    if (format.contains("full")) {
        m_formatCompact = false;
    }
    if (format.contains("sort")) {
        m_formatSort = true;
    }
    m_depth = TextUtil.parseIntParameter(params.get(PARAM_DEPTH), MIN_DEPTH);
    if (m_depth > MAX_DEPTH) {
        m_depth = MAX_DEPTH;
    }
    String includePattern = params.get(PARAM_INCLUDE);
    if (includePattern == null) {
        includePattern = ".*";
    }
    String excludePattern = params.get(PARAM_EXCLUDE);
    if (excludePattern == null) {
        excludePattern = "^$";
    }
    final String columns = params.get(PARAM_COLUMNS);
    if (columns != null) {
        items = TextUtil.parseIntParameter(columns, 0);
    }
    log.debug("Fetching referred pages for " + rootname + " with a depth of " + m_depth + " with include pattern of " + includePattern + " with exclude pattern of " + excludePattern + " with " + columns + " items");
    // 
    // do the actual work
    // 
    final String href = context.getViewURL(rootname);
    final String title = "ReferredPagesPlugin: depth[" + m_depth + "] include[" + includePattern + "] exclude[" + excludePattern + "] format[" + (m_formatCompact ? "compact" : "full") + (m_formatSort ? " sort" : "") + "]";
    if (items > 1) {
        m_result.append("<div class=\"ReferredPagesPlugin\" style=\"").append("columns:").append(columns).append(";").append("moz-columns:").append(columns).append(";").append("webkit-columns:").append(columns).append(";").append("\">\n");
    } else {
        m_result.append("<div class=\"ReferredPagesPlugin\">\n");
    }
    m_result.append("<a class=\"wikipage\" href=\"").append(href).append("\" title=\"").append(TextUtil.replaceEntities(title)).append("\">").append(TextUtil.replaceEntities(rootname)).append("</a>\n");
    m_exists.add(rootname);
    // pre compile all needed patterns
    // glob compiler :  * is 0..n instance of any char  -- more convenient as input
    // perl5 compiler : .* is 0..n instances of any char -- more powerful
    // PatternCompiler g_compiler = new GlobCompiler();
    final PatternCompiler compiler = new Perl5Compiler();
    try {
        m_includePattern = compiler.compile(includePattern);
        m_excludePattern = compiler.compile(excludePattern);
    } catch (final MalformedPatternException e) {
        if (m_includePattern == null) {
            throw new PluginException("Illegal include pattern detected.");
        } else if (m_excludePattern == null) {
            throw new PluginException("Illegal exclude pattern detected.");
        } else {
            throw new PluginException("Illegal internal pattern detected.");
        }
    }
    // go get all referred links
    getReferredPages(context, rootname, 0);
    // close and finish
    m_result.append("</div>\n");
    return m_result.toString();
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) PluginException(org.apache.wiki.api.exceptions.PluginException) Page(org.apache.wiki.api.core.Page) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

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