Search in sources :

Example 26 with ForumException

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);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) StringWriter(java.io.StringWriter) SimpleHash(freemarker.template.SimpleHash) ForumException(net.jforum.exceptions.ForumException) Template(freemarker.template.Template)

Example 27 with ForumException

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();
}
Also used : ForumException(net.jforum.exceptions.ForumException) BanlistDAO(net.jforum.dao.BanlistDAO) Banlist(net.jforum.entities.Banlist)

Example 28 with ForumException

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;
}
Also used : ForumException(net.jforum.exceptions.ForumException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URI(java.net.URI)

Example 29 with ForumException

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) {
            }
        }
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) IndexReader(org.apache.lucene.index.IndexReader) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Example 30 with ForumException

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);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) TemplateNotFoundException(net.jforum.exceptions.TemplateNotFoundException) IOException(java.io.IOException) TemplateNotFoundException(net.jforum.exceptions.TemplateNotFoundException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Aggregations

ForumException (net.jforum.exceptions.ForumException)37 IOException (java.io.IOException)24 FileInputStream (java.io.FileInputStream)10 File (java.io.File)7 Iterator (java.util.Iterator)6 Properties (java.util.Properties)6 DatabaseException (net.jforum.exceptions.DatabaseException)6 List (java.util.List)5 SQLException (java.sql.SQLException)4 CacheEngineStartupException (net.jforum.exceptions.CacheEngineStartupException)4 SchedulerException (org.quartz.SchedulerException)4 FileOutputStream (java.io.FileOutputStream)3 PreparedStatement (java.sql.PreparedStatement)3 Enumeration (java.util.Enumeration)3 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 SAXParser (javax.xml.parsers.SAXParser)2 Post (net.jforum.entities.Post)2 User (net.jforum.entities.User)2 SSO (net.jforum.sso.SSO)2