You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/04/28 18:33:39 UTC
svn commit: r1331791 [12/12] - in /chemistry/opencmis/trunk: ./
chemistry-opencmis-client/chemistry-opencmis-client-bindings/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/cache...
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.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/fractal/FractalGenerator.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java Sat Apr 28 16:33:35 2012
@@ -1,490 +1,490 @@
-////////////////////////////////////////////////////////////////////////////////
-/*
- * 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.
- */
-
-/*
- * Original code inspired by work from David Lebernight
- * see: http://www.gui.net/fractal.html
- * email as requested in original source has been sent,
- * to david@leberknight.com, but address is invalid (2012-02-07)
- */
-
-package org.apache.chemistry.opencmis.util.content.fractal;
-
-import java.awt.Color;
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Random;
-
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
-import javax.imageio.stream.ImageOutputStream;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-public class FractalGenerator {
- private static final Log LOG = LogFactory.getLog(FractalGenerator.class);
-
- private final static int ZOOM_STEPS_PER_BATCH = 10;
- private final static int DEFAULT_MAX_ITERATIONS = 33;
- private final static ComplexRectangle INITIAL_RECT = new ComplexRectangle(-2.1, 1.1, -1.3, 1.3);
- private final static ComplexRectangle INITIAL_JULIA_RECT = new ComplexRectangle(-2.0, 2.0, -2.0, 2.0);
- private final static int INITIAL_ITERATIONS = 33;
-
- // Color:
- private Map<String, int[]> colorTable;
- private final String COLORS_BLACK_AND_WHITE = "black & white";
- private final String COLORS_BLUE_ICE = "blue ice";
- private final String COLORS_FUNKY = "funky";
- private final String COLORS_PASTEL = "pastel";
- private final String COLORS_PSYCHEDELIC = "psychedelic";
- private final String COLORS_PURPLE_HAZE = "purple haze";
- private final String COLORS_RADICAL = "radical";
- private final String COLORS_RAINBOW = "rainbow";
- private final String COLORS_RAINBOWS = "rainbows";
- private final String COLORS_SCINTILLATION = "scintillation";
- private final String COLORS_WARPED = "warped";
- private final String COLORS_WILD = "wild";
- private final String COLORS_ZEBRA = "zebra";
- private final String[] colorSchemes = {COLORS_BLACK_AND_WHITE, COLORS_BLUE_ICE, COLORS_FUNKY, COLORS_PASTEL,
- COLORS_PSYCHEDELIC, COLORS_PURPLE_HAZE, COLORS_RADICAL, COLORS_RAINBOW, COLORS_RAINBOWS,
- COLORS_SCINTILLATION, COLORS_WARPED, COLORS_WILD, COLORS_ZEBRA};
- private final int imageHeight = 512; // default
- private final int imageWidth = 512; // default
- private final int numColors = 512; // colors per colormap
- private FractalCalculator calculator;
- private int previousIterations = 1;
- private int maxIterations;
- String color;
- int counter = 0;
- int newRowTile, newColTile;
- int parts = 16;
- private int stepInBatch = 0;
- ComplexRectangle rect;
- ComplexPoint juliaPoint;
-
- public FractalGenerator() {
- reset();
- }
-
- private void reset() {
- rect = new ComplexRectangle(-1.6, -1.2, -0.1, 0.1);
- juliaPoint = null; // new ComplexPoint();
- maxIterations = DEFAULT_MAX_ITERATIONS;
-
- Random ran = new Random();
- color = colorSchemes[ran.nextInt(colorSchemes.length)];
- parts = ran.nextInt(13)+3;
- LOG.debug("Parts: " + parts);
- maxIterations = DEFAULT_MAX_ITERATIONS;
- LOG.debug("Original rect " + ": (" + rect.getRMin() + "r," + rect.getRMax() +
- "r, " + rect.getIMin() + "i, " + rect.getIMax() + "i)");
- randomizeRect(rect);
- }
-
- public ByteArrayOutputStream generateFractal() throws IOException {
- ByteArrayOutputStream bos = null;
-
- if (stepInBatch == ZOOM_STEPS_PER_BATCH) {
- stepInBatch = 0;
- reset();
- }
-
- ++stepInBatch;
- LOG.debug("Generating rect no " + stepInBatch + ": (" + rect.getRMin() + "r," +
- rect.getRMax() + "r, " + rect.getIMin() + "i, " + rect.getIMax() + "i)");
- LOG.debug(" width: " + rect.getWidth() + " height: " + rect.getHeight());
- bos = genFractal(rect, juliaPoint);
-
- double r1New = rect.getWidth() * newColTile / parts + rect.getRMin();
- double r2New = rect.getWidth() * (newColTile+1) / parts + rect.getRMin();
- double i1New = rect.getIMax() - (rect.getHeight() * newRowTile / parts);
- double i2New = rect.getIMax() - (rect.getHeight() * (newRowTile+1) / parts);
- rect.set(r1New, r2New, i1New, i2New);
- randomizeRect(rect);
- LOG.debug("Done generating fractals.");
-
- return bos;
- }
-
- private void randomizeRect( ComplexRectangle rect) {
- double jitterFactor = 0.15; // +/- 15%
- double ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
- double width = rect.getWidth() * ran;
- ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
- double height = rect.getHeight() * ran;
- ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
- double r1 = (rect.getWidth() - width) * ran + rect.getRMin();
- ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
- double i1 = (rect.getHeight() - height) * ran + rect.getIMin();
- rect.set(r1, r1+width, i1, i1+height);
- }
-
- /**
- * Create a fractal image as JPEG in memory and return it
- * @param rect
- * rectangle of mandelbrot or julia set
- * @param juliaPoint
- * point in Julia set or null
- * @return
- * byte array with JPEG stream
- * @throws IOException
- */
- public ByteArrayOutputStream genFractal(ComplexRectangle rect, ComplexPoint juliaPoint) throws IOException {
-
- boolean isJulia = null != juliaPoint;
- expandRectToFitImage(rect);
- initializeColors();
-
- maxIterations = maybeGuessMaxIterations(maxIterations, rect, isJulia);
- LOG.debug("using " + maxIterations + " iterations.");
- detectDeepZoom(rect);
-
- calculator = new FractalCalculator(rect, maxIterations, imageWidth, imageHeight, getCurrentColorMap(),
- juliaPoint);
- int[][] iterations = calculator.calcFractal();
- BufferedImage image = calculator.mapItersToColors(iterations);
- findNewRect(image, iterations);
-
- // fast method to write to a file with default options
- // ImageIO.write((BufferedImage)(image), "jpg", new File("fractal-" + counter++ + ".jpg"));
-
- // create image in memory
- ByteArrayOutputStream bos = new ByteArrayOutputStream(200*1024);
- ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
- Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName( "jpg" );
- ImageWriter imageWriter = writers.next();
-
- JPEGImageWriteParam params = new JPEGImageWriteParam( Locale.getDefault() );
- params.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
- params.setCompressionQuality( 0.9f );
-
- imageWriter.setOutput( ios );
- imageWriter.write( null, new IIOImage( image, null, null ), params );
- ios.close();
-
- // write memory block to a file
- // String fileName = String.format(pattern, counter++);
- // FileOutputStream outputStream = new FileOutputStream (fileName);
- // bos.writeTo(outputStream);
- // bos.close();
- // outputStream.close();
-
- return bos;
- }
-
- protected int[] getCurrentColorMap() {
- return colorTable.get(getColor());
- }
-
- protected String getColor() {
- return color;
- }
-
- protected void expandRectToFitImage(ComplexRectangle complexRect) {
- // The complex rectangle must be scaled to fit the pixel image view.
- // Method: compare the width/height ratios of the two rectangles.
- double imageWHRatio = 1.0;
- double complexWHRatio = 1.0;
- double iMin = complexRect.getIMin();
- double iMax = complexRect.getIMax();
- double rMin = complexRect.getRMin();
- double rMax = complexRect.getRMax();
- double complexWidth = rMax - rMin;
- double complexHeight = iMax - iMin;
-
- if ((imageWidth != 0) && (imageHeight != 0)) {
- imageWHRatio = ((double) imageWidth / (double) imageHeight);
- } else
- return;
-
- if ((complexWidth != 0) && (complexHeight != 0)) {
- complexWHRatio = complexWidth / complexHeight;
- } else
- return;
-
- if (imageWHRatio == complexWHRatio)
- return;
-
- if (imageWHRatio < complexWHRatio) {
- // Expand vertically
- double newHeight = complexWidth / imageWHRatio;
- double heightDifference = Math.abs(newHeight - complexHeight);
- iMin = iMin - heightDifference / 2;
- iMax = iMax + heightDifference / 2;
- } else {
- // Expand horizontally
- double newWidth = complexHeight * imageWHRatio;
- double widthDifference = Math.abs(newWidth - complexWidth);
- rMin = rMin - widthDifference / 2;
- rMax = rMax + widthDifference / 2;
- }
- complexRect.set(rMin, rMax, iMin, iMax);
- }
-
- private int guessNewMaxIterations(ComplexRectangle cr, boolean isJulia) {
- // The higher the zoom factor, the more iterations that are needed to
- // see
- // the detail. Guess at a number to produce a cool looking fractal:
- double zoom = INITIAL_RECT.getWidth() / cr.getWidth();
- if (zoom < 1.0) {
- zoom = 1.0; // forces logZoom >= 0
- }
- double logZoom = Math.log(zoom);
- double magnitude = (logZoom / 2.3) - 2.0; // just a guess.
- if (magnitude < 1.0) {
- magnitude = 1.0;
- }
- double iterations = INITIAL_ITERATIONS * (magnitude * logZoom + 1.0);
- if (isJulia)
- iterations *= 2.0; // Julia sets tend to need more iterations.
- return (int) iterations;
- }
-
- private int maybeGuessMaxIterations(int maxIterations, ComplexRectangle cr, boolean isJulia) {
- // If the user did not change the number of iterations, make a guess...
- if (previousIterations == maxIterations) {
- maxIterations = guessNewMaxIterations(cr, isJulia);
- }
- previousIterations = maxIterations;
- return maxIterations;
- }
-
- private boolean detectDeepZoom(ComplexRectangle cr) {
- // "Deep Zoom" occurs when the precision provided by the Java type
- // double
- // runs out of resolution. The use of BigDecimal is required to fix
- // this.
- double deltaDiv2 = cr.getWidth() / ((imageWidth) * 2.0);
- String min = "" + (cr.getRMin());
- String minPlus = "" + (cr.getRMin() + deltaDiv2);
-
- if (Double.valueOf(min).doubleValue() == Double.valueOf(minPlus).doubleValue()) {
- LOG.warn("Deep Zoom... Drawing resolution will be degraded ;-(");
- return true;
- }
- return false;
- }
-
- private void initializeColors() {
- colorTable = new HashMap<String, int[]>();
-
- int red = 255;
- int green = 255;
- int blue = 255;
-
- float hue = (float) 1.0;
- float saturation = (float) 1.0;
- float brightness = (float) 1.0;
-
- // COLORS_BLACK_AND_WHITE:
- int[] colorMap = new int[numColors];
- for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
- colorMap[colorNum] = Color.white.getRGB();
- }
- colorTable.put(COLORS_BLACK_AND_WHITE, colorMap);
-
- // COLORS_BLUE_ICE:
- blue = 255;
- colorMap = new int[numColors];
- for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
- red = (int) ((255 * (float) colorNum / numColors)) % 255;
- green = (int) ((255 * (float) colorNum / numColors)) % 255;
- colorMap[colorNum] = new Color(red, green, blue).getRGB();
- }
- colorTable.put(COLORS_BLUE_ICE, colorMap);
-
- // COLORS_FUNKY:
- colorMap = new int[numColors];
- for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
- red = (int) ((1024 * (float) colorNum / numColors)) % 255;
- green = (int) ((512 * (float) colorNum / numColors)) % 255;
- blue = (int) ((256 * (float) colorNum / numColors)) % 255;
- colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
- }
- colorTable.put(COLORS_FUNKY, colorMap);
-
- // COLORS_PASTEL
- brightness = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 4) / (float) numColors) % numColors;
- saturation = ((float) (colorNum * 2) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_PASTEL, colorMap);
-
- // COLORS_PSYCHEDELIC:
- saturation = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 5) / (float) numColors) % numColors;
- brightness = ((float) (colorNum * 20) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_PSYCHEDELIC, colorMap);
-
- // COLORS_PURPLE_HAZE:
- red = 255;
- blue = 255;
- colorMap = new int[numColors];
- for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
- green = (int) ((255 * (float) colorNum / numColors)) % 255;
- colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
- }
- colorTable.put(COLORS_PURPLE_HAZE, colorMap);
-
- // COLORS_RADICAL:
- saturation = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 7) / (float) numColors) % numColors;
- brightness = ((float) (colorNum * 49) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_RADICAL, colorMap);
-
- // COLORS_RAINBOW:
- saturation = (float) 1.0;
- brightness = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = (float) colorNum / (float) numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_RAINBOW, colorMap);
-
- // COLORS_RAINBOWS:
- saturation = (float) 1.0;
- brightness = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 5) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_RAINBOWS, colorMap);
-
- // COLORS_SCINTILLATION
- brightness = (float) 1.0;
- saturation = (float) 1.0;
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 2) / (float) numColors) % numColors;
- brightness = ((float) (colorNum * 5) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_SCINTILLATION, colorMap);
-
- // COLORS_WARPED:
- colorMap = new int[numColors];
- for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
- red = (int) ((1024 * (float) colorNum / numColors)) % 255;
- green = (int) ((256 * (float) colorNum / numColors)) % 255;
- blue = (int) ((512 * (float) colorNum / numColors)) % 255;
- colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
- }
- colorTable.put(COLORS_WARPED, colorMap);
-
- // COLORS_WILD:
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- hue = ((float) (colorNum * 1) / (float) numColors) % numColors;
- saturation = ((float) (colorNum * 2) / (float) numColors) % numColors;
- brightness = ((float) (colorNum * 4) / (float) numColors) % numColors;
- colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
- }
- colorTable.put(COLORS_WILD, colorMap);
-
- // COLORS_ZEBRA:
- colorMap = new int[numColors];
- for (int colorNum = 0; colorNum < numColors; colorNum++) {
- if (colorNum % 2 == 0) {
- colorMap[colorNum] = Color.white.getRGB();
- ;
- } else {
- colorMap[colorNum] = Color.black.getRGB();
- ;
- }
- }
- colorTable.put(COLORS_ZEBRA, colorMap);
- }
-
-
- private void findNewRect(BufferedImage image, int[][] iterations) {
-
- int newWidth = image.getWidth() / parts;
- int newHeight = image.getHeight() / parts;
- int i=0, j=0;
- int noTiles = (image.getWidth() / newWidth) * (image.getHeight() / newHeight); // equals parts but be aware of rounding errors!;
- double[] stdDev = new double [noTiles];
-
- for (int y = 0; y+newHeight <= image.getHeight(); y+=newHeight) {
- for (int x = 0; x+newWidth <= image.getWidth(); x+=newWidth) {
- Rectangle subRect = new Rectangle(x, y, newWidth, newHeight);
- stdDev[i*parts+j] = calcStdDev(iterations, subRect);
- ++j;
- }
- ++i;
- j=0;
- }
-
- // find tile with greatest std deviation:
- double max = 0;
- int index = 0;
- for (i=0; i<noTiles; i++) {
- if (stdDev[i] > max) {
- index = i;
- max = stdDev[i];
- }
- }
- newRowTile = index / parts;
- newColTile = index % parts;
- }
-
- private double calcStdDev(int[][] iterations, Rectangle rect) {
-
- int sum=0;
- long sumSquare=0;
-
- for (int x = rect.x; x < rect.x+rect.width; x+=1) {
- for (int y = rect.y; y < rect.y+rect.height; y+=1) {
- int iters = iterations[x][y];
- sum +=iters;
- sumSquare +=iters*iters;
- }
- }
- int count = rect.width * rect.height;
- double mean = 0.0;
-
- mean = sum / count;
- return Math.sqrt(sumSquare/count - (mean * mean));
- }
-
-}
+////////////////////////////////////////////////////////////////////////////////
+/*
+ * 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.
+ */
+
+/*
+ * Original code inspired by work from David Lebernight
+ * see: http://www.gui.net/fractal.html
+ * email as requested in original source has been sent,
+ * to david@leberknight.com, but address is invalid (2012-02-07)
+ */
+
+package org.apache.chemistry.opencmis.util.content.fractal;
+
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+
+import javax.imageio.IIOImage;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.ImageWriter;
+import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
+import javax.imageio.stream.ImageOutputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class FractalGenerator {
+ private static final Logger LOG = LoggerFactory.getLogger(FractalGenerator.class);
+
+ private final static int ZOOM_STEPS_PER_BATCH = 10;
+ private final static int DEFAULT_MAX_ITERATIONS = 33;
+ private final static ComplexRectangle INITIAL_RECT = new ComplexRectangle(-2.1, 1.1, -1.3, 1.3);
+ private final static ComplexRectangle INITIAL_JULIA_RECT = new ComplexRectangle(-2.0, 2.0, -2.0, 2.0);
+ private final static int INITIAL_ITERATIONS = 33;
+
+ // Color:
+ private Map<String, int[]> colorTable;
+ private final String COLORS_BLACK_AND_WHITE = "black & white";
+ private final String COLORS_BLUE_ICE = "blue ice";
+ private final String COLORS_FUNKY = "funky";
+ private final String COLORS_PASTEL = "pastel";
+ private final String COLORS_PSYCHEDELIC = "psychedelic";
+ private final String COLORS_PURPLE_HAZE = "purple haze";
+ private final String COLORS_RADICAL = "radical";
+ private final String COLORS_RAINBOW = "rainbow";
+ private final String COLORS_RAINBOWS = "rainbows";
+ private final String COLORS_SCINTILLATION = "scintillation";
+ private final String COLORS_WARPED = "warped";
+ private final String COLORS_WILD = "wild";
+ private final String COLORS_ZEBRA = "zebra";
+ private final String[] colorSchemes = {COLORS_BLACK_AND_WHITE, COLORS_BLUE_ICE, COLORS_FUNKY, COLORS_PASTEL,
+ COLORS_PSYCHEDELIC, COLORS_PURPLE_HAZE, COLORS_RADICAL, COLORS_RAINBOW, COLORS_RAINBOWS,
+ COLORS_SCINTILLATION, COLORS_WARPED, COLORS_WILD, COLORS_ZEBRA};
+ private final int imageHeight = 512; // default
+ private final int imageWidth = 512; // default
+ private final int numColors = 512; // colors per colormap
+ private FractalCalculator calculator;
+ private int previousIterations = 1;
+ private int maxIterations;
+ String color;
+ int counter = 0;
+ int newRowTile, newColTile;
+ int parts = 16;
+ private int stepInBatch = 0;
+ ComplexRectangle rect;
+ ComplexPoint juliaPoint;
+
+ public FractalGenerator() {
+ reset();
+ }
+
+ private void reset() {
+ rect = new ComplexRectangle(-1.6, -1.2, -0.1, 0.1);
+ juliaPoint = null; // new ComplexPoint();
+ maxIterations = DEFAULT_MAX_ITERATIONS;
+
+ Random ran = new Random();
+ color = colorSchemes[ran.nextInt(colorSchemes.length)];
+ parts = ran.nextInt(13)+3;
+ LOG.debug("Parts: " + parts);
+ maxIterations = DEFAULT_MAX_ITERATIONS;
+ LOG.debug("Original rect " + ": (" + rect.getRMin() + "r," + rect.getRMax() +
+ "r, " + rect.getIMin() + "i, " + rect.getIMax() + "i)");
+ randomizeRect(rect);
+ }
+
+ public ByteArrayOutputStream generateFractal() throws IOException {
+ ByteArrayOutputStream bos = null;
+
+ if (stepInBatch == ZOOM_STEPS_PER_BATCH) {
+ stepInBatch = 0;
+ reset();
+ }
+
+ ++stepInBatch;
+ LOG.debug("Generating rect no " + stepInBatch + ": (" + rect.getRMin() + "r," +
+ rect.getRMax() + "r, " + rect.getIMin() + "i, " + rect.getIMax() + "i)");
+ LOG.debug(" width: " + rect.getWidth() + " height: " + rect.getHeight());
+ bos = genFractal(rect, juliaPoint);
+
+ double r1New = rect.getWidth() * newColTile / parts + rect.getRMin();
+ double r2New = rect.getWidth() * (newColTile+1) / parts + rect.getRMin();
+ double i1New = rect.getIMax() - (rect.getHeight() * newRowTile / parts);
+ double i2New = rect.getIMax() - (rect.getHeight() * (newRowTile+1) / parts);
+ rect.set(r1New, r2New, i1New, i2New);
+ randomizeRect(rect);
+ LOG.debug("Done generating fractals.");
+
+ return bos;
+ }
+
+ private void randomizeRect( ComplexRectangle rect) {
+ double jitterFactor = 0.15; // +/- 15%
+ double ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
+ double width = rect.getWidth() * ran;
+ ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
+ double height = rect.getHeight() * ran;
+ ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
+ double r1 = (rect.getWidth() - width) * ran + rect.getRMin();
+ ran = Math.random() * jitterFactor + (1.0 - jitterFactor);
+ double i1 = (rect.getHeight() - height) * ran + rect.getIMin();
+ rect.set(r1, r1+width, i1, i1+height);
+ }
+
+ /**
+ * Create a fractal image as JPEG in memory and return it
+ * @param rect
+ * rectangle of mandelbrot or julia set
+ * @param juliaPoint
+ * point in Julia set or null
+ * @return
+ * byte array with JPEG stream
+ * @throws IOException
+ */
+ public ByteArrayOutputStream genFractal(ComplexRectangle rect, ComplexPoint juliaPoint) throws IOException {
+
+ boolean isJulia = null != juliaPoint;
+ expandRectToFitImage(rect);
+ initializeColors();
+
+ maxIterations = maybeGuessMaxIterations(maxIterations, rect, isJulia);
+ LOG.debug("using " + maxIterations + " iterations.");
+ detectDeepZoom(rect);
+
+ calculator = new FractalCalculator(rect, maxIterations, imageWidth, imageHeight, getCurrentColorMap(),
+ juliaPoint);
+ int[][] iterations = calculator.calcFractal();
+ BufferedImage image = calculator.mapItersToColors(iterations);
+ findNewRect(image, iterations);
+
+ // fast method to write to a file with default options
+ // ImageIO.write((BufferedImage)(image), "jpg", new File("fractal-" + counter++ + ".jpg"));
+
+ // create image in memory
+ ByteArrayOutputStream bos = new ByteArrayOutputStream(200*1024);
+ ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName( "jpg" );
+ ImageWriter imageWriter = writers.next();
+
+ JPEGImageWriteParam params = new JPEGImageWriteParam( Locale.getDefault() );
+ params.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
+ params.setCompressionQuality( 0.9f );
+
+ imageWriter.setOutput( ios );
+ imageWriter.write( null, new IIOImage( image, null, null ), params );
+ ios.close();
+
+ // write memory block to a file
+ // String fileName = String.format(pattern, counter++);
+ // FileOutputStream outputStream = new FileOutputStream (fileName);
+ // bos.writeTo(outputStream);
+ // bos.close();
+ // outputStream.close();
+
+ return bos;
+ }
+
+ protected int[] getCurrentColorMap() {
+ return colorTable.get(getColor());
+ }
+
+ protected String getColor() {
+ return color;
+ }
+
+ protected void expandRectToFitImage(ComplexRectangle complexRect) {
+ // The complex rectangle must be scaled to fit the pixel image view.
+ // Method: compare the width/height ratios of the two rectangles.
+ double imageWHRatio = 1.0;
+ double complexWHRatio = 1.0;
+ double iMin = complexRect.getIMin();
+ double iMax = complexRect.getIMax();
+ double rMin = complexRect.getRMin();
+ double rMax = complexRect.getRMax();
+ double complexWidth = rMax - rMin;
+ double complexHeight = iMax - iMin;
+
+ if ((imageWidth != 0) && (imageHeight != 0)) {
+ imageWHRatio = ((double) imageWidth / (double) imageHeight);
+ } else
+ return;
+
+ if ((complexWidth != 0) && (complexHeight != 0)) {
+ complexWHRatio = complexWidth / complexHeight;
+ } else
+ return;
+
+ if (imageWHRatio == complexWHRatio)
+ return;
+
+ if (imageWHRatio < complexWHRatio) {
+ // Expand vertically
+ double newHeight = complexWidth / imageWHRatio;
+ double heightDifference = Math.abs(newHeight - complexHeight);
+ iMin = iMin - heightDifference / 2;
+ iMax = iMax + heightDifference / 2;
+ } else {
+ // Expand horizontally
+ double newWidth = complexHeight * imageWHRatio;
+ double widthDifference = Math.abs(newWidth - complexWidth);
+ rMin = rMin - widthDifference / 2;
+ rMax = rMax + widthDifference / 2;
+ }
+ complexRect.set(rMin, rMax, iMin, iMax);
+ }
+
+ private int guessNewMaxIterations(ComplexRectangle cr, boolean isJulia) {
+ // The higher the zoom factor, the more iterations that are needed to
+ // see
+ // the detail. Guess at a number to produce a cool looking fractal:
+ double zoom = INITIAL_RECT.getWidth() / cr.getWidth();
+ if (zoom < 1.0) {
+ zoom = 1.0; // forces logZoom >= 0
+ }
+ double logZoom = Math.log(zoom);
+ double magnitude = (logZoom / 2.3) - 2.0; // just a guess.
+ if (magnitude < 1.0) {
+ magnitude = 1.0;
+ }
+ double iterations = INITIAL_ITERATIONS * (magnitude * logZoom + 1.0);
+ if (isJulia)
+ iterations *= 2.0; // Julia sets tend to need more iterations.
+ return (int) iterations;
+ }
+
+ private int maybeGuessMaxIterations(int maxIterations, ComplexRectangle cr, boolean isJulia) {
+ // If the user did not change the number of iterations, make a guess...
+ if (previousIterations == maxIterations) {
+ maxIterations = guessNewMaxIterations(cr, isJulia);
+ }
+ previousIterations = maxIterations;
+ return maxIterations;
+ }
+
+ private boolean detectDeepZoom(ComplexRectangle cr) {
+ // "Deep Zoom" occurs when the precision provided by the Java type
+ // double
+ // runs out of resolution. The use of BigDecimal is required to fix
+ // this.
+ double deltaDiv2 = cr.getWidth() / ((imageWidth) * 2.0);
+ String min = "" + (cr.getRMin());
+ String minPlus = "" + (cr.getRMin() + deltaDiv2);
+
+ if (Double.valueOf(min).doubleValue() == Double.valueOf(minPlus).doubleValue()) {
+ LOG.warn("Deep Zoom... Drawing resolution will be degraded ;-(");
+ return true;
+ }
+ return false;
+ }
+
+ private void initializeColors() {
+ colorTable = new HashMap<String, int[]>();
+
+ int red = 255;
+ int green = 255;
+ int blue = 255;
+
+ float hue = (float) 1.0;
+ float saturation = (float) 1.0;
+ float brightness = (float) 1.0;
+
+ // COLORS_BLACK_AND_WHITE:
+ int[] colorMap = new int[numColors];
+ for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
+ colorMap[colorNum] = Color.white.getRGB();
+ }
+ colorTable.put(COLORS_BLACK_AND_WHITE, colorMap);
+
+ // COLORS_BLUE_ICE:
+ blue = 255;
+ colorMap = new int[numColors];
+ for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
+ red = (int) ((255 * (float) colorNum / numColors)) % 255;
+ green = (int) ((255 * (float) colorNum / numColors)) % 255;
+ colorMap[colorNum] = new Color(red, green, blue).getRGB();
+ }
+ colorTable.put(COLORS_BLUE_ICE, colorMap);
+
+ // COLORS_FUNKY:
+ colorMap = new int[numColors];
+ for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
+ red = (int) ((1024 * (float) colorNum / numColors)) % 255;
+ green = (int) ((512 * (float) colorNum / numColors)) % 255;
+ blue = (int) ((256 * (float) colorNum / numColors)) % 255;
+ colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
+ }
+ colorTable.put(COLORS_FUNKY, colorMap);
+
+ // COLORS_PASTEL
+ brightness = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 4) / (float) numColors) % numColors;
+ saturation = ((float) (colorNum * 2) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_PASTEL, colorMap);
+
+ // COLORS_PSYCHEDELIC:
+ saturation = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 5) / (float) numColors) % numColors;
+ brightness = ((float) (colorNum * 20) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_PSYCHEDELIC, colorMap);
+
+ // COLORS_PURPLE_HAZE:
+ red = 255;
+ blue = 255;
+ colorMap = new int[numColors];
+ for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
+ green = (int) ((255 * (float) colorNum / numColors)) % 255;
+ colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
+ }
+ colorTable.put(COLORS_PURPLE_HAZE, colorMap);
+
+ // COLORS_RADICAL:
+ saturation = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 7) / (float) numColors) % numColors;
+ brightness = ((float) (colorNum * 49) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_RADICAL, colorMap);
+
+ // COLORS_RAINBOW:
+ saturation = (float) 1.0;
+ brightness = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = (float) colorNum / (float) numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_RAINBOW, colorMap);
+
+ // COLORS_RAINBOWS:
+ saturation = (float) 1.0;
+ brightness = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 5) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_RAINBOWS, colorMap);
+
+ // COLORS_SCINTILLATION
+ brightness = (float) 1.0;
+ saturation = (float) 1.0;
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 2) / (float) numColors) % numColors;
+ brightness = ((float) (colorNum * 5) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_SCINTILLATION, colorMap);
+
+ // COLORS_WARPED:
+ colorMap = new int[numColors];
+ for (int colorNum = numColors - 1; colorNum >= 0; colorNum--) {
+ red = (int) ((1024 * (float) colorNum / numColors)) % 255;
+ green = (int) ((256 * (float) colorNum / numColors)) % 255;
+ blue = (int) ((512 * (float) colorNum / numColors)) % 255;
+ colorMap[numColors - colorNum - 1] = new Color(red, green, blue).getRGB();
+ }
+ colorTable.put(COLORS_WARPED, colorMap);
+
+ // COLORS_WILD:
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ hue = ((float) (colorNum * 1) / (float) numColors) % numColors;
+ saturation = ((float) (colorNum * 2) / (float) numColors) % numColors;
+ brightness = ((float) (colorNum * 4) / (float) numColors) % numColors;
+ colorMap[colorNum] = Color.HSBtoRGB(hue, saturation, brightness);
+ }
+ colorTable.put(COLORS_WILD, colorMap);
+
+ // COLORS_ZEBRA:
+ colorMap = new int[numColors];
+ for (int colorNum = 0; colorNum < numColors; colorNum++) {
+ if (colorNum % 2 == 0) {
+ colorMap[colorNum] = Color.white.getRGB();
+ ;
+ } else {
+ colorMap[colorNum] = Color.black.getRGB();
+ ;
+ }
+ }
+ colorTable.put(COLORS_ZEBRA, colorMap);
+ }
+
+
+ private void findNewRect(BufferedImage image, int[][] iterations) {
+
+ int newWidth = image.getWidth() / parts;
+ int newHeight = image.getHeight() / parts;
+ int i=0, j=0;
+ int noTiles = (image.getWidth() / newWidth) * (image.getHeight() / newHeight); // equals parts but be aware of rounding errors!;
+ double[] stdDev = new double [noTiles];
+
+ for (int y = 0; y+newHeight <= image.getHeight(); y+=newHeight) {
+ for (int x = 0; x+newWidth <= image.getWidth(); x+=newWidth) {
+ Rectangle subRect = new Rectangle(x, y, newWidth, newHeight);
+ stdDev[i*parts+j] = calcStdDev(iterations, subRect);
+ ++j;
+ }
+ ++i;
+ j=0;
+ }
+
+ // find tile with greatest std deviation:
+ double max = 0;
+ int index = 0;
+ for (i=0; i<noTiles; i++) {
+ if (stdDev[i] > max) {
+ index = i;
+ max = stdDev[i];
+ }
+ }
+ newRowTile = index / parts;
+ newColTile = index % parts;
+ }
+
+ private double calcStdDev(int[][] iterations, Rectangle rect) {
+
+ int sum=0;
+ long sumSquare=0;
+
+ for (int x = rect.x; x < rect.x+rect.width; x+=1) {
+ for (int y = rect.y; y < rect.y+rect.height; y+=1) {
+ int iters = iterations[x][y];
+ sum +=iters;
+ sumSquare +=iters*iters;
+ }
+ }
+ int count = rect.width * rect.height;
+ double mean = 0.0;
+
+ mean = sum / count;
+ return Math.sqrt(sumSquare/count - (mean * mean));
+ }
+
+}
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=1331791&r1=1331790&r2=1331791&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 Sat Apr 28 16:33:35 2012
@@ -51,8 +51,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
import org.apache.chemistry.opencmis.util.content.fractal.FractalGenerator;
import org.apache.chemistry.opencmis.util.content.loremipsum.LoremIpsum;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A simple helper class for the tests that generates a sample folder hierarchy
@@ -63,7 +63,7 @@ import org.apache.commons.logging.LogFac
*/
public class ObjectGenerator {
- private static final Log log = LogFactory.getLog(ObjectGenerator.class);
+ private static final Logger log = LoggerFactory.getLogger(ObjectGenerator.class);
private final BindingsObjectFactory fFactory;
NavigationService fNavSvc;
ObjectService fObjSvc;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.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/TimeLogger.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java Sat Apr 28 16:33:35 2012
@@ -20,8 +20,8 @@ package org.apache.chemistry.opencmis.ut
import java.util.LinkedList;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple utility class for time logging Note: NOT thread safe!
@@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFac
*
*/
public class TimeLogger {
- private static final Log LOG = LogFactory.getLog(TimeLogger.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TimeLogger.class);
private static class TimeRecord {
public long fStart;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/loremipsum/LoremIpsumTest.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/loremipsum/LoremIpsumTest.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/loremipsum/LoremIpsumTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/test/java/org/apache/chemistry/opencmis/util/content/loremipsum/LoremIpsumTest.java Sat Apr 28 16:33:35 2012
@@ -1,401 +1,401 @@
-/*
- * 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.loremipsum;
-
-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.chemistry.opencmis.util.content.loremipsum.LoremIpsum;
-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 LoremIpsumTest {
-
- private static final Log LOG = LogFactory.getLog(LoremIpsumTest.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";
- LoremIpsum generator = new LoremIpsum(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, LoremIpsum.mean(ia1), 0.01d);
- int[] ia2 = {6, 6, 4, 4};
- assertEquals(5.0d, LoremIpsum.mean(ia2), 0.01d);
- }
-
- @Test
- public void test_mean_empty() {
- int[] ia1 = {};
- assertEquals(0.0d, LoremIpsum.mean(ia1), 0.01d);
- }
-
- @Test
- public void test_variance() {
- double[] ia1 = {6.0d, 6.0d, 4.0d, 4.0d};
- assertEquals(1.0d, LoremIpsum.variance(ia1), 0.01d);
- double[] ia2 = {1.0d, 2.0d, 3.0d, 4.0d};
- assertEquals(1.25d, LoremIpsum.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, LoremIpsum.sigma(ia1), 0.01d);
- assertEquals(Math.sqrt(1.25), LoremIpsum.sigma(ia2), 0.01d);
- }
-
- @Test
- public void test_sigma_empty() {
- int[] ia1 = {};
- assertEquals(0.0d, LoremIpsum.sigma(ia1), 0.01d);
- }
-
- @Test
- public void test_split_sentences() {
- String[] sentences1 = {"Hello", "Hi"};
- assertArrayEquals (sentences1, LoremIpsum.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, LoremIpsum.splitSentences(sample));
- }
-
- @Test
- public void test_split_sentences_empty() {
- String[] sentences = {};
- assertArrayEquals(sentences, LoremIpsum.splitSentences(""));
- }
-
- @Test
- public void test_split_sentences_trailing() {
- String[] sentences1 = {"Hello", "Hi", "Hello"};
- assertArrayEquals(sentences1, LoremIpsum.splitSentences("Hello. Hi. Hello"));
- String[] sentences2 = {"Hello", "Hi", "Hello"};
- assertArrayEquals(sentences2, LoremIpsum.splitSentences(" Hello. Hi. Hello "));
- String[] sentences3 = {"Hello", "Hi", "Hello"};
- assertArrayEquals(sentences3, LoremIpsum.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, LoremIpsum.splitParagraphs(sample));
- }
-
- @Test
- public void test_split_paragraphs_empty() {
- String[] paragraphs = {};
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs(""));
- }
-
- @Test
- public void test_split_paragraphs_trailing() {
- String[] paragraphs = {"Hello", "Hi"};
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n\n"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n\n\n\n\n"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\nHello\n\nHi"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\nHello\n\nHi"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\n\nHello\n\nHi"));
- assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\n\n\n\n\nHello\n\nHi"));
- }
-
- @Test
- public void test_split_words() {
- String[] words = {"One", "two", "three", "four"};
- assertArrayEquals(words, LoremIpsum.splitWords("One two three four"));
- assertArrayEquals(words, LoremIpsum.splitWords(" One two three four "));
- }
-
- @Test
- public void test_split_words_empty() {
- String[] words = {};
- assertArrayEquals(words, LoremIpsum.splitWords(""));
- }
-
- @Test
- public void test_choose_closest() {
- Integer[] intArray1 ={1,2,3,4};
- assertEquals(1, LoremIpsum.chooseClosest(intArray1, 1));
- Integer[] intArray2 ={1,2,3,4};
- assertEquals(4, LoremIpsum.chooseClosest(intArray2, 4));
- assertEquals(4, LoremIpsum.chooseClosest(intArray2, 20));
- assertEquals(1, LoremIpsum.chooseClosest(intArray2, -10));
- Integer[] intArray3 ={1,4};
- assertEquals(1, LoremIpsum.chooseClosest(intArray3, 2));
- assertEquals(4, LoremIpsum.chooseClosest(intArray3, 3));
- Integer[] intArray4 ={1,3};
- assertEquals(1, LoremIpsum.chooseClosest(intArray4, 2));
- Integer[] intArray5 ={3,1};
- assertEquals(3, LoremIpsum.chooseClosest(intArray5, 2));
- Integer[] intArray6 ={1};
- assertEquals(1, LoremIpsum.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 LoremIpsum(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 LoremIpsum(sample, dict);
- generator.generateParagraph(false);
- fail("Dictionary " + dict + " should generate exception.");
- } catch (RuntimeException e) {
- assertEquals(e.getMessage(), "Invalid dictionary.");
- }
- }
-
- @Test
- public void testGenerate() {
- LOG.debug("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.debug(newParagraphs[i]);
- LOG.debug("");
- }
- 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.debug("Generate new Lore Ipsum text: ");
- LoremIpsum ipsum = new LoremIpsum();
- String[] newParagraphs = new String[4];
- for (int i=0; i<newParagraphs.length; i++) {
- newParagraphs[i] = ipsum.generateParagraph(false);
- LOG.debug(newParagraphs[i]);
- LOG.debug("");
- LOG.debug("");
- }
- }
-
- @Test
- public void testGenerateLoreIpsumHtml1() {
- LOG.debug("Generate new Lore Ipsum as html paragraphs:");
- LoremIpsum ipsum = new LoremIpsum();
- String output = ipsum.generateParagraphsHtml(2048, true);
- LOG.debug(output);
- LOG.debug("");
- }
-
- @Test
- public void testGenerateLoreIpsumHtml2() {
- LOG.debug("Generate new Lore Ipsum as one html paragraph:");
- LoremIpsum ipsum = new LoremIpsum();
- String output = ipsum.generateOneParagraphHtml(2048, true);
- LOG.debug(output);
- LOG.debug("");
- }
-
- @Test
- public void testGenerateLoreIpsumHtml3() {
- LOG.debug("Generate new Lore Ipsum as full html document: ");
- LoremIpsum ipsum = new LoremIpsum();
- String output = ipsum.generateParagraphsFullHtml(2048, true);
- LOG.debug(output);
- LOG.debug("");
- }
-
- @Test
- public void testGenerateLoreIpsumPlainText() {
- LOG.debug("Generate new Lore Ipsum as plain text: ");
- LoremIpsum ipsum = new LoremIpsum();
- String output = ipsum.generateParagraphsPlainText(2048, true);
- LOG.debug(output);
- LOG.debug("");
- }
-
- @Test
- public void testGenerateLoreIpsumPlainTextFormatted() {
- LOG.debug("Generate new Lore Ipsum as plain text with 60 columns: ");
- LoremIpsum ipsum = new LoremIpsum();
- String output = ipsum.generateParagraphsPlainText(256, 60, false);
- LOG.debug(output);
- LOG.debug("");
- }
-
- @Test
- public void testGenerateLoreIpsumHtml1Writer() throws IOException {
- LOG.debug("Generate new Lore Ipsum as html paragraphs with PrintWriter:");
- LoremIpsum ipsum = new LoremIpsum();
- StringWriter writer = new StringWriter();
- ipsum.generateParagraphsHtml(writer, 2048, true);
- LOG.debug(writer.toString());
- LOG.debug("End Test.");
- }
-
- @Test
- public void testGenerateLoreIpsumHtml2Writer() throws IOException {
- LOG.debug("Generate new Lore Ipsum as full html paragraph with PrintWriter:");
- LoremIpsum ipsum = new LoremIpsum();
- StringWriter writer = new StringWriter();
- ipsum.generateParagraphsFullHtml(writer, 2048, true);
- LOG.debug(writer.toString());
- LOG.debug("End Test.");
- }
-
- @Test
- public void testGenerateLoreIpsumPlainTextWriter() throws IOException {
- LOG.debug("Generate new Lore Ipsum as plain text with PrintWriter: ");
- LoremIpsum ipsum = new LoremIpsum();
- StringWriter writer = new StringWriter();
- ipsum.generateParagraphsPlainText(writer, 2048, true);
- LOG.debug(writer.toString());
- LOG.debug("End Test.");
- }
-
- @Test
- public void testGenerateLoreIpsumPlainTextFormattedWriter() throws IOException {
- LOG.debug("Generate new Lore Ipsum as plain text with 60 columns with PrintWriter: ");
- LoremIpsum ipsum = new LoremIpsum();
- StringWriter writer = new StringWriter();
- ipsum.generateParagraphsPlainText(writer, 256, 60, false);
- LOG.debug(writer.toString());
- LOG.debug("End Test.");
- }
-
- @Test
- public void testGenerateLoreIpsumGerman() throws Exception {
- LOG.debug("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);
-
-
- LoremIpsum ipsum = new LoremIpsum(sample.toString());
- String output = ipsum.generateParagraphsPlainText(4096, 80, false);
- LOG.debug(output);
- LOG.debug("End Test.");
- }
-
-}
+/*
+ * 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.loremipsum;
+
+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.chemistry.opencmis.util.content.loremipsum.LoremIpsum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoremIpsumTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LoremIpsumTest.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";
+ LoremIpsum generator = new LoremIpsum(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, LoremIpsum.mean(ia1), 0.01d);
+ int[] ia2 = {6, 6, 4, 4};
+ assertEquals(5.0d, LoremIpsum.mean(ia2), 0.01d);
+ }
+
+ @Test
+ public void test_mean_empty() {
+ int[] ia1 = {};
+ assertEquals(0.0d, LoremIpsum.mean(ia1), 0.01d);
+ }
+
+ @Test
+ public void test_variance() {
+ double[] ia1 = {6.0d, 6.0d, 4.0d, 4.0d};
+ assertEquals(1.0d, LoremIpsum.variance(ia1), 0.01d);
+ double[] ia2 = {1.0d, 2.0d, 3.0d, 4.0d};
+ assertEquals(1.25d, LoremIpsum.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, LoremIpsum.sigma(ia1), 0.01d);
+ assertEquals(Math.sqrt(1.25), LoremIpsum.sigma(ia2), 0.01d);
+ }
+
+ @Test
+ public void test_sigma_empty() {
+ int[] ia1 = {};
+ assertEquals(0.0d, LoremIpsum.sigma(ia1), 0.01d);
+ }
+
+ @Test
+ public void test_split_sentences() {
+ String[] sentences1 = {"Hello", "Hi"};
+ assertArrayEquals (sentences1, LoremIpsum.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, LoremIpsum.splitSentences(sample));
+ }
+
+ @Test
+ public void test_split_sentences_empty() {
+ String[] sentences = {};
+ assertArrayEquals(sentences, LoremIpsum.splitSentences(""));
+ }
+
+ @Test
+ public void test_split_sentences_trailing() {
+ String[] sentences1 = {"Hello", "Hi", "Hello"};
+ assertArrayEquals(sentences1, LoremIpsum.splitSentences("Hello. Hi. Hello"));
+ String[] sentences2 = {"Hello", "Hi", "Hello"};
+ assertArrayEquals(sentences2, LoremIpsum.splitSentences(" Hello. Hi. Hello "));
+ String[] sentences3 = {"Hello", "Hi", "Hello"};
+ assertArrayEquals(sentences3, LoremIpsum.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, LoremIpsum.splitParagraphs(sample));
+ }
+
+ @Test
+ public void test_split_paragraphs_empty() {
+ String[] paragraphs = {};
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs(""));
+ }
+
+ @Test
+ public void test_split_paragraphs_trailing() {
+ String[] paragraphs = {"Hello", "Hi"};
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n\n"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("Hello\n\nHi\n\n\n\n\n\n"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\nHello\n\nHi"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\nHello\n\nHi"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\n\nHello\n\nHi"));
+ assertArrayEquals(paragraphs, LoremIpsum.splitParagraphs("\n\n\n\n\n\nHello\n\nHi"));
+ }
+
+ @Test
+ public void test_split_words() {
+ String[] words = {"One", "two", "three", "four"};
+ assertArrayEquals(words, LoremIpsum.splitWords("One two three four"));
+ assertArrayEquals(words, LoremIpsum.splitWords(" One two three four "));
+ }
+
+ @Test
+ public void test_split_words_empty() {
+ String[] words = {};
+ assertArrayEquals(words, LoremIpsum.splitWords(""));
+ }
+
+ @Test
+ public void test_choose_closest() {
+ Integer[] intArray1 ={1,2,3,4};
+ assertEquals(1, LoremIpsum.chooseClosest(intArray1, 1));
+ Integer[] intArray2 ={1,2,3,4};
+ assertEquals(4, LoremIpsum.chooseClosest(intArray2, 4));
+ assertEquals(4, LoremIpsum.chooseClosest(intArray2, 20));
+ assertEquals(1, LoremIpsum.chooseClosest(intArray2, -10));
+ Integer[] intArray3 ={1,4};
+ assertEquals(1, LoremIpsum.chooseClosest(intArray3, 2));
+ assertEquals(4, LoremIpsum.chooseClosest(intArray3, 3));
+ Integer[] intArray4 ={1,3};
+ assertEquals(1, LoremIpsum.chooseClosest(intArray4, 2));
+ Integer[] intArray5 ={3,1};
+ assertEquals(3, LoremIpsum.chooseClosest(intArray5, 2));
+ Integer[] intArray6 ={1};
+ assertEquals(1, LoremIpsum.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 LoremIpsum(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 LoremIpsum(sample, dict);
+ generator.generateParagraph(false);
+ fail("Dictionary " + dict + " should generate exception.");
+ } catch (RuntimeException e) {
+ assertEquals(e.getMessage(), "Invalid dictionary.");
+ }
+ }
+
+ @Test
+ public void testGenerate() {
+ LOG.debug("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.debug(newParagraphs[i]);
+ LOG.debug("");
+ }
+ 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.debug("Generate new Lore Ipsum text: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ String[] newParagraphs = new String[4];
+ for (int i=0; i<newParagraphs.length; i++) {
+ newParagraphs[i] = ipsum.generateParagraph(false);
+ LOG.debug(newParagraphs[i]);
+ LOG.debug("");
+ LOG.debug("");
+ }
+ }
+
+ @Test
+ public void testGenerateLoreIpsumHtml1() {
+ LOG.debug("Generate new Lore Ipsum as html paragraphs:");
+ LoremIpsum ipsum = new LoremIpsum();
+ String output = ipsum.generateParagraphsHtml(2048, true);
+ LOG.debug(output);
+ LOG.debug("");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumHtml2() {
+ LOG.debug("Generate new Lore Ipsum as one html paragraph:");
+ LoremIpsum ipsum = new LoremIpsum();
+ String output = ipsum.generateOneParagraphHtml(2048, true);
+ LOG.debug(output);
+ LOG.debug("");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumHtml3() {
+ LOG.debug("Generate new Lore Ipsum as full html document: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ String output = ipsum.generateParagraphsFullHtml(2048, true);
+ LOG.debug(output);
+ LOG.debug("");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumPlainText() {
+ LOG.debug("Generate new Lore Ipsum as plain text: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ String output = ipsum.generateParagraphsPlainText(2048, true);
+ LOG.debug(output);
+ LOG.debug("");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumPlainTextFormatted() {
+ LOG.debug("Generate new Lore Ipsum as plain text with 60 columns: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ String output = ipsum.generateParagraphsPlainText(256, 60, false);
+ LOG.debug(output);
+ LOG.debug("");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumHtml1Writer() throws IOException {
+ LOG.debug("Generate new Lore Ipsum as html paragraphs with PrintWriter:");
+ LoremIpsum ipsum = new LoremIpsum();
+ StringWriter writer = new StringWriter();
+ ipsum.generateParagraphsHtml(writer, 2048, true);
+ LOG.debug(writer.toString());
+ LOG.debug("End Test.");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumHtml2Writer() throws IOException {
+ LOG.debug("Generate new Lore Ipsum as full html paragraph with PrintWriter:");
+ LoremIpsum ipsum = new LoremIpsum();
+ StringWriter writer = new StringWriter();
+ ipsum.generateParagraphsFullHtml(writer, 2048, true);
+ LOG.debug(writer.toString());
+ LOG.debug("End Test.");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumPlainTextWriter() throws IOException {
+ LOG.debug("Generate new Lore Ipsum as plain text with PrintWriter: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ StringWriter writer = new StringWriter();
+ ipsum.generateParagraphsPlainText(writer, 2048, true);
+ LOG.debug(writer.toString());
+ LOG.debug("End Test.");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumPlainTextFormattedWriter() throws IOException {
+ LOG.debug("Generate new Lore Ipsum as plain text with 60 columns with PrintWriter: ");
+ LoremIpsum ipsum = new LoremIpsum();
+ StringWriter writer = new StringWriter();
+ ipsum.generateParagraphsPlainText(writer, 256, 60, false);
+ LOG.debug(writer.toString());
+ LOG.debug("End Test.");
+ }
+
+ @Test
+ public void testGenerateLoreIpsumGerman() throws Exception {
+ LOG.debug("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);
+
+
+ LoremIpsum ipsum = new LoremIpsum(sample.toString());
+ String output = ipsum.generateParagraphsPlainText(4096, 80, false);
+ LOG.debug(output);
+ LOG.debug("End Test.");
+ }
+
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/pom.xml?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/pom.xml (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/pom.xml Sat Apr 28 16:33:35 2012
@@ -229,6 +229,11 @@
<version>1.8.6</version>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</version>
+ </dependency>
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ChangeLogFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ChangeLogFrame.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ChangeLogFrame.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ChangeLogFrame.java Sat Apr 28 16:33:35 2012
@@ -48,7 +48,7 @@ public class ChangeLogFrame extends JFra
private static final long serialVersionUID = 1L;
- private static final String WINDOW_TITLE = "CMIS Change Log";
+ private static final String WINDOW_TITLE = "CMIS Change Logger";
private final ClientModel model;
@@ -72,7 +72,7 @@ public class ChangeLogFrame extends JFra
JPanel inputPanel = new JPanel(new BorderLayout());
inputPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
- inputPanel.add(new JLabel("Change Log Token: "), BorderLayout.LINE_START);
+ inputPanel.add(new JLabel("Change Logger Token: "), BorderLayout.LINE_START);
changeLogTokenField = new JTextField();
try {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java Sat Apr 28 16:33:35 2012
@@ -161,7 +161,7 @@ public class ClientFrame extends JFrame
toolBar.add(toolbarButton[BUTTON_QUERY]);
- toolbarButton[BUTTON_CHANGELOG] = new JButton("Change Log", ClientHelper.getIcon("changelog.png"));
+ toolbarButton[BUTTON_CHANGELOG] = new JButton("Change Logger", ClientHelper.getIcon("changelog.png"));
toolbarButton[BUTTON_CHANGELOG].setEnabled(false);
toolbarButton[BUTTON_CHANGELOG].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java Sat Apr 28 16:33:35 2012
@@ -81,15 +81,15 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
import org.apache.chemistry.opencmis.commons.impl.MimeTypes;
import org.apache.chemistry.opencmis.workbench.model.ClientModel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ClientHelper {
public static final Color LINK_COLOR = new Color(105, 29, 21);
public static final Color LINK_SELECTED_COLOR = new Color(255, 255, 255);
- private static final Log log = LogFactory.getLog(ClientHelper.class);
+ private static final Logger log = LoggerFactory.getLogger(ClientHelper.class);
private static final int BUFFER_SIZE = 64 * 1024;
private ClientHelper() {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java Sat Apr 28 16:33:35 2012
@@ -331,7 +331,7 @@ public class LoginDialog extends JDialog
boolean browser = (bc == 'b');
bindingAtomButton = new JRadioButton("AtomPub", atom);
bindingWebServicesButton = new JRadioButton("Web Services", ws);
- bindingBrowserButton = new JRadioButton("Browser (experimental)", browser);
+ bindingBrowserButton = new JRadioButton("Browser", browser);
ButtonGroup bindingGroup = new ButtonGroup();
bindingGroup.add(bindingAtomButton);
bindingGroup.add(bindingWebServicesButton);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/RepositoryInfoFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/RepositoryInfoFrame.java?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/RepositoryInfoFrame.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/RepositoryInfoFrame.java Sat Apr 28 16:33:35 2012
@@ -112,7 +112,7 @@ public class RepositoryInfoFrame extends
if (repInfo.getCapabilities() != null) {
RepositoryCapabilities cap = repInfo.getCapabilities();
- addLine("Capabilities", true).setText("");
+ addLine("Capabilities:", true).setText("");
addYesNoLabel("Get descendants supported:").setValue(is(cap.isGetDescendantsSupported()));
addYesNoLabel("Get folder tree supported:").setValue(is(cap.isGetFolderTreeSupported()));
Modified: chemistry/opencmis/trunk/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/pom.xml?rev=1331791&r1=1331790&r2=1331791&view=diff
==============================================================================
--- chemistry/opencmis/trunk/pom.xml (original)
+++ chemistry/opencmis/trunk/pom.xml Sat Apr 28 16:33:35 2012
@@ -430,21 +430,9 @@
<dependencies>
<dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- </dependency>
-
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.16</version>
- <scope>test</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>