public class NamingServiceBeanextends AddressbookBean
Talk to the NamingService API instead of modifying the hosts.txt files directly, except for the 'published' addressbook.
  • Field Details

    • _log

      private static final Log _log
      Logger for this class.
    • DEFAULT_NS

      private static final String DEFAULT_NS
      Naming service used when none is configured.
      See Also:
    • detail

      private String detail
      Detail line shown for the service on the page.
    • notes

      private String notes
      Notes shown for the service on the page.
    • fail

      private boolean fail
      True if the lookup through this service failed.
    • filteredCount

      private int filteredCount
      How many found entries the blacklist removed.
    • fullFilteredEntries

      private AddressBean[] fullFilteredEntries
      The entries that survived filtering.
    • _serverPaginated

      private boolean _serverPaginated
      True when the last load applied skip/limit server-side; total is then totalSize().
    • CACHE_TTL

      private static final long CACHE_TTL
      How long a cached addressbook load or book size is reused before the naming service is re-queried.
      See Also:
    • _loadKey

      private String _loadKey
      Key of the currently cached load (filter, search, category, pagination, book).
    • _loadTime

      private long _loadTime
      When the cached load was performed.
    • _cachedLoadMessage

      private String _cachedLoadMessage
      Message from the cached load, null until the first successful load.
    • _sizeKey

      private String _sizeKey
      Key of the currently cached book size.
    • _sizeTime

      private long _sizeTime
      When the cached book size was computed.
    • _cachedSize

      private int _cachedSize
      Cached book size, -1 until computed.
  • Constructor Details

    • NamingServiceBean

      public NamingServiceBean()
      A fresh bean: the display range is initialised by AddressbookBean and the cached load and book-size entries below are empty, so the first query repopulates them.
  • Method Details

    • isDirect

      private boolean isDirect()
      Check if the published addressbook is in use (direct file access).
      Returns:
      true if the book is "published"
    • isPrefiltered

      protected boolean isPrefiltered()
      Checks if entries are pre-filtered.
      Overrides:
      isPrefiltered in class AddressbookBean
      Returns:
      true when the entries came back already filtered by the naming service, so callers must not filter or paginate them again
    • resultSize

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

      protected int getTotalFilteredCount()
      Gets the total count of filtered results for pagination display. Returns the count BEFORE manual pagination is applied.
      Overrides:
      getTotalFilteredCount in class AddressbookBean
      Returns:
      the total count of filtered results
    • totalSize

      protected int totalSize()
      The total number of entries in the book.
      Overrides:
      totalSize in class AddressbookBean
      Returns:
      the total size of the address book
    • isNotEmpty

      public boolean isNotEmpty()
      Returns whether the address book is not empty.
      Overrides:
      isNotEmpty in class AddressbookBean
      Returns:
      whether not empty
    • getFileName

      public String getFileName()
      Returns the file name for the address book.
      Overrides:
      getFileName in class AddressbookBean
      Returns:
      the file name
    • getDisplayName

      public String getDisplayName()
      Returns the display name for the address book.
      Overrides:
      getDisplayName in class AddressbookBean
      Returns:
      the display name
    • searchNamingService

      private static NamingService searchNamingService(NamingService ns, String srch)
      Perform a depth-first search for a naming service by name.
      Parameters:
      ns - the root naming service to search from
      srch - the name to search for
      Returns:
      the matching NamingService, or null if not found
    • basename

      private static String basename(String filename)
      Get the basename of a file path.
      Parameters:
      filename - the full file path
      Returns:
      the basename (part after the last '/')
    • getNamingService

      private NamingService getNamingService()
      Get the NamingService for the current file name, or the root NamingService.
      Returns:
      the book matching the current file name, falling back to the root naming service when no book in the tree matches
    • loadKey

      private String loadKey()
      Key for the load cache; changes whenever an input that affects the displayed entries changes.
      Returns:
      the cache key
    • clearCaches

      private void clearCaches()
      Drop cached load results and book size so the next access re-queries the naming service. Called after actions that mutate the addressbook.
    • getLoadBookMessages

      public String getLoadBookMessages()
      Load addressbook and apply filter, returning messages about this. To control memory, don't load the whole addressbook if we can help it... only load what is searched for. Results are cached for CACHE_TTL and reused while the inputs (filter, search, category, pagination, book) are unchanged.
      Overrides:
      getLoadBookMessages in class AddressbookBean
      Returns:
      messages about loading the address book
    • getEntries

      public AddressBean[] getEntries()
      Returns the address entries. Returns the entries with blacklist filtering and the current filter, search, and pagination applied, loading or reusing the cached load.
      Overrides:
      getEntries in class AddressbookBean
      Returns:
      the filtered, searched, and paginated entries, or null if no load has succeeded yet
    • getMessages

      public String getMessages()
      Perform actions, returning messages about this.
      Overrides:
      getMessages in class AddressbookBean
      Returns:
      messages about the performed actions
    • saveNotes

      public void saveNotes()
      Save notes for a destination.
    • setH

      public void setH(String h)
      Sets the hostname for lookup.
      Parameters:
      h - the hostname to set
    • setNofilter_notes

      public void setNofilter_notes(String n)
      Sets the notes for the destination.
      Parameters:
      n - the notes to set
    • getLookup

      public AddressBean getLookup()
      Lookup a single destination by hostname.
      Returns:
      the AddressBean for the destination, or null if not found
    • getLookupAll

      public List<AddressBean> getLookupAll()
      Lookup all destinations for a hostname.
      Returns:
      list of AddressBeans for all destinations, or null if not found
    • export

      public void export(Writer out) throws IOException
      Export address book entries to a writer.
      Parameters:
      out - the writer to export to
      Throws:
      IOException - if an I/O error occurs
    • importFile

      public String importFile(RequestWrapper wrequest) throws IOException
      Import entries from a file upload.
      Parameters:
      wrequest - the request wrapper containing the file
      Returns:
      messages about the import operation
      Throws:
      IOException - if an I/O error occurs
    • styleMessage

      private static String styleMessage(String message, boolean fail)
      Style a message for display in the UI.
      Parameters:
      message - the text for the messages paragraph, inserted verbatim and not escaped
      fail - true if the message indicates a failure
      Returns:
      the styled HTML message
    • haveImagegen

      public boolean haveImagegen()
      Check if the imagegen service is available.
      Returns:
      true if imagegen is registered