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;
}
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());
}
}
}
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;
}
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;
}
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;
}
Aggregations