Class 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
    • Constructor Detail

      • SpoofedTextContentReader

        public SpoofedTextContentReader​(java.lang.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​(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 text
        size - the size (bytes) of the text to generate
        words - 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.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:
        createReader in class AbstractContentReader
        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.ContentIOException
        Description copied from class: AbstractContentReader
        Provides 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:
        getDirectReadableChannel in class AbstractContentReader
        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: AbstractContentAccessor
        Allow derived implementations to set the Content URL. This allows for implementations where the URL is not known when the accessor is first constructed.
        Overrides:
        setContentUrl in class AbstractContentAccessor
        Parameters:
        contentUrl - the new content URL