Package ch.autumo.beetroot.utils.web
Class Web
java.lang.Object
ch.autumo.beetroot.utils.web.Web
Web helper methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringenrichQuery(String url, String name, Object value) Enrich URL with parameters.static StringescapeHtml(String value) Full HTML escape value.static StringescapeHtmlReserved(String input) HTML escape (reserved characters only) value.protected static StringformatDateForHTML(Date sqlDate) Format SQL date.protected static StringformatDateTimeForHTML(Timestamp sqlTimestamp) Format SQL time-stamp.protected static StringformatTimeForHTML(Time sqlTime) Format SQL time.static StringgetHtmlDivType(ResultSetMetaData rsmd, int idx, String columnName) Determine HTML div field type for SQL data type.static StringgetHtmlInputPattern(int idx, String columnName) Determine HTML input field pattern based on column name.static StringgetHtmlInputType(ResultSetMetaData rsmd, int idx, String columnName) Determine HTML input field type for SQL data type.static StringgetRealPath(jakarta.servlet.ServletContext context) Returns the real filesystem path of the web application's root directory.static StringnormalizeUri(String uri) Normalize URI.static booleanpingWebsite(String urlAddress) Ping a web-site.static StringpreFormatForHTML(Object databaseValueObject, int sqlType) Pre-format values from database for HTML input values.static StringprepareHtmlWithLineBreaks(String html, boolean prettyPrint) Remove unnecessary HTML tags, but preserve line-breaks.static StringprepareHtmlWithLineBreaks(String html, boolean prettyPrint, String... addTags) Remove unnecessary HTML tags, but preserve line-breaks.static StringprepareHtmlWithLineBreaks(String html, boolean prettyPrint, List<AbstractMap.SimpleEntry<String, String>> replacements) Remove unnecessary HTML tags, but preserve line-breaks.static StringprepareHtmlWithLineBreaks(String html, boolean prettyPrint, List<AbstractMap.SimpleEntry<String, String>> replacements, String... addTags) Remove unnecessary HTML tags, but preserve line-breaks.
-
Method Details
-
escapeHtmlReserved
HTML escape (reserved characters only) value.- Parameters:
input- value to escape- Returns:
- escaped value
-
escapeHtml
Full HTML escape value. Includes "Umlaute".- Parameters:
value- to escape- Returns:
- value escaped value
-
enrichQuery
Enrich URL with parameters.- Parameters:
url- urlname- parameter namevalue- parameter value- Returns:
- new url
-
normalizeUri
Normalize URI.- Parameters:
uri- URI- Returns:
- normalized URI
-
getRealPath
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
Remove unnecessary HTML tags, but preserve line-breaks.- Parameters:
html- the input HTMLprettyPrint- use pretty-print?- Returns:
- prepared HTML
-
prepareHtmlWithLineBreaks
Remove unnecessary HTML tags, but preserve line-breaks.- Parameters:
html- the input HTMLprettyPrint- 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 HTMLprettyPrint- 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 HTMLprettyPrint- use pretty-print?addTags- additional tags that should be kept if anyreplacements- 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 dataidx- db column indexcolumnName- 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 dataidx- db column indexcolumnName- db column name- Returns:
- type
- Throws:
SQLException- SQL exception
-
getHtmlInputPattern
Determine HTML input field pattern based on column name.- Parameters:
idx- db column indexcolumnName- db column name- Returns:
- pattern
- Throws:
SQLException- SQL exception
-
preFormatForHTML
Pre-format values from database for HTML input values.- Parameters:
databaseValueObject- database value objectsqlType- SQL type, seeTypes- Returns:
- pre-formatted value for HTML
-
formatDateForHTML
Format SQL date.- Parameters:
sqlDate- SQL date- Returns:
- formatted string for HTML input value
-
formatTimeForHTML
Format SQL time.- Parameters:
sqlTime- SQL time- Returns:
- formatted string for HTML input value
-
formatDateTimeForHTML
Format SQL time-stamp.- Parameters:
sqlTimestamp- SQL time-stamp- Returns:
- formatted string for HTML input value
-
pingWebsite
Ping a web-site.- Parameters:
urlAddress- URL address- Returns:
- true if ping was successful
-