java.lang.Object
i2p.susi.dns.BaseBean
i2p.susi.dns.AddressbookBean
Direct Known Subclasses:
NamingServiceBean

public class AddressbookBeanextends BaseBean
Bean for managing I2P address books. Provides functionality for loading, filtering, and managing address entries.
  • Field Details

    • _log

      private static final Log _log
      Logger instance.
    • book

      protected String book
      The address book name.
    • filter

      protected String filter
      The filter string.
    • hostname

      protected String hostname
      The hostname.
    • destination

      protected String destination
      The destination.
    • category

      protected String category
      The category filter string.
    • VALID_CATEGORIES

      private static final String[] VALID_CATEGORIES
      Valid category names.
    • beginIndex

      protected int beginIndex
      Beginning index for pagination.
    • endIndex

      protected int endIndex
      Ending index for pagination.
    • addressbook

      private Properties addressbook
      Subscriptions by name.
    • _propsByHost

      private Map<String, Properties> _propsByHost
      Parsed #! properties per hostname, built once per load.
    • deletionMarks

      protected final LinkedList<String> deletionMarks
      List of entries marked for deletion.
    • sorter

      protected static final Comparator<AddressBean> sorter
      Comparator for sorting addresses.
    • DISPLAY_SIZE

      private static final int DISPLAY_SIZE
      Subscriptions listed on one page.
      See Also:
    • entries

      protected AddressBean[] entries
      Array of address entries.
  • Constructor Details

    • AddressbookBean

      public AddressbookBean()
      Creates an empty addressbook bean.
  • Method Details

    • getSearch

      public String getSearch()
      Returns the search string.
      Returns:
      the search string
    • setSearch

      public void setSearch(String s)
      Sets the search string.
      Parameters:
      s - the search string to set
    • isHasFilter

      public boolean isHasFilter()
      Returns whether a filter is active.
      Returns:
      true if a filter is active
    • isIsEmpty

      public boolean isIsEmpty()
      Returns whether the address book is empty.
      Returns:
      true if the address book is empty
    • isNotEmpty

      public boolean isNotEmpty()
      Returns whether the address book is not empty.
      Returns:
      true if the address book is not empty
    • getFileName

      public String getFileName()
      Returns the file name for the address book.
      Returns:
      the file name
    • loadPropertiesFromFile

      private void loadPropertiesFromFile(AddressBean bean, String hostname)
      Load properties for a hostname from the raw hosts.txt file. This parses the #! format for properties.
      Parameters:
      bean - the AddressBean to set properties on
      hostname - the host whose hosts.txt entry is to be parsed
    • parsePropertiesFromFile

      private Map<String, Properties> parsePropertiesFromFile()
      Parse the #! properties from the raw hosts.txt file in one pass. Called once per load and reused for every entry.
      Returns:
      the map of hostname to parsed properties, may be empty
    • getDisplayName

      public String getDisplayName()
      Returns the display name for the address book.
      Returns:
      the display name
    • getEntries

      public AddressBean[] getEntries()
      Returns the address entries.
      Returns:
      the address entries
    • getBook

      public String getBook()
      This always returns a valid book, non-null.
      Returns:
      the book name
    • setBook

      public void setBook(String book)
      Set the address book to display, normalizing unknown names to "router".
      Parameters:
      book - the book name to set
    • getLoadBookMessages

      public String getLoadBookMessages()
      Load addressbook and apply filter, returning messages about this.
      Returns:
      messages about loading the address book
    • generateLoadMessage

      protected String generateLoadMessage()
      Format a message about filtered addressbook size, and the number of displayed entries addressbook.jsp catches the case where the whole book is empty.
      Returns:
      message about loading
    • getMessages

      public String getMessages()
      Perform actions, returning messages about this.
      Returns:
      messages about the performed actions
    • save

      private void save() throws IOException
      Writes the subscriptions back to the file.
      Throws:
      IOException - if the file cannot be written
    • getFilter

      public String getFilter()
      The search filter narrowing the displayed entries.
      Returns:
      the filter string
    • isValidBook

      public boolean isValidBook()
      Because the following from addressbook.jsp fails parsing in the new EL: javax.el.ELException: Failed to parse the expression Can't figure out why, so just replace it with book.validBook:
      <c:if test="${book.master || book.router || book.published || book.private}">
      This always returns true anyway, because getBook() always returns a valid book.
      Returns:
      true if the book is one of router, master, local, published or private
    • setFilter

      public void setFilter(String filter)
      Set the search filter; "none" clears it, and a category name selects that category.
      Parameters:
      filter - filter string to set
    • getDestination

      public String getDestination()
      The destination for the add or edit form, as entered.
      Returns:
      the destination string
    • setDestination

      public void setDestination(String destination)
      Set the destination for the add or edit form.
      Parameters:
      destination - the destination string to store, stripped of any HTML
    • getCategoryFilter

      public String getCategoryFilter()
      The category filter, set when the search filter names a category.
      Returns:
      the category filter string
    • getHostname

      public String getHostname()
      The hostname for the add or edit form, as entered.
      Returns:
      the hostname string
    • setResetDeletionMarks

      public void setResetDeletionMarks(String dummy)
      Resets the deletion marks.
      Parameters:
      dummy - unused, required by the JavaBeans setter convention
    • setMarkedForDeletion

      public void setMarkedForDeletion(String name)
      Marks an entry for deletion.
      Parameters:
      name - the name of the entry to mark for deletion
    • setHostname

      public void setHostname(String hostname)
      Set the hostname for the add or edit form.
      Parameters:
      hostname - the hostname string to store, stripped of any HTML
    • getBeginInt

      protected int getBeginInt()
      The first displayed entry index, clamped to the result set.
      Returns:
      the beginning index
    • getBegin

      public String getBegin()
      The clamped first displayed entry index, as a string for the JSP.
      Returns:
      the beginning index as string
    • getPageBegin

      public int getPageBegin()
      Gets the beginning index into results for display purposes. Returns the actual page start index, not clamped to resultSize().
      Returns:
      the page start index (0-based)
    • setBegin

      public void setBegin(String s)
      Set the page start index from a form string, ignoring garbage.
      Parameters:
      s - the beginning index as string
    • getEndInt

      protected int getEndInt()
      The last displayed entry index, clamped to the result set.
      Returns:
      the ending index
    • getEnd

      public String getEnd()
      The clamped last displayed entry index, as a string for the JSP.
      Returns:
      the ending index as string
    • getResultBegin

      public String getResultBegin()
      The index of the first entry in the result set, as a string.
      Returns:
      beginning index into results
    • getResultEnd

      public String getResultEnd()
      The index of the last entry in the result set, as a string.
      Returns:
      ending index into results
    • setEnd

      public void setEnd(String s)
      Set the page end index from a form string, ignoring garbage.
      Parameters:
      s - the ending index as string
    • isPrefiltered

      protected boolean isPrefiltered()
      Checks if entries are pre-filtered.
      Returns:
      true if pre-filtered
    • resultSize

      protected int resultSize()
      The number of entries in the current result set.
      Returns:
      the size of the lookup result
    • getTotalFilteredCount

      protected int getTotalFilteredCount()
      Gets the total count of filtered results for pagination display. Subclasses can override to return the count before manual pagination.
      Returns:
      the total count of filtered results
    • totalSize

      protected int totalSize()
      The total number of entries in the book.
      Returns:
      the total size of the address book