java.lang.Object
net.i2p.router.news.NewsManager
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionprivate final ClientAppManagerThe manager registering the news app.private final I2PAppContextThe app context.The current news entries.private final LogThe log for the news.private ClientAppStateThe state of the news client app.static final StringClientApp name this manager registers under with the update manager.private static final StringThe bundle of the translated news strings.Constructor Summary
ConstructorsConstructorDescriptionNewsManager(I2PAppContext ctx, ClientAppManager listener, String[] args) Create a news manager and mark it initialized; no news is fetched until the client app is started.Method Summary
Modifier and TypeMethodDescriptionvoidaddEntries(List<NewsEntry> entries) Add or replace each entry in the list.private voidchangeState(ClientAppState state) Changes the state of the client app.The app's display name.Return the current news entries, loading them from disk on first call.The initial (Welcome to I2P) news.getName()The app's internal name.getState()Current app state.Reads the news shipped with the router.Used for initialNews.xml and news.xml.Reads the news saved by a previous run.voidClientApp interface.voidstartup()ClientApp interface method.booleanstoreEntries(List<Node> entries) Store each entry.
Field Details
_context
The app context._log
The log for the news._cmgr
The manager registering the news app._state
The state of the news client app._currentNews
APP_NAME
ClientApp name this manager registers under with the update manager.- See Also:
BUNDLE_NAME
The bundle of the translated news strings.- See Also:
Constructor Details
NewsManager
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 configlistener- the client app manager to notify when a new news bundle arrivesargs- unused; the only caller passes null, since news is read from docs/news.xml rather than supplied as an argument
Method Details
getEntries
storeEntries
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
startup
shutdown
getState
Current app state.- Specified by:
getStatein interfaceClientApp- Returns:
- the current
ClientAppState,INITIALIZEDonce constructed andSTARTING,RUNNINGorSTOPPEDthereafter
getName
getDisplayName
The app's display name.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- the display name
changeState
Changes the state of the client app.- Parameters:
state- the new state
parseOldNews
getInitialNews
The initial (Welcome to I2P) news.- Returns:
- entry with first-installed date stamp, or null
parseInitialNews
parseNews
Used for initialNews.xml and news.xml.- Parameters:
newsContent- the raw news file contents to scan for headingsaddMissingDiv- true for initialNews, false for news.xml- Returns:
- the news entries found in document order, empty if no headings