Search in sources :

Example 16 with ForumException

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

the class SystemGlobals method loadQueries.

/**
 * Load the SQL queries
 *
 * @param queryFile Complete path to the SQL queries file.
 */
public static void loadQueries(String queryFile) {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(queryFile);
        queries.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) InvalidParameterException(java.security.InvalidParameterException) ForumException(net.jforum.exceptions.ForumException)

Example 17 with ForumException

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

the class SystemGlobals method loadDefaults.

/**
 * Load system defaults
 */
public static void loadDefaults() {
    try {
        FileInputStream input = new FileInputStream(globals.defaultConfig);
        globals.defaults.load(input);
        input.close();
        globals.expander.clearCache();
    } catch (IOException e) {
        throw new ForumException(e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 18 with ForumException

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

the class SystemGlobals method saveInstallation.

/**
 * Save installation defaults
 */
public static void saveInstallation() {
    // our new keys.
    class SortedProperties extends Properties {

        public synchronized Enumeration keys() {
            Enumeration keysEnum = super.keys();
            Vector keyList = new Vector();
            while (keysEnum.hasMoreElements()) {
                keyList.add(keysEnum.nextElement());
            }
            Collections.sort(keyList);
            return keyList.elements();
        }
    }
    Properties p = new SortedProperties();
    p.putAll(globals.installation);
    try {
        FileOutputStream out = new FileOutputStream(globals.installationConfig);
        p.store(out, "Installation specific configuration options");
        out.close();
    } catch (IOException e) {
        throw new ForumException(e);
    }
    ConfigLoader.listenInstallationConfig();
}
Also used : Enumeration(java.util.Enumeration) ForumException(net.jforum.exceptions.ForumException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) Vector(java.util.Vector)

Example 19 with ForumException

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

the class DefaultLoginAuthenticator method validateLogin.

/**
 * @see net.jforum.sso.LoginAuthenticator#validateLogin(String, String, java.util.Map)
 */
public User validateLogin(String username, String password, Map extraParams) {
    User user = null;
    ResultSet rs = null;
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.login"));
        p.setString(1, username);
        p.setString(2, MD5.crypt(password));
        rs = p.executeQuery();
        if (rs.next() && rs.getInt("user_id") > 0) {
            user = this.userModel.selectById(rs.getInt("user_id"));
        }
    } catch (SQLException e) {
        throw new ForumException(e);
    } finally {
        DbUtils.close(rs, p);
    }
    if (user != null && !user.isDeleted() && (user.getActivationKey() == null || user.isActive())) {
        return user;
    }
    return null;
}
Also used : User(net.jforum.entities.User) ForumException(net.jforum.exceptions.ForumException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 20 with ForumException

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

the class UploadUtils method saveUploadedFile.

public void saveUploadedFile(String filename) {
    BufferedInputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = new BufferedInputStream(this.item.getInputStream());
        outputStream = new FileOutputStream(filename);
        int c;
        byte[] b = new byte[4096];
        while ((c = inputStream.read(b)) != -1) {
            outputStream.write(b, 0, c);
        }
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
            }
        }
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

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