xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r734638 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/image/loader/ src/java/org/apache/xmlgraphics/image/loader/impl/ test/java/org/apache/xmlgraphics/image/loader/
Date Thu, 15 Jan 2009 09:19:32 GMT
Author: jeremias
Date: Thu Jan 15 01:19:32 2009
New Revision: 734638

URL: http://svn.apache.org/viewvc?rev=734638&view=rev
Log:
Extended ImageFlavor to provide direct access to MIME type and XML namespace URI if applicable.

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageFlavor.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/MimeEnabledImageFlavor.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/RefinedImageFlavor.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/XMLNamespaceEnabledImageFlavor.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageLoader.java
    xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
    xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageFlavor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageFlavor.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageFlavor.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageFlavor.java
Thu Jan 15 01:19:32 2009
@@ -34,8 +34,10 @@
     /** An image in form of a BufferedImage instance */
     public static final ImageFlavor BUFFERED_IMAGE = new SimpleRefinedImageFlavor(
                                                             RENDERED_IMAGE, "BufferedImage");
+    /** An image in form of a W3C DOM instance */
+    private static final ImageFlavor DOM = new ImageFlavor("DOM");
     /** An XML-based image in form of a W3C DOM instance */
-    public static final ImageFlavor XML_DOM = new ImageFlavor("text/xml;form=dom");
+    public static final ImageFlavor XML_DOM = new MimeEnabledImageFlavor(DOM, "text/xml");
     /** An image in form of a raw PNG file/stream */
     public static final ImageFlavor RAW = new ImageFlavor("Raw");
     /** An image in form of a raw PNG file/stream */
@@ -74,6 +76,26 @@
     }
 
     /**
+     * Returns the MIME type that the image flavor represents if a MIME type is available.
This
+     * is only applicable to images which can also exist as files. For images flavors like
+     * decoded in-memory images (Rendered/BufferedImage), this method will return null.
+     * @return the MIME type or null if no MIME type can be provided (like for in-memory
images)
+     */
+    public String getMimeType() {
+        return null;
+    }
+
+    /**
+     * Returns the XML namespace URI that the image flavor represents if such a namespace
URI
+     * is available. This is only applicable to images in XML form. Other image types will
return
+     * null.
+     * @return the XML or null if no MIME type can be provided (like for in-memory images)
+     */
+    public String getNamespace() {
+        return null;
+    }
+
+    /**
      * Indicates whether a particular image flavor is compatible with this one.
      * @param flavor the other image flavor
      * @return true if the two are compatible

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/MimeEnabledImageFlavor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/MimeEnabledImageFlavor.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/MimeEnabledImageFlavor.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/MimeEnabledImageFlavor.java
Thu Jan 15 01:19:32 2009
@@ -36,11 +36,8 @@
         this.mime = mime;
     }
 
-    /**
-     * Returns the MIME type associated with the image flavor.
-     * @return the MIME type
-     */
-    public String getMIMEType() {
+    /** {@inheritDoc} */
+    public String getMimeType() {
         return this.mime;
     }
 

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/RefinedImageFlavor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/RefinedImageFlavor.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/RefinedImageFlavor.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/RefinedImageFlavor.java
Thu Jan 15 01:19:32 2009
@@ -54,6 +54,16 @@
     }
 
     /** {@inheritDoc} */
