Class AppDirectory
java.lang.Object
com.iizix.server.app.AppDirectory
- All Implemented Interfaces:
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>(anddir) 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.iiziPWApresent (AU-9) - the manifest link of the page's language, the PNG and Apple icon links, the Apple title and capable metas and the twotheme-colormetas; - an installable application has a manifest per language,
manifest-<lang>.webmanifest(PWAManifest), the iconsPWAIcons.build(PWAIcons.Sources)makes of the module's PWA folder, the icons.iiziPWAnames, the iiziRun icon set and the master icon (CC-PUSH-PWA-PAGES Set I), and the screenshots of the PWA folder (PWAScreenshots) asscreenshots/<name>; - every application has an offline page per language (
PWAOfflinePage), served asoffline.html?lang=<lang>and, for the default language,offline.html, and its Service Workersw.js(PWAServiceWorker): Push in a Browser needs the worker, the manifest does not.
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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhat the generated files of a directory are made from (work order CC-PWA-V5E-APPDIR-PWA).Nested classes/interfaces inherited from interface IAppDirectory
IAppDirectory.GeneratedFileField Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe key of the default language's page.static final intThe number of hexadecimal digits of the stamp.static final StringThe media type of the Service Worker.Fields inherited from interface IAppDirectory
ICON_MAX_AGEConstructor Summary
ConstructorsConstructorDescriptionAppDirectory(String appID, Map<String, String> pages, AppDirectory.Source source, String build) Creates a directory from its pages and the source of its generated files.Creates a directory from its pages, without generated files.Method Summary
Modifier and TypeMethodDescriptiongetAppID()--- IAppDirectory ---Gets a generated file of the directory by its name directly under the directory.Gets the names of the generated files, the offline page once, asgetFile(String,String)answers them (a screenshot asscreenshots/<name>).Gets the language codes of the directory's pages,DEFAULT_LANGUAGEamong them.Gets the application page for a language.getStamp()Gets the stampvof 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.longGets the time the stamp was first built, theLast-Modifiedof every file of the directory.static AppDirectoryload(String appID, File iiziAppFile, Collection<String> languages, Function<String, File> generator, AppDirectory.Source source, String build) Builds the directory of an application asload(String,File,Collection,Function,String)does, with the generated files of a source.static AppDirectoryload(String appID, File iiziAppFile, Collection<String> languages, Function<String, File> generator, String build) Builds the directory of an application from the web root'siiziApp.htmland 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.
Field Details
DEFAULT_LANGUAGE
STAMP_LENGTH
public static final int STAMP_LENGTHThe number of hexadecimal digits of the stamp.- See Also:
SW_MEDIA_TYPE
Constructor Details
AppDirectory
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 underDEFAULT_LANGUAGE; copied.build- The server's version and build,SystemConfig.VERSION_BUILDin 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 underDEFAULT_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_BUILDin 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 IOExceptionBuilds the directory of an application from the web root'siiziApp.htmland 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'siiziApp.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.getCustomizedAppHTMLfor 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 IOExceptionBuilds the directory of an application asload(String,File,Collection,Function,String)does, with the generated files of a source.- Parameters:
appID- The canonical application ID.iiziAppFile- The web root'siiziApp.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
--- IAppDirectory ---- Specified by:
getAppIDin interfaceIAppDirectory- Returns:
- The application ID, never null nor empty.
getStamp
Description copied from interface:IAppDirectoryGets the stampvof 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:
getStampin interfaceIAppDirectory- Returns:
- The stamp, 16 lower-case hexadecimal digits.
getVersionTime
public long getVersionTime()Description copied from interface:IAppDirectoryGets the time the stamp was first built, theLast-Modifiedof every file of the directory.- Specified by:
getVersionTimein interfaceIAppDirectory- Returns:
- The time in milliseconds since the Epoch, whole seconds.
getPage
Description copied from interface:IAppDirectoryGets the application page for a language.- Specified by:
getPagein interfaceIAppDirectory- Parameters:
lang- The language code from thelangentry 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
Description copied from interface:IAppDirectoryGets a generated file of the directory by its name directly under the directory.- Specified by:
getFilein interfaceIAppDirectory- Parameters:
name- The name:sw.js,offline.html,manifest-<lang>.webmanifest(ormanifest.webmanifest), one of the icon names, orscreenshots/<file>.lang- The language code from thelangentry 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
Gets the names of the generated files, the offline page once, asgetFile(String,String)answers them (a screenshot asscreenshots/<name>).- Returns:
- The names, in the order they were generated; empty without a source.
getLanguages
Gets the language codes of the directory's pages,DEFAULT_LANGUAGEamong them.- Returns:
- The codes, unmodifiable.