Package org.eclipse.rdf4j.rio.languages
Class BCP47LanguageHandler
java.lang.Object
org.eclipse.rdf4j.rio.languages.BCP47LanguageHandler
- All Implemented Interfaces:
LanguageHandler
A language handler that can verify BCP47 formatted language tags.
This language handler normalises language tags to lower-case if
normalizeLanguage(String, String, ValueFactory)
is used.
- Author:
- Peter Ansell
- See Also:
- BCP47
-
Field Summary
Fields inherited from interface org.eclipse.rdf4j.rio.LanguageHandler
BCP47, RFC3066, RFC4646
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetKey()
A unique key for this language handler to identify it in the LanguageHandlerRegistry.boolean
isRecognizedLanguage(String languageTag)
Checks if the given language tag is recognized by this language handler, including cases where the language tag is recognized, but is not yet normalized.normalizeLanguage(String literalValue, String languageTag, ValueFactory valueFactory)
Normalize both the language tag and the language if appropriate, and use the given value factory to generate a literal matching the literal value and language tag.boolean
verifyLanguage(String literalValue, String languageTag)
Verifies that the language tag is valid, optionally including an automated check on the literal value.
-
Constructor Details
-
BCP47LanguageHandler
public BCP47LanguageHandler()Default constructor.
-
-
Method Details
-
isRecognizedLanguage
Description copied from interface:LanguageHandler
Checks if the given language tag is recognized by this language handler, including cases where the language tag is recognized, but is not yet normalized.- Specified by:
isRecognizedLanguage
in interfaceLanguageHandler
- Parameters:
languageTag
- The language tag to check.- Returns:
- True if the language tag is syntactically valid and could be used with
LanguageHandler.verifyLanguage(String, String)
andLanguageHandler.normalizeLanguage(String, String, ValueFactory)
.
-
verifyLanguage
Description copied from interface:LanguageHandler
Verifies that the language tag is valid, optionally including an automated check on the literal value.This method must only be called after verifying that
LanguageHandler.isRecognizedLanguage(String)
returns true for the given language tag.- Specified by:
verifyLanguage
in interfaceLanguageHandler
- Parameters:
literalValue
- Literal value matching the given language tag.languageTag
- A language tag that matched withLanguageHandler.isRecognizedLanguage(String)
.- Returns:
- True if the language tag is recognized by this language handler, and it is verified to be syntactically valid.
- Throws:
LiteralUtilException
- If the language tag was not recognized.
-
normalizeLanguage
public Literal normalizeLanguage(String literalValue, String languageTag, ValueFactory valueFactory) throws LiteralUtilExceptionDescription copied from interface:LanguageHandler
Normalize both the language tag and the language if appropriate, and use the given value factory to generate a literal matching the literal value and language tag.This method must only be called after verifying that
LanguageHandler.isRecognizedLanguage(String)
returns true for the given language tag, andLanguageHandler.verifyLanguage(String, String)
also returns true for the given language and literal value.- Specified by:
normalizeLanguage
in interfaceLanguageHandler
- Parameters:
literalValue
- Required literal value to use in the normalization process and to provide the value for the resulting literal.languageTag
- The language tag which is to be normalized. This tag is available in normalized form from the result usingLiteral.getLanguage()
.valueFactory
- TheValueFactory
to use to create the result literal.- Returns:
- A
Literal
containing the normalized literal value and language tag. - Throws:
LiteralUtilException
- If the language tag was not recognized or verified, or the literal value could not be normalized due to an error.
-
getKey
Description copied from interface:LanguageHandler
A unique key for this language handler to identify it in the LanguageHandlerRegistry.- Specified by:
getKey
in interfaceLanguageHandler
- Returns:
- A unique string key.
-