Search in sources :

Example 31 with ForumException

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) {
            }
        }
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) CacheEngineStartupException(net.jforum.exceptions.CacheEngineStartupException) SchedulerException(org.quartz.SchedulerException) ForumException(net.jforum.exceptions.ForumException)

Example 32 with ForumException

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) {
            }
        }
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) Iterator(java.util.Iterator) IOException(java.io.IOException) Properties(java.util.Properties) Map(java.util.Map) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) CacheEngineStartupException(net.jforum.exceptions.CacheEngineStartupException) SchedulerException(org.quartz.SchedulerException) ForumException(net.jforum.exceptions.ForumException)

Example 33 with ForumException

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);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ForumException(net.jforum.exceptions.ForumException) SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) DatabaseException(net.jforum.exceptions.DatabaseException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) ForumException(net.jforum.exceptions.ForumException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 34 with ForumException

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();
}
Also used : ForumException(net.jforum.exceptions.ForumException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 35 with ForumException

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();
}
Also used : Lexer(org.htmlparser.lexer.Lexer) ForumException(net.jforum.exceptions.ForumException) Node(org.htmlparser.Node) TextNode(org.htmlparser.nodes.TextNode) Tag(org.htmlparser.Tag) ForumException(net.jforum.exceptions.ForumException)

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