Class Web

java.lang.Object
ch.autumo.beetroot.utils.web.Web

public class Web extends Object
Web helper methods.
  • Method Details

    • escapeHtmlReserved

      public static String escapeHtmlReserved(String input)
      HTML escape (reserved characters only) value.
      Parameters:
      input - value to escape
      Returns:
      escaped value
    • escapeHtml

      public static String escapeHtml(String value)
      Full HTML escape value. Includes "Umlaute".
      Parameters:
      value - to escape
      Returns:
      value escaped value
    • enrichQuery

      public static String enrichQuery(String url, String name, Object value)
      Enrich URL with parameters.
      Parameters:
      url - url
      name - parameter name
      value - parameter value
      Returns:
      new url
    • normalizeUri

      public static String normalizeUri(String uri)
      Normalize URI.
      Parameters:
      uri - URI
      Returns:
      normalized URI
    • getRealPath

      public static String getRealPath(jakarta.servlet.ServletContext context)
      Returns the real filesystem path of the web application's root directory. Note: This only works for exploded (unpacked) web applications. If the application is packaged in a WAR and not exploded, this method may return null.
      Parameters:
      context - the ServletContext
      Returns:
      the absolute filesystem path ending with a file separator, or null if unavailable
    • prepareHtmlWithLineBreaks

      public static String prepareHtmlWithLineBreaks(String html, boolean prettyPrint)
      Remove unnecessary HTML tags, but preserve line-breaks.
      Parameters:
      html - the input HTML
      prettyPrint - use pretty-print?
      Returns:
      prepared HTML
    • prepareHtmlWithLineBreaks

      public static String prepareHtmlWithLineBreaks(String html, boolean prettyPrint, String... addTags)
      Remove unnecessary HTML tags, but preserve line-breaks.
      Parameters:
      html - the input HTML
      prettyPrint - use pretty-print?
      addTags - additional tags that should be kept if any
      Returns:
      prepared HTML
    • prepareHtmlWithLineBreaks

      public static String prepareHtmlWithLineBreaks(String html, boolean prettyPrint, List<AbstractMap.SimpleEntry<String,String>> replacements)
      Remove unnecessary HTML tags, but preserve line-breaks.
      Parameters:
      html - the input HTML
      prettyPrint - use pretty-print?
      replacements - tags to replace if any
      Returns:
      prepared HTML
    • prepareHtmlWithLineBreaks

      public static String prepareHtmlWithLineBreaks(String html, boolean prettyPrint, List<AbstractMap.SimpleEntry<String,String>> replacements, String... addTags)
      Remove unnecessary HTML tags, but preserve line-breaks.
      Parameters:
      html - the input HTML
      prettyPrint - use pretty-print?
      addTags - additional tags that should be kept if any
      replacements - tags to replace if any
      Returns:
      prepared HTML
    • getHtmlDivType

      public static String getHtmlDivType(ResultSetMetaData rsmd, int idx, String columnName) throws SQLException
      Determine HTML div field type for SQL data type.
      Parameters:
      rsmd - result set meta data
      idx - db column index
      columnName - db column name
      Returns:
      type
      Throws:
      SQLException - SQL exception
    • getHtmlInputType

      public static String getHtmlInputType(ResultSetMetaData rsmd, int idx, String columnName) throws SQLException
      Determine HTML input field type for SQL data type.
      Parameters:
      rsmd - result set meta data
      idx - db column index
      columnName - db column name
      Returns:
      type
      Throws:
      SQLException - SQL exception
    • getHtmlInputPattern

      public static String getHtmlInputPattern(int idx, String columnName) throws SQLException
      Determine HTML input field pattern based on column name.
      Parameters:
      idx - db column index
      columnName - db column name
      Returns:
      pattern
      Throws:
      SQLException - SQL exception
    • preFormatForHTML

      public static String preFormatForHTML(Object databaseValueObject, int sqlType)
      Pre-format values from database for HTML input values.
      Parameters:
      databaseValueObject - database value object
      sqlType - SQL type, see Types
      Returns:
      pre-formatted value for HTML
    • formatDateForHTML

      protected static String formatDateForHTML(Date sqlDate)
      Format SQL date.
      Parameters:
      sqlDate - SQL date
      Returns:
      formatted string for HTML input value
    • formatTimeForHTML

      protected static String formatTimeForHTML(Time sqlTime)
      Format SQL time.
      Parameters:
      sqlTime - SQL time
      Returns:
      formatted string for HTML input value
    • formatDateTimeForHTML

      protected static String formatDateTimeForHTML(Timestamp sqlTimestamp)
      Format SQL time-stamp.
      Parameters:
      sqlTimestamp - SQL time-stamp
      Returns:
      formatted string for HTML input value
    • pingWebsite

      public static boolean pingWebsite(String urlAddress)
      Ping a web-site.
      Parameters:
      urlAddress - URL address
      Returns:
      true if ping was successful