use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class ConfigLoader method loadModulesMapping.
/**
* Loads module mappings for the system.
*
* @param baseConfigDir The directory where the file <i>modulesMapping.properties</i> is.
* @return The <code>java.util.Properties</code> instance, with the loaded modules
*/
public static Properties loadModulesMapping(String baseConfigDir) {
FileInputStream fis = null;
try {
Properties modulesMapping = new Properties();
fis = new FileInputStream(baseConfigDir + "/modulesMapping.properties");
modulesMapping.load(fis);
return modulesMapping;
} 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 ConfigLoader method loadUrlPatterns.
/**
* Load url patterns.
* The method tries to load url patterns from <i>WEB-INF/config/urlPattern.properties</i>
*/
public static void loadUrlPatterns() {
FileInputStream fis = null;
try {
Properties p = new Properties();
fis = new FileInputStream(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/urlPattern.properties");
p.load(fis);
for (Iterator iter = p.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
UrlPatternCollection.addPattern((String) entry.getKey(), (String) entry.getValue());
}
} 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 XMLPermissionControl method loadConfigurations.
/**
* @return <code>List</code> object containing <code>Section</code> objects. Each
* <code>Section</code> contains many <code>PermissionItem</code> objects,
* which represent the permission elements of some section. For its turn, the
* <code>PermissionItem</code> objects have many <code>FormSelectedData</code>
* objects, which are the ones responsible to store field values, and which values
* are checked and which not.
* @param xmlFile String
*/
public List loadConfigurations(String xmlFile) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
File fileInput = new File(xmlFile);
if (fileInput.exists()) {
parser.parse(fileInput, this);
} else {
InputSource inputSource = new InputSource(xmlFile);
parser.parse(inputSource, this);
}
return this.listSections;
} catch (Exception e) {
throw new ForumException(e);
}
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class MD5 method crypt.
/**
* Encodes a string
*
* @param str String to encode
* @return Encoded String
* @throws NoSuchAlgorithmException
*/
public static String crypt(String str) {
if (str == null || str.length() == 0) {
throw new IllegalArgumentException("String to encript cannot be null or zero length");
}
StringBuffer hexString = new StringBuffer();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] hash = md.digest();
for (int i = 0; i < hash.length; i++) {
if ((0xff & hash[i]) < 0x10) {
hexString.append("0" + Integer.toHexString((0xFF & hash[i])));
} else {
hexString.append(Integer.toHexString(0xFF & hash[i]));
}
}
} catch (NoSuchAlgorithmException e) {
throw new ForumException("" + e);
}
return hexString.toString();
}
use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.
the class SafeHtml method ensureAllAttributesAreSafe.
/**
* Given an input, analyze each HTML tag and remove unsecure attributes from them.
* @param contents The content to verify
* @return the content, secure.
*/
public String ensureAllAttributesAreSafe(String contents) {
StringBuffer sb = new StringBuffer(contents.length());
try {
Lexer lexer = new Lexer(contents);
Node node;
while ((node = lexer.nextNode()) != null) {
if (node instanceof Tag) {
Tag tag = (Tag) node;
this.checkAndValidateAttributes(tag, false);
sb.append(tag.toHtml());
} else {
sb.append(node.toHtml());
}
}
} catch (Exception e) {
throw new ForumException("Problems while parsing HTML: " + e, e);
}
return sb.toString();
}
Aggregations