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);
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations