use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class GenericRSS method createRSS.
public String createRSS() {
try {
Template t = JForumExecutionContext.templateConfig().getTemplate(SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR) + "/rss_template.htm");
StringWriter sw = new StringWriter();
SimpleHash templateContext = JForumExecutionContext.getTemplateContext();
templateContext.put("encoding", SystemGlobals.getValue(ConfigKeys.ENCODING));
templateContext.put("rss", this.rss);
t.process(templateContext, sw);
return sw.toString();
} catch (Exception e) {
throw new ForumException(e);
}
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class BanlistAction method insertSave.
public void insertSave() {
String type = this.request.getParameter("type");
String value = this.request.getParameter("value");
if (!StringUtils.isEmpty(type) && !StringUtils.isEmpty(value)) {
Banlist b = new Banlist();
if ("email".equals(type)) {
b.setEmail(value);
} else if ("user".equals(type)) {
b.setUserId(Integer.parseInt(value));
} else if ("ip".equals(type)) {
b.setIp(value);
} else {
throw new ForumException("Unknown banlist type");
}
BanlistDAO dao = DataAccessDriver.getInstance().newBanlistDAO();
dao.insert(b);
BanlistRepository.add(b);
}
this.list();
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class ViewCommon method contextToLogin.
/**
* Prepares the template context to show the login page, using "returnPath" as return path
* @param returnPath the URI to use as return path
* @return TemplateKeys.USER_LOGIN
*/
public static String contextToLogin(String returnPath) {
JForumExecutionContext.getTemplateContext().put("returnPath", returnPath);
if (ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
String redirect = SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT);
if (!StringUtils.isEmpty(redirect)) {
URI redirectUri = URI.create(redirect);
if (!redirectUri.isAbsolute()) {
throw new ForumException("SSO redirect URL should start with a scheme");
}
try {
returnPath = URLEncoder.encode(ViewCommon.getForumLink() + returnPath, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
if (redirect.indexOf('?') == -1) {
redirect += "?";
} else {
redirect += "&";
}
redirect += "returnUrl=" + returnPath;
JForumExecutionContext.setRedirect(redirect);
}
}
return TemplateKeys.USER_LOGIN;
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class LuceneStatsAction method list.
/**
* @see net.jforum.Command#list()
*/
public void list() {
IndexReader reader = null;
try {
File indexDir = new File(SystemGlobals.getValue(ConfigKeys.LUCENE_INDEX_WRITE_PATH));
this.setTemplateName(TemplateKeys.SEARCH_STATS_LIST);
boolean isInformationAvailable = true;
try {
reader = IndexReader.open(indexDir);
} catch (IOException e) {
isInformationAvailable = false;
}
this.context.put("isInformationAvailable", isInformationAvailable);
this.context.put("indexExists", IndexReader.indexExists(indexDir));
this.context.put("currentlyIndexing", "1".equals(SystemGlobals.getValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING)));
if (isInformationAvailable) {
this.context.put("isLocked", IndexReader.isLocked(indexDir.getAbsolutePath()));
this.context.put("lastModified", new Date(IndexReader.lastModified(indexDir)));
this.context.put("indexLocation", indexDir.getAbsolutePath());
this.context.put("totalMessages", new Integer(ForumRepository.getTotalMessages()));
this.context.put("indexVersion", new Long(reader.getVersion()));
this.context.put("numberOfDocs", new Integer(reader.numDocs()));
}
} catch (IOException e) {
throw new ForumException(e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class Command method process.
/**
* Process and manipulate a requisition.
* @return <code>Template</code> reference
* @param request WebContextRequest
* @param response WebContextResponse
*/
public Template process(RequestContext request, ResponseContext response, SimpleHash context) {
this.request = request;
this.response = response;
this.context = context;
String action = this.request.getAction();
if (!this.ignoreAction) {
try {
this.getClass().getMethod(action, NO_ARGS_CLASS).invoke(this, NO_ARGS_OBJECT);
} catch (NoSuchMethodException e) {
this.list();
} catch (Exception e) {
throw new ForumException(e);
}
}
if (JForumExecutionContext.getRedirectTo() != null) {
this.setTemplateName(TemplateKeys.EMPTY);
} else if (request.getAttribute("template") != null) {
this.setTemplateName((String) request.getAttribute("template"));
}
if (JForumExecutionContext.isCustomContent()) {
return null;
}
if (this.templateName == null) {
throw new TemplateNotFoundException("Template for action " + action + " is not defined");
}
try {
return JForumExecutionContext.templateConfig().getTemplate(new StringBuffer(SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR)).append('/').append(this.templateName).toString());
} catch (IOException e) {
throw new ForumException(e);
}
}
Aggregations