Issue 95421

Summary: ODT: Media type for png thumbnail not set.
Product: Writer Reporter: lars.langhans
Component: save-exportAssignee: Ariel Constenla-Haile <arielch>
Status: CLOSED FIXED QA Contact:
Severity: Trivial    
Priority: P3 CC: arielch, issues, orcmid, rb.henschel
Version: DEV300m30Keywords: odf_validation
Target Milestone: 4.0.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---

Description lars.langhans 2008-10-24 14:37:59 UTC
1. Create a text document
2. Create some content (d t F3)
3. Store as ODT
4. Rename the ODT to ODT.zip
5. take a look into the META-INF/manifest.xml 

The media type of "Thumbnains/thumbnail.png" is empty ("") shouldn't it be
'image/png'?
Comment 1 Regina Henschel 2013-03-29 17:32:39 UTC
*** Issue 30870 has been marked as a duplicate of this issue. ***
Comment 2 Regina Henschel 2013-03-29 20:53:48 UTC
The media type is missing in .ods, .odp, and .odg too. I've tested with OOo3.4 and a AOO4.0 buildbot version.
Comment 3 Ariel Constenla-Haile 2013-03-30 13:30:16 UTC
The mime type is never set in SfxObjectShell::GenerateAndStoreThumbnail
http://svn.apache.org/viewvc/openoffice/trunk/main/sfx2/source/doc/objstor.cxx?revision=1413471&view=markup#l3695

The fix is rather trivial:


sal_Bool SfxObjectShell::GenerateAndStoreThumbnail( sal_Bool bEncrypted,
                                                    sal_Bool bSigned,
                                                    sal_Bool bIsTemplate,
                                                    const uno::Reference< embed::XStorage >& xStor )
{
    RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxObjectShell::GenerateAndStoreThumbnail" );
	
    bIsInGenerateThumbnail = sal_True;//optimize thumbnail generate and store procedure to improve odt saving performance, i120030

    sal_Bool bResult = sal_False;

    try {
        uno::Reference< embed::XStorage > xThumbnailStor =
                                        xStor->openStorageElement( ::rtl::OUString::createFromAscii( "Thumbnails" ),
                                                                    embed::ElementModes::READWRITE );
        if ( xThumbnailStor.is() )
        {
            uno::Reference< io::XStream > xStream = xThumbnailStor->openStreamElement(
                                                        ::rtl::OUString::createFromAscii( "thumbnail.png" ),
                                                        embed::ElementModes::READWRITE );

            if ( xStream.is() && WriteThumbnail( bEncrypted, bSigned, bIsTemplate, xStream ) )
            {
                uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY );
                if ( xPropSet.is() )
                    xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
                                                uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ) ) );
                uno::Reference< embed::XTransactedObject > xTransact( xThumbnailStor, uno::UNO_QUERY_THROW );
                xTransact->commit();
                bResult = sal_True;
            }
        }
    }
    catch( uno::Exception& )
    {
    }
	
    bIsInGenerateThumbnail = sal_False;//optimize thumbnail generate and store procedure to improve odt saving performance, i120030

    return bResult;
}
Comment 4 Ariel Constenla-Haile 2013-03-30 13:32:21 UTC
(In reply to comment #2)
> The media type is missing in .ods, .odp, and .odg too.

This affects all document types based in the old sfx2 module (Writer, Draw/Impress, Calc, Math).
Comment 5 SVN Robot 2013-03-30 13:50:17 UTC
"arielch" committed SVN revision 1462756 into trunk:
i95421 - Set MediaType when storing thumbnail.png
Comment 6 Ariel Constenla-Haile 2013-03-30 13:50:53 UTC
Fixed on trunk
Comment 7 orcmid 2013-03-30 15:48:56 UTC
Although the provision of a media-type is a "should," the <manifest:file-entry> manifest:media-type attribute is required by the schema for ODF 1.2 META-INF/manifest.xml.  This is apparently the justification for manifest:media-type="", a common practice despite the absence of any such media type.

Note that the media type of optional package part "Thumbnails/thumbnail.png" is always known.  It is required to be a PNG by the ODF 1.2 specification.  I also assume that software (other than an ODF consumer) that makes the thumbnail available probably does not bother with processing META-INF/manifest.xml in order to use it.

I heartily agree that "image/png" is preferable to "" but I wonder who will check this on input.  It seems that a practical verification of ODF package conformance would need to accept either media-type value when the preview image is present and also require that the thumbnail be a valid PNG as well.