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