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)
Analyze characters from the key beginning index to the possible closure sequence '}}',
and write the appropriate replacement in the output string builder
|
private String |
_getLocale(Parameters par) |
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,
Parameters par)
Generate the resource configured during setup, and output it
|
Serializable |
getKey(Source source,
Parameters par)
Get the unique key for this resource, for cache purpose.
|
String |
getMimeType(Source source,
Parameters par)
Return the mime type of the configured resource.
|
void |
service(ServiceManager serviceManager) |
Source |
setup(String location,
Parameters par)
Initialize the resource handler with a resource.
|
configure, contextualize, getLastModified, 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, Parameters par) throws ProcessingException, IOException
ResourceHandler
setup
in interface ResourceHandler
setup
in class AbstractResourceHandler
location
- The source uripar
- The parametersProcessingException
- If an error occursIOException
- If an error occursprivate String _getLocale(Parameters par)
public void generateResource(Source source, OutputStream out, Parameters par) throws IOException, ProcessingException
ResourceHandler
generateResource
in interface ResourceHandler
source
- The sourceout
- The output stream to write topar
- The 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) 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 parameters (to get locale)IOException
- 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, Parameters par)
ResourceHandler
getKey
in interface ResourceHandler
getKey
in class AbstractResourceHandler
source
- The sourcepar
- The parameterspublic String getMimeType(Source source, Parameters par)
ResourceHandler
getMimeType
in interface ResourceHandler
getMimeType
in class AbstractResourceHandler
source
- The sourcepar
- The parameters