Search in sources :

Example 1 with Smilie

use of net.jforum.entities.Smilie in project jforum2 by rafaelsteil.

the class GenericSmilieDAO method selectById.

/**
	 * @see net.jforum.dao.SmilieDAO#selectById(int)
	 */
public Smilie selectById(int id) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("SmiliesModel.selectById"));
        p.setInt(1, id);
        Smilie s = new Smilie();
        rs = p.executeQuery();
        if (rs.next()) {
            s = this.getSmilie(rs);
        }
        return s;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Smilie(net.jforum.entities.Smilie) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with Smilie

use of net.jforum.entities.Smilie in project jforum2 by rafaelsteil.

the class PostCommon method processSmilies.

/**
	 * Replace the smlies code by the respective URL.
	 * @param text The text to process
	 * @return the parsed text. Note that the StringBuffer you pass as parameter
	 * will already have the right contents, as the replaces are done on the instance
	 */
public static String processSmilies(StringBuffer text) {
    List smilies = SmiliesRepository.getSmilies();
    for (Iterator iter = smilies.iterator(); iter.hasNext(); ) {
        Smilie s = (Smilie) iter.next();
        int pos = text.indexOf(s.getCode());
        // The counter is used as prevention, in case
        // the while loop turns into an always true 
        // expression, for any reason
        int counter = 0;
        while (pos > -1 && counter++ < 300) {
            text.replace(pos, pos + s.getCode().length(), s.getUrl());
            pos = text.indexOf(s.getCode());
        }
    }
    return text.toString();
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Smilie(net.jforum.entities.Smilie)

Example 3 with Smilie

use of net.jforum.entities.Smilie in project jforum2 by rafaelsteil.

the class SmiliesAction method editSave.

public void editSave() {
    Smilie s = DataAccessDriver.getInstance().newSmilieDAO().selectById(this.request.getIntParameter("id"));
    s.setCode(this.request.getParameter("code"));
    if (this.request.getObjectParameter("smilie_img") != null) {
        String imgName = this.processUpload();
        s.setUrl(SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_PATTERN).replaceAll("#IMAGE#", imgName));
        s.setDiskName(imgName);
    }
    DataAccessDriver.getInstance().newSmilieDAO().update(s);
    SmiliesRepository.loadSmilies();
    this.list();
}
Also used : Smilie(net.jforum.entities.Smilie)

Example 4 with Smilie

use of net.jforum.entities.Smilie in project jforum2 by rafaelsteil.

the class SmiliesAction method delete.

public void delete() {
    String[] ids = this.request.getParameterValues("id");
    if (ids != null) {
        SmilieDAO dao = DataAccessDriver.getInstance().newSmilieDAO();
        for (int i = 0; i < ids.length; i++) {
            int id = Integer.parseInt(ids[i]);
            Smilie s = dao.selectById(id);
            dao.delete(id);
            File smilieFile = new File(s.getDiskName());
            File fileToDelete = new File(SystemGlobals.getApplicationPath() + "/" + SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_DIR) + "/" + smilieFile.getName());
            if (fileToDelete.exists()) {
                fileToDelete.delete();
            }
        }
    }
    SmiliesRepository.loadSmilies();
    this.list();
}
Also used : SmilieDAO(net.jforum.dao.SmilieDAO) Smilie(net.jforum.entities.Smilie) File(java.io.File)

Example 5 with Smilie

use of net.jforum.entities.Smilie in project jforum2 by rafaelsteil.

the class SmiliesAction method insertSave.

public void insertSave() {
    Smilie s = new Smilie();
    s.setCode(this.request.getParameter("code"));
    String imgName = this.processUpload();
    s.setUrl(SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_PATTERN).replaceAll("#IMAGE#", imgName));
    s.setDiskName(imgName);
    DataAccessDriver.getInstance().newSmilieDAO().addNew(s);
    SmiliesRepository.loadSmilies();
    this.list();
}
Also used : Smilie(net.jforum.entities.Smilie)

Aggregations

Smilie (net.jforum.entities.Smilie)7 Iterator (java.util.Iterator)2 List (java.util.List)2 File (java.io.File)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 SmilieDAO (net.jforum.dao.SmilieDAO)1 DatabaseException (net.jforum.exceptions.DatabaseException)1