.. java:import:: java.io File .. java:import:: java.io IOException .. java:import:: java.nio.charset StandardCharsets .. java:import:: java.nio.file Files .. java:import:: java.nio.file Path .. java:import:: java.nio.file Paths .. java:import:: java.util HashMap .. java:import:: java.util Map .. java:import:: java.util.stream Stream .. java:import:: org.apache.logging.log4j LogManager .. java:import:: org.apache.logging.log4j Logger .. java:import:: org.caosdb.server CaosDBServer .. java:import:: org.caosdb.server ServerProperties .. java:import:: org.caosdb.server.resource AbstractCaosDBServerResource .. java:import:: org.caosdb.server.resource Webinterface .. java:import:: org.restlet Request .. java:import:: org.restlet.data Reference WebinterfaceUtils ================= .. java:package:: org.caosdb.server.utils :noindex: .. java:type:: public class WebinterfaceUtils This class is responsible for two things: Resolving relative paths of files of the web interface to \ :java:ref:`File`\ objects.Generating URIs to public files of the web interface from relative string paths. Especially the \ :java:ref:`AbstractCaosDBServerResource`\ and the \ :java:ref:`Webinterface`\ use this class for these tasks. :author: Timm Fitschen (t.fitschen@indiscale.com) Fields ------ DEFAULT_BUILD_NUMBER_FILE ^^^^^^^^^^^^^^^^^^^^^^^^^ .. java:field:: public static final String DEFAULT_BUILD_NUMBER_FILE :outertype: WebinterfaceUtils DEFAULT_ROUTE ^^^^^^^^^^^^^ .. java:field:: public static final String DEFAULT_ROUTE :outertype: WebinterfaceUtils DEFAULT_WEBUI_PUBLIC ^^^^^^^^^^^^^^^^^^^^ .. java:field:: public static final String DEFAULT_WEBUI_PUBLIC :outertype: WebinterfaceUtils Constructors ------------ WebinterfaceUtils ^^^^^^^^^^^^^^^^^ .. java:constructor:: WebinterfaceUtils(String host, String contextRoot, String publicDir, String route, String buildNumberFile) :outertype: WebinterfaceUtils Create a utility class for creating references to resources of the web interface. :param host: :param contextRoot: :param publicDir: :param route: :param buildNumberFile: WebinterfaceUtils ^^^^^^^^^^^^^^^^^ .. java:constructor:: WebinterfaceUtils(Reference host) :outertype: WebinterfaceUtils Create a utility class for creating references to resources of the web interface. The route to the web interface, the build number file and the public folder of the web interface build directory are set to default values (\ :java:ref:`DEFAULT_BUILD_NUMBER_FILE`\ , \ :java:ref:`DEFAULT_ROUTE`\ , and \ :java:ref:`DEFAULT_WEBUI_PUBLIC`\ ). The contextRoute defaults to the server property \ :java:ref:`ServerProperties.KEY_CONTEXT_ROOT`\ . :param host: - the host of the web interface. **See also:** :java:ref:`{@linkWebinterfaceUtils.WebinterfaceUtils(String,String,String,String)}.` WebinterfaceUtils ^^^^^^^^^^^^^^^^^ .. java:constructor:: WebinterfaceUtils(String host) :outertype: WebinterfaceUtils Create a utility class for creating references to resources of the web interface. The route to the web interface, the build number file and the public folder of the web interface build directory are set to default values (\ :java:ref:`DEFAULT_BUILD_NUMBER_FILE`\ , \ :java:ref:`DEFAULT_ROUTE`\ , and \ :java:ref:`DEFAULT_WEBUI_PUBLIC`\ ). The contextRoute defaults to the server property \ :java:ref:`ServerProperties.KEY_CONTEXT_ROOT`\ . :param host: - the host of the web interface. **See also:** :java:ref:`{@linkWebinterfaceUtils.WebinterfaceUtils(String,String,String,String)}.` Methods ------- getBuildNumber ^^^^^^^^^^^^^^ .. java:method:: public String getBuildNumber() :outertype: WebinterfaceUtils Determine the build number of the webui. Returns null if the build number could not be determined. Because opening and reading the \ :java:ref:`buildNumberFile`\ content is expensive, the buildNumber is cached. The cached buildNumber invalidates when the files modified time stamp is younger than the \ :java:ref:`buildNumberDate`\ . The validity of the cache is checked once every minute with a \ :java:ref:`CronJob`\ . :return: Build number or null. getBuildNumberFile ^^^^^^^^^^^^^^^^^^ .. java:method:: public Path getBuildNumberFile() :outertype: WebinterfaceUtils return the Path of the build number file. getForwardedProto ^^^^^^^^^^^^^^^^^ .. java:method:: public static String getForwardedProto(Request request) :outertype: WebinterfaceUtils getInstance ^^^^^^^^^^^ .. java:method:: public static WebinterfaceUtils getInstance(Request request) :outertype: WebinterfaceUtils Retrieve an instance of \ :java:ref:`WebinterfaceUtils`\ for the request. The instance can be shared with other callers. :param request: :return: a shared instance of \ :java:ref:`WebinterfaceUtils`\ . getInstance ^^^^^^^^^^^ .. java:method:: public static WebinterfaceUtils getInstance(String host) :outertype: WebinterfaceUtils Retrieve an instance of \ :java:ref:`WebinterfaceUtils`\ for the host. The instance can be shared with other callers. :param host: :return: a shared instance of \ :java:ref:`WebinterfaceUtils`\ . getPublicFile ^^^^^^^^^^^^^ .. java:method:: public File getPublicFile(String path) :outertype: WebinterfaceUtils Return the public file or null if the file does not exists or is not in the public directory of the web interface. This method is used to resolve requests for files of the web interface. :param path: :return: The file or null getPublicFilePath ^^^^^^^^^^^^^^^^^ .. java:method:: public Path getPublicFilePath(String path) :outertype: WebinterfaceUtils Return the absolute path to the public file denoted by the path. This method is used to resolve requests for files of the web interface. :param path: - path to the file of the web interface, relative to the public directory of the web interface. :return: The absolute path of the web interface file. getPublicRootPath ^^^^^^^^^^^^^^^^^ .. java:method:: public Path getPublicRootPath() :outertype: WebinterfaceUtils Return the absolute path of the root of the public directory of the webui. :return: Public directory of webui. getServerRootURI ^^^^^^^^^^^^^^^^ .. java:method:: public String getServerRootURI() :outertype: WebinterfaceUtils Return the server root reference. The server root is composed of the scheme (https://) the host name (example.com) the port if necessary (:10443) and the context root of the application (beta). :return: the server root reference e.g. https://example.com:10443/beta. getWebinterfaceRootURI ^^^^^^^^^^^^^^^^^^^^^^ .. java:method:: public String getWebinterfaceRootURI() :outertype: WebinterfaceUtils Return the root reference for the web interface. The root reference for the web interface is the server root reference (\ :java:ref:`getServerRootURI()`\ ) plus the route to the resource which routes to the individual resources of the web interface (\ :java:ref:`Webinterface`\ ). :return: root reference for the web interface. getWebinterfaceURI ^^^^^^^^^^^^^^^^^^ .. java:method:: public String getWebinterfaceURI(String publicFile) :outertype: WebinterfaceUtils Return a URI to a public file of the web interface. This method is used to generate references for *.xsl files or other resources of the web interface. :param publicFile: - the path of the public file, relative to the public directory of the web interface. :return: a URI for the public file of the web interface. readBuildNumber ^^^^^^^^^^^^^^^ .. java:method:: public String readBuildNumber() :outertype: WebinterfaceUtils Return the latest buildNumber, freshly read from the buildNumberfile. :return: fresh build number. validateBuildNumber ^^^^^^^^^^^^^^^^^^^ .. java:method:: public void validateBuildNumber() :outertype: WebinterfaceUtils Check the validity of the buildNumber and invalidate the buildNumber if the buildNumberDate is older than the \ :java:ref:`File.lastModified`\ time stamp of the buildNumberFile.