Search in sources :

Example 1 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class ConfigLoader method loadDaoImplementation.

public static void loadDaoImplementation() {
    // Start the dao.driver implementation
    String driver = SystemGlobals.getValue(ConfigKeys.DAO_DRIVER);
    logger.info("Loading JDBC driver " + driver);
    try {
        Class c = Class.forName(driver);
        DataAccessDriver d = (DataAccessDriver) c.newInstance();
        DataAccessDriver.init(d);
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) DataAccessDriver(net.jforum.dao.DataAccessDriver) IOException(java.io.IOException) CacheEngineStartupException(net.jforum.exceptions.CacheEngineStartupException) SchedulerException(org.quartz.SchedulerException) ForumException(net.jforum.exceptions.ForumException)

Example 2 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class ConfigLoader method createLoginAuthenticator.

public static void createLoginAuthenticator() {
    String className = SystemGlobals.getValue(ConfigKeys.LOGIN_AUTHENTICATOR);
    try {
        LoginAuthenticator loginAuthenticator = (LoginAuthenticator) Class.forName(className).newInstance();
        SystemGlobals.setObjectValue(ConfigKeys.LOGIN_AUTHENTICATOR_INSTANCE, loginAuthenticator);
    } catch (Exception e) {
        throw new ForumException("Error while trying to create a login.authenticator instance (" + className + "): " + e, e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) LoginAuthenticator(net.jforum.sso.LoginAuthenticator) IOException(java.io.IOException) CacheEngineStartupException(net.jforum.exceptions.CacheEngineStartupException) SchedulerException(org.quartz.SchedulerException) ForumException(net.jforum.exceptions.ForumException)

Example 3 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class I18n method loadLocales.

private static void loadLocales() {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(baseDir + SystemGlobals.getValue(ConfigKeys.LOCALES_NAMES));
        localeNames.load(fis);
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Example 4 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class BBCodeHandler method parse.

public BBCodeHandler parse() {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        BBCodeHandler bbParser = new BBCodeHandler();
        String path = SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/bb_config.xml";
        File fileInput = new File(path);
        if (fileInput.exists()) {
            parser.parse(fileInput, bbParser);
        } else {
            InputSource input = new InputSource(path);
            parser.parse(input, bbParser);
        }
        return bbParser;
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ForumException(net.jforum.exceptions.ForumException) SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) ForumException(net.jforum.exceptions.ForumException)

Example 5 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class PostAction method downloadAttach.

public void downloadAttach() {
    int id = this.request.getIntParameter("attach_id");
    if (!SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
        String referer = this.request.getHeader("Referer");
        if (referer != null) {
            this.setTemplateName(ViewCommon.contextToLogin(referer));
        } else {
            this.setTemplateName(ViewCommon.contextToLogin());
        }
        return;
    }
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    Attachment a = am.selectAttachmentById(id);
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(a.getPostId());
    String forumId = Integer.toString(post.getForumId());
    boolean attachmentsEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, forumId);
    boolean attachmentsDownload = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD, forumId);
    if (!attachmentsEnabled && !attachmentsDownload) {
        this.setTemplateName(TemplateKeys.POSTS_CANNOT_DOWNLOAD);
        this.context.put("message", I18n.getMessage("Attachments.featureDisabled"));
        return;
    }
    String filename = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/" + a.getInfo().getPhysicalFilename();
    if (!new File(filename).exists()) {
        this.setTemplateName(TemplateKeys.POSTS_ATTACH_NOTFOUND);
        this.context.put("message", I18n.getMessage("Attachments.notFound"));
        return;
    }
    FileInputStream fis = null;
    OutputStream os = null;
    try {
        a.getInfo().setDownloadCount(a.getInfo().getDownloadCount() + 1);
        am.updateAttachment(a);
        fis = new FileInputStream(filename);
        os = response.getOutputStream();
        if (am.isPhysicalDownloadMode(a.getInfo().getExtension().getExtensionGroupId())) {
            this.response.setContentType("application/octet-stream");
        } else {
            this.response.setContentType(a.getInfo().getMimetype());
        }
        if (this.request.getHeader("User-Agent").indexOf("Firefox") != -1) {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(a.getInfo().getRealFilename().getBytes(SystemGlobals.getValue(ConfigKeys.ENCODING)), SystemGlobals.getValue(ConfigKeys.DEFAULT_CONTAINER_ENCODING)) + "\";");
        } else {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + ViewCommon.toUtf8String(a.getInfo().getRealFilename()) + "\";");
        }
        this.response.setContentLength((int) a.getInfo().getFilesize());
        int c;
        byte[] b = new byte[4096];
        while ((c = fis.read(b)) != -1) {
            os.write(b, 0, c);
        }
        JForumExecutionContext.enableCustomContent(true);
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Exception e) {
            }
        }
    }
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) Post(net.jforum.entities.Post) OutputStream(java.io.OutputStream) Attachment(net.jforum.entities.Attachment) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AttachmentException(net.jforum.exceptions.AttachmentException) ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException) PostDAO(net.jforum.dao.PostDAO) File(java.io.File)

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