public class NewsHelperextends ContentHelper
If news file does not exist, use file from the initialNews directory in $I2P.
  • Field Details

    • PROP_LAST_UPDATE_TIME

      public static final String PROP_LAST_UPDATE_TIME
      Router config property recording when news was last downloaded, in milliseconds.
      See Also:
    • PROP_LAST_HIDDEN

      private static final String PROP_LAST_HIDDEN
      Config key for when the news bar was last hidden.
      See Also:
    • PROP_LAST_CHECKED

      public static final String PROP_LAST_CHECKED
      When news was last fetched, in milliseconds since the epoch.
      See Also:
    • PROP_LAST_UPDATED

      public static final String PROP_LAST_UPDATED
      Last-Modified stamp of the news actually downloaded, in milliseconds since the epoch.
      See Also:
    • PROP_LAST_NEW_ENTRY

      public static final String PROP_LAST_NEW_ENTRY
      Last-Modified stamp of the fetch that first added an entry, in milliseconds since the epoch.
      See Also:
    • PROP_LAST_LANG

      public static final String PROP_LAST_LANG
      Console language the news was last downloaded in.
      See Also:
    • PROP_TRANSLATE

      public static final String PROP_TRANSLATE
      Default true.
      See Also:
    • NEWS_FILE

      public static final String NEWS_FILE
      Bundled news XML the console fetches and parses.
      See Also:
  • Constructor Details

    • NewsHelper

      public NewsHelper()
      Leaves the context unset; setContextId() must supply it first.
  • Method Details

    • isAnyUpdateInProgress

      public static boolean isAnyUpdateInProgress()
      If ANY update is in progress.
      Returns:
      whether any update in progress
    • isUpdateInProgress

      public static boolean isUpdateInProgress()
      If a signed or unsigned router update is in progress. Does NOT cover plugins, news, etc.
      Returns:
      whether update in progress
    • isUpdateAvailable

      public static boolean isUpdateAvailable()
      Release update only. Will be false if already downloaded.
      Returns:
      whether update available
    • isExternalRestartPending

      public static boolean isExternalRestartPending()
      A router update had been downloaded and handled by an UpdatePostProcessor. It will provide wrapper-like function to install the update and restart after shutdown.
      Returns:
      whether external restart pending
    • updateVersion

      public static String updateVersion()
      Release update only. Available version, will be null if already downloaded.
      Returns:
      null if none
    • updateConstraint

      public static String updateConstraint()
      Release update only. Translated message about new version available but constrained.
      Returns:
      null if none
    • unsignedUpdateConstraint

      public static String unsignedUpdateConstraint()
      Translated message about new version available but constrained.
      Returns:
      null if none
    • devSU3UpdateConstraint

      public static String devSU3UpdateConstraint()
      Translated message about new version available but constrained.
      Returns:
      null if none
    • updateVersionDownloaded

      public static String updateVersionDownloaded()
      Release update only. Already downloaded but not installed version.
      Returns:
      null if none
    • isUnsignedUpdateAvailable

      public static boolean isUnsignedUpdateAvailable(RouterContext ctx)
      Will be false if already downloaded or if dev update disabled.
      Parameters:
      ctx - the router context, consulted for router.updateUnsigned
      Returns:
      whether unsigned update available
    • unsignedUpdateVersion

      public static String unsignedUpdateVersion()
      The version of the unsigned update on offer.
      Returns:
      null if none
    • unsignedVersionDownloaded

      public static String unsignedVersionDownloaded()
      Already downloaded but not installed version.
      Returns:
      null if none
    • isDevSU3UpdateAvailable

      public static boolean isDevSU3UpdateAvailable(RouterContext ctx)
      Will be false if already downloaded or if dev update disabled.
      Parameters:
      ctx - the router context, consulted for router.updateDevSU3
      Returns:
      whether dev s u3 update available
    • devSU3UpdateVersion

      public static String devSU3UpdateVersion()
      The version of the development SU3 update on offer.
      Returns:
      null if none
    • devSU3VersionDownloaded

      public static String devSU3VersionDownloaded()
      Already downloaded but not installed version.
      Returns:
      null if none
    • formatUnsignedVersion

      private static String formatUnsignedVersion(String ver)
      Convert long date stamp to date/time in the system locale, local time zone.
      Parameters:
      ver - the unsigned update's version, a modification time in ms
      Returns:
      the date and time in the local zone, null if ver is null or not a number
    • getUpdateStatus

      public static String getUpdateStatus()
      The update manager's own status line.
      Returns:
      "" if none
    • getContent

      public String getContent()
      If we haven't downloaded news yet, use the translated initial news file.
      Overrides:
      getContent in class ContentHelper
      Returns:
      up to three entries no older than 60 days
    • shouldShowNews

      public boolean shouldShowNews()
      Is the news newer than the last time it was hidden?
      Returns:
      whether show news
    • shouldShowNews

      public static boolean shouldShowNews(RouterContext ctx)
      Whether the news file is newer than the stamp saved when it was hidden.
      Parameters:
      ctx - the router context to read the hidden-news stamp from
      Returns:
      whether show news
    • showNews

      public void showNews(boolean yes)
      Save config with the timestamp of the current news to hide, or 0 to show.
      Parameters:
      yes - true to show the news, false to stamp it as hidden
    • showNews

      public static void showNews(RouterContext ctx, boolean yes)
      Save config with the timestamp of the current news to hide, or 0 to show.
      Parameters:
      ctx - the router context whose config is updated
      yes - true to show the news, false to stamp it as hidden
    • status

      public String status()
      The news and update status block: how long ago news was last fetched and updated, which update is on offer, and links to hide or show the news.
      Returns:
      the rendered status block
    • status

      public static String status(RouterContext ctx)
      The news and update status block.
      Parameters:
      ctx - the router context supplying the news and update state
      Returns:
      the rendered status block
    • status

      public static String status(RouterContext ctx, HttpSession session)
      The news and update status block.
      Parameters:
      ctx - the router context supplying the news and update state
      session - the caller's session, not consulted while rendering
      Returns:
      the rendered status block
    • dontInstall

      public static boolean dontInstall(RouterContext ctx)
      Whether installing an update is blocked outright.
      Parameters:
      ctx - the router context supplying the update and base dir settings
      Returns:
      true if updates are disabled or the base dir is not writable
    • isUpdateDisabled

      public static boolean isUpdateDisabled(RouterContext ctx)
      Whether updating has been switched off in the config.
      Parameters:
      ctx - the router context consulted for router.updateDisabled
      Returns:
      whether update disabled
    • isBaseReadonly

      public static boolean isBaseReadonly(RouterContext ctx)
      Whether an update could not be written even if it were allowed.
      Parameters:
      ctx - the router context supplying the base dir to test
      Returns:
      whether base readonly
    • lastChecked

      public static long lastChecked(RouterContext ctx)
      When news was last fetched, whether or not anything changed.
      Parameters:
      ctx - the router context to read the fetch stamp from
      Returns:
      milliseconds since the epoch, or 0 if never fetched
    • lastUpdated

      public static long lastUpdated(RouterContext ctx)
      When the news was last downloaded.
      Parameters:
      ctx - the router context to read the stamp from and save it to
      Returns:
      milliseconds since the epoch, or 0 if unknown
    • lastNewEntry

      private static long lastNewEntry(RouterContext ctx)
      When we last got a new news entry.
      Parameters:
      ctx - the router context, used for the property and to save the fallback
      Returns:
      the last new entry time, or the last update time if none is stored