java.lang.Object
net.i2p.router.news.NewsManager
All Implemented Interfaces:
ClientApp

public class NewsManagerextends Object implements ClientApp
Manages I2P router news entries with in-memory storage and disk persistence.

Maintains current news entries in memory while providing methods to add new entries and persist them to disk storage. Handles both initial welcome news and dynamic news feed updates with proper sorting and deduplication logic.

Implements ClientApp interface for lifecycle management with state tracking and notification capabilities. Supports legacy news.xml format for backward compatibility alongside newer structured formats.

  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      The log for the news.
    • _cmgr

      private final ClientAppManager _cmgr
      The manager registering the news app.
    • _state

      private volatile ClientAppState _state
      The state of the news client app.
    • _currentNews

      private List<NewsEntry> _currentNews
      The current news entries.
    • APP_NAME

      public static final String APP_NAME
      ClientApp name this manager registers under with the update manager.
      See Also:
    • BUNDLE_NAME

      private static final String BUNDLE_NAME
      The bundle of the translated news strings.
      See Also:
  • Constructor Details

    • NewsManager

      public NewsManager(I2PAppContext ctx, ClientAppManager listener, String[] args)
      Create a news manager and mark it initialized; no news is fetched until the client app is started.
      Parameters:
      ctx - the application context supplying the log manager and config
      listener - the client app manager to notify when a new news bundle arrives
      args - unused; the only caller passes null, since news is read from docs/news.xml rather than supplied as an argument
  • Method Details

    • getEntries

      public List<NewsEntry> getEntries()
      Return the current news entries, loading them from disk on first call.
      Returns:
      non-null, sorted by updated date, newest first
    • storeEntries

      public boolean storeEntries(List<Node> entries)
      Store each entry. Old entries are always overwritten, as they may change even without the updated date changing. Does NOT update the NewsEntry list.
      Parameters:
      entries - each one should be "entry" at the root
      Returns:
      true if any new entry was written (not if changed)
    • addEntries

      public void addEntries(List<NewsEntry> entries)
      Add or replace each entry in the list. Does NOT store them to disk.
      Parameters:
      entries - the entries to add or replace, matched against existing entries by id, or by title for entries parsed from the old news.xml
    • startup

      public void startup()
      ClientApp interface method. Loads the persisted news, sets the state to running, and registers for state change notifications.
      Specified by:
      startup in interface ClientApp
    • shutdown

      public void shutdown(String[] args)
      ClientApp interface.
      Specified by:
      shutdown in interface ClientApp
      Parameters:
      args - unused; the ClientApp contract allows stopArgs from clients.config, but shutdown only sets the state to STOPPED
    • getState

      public ClientAppState getState()
      Current app state.
      Specified by:
      getState in interface ClientApp
      Returns:
      the current ClientAppState, INITIALIZED once constructed and STARTING, RUNNING or STOPPED thereafter
    • getName

      public String getName()
      The app's internal name.
      Specified by:
      getName in interface ClientApp
      Returns:
      the app name news, the key this app is registered under
    • getDisplayName

      public String getDisplayName()
      The app's display name.
      Specified by:
      getDisplayName in interface ClientApp
      Returns:
      the display name
    • changeState

      private void changeState(ClientAppState state)
      Changes the state of the client app.
      Parameters:
      state - the new state
    • parseOldNews

      private List<NewsEntry> parseOldNews()
      Reads the news saved by a previous run.
      Returns:
      the saved entries
    • getInitialNews

      public NewsEntry getInitialNews()
      The initial (Welcome to I2P) news.
      Returns:
      entry with first-installed date stamp, or null
    • parseInitialNews

      private List<NewsEntry> parseInitialNews()
      Reads the news shipped with the router.
      Returns:
      the built-in entries
    • parseNews

      private List<NewsEntry> parseNews(String newsContent, boolean addMissingDiv)
      Used for initialNews.xml and news.xml.
      Parameters:
      newsContent - the raw news file contents to scan for headings
      addMissingDiv - true for initialNews, false for news.xml
      Returns:
      the news entries found in document order, empty if no headings