use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class ParentPageNameTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null) {
if (page instanceof Attachment) {
pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(((Attachment) page).getParentName()));
} else {
String name = page.getName();
final int entrystart = name.indexOf("_blogentry_");
if (entrystart != -1) {
name = name.substring(0, entrystart);
}
final int commentstart = name.indexOf("_comments_");
if (commentstart != -1) {
name = name.substring(0, commentstart);
}
pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(name));
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class UserNameTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Session wikiSession = Wiki.session().find(engine, (HttpServletRequest) pageContext.getRequest());
final Principal user = wikiSession.getUserPrincipal();
if (user != null) {
if (VALID_USER_NAME_PATTERN.matcher(user.getName()).matches()) {
pageContext.getOut().print(TextUtil.replaceEntities(user.getName()));
} else {
pageContext.getOut().print(Preferences.getBundle(m_wikiContext, InternationalizationManager.CORE_BUNDLE).getString("security.user.fullname.invalid"));
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class VariableTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws JspException, IOException {
final Engine engine = m_wikiContext.getEngine();
final JspWriter out = pageContext.getOut();
String msg = null;
String value = null;
try {
value = engine.getManager(VariableManager.class).getValue(m_wikiContext, getVar());
} catch (final NoSuchVariableException e) {
msg = "No such variable: " + e.getMessage();
} catch (final IllegalArgumentException e) {
msg = "Incorrect variable name: " + e.getMessage();
}
if (value == null) {
value = m_default;
}
if (value == null) {
value = msg;
}
out.write(TextUtil.replaceEntities(value));
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class CookieAuthenticationLoginModule method login.
/**
* {@inheritDoc}
*
* @see javax.security.auth.spi.LoginModule#login()
*/
@Override
public boolean login() throws LoginException {
// Otherwise, let's go and look for the cookie!
final HttpRequestCallback hcb = new HttpRequestCallback();
final WikiEngineCallback wcb = new WikiEngineCallback();
final Callback[] callbacks = new Callback[] { hcb, wcb };
try {
m_handler.handle(callbacks);
final HttpServletRequest request = hcb.getRequest();
final String uid = getLoginCookie(request);
if (uid != null) {
final Engine engine = wcb.getEngine();
final File cookieFile = getCookieFile(engine, uid);
if (cookieFile != null && cookieFile.exists() && cookieFile.canRead()) {
try (final Reader in = new BufferedReader(new InputStreamReader(Files.newInputStream(cookieFile.toPath()), StandardCharsets.UTF_8))) {
final String username = FileUtil.readContents(in);
log.debug("Logged in cookie authenticated name={}", username);
// If login succeeds, commit these principals/roles
m_principals.add(new WikiPrincipal(username, WikiPrincipal.LOGIN_NAME));
// Tag the file so that we know that it has been accessed recently.
return cookieFile.setLastModified(System.currentTimeMillis());
} catch (final IOException e) {
return false;
}
}
}
} catch (final IOException e) {
final String message = "IO exception; disallowing login.";
log.error(message, e);
throw new LoginException(message);
} catch (final UnsupportedCallbackException e) {
final String message = "Unable to handle callback; disallowing login.";
log.error(message, e);
throw new LoginException(message);
}
return false;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class MetaWeblogHandler method editPost.
/**
* Allows the user to edit a post. It does not allow general editability of wiki pages, because of the limitations of the metaWeblog API.
*/
boolean editPost(final String postid, final String username, final String password, final Hashtable<String, Object> content, final boolean publish) throws XmlRpcException {
final Engine engine = m_context.getEngine();
log.info("metaWeblog.editPost(" + postid + ") called");
// FIXME: Is postid correct? Should we determine it from the page name?
final Page page = engine.getManager(PageManager.class).getPage(postid);
checkPermissions(page, username, password, "edit");
try {
final Page entryPage = page.clone();
entryPage.setAuthor(username);
final Context context = Wiki.context().create(engine, entryPage);
final StringBuilder text = new StringBuilder();
text.append("!").append(content.get("title"));
text.append("\n\n");
text.append(content.get("description"));
log.debug("Updating entry: " + text);
engine.getManager(PageManager.class).saveText(context, text.toString());
} catch (final Exception e) {
log.error("Failed to create weblog entry", e);
throw new XmlRpcException(0, "Failed to update weblog entry: " + e.getMessage());
}
return true;
}
Aggregations