[dna-commits] DNA SVN: r152 - in trunk: sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images and 2 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue May 13 14:30:33 EDT 2008


Author: rhauch
Date: 2008-05-13 14:30:33 -0400 (Tue, 13 May 2008)
New Revision: 152

Added:
   trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
   trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageSequencerI18n.java
   trunk/sequencers/dna-sequencer-images/src/main/resources/org/jboss/dna/sequencer/images/ImageSequencerI18n.properties
   trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
   trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageSequencerI18nTest.java
Modified:
   trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
Log:
Enhanced the image sequencer implementation by adding calls to the progress monitor and adding unit tests.  Also added an I18n class.

Added: trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java	                        (rev 0)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java	2008-05-13 18:30:33 UTC (rev 152)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.sequencers;
+
+import java.util.HashMap;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+
+/**
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class MockSequencerOutput implements SequencerOutput {
+
+    private final Map<String, Object[]> properties;
+    private final Map<String, String[]> references;
+
+    /**
+     * 
+     */
+    public MockSequencerOutput() {
+        this.properties = new HashMap<String, Object[]>();
+        this.references = new HashMap<String, String[]>();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperty( String nodePath, String property, Object... values ) {
+        String key = getKey(nodePath, property);
+        if (values == null || values.length == 0) {
+            this.properties.remove(key);
+        } else {
+            this.properties.put(key, values);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setReference( String nodePath, String property, String... paths ) {
+        String key = getKey(nodePath, property);
+        if (paths == null || paths.length == 0) {
+            this.references.remove(key);
+        } else {
+            this.references.put(key, paths);
+        }
+    }
+
+    public Object[] getPropertyValues( String nodePath, String property ) {
+        String key = getKey(nodePath, property);
+        return this.properties.get(key);
+    }
+
+    public String[] getReferenceValues( String nodePath, String property ) {
+        String key = getKey(nodePath, property);
+        return this.references.get(key);
+    }
+
+    public boolean hasProperty( String nodePath, String property ) {
+        String key = nodePath + "@" + property;
+        return this.properties.containsKey(key);
+    }
+
+    public boolean hasReference( String nodePath, String property ) {
+        String key = nodePath + "@" + property;
+        return this.references.containsKey(key);
+    }
+
+    public boolean hasProperties() {
+        return this.properties.size() > 0;
+    }
+
+    public boolean hasReferences() {
+        return this.references.size() > 0;
+    }
+
+    protected String getKey( String nodePath, String property ) {
+        return nodePath + "@" + property;
+    }
+
+}


Property changes on: trunk/dna-spi/src/test/java/org/jboss/dna/spi/sequencers/MockSequencerOutput.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java	2008-05-13 16:00:15 UTC (rev 151)
+++ trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageMetadataSequencer.java	2008-05-13 18:30:33 UTC (rev 152)
@@ -83,16 +83,21 @@
      * {@inheritDoc}
      */
     public void sequence( InputStream stream, SequencerOutput output, ProgressMonitor progressMonitor ) {
+        progressMonitor.beginTask(10, ImageSequencerI18n.sequencerTaskName);
+
         ImageMetadata metadata = new ImageMetadata();
         metadata.setInput(stream);
         metadata.setDetermineImageNumber(true);
         metadata.setCollectComments(true);
 
-        // Process the image ...
+        // Process the image stream and extract the metadata ...
         if (!metadata.check()) {
             metadata = null;
         }
+        progressMonitor.worked(5);
+        if (progressMonitor.isCancelled()) return;
 
+        // Generate the output graph if we found useful metadata ...
         if (metadata != null) {
             // Place the image metadata into the output map ...
             output.setProperty(METADATA_NODE, IMAGE_PRIMARY_TYPE, "image:metadata");
@@ -110,5 +115,7 @@
             output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_WIDTH_INCHES, metadata.getPhysicalWidthInch());
             output.setProperty(METADATA_NODE, IMAGE_PHYSICAL_HEIGHT_INCHES, metadata.getPhysicalHeightInch());
         }
+
+        progressMonitor.done();
     }
 }

