RamHttpTools API Document
RamHttpTools API Document
jakarta.servlet
Interface RamHttpTools
For HTTP protocol information about time date formats (RFC 3339) 5.6. Internet Date/Time Format
https://tools.ietf.org/html/rfc3339 and
(RFC 1945) 3.3 Date/Time Formats https://tools.ietf.org/html/rfc1945#section-3.3
For information on custom java date-time formatting templates see class
java.time.format.DateTimeFormatter
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
note: method getzonedDateRFC1123format(java.time.ZonedDateTime ZmethodCall) returns a GMT string almost suitable for the
1.0 "expires" command and is easy to manipulate as a String.
However, TZif is not supported at this time (pardon the pun). https://tools.ietf.org/html/rfc8536 neither WebDAV (CalDAV)
https://tools.ietf.org/rfc/rfc7809.txt
Although this class is persistent AND has a global HashTable<String,String> array instantiated on application startup, it is not for
use of storing any data from servlets or jsp or other java container systems, those such problems are for web application servlet user
session or jsp user session and the loaded application's bean repository.
This class does instantiate some data on starting but is only for use with the methods in this class.
The HashTable array is for storing String elements of e.g. pre-formatted ready date-time , header command right-side values, String
templates for Date Formatter and other associate "pre determined parts" that should be (usually) loaded using the application context
listener class on application startup.
The class also contains what i call "convenience methods". These methods are made with short one or two lines of code considered to
be almost nothing that are in essence supplied by the Java API classes in context to the operations, Used here in this class it does
suggest to the programmer the type of object to use or create in the circumstance, although almost uneeded to write, however, these
methods are a point in the correct direction for use. It is also effectively a little quicker to use than actually finding a method from the
docs.
For internationalization assistance, the array of http header commands also contains single symbol elements representing many
English language programming and punctuation symbols,
these symbols can be converted to other ISO charset with the method reEncodechars() , in the interface is also a method returning a
String to output the complete array of symbol and command elements indexed with their output representation.
Below are some construct of pieces required or may be required when using reEncodechars() String ISO converter method
One of the most important benefits of encoding conversion for internationalization in HTTP comes from the problem much of
the supplied HTML page scripting and server side programming such as header output commands and value fields is required to be
constructed in ASCII character set / subset, and can be declared in an international markup page inside an element and its sub
elements to be in EN_us language with the lang= markup attribute supplied by some markup elements. This is specially useful and
practical for output of javascript DHTML from non English charset and language servers.
A note to non English coders / programmers, this works much better for .js javascript DHTML script when the script is stored in a file
external to the html / xml page and the re-encode sequence called alike / similar to below is checked by saving in a file using a byte
stream then opened in an editor sure to acknowledge the ASCII charset for correct display.
java.nio.charset.Charset defchar = java.nio.charset.Charset.defaultCharset();
String charsetInputName = defchar.name(); // get default OS system underlying base charset code page
// "UTF_8"; "GB18030" //java.nio.charset.StandardCharsets.UTF_8.name(); // "GB2312"; /// "UTF_16"; // "UTF_8"; "GB18030"
// FOLLOWING is middle hop transfer re-encode from ("GB18030") PRC Chinese simplified carrying an English subset to a (GB2312)
Web Cinese simplified with English subset
// THEN from the middle hop (GB2312) web charset to a standard English charset (UTF_8)
String charsetFrom = "GB2312";
String charsetNameto = java.nio.charset.StandardCharsets.UTF_8.name(); //"GB2312"; US_ASCII UTF_8
String charout = ramm.reEncodechars(java.util.Locale.ENGLISH,headerOrigin,"GB18030","GB2312");
charout = ramm.reEncodechars(java.util.Locale.ENGLISH,charout,charsetFrom,charsetNameto);
Included class of this interface are methods to use the internal HTTP header commands array. The header commands array is
incorporate with and as english text "symbols" array for assistance to conversion of characters in foreign ISO charsets.
They include two array element header parts string concatenator methods, a method to replace the ten basic digits "0 - 9 global Array of
digits" in one of the two supplied special concatenator methods for convenience of other ISO charset use.
NOTE: The tools in this object relating ISO charsets are not intended to replace normal custom programmed components and are an
assistance only.
The HTTP header commands array is a global final String[] array and contains a quantity of common 1.1 header commands for cache
setting and output and http 1.0 GMT string construction for "expires" header.
A note on http cookies , settings of Max-Age= and Expires= and alike keys , these are "cache mechanism" parameters , meaning
setting a long period of time while developing the code in the server or the page may not clear the previous cookie entry, so matter of
only seconds is better than a single minute as the value of the setting while testing.
See also: an associate similar mechanism javax.servlet.RamStringB64 / jakarta.servlet.RamStringB64 and
org.apache.catalina.core.RAMStringB64Array
See also: an associate similar mechanism javax.servlet.Ramfile / jakarta.servlet.Ramfile and
org.apache.catalina.core.RAMfileArray
Method Summary
Method to join elements together of the Http commands and symbols array repository for
output http header writing. Each int is an index of the desired symbol or command drawn from
the Http commands and symbols array, int indexes of the array elements are concatenated in
sequence into a single String.
This method constructs a java.util.TimeZone object from an ID that is a String that is a qualified
java.util.TimeZone ID name. A qualifying TimeZone name can be obtained from the array of
TimeZone names by method getListedTimeZoneID(int indexTZ) of this class.
Note: the pre constructed arrays in this class may vary their index between versions of JVM !
java.lang.String[] getAllCountryNameText()
Returns a pre loaded String[] array of all available java.util.Locale national country display
names in the version of JVM.
java.lang.String[] getAllLanguageNameText()
Returns a pre loaded String[] array of all available java.util.Locale language display names in
the version of JVM.
Obtains a java.time.ZoneId object from the pre loaded array of ZoneId-ID. method input
argument is the index of the element on the array.
Uses static call ZoneId.of(String arrayIdIndexedvalue) to produce a ZoneId object. The String
arrayIdIndexedvalue argument is the name (not display name) of a ZoneId from the qualified
ZoneId names array of this class can be called by method getListedZoneID(int indexZID) or,
and more likely, an "obtained from a set object" qualified String ZoneId name from some other
source.
Creates a java.time.ZoneOffset qualified String name of a ZoneId object value, note that
ZoneOffset class extends ZoneId class.
Returns a pre loaded array of all available locales from this class.
Formats a java.util.Date object to a GMT String. (this method was only added as convenience)
java.lang.String[] getDigitISOTestArray()
This method brings back a single element String of the http header main symbols and
commands utility array.
This method is a documentation printout tool. Brings back a String of "all elements" in the http
commands and symbols array for printing to a page using a servlet.
This method is a documentation printout tool. Brings back a String of "single character symbol
elements initially in the class compiled UTF_8" for printing to a page using a servlet.
java.util.Enumeration getkeysForStoredDateStrings()
Returns an Enumeration object of all the "unique identifier Keys" present in the global storage
HashTable<String,String> array..
java.lang.String getLineCRLF()
Returns a newline character, either a default machine string "newline character" has been set
or the compliment set method of this get method can be used to custom set a "newline
character".
Returns a String element of the two letter Locale national Country code of the pre loaded
Locale array by int index.
java.lang.String[] getListedCountryLocaleCodeArray()
Returns a String[] array of the two letter Locale codes of the pre loaded array of Locale objects.
Gets a String value of the "displayable name" of an element on the pre loaded Locale array.
Returns a String element of the "two letter Locale" language code pre loaded array by int index
argument.
java.lang.String[] getListedLanguageLocaleCodeArray()
Returns a String[] array of the two letter Locale language codes of the pre loaded array of
Locale objects.
java.lang.String getListedLanguageNameText(int indexZID)
Gets the human readable displayable name of the locale language code of the pre loaded
locale array.
Obtains a TimeZone object ID from the pre loaded array of TimeZone ID's.
Gets a ZoneID as a qualified name String reference object from the pre loaded array of ID's
stored in this class.
java.time.Clock getNowUTCclockInstance()
This method returns a HashTable<String,String> element value stored String by access to the
RAMfilingHTTPtools class dates, header-parts, formatted times global String storage array, the
array is created at application startup. The argument passed to the method is a String unique
name to identify the stored item on the HashTable array.
int getStoredDateStringsSize()
Returns the int total quantity of all the elements (pairs) present in the global storage
HashTable<String,String> array.
java.lang.String getTestSpaceToken()
get the test space token that is set for use in the
concatHttpArrayParts(java.lang.String[] http1011CacheHeaderelements) string elements joiner
method.
Printout documentation tool of the TimeZone array indexes and values of TimeZone class
objects (principally its string ID's).
java.lang.String[] getTimeZoneNameTextArray()
Printout documentation tool of the TimeZone array indexes and values of TimeZone class
objects (principally its string DISPLAY NAMES).
Before obtaining any text array from the actual JRE API !(not from this class - this class is
loaded in default Locale)
The time and zone java api classes do have methods to input locale onto displayable text
objects and translate , aside the fact these arrays are loaded in default locale.
It is possible to change locale on the "text display names index" array call from the JRE
binaries itself and obtain DISPLAY NAMES IN THERE OWN "script" and "language
(translation)"
However, do not forget that to render these the User Agent will require both a suitable charset
and font to display them and too the correct HTML element lang= attributes.
java.lang.String getTimeZoneNameTextIndex(int indexZID)
Get a display name from the TimeZone array by its index as a String array element.
UAhttpCookie getUAClientCookieManager()
Obtains the interface for the UserAgent Cookie Manager class , for storage and
construction of HTTP cookies as a special "cookie object class" and cookie templates as
a cookie class.
Gets a fully qualified ZoneId human readable string display name from the pre loaded array by
int index.
java.lang.String[] getZoneIDNameTextArray()
Gets the complete pre loaded array of human readable string display names.
Print out tool. Print out of pre loaded ZoneId array elements "representations".
Grabs the time from the system clock and directly creates a java.time.OffsetZonedTime object
of it in the ZoneId argument TimeZone.
java.time.ZonedDateTime nowZoneDateTime()
Grabs the time from the system clock and directly creates a java.time.ZonedDateTime object
of it.
Grabs the time from the system clock and directly creates a java.time.ZonedDateTime object
of it adjusting it to the basic zone time supplied by the ZoneId argument.
java.lang.String pingMessageTest()
Returns a String message of version and particulars as output about the RAMfilingHTTPtools
class object for test and debug purpose.
java.lang.String printLocalesCountryCalendar()
Printout tool for the pre loaded Locale[] array, it prints ... [ index on the array ] [ two letter
language code ] [ two letter country code ] [ display name ]
Removes a HashTable pre-set element <String,String> key value pair from storage on the
RAMfilingHTTPtools class dates, header-parts, formatted times global String storage array.
Sets a character token other than a text space (text break space) for use as alternative to a
leading space character when recognizing input argument String literals that are input to
concatHttpArrayParts(java.lang.String[] http1011CacheHeaderelements)
Matches an input variable to the value of a TimeZone ID on the pre loaded array of time zone
ID's.
returns -1 if no match is made.
Matches an input Locale object variable to the value of a two letter Locale "country code" on
the pre loaded array of Locale[] objects.
returns -1 if no match is made.
Matches an input Locale object variable to the value of a two letter Locale "language code" on
the pre loaded array of Locale[] objects.
returns -1 if no match is made.
Uses the system clock instant to obtain and adjust the current time to another zone and return
it as a Clock object.
Method Detail
urlDeCoder
urlCoder
urlDeCoder
urlCoder
getFormattedCookieDate
getUAClientCookieManager
UAhttpCookie getUAClientCookieManager()
getStoredDateString
putStoredDateString
replaceStoredDateString
removeStoredDateString
getkeysForStoredDateStrings
java.util.Enumeration getkeysForStoredDateStrings()
Returns an Enumeration object of all the "unique identifier Keys" present in the global storage HashTable<String,String> array.
(note that there is a good idea to prefix your keys with a character symbol as the first character (alike a geographic map "Legend
symbol") to denote their purpose to clearly identify and check that the correct type of information is being obtained when the get
method draws information from the array)
getStoredDateStringsSize
int getStoredDateStringsSize()
Returns the int total quantity of all the elements (pairs) present in the global storage HashTable<String,String> array.
isStoredDateStringKeyNamePresent
printLocalesCountryCalendar
java.lang.String printLocalesCountryCalendar()
Printout tool for the pre loaded Locale[] array, it prints ... [ index on the array ] [ two letter language code ] [ two letter country
code ] [ display name ]
A number of parameters make a complete locale object, the two main parameters are "Language" and "Country". These are
displayed in English with their Locale object array index.
This array of Locales is created in the constructor of the org.apache.catalina.core.RAMfilingHTTPtools class, using a Calendar
object. The Array of this printout may vary depending the "explicit" JVM runtime "versio"n used.
Also note that this is stored by the API as an array in its origin not a Set or Map or List or any other Enumeration type.
getCalendarLocalesArray
getNowUTCclockInstance
java.time.Clock getNowUTCclockInstance()
Returns a UTC clock with the time set at this instant moment of call.
zoneInstantClock
getzonedClockinstant
getzonedDateFormatted
ZmethodCall The Date and Time information object to extract data from to format to a view
pattern, Pattern template to show each section and symbol in the Date and Time
lcal Locale to format the String to
getzonedDateRFC1123format
getlocalDateRFC1123format
getlocalDateANSIformat
nowOffsetZonedTime
getzonedDateUTCformat
getCalendar
getInstantFromCalendar
getListedTimeZoneID
getTimeZoneIdPrintOut
getAsZoneIDListed
getZoneIDListedNameText
getZoneIDNameTextArray
java.lang.String[] getZoneIDNameTextArray()
Gets the complete pre loaded array of human readable string display names.
getListedCountryLocaleCodeArray
java.lang.String[] getListedCountryLocaleCodeArray()
Gets the complete pre loaded array of human readable string Locale object "national country codes".
getListedCountryLocaleCode
getListedCountryNameText
getAllCountryNameText
java.lang.String[] getAllCountryNameText()
Gets the complete pre loaded array[] of human readable string Locale object "national country NAMES".
getListedLanguageLocaleCodeArray
java.lang.String[] getListedLanguageLocaleCodeArray()
Gets the complete pre loaded array[] of language codes.
getListedLanguageLocaleCode
getListedLanguageNameText
java.lang.String[] getAllLanguageNameText()
Returns an array of all Language names from each locale.
getZoneIdPrintOut
nowZoneDateTime
java.time.ZonedDateTime nowZoneDateTime()
Gets a java.time.ZonedDateTime directly from the system clock at that moment.
nowZoneDateTime
getTimeZoneNameTextArray
java.lang.String[] getTimeZoneNameTextArray()
Gets the Pre loaded array[] of TimeZone object displayable names.
(There is a minor difference between a TimeZone and ZoneId)
getTimeZoneNameTextIndex
constructTimeZone
constructTimeZone
getaZoneId
getaZoneId
getaZoneOffset
java.time.ZoneOffset getaZoneOffset(java.lang.String zoffoZId)
getaZoneOffset
getaOffSetDateTime
getaTimeQuantity
getaWeekQuantity
periodToTemporalAmount
obtainHeaderDate
getCreatedGMTDate
plusTimeDays
plusTimeWeeks
plusTimeMonths
minusTimeDays
minusTimeWeeks
minusTimeMonths
testZoneIdMatch
testIndexIDTimeZoneMatch
testIndexLocaleCountryCodeMatch
testIndexLocaleLanguageMatch
int testIndexLocaleLanguageMatch(java.util.Locale lolang)
Find the Pre loaded Locale objects' "index" for "Language letter code" that matches the input argument Locale object to test.
If this method is successful the pre loaded array index number in this class will be returned.
If it cannot find a match then -1 is returned.
setTestSpaceToken
getTestSpaceToken
java.lang.String getTestSpaceToken()
Retrieve the test space token that is set for use in the concatHttpArrayParts(java.lang.String[] http1011CacheHeaderelements)
string elements joiner method.
setLineCRLF
getLineCRLF
java.lang.String getLineCRLF()
Retrieves a newline character, either a default machine string "newline character" has been set or the compliment set method of
this get method can be used to custom set a "newline character".
setDigitISOTestArray
getDigitISOTestArray
java.lang.String[] getDigitISOTestArray()
returns the numbers with 0 through to inclusive 9 that are used to test the String text numbers written elements of the String[]
array argument to method concatHttpArrayParts(java.lang.String[] http1011CacheHeaderelements)
This array can be replaced with a String[] array of a different ISO character set and be persistent throughout the life-cycle of the
application that loaded this class.
concatHttpArrayParts
Note: by default the leading left single character to represent a literal not an array index number, is a " " single space (break
space)
1. it will be treated as a String LITERAL,
2. The leading space on the left of the String entry will be stripped off by one single character (the String "array
element literal" beginning denotation, the space token getTestSpaceToken())( SEE methods getTestSpaceToken()
setTestSpaceToken(String) setDigitISOTestArray(String[]) ) (if there are more spaces they will remain as part of the
String literal e.g. if you want a space to lead on the literal it requires two spaces because one will be removed to
recognose the element is not for conversion to digit but an insert in sequence)
3. Any digits within the String index array entry with a leading space character are text symbols and not processed.
int indexes (as String digits) for purpose are written in the sequence of desired joint together one after the other, into the method
input argument String literals array, they then are placed as an String[] array into the input argument to be converted to int.
*Although a space on the left of the input string element argument is required to denote the element to be a string
literal, this token character (the space) can be changed by setting it to another character for use to denote the
element as a literal.
See getTestSpaceToken() and setTestSpaceToken(java.lang.String spaceSymbolChar)
concatHttpArrayParts
getHttpPartsArrayElement
getHttpPartsFullArrayLegend
getHttpPartsSymbolArrayLegend
reEncodechars
java.lang.String reEncodechars(java.util.Locale locum,
java.lang.String headerOrigin,
java.lang.String charsetInputName,
java.lang.String charsetnameto)
locum The Locale object that represents the Country and Language symbols the string is to be converted "to" (or "is" if it is
inside a different language and locale ISO charset subset as origin)
charsetInputName The string "input ISO name" that is to be converted
headerOrigin The input string to be converted
charsetnameto The name or alias of a charset to convert to
(note: "This method may need to be called twice for proper conversion to occur", with the first call to a more common language
ISO of its original language ISO that recognises ASCII characters more commonly for its purpose as an intermediate language,
then from that language to the english. SEE above page introduction for an example)
This method is for "International Web ISO charsets" to change and make use of Strings that are encoded in english in the RAM
file object or server or other programs, it is intended to help "clean" the strings to another ISO such as input file-name list for
loading if ever required. Hopwever, it must be instigated manually.
To use it will require an understnding of code pages and ISO charset alias.
Defined for Java here:
https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
Many foreign language servers have an ISO charset apart UTF_8 or UTF_16 or variants of these that carry a subset of US_ASCII
for the various web server additives such as javascript. One example of this is simplified Chinese "GB2312" , in essence Chinese
language characters but a normal English ascii string will be less troublesome carried in the "GB2312" although it is numerically
identical in its byte value.
"GB18030" is a PRC Chinese version that carries ASCII subset of english but does not convert well, so a middle hop into
"GB2312" first then re encoded into UTF_8 or ISO_8859_1 English locale format.
See also java.nio.charset.StandardCharsets and the java.util.Locale static variables for countries (ISO 636)
https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html
https://www.oracle.com/technical-resources/articles/javase/locale.html
pingMessageTest
java.lang.String pingMessageTest()
Should contain details such as Version , date compiled, OS Platform compiled on , JDK level used for compile, and any changes
from previous versions
All in all a debug ping message to understand if it is operative without triggering any dangerous mechanisms.