Class SpoofedTextContentReader
- java.lang.Object
-
- org.alfresco.repo.content.AbstractContentAccessor
-
- org.alfresco.repo.content.AbstractContentReader
-
- org.alfresco.repo.content.filestore.SpoofedTextContentReader
-
- All Implemented Interfaces:
org.alfresco.service.cmr.repository.ContentAccessor,org.alfresco.service.cmr.repository.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 java.lang.StringKEY_LOCALEstatic java.lang.StringKEY_SEEDstatic java.lang.StringKEY_SIZEstatic java.lang.StringKEY_WORDSstatic java.lang.StringLEXICON_STEM_PATH
-
Constructor Summary
Constructors Constructor Description SpoofedTextContentReader(java.lang.String url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcreateContentUrl(java.util.Locale locale, long seed, long size, java.lang.String... words)Helper to create a content URL that represents spoofed textprotected org.alfresco.service.cmr.repository.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 java.nio.channels.ReadableByteChannelgetDirectReadableChannel()Provides low-level access to read content from the repository.longgetLastModified()longgetSeed()longgetSize()org.alfresco.textgen.TextGeneratorgetTextGenerator()static org.alfresco.textgen.TextGeneratorgetTextGenerator(java.util.Locale locale)Get a text generator for the given localejava.lang.String[]getWords()protected voidsetContentUrl(java.lang.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
-
-
-
-
Field Detail
-
LEXICON_STEM_PATH
public static final java.lang.String LEXICON_STEM_PATH
- See Also:
- Constant Field Values
-
KEY_LOCALE
public static final java.lang.String KEY_LOCALE
- See Also:
- Constant Field Values
-
KEY_SEED
public static final java.lang.String KEY_SEED
- See Also:
- Constant Field Values
-
KEY_SIZE
public static final java.lang.String KEY_SIZE
- See Also:
- Constant Field Values
-
KEY_WORDS
public static final java.lang.String KEY_WORDS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTextGenerator
public static org.alfresco.textgen.TextGenerator getTextGenerator(java.util.Locale locale)
Get a text generator for the given locale- Throws:
java.lang.RuntimeException- if the locale has no lexicon exists for the locale
-
createContentUrl
public static java.lang.String createContentUrl(java.util.Locale locale, long seed, long size, java.lang.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:
java.lang.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 java.lang.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 org.alfresco.service.cmr.repository.ContentReader createReader() throws org.alfresco.service.cmr.repository.ContentIOExceptionThe 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:
org.alfresco.service.cmr.repository.ContentIOException
-
getDirectReadableChannel
protected java.nio.channels.ReadableByteChannel getDirectReadableChannel() throws org.alfresco.service.cmr.repository.ContentIOExceptionDescription 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:
org.alfresco.service.cmr.repository.ContentIOException- if the channel could not be opened or the underlying content has disappeared
-
setContentUrl
protected final void setContentUrl(java.lang.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
-
-