Package com.globalmentor.net
Class ResourceRecord
java.lang.Object
com.globalmentor.net.ResourceRecord
Encapsulation of information that appears in the resource record of a DNS zone file.
- Author:
- Garret Wilson
- API Note:
- This is an entity type, not a value type. In particular equality is not defined based upon the contents of the record.
- Implementation Specification:
- This implementation does not support raw
TXT
records that begin and end with double-quote characters as if they were quoted. It is likely such values do not exist in real-world scenarios,, This implementation does not handle escaped characters other than '\"' and '\\'. as quoted strings as per RFC 1035 indicate escaping. - See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Common, known resource record types. -
Field Summary
Modifier and TypeFieldDescriptionstatic final char
The character for escaping a quote character in a string designated as acharacter-string
in RFC 1035.static final char
The character for quoting a string designated as acharacter-string
in RFC 1035 containing spaces. -
Constructor Summary
ConstructorDescriptionResourceRecord
(ResourceRecord.Type type, DomainName name, String value, long ttl) Constructor using a known type.ResourceRecord
(String type, DomainName name, String value, long ttl) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
decodeCharactString
(String characterString) Decodes a resource record string designated as acharacter-string
in RFC 1035 if it is quoted.static boolean
detectCharacterStringEncoded
(String string) Attempts to determine whether a string designated as acharacter-string
in RFC 1035 is already encoded (quoted) as per RFC 1035.static String
encodeCharacterString
(String string) Encodes (quotes) a resource record string designated as acharacter-string
in RFC 1035.static String
encodeCharacterString
(String string, boolean alwaysQuote) Encodes (quotes) a resource record string designated as acharacter-string
in RFC 1035.getName()
getTtl()
getType()
getValue()
static String
normalizeCharacterString
(String string) Encodes (quotes) as needed a resource record string designated as acharacter-string
in RFC 1035.static String
normalizeCharacterString
(String string, boolean alwaysQuote) Encodes (quotes) as needed a resource record string designated as acharacter-string
in RFC 1035.toString()
-
Field Details
-
CHARACTER_STRING_QUOTE_CHAR
public static final char CHARACTER_STRING_QUOTE_CHARThe character for quoting a string designated as acharacter-string
in RFC 1035 containing spaces.- See Also:
-
CHARACTER_STRING_ESCAPE_CHAR
public static final char CHARACTER_STRING_ESCAPE_CHARThe character for escaping a quote character in a string designated as acharacter-string
in RFC 1035.- See Also:
-
-
Constructor Details
-
ResourceRecord
public ResourceRecord(@Nonnull ResourceRecord.Type type, @Nullable DomainName name, @Nonnull String value, @Nonnegative long ttl) Constructor using a known type.- API Note:
- The given value must be in its unencoded form. If storing use-entered information, it may be desirable to call
decodeCharactString(String)
on the value first. - Parameters:
type
- The type of resource record.name
- The domain name of the resource record, which may be absolute or relative if the name should be resolved against the origin; ornull
to indicate the origin should be used.value
- The value to store in the resource record, encoded as a appropriate for the resource record type.ttl
- The resource record cache time to live, in seconds; or-1
if not specified, indicating the default TTL should be used.- Throws:
IllegalArgumentException
- if the given TTL is a negative value other than-1
.- See Also:
-
ResourceRecord
public ResourceRecord(@Nonnull String type, @Nullable DomainName name, @Nonnull String value, @Nonnegative long ttl) Constructor.- API Note:
- The given value must be in its unencoded form. If storing use-entered information, it may be desirable to call
decodeCharactString(String)
on the value first. - Parameters:
type
- The type of resource record.name
- The domain name of the resource record, which may be absolute or relative if the name should be resolved against the origin; ornull
to indicate the origin should be used.value
- The value to store in the resource record, encoded as a appropriate for the resource record type.ttl
- The resource record cache time to live, in seconds; or-1
if not specified, indicating the default TTL should be used.- Throws:
IllegalArgumentException
- if the given TTL is a negative value other than-1
.- See Also:
-
-
Method Details
-
getType
- Returns:
- The type of resource record.
-
getName
- Returns:
- The domain name of the resource record, which may be absolute or relative if the name should be resolved against the origin; or empty to indicate the origin should be used.
-
getValue
- Returns:
- The resource record value encoded as a appropriate for the resource record type.
-
getTtl
- Returns:
- The resource record cache time to live, in seconds; or empty if not specified, indicating the default TTL should be used.
-
toString
-
detectCharacterStringEncoded
Attempts to determine whether a string designated as acharacter-string
in RFC 1035 is already encoded (quoted) as per RFC 1035.- API Note:
- Not all string values are "character string" value; this only applies to the values of some types of records in RFC 1035, notably
ResourceRecord.Type.TXT
. - Implementation Note:
- This method has no way of knowing with certainty whether a value is encoded, because a string with surrounding double-quote characters could simply be a string itself needing encoding. However such a situation is very rare and unlikely to be found in practice.
- Parameters:
string
- A "character string" value that may or may not already be encoded.- Returns:
true
if the given "character string" is in quoted, encoded form.- Throws:
IllegalArgumentException
- if the given value is incorrectly encoded, for example starting but not ending with a double quote.- See Also:
-
normalizeCharacterString
Encodes (quotes) as needed a resource record string designated as acharacter-string
in RFC 1035. If the value is detected as already encoded, the string is returned unchanged. Otherwise the string is quoted only as necessary (i.e. if it contains one or more spaces) unless always quoting is requested.- API Note:
- This method may be useful for normalizing an RFC 1035 character string entered by a user.
- Implementation Specification:
- This method delegates to
normalizeCharacterString(String, boolean)
. - Implementation Note:
- This method has no way of knowing with certainty whether a value is encoded, because a string with surrounding double-quote characters could simply be a string itself needing encoding. However such a situation is very rare and unlikely to be found in practice.
- Parameters:
string
- A "character string" value that may or may not already be encoded.- Returns:
- The value encoded as necessary for a "character string".
- See Also:
-
normalizeCharacterString
Encodes (quotes) as needed a resource record string designated as acharacter-string
in RFC 1035. If the value is detected as already encoded, the string is returned unchanged. Otherwise the string is quoted only as necessary (i.e. if it contains one or more spaces).- API Note:
- This method may be useful for normalizing an RFC 1035 character string entered by a user.
- Implementation Note:
- This method has no way of knowing with certainty whether a value is encoded, because a string with surrounding double-quote characters could simply be a string itself needing encoding. However such a situation is very rare and unlikely to be found in practice.
- Parameters:
string
- A "character string" value that may or may not already be encoded.alwaysQuote
-true
if the string should always be quoted, even if it contains no characters that require quoting by RFC 1035.- Returns:
- The value encoded as necessary for a "character string".
- See Also:
-
encodeCharacterString
Encodes (quotes) a resource record string designated as acharacter-string
in RFC 1035. The string is quoted only as necessary (i.e. if it contains one or more spaces).- API Note:
- Calling this method multiple times on a string that needs encoding will result in a string that is multiply-encoded.
- Implementation Specification:
- This method delegates to
encodeCharacterString(String, boolean)
. - Parameters:
string
- A raw, unencoded resource record string value.- Returns:
- The value encoded as necessary for a "character string".
-
encodeCharacterString
Encodes (quotes) a resource record string designated as acharacter-string
in RFC 1035. The string is quoted only as necessary (i.e. if it contains one or more spaces) unless always quoting is requested.- API Note:
- Calling this method multiple times on a string that needs encoding will result in a string that is multiply-encoded.
- Parameters:
string
- A raw, unencoded resource record string value.alwaysQuote
-true
if the string should always be quoted, even if it contains no characters that require quoting by RFC 1035.- Returns:
- The value encoded as necessary for a "character string".
-
decodeCharactString
Decodes a resource record string designated as acharacter-string
in RFC 1035 if it is quoted. If the value is not quoted, the string is returned unchanged.- API Note:
- In theory calling this method multiple times on a string that was doubly quoted would result in different strings; that is, if a quoted string itself had been encoded.
- Parameters:
characterString
- A resource record "character string" value in encoded form, potentially quoted.- Returns:
- The character string decoded as appropriate.
- Throws:
IllegalArgumentException
- if the given value is incorrectly encoded, for example starting but not ending with a double quote.
-