public class I18nTextResourceHandler extends AbstractResourceHandler implements Component
I18nizableText
with x and try to translate it. Modifier and Type | Field and Description |
---|---|
private static char[] |
__I18N_BEGINNING_CHARS
The beginning of a valid declaration for an internationalizable text as characters
|
private static String |
__I18N_DEFAULT_CATALOGUE_ID
This configuration parameter specifies the id of the catalogue to be used as
default catalogue, allowing to redefine the default catalogue on the pipeline
level.
|
private static String |
__I18N_LOCALE |
private static Pattern |
__LOCALE_PATTERN |
private I18nUtils |
_i18nUtils
Avalon component gathering utility methods concerning
I18nizableText , allowing their translation in several languages |
private boolean |
_isDeclarationValid
Is the last analyzed i18n declaration valid ?
|
_cocoonContext, _context, _resolver, _supportedSuffixes
MAX_PRIORITY, MIN_PRIORITY
Constructor and Description |
---|
I18nTextResourceHandler() |
Modifier and Type | Method and Description |
---|---|
private int |
_analyzeI18nDeclaration(char[] srcChars,
int candidateBeginIdx,
BufferedWriter outWriter,
int initialOffset,
Source source,
Parameters par,
Map<String,Object> additionalParameters)
Analyze characters from the key beginning index to the possible closure sequence '}}',
and write the appropriate replacement in the output string builder
|
private boolean |
_testI18nDeclarationPrefix(char[] srcChars,
int start)
Test if the given character is the start of an i18n declaration
|
private void |
_translateKey(char[] srcChars,
BufferedWriter outWriter,
int candidateBeginIdx,
int lastIdx,
int initialOffset,
String locale,
Parameters par)
Try to translate the key and write the output stream with its translation if found, the key itself if not
|
void |
generateResource(Source source,
OutputStream out,
Map objectModel,
Parameters par,
Map<String,Object> additionalParameters)
Generate the resource configured during setup, and output it
|
Serializable |
getKey(Source source,
Map objectModel,
Parameters parameters,
Map<String,Object> additionalParameters)
Get the unique key for this resource, for cache purpose.
|
protected String |
getLocale(Map<String,Object> additionalParameters)
Retrieve the locale from the parameters
|
void |
service(ServiceManager serviceManager) |
Source |
setup(String location,
Map objectModel,
Parameters par,
Map<String,Object> additionalParameters)
Initialize the resource handler with a resource.
|
configure, contextualize, getLastModified, getMimeType, getPriority, getSize, getValidity, isSupported
getLogger, setLogger
private static final String __I18N_DEFAULT_CATALOGUE_ID
private static final String __I18N_LOCALE
private static final char[] __I18N_BEGINNING_CHARS
private static final Pattern __LOCALE_PATTERN
private I18nUtils _i18nUtils
I18nizableText
, allowing their translation in several languagesprivate boolean _isDeclarationValid
public I18nTextResourceHandler()
public void service(ServiceManager serviceManager) throws ServiceException
service
in interface Serviceable
service
in class AbstractResourceHandler
ServiceException
public Source setup(String location, Map objectModel, Parameters par, Map<String,Object> additionalParameters) throws ProcessingException, IOException
ResourceHandler
setup
in interface ResourceHandler
setup
in class AbstractResourceHandler
location
- The source uriobjectModel
- The object modelpar
- The parametersadditionalParameters
- Additional parameters that can be filled, and will be transmitted to getKey, getValidity and generateResourceProcessingException
- If an error occursIOException
- If an error occursprotected String getLocale(Map<String,Object> additionalParameters)
additionalParameters
- The parameterspublic void generateResource(Source source, OutputStream out, Map objectModel, Parameters par, Map<String,Object> additionalParameters) throws IOException, ProcessingException
ResourceHandler
generateResource
in interface ResourceHandler
source
- The sourceout
- The output stream to write toobjectModel
- The object modelpar
- The sitemap parametersadditionalParameters
- Additional parametersIOException
- If an error occursProcessingException
- If an error occursprivate boolean _testI18nDeclarationPrefix(char[] srcChars, int start)
srcChars
- the input file as charactersstart
- the index of the given characterprivate int _analyzeI18nDeclaration(char[] srcChars, int candidateBeginIdx, BufferedWriter outWriter, int initialOffset, Source source, Parameters par, Map<String,Object> additionalParameters) throws IOException
srcChars
- the input file as characterscandidateBeginIdx
- the index at which we started analyzing a viable i18n declarationoutWriter
- the buffered writer where we store the output stringinitialOffset
- the initial offsetsource
- The source using the i18npar
- The declaration parametersadditionalParameters
- The additional parametersIOException
- if an error occurs while writing the outputprivate void _translateKey(char[] srcChars, BufferedWriter outWriter, int candidateBeginIdx, int lastIdx, int initialOffset, String locale, Parameters par) throws IOException
srcChars
- the input source as charactersoutWriter
- the string builder where to writecandidateBeginIdx
- the index at which the i18n declaration startedlastIdx
- the last index analyzedinitialOffset
- the amount of characters that we have to write before the i18n declarationlocale
- The locale to usepar
- The declaration parametersIOException
- if an error occurs while writing the outputpublic Serializable getKey(Source source, Map objectModel, Parameters parameters, Map<String,Object> additionalParameters)
ResourceHandler
getKey
in interface ResourceHandler
getKey
in class AbstractResourceHandler
source
- The sourceobjectModel
- The object modelparameters
- The parametersadditionalParameters
- Additional parameters