Added: trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageSequencerI18n.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageSequencerI18n.java	                        (rev 0)
+++ trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageSequencerI18n.java	2008-05-13 18:30:33 UTC (rev 152)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.sequencer.images;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ */
+public final class ImageSequencerI18n {
+
+    public static I18n sequencerTaskName;
+
+    static {
+        try {
+            I18n.initialize(ImageSequencerI18n.class);
+        } catch (final Exception err) {
+            System.err.println(err);
+        }
+    }
+
+    public static Set<Locale> getLocalizationProblemLocales() {
+        return I18n.getLocalizationProblemLocales(ImageSequencerI18n.class);
+    }
+
+    public static Set<String> getLocalizationProblems() {
+        return I18n.getLocalizationProblems(ImageSequencerI18n.class);
+    }
+
+    public static Set<String> getLocalizationProblems( Locale locale ) {
+        return I18n.getLocalizationProblems(ImageSequencerI18n.class, locale);
+    }
+}


Property changes on: trunk/sequencers/dna-sequencer-images/src/main/java/org/jboss/dna/sequencer/images/ImageSequencerI18n.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/sequencers/dna-sequencer-images/src/main/resources/org/jboss/dna/sequencer/images/ImageSequencerI18n.properties
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/main/resources/org/jboss/dna/sequencer/images/ImageSequencerI18n.properties	                        (rev 0)
+++ trunk/sequencers/dna-sequencer-images/src/main/resources/org/jboss/dna/sequencer/images/ImageSequencerI18n.properties	2008-05-13 18:30:33 UTC (rev 152)
@@ -0,0 +1 @@
+sequencerTaskName = Processing image contents


