You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2011/05/12 08:25:23 UTC

svn commit: r1102179 - in /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src: main/java/org/apache/chemistry/opencmis/util/content/ main/java/org/apache/chemistry/opencmis/util/repository/ test/ test/java/ test/java/org/...

Author: jens
Date: Thu May 12 06:25:22 2011
New Revision: 1102179

URL: http://svn.apache.org/viewvc?rev=1102179&view=rev
Log:
add Lorem Ipsum generator [CMIS-377]

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/LoreIpsum.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/LoreIpsumTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/HaenselUndGretel.txt
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/log4j.properties
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/LoreIpsum.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/LoreIpsum.java?rev=1102179&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/LoreIpsum.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/LoreIpsum.java Thu May 12 06:25:22 2011
@@ -0,0 +1,1158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.util.content;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+/**
+ * A generator of lorem ipsum text ported from the Python implementation at
+ * http://code.google.com/p/lorem-ipsum-generator/. 
+ * Note: original code licensed under the BSD license
+ * 
+ */
+public class LoreIpsum {
+
+    private static class WordLengthPair {
+        public int len1;
+        public int len2;
+
+        public WordLengthPair(int len1, int len2) {
+            this.len1 = len1;
+            this.len2 = len2;
+        }
+
+        public String toString() {
+            return "WordLengthPair: len1: " + len1 + ", len2: " + len2;
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (this == null || other == null)
+                return false;
+            if (other.getClass() != WordLengthPair.class)
+                return false;
+            if (len1 == ((WordLengthPair) other).len1 && len2 == ((WordLengthPair) other).len2)
+                return true;
+            else
+                return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return len1 ^ len2;
+        }
+    }
+
+    /**
+     * Delimiters that end sentences.
+     * 
+     * @type {Array.<string>}
+     * @private
+     */
+    private static final String DELIMITERS_SENTENCES[] = { ".", "?", "!" };
+
+    /**
+     * Regular expression for splitting a text into sentences.
+     * 
+     * @type {RegExp}
+     * @private
+     */
+    private static final String SENTENCE_SPLIT_REGEX = "[\\.\\?\\!]";
+
+    /**
+     * Delimiters that end words.
+     * 
+     * @type {Array.<string>}
+     * @private
+     */
+    private static final String DELIMITERS_WORDS[] = { ".", ",", "?", "!" };
+
+    /**
+     * Regular expression for splitting text into words.
+     * 
+     * @type {RegExp}
+     * @private
+     */
+    private static final String WORD_SPLIT_REGEX = "\\s";
+
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+    /**
+     * Words that can be used in the generated output. Maps a word-length to a
+     * list of words of that length.
+     * 
+     * @type {goog.structs.Map}
+     * @private
+     */
+    private Map<Integer, List<String>> words;
+
+    /**
+     * Chains of three words that appear in the sample text Maps a pair of
+     * word-lengths to a third word-length and an optional piece of trailing
+     * punctuation (for example, a period, comma, etc.).
+     * 
+     * @type {goog.structs.Map}
+     * @private
+     */
+    private Map<WordLengthPair, List<WordInfo>> chains;
+
+    /**
+     * Pairs of word-lengths that can appear at the beginning of sentences.
+     * 
+     * @type {Array}
+     */
+    private List<WordLengthPair> starts;
+
+    /**
+     * Average sentence length in words.
+     * 
+     * @type {number}
+     * @private
+     */
+    private double sentenceMean;
+
+    /**
+     * Sigma (sqrt of Objectiance) for the sentence length in words.
+     * 
+     * @type {number}
+     * @private
+     */
+    private double sentenceSigma;
+
+    /**
+     * Average paragraph length in sentences.
+     * 
+     * @type {number}
+     * @private
+     */
+    private double paragraphMean;
+
+    /**
+     * Sigma (sqrt of variance) for the paragraph length in sentences.
+     * 
+     * @type {number}
+     * @private
+     */
+    private double paragraphSigma;
+
+    /**
+     * Sample that the generated text is based on .
+     * 
+     * @type {string}
+     */
+    private String sample = SAMPLE;
+
+    /**
+     * Dictionary of words.
+     * 
+     * @type {string}
+     */
+    private String dictionary = DICT;
+
+    /**
+     * Picks a random element of the array.
+     * 
+     * @param {Array} array The array to pick from.
+     * @return {*} An element from the array.
+     */
+    private WordInfo randomChoice(WordInfo[] array) {
+        return array[randomInt(array.length)];
+    };
+
+    private String randomChoice(String[] array) {
+        return array[randomInt(array.length)];
+    };
+
+    private int randomInt(int length) {
+        return randomGenerator.nextInt(length);
+    }
+
+    private static class WordInfo {
+        int len;
+        String delim;
+    }
+
+    private Random randomGenerator = new Random();
+
+    /**
+     * Generates random strings of "lorem ipsum" text, based on the word
+     * distribution of a sample text, using the words in a dictionary.
+     * 
+     * @constructor
+     */
+    public LoreIpsum() {
+        generateChains(this.sample);
+        generateStatistics(this.sample);
+        initializeDictionary(this.dictionary);
+    };
+
+    public LoreIpsum(String sample, String dictionary) {
+        this.sample = sample;
+        this.dictionary = dictionary;
+        generateChains(this.sample);
+        generateStatistics(this.sample);
+        initializeDictionary(this.dictionary);
+    };
+
+    public LoreIpsum(String sample, String[] dictionary) {
+        this.sample = sample;
+        this.dictionary = null;
+        generateChains(this.sample);
+        generateStatistics(this.sample);
+        initializeDictionary(dictionary);
+    };
+
+    public LoreIpsum(String sample) {
+        this.sample = sample;
+        String[] dictWords = filterNotEmptyOrWhiteSpace(sample.split("[^\\p{L}]"/* "\\W" */)).toArray(new String[0]);
+        Set<String> dict = new HashSet<String>(Arrays.asList(dictWords));
+        dictWords = dict.toArray(new String[0]);
+        Arrays.sort(dictWords);
+
+        generateChains(this.sample);
+        generateStatistics(this.sample);
+        initializeDictionary(dictWords);
+    };
+
+    /**
+     * Generates a single lorem ipsum paragraph, of random length.
+     * 
+     * @param {boolean} opt_startWithLorem Whether to start the sentence with
+     *        the standard "Lorem ipsum..." first sentence.
+     * @return {string} The generated sentence.
+     */
+    public String generateParagraph(boolean opt_startWithLorem) {
+        // The length of the paragraph is a normally distributed random
+        // Objectiable.
+        Double paragraphLengthDbl = randomNormal(this.paragraphMean, this.paragraphSigma);
+        int paragraphLength = Math.max((int) Math.floor(paragraphLengthDbl), 1);
+
+        // Construct a paragraph from a number of sentences.
+        List<String> paragraph = new ArrayList<String>();
+        boolean startWithLorem = opt_startWithLorem;
+        while (paragraph.size() < paragraphLength) {
+            String sentence = this.generateSentence(startWithLorem);
+            paragraph.add(sentence);
+            startWithLorem = false;
+        }
+
+        StringBuffer result = new StringBuffer();
+        // Form the paragraph into a string.
+        for (String sentence : paragraph) {
+            result.append(sentence);
+            result.append(" ");
+        }
+        return result.toString();
+    }
+
+    /**
+     * Generates a single sentence, of random length.
+     * 
+     * @param {boolean} opt_startWithLorem Whether to start the setnence with
+     *        the standard "Lorem ipsum..." first sentence.
+     * @return {string} The generated sentence.
+     */
+    public String generateSentence(boolean opt_startWithLorem) {
+        if (this.chains.size() == 0 || this.starts.size() == 0) {
+            throw new RuntimeException("No chains created (Invalid sample text?)");
+        }
+
+        if (this.words.size() == 0) {
+            throw new RuntimeException("No dictionary");
+        }
+
+        // The length of the sentence is a normally distributed random
+        // Objectiable.
+        double sentenceLengthDbl = randomNormal(this.sentenceMean, this.sentenceSigma);
+        int sentenceLength = Math.max((int) Math.floor(sentenceLengthDbl), 1);
+
+        String wordDelimiter = ""; // Defined here in case while loop doesn't
+                                   // run
+
+        // Start the sentence with "Lorem ipsum...", if desired
+        List<String> sentence;
+        ;
+        if (opt_startWithLorem) {
+            String lorem = "lorem ipsum dolor sit amet, consecteteur adipiscing elit";
+            sentence = new ArrayList<String>(Arrays.asList(splitWords(lorem)));
+            if (sentence.size() > sentenceLength) {
+                sentence.subList(0, sentenceLength);
+            }
+            String lastWord = sentence.get(sentence.size() - 1);
+            String lastChar = lastWord.substring(lastWord.length() - 1);
+            if (contains(DELIMITERS_WORDS, lastChar)) {
+                wordDelimiter = lastChar;
+            }
+        } else {
+            sentence = new ArrayList<String>();
+        }
+
+        WordLengthPair previous = new WordLengthPair(0, 0);
+
+        // Generate a sentence from the "chains"
+        while (sentence.size() < sentenceLength) {
+            // If the current starting point is invalid, choose another randomly
+            if (!this.chains.containsKey(previous)) {
+                previous = this.chooseRandomStart_();
+            }
+
+            // Choose the next "chain" to go to. This determines the next word
+            // length we use, and whether there is e.g. a comma at the end of
+            // the word.
+            WordInfo chain = randomChoice(this.chains.get(previous).toArray(new WordInfo[0]));
+            int wordLength = chain.len;
+
+            // If the word delimiter contained in the chain is also a sentence
+            // delimiter, then we don"t include it because we don"t want the
+            // sentence to end prematurely (we want the length to match the
+            // sentence_length value).
+            if (contains(DELIMITERS_SENTENCES, chain.delim)) {
+                wordDelimiter = "";
+            } else {
+                wordDelimiter = chain.delim;
+            }
+
+            // Choose a word randomly that matches (or closely matches) the
+            // length we're after.
+            int closestLength = chooseClosest(this.words.keySet().toArray(new Integer[0]), wordLength);
+            String word = randomChoice(this.words.get(closestLength).toArray(new String[0]));
+
+            sentence.add(word + wordDelimiter);
+            previous = new WordLengthPair(previous.len2, wordLength);
+
+        }
+
+        // Finish the sentence off with capitalisation, a period and
+        // form it into a string
+        StringBuffer result = new StringBuffer();
+        for (String s : sentence) {
+            result.append(s);
+            result.append(" ");
+        }
+        result.deleteCharAt(result.length() - 1);
+
+        result.replace(0, 1, result.substring(0, 1).toUpperCase());
+        int strLen = result.length() - 1;
+        if (wordDelimiter.length() > 0 && wordDelimiter.charAt(0) == result.charAt(strLen))
+            result.deleteCharAt(strLen);
+        result.append(".");
+        return result.toString();
+    }
+
+    public String getSample() {
+        return sample;
+    }
+
+    public void setSample(String sample) {
+        this.sample = sample;
+        generateChains(this.sample);
+        generateStatistics(this.sample);
+    }
+
+    public String getDictionary() {
+        return dictionary;
+    }
+
+    public void setDictionary(String dictionary) {
+        this.dictionary = dictionary;
+        initializeDictionary(this.dictionary);
+    }
+
+    /**
+     * Generates multiple paragraphs of text, with begin before the paragraphs,
+     * end after the paragraphs, and between between each two paragraphs.
+     */
+    private String generateMarkupParagraphs(String begin, String end, String between, int quantity,
+            boolean startWithLorem) {
+
+        StringBuffer text = new StringBuffer();
+
+        text.append(begin);
+        String para = generateParagraph(startWithLorem);
+        text.append(para);
+        while (text.length() < quantity) {
+            para = generateParagraph(false);
+            text.append(para);
+            if (text.length() < quantity)
+                text.append(between);
+        }
+
+        text.append(end);
+        return text.toString();
+    }
+    
+    /**
+     * Generates multiple paragraphs of text, with begin before the paragraphs,
+     * end after the paragraphs, and between between each two paragraphs.
+     * @throws IOException 
+     */
+    private void generateMarkupParagraphs(Appendable writer, String begin, String end, String between, int quantity,
+            boolean startWithLorem) throws IOException {
+
+        int len = begin.length();
+        writer.append(begin);
+        String para = generateParagraph(startWithLorem);
+        len += para.length();
+        writer.append(para);
+        while (len < quantity) {
+            para = generateParagraph(false);
+            len += para.length();
+            writer.append(para);
+            if (len < quantity) {
+                writer.append(between);
+                len += para.length();
+            }
+        }
+
+        writer.append(end);
+    }
+    /**
+     * Generates multiple sentences of text, with begin before the sentences,
+     * end after the sentences, and between between each two sentences.
+     */
+    private String generateMarkupSentences(String begin, String end, String between, int quantity,
+            boolean startWithLorem) {
+
+        StringBuffer text = new StringBuffer();
+        text.append(begin);
+        String sentence = generateSentence(startWithLorem);
+        text.append(sentence);
+
+        while (text.length() < quantity) {
+            sentence = generateSentence(false);
+            text.append(sentence);
+            if (text.length() < quantity)
+                text.append(between);
+        }
+
+        text.append(end);
+        return text.toString();
+    }
+
+    /**
+     * Generates the chains and starts values required for sentence generation.
+     * 
+     * @param {string} sample The same text.
+     * @private
+     */
+    private void generateChains(String sample) {
+
+        String[] words = splitWords(sample);
+        WordInfo[] wordInfos = generateWordInfo(words);
+        WordLengthPair previous = new WordLengthPair(0, 0);
+        List<WordLengthPair> starts = new ArrayList<WordLengthPair>();
+        List<String> delimList = Arrays.asList(DELIMITERS_SENTENCES);
+        Map<WordLengthPair, List<WordInfo>> chains = new HashMap<WordLengthPair, List<WordInfo>>();
+
+        for (WordInfo wi : wordInfos) {
+            if (wi.len == 0)
+                continue;
+
+            List<WordInfo> value = chains.get(previous);
+            if (null == value)
+                chains.put(previous, new ArrayList<WordInfo>());
+            else
+                chains.get(previous).add(wi);
+
+            if (delimList.contains(wi.delim))
+                starts.add(previous);
+
+            previous.len1 = previous.len2;
+            previous.len2 = wi.len;
+        }
+
+        if (chains.size() > 0) {
+            this.chains = chains;
+            this.starts = starts;
+        } else {
+            throw new RuntimeException("Invalid sample text.");
+        }
+
+    }
+
+    /**
+     * Calculates the mean and standard deviation of sentence and paragraph
+     * lengths.
+     * 
+     * @param {string} sample The same text.
+     * @private
+     */
+    private void generateStatistics(String sample) {
+        this.generateSentenceStatistics(sample);
+        this.generateParagraphStatistics(sample);
+    }
+
+    /**
+     * Calculates the mean and standard deviation of the lengths of sentences
+     * (in words) in a sample text.
+     * 
+     * @param {string} sample The same text.
+     * @private
+     */
+    private void generateSentenceStatistics(String sample) {
+        List<String> sentences = filterNotEmptyOrWhiteSpace(splitSentences(sample));
+        int sentenceLengths[] = new int[sentences.size()];
+        for (int i = 0; i < sentences.size(); i++) {
+            String[] words = splitWords(sentences.get(i));
+            sentenceLengths[i] = words.length;
+        }
+        this.sentenceMean = mean(sentenceLengths);
+        this.sentenceSigma = sigma(sentenceLengths);
+    }
+
+    /**
+     * Calculates the mean and standard deviation of the lengths of paragraphs
+     * (in sentences) in a sample text.
+     * 
+     * @param {string} sample The same text.
+     * @private
+     */
+    private void generateParagraphStatistics(String sample) {
+        List<String> paragraphs = filterNotEmptyOrWhiteSpace(splitParagraphs(sample));
+
+        int paragraphLengths[] = new int[paragraphs.size()];
+        for (int i = 0; i < paragraphs.size(); i++) {
+            String[] sentences = splitSentences(paragraphs.get(i));
+            paragraphLengths[i] = sentences.length;
+        }
+
+        this.paragraphMean = mean(paragraphLengths);
+        this.paragraphSigma = sigma(paragraphLengths);
+    }
+
+    /**
+     * Sets the generator to use a given selection of words for generating
+     * sentences with.
+     * 
+     * @param {string} dictionary The dictionary to use.
+     */
+    private void initializeDictionary(String dictionary) {
+        String[] dictionaryWords = splitWords(dictionary);
+        initializeDictionary(dictionaryWords);
+    }
+
+    private void initializeDictionary(String[] dictionaryWords) {
+        words = new HashMap<Integer, List<String>>();
+        for (String word : dictionaryWords) {
+            List<String> wordWithLen = words.get(word.length());
+            if (null == wordWithLen) {
+                List<String> list = new ArrayList<String>();
+                list.add(word);
+                words.put(word.length(), list);
+            } else {
+                wordWithLen.add(word);
+            }
+        }
+
+        if (words.size() == 0)
+            throw new RuntimeException("Invalid dictionary.");
+    }
+
+    /**
+     * Picks a random starting chain.
+     * 
+     * @return {string} The starting key.
+     * @private
+     */
+    private WordLengthPair chooseRandomStart_() {
+        Set<WordLengthPair> keys = chains.keySet();
+        Set<WordLengthPair> validStarts = new HashSet<WordLengthPair>(starts);
+        validStarts.retainAll(keys);
+        int index = randomInt(validStarts.size());
+        WordLengthPair wlPair = validStarts.toArray(new WordLengthPair[0])[index];
+        return wlPair;
+    }
+
+    /**
+     * Splits a piece of text into paragraphs.
+     * 
+     * @param {string} text The text to split.
+     * @return {Array.<string>} An array of paragraphs.
+     * @private
+     */
+
+    static String[] splitParagraphs(String text) {
+        return filterNotEmptyOrWhiteSpace(text.split("\n")).toArray(new String[0]);
+    }
+
+    /**
+     * Splits a piece of text into sentences.
+     * 
+     * @param {string} text The text to split.
+     * @return {Array.<string>} An array of sentences.
+     * @private
+     */
+    static String[] splitSentences(String text) {
+        return filterNotEmptyOrWhiteSpace(text.split(SENTENCE_SPLIT_REGEX)).toArray(new String[0]);
+    }
+
+    /**
+     * Splits a piece of text into words..
+     * 
+     * @param {string} text The text to split.
+     * @return {Array.<string>} An array of words.
+     * @private
+     */
+    static String[] splitWords(String text) {
+        return filterNotEmptyOrWhiteSpace(text.split(WORD_SPLIT_REGEX)).toArray(new String[0]);
+    }
+
+    /**
+     * Find the number in the list of values that is closest to the target.
+     * 
+     * @param {Array.<number>} values The values.
+     * @param {number} target The target value.
+     * @return {number} The closest value.
+     */
+    static int chooseClosest(Integer[] values, int target) {
+        int closest = values[0];
+        for (int value : values) {
+            if (Math.abs(target - value) < Math.abs(target - closest))
+                closest = value;
+        }
+
+        return closest;
+    }
+
+    /**
+     * Gets info about a word used as part of the lorem ipsum algorithm.
+     * 
+     * @param {string} word The word to check.
+     * @return {Array} A two element array. The first element is the size of the
+     *         word. The second element is the delimiter used in the word.
+     * @private
+     */
+    static private WordInfo getWordInfo(String word) {
+        WordInfo ret = new WordInfo();
+        for (String delim : DELIMITERS_WORDS) {
+            if (word.endsWith(delim)) {
+                ret.len = word.length() - delim.length();
+                ret.delim = delim;
+                return ret;
+            }
+        }
+        ret.len = word.length();
+        ret.delim = "";
+        return ret;
+    }
+
+    static private WordInfo[] generateWordInfo(String[] words) {
+        WordInfo[] result = new WordInfo[words.length];
+        int i = 0;
+        for (String word : words)
+            result[i++] = getWordInfo(word);
+        return result;
+    }
+
+    /**
+     * Constant used for {@link #randomNormal_}.
+     * 
+     * @type {number}
+     * @private
+     */
+    private static final double NV_MAGICCONST_ = 4 * Math.exp(-0.5) / Math.sqrt(2.0);
+
+    /**
+     * Generates a random number for a normal distribution with the specified
+     * mean and sigma.
+     * 
+     * @param {number} mu The mean of the distribution.
+     * @param {number} sigma The sigma of the distribution.
+     * @private
+     */
+    private static double randomNormal(double mu, double sigma) {
+        double z = 0.0d;
+        while (true) {
+            double u1 = Math.random();
+            double u2 = 1.0d - Math.random();
+            z = NV_MAGICCONST_ * (u1 - 0.5d) / u2;
+            double zz = z * z / 4.0d;
+            if (zz <= -Math.log(u2)) {
+                break;
+            }
+        }
+        return mu + z * sigma;
+    }
+
+    /**
+     * Returns the text if it is not empty or just whitespace.
+     * 
+     * @param {string} text the text to check.
+     * @return {boolean} Whether the text is neither empty nor whitespace.
+     * @private
+     */
+    private static List<String> filterNotEmptyOrWhiteSpace(String[] arr) {
+        List<String> result = new ArrayList<String>();
+        for (String s : arr) {
+            String trims = s.trim();
+            if (trims.length() > 0)
+                result.add(trims);
+        }
+        return result;
+    }
+
+    public static double mean(int[] values) {
+        return ((double) sum(values)) / ((double) (Math.max(values.length, 1)));
+    }
+
+    public static double mean(double[] values) {
+        return sum(values) / ((double) (Math.max(values.length, 1)));
+    }
+
+    public static double variance(double[] values) {
+        double[] squared = new double[values.length];
+        for (int i = 0; i < values.length; i++)
+            squared[i] = values[i] * values[i];
+
+        double meanVal = mean(values);
+        return mean(squared) - (meanVal * meanVal);
+    }
+
+    public static double sigma(int[] values) {
+        double[] d = new double[values.length];
+        for (int i = 0; i < values.length; i++)
+            d[i] = (double) values[i];
+
+        return sigma(d);
+    }
+
+    public static double sigma(double[] values) {
+        return Math.sqrt(variance(values));
+    }
+
+    public static int sum(int[] values) {
+        int sum = 0;
+        for (int val : values)
+            sum += val;
+        return sum;
+    }
+
+    public static double sum(double[] values) {
+        double sum = 0.0d;
+        for (double val : values)
+            sum += val;
+        return sum;
+    }
+
+    public static boolean contains(String[] array, String val) {
+        for (String s : array)
+            if (s.equals(val))
+                return true;
+        return false;
+    }
+
+    /* for unit testing */
+    double getSentenceMean() {
+        return sentenceMean;
+    }
+
+    double getSentenceSigma() {
+        return sentenceSigma;
+    }
+
+    double getParagraphMean() {
+        return paragraphMean;
+    }
+
+    double getParagraphSigma() {
+        return paragraphSigma;
+    }
+
+    /**
+     * Dictionary of words for lorem ipsum.
+     * 
+     * @type {string}
+     * @private
+     */
+    private static final String DICT = "a ac accumsan ad adipiscing aenean aliquam aliquet amet ante "
+            + "aptent arcu at auctor augue bibendum blandit class commodo "
+            + "condimentum congue consectetuer consequat conubia convallis cras "
+            + "cubilia cum curabitur curae cursus dapibus diam dictum dictumst "
+            + "dignissim dis dolor donec dui duis egestas eget eleifend elementum "
+            + "elit eni enim erat eros est et etiam eu euismod facilisi facilisis "
+            + "fames faucibus felis fermentum feugiat fringilla fusce gravida "
+            + "habitant habitasse hac hendrerit hymenaeos iaculis id imperdiet "
+            + "in inceptos integer interdum ipsum justo lacinia lacus laoreet "
+            + "lectus leo libero ligula litora lobortis lorem luctus maecenas "
+            + "magna magnis malesuada massa mattis mauris metus mi molestie "
+            + "mollis montes morbi mus nam nascetur natoque nec neque netus "
+            + "nibh nisi nisl non nonummy nostra nulla nullam nunc odio orci "
+            + "ornare parturient pede pellentesque penatibus per pharetra "
+            + "phasellus placerat platea porta porttitor posuere potenti praesent "
+            + "pretium primis proin pulvinar purus quam quis quisque rhoncus "
+            + "ridiculus risus rutrum sagittis sapien scelerisque sed sem semper "
+            + "senectus sit sociis sociosqu sodales sollicitudin suscipit "
+            + "suspendisse taciti tellus tempor tempus tincidunt torquent tortor "
+            + "tristique turpis ullamcorper ultrices ultricies urna ut Objectius ve "
+            + "vehicula vel velit venenatis vestibulum vitae vivamus viverra " + "volutpat vulputate";
+
+    /**
+     * A sample to use for generating the distribution of word and sentence
+     * lengths in lorem ipsum.
+     * 
+     * @type {string}
+     * @private
+     */
+    private static final String SAMPLE = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean "
+            + "commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus "
+            + "et magnis dis parturient montes, nascetur ridiculus mus. Donec quam "
+            + "felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla "
+            + "consequat massa quis enim. Donec pede justo, fringilla vel, aliquet "
+            + "nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, "
+            + "venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. "
+            + "Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean "
+            + "vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat "
+            + "vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra "
+            + "quis, feugiat a, tellus. Phasellus viverra nulla ut metus Objectius "
+            + "laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel "
+            + "augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.\n\n" +
+
+            "Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem "
+            + "quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam "
+            + "nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec "
+            + "odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis "
+            + "faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus "
+            + "tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales "
+            + "sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit "
+            + "cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend "
+            + "sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, "
+            + "metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis "
+            + "hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci "
+            + "luctus et ultrices posuere cubilia Curae; In ac dui quis mi " + "consectetuer lacinia.\n\n" +
+
+            "Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet "
+            + "nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer "
+            + "ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent "
+            + "adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy "
+            + "metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros "
+            + "et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, "
+            + "nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit "
+            + "risus. Phasellus nec sem in justo pellentesque facilisis. Etiam "
+            + "imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus "
+            + "non, auctor et, hendrerit quis, nisi.\n\n" +
+
+            "Curabitur ligula sapien, tincidunt non, euismod vitae, posuere "
+            + "imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed "
+            + "cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus "
+            + "accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci "
+            + "luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis "
+            + "porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis "
+            + "orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, "
+            + "bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede "
+            + "sit amet augue. In turpis. Pellentesque posuere. Praesent turpis.\n\n" +
+
+            "Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu "
+            + "sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales "
+            + "nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse "
+            + "pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, "
+            + "nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in "
+            + "faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id "
+            + "purus. Ut Objectius tincidunt libero. Phasellus dolor. Maecenas vestibulum "
+            + "mollis diam. Pellentesque ut neque. Pellentesque habitant morbi "
+            + "tristique senectus et netus et malesuada fames ac turpis egestas.\n\n" +
+
+            "In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac "
+            + "felis quis tortor malesuada pretium. Pellentesque auctor neque nec "
+            + "urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean "
+            + "viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et "
+            + "netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis "
+            + "pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna.\n\n" +
+
+            "In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare "
+            + "lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis "
+            + "ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. "
+            + "Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, "
+            + "quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at "
+            + "pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo "
+            + "quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam "
+            + "sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce "
+            + "risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis " + "vulputate lorem.\n\n" +
+
+            "Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, "
+            + "dui et placerat feugiat, eros pede Objectius nisi, condimentum viverra "
+            + "felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu, "
+            + "Objectius ut, felis. In auctor lobortis lacus. Quisque libero metus, "
+            + "condimentum nec, tempor a, commodo mollis, magna. Vestibulum "
+            + "ullamcorper mauris at ligula. Fusce fermentum. Nullam cursus lacinia "
+            + "erat. Praesent blandit laoreet nibh.\n\n" +
+
+            "Fusce convallis metus id felis luctus adipiscing. Pellentesque egestas, "
+            + "neque sit amet convallis pulvinar, justo nulla eleifend augue, ac "
+            + "auctor orci leo non est. Quisque id mi. Ut tincidunt tincidunt erat. "
+            + "Etiam feugiat lorem non metus. Vestibulum dapibus nunc ac augue. "
+            + "Curabitur vestibulum aliquam leo. Praesent egestas neque eu enim. In "
+            + "hac habitasse platea dictumst. Fusce a quam. Etiam ut purus mattis "
+            + "mauris sodales aliquam. Curabitur nisi. Quisque malesuada placerat "
+            + "nisl. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, " + "lacus.\n\n" +
+
+            "Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, "
+            + "dui. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi "
+            + "congue nunc, vitae euismod ligula urna in dolor. Mauris sollicitudin "
+            + "fermentum libero. Praesent nonummy mi in odio. Nunc interdum lacus sit "
+            + "amet orci. Vestibulum rutrum, mi nec elementum vehicula, eros quam "
+            + "gravida nisl, id fringilla neque ante vel mi. Morbi mollis tellus ac "
+            + "sapien. Phasellus volutpat, metus eget egestas mollis, lacus lacus "
+            + "blandit dui, id egestas quam mauris ut lacus. Fusce vel dui. Sed in "
+            + "libero ut nibh placerat accumsan. Proin faucibus arcu quis ante. In "
+            + "consectetuer turpis ut velit. Nulla sit amet est. Praesent metus "
+            + "tellus, elementum eu, semper a, adipiscing nec, purus. Cras risus "
+            + "ipsum, faucibus ut, ullamcorper id, Objectius ac, leo. Suspendisse "
+            + "feugiat. Suspendisse enim turpis, dictum sed, iaculis a, condimentum "
+            + "nec, nisi. Praesent nec nisl a purus blandit viverra. Praesent ac "
+            + "massa at ligula laoreet iaculis. Nulla neque dolor, sagittis eget, "
+            + "iaculis quis, molestie non, velit.\n\n" +
+
+            "Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. "
+            + "Fusce pharetra convallis urna. Quisque ut nisi. Donec mi odio, faucibus "
+            + "at, scelerisque quis, convallis in, nisi. Suspendisse non nisl sit amet "
+            + "velit hendrerit rutrum. Ut leo. Ut a nisl id ante tempus hendrerit. "
+            + "Proin pretium, leo ac pellentesque mollis, felis nunc ultrices eros, "
+            + "sed gravida augue augue mollis justo. Suspendisse eu ligula. Nulla "
+            + "facilisi. Donec id justo. Praesent porttitor, nulla vitae posuere "
+            + "iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. "
+            + "Curabitur suscipit suscipit tellus.\n\n" +
+
+            "Praesent vestibulum dapibus nibh. Etiam iaculis nunc ac metus. Ut id "
+            + "nisl quis enim dignissim sagittis. Etiam sollicitudin, ipsum eu "
+            + "pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante "
+            + "odio sit amet eros. Proin magna. Duis vel nibh at velit scelerisque "
+            + "suscipit. Curabitur turpis. Vestibulum suscipit nulla quis orci. Fusce "
+            + "ac felis sit amet ligula pharetra condimentum. Maecenas egestas arcu "
+            + "quis ligula mattis placerat. Duis lobortis massa imperdiet quam. " + "Suspendisse potenti.\n\n" +
+
+            "Pellentesque commodo eros a enim. Vestibulum turpis sem, aliquet eget, "
+            + "lobortis pellentesque, rutrum eu, nisl. Sed libero. Aliquam erat "
+            + "volutpat. Etiam vitae tortor. Morbi vestibulum volutpat enim. Aliquam "
+            + "eu nunc. Nunc sed turpis. Sed mollis, eros et ultrices tempus, mauris "
+            + "ipsum aliquam libero, non adipiscing dolor urna a orci. Nulla porta "
+            + "dolor. Class aptent taciti sociosqu ad litora torquent per conubia "
+            + "nostra, per inceptos hymenaeos.\n\n" +
+
+            "Pellentesque dapibus hendrerit tortor. Praesent egestas tristique nibh. "
+            + "Sed a libero. Cras Objectius. Donec vitae orci sed dolor rutrum auctor. "
+            + "Fusce egestas elit eget lorem. Suspendisse nisl elit, rhoncus eget, "
+            + "elementum ac, condimentum eget, diam. Nam at tortor in tellus interdum "
+            + "sagittis. Aliquam lobortis. Donec orci lectus, aliquam ut, faucibus "
+            + "non, euismod id, nulla. Curabitur blandit mollis lacus. Nam adipiscing. " + "Vestibulum eu odio.\n\n" +
+
+            "Vivamus laoreet. Nullam tincidunt adipiscing enim. Phasellus tempus. "
+            + "Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique "
+            + "sapien, a accumsan nisi mauris ac eros. Fusce neque. Suspendisse "
+            + "faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, "
+            + "vitae iaculis lacus elit id tortor. Vivamus aliquet elit ac nisl. Fusce "
+            + "fermentum odio nec arcu. Vivamus euismod mauris. In ut quam vitae "
+            + "odio lacinia tincidunt. Praesent ut ligula non mi Objectius sagittis. "
+            + "Cras sagittis. Praesent ac sem eget est egestas volutpat. Vivamus "
+            + "consectetuer hendrerit lacus. Cras non dolor. Vivamus in erat ut urna "
+            + "cursus vestibulum. Fusce commodo aliquam arcu. Nam commodo suscipit "
+            + "quam. Quisque id odio. Praesent venenatis metus at tortor pulvinar " + "varius.\n\n";
+
+    /**
+     * Generates a number of paragraphs, with each paragraph surrounded by HTML
+     * pararaph tags.
+     * 
+     * @param quantity
+     * @param startWithLorem
+     * @return
+     */
+    public String generateParagraphsHtml(int quantity, boolean startWithLorem) {
+
+        return generateMarkupParagraphs("<p>" + LINE_SEPARATOR + "\t", LINE_SEPARATOR + "</p>", LINE_SEPARATOR + "</p>"
+                + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR + "\t", quantity, startWithLorem);
+
+    }
+
+    /**
+     * Generates a number of paragraphs, with each paragraph surrounded by HTML
+     * pararaph tags.
+     * 
+     * @param writer
+     * @param quantity
+     * @param startWithLorem
+     * @throws IOException 
+     */
+    public void generateParagraphsHtml(Appendable writer, int quantity, boolean startWithLorem) throws IOException {
+
+        generateMarkupParagraphs(writer, "<p>" + LINE_SEPARATOR + "\t", LINE_SEPARATOR + "</p>", LINE_SEPARATOR + "</p>"
+                + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR + "\t", quantity, startWithLorem);
+
+    }
+    
+    
+    /**
+     * Generates one paragraph of HTML, surrounded by HTML pararaph tags.
+     * 
+     * @param quantity
+     * @param startWithLorem
+     * @return
+     */
+    public String generateOneParagraphHtml(int quantity, boolean startWithLorem) {
+
+        return generateMarkupSentences("<p>" + LINE_SEPARATOR + "\t", LINE_SEPARATOR + "</p>", LINE_SEPARATOR,
+                quantity, startWithLorem);
+
+    }
+
+    /**
+     * Generates a number of paragraphs, with each paragraph surrounded by HTML
+     * paragraph tags as a full HTML page.
+     * 
+     * @param quantity
+     * @param startWithLorem
+     * @return
+     */
+    public String generateParagraphsFullHtml(int quantity, boolean startWithLorem) {
+
+        String prefix = "<html>" + LINE_SEPARATOR + "<header>" + LINE_SEPARATOR + "<title>Lorem Ipsum</title>"
+                + LINE_SEPARATOR + "</header>" + LINE_SEPARATOR + LINE_SEPARATOR + "<body>";
+        String postfix = "</body>" + LINE_SEPARATOR + "</html>" + LINE_SEPARATOR;
+
+        return generateMarkupParagraphs(prefix + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR + "\t", LINE_SEPARATOR
+                + "</p>" + LINE_SEPARATOR + postfix, LINE_SEPARATOR + "</p>" + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR
+                + "\t", quantity, startWithLorem);
+    }
+    
+    
+    /**
+     * Generates a number of paragraphs, with each paragraph surrounded by HTML
+     * paragraph tags as a full HTML page.
+     * 
+     * @param writer
+     * @param quantity
+     * @param startWithLorem
+     * @throws IOException 
+     */
+    public void generateParagraphsFullHtml(Appendable writer, int quantity, boolean startWithLorem) throws IOException {
+
+        String prefix = "<html>" + LINE_SEPARATOR + "<header>" + LINE_SEPARATOR + "<title>Lorem Ipsum</title>"
+                + LINE_SEPARATOR + "</header>" + LINE_SEPARATOR + LINE_SEPARATOR + "<body>";
+        String postfix = "</body>" + LINE_SEPARATOR + "</html>" + LINE_SEPARATOR;
+
+        generateMarkupParagraphs(writer, prefix + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR + "\t", LINE_SEPARATOR
+                + "</p>" + LINE_SEPARATOR + postfix, LINE_SEPARATOR + "</p>" + LINE_SEPARATOR + "<p>" + LINE_SEPARATOR
+                + "\t", quantity, startWithLorem);
+    }
+    
+    
+    /**
+     * Generates a number of paragraphs, with each paragraph separated by two
+     * newlines.
+     * 
+     * @param quantity
+     * @param startWithLorem
+     * @return
+     */
+    public String generateParagraphsPlainText(int quantity, boolean startWithLorem) {
+
+        return generateMarkupParagraphs("", "", LINE_SEPARATOR + LINE_SEPARATOR, quantity, startWithLorem);
+    }
+
+    /**
+     * Generates a number of paragraphs, with each paragraph separated by two
+     * newlines.
+     * 
+     * @param writer
+     * @param quantity
+     * @param startWithLorem
+     * @throws IOException 
+     */
+    public void generateParagraphsPlainText(Appendable writer, int quantity, boolean startWithLorem) throws IOException {
+
+        generateMarkupParagraphs(writer, "", "", LINE_SEPARATOR + LINE_SEPARATOR, quantity, startWithLorem);
+    }
+
+    /**
+     * Generates a number of paragraphs, with each paragraph separated by two
+     * newlines and no line exceeding maxCols columns
+     * 
+     * @param quantity
+     * @param startWithLorem
+     * @return
+     */
+    public String generateParagraphsPlainText(int quantity, int maxCols, boolean startWithLorem) {
+
+        StringWriter writer = new StringWriter(quantity + 512);
+        try {
+            generateParagraphsPlainText(writer, quantity, maxCols, startWithLorem);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return writer.toString();
+    }
+
+    /**
+     * Generates a number of paragraphs, with each paragraph separated by two
+     * newlines and no line exceeding maxCols columns
+     * 
+     * @param writer
+     * @param quantity
+     * @param startWithLorem
+     * @throws IOException 
+     */
+    public void generateParagraphsPlainText(Appendable writer, int quantity, int maxCols, boolean startWithLorem) throws IOException {
+
+        String delims = " .,?!";
+        String unformatted = generateMarkupParagraphs("", "", LINE_SEPARATOR + LINE_SEPARATOR, quantity, startWithLorem);
+        int len = unformatted.length();
+
+        if (maxCols <= 0)
+            writer.append(unformatted);
+        else {
+            int startPos = 0;
+            while (startPos < len - 1) {
+                int endPos = Math.min(startPos + maxCols, len - 1);
+                boolean shift = true;
+                // check if there is already a line break:
+                for (int i = startPos; i < endPos; i++) {
+                    if (unformatted.charAt(i) == '\n') {
+                        shift = false;
+                        endPos = i;
+                    }
+                }
+                char ch = unformatted.charAt(endPos);
+                while (shift) {
+                    for (int i = 0; i < delims.length(); i++) {
+                        if (ch == delims.charAt(i)) {
+                            shift = false;
+                            break;
+                        }
+                    }
+                    if (shift) {
+                        ch = unformatted.charAt(--endPos);
+                        shift = endPos > startPos;
+                    }
+                }
+                writer.append(unformatted.substring(startPos, endPos + 1));
+                if (unformatted.charAt(endPos) != '\n')
+                    writer.append(LINE_SEPARATOR);
+                startPos = endPos + 1;
+            }
+        }
+    }
+
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java?rev=1102179&r1=1102178&r2=1102179&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java Thu May 12 06:25:22 2011
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.ut
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.StringReader;
 import java.math.BigInteger;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -46,6 +47,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 import org.apache.chemistry.opencmis.commons.spi.NavigationService;
 import org.apache.chemistry.opencmis.commons.spi.ObjectService;
+import org.apache.chemistry.opencmis.util.content.LoreIpsum;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -113,6 +115,11 @@ public class ObjectGenerator {
      * size of content in KB, if 0 create documents without content
      */
     private int fContentSizeInK = 0;
+    
+    /**
+     * true: use Lore Ipsum generator, false: use static text
+     */
+    private boolean useLoreIpsum = true;
 
     private static final String NAMEPROPVALPREFIXDOC = "My_Document-";
     private static final String NAMEPROPVALPREFIXFOLDER = "My_Folder-";
@@ -169,6 +176,14 @@ public class ObjectGenerator {
     public void setContentSizeInKB(int sizeInK) {
         fContentSizeInK = sizeInK;
     }
+    
+    public boolean getLoreIpsumGenerator() {
+        return useLoreIpsum;
+    }
+    
+    public void setLoreIpsumGenerator(boolean use) {
+        useLoreIpsum = use;
+    }
 
     public void setCleanUpAfterCreate(boolean doCleanup) {
         fCleanup = doCleanup;
@@ -416,7 +431,7 @@ public class ObjectGenerator {
         Properties props = createDocumentProperties(no, level);
         String id = null;
         if (fContentSizeInK > 0) {
-            contentStream = createContent();
+            contentStream = useLoreIpsum ? createContent() : createContentStaticText();
         }
         try {
             fTimeLoggerCreateDoc.start();
@@ -465,6 +480,18 @@ public class ObjectGenerator {
         content.setFileName("data.txt");
         content.setMimeType("text/plain");
         int len = fContentSizeInK * 1024; // size of document in K
+        
+        LoreIpsum ipsum = new LoreIpsum();
+        String text = ipsum.generateParagraphsPlainText(len, 80, true);
+        content.setStream(new ByteArrayInputStream(text.getBytes()));
+        return content;
+    }
+
+    private ContentStream createContentStaticText() {
+        ContentStreamImpl content = new ContentStreamImpl();
+        content.setFileName("data.txt");
+        content.setMimeType("text/plain");
+        int len = fContentSizeInK * 1024; // size of document in K
         byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
                 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a }; // 32
         // Bytes

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/LoreIpsumTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/LoreIpsumTest.java?rev=1102179&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/LoreIpsumTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/LoreIpsumTest.java Thu May 12 06:25:22 2011
@@ -0,0 +1,400 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.util.content;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoreIpsumTest {
+
+    private static final Log LOG = LogFactory.getLog(LoreIpsumTest.class);
+
+    String sample = "One two three four five six. Seven eight nine ten eleven twelve. "
+		+ "\n\n"
+		+ "Thirteen fourteen fifteen sixteen. Seventeen eighteen nineteen twenty.";
+       
+    String dictionary = "a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh iiiiiiiii jjjjjjjjjj kkkkkkkkkkk llllllllllll";
+    LoreIpsum generator = new LoreIpsum(sample, dictionary);
+    
+	@Before
+	public void setUp() throws Exception {
+	    dictionary.split(" ");
+	}
+
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void  test_mean() {
+		int[] ia1 = {1, 2, 3, 4};
+        assertEquals(2.5d, LoreIpsum.mean(ia1), 0.01d);
+        int[] ia2 = {6, 6, 4, 4};
+        assertEquals(5.0d, LoreIpsum.mean(ia2), 0.01d);
+	}
+	
+    @Test
+	public void  test_mean_empty() {
+		int[] ia1 = {};
+        assertEquals(0.0d, LoreIpsum.mean(ia1), 0.01d);
+    }
+    
+    @Test
+	public void  test_variance() {
+		double[] ia1 = {6.0d, 6.0d, 4.0d, 4.0d};
+        assertEquals(1.0d, LoreIpsum.variance(ia1), 0.01d);
+        double[] ia2 = {1.0d, 2.0d, 3.0d, 4.0d};
+        assertEquals(1.25d, LoreIpsum.variance(ia2), 0.01d);
+    }
+    
+    @Test
+	public void  test_sigma() {
+		double[] ia1 = {6.0d, 6.0d, 4.0d, 4.0d};
+        double[] ia2 = {1.0d, 2.0d, 3.0d, 4.0d};
+        assertEquals(1.0d, LoreIpsum.sigma(ia1), 0.01d);
+        assertEquals(Math.sqrt(1.25), LoreIpsum.sigma(ia2), 0.01d);
+    }
+    
+    @Test
+	public void  test_sigma_empty() {
+		int[] ia1 = {};
+        assertEquals(0.0d, LoreIpsum.sigma(ia1), 0.01d);
+    }
+    
+    @Test
+	public void test_split_sentences() {
+    	String[] sentences1 = {"Hello", "Hi"};
+    	assertArrayEquals (sentences1, LoreIpsum.splitSentences("Hello. Hi."));
+        String[] sentences2 = {"One two three four five six", 
+                                 "Seven eight nine ten eleven twelve", 
+                                 "Thirteen fourteen fifteen sixteen", 
+                                 "Seventeen eighteen nineteen twenty"}; 
+        assertArrayEquals(sentences2, LoreIpsum.splitSentences(sample));
+    }
+    
+    @Test
+	public void test_split_sentences_empty() {
+    	String[] sentences = {};
+    	assertArrayEquals(sentences, LoreIpsum.splitSentences(""));
+    }
+    
+    @Test
+	public void test_split_sentences_trailing() {
+    	String[] sentences1 = {"Hello", "Hi", "Hello"};    	
+    	assertArrayEquals(sentences1, LoreIpsum.splitSentences("Hello. Hi. Hello"));
+    	String[] sentences2 = {"Hello", "Hi", "Hello"};
+    	assertArrayEquals(sentences2, LoreIpsum.splitSentences("  Hello. Hi. Hello  "));
+        String[] sentences3 = {"Hello", "Hi", "Hello"};
+        assertArrayEquals(sentences3, LoreIpsum.splitSentences("..  Hello... Hi.... Hello  ")); 
+    }
+
+    @Test
+	public void test_split_paragraphs() {
+    	String[] paragraphs = {"One two three four five six. Seven eight nine ten eleven twelve.",
+    			"Thirteen fourteen fifteen sixteen. Seventeen eighteen nineteen twenty."};
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs(sample));
+    }
+    
+    @Test
+	public void test_split_paragraphs_empty() {
+    	String[] paragraphs = {};
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs(""));
+    }
+    
+    @Test
+	public void test_split_paragraphs_trailing() {
+    	String[] paragraphs = {"Hello", "Hi"};
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("Hello\n\nHi"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("Hello\n\nHi\n"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("Hello\n\nHi\n\n"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("Hello\n\nHi\n\n\n"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("Hello\n\nHi\n\n\n\n\n\n"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("\nHello\n\nHi"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("\n\nHello\n\nHi"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("\n\n\nHello\n\nHi"));
+    	assertArrayEquals(paragraphs, LoreIpsum.splitParagraphs("\n\n\n\n\n\nHello\n\nHi"));
+    }
+    
+    @Test
+	public void test_split_words() {
+    	String[] words = {"One", "two", "three", "four"};
+    	assertArrayEquals(words, LoreIpsum.splitWords("One two three four"));    	
+    	assertArrayEquals(words, LoreIpsum.splitWords("  One    two  three  four   ")); 
+    }
+                
+    @Test
+	public void test_split_words_empty() {
+    	String[] words = {};
+    	assertArrayEquals(words, LoreIpsum.splitWords(""));
+	}
+    
+    @Test
+	public void test_choose_closest() {
+    	Integer[] intArray1 ={1,2,3,4};
+        assertEquals(1, LoreIpsum.chooseClosest(intArray1, 1));
+        Integer[] intArray2 ={1,2,3,4};
+        assertEquals(4, LoreIpsum.chooseClosest(intArray2, 4));
+        assertEquals(4, LoreIpsum.chooseClosest(intArray2, 20));
+        assertEquals(1, LoreIpsum.chooseClosest(intArray2, -10));
+        Integer[] intArray3 ={1,4};
+        assertEquals(1, LoreIpsum.chooseClosest(intArray3, 2));
+        assertEquals(4, LoreIpsum.chooseClosest(intArray3, 3));
+        Integer[] intArray4 ={1,3};
+        assertEquals(1, LoreIpsum.chooseClosest(intArray4, 2));
+        Integer[] intArray5 ={3,1};
+        assertEquals(3, LoreIpsum.chooseClosest(intArray5, 2));
+        Integer[] intArray6 ={1};
+        assertEquals(1, LoreIpsum.chooseClosest(intArray6, 200));
+    }
+
+    @Test
+	public void test_sentence_mean() {
+        assertEquals(5.0d, generator.getSentenceMean(), 0.01d);
+	}
+   
+    @Test
+	public void test_paragraph_mean() {
+    	assertEquals(2.0d, generator.getParagraphMean(), 0.01d);
+    }
+        
+    @Test
+	public void test_sentence_sigma() {
+        assertEquals(1.0d, generator.getSentenceSigma(), 0.01d);
+    }
+        
+    @Test
+	public void test_paragraph_sigma() {
+        assertEquals(0.0d, generator.getParagraphSigma(), 0.01d);
+    }
+        
+    @Test
+	public void test_sample() {
+        assertEquals(generator.getSample(), sample);
+    }
+
+    @Test
+	public void test_dictionary() {
+        assertEquals(generator.getDictionary(), dictionary);
+    }
+
+    @Test
+	public void test_set_dictionary() {
+        String newdict = "a b c";
+        generator.setDictionary(newdict);
+        assertEquals(generator.getDictionary(), newdict);
+	}
+    
+    @Test 
+    public void test_init_no_sample() {
+    	doGenerate("");
+    	doGenerate(" ");
+    	doGenerate("\n\n");
+    	doGenerate("  \n\n  ");
+    	doGenerate(" .\n\n .");
+    }
+    
+    private void doGenerate(String text) {
+    	try {
+    		generator = new LoreIpsum(text, dictionary);
+    		generator.generateParagraph(false);
+    		fail("Sample text " + text + " should generate exception.");
+    	} catch (RuntimeException e) {
+    		assertTrue(e.getMessage().contains("Invalid sample text"));
+    	}
+    }
+    
+    @Test 
+    public void test_init_no_dict() {
+    	doGenerateNoDict("");
+    	doGenerateNoDict(" ");
+    	doGenerateNoDict("\n\n");
+    	doGenerateNoDict("  \n\n  ");
+    }
+    
+    private void doGenerateNoDict(String dict) {
+    	try {
+    		generator = new LoreIpsum(sample, dict);
+    		generator.generateParagraph(false);
+    		fail("Dictionary " + dict + " should generate exception.");
+    	} catch (RuntimeException e) {
+    		assertEquals(e.getMessage(), "Invalid dictionary.");
+    	}
+    }
+
+    @Test 
+    public void testGenerate() {
+    	LOG.info("Generate new text: ");
+    	String newDict = "me you he the One two three four five six Seven eight nine ten eleven twelve "
+       		+ "Thirteen fourteen fifteen sixteen Seventeen eighteen nineteen twenty joe fred some";
+    	String[] newParagraphs = new String[4];
+    	generator.setDictionary(newDict);
+    	for (int i=0; i<newParagraphs.length; i++) {
+    		newParagraphs[i] = generator.generateParagraph(false);
+    		LOG.info(newParagraphs[i]);
+    		LOG.info("");
+    	}
+    	assertFalse(newParagraphs[0].equals(newParagraphs[1]));
+    	assertFalse(newParagraphs[0].equals(newParagraphs[2]));
+    	assertFalse(newParagraphs[0].equals(newParagraphs[3]));
+    	assertFalse(newParagraphs[1].equals(newParagraphs[2]));
+    	assertFalse(newParagraphs[1].equals(newParagraphs[3]));
+    	assertFalse(newParagraphs[2].equals(newParagraphs[3]));
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsum() {
+    	LOG.info("Generate new Lore Ipsum text: ");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String[] newParagraphs = new String[4];
+    	for (int i=0; i<newParagraphs.length; i++) {
+    		newParagraphs[i] = ipsum.generateParagraph(false);
+    		LOG.info(newParagraphs[i]);
+    		LOG.info("");
+    		LOG.info("");
+    	}
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumHtml1() {
+    	LOG.info("Generate new Lore Ipsum as html paragraphs:");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String output = ipsum.generateParagraphsHtml(2048, true);
+    	LOG.info(output);
+    	LOG.info("");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumHtml2() {
+    	LOG.info("Generate new Lore Ipsum as one html paragraph:");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String output = ipsum.generateOneParagraphHtml(2048, true);
+    	LOG.info(output);
+    	LOG.info("");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumHtml3() {
+        LOG.info("Generate new Lore Ipsum as full html document: ");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String output = ipsum.generateParagraphsFullHtml(2048, true);
+    	LOG.info(output);
+    	LOG.info("");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumPlainText() {
+    	LOG.info("Generate new Lore Ipsum as plain text: ");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String output = ipsum.generateParagraphsPlainText(2048, true);
+    	LOG.info(output);
+    	LOG.info("");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumPlainTextFormatted() {
+    	LOG.info("Generate new Lore Ipsum as plain text with 60 columns: ");
+    	LoreIpsum ipsum = new LoreIpsum();
+    	String output = ipsum.generateParagraphsPlainText(256, 60, false);
+    	LOG.info(output);
+    	LOG.info("");
+    }
+        
+    @Test 
+    public void testGenerateLoreIpsumHtml1Writer() throws IOException {
+        LOG.info("Generate new Lore Ipsum as html paragraphs with PrintWriter:");
+        LoreIpsum ipsum = new LoreIpsum();
+        StringWriter writer = new StringWriter();
+        ipsum.generateParagraphsHtml(writer, 2048, true);
+        LOG.info(writer.toString());
+        LOG.info("End Test.");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumHtml2Writer() throws IOException  {
+        LOG.info("Generate new Lore Ipsum as full html paragraph with PrintWriter:");
+        LoreIpsum ipsum = new LoreIpsum();
+        StringWriter writer = new StringWriter();
+        ipsum.generateParagraphsFullHtml(writer, 2048, true);
+        LOG.info(writer.toString());
+        LOG.info("End Test.");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumPlainTextWriter() throws IOException  {
+        LOG.info("Generate new Lore Ipsum as plain text with PrintWriter: ");
+        LoreIpsum ipsum = new LoreIpsum();
+        StringWriter writer = new StringWriter();
+        ipsum.generateParagraphsPlainText(writer, 2048, true);
+        LOG.info(writer.toString());
+        LOG.info("End Test.");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumPlainTextFormattedWriter() throws IOException {
+        LOG.info("Generate new Lore Ipsum as plain text with 60 columns with PrintWriter: ");
+        LoreIpsum ipsum = new LoreIpsum();
+        StringWriter writer = new StringWriter();
+        ipsum.generateParagraphsPlainText(writer, 256, 60, false);
+        LOG.info(writer.toString());
+        LOG.info("End Test.");
+    }
+    
+    @Test 
+    public void testGenerateLoreIpsumGerman() throws Exception {
+    	LOG.info("Generate new Lore Ipsum Ferry Tale: ");
+    	InputStream is = this.getClass().getResourceAsStream("/HaenselUndGretel.txt");
+    	
+    	// read stream into a string
+    	final char[] buffer = new char[0x10000];
+    	StringBuilder sample = new StringBuilder();
+    	Reader in = new InputStreamReader(is, "ISO-8859-1");
+    	int read;
+    	do {
+    	  read = in.read(buffer, 0, buffer.length);
+    	  if (read>0) {
+    	    sample.append(buffer, 0, read);
+    	  }
+    	} while (read>=0);
+
+    	
+    	LoreIpsum ipsum = new LoreIpsum(sample.toString());
+    	String output = ipsum.generateParagraphsPlainText(4096, 80, false);
+    	LOG.info(output);
+        LOG.info("End Test.");
+    }
+    
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/HaenselUndGretel.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/HaenselUndGretel.txt?rev=1102179&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/HaenselUndGretel.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/HaenselUndGretel.txt Thu May 12 06:25:22 2011
@@ -0,0 +1,45 @@
+Hänsel und Grethel.
+
+Vor einem großen Walde wohnte ein armer Holzhacker mit seiner Frau und seinen zwei Kindern; das Bübchen hieß Hänsel und das Mädchen Grethel. Er hatte wenig zu beißen und zu brechen, und einmal, als große Theuerung ins Land kam, konnte er auch das täglich Brot nicht mehr schaffen. Wie er sich nun Abends im Bette Gedanken machte und sich vor Sorgen herum wälzte, seufzte er und sprach zu seiner Frau "was soll aus uns werden? wie können wir unsere armen Kinder ernähren, da wir für uns selbst nichts mehr haben?" "Weißt du was, Mann," antwortete die Frau, "wir wollen Morgen in aller Frühe die Kinder hinaus in den Wald führen, wo er am dicksten ist: da machen wir ihnen ein Feuer an und geben jedem noch ein Stückchen Brot, dann gehen wir an unsere Arbeit und lassen sie allein. Sie finden den Weg nicht wieder nach Haus und wir sind sie los." "Nein, Frau," sagte der Mann, "das thue ich nicht; wie sollt ichs übers Herz bringen meine Kinder im Walde allein zu lassen, di
 e wilden Thiere würden bald kommen und sie zerreißen." "O du Narr," sagte sie, "dann müssen wir alle viere Hungers sterben, du kannst nur die Bretter für die Särge hobelen," und ließ ihm keine Ruhe bis er einwilligte. "Aber die armen Kinder dauern mich doch" sagte der Mann.
+
+Die zwei Kinder hatten vor Hunger auch nicht einschlafen können und hatten gehört was die Stiefmutter zum Vater gesagt 
+Als der Tag anbrach, noch ehe die Sonne aufgegangen war, kam schon die Frau und weckte die beiden Kinder, "steht auf, ihr Faullenzer, wir wollen in den Wald gehen und Holz holen." Dann gab sie jedem ein Stückchen Brot und sprach "da habt ihr etwas für den Mittag, aber eßts nicht vorher auf, weiter kriegt ihr nichts." Grethel nahm das Brot unter die Schürze, weil Hänsel die Steine in der Tasche hatte. Danach machten sie sich alle zusammen auf den Weg nach dem Wald. Als sie ein Weilchen gegangen waren, stand Hänsel still und guckte nach dem Haus zurück und that das wieder und immer wieder. Der Vater sprach "Hänsel, was guckst du da und bleibst zurück, hab Acht und vergiß deine Beine nicht." "Ach, Vater," sagte Hänsel, "ich sehe nach meinem weißen Kätzchen, das sitzt oben auf dem Dach und will mir Ade sagen." Die Frau sprach "Narr, das ist dein Kätzchen nicht, das ist die Morgensonne, die auf den Schornstein scheint." Hänsel aber hatte nicht nach dem Kätzchen ge
 sehen, sondern immer einen von den blanken Kieselsteinen aus seiner Tasche auf den Weg geworfen.
+
+Als sie mitten in den Wald gekommen waren, sprach der Vater "nun sammelt Holz, ihr Kinder, ich will ein Feuer anmachen, damit ihr nicht friert." Hänsel und Grethel trugen Reisig zusammen, einen kleinen Berg hoch. Das Reisig ward angezündet, und als die Flamme recht hoch brannte, sagte die Frau "nun legt euch ans Feuer, ihr Kinder und ruht euch aus, wir gehen in den Wald und hauen Holz. Wenn wir fertig sind, kommen wir wieder und holen euch ab."
+
+Hänsel und Grethel saßen am Feuer, und als der Mittag kam, aß jedes sein Stücklein Brot. Und weil sie die Schläge der Holzaxt hörten, so glaubten sie ihr Vater wäre in der Nähe. Es war aber nicht die Holzaxt, es war ein Ast, den er an einen dürren Baum gebunden hatte und den der Wind hin und her schlug. Und als sie so lange gesessen hatten, fielen ihnen die Augen vor Müdigkeit zu, und sie schliefen fest ein. Als sie endlich erwachten, war es schon finstere Nacht. Grethel fieng an zu weinen und sprach "wie sollen wir nun aus dem Wald kommen!" Hänsel aber tröstete sie, "wart nur ein Weilchen, bis der Mond aufgegangen ist, dann wollen wir den Weg schon finden." Und als der volle Mond aufgestiegen war, so nahm Hänsel sein Schwesterchen an der Hand und gieng den Kieselsteinen nach, die schimmerten wie neu geschlagene Batzen und zeigten ihnen den Weg. Sie giengen die ganze Nacht hindurch und kamen bei anbrechendem Tag wieder zu ihres Vaters Haus. Sie klopften an die T
 hür, und als die Frau aufmachte und sah daß es Hänsel und Grethel war, sprach sie "ihr bösen Kinder, was habt ihr so lange im Walde geschlafen, wir haben geglaubt ihr wolltet gar nicht wieder kommen." Der Vater aber freute sich, denn es war ihm zu Herzen gegangen daß er sie so allein zurück gelassen hatte.
+
+Nicht lange danach war wieder Noth in allen Ecken, und die Kinder hörten wie die Mutter Nachts im Bette zu dem Vater sprach "alles ist wieder aufgezehrt, wir haben noch einen halben Laib Brot, hernach hat das Lied ein Ende. Die Kinder müssen fort, wir wollen sie tiefer in den Wald hineinführen, damit sie den Weg nicht wieder heraus finden; es ist sonst keine Rettung für uns." Dem Mann fiels schwer aufs Herz und er dachte "es wäre besser, daß du den letzten Bissen mit deinen Kindern theiltest." Aber die Frau hörte auf nichts, was er sagte, schalt ihn und machte ihm Vorwürfe. Wer A sagt muß auch B sagen, und weil er das erste Mal nachgegeben hatte, so mußte er es auch zum zweiten Mal.
+
+Die Kinder waren aber noch wach gewesen und hatten das Gespräch mit angehört. Als die Alten schliefen, stand Hänsel wieder auf, wollte hinaus und Kieselsteine auflesen, wie das vorigemal, aber die Frau hatte die Thür verschlossen, und Hänsel konnte nicht heraus. Aber er tröstete sein Schwesterchen und sprach "weine nicht, Grethel, und schlaf nur ruhig, der liebe Gott wird uns schon helfen."
+
+Am frühen Morgen kam die Frau und holte die Kinder aus dem Bette. Sie erhielten ihr Stückchen Brot, das war aber noch kleiner als das vorigemal. Auf dem Wege nach dem Wald bröckelte es Hänsel in der Tasche, stand oft still und warf ein Bröcklein auf die Erde. "Hänsel, was stehst du und guckst dich um," sagte der Vater, "geh deiner Wege." "Ich sehe nach meinem Täubchen, das sitzt auf dem Dache und will mir Ade sagen," antwortete Hänsel. "Narr," sagte die Frau, "das ist dein Täubchen nicht, das ist die Morgensonne, die auf den Schornstein oben scheint." Hänsel aber warf nach und nach alle Bröcklein auf den Weg.
+
+Die Frau führte die Kinder noch tiefer in den Wald, wo sie ihr Lebtag noch nicht gewesen waren. Da ward wieder ein großes Feuer angemacht, und die Mutter sagte "bleibt nur da sitzen, ihr Kinder, und wenn ihr müde seid, könnt ihr ein wenig schlafen: wir gehen in den Wald und hauen Holz, und Abends, wenn wir fertig sind, kommen wir und holen euch ab." Als es Mittag war, theilte Grethel ihr Brot mit Hänsel, der sein Stück auf den Weg gestreut hatte. Dann schliefen sie ein, und der Abend vergieng, aber niemand kam zu den armen Kindern. Sie erwachten erst in der finstern Nacht, und Hänsel tröstete sein Schwesterchen und sagte, "wart nur, Grethel, bis der Mond aufgeht, dann werden wir die Brotbröcklein sehen, die ich ausgestreut habe, die zeigen uns den Weg nach Haus." Als der Mond kam, machten sie sich auf, aber sie fanden kein Bröcklein mehr, denn die viel tausend Vögel, die im Walde und im Felde umher fliegen, die hatten sie weggepickt. Hänsel sagte zu Grethel "wir 
 werden den Weg schon finden," aber sie fanden ihn nicht. Sie giengen die ganze Nacht und noch einen Tag von Morgen bis Abend, aber sie kamen aus dem Wald nicht heraus, und waren so hungrig, denn sie hatten nichts als die paar Beeren, die auf der Erde standen. Und weil sie so müde waren daß die Beine sie nicht mehr tragen wollten, so legten sie sich unter einen Baum und schliefen ein.
+
+Nun wars schon der dritte Morgen, daß sie ihres Vaters Haus verlassen hatten. Sie fiengen wieder an zu gehen, aber sie geriethen immer tiefer in den Wald und wenn nicht bald Hilfe kam, so mußten sie verschmachten. Als es Mittag war, sahen sie ein schönes schneeweißes Vöglein auf einem Ast sitzen, das sang so schön, daß sie stehen blieben und ihm zuhörten. Und als es fertig war, schwang es seine Flügel und flog vor ihnen her, und sie giengen ihm nach, bis sie zu einem Häuschen gelangten, auf dessen Dach es sich setzte, und als sie ganz nah heran kamen, so sahen sie daß das Häuslein aus Brot gebaut war, und mit Kuchen gedeckt; aber die Fenster waren von hellem Zucker. "Da wollen wir uns dran machen," sprach Hänsel, "und eine gesegnete Mahlzeit halten. Ich will ein Stück vom Dach essen, Grethel, du kannst vom Fenster essen, das schmeckt süß." Hänsel reichte in die Höhe und brach sich ein wenig vom Dach ab, um zu versuchen wie es schmeckte, und Grethel stellte 
 sich an die Scheiben und knuperte daran. Da rief eine feine Stimme aus der Stube heraus
+
+"knuper, knuper, kneischen,
+wer knupert an meinem Häuschen?"
+
+die Kinder antworteten
+
+"der Wind, der Wind,
+das himmlische Kind,"
+
+und aßen weiter, ohne sich irre machen zu lassen. Hänsel, dem das Dach sehr gut schmeckte, riß sich ein großes Stück davon herunter, und Grethel stieß eine ganze runde Fensterscheibe heraus, setzte sich nieder, und that sich wohl damit. Da gieng auf einmal die Thüre auf, und eine steinalte Frau, die sich auf eine Krücke stützte, kam heraus geschlichen. Hänsel und Grethel erschracken so gewaltig, daß sie fallen ließen was sie in den Händen hielten. Die Alte aber wackelte mit dem Kopfe und sprach "ei, ihr lieben Kinder, wer hat euch hierher gebracht? kommt nur herein und bleibt bei mir, es geschieht euch kein Leid." Sie faßte beide an der Hand und führte sie in ihr Häuschen. Da ward gutes Essen aufgetragen, Milch und Pfannekuchen mit Zucker, Äpfel und Nüsse. Hernach wurden zwei schöne Bettlein weiß gedeckt, und Hänsel und Grethel legten sich hinein und meinten sie wären im Himmel.
+
+Die Alte hatte sich nur so freundlich angestellt, sie war aber eine böse Hexe, die den Kindern auflauerte, und hatte das Brothäuslein bloß gebaut, um sie herbeizulocken. Wenn eins in ihre Gewalt kam, so machte sie es todt, kochte es und aß es, und das war ihr ein Festtag. Die Hexen haben rothe Augen und können nicht weit sehen, aber sie haben eine feine Witterung, wie die Thiere, und merkens wenn Menschen heran kommen. Als Hänsel und Grethel in ihre Nähe kamen, da lachte sie boshaft und sprach höhnisch "die habe ich, die sollen mir nicht wieder entwischen." Früh Morgens ehe die Kinder erwacht waren, stand sie schon auf, und als sie beide so lieblich ruhen sah, mit den vollen rothen Backen, so murmelte sie vor sich hin "das wird ein guter Bissen werden." Da packte sie Hänsel mit ihrer dürren Hand und trug ihn in einen kleinen Stall und sperrte ihn mit einer Gitterthüre ein; er mochte schreien wie er wollte, es half ihm nichts. Dann gieng sie zur Grethel, rüttelte
  sie wach und rief "steh auf, Faullenzerin, trag Wasser und koch deinem Bruder etwas gutes, der sitzt draußen im Stall und soll fett werden. Wenn er fett ist, so will ich ihn essen." Grethel fieng an bitterlich zu weinen, aber es war alles vergeblich, sie mußte thun was die böse Hexe verlangte.
+
+Nun ward dem armen Hänsel das beste Essen gekocht, aber Grethel bekam nichts als Krebsschalen. Jeden Morgen schlich die Alte zu dem Ställchen und rief "Hänsel, streck deine Finger heraus, damit ich fühle ob du bald fett bist." Hänsel streckte ihr aber ein Knöchlein heraus, und die Alte, die trübe Augen hatte, konnte es nicht sehen, und meinte es wären Hänsels Finger, und verwunderte sich daß er gar nicht fett werden wollte. Als vier Wochen herum waren und Hänsel immer mager blieb, da übernahm sie die Ungeduld, und sie wollte nicht länger warten. "Heda, Grethel," rief sie dem Mädchen zu, "sei flink und trag Wasser: Hänsel mag fett oder mager sein, morgen will ich ihn schlachten und kochen." Ach, wie jammerte das arme Schwesterchen, als es das Wasser tragen mußte, und wie flossen ihm die Thränen über die Backen herunter! "Lieber Gott, hilf uns doch," rief sie aus, "hätten uns nur die wilden Thiere im Wald gefressen, so wären wir doch zusammen gestorben." "S
 par nur dein Geblärre," sagte die Alte, "es hilft dir alles nichts."
+
+Früh Morgens mußte Grethel heraus, den Kessel mit Wasser aufhängen und Feuer anzünden. "Erst wollen wir backen" sagte die Alte, "ich habe den Backofen schon eingeheizt und den Teig geknätet." Sie stieß das arme Grethel hinaus zu dem Backofen, aus dem die Feuerflammen schon heraus schlugen. "Kriech hinein," sagte die Hexe, "und sieh zu ob recht eingeheizt ist, damit wir das Brot hineinschieben können." Und wenn Grethel darin war, wollte sie den Ofen zumachen, und Grethel sollte darin braten, und dann wollte sies auch aufessen. Aber Grethel merkte was sie im Sinn hatte und sprach "ich weiß nicht wie ichs machen soll; wie komm ich da hinein?" "Dumme Gans," sagte die Alte, "die Öffnung ist groß genug, siehst du wohl, ich könnte selbst hinein," krappelte heran und steckte den Kopf in den Backofen. Da gab ihr Grethel einen Stoß daß sie weit hinein fuhr, machte die eiserne Thür zu und schob den Riegel vor. Hu! da fieng sie an zu heulen, ganz grauselich; aber Grethel l
 ief fort, und die gottlose Hexe mußte elendiglich verbrennen.
+
+Grethel aber lief schnurstracks zum Hänsel, öffnete sein Ställchen und rief "Hänsel, wir sind erlöst, die alte Hexe ist todt." Da sprang Hänsel heraus, wie ein Vogel aus dem Käfig, wenn ihm die Thüre aufgemacht wird. Wie haben sie sich gefreut, sind sich um den Hals gefallen, sind herumgesprungen und haben sich geküßt! Und weil sie sich nicht mehr zu fürchten brauchten, so giengen sie in das Haus der Hexe hinein, da standen in allen Ecken Kasten mit Perlen und Edelsteinen. "Die sind noch besser als Kieselsteine" sagte Hänsel und steckte in seine Taschen was hinein wollte, und Grethel sagte "ich will auch etwas mit nach Haus bringen" und füllte sich sein Schürzchen voll. "Aber jetzt wollen wir fort," sagte Hänsel, "damit wir aus dem Hexenwald herauskommen." Als sie aber ein paar Stunden gegangen waren, gelangten sie an ein großes Wasser. "Wir können nicht hinüber," sprach Hänsel, "ich sehe keinen Steg und keine Brücke." "Hier fährt auch kein Schiffchen," 
 antwortete Grethel, "aber da schwimmt eine weiße Ente, wenn ich die bitte, so hilft sie uns hinüber." Da rief sie
+
+"Entchen, Entchen,
+da steht Grethel und Hänsel.
+Kein Steg und keine Brücke,
+nimm uns auf deinen weißen Rücken."
+
+Das Entchen kam auch heran, und Hänsel setzte sich auf und bat sein Schwesterchen sich zu ihm zu setzen. "Nein," antwortete Grethel, "es wird dem Entchen zu schwer, es soll uns nach einander hinüber bringen." Das that das gute Thierchen, und als sie glücklich drüben waren und ein Weilchen fortgiengen, da kam ihnen der Wald immer bekannter und immer bekannter vor, und endlich erblickten sie von weitem ihres Vaters Haus. Da fiengen sie an zu laufen, stürzten in die Stube hinein und fielen ihrem Vater um den Hals. Der Mann hatte keine frohe Stunde gehabt, seitdem er die Kinder im Walde gelassen hatte, die Frau aber war gestorben. Grethel schüttete sein Schürzchen aus daß die Perlen und Edelsteine in der Stube herumsprangen, und Hänsel warf eine Handvoll nach der andern aus seiner Tasche dazu. Da hatten alle Sorgen ein Ende, und sie lebten in lauter Freude zusammen. Mein Märchen ist aus, dort lauft eine Maus, wer sie fängt, darf sich eine große große Pelzkappe darau
 s machen
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/log4j.properties?rev=1102179&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/log4j.properties (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/resources/log4j.properties Thu May 12 06:25:22 2011
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#      http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# sample log4j.properties
+
+log4j.rootCategory=WARN, R, O
+
+# Stdout
+log4j.appender.O=org.apache.log4j.ConsoleAppender
+
+# File
+log4j.appender.R=org.apache.log4j.RollingFileAppender
+log4j.appender.R.File=log4j.log
+
+# Control the maximum log file size
+log4j.appender.R.MaxFileSize=100KB
+
+# Archive log files (one backup file here)
+log4j.appender.R.MaxBackupIndex=1
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.O.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c: %m%n
+log4j.appender.O.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c: %m%n
+
+log4j.logger.org.apache.chemistry.opencmis.util=INFO