+    public String getMimeType() {
+        return this.parentFlavor.getMimeType();
+    }
+
+    /** {@inheritDoc} */
+    public String getNamespace() {
+        return this.parentFlavor.getNamespace();
+    }
+
+    /** {@inheritDoc} */
     public boolean isCompatible(ImageFlavor flavor) {
         return getParentFlavor().isCompatible(flavor)
             || super.isCompatible(flavor);

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/XMLNamespaceEnabledImageFlavor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/XMLNamespaceEnabledImageFlavor.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/XMLNamespaceEnabledImageFlavor.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/XMLNamespaceEnabledImageFlavor.java
Thu Jan 15 01:19:32 2009
@@ -27,7 +27,7 @@
     /** An XML-based SVG image in form of a W3C DOM instance */
     public static final ImageFlavor SVG_DOM = new XMLNamespaceEnabledImageFlavor(
             ImageFlavor.XML_DOM, "http://www.w3.org/2000/svg");
-    
+
     private String namespace;
 
     /**
@@ -40,10 +40,7 @@
         this.namespace = namespace;
     }
 
-    /**
-     * Returns the XML namespace URI associated with the image flavor.
-     * @return the XML namespace URI
-     */
+    /** {@inheritDoc} */
     public String getNamespace() {
         return this.namespace;
     }

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageLoader.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageLoader.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageLoader.java
Thu Jan 15 01:19:32 2009
@@ -5,9 +5,9 @@
  * 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.
@@ -34,7 +34,7 @@
  */
 public abstract class AbstractImageLoader implements ImageLoader {
 
-    /** {@inheritDoc} */ 
+    /** {@inheritDoc} */
     public Image loadImage(ImageInfo info, ImageSessionContext session)
                 throws ImageException, IOException {
         return loadImage(info, null, session);
@@ -42,7 +42,7 @@
 
     /** {@inheritDoc} */
     public int getUsagePenalty() {
-        return 0;
+        return MEDIUM_LOADING_PENALTY;
     }
 
     /**

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
(original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
Thu Jan 15 01:19:32 2009
@@ -21,6 +21,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.xmlgraphics.util.MimeConstants;
+
 /**
  * Tests for image flavors.
  */
@@ -32,10 +34,16 @@
         f1 = ImageFlavor.RAW_JPEG;
         f2 = ImageFlavor.RAW_PNG;
         assertFalse(f1.equals(f2));
+        assertEquals(MimeConstants.MIME_JPEG, f1.getMimeType());
+        assertNull(f1.getNamespace());
+        assertEquals(MimeConstants.MIME_PNG, f2.getMimeType());
+        assertNull(f2.getNamespace());
 
         f1 = ImageFlavor.GRAPHICS2D;
         f2 = new ImageFlavor(ImageFlavor.GRAPHICS2D.getName());
         assertTrue(f1.equals(f2));
+        assertNull(f1.getMimeType());
+        assertNull(f1.getNamespace());
     }
 
     public void testRefinedFlavors() throws Exception {
@@ -47,11 +55,21 @@
         assertTrue(f2.isCompatible(f1));
         assertFalse(f1.isCompatible(f2));
 
+        assertNull(f1.getMimeType());
+        assertNull(f1.getNamespace());
+        assertNull(f2.getMimeType());
+        assertNull(f2.getNamespace());
+
         f1 = ImageFlavor.XML_DOM;
         f2 = new XMLNamespaceEnabledImageFlavor(ImageFlavor.XML_DOM, "http://www.w3.org/2000/svg");
         assertFalse(f1.equals(f2));
         assertTrue(f2.isCompatible(f1));
         assertFalse(f1.isCompatible(f2));
+
+        assertEquals("text/xml", f1.getMimeType());
+        assertNull(f1.getNamespace());
+        assertEquals("text/xml", f2.getMimeType());
+        assertEquals("http://www.w3.org/2000/svg", f2.getNamespace());
     }
 
 }

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java?rev=734638&r1=734637&r2=734638&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java
(original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java
Thu Jan 15 01:19:32 2009
@@ -32,6 +32,7 @@
 import org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline;
 import org.apache.xmlgraphics.image.loader.spi.ImageLoader;
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.util.MimeConstants;
 
 /**
  * Tests for the image pipeline functionality.
@@ -39,58 +40,67 @@
 public class ImagePipelineTestCase extends TestCase {
 
     private MockImageContext imageContext = MockImageContext.getInstance();
-    
+
     public ImagePipelineTestCase(String name) {
         super(name);
     }
-    
+
     public void testPipelineWithLoader() throws Exception {
         String uri = "bgimg72dpi.gif";
 
         ImageSessionContext sessionContext = imageContext.newSessionContext();
         ImageManager manager = imageContext.getImageManager();
-        
+
         ImageInfo info = manager.preloadImage(uri, sessionContext);
         assertNotNull("ImageInfo must not be null", info);
-        
+
         ImageLoader loader = new ImageLoaderImageIO(ImageFlavor.RENDERED_IMAGE);
         ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), loader);
         pipeline.addConverter(new ImageConverterRendered2PNG());
-        
+
         Image img = pipeline.execute(info, null, sessionContext);
         assertNotNull("Image must not be null", img);
         assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
         assertTrue(img instanceof ImageRawStream);
+
+        //Original MIME type stays the same, but the flavor MIME changes
+        assertEquals(MimeConstants.MIME_GIF, img.getInfo().getMimeType());
+        assertEquals(MimeConstants.MIME_PNG, img.getFlavor().getMimeType());
     }
-    
+
     public void testPipelineWithoutLoader() throws Exception {
 
         ImageSessionContext sessionContext = imageContext.newSessionContext();
         ImageManager manager = imageContext.getImageManager();
 
         Image original = createG2DImage();
-        
+
         ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), null);
         pipeline.addConverter(new ImageConverterG2D2Bitmap());
         pipeline.addConverter(new ImageConverterBuffered2Rendered());
         pipeline.addConverter(new ImageConverterRendered2PNG());
-        
+
         Image img = pipeline.execute(original.getInfo(), original, null,
                 sessionContext);
         assertNotNull("Image must not be null", img);
         assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
         assertTrue(img instanceof ImageRawStream);
+
+        //Original MIME type stays the same, but the flavor MIME changes
+        assertNull(img.getInfo().getMimeType());
+        assertEquals(MimeConstants.MIME_PNG, img.getFlavor().getMimeType());
+
     }
-    
+
     private Image createG2DImage() {
         Graphics2DImagePainter painter = new DemoPainter();
         Dimension dim = painter.getImageSize();
-        
+
         ImageSize size = new ImageSize();
         size.setSizeInMillipoints(dim.width, dim.height);
         size.setResolution(72);
         size.calcPixelsFromSize();
-        
+
         ImageInfo info = new ImageInfo(null /*null is the intention here*/, null);
         info.setSize(size);
         ImageGraphics2D g2dImage = new ImageGraphics2D(info, painter);
@@ -99,7 +109,7 @@
 
     public void testPipelineFromURIThroughManager() throws Exception {
         String uri = "asf-logo.png";
-        
+
         ImageSessionContext sessionContext = imageContext.newSessionContext();
         ImageManager manager = imageContext.getImageManager();
 
@@ -110,25 +120,25 @@
                 ImageFlavor.RAW_PNG, ImageFlavor.RAW_JPEG
         };
         Image img = manager.getImage(info, flavors, sessionContext);
-        
+
         assertNotNull("Image must not be null", img);
         assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
         assertTrue(img instanceof ImageRawStream);
     }
-    
+
     public void testPipelineWithoutURIThroughManager() throws Exception {
         ImageManager manager = imageContext.getImageManager();
-        
+
         Image original = createG2DImage();
 
         ImageFlavor[] flavors = new ImageFlavor[] {
                 ImageFlavor.RAW_PNG, ImageFlavor.RAW_JPEG
         };
         Image img = manager.convertImage(original, flavors);
-        
+
         assertNotNull("Image must not be null", img);
         assertEquals(ImageFlavor.RAW_PNG, img.getFlavor());
         assertTrue(img instanceof ImageRawStream);
     }
-    
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message