//# 0 errors, 139 messages
//#
package net.sourceforge.pebble.dao.file;
    //#filerefererfilterdao.java:1:1: class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO

import net.sourceforge.pebble.dao.PersistenceException;
import net.sourceforge.pebble.dao.RefererFilterDAO;
import net.sourceforge.pebble.domain.Blog;
import net.sourceforge.pebble.domain.RefererFilter;
import net.sourceforge.pebble.domain.RefererFilterManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * A mock implementation of the CategoryDAO interface that does nothing. This
 * is used when performing unit tests.
 *
 * @author    Simon Brown
 */
public class FileRefererFilterDAO implements RefererFilterDAO {
    //#filerefererfilterdao.java:22: method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.net.sourceforge.pebble.dao.file.FileRefererFilterDAO()
    //#filerefererfilterdao.java:22: end of method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.net.sourceforge.pebble.dao.file.FileRefererFilterDAO()

  /** the name of the file containing the filter */
  private static final String FILTERS_FILE = "refererFilters.txt";

  /** the log used by this class */
  private static Log log = LogFactory.getLog(RefererFilterManager.class);
    //#filerefererfilterdao.java:28: method: net.sourceforge.pebble.dao.file.FileRefererFilterDAO.net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init
    //#filerefererfilterdao.java:28: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO
    //#    method: net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO]
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.addRefererFilter(Lnet/sourceforge/pebble/domain/RefererFilter;Lnet/sourceforge/pebble/domain/Blog;)V
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.deleteRefererFilter(Lnet/sourceforge/pebble/domain/RefererFilter;Lnet/sourceforge/pebble/domain/Blog;)V
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.getRefererFilters(Lnet/sourceforge/pebble/domain/Blog;)Ljava/util/Collection;
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.store(Ljava/util/Collection;Lnet/sourceforge/pebble/domain/Blog;)V
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): log
    //#output(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): net/sourceforge/pebble/dao/RefererFilterDAO.__Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO]
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): net/sourceforge/pebble/dao/RefererFilterDAO.__Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.addRefererFilter(Lnet/sourceforge/pebble/domain/RefererFilter;Lnet/sourceforge/pebble/domain/Blog;)V == &addRefererFilter
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.deleteRefererFilter(Lnet/sourceforge/pebble/domain/RefererFilter;Lnet/sourceforge/pebble/domain/Blog;)V == &deleteRefererFilter
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.getRefererFilters(Lnet/sourceforge/pebble/domain/Blog;)Ljava/util/Collection; == &getRefererFilters
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): __Dispatch_Table.store(Ljava/util/Collection;Lnet/sourceforge/pebble/domain/Blog;)V == &store
    //#post(net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init): init'ed(log)
    //#filerefererfilterdao.java:28: end of method: net.sourceforge.pebble.dao.file.FileRefererFilterDAO.net.sourceforge.pebble.dao.file.FileRefererFilterDAO__static_init

  /**
   * Loads the referer filters.
   *
   * @param rootBlog    the owning Blog instance
   * @return  a Collection of RefererFilter instances
   * @throws  PersistenceException    if filters cannot be loaded
   */
  public Collection getRefererFilters(Blog rootBlog) throws PersistenceException {
    ArrayList filters = new ArrayList();
    //#filerefererfilterdao.java:38: method: Collection net.sourceforge.pebble.dao.file.FileRefererFilterDAO.getRefererFilters(Blog)
    //#input(Collection getRefererFilters(Blog)): log
    //#input(Collection getRefererFilters(Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[net/sourceforge/pebble/domain/RefererFilter]
    //#input(Collection getRefererFilters(Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[others]
    //#input(Collection getRefererFilters(Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.setExpression(Ljava/lang/String;)V
    //#input(Collection getRefererFilters(Blog)): rootBlog
    //#output(Collection getRefererFilters(Blog)): new ArrayList(getRefererFilters#1) num objects
    //#output(Collection getRefererFilters(Blog)): return_value
    //#new obj(Collection getRefererFilters(Blog)): new ArrayList(getRefererFilters#1)
    //#pre[2] (Collection getRefererFilters(Blog)): rootBlog != null
    //#pre[1] (Collection getRefererFilters(Blog)): (soft) log != null
    //#post(Collection getRefererFilters(Blog)): return_value == &new ArrayList(getRefererFilters#1)
    //#post(Collection getRefererFilters(Blog)): new ArrayList(getRefererFilters#1) num objects == 1
    //#unanalyzed(Collection getRefererFilters(Blog)): Effects-of-calling:java.util.regex.Pattern:compile
    //#test_vector(Collection getRefererFilters(Blog)): java.io.File:exists(...)@43: {1}, {0}
    String root = rootBlog.getRoot();
    //#filerefererfilterdao.java:39: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getRoot()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO
    //#    method: Collection getRefererFilters(Blog)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getRoot()
    try {

      File filtersFile = new File(root, FILTERS_FILE);
      if (!filtersFile.exists()) {
        return filters;
      }

      BufferedReader reader = new BufferedReader(new FileReader(filtersFile));
      String expression = reader.readLine();
      while (expression != null) {
        filters.add(new RefererFilter(expression));
        expression = reader.readLine();
      }

      reader.close();
    } catch (IOException ioe) {
      log.error("A " + FILTERS_FILE + " file at " + root + " cannot be loaded", ioe);
    //#filerefererfilterdao.java:56: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO
    //#    method: Collection getRefererFilters(Blog)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
    }

    return filters;
    //#filerefererfilterdao.java:59: end of method: Collection net.sourceforge.pebble.dao.file.FileRefererFilterDAO.getRefererFilters(Blog)
  }

  /**
   * Adds the specified referer filter.
   *
   * @param filter    the RefererFilter instance to be added
   * @param rootBlog    the owning Blog instance
   * @throws PersistenceException   if something goes wrong storing the filters
   */
  public void addRefererFilter(RefererFilter filter, Blog rootBlog) throws PersistenceException {
    Collection filters = getRefererFilters(rootBlog);
    //#filerefererfilterdao.java:70: method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.addRefererFilter(RefererFilter, Blog)
    //#input(void addRefererFilter(RefererFilter, Blog)): __Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO]
    //#input(void addRefererFilter(RefererFilter, Blog)): __Descendant_Table[others]
    //#input(void addRefererFilter(RefererFilter, Blog)): __Dispatch_Table.getRefererFilters(Lnet/sourceforge/pebble/domain/Blog;)Ljava/util/Collection;
    //#input(void addRefererFilter(RefererFilter, Blog)): filter
    //#input(void addRefererFilter(RefererFilter, Blog)): log
    //#input(void addRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[net/sourceforge/pebble/domain/RefererFilter]
    //#input(void addRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[others]
    //#input(void addRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.getExpression()Ljava/lang/String;
    //#input(void addRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.setExpression(Ljava/lang/String;)V
    //#input(void addRefererFilter(RefererFilter, Blog)): rootBlog
    //#input(void addRefererFilter(RefererFilter, Blog)): this
    //#input(void addRefererFilter(RefererFilter, Blog)): this.__Tag
    //#pre[3] (void addRefererFilter(RefererFilter, Blog)): rootBlog != null
    //#pre[5] (void addRefererFilter(RefererFilter, Blog)): this.__Tag == net/sourceforge/pebble/dao/file/FileRefererFilterDAO
    //#pre[2] (void addRefererFilter(RefererFilter, Blog)): (soft) log != null
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getRoot
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.File
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.File:exists
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.FileReader
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.regex.Pattern:compile
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.ArrayList:add
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader:close
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Collection:iterator
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:close
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.IOException:getMessage
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:net.sourceforge.pebble.dao.PersistenceException
    //#unanalyzed(void addRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.Exception
    filters.add(filter);
    store(filters, rootBlog);
  }
    //#filerefererfilterdao.java:73: end of method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.addRefererFilter(RefererFilter, Blog)

  /**
   * Removes the specified referer filter.
   *
   * @param filter    the RefererFilter instance to be removed
   * @param rootBlog    the owning Blog instance
   * @throws PersistenceException   if something goes wrong removing the filter
   */
  public void deleteRefererFilter(RefererFilter filter, Blog rootBlog) throws PersistenceException {
    Collection filters = getRefererFilters(rootBlog);
    //#filerefererfilterdao.java:83: method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.deleteRefererFilter(RefererFilter, Blog)
    //#input(void deleteRefererFilter(RefererFilter, Blog)): __Descendant_Table[net/sourceforge/pebble/dao/file/FileRefererFilterDAO]
    //#input(void deleteRefererFilter(RefererFilter, Blog)): __Descendant_Table[others]
    //#input(void deleteRefererFilter(RefererFilter, Blog)): __Dispatch_Table.getRefererFilters(Lnet/sourceforge/pebble/domain/Blog;)Ljava/util/Collection;
    //#input(void deleteRefererFilter(RefererFilter, Blog)): filter
    //#input(void deleteRefererFilter(RefererFilter, Blog)): log
    //#input(void deleteRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[net/sourceforge/pebble/domain/RefererFilter]
    //#input(void deleteRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[others]
    //#input(void deleteRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.getExpression()Ljava/lang/String;
    //#input(void deleteRefererFilter(RefererFilter, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.setExpression(Ljava/lang/String;)V
    //#input(void deleteRefererFilter(RefererFilter, Blog)): rootBlog
    //#input(void deleteRefererFilter(RefererFilter, Blog)): this
    //#input(void deleteRefererFilter(RefererFilter, Blog)): this.__Tag
    //#pre[3] (void deleteRefererFilter(RefererFilter, Blog)): rootBlog != null
    //#pre[5] (void deleteRefererFilter(RefererFilter, Blog)): this.__Tag == net/sourceforge/pebble/dao/file/FileRefererFilterDAO
    //#pre[2] (void deleteRefererFilter(RefererFilter, Blog)): (soft) log != null
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:net.sourceforge.pebble.domain.Blog:getRoot
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.File
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.File:exists
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.FileReader
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.regex.Pattern:compile
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.ArrayList:add
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedReader:close
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.FileWriter
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Collection:iterator
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:write
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:newLine
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:flush
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.BufferedWriter:close
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.io.IOException:getMessage
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:net.sourceforge.pebble.dao.PersistenceException
    //#unanalyzed(void deleteRefererFilter(RefererFilter, Blog)): Effects-of-calling:java.lang.Exception
    filters.remove(filter);
    store(filters, rootBlog);
  }
    //#filerefererfilterdao.java:86: end of method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.deleteRefererFilter(RefererFilter, Blog)

  /**
   * Helper method to store all filters for a given blog.
   *
   * @param filters   the Collection of RefererFilter instances to store
   * @param rootBlog      the blog to which the filters belong
   */
  private void store(Collection filters, Blog rootBlog) throws PersistenceException {
    try {
      String root = rootBlog.getRoot();
    //#filerefererfilterdao.java:96: method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.store(Collection, Blog)
    //#filerefererfilterdao.java:96: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getRoot()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO
    //#    method: void store(Collection, Blog)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getRoot()
    //#input(void store(Collection, Blog)): filters
    //#input(void store(Collection, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[net/sourceforge/pebble/domain/RefererFilter]
    //#input(void store(Collection, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Descendant_Table[others]
    //#input(void store(Collection, Blog)): net/sourceforge/pebble/domain/RefererFilter.__Dispatch_Table.getExpression()Ljava/lang/String;
    //#input(void store(Collection, Blog)): rootBlog
    //#pre[1] (void store(Collection, Blog)): filters != null
    //#pre[3] (void store(Collection, Blog)): rootBlog != null
    //#presumption(void store(Collection, Blog)): java.util.Iterator:next(...).__Tag@102 == net/sourceforge/pebble/domain/RefererFilter
    //#presumption(void store(Collection, Blog)): java.util.Iterator:next(...)@102 != null
    //#unanalyzed(void store(Collection, Blog)): Effects-of-calling:java.lang.Exception
    //#test_vector(void store(Collection, Blog)): java.util.Iterator:hasNext(...)@101: {1}, {0}
      BufferedWriter writer = new BufferedWriter(new FileWriter(new File(root, FILTERS_FILE)));

      Iterator it = filters.iterator();
      RefererFilter filter;
      while (it.hasNext()) {
        filter = (RefererFilter)it.next();
        writer.write(filter.getExpression());
        writer.newLine();
      }

      writer.flush();
      writer.close();
    } catch (IOException ioe) {
      log.error(ioe);
      throw new PersistenceException("Filters could not be saved : " + ioe.getMessage());
    }
  }
    //#filerefererfilterdao.java:113: end of method: void net.sourceforge.pebble.dao.file.FileRefererFilterDAO.store(Collection, Blog)

}
    //#filerefererfilterdao.java:: end of class: net.sourceforge.pebble.dao.file.FileRefererFilterDAO
