You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/02/04 22:41:19 UTC

[Bug 58917] [Patch] AddContentType failing to add new content type to docx for JPEG/image if one already exists for jpg

https://bz.apache.org/bugzilla/show_bug.cgi?id=58917

Scull.sarah@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #2 from Scull.sarah@gmail.com ---
I replaced the existing method...

    public void addContentType(PackagePartName partName, String contentType) {
        boolean defaultCTExists =
this.defaultContentType.containsValue(contentType);
        String extension = partName.getExtension().toLowerCase(Locale.ROOT);
        if ((extension.length() == 0)
                || (this.defaultContentType.containsKey(extension) &&
!defaultCTExists))
            this.addOverrideContentType(partName, contentType);
        else if (!defaultCTExists)
            this.addDefaultContentType(extension, contentType);
    }

with...

    public void addContentType(final PackagePartName partName, final String
contentType) {
        final String extension =
partName.getExtension().toLowerCase(Locale.ROOT);
        if (extension.length() == 0) {
            this.addOverrideContentType(partName, contentType);
        }
        else {
            final String defaultContentType =
this.defaultContentType.get(extension);
            if(defaultContentType == null) {
                this.addDefaultContentType(extension, contentType);
            }
            else {
                if(!defaultContentType.equals(contentType)) {
                    this.addOverrideContentType(partName, contentType);
                }
            }
        }
    }

I built from the release distribution so no svn and ant -f patch.xml does not
work. The problem with the original logic is where a default type exists but
the extensions differ, as in:

if ((extension.length() == 0) || this.defaultContentType.containsKey(extension)
&& !defaultCTExists))

I think the logic is now simpler in the modified version...
IF there is no extension add an override type
ELSE IF there is no default type for the extension add one
ELSE IF default content type differs from the supplied value add an override

You might feel the need to tidy the nested ifs... depends what you feel looks
clearer.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org