use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class MetaWeblogHandler method getPost.
/**
* Gets the text of any page. The title of the page is parsed
* (if any is provided).
*/
Hashtable<String, Object> getPost(final String postid, final String username, final String password) throws XmlRpcException {
final String wikiname = "FIXME";
final Page page = m_context.getEngine().getManager(PageManager.class).getPage(wikiname);
checkPermissions(page, username, password, "view");
return makeEntry(page);
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class MetaWeblogHandler method getRecentPosts.
/**
* Returns a list of the recent posts to this weblog.
*
* @param blogid The id of the blog.
* @param username The username to use
* @param password The password
* @param numberOfPosts How many posts to find
* @throws XmlRpcException If something goes wrong
* @return As per MetaweblogAPI specification
*/
// FIXME: The implementation is suboptimal, as it goes through all of the blog entries.
public Hashtable getRecentPosts(final String blogid, final String username, final String password, final int numberOfPosts) throws XmlRpcException {
final Hashtable<String, Hashtable<String, Object>> result = new Hashtable<>();
log.info("metaWeblog.getRecentPosts() called");
final Page page = m_context.getEngine().getManager(PageManager.class).getPage(blogid);
checkPermissions(page, username, password, "view");
final WeblogPlugin plugin = new WeblogPlugin();
final List<Page> changed = plugin.findBlogEntries(m_context.getEngine(), blogid, new Date(0L), new Date());
changed.sort(new PageTimeComparator());
int items = 0;
for (final Iterator<Page> i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++) {
final Page p = i.next();
result.put("entry", makeEntry(p));
}
return result;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class RPCHandlerUTF8 method getRecentChanges.
@Override
public Vector<Hashtable<String, Object>> getRecentChanges(Date since) {
checkPermission(PagePermission.VIEW);
final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
final Vector<Hashtable<String, Object>> result = new Vector<>();
final Calendar cal = Calendar.getInstance();
cal.setTime(since);
//
// Convert UTC to our time.
//
cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0)));
since = cal.getTime();
for (final Page page : pages) {
if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
result.add(encodeWikiPage(page));
}
}
return result;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class DefaultVariableManager method getValue.
/**
* {@inheritDoc}
*/
@Override
public String getValue(final Context context, final String varName) throws IllegalArgumentException, NoSuchVariableException {
if (varName == null) {
throw new IllegalArgumentException("Null variable name.");
}
if (varName.isEmpty()) {
throw new IllegalArgumentException("Zero length variable name.");
}
// Faster than doing equalsIgnoreCase()
final String name = varName.toLowerCase();
for (final String value : THE_BIG_NO_NO_LIST) {
if (name.equals(value)) {
// FIXME: Should this be something different?
return "";
}
}
try {
//
// Using reflection to get system variables adding a new system variable
// now only involves creating a new method in the SystemVariables class
// with a name starting with get and the first character of the name of
// the variable capitalized. Example:
// public String getMysysvar(){
// return "Hello World";
// }
//
final SystemVariables sysvars = new SystemVariables(context);
final String methodName = "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
final Method method = sysvars.getClass().getMethod(methodName);
return (String) method.invoke(sysvars);
} catch (final NoSuchMethodException e1) {
//
if ((context.getVariable(varName)) != null) {
return context.getVariable(varName).toString();
}
//
// Well, I guess it wasn't a final straw. We also allow variables from the session and the request (in this order).
//
final HttpServletRequest req = context.getHttpRequest();
if (req != null && req.getSession() != null) {
final HttpSession session = req.getSession();
try {
String s = (String) session.getAttribute(varName);
if (s != null) {
return s;
}
s = context.getHttpParameter(varName);
if (s != null) {
return s;
}
} catch (final ClassCastException e) {
log.debug("Not a String: " + varName);
}
}
//
// And the final straw: see if the current page has named metadata.
//
final Page pg = context.getPage();
if (pg != null) {
final Object metadata = pg.getAttribute(varName);
if (metadata != null) {
return metadata.toString();
}
}
//
// And the final straw part 2: see if the "real" current page has named metadata. This allows
// a parent page to control a inserted page through defining variables
//
final Page rpg = context.getRealPage();
if (rpg != null) {
final Object metadata = rpg.getAttribute(varName);
if (metadata != null) {
return metadata.toString();
}
}
//
if (varName.startsWith("jspwiki.")) {
final Properties props = context.getEngine().getWikiProperties();
final String s = props.getProperty(varName);
if (s != null) {
return s;
}
}
//
if (varName.equals(VAR_ERROR) || varName.equals(VAR_MSG)) {
return "";
}
throw new NoSuchVariableException("No variable " + varName + " defined.");
} catch (final Exception e) {
log.info("Interesting exception: cannot fetch variable value", e);
}
return "";
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class DefaultPageRenamer method updateReferrers.
/**
* This method finds all the pages which have anything to do with the fromPage and
* change any referrers it can figure out in that page.
*
* @param context WikiContext in which we operate
* @param fromPage The old page
* @param toPage The new page
*/
private void updateReferrers(final Context context, final Page fromPage, final Page toPage, final Set<String> referrers) {
if (referrers.isEmpty()) {
// No referrers
return;
}
final Engine engine = context.getEngine();
for (String pageName : referrers) {
// In case the page was just changed from under us, let's do this small kludge.
if (pageName.equals(fromPage.getName())) {
pageName = toPage.getName();
}
final Page p = engine.getManager(PageManager.class).getPage(pageName);
final String sourceText = engine.getManager(PageManager.class).getPureText(p);
String newText = replaceReferrerString(context, sourceText, fromPage.getName(), toPage.getName());
m_camelCase = TextUtil.getBooleanProperty(engine.getWikiProperties(), MarkupParser.PROP_CAMELCASELINKS, m_camelCase);
if (m_camelCase) {
newText = replaceCCReferrerString(context, newText, fromPage.getName(), toPage.getName());
}
if (!sourceText.equals(newText)) {
p.setAttribute(Page.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName());
p.setAuthor(context.getCurrentUser().getName());
try {
engine.getManager(PageManager.class).putPageText(p, newText);
engine.getManager(ReferenceManager.class).updateReferences(p);
} catch (final ProviderException e) {
// We fail with an error, but we will try to continue to rename other referrers as well.
log.error("Unable to perform rename.", e);
}
}
}
}
Aggregations