kinow commented on a change in pull request #5: Proposal for a patch for 
Imaging-159 using a POJO
URL: https://github.com/apache/commons-imaging/pull/5#discussion_r370990102
 
 

 ##########
 File path: src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
 ##########
 @@ -513,25 +497,36 @@ public void writeImage(final BufferedImage src, final 
OutputStream os, Map<Strin
                         (byte) 1);
             }
         }
-
-        if (params.containsKey(ImagingConstants.PARAM_KEY_XMP_XML)) {
-            final String xmpXml = (String) 
params.get(ImagingConstants.PARAM_KEY_XMP_XML);
+        
+        // care about XMP XML if provided by parameter 
+        if (parameters.isXmpXmlAsStringPresent()) {
+            final String xmpXml = parameters.getXmpXmlAsString();
             writeChunkXmpiTXt(os, xmpXml);
         }
-
-        if (params.containsKey(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS)) {
-            final List<?> outputTexts = (List<?>) 
params.get(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS);
-            for (Object outputText : outputTexts) {
-                final PngText text = (PngText) outputText;
-                if (text instanceof PngText.Text) {
-                    writeChunktEXt(os, (PngText.Text) text);
-                } else if (text instanceof PngText.Ztxt) {
-                    writeChunkzTXt(os, (PngText.Ztxt) text);
-                } else if (text instanceof PngText.Itxt) {
-                    writeChunkiTXt(os, (PngText.Itxt) text);
-                } else {
-                    throw new ImageWriteException(
-                            "Unknown text to embed in PNG: " + text);
+        
+        // text chunks are parameters specific for PNG images
+        // so we need to ask first if parameters specific for PNG images are 
provided
+        // than ask for text chunks
+        if (parameters instanceof ImagingParametersPng) {
 
 Review comment:
   Would be good if generics could be used here to avoid the `instanceof`, or 
another way to model objects.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to