Property changes on: trunk/sequencers/dna-sequencer-images/src/main/resources/org/jboss/dna/sequencer/images/ImageSequencerI18n.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java	                        (rev 0)
+++ trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java	2008-05-13 18:30:33 UTC (rev 152)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.sequencer.images;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+import org.jboss.dna.common.monitor.SimpleProgressMonitor;
+import org.jboss.dna.spi.sequencers.MockSequencerOutput;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ImageMetadataSequencerTest {
+
+    private ImageMetadataSequencer sequencer;
+    private InputStream content;
+    private MockSequencerOutput output;
+    private ProgressMonitor progress;
+    private URL cautionGif;
+    private URL cautionJpg;
+    private URL cautionPict;
+    private URL cautionPng;
+
+    @Before
+    public void beforeEach() throws Exception {
+        this.sequencer = new ImageMetadataSequencer();
+        this.output = new MockSequencerOutput();
+        this.progress = new SimpleProgressMonitor("Test activity");
+        this.cautionGif = this.getClass().getClassLoader().getResource("caution.gif");
+        this.cautionJpg = this.getClass().getClassLoader().getResource("caution.jpg");
+        this.cautionPict = this.getClass().getClassLoader().getResource("caution.pict");
+        this.cautionPng = this.getClass().getClassLoader().getResource("caution.png");
+    }
+
+    @After
+    public void afterEach() throws Exception {
+        if (content != null) {
+            try {
+                content.close();
+            } finally {
+                content = null;
+            }
+        }
+    }
+
+    @Test
+    public void shouldGenerateMetadataForJpegImageFiles() throws IOException {
+        URL url = this.cautionJpg;
+        assertThat(url, is(notNullValue()));
+        content = url.openStream();
+        assertThat(content, is(notNullValue()));
+        sequencer.sequence(content, output, progress);
+        assertThat(output.getPropertyValues("image:metadata", "jcr:primaryType"), is(new Object[] {"image:metadata"}));
+        assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/jpeg"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"JPEG"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:width"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:height"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:bitsPerPixel"), is(new Object[] {24}));
+        assertThat(output.getPropertyValues("image:metadata", "image:progressive"), is(new Object[] {false}));
+        assertThat(output.getPropertyValues("image:metadata", "image:numberOfImages"), is(new Object[] {1}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalWidthDpi"), is(new Object[] {72}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {72}));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])).doubleValue(), is(closeTo(0.666667d, 0.0001d)));
+        assertThat(output.hasReferences(), is(false));
+    }
+
+    @Test
+    public void shouldGenerateMetadataForPngImageFiles() throws IOException {
+        URL url = this.cautionPng;
+        assertThat(url, is(notNullValue()));
+        content = url.openStream();
+        assertThat(content, is(notNullValue()));
+        sequencer.sequence(content, output, progress);
+        assertThat(output.getPropertyValues("image:metadata", "jcr:primaryType"), is(new Object[] {"image:metadata"}));
+        assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/png"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"PNG"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:width"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:height"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:bitsPerPixel"), is(new Object[] {24}));
+        assertThat(output.getPropertyValues("image:metadata", "image:progressive"), is(new Object[] {false}));
+        assertThat(output.getPropertyValues("image:metadata", "image:numberOfImages"), is(new Object[] {1}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalWidthDpi"), is(new Object[] {-1}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
+        assertThat(output.hasReferences(), is(false));
+    }
+
+    @Test
+    public void shouldGenerateMetadataForGifImageFiles() throws IOException {
+        URL url = this.cautionGif;
+        assertThat(url, is(notNullValue()));
+        content = url.openStream();
+        assertThat(content, is(notNullValue()));
+        sequencer.sequence(content, output, progress);
+        assertThat(output.getPropertyValues("image:metadata", "jcr:mimeType"), is(new Object[] {"image/gif"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:formatName"), is(new Object[] {"GIF"}));
+        assertThat(output.getPropertyValues("image:metadata", "image:width"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:height"), is(new Object[] {48}));
+        assertThat(output.getPropertyValues("image:metadata", "image:bitsPerPixel"), is(new Object[] {8}));
+        assertThat(output.getPropertyValues("image:metadata", "image:progressive"), is(new Object[] {false}));
+        assertThat(output.getPropertyValues("image:metadata", "image:numberOfImages"), is(new Object[] {1}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalWidthDpi"), is(new Object[] {-1}));
+        assertThat(output.getPropertyValues("image:metadata", "image:physicalHeightDpi"), is(new Object[] {-1}));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalWidthInches")[0])), is(-1f));
+        assertThat(((Float)(output.getPropertyValues("image:metadata", "image:physicalHeightInches")[0])), is(-1f));
+        assertThat(output.hasReferences(), is(false));
+    }
+
+    @Test
+    public void shouldGenerateNoMetadataforPictImageFiles() throws IOException {
+        URL url = this.cautionPict;
+        assertThat(url, is(notNullValue()));
+        content = url.openStream();
+        assertThat(content, is(notNullValue()));
+        sequencer.sequence(content, output, progress);
+        assertThat(output.hasProperties(), is(false));
+        assertThat(output.hasReferences(), is(false));
+
+    }
+}


Property changes on: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageMetadataSequencerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageSequencerI18nTest.java
===================================================================
--- trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageSequencerI18nTest.java	                        (rev 0)
+++ trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageSequencerI18nTest.java	2008-05-13 18:30:33 UTC (rev 152)
@@ -0,0 +1,13 @@
+package org.jboss.dna.sequencer.images;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author John Verhaeg
+ */
+public class ImageSequencerI18nTest extends AbstractI18nTest {
+
+    public ImageSequencerI18nTest() {
+        super(ImageSequencerI18n.class);
+    }
+}


Property changes on: trunk/sequencers/dna-sequencer-images/src/test/java/org/jboss/dna/sequencer/images/ImageSequencerI18nTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list