xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r991835 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java status.xml
Date Thu, 02 Sep 2010 07:53:28 GMT
Author: jeremias
Date: Thu Sep  2 07:53:28 2010
New Revision: 991835

URL: http://svn.apache.org/viewvc?rev=991835&view=rev
Log:
Bugzilla #49696:
Allow to override priority when registering an ImageWriter on the ImageWriterRegistry.
Submitted by: Joshua Marquart <joshua.marquart.at.firstdata.com>

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java?rev=991835&r1=991834&r2=991835&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java
Thu Sep  2 07:53:28 2010
@@ -25,7 +25,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Properties;
 
 import org.apache.xmlgraphics.util.Service;
@@ -39,7 +38,7 @@ public class ImageWriterRegistry {
 
     private static ImageWriterRegistry instance;
 
-    private Map imageWriterMap = new HashMap();
+    private Map imageWriterMap = new java.util.HashMap();
     private Map preferredOrder;
 
     /**
@@ -108,8 +107,24 @@ public class ImageWriterRegistry {
     }
 
     /**
+     * Registers a new ImageWriter implementation with the associated priority in the registry.
+     * Higher priorities get preference over lower priorities.
+     * @param writer the ImageWriter instance to register.
+     * @param priority the priority of the writer in the registry.
+     * @see #register(ImageWriter)
+     */
+    public void register(ImageWriter writer, int priority) {
+
+    	String key = writer.getClass().getName();
+    	// Register the priority to preferredOrder; overwrite original priority if exists
+    	preferredOrder.put(key, String.valueOf(priority));
+
+    	register(writer);
+    }
+
+    /**
      * Registers a new ImageWriter implementation in the registry. If an ImageWriter for
the same
-     * target MIME type has already been registered, it is overwritten with the new one.
+     * target MIME type has already been registered, it is placed in an array based on priority.
      * @param writer the ImageWriter instance to register.
      */
     public void register(ImageWriter writer) {
@@ -120,14 +135,13 @@ public class ImageWriterRegistry {
         }
 
         int priority = getPriority(writer);
-        ListIterator li;
-        li = entries.listIterator();
+
+    	ListIterator li = entries.listIterator();
         while (li.hasNext()) {
             ImageWriter w = (ImageWriter)li.next();
             if (getPriority(w) < priority) {
                 li.previous();
-                li.add(writer);
-                return;
+                break;
             }
         }
         li.add(writer);
@@ -136,8 +150,8 @@ public class ImageWriterRegistry {
     /**
      * Returns an ImageWriter that can be used to encode an image to the requested MIME type.
      * @param mime the MIME type of the desired output format
-     * @return an ImageWriter instance handling the desired output format or null if none
can be
-     *         found.
+     * @return a functional ImageWriter instance handling the desired output format or
+     *         null if none can be found.
      */
     public ImageWriter getWriterFor(String mime) {
         List entries = (List)imageWriterMap.get(mime);

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=991835&r1=991834&r2=991835&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Thu Sep  2 07:53:28 2010
@@ -40,6 +40,9 @@
   </contexts>
   <changes>
     <release version="Trunk" date="n/a">
+      <action context="Code" dev="JM" type="fix" fixes-bug="49696" due-to="Joshua Marquart">
+        Allow to override priority when registering an ImageWriter on the ImageWriterRegistry.
+      </action>
       <action context="Code" dev="JM" type="fix">
         Fix for TIFFs which report zero as their resolution. This resulted in an exception.
       </action>



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


Mime
View raw message