Class AppDirectory

java.lang.Object
com.iizix.server.app.AppDirectory
All Implemented Interfaces:
IAppDirectory

public final class AppDirectory extends Object implements IAppDirectory
The virtual directory /app/<appID>/ of an application (work order CC-PWA-V5A-APPDIR-ROUTE, design CC-DESIGN-APP-URL-V2 section 2.4): the application page per language as the generator of AppFactory.getCustomizedAppHTML(ServerShell, File, String) produces it, the stamp v over all of them and the server's version and build, and the time the stamp was built. Immutable; held by the AppFactory, so a hot deploy discards it with the factory.

The stamp is the first 16 hexadecimal digits of SHA-256 over, per page in the order of the language codes, the code, a zero byte, the page in UTF-8 and a zero byte, then per generated file in the order of the names the same for the name and the bytes, then the build string: the same pages and files on the same build give the same stamp on every server, and one byte of difference in any of them gives another. The order of the map given does not matter.

The generated files (work order CC-PWA-V5E-APPDIR-PWA, design sections 2.2 and 2.5), made from a AppDirectory.Source when one is given, with the generators of com.iizix.pwa:

  • every page gets its head from PWAHeadTags.apply(String, ModuleApp, PWAProps, String, PWAIcons): the App's title and description, the <html lang> (and dir) of the page's language and no X-UA-Compatible meta for every application (decision V5B-D-7, rulings PM-1, PM-5), and for an installable one - its .iiziPWA present (AU-9) - the manifest link of the page's language, the PNG and Apple icon links, the Apple title and capable metas and the two theme-color metas;
  • an installable application has a manifest per language, manifest-<lang>.webmanifest (PWAManifest), the icons PWAIcons.build(PWAIcons.Sources) makes of the module's PWA folder, the icons .iiziPWA names, the iiziRun icon set and the master icon (CC-PUSH-PWA-PAGES Set I), and the screenshots of the PWA folder (PWAScreenshots) as screenshots/<name>;
  • every application has an offline page per language (PWAOfflinePage), served as offline.html?lang=<lang> and, for the default language, offline.html, and its Service Worker sw.js (PWAServiceWorker): Push in a Browser needs the worker, the manifest does not.
The default page is the page of the first language: its manifest link, its offline page and the lang of both are that language's, and an application without languages has one manifest, manifest.webmanifest (ruling PW-3), whose lang and the page's <html lang> are the App's default language code when it has one (ruling PM-1) and absent otherwise. The worker carries the stamp, so it is generated last and is the one file the stamp does not cover: the stamp is over everything else, the icons' bytes included.
Author:
Christopher Mindus
  • Field Details

    • DEFAULT_LANGUAGE

      public static final String DEFAULT_LANGUAGE
      The key of the default language's page.
      See Also:
    • STAMP_LENGTH

      public static final int STAMP_LENGTH
      The number of hexadecimal digits of the stamp.
      See Also:
    • SW_MEDIA_TYPE

      public static final String SW_MEDIA_TYPE
      The media type of the Service Worker.
      See Also:
  • Constructor Details

    • AppDirectory

      public AppDirectory(String appID, Map<String,String> pages, String build)
      Creates a directory from its pages, without generated files.
      Parameters:
      appID - The canonical application ID.
      pages - The pages by language code, with the default language's page under DEFAULT_LANGUAGE; copied.
      build - The server's version and build, SystemConfig.VERSION_BUILD in production.
      Throws:
      IllegalArgumentException - When there is no default page.
    • AppDirectory

      public AppDirectory(String appID, Map<String,String> pages, AppDirectory.Source source, String build)
      Creates a directory from its pages and the source of its generated files.
      Parameters:
      appID - The canonical application ID.
      pages - The pages by language code, with the default language's page under DEFAULT_LANGUAGE; copied. The order of the map is the order of the languages: the first code after the default is the default language's.
      source - The source of the generated files, null for none: the pages are then served as given and the directory holds no file.
      build - The server's version and build, SystemConfig.VERSION_BUILD in production.
      Throws:
      IllegalArgumentException - When there is no default page, or when a page has no </head> and the head tags must be inserted.
  • Method Details

    • load

      public static AppDirectory load(String appID, File iiziAppFile, Collection<String> languages, Function<String,File> generator, String build) throws IOException
      Builds the directory of an application from the web root's iiziApp.html and the generator of the customized page: the default page, then one per language, each the generated file when the generator answers one and else the web root's page as the legacy servlet serves it, with %%DEVEL%% substituted.
      Parameters:
      appID - The canonical application ID.
      iiziAppFile - The web root's iiziApp.html.
      languages - The language codes of the application, none for a single page; the default page is always built and is the generator's answer for null.
      generator - The generator: AppFactory.getCustomizedAppHTML for a language code, null for the default; answers the generated file or null.
      build - The server's version and build.
      Returns:
      The directory.
      Throws:
      IOException - When a page cannot be read.
    • load

      public static AppDirectory load(String appID, File iiziAppFile, Collection<String> languages, Function<String,File> generator, AppDirectory.Source source, String build) throws IOException
      Builds the directory of an application as load(String,File,Collection,Function,String) does, with the generated files of a source.
      Parameters:
      appID - The canonical application ID.
      iiziAppFile - The web root's iiziApp.html.
      languages - The language codes of the application in their order, the first the default language's; none for a single page.
      generator - The generator of the customized page.
      source - The source of the generated files, null for none.
      build - The server's version and build.
      Returns:
      The directory.
      Throws:
      IOException - When a page cannot be read.
    • getAppID

      public String getAppID()
      --- IAppDirectory ---
      Specified by:
      getAppID in interface IAppDirectory
      Returns:
      The application ID, never null nor empty.
    • getStamp

      public String getStamp()
      Description copied from interface: IAppDirectory
      Gets the stamp v of the directory: the first 16 hexadecimal digits of SHA-256 over the generated bytes of every file of the directory and the server's version and build. Two directories with the same pages on the same build have the same stamp; one byte of difference gives another. It is the first half of every ETag the handler sends.
      Specified by:
      getStamp in interface IAppDirectory
      Returns:
      The stamp, 16 lower-case hexadecimal digits.
    • getVersionTime

      public long getVersionTime()
      Description copied from interface: IAppDirectory
      Gets the time the stamp was first built, the Last-Modified of every file of the directory.
      Specified by:
      getVersionTime in interface IAppDirectory
      Returns:
      The time in milliseconds since the Epoch, whole seconds.
    • getPage

      public String getPage(String lang)
      Description copied from interface: IAppDirectory
      Gets the application page for a language.
      Specified by:
      getPage in interface IAppDirectory
      Parameters:
      lang - The language code from the lang entry parameter, null or empty for the default language.
      Returns:
      The page, never null: the default language's page when the language is not one of the application's.
    • getFile

      public IAppDirectory.GeneratedFile getFile(String name, String lang)
      Description copied from interface: IAppDirectory
      Gets a generated file of the directory by its name directly under the directory.
      Specified by:
      getFile in interface IAppDirectory
      Parameters:
      name - The name: sw.js, offline.html, manifest-<lang>.webmanifest (or manifest.webmanifest), one of the icon names, or screenshots/<file>.
      lang - The language code from the lang entry parameter, null or empty for the default language: it selects the language of a file that is served in several languages under one name - the offline page, whose answer for a language the application does not have is the default language's - and is ignored for the others.
      Returns:
      The file, or null when the directory holds none of that name: the manifest and the icons of an application without .iiziPWA, a manifest of another language, or a directory without generated files, which is what this default answers.
    • getFileNames

      public List<String> getFileNames()
      Gets the names of the generated files, the offline page once, as getFile(String,String) answers them (a screenshot as screenshots/<name>).
      Returns:
      The names, in the order they were generated; empty without a source.
    • getLanguages

      public Set<String> getLanguages()
      Gets the language codes of the directory's pages, DEFAULT_LANGUAGE among them.
      Returns:
      The codes, unmodifiable.