Class SpoofedTextContentReader
- java.lang.Object
-
- org.alfresco.repo.content.AbstractContentAccessor
-
- org.alfresco.repo.content.AbstractContentReader
-
- org.alfresco.repo.content.filestore.SpoofedTextContentReader
-
- All Implemented Interfaces:
ContentAccessor,ContentReader
public class SpoofedTextContentReader extends AbstractContentReader
Provides access to text data that is generated when requested. The URL has the format: spoofed://{locale=en_GB,seed=12345,length=1024,strings=["Alfresco", "Cloud"]} The lexicon for the given locale is found by taking the language part of the locale (en in en_GB) and finding the resource alfresco/textgen/lexicon-stem-en.txt.- Since:
- 5.1
- Author:
- Derek Hulley
- See Also:
TextGenerator
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_LOCALEstatic StringKEY_SEEDstatic StringKEY_SIZEstatic StringKEY_WORDSstatic StringLEXICON_STEM_PATH
-
Constructor Summary
Constructors Constructor Description SpoofedTextContentReader(String url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringcreateContentUrl(Locale locale, long seed, long size, String... words)Helper to create a content URL that represents spoofed textprotected ContentReadercreateReader()The URL of the write is known from the start and this method contract states that no consideration needs to be taken w.r.t.booleanexists()protected ReadableByteChannelgetDirectReadableChannel()Provides low-level access to read content from the repository.longgetLastModified()longgetSeed()longgetSize()org.alfresco.textgen.TextGeneratorgetTextGenerator()static org.alfresco.textgen.TextGeneratorgetTextGenerator(Locale locale)Get a text generator for the given localeString[]getWords()protected voidsetContentUrl(String contentUrl)Allow derived implementations to set the Content URL.-
Methods inherited from class org.alfresco.repo.content.AbstractContentReader
addListener, compareContentReaders, getContent, getContent, getContentInputStream, getContentString, getContentString, getFileChannel, getLimits, getReadableChannel, getReader, getTransformerDebug, getUseBufferedInputStream, isChannelOpen, isClosed, setLimits, setTransformerDebug, setUseBufferedInputStream
-
Methods inherited from class org.alfresco.repo.content.AbstractContentAccessor
channelOpened, finalize, getCallbackFileChannel, getContentData, getContentUrl, getEncoding, getLocale, getMimetype, setEncoding, setLocale, setMimetype, toString
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.alfresco.service.cmr.repository.ContentAccessor
getContentData, getContentUrl, getEncoding, getLocale, getMimetype, setEncoding, setLocale, setMimetype
-
-
-
-
Field Detail
-
LEXICON_STEM_PATH
public static final String LEXICON_STEM_PATH
- See Also:
- Constant Field Values
-
KEY_LOCALE
public static final String KEY_LOCALE
- See Also:
- Constant Field Values
-
KEY_SEED
public static final String KEY_SEED
- See Also:
- Constant Field Values
-
KEY_SIZE
public static final String KEY_SIZE
- See Also:
- Constant Field Values
-
KEY_WORDS
public static final String KEY_WORDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SpoofedTextContentReader
public SpoofedTextContentReader(String url)
- Parameters:
url- a URL describing the type of text to produce (see class comments)
-
-
Method Detail
-
getTextGenerator
public static org.alfresco.textgen.TextGenerator getTextGenerator(Locale locale)
Get a text generator for the given locale- Throws:
RuntimeException- if the locale has no lexicon exists for the locale
-
createContentUrl
public static String createContentUrl(Locale locale, long seed, long size, String... words)
Helper to create a content URL that represents spoofed text- Parameters:
locale- the text local (must be supported by an appropriate lexicon config resource)seed- numerical seed to ensure repeatable sequences of random textsize- the size (bytes) of the text to generatewords- additional words with decreasing frequency- Returns:
- the content URL
- Throws:
IllegalArgumentException- if the resulting URL exceeds 255 characters
-
exists
public boolean exists()
- Returns:
- true always
-
getTextGenerator
public org.alfresco.textgen.TextGenerator getTextGenerator()
- Returns:
- the text generator that will make the spoofed text
-
getSeed
public long getSeed()
- Returns:
- the random seed for the spoofed text
-
getWords
public String[] getWords()
- Returns:
- the words to add to the spoofed text
-
getSize
public long getSize()
- Returns:
- spoofed text size
-
getLastModified
public long getLastModified()
- See Also:
File.lastModified()
-
createReader
protected ContentReader createReader() throws ContentIOException
The URL of the write is known from the start and this method contract states that no consideration needs to be taken w.r.t. the stream state.- Specified by:
createReaderin classAbstractContentReader- Returns:
- Returns a reader onto the location referenced by this instance. The instance must always be a new instance.
- Throws:
ContentIOException
-
getDirectReadableChannel
protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException
Description copied from class:AbstractContentReaderProvides low-level access to read content from the repository.This is the only of the content reading methods that needs to be implemented by derived classes. All other content access methods make use of this in their underlying implementations.
- Specified by:
getDirectReadableChannelin classAbstractContentReader- Returns:
- Returns a channel from which content can be read
- Throws:
ContentIOException- if the channel could not be opened or the underlying content has disappeared
-
setContentUrl
protected final void setContentUrl(String contentUrl)
Description copied from class:AbstractContentAccessorAllow derived implementations to set the Content URL. This allows for implementations where the URL is not known when the accessor is first constructed.- Overrides:
setContentUrlin classAbstractContentAccessor- Parameters:
contentUrl- the new content URL
-
-