Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/1761 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/61/1761/1 xmloff: refactor Generator version handling: Since there are now 2 forks of OpenOffice.org, we cannot rely on a simple total ordering of versions any more; add a new function SvXMLImport::isGeneratorVersionOlderThan(), taking 2 reference versions. Also extract the LibreOffice version number from the generator string, and extend the BuildId property to store this as a third number. This also allows removal of the "fake LibreOffice3 as OpenOffice.org 3.3 release" hack, which is not future-proof. (cherry picked from commit bea63709d05514555d5283279cd66439f4ceed73) Conflicts: xmloff/source/core/xmlimp.cxx Change-Id: I44d8105eb537ac43fb9529a8b1b661ae0f2bba30 --- M xmloff/inc/xmloff/xmlimp.hxx M xmloff/source/core/xmlimp.cxx M xmloff/source/draw/ximpshap.cxx M xmloff/source/meta/xmlmetai.cxx 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/xmloff/inc/xmloff/xmlimp.hxx b/xmloff/inc/xmloff/xmlimp.hxx index 125728f..3a5d1e0 100644 --- a/xmloff/inc/xmloff/xmlimp.hxx +++ b/xmloff/inc/xmloff/xmlimp.hxx @@ -422,8 +422,16 @@ static const sal_uInt16 OOo_32x = 32; static const sal_uInt16 OOo_33x = 33; static const sal_uInt16 OOo_34x = 34; + static const sal_uInt16 LO_flag = 0x100; + static const sal_uInt16 LO_3x = 30 | LO_flag; + static const sal_uInt16 LO_4x = 40 | LO_flag; static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16; + /** depending on whether the generator version indicates LO, compare + against either the given LO or given OOo version */ + bool isGeneratorVersionOlderThan( + sal_uInt16 const nOOoVersion, sal_uInt16 const nLOVersion); + /** this checks the build ID and returns * OOo_1x for files created with OpenOffice.org 1.x or StarOffice 7 (this also includes binary import over binfilter) diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index d6e29df..858f838 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -157,6 +157,31 @@ namespace { + +static OUString +getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo) +{ + if (xImportInfo.is()) + { + try + { + Reference< XPropertySetInfo > const xSetInfo( + xImportInfo->getPropertySetInfo()); + if (xSetInfo.is() && xSetInfo->hasPropertyByName("BuildId")) + { + OUString aBuildId; + xImportInfo->getPropertyValue("BuildId") >>= aBuildId; + return aBuildId; + } + } + catch (Exception const& e) + { + SAL_WARN("xmloff", "exception getting BuildId" << e.Message); + } + } + return OUString(); +} + class DocumentInfo { private: @@ -166,6 +191,30 @@ DocumentInfo( const SvXMLImport& rImport ) : mnGeneratorVersion( SvXMLImport::ProductVersionUnknown ) { + OUString const buildIds( + getBuildIdsProperty(rImport.getImportInfo())); + if (!buildIds.isEmpty()) + { + sal_Int32 const ix = buildIds.indexOf(';'); + if (-1 != ix) + { + OUString const loVersion(buildIds.copy(ix + 1)); + if (!loVersion.isEmpty()) + { + if ('3' == loVersion[0]) + { + mnGeneratorVersion = SvXMLImport::LO_3x; + } + else + { + SAL_INFO_IF('4' != loVersion[0], "xmloff", + "unknown LO version: " << loVersion); + mnGeneratorVersion = SvXMLImport::LO_4x; + } + return; // ignore buildIds + } + } + } sal_Int32 nUPD, nBuild; if ( rImport.getBuildIds( nUPD, nBuild ) ) { @@ -1838,28 +1887,19 @@ bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const { bool bRet = false; - if( mxImportInfo.is() ) try + OUString const aBuildId(getBuildIdsProperty(mxImportInfo)); + if (!aBuildId.isEmpty()) { - const OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("BuildId")); - Reference< XPropertySetInfo > xSetInfo( mxImportInfo->getPropertySetInfo() ); - if( xSetInfo.is() && xSetInfo->hasPropertyByName( aPropName ) ) + sal_Int32 nIndex = aBuildId.indexOf('$'); + if (nIndex != -1) { - OUString aBuildId; - mxImportInfo->getPropertyValue( aPropName ) >>= aBuildId; - if( !aBuildId.isEmpty() ) - { - sal_Int32 nIndex = aBuildId.indexOf('$'); - if( nIndex != -1 ) - { - rUPD = aBuildId.copy( 0, nIndex ).toInt32(); - rBuild = aBuildId.copy( nIndex+1 ).toInt32(); - bRet = true; - } - } + rUPD = aBuildId.copy( 0, nIndex ).toInt32(); + sal_Int32 nIndexEnd = aBuildId.indexOf(';', nIndex); + rBuild = (nIndexEnd == -1) + ? aBuildId.copy(nIndex + 1).toInt32() + : aBuildId.copy(nIndex + 1, nIndexEnd - nIndex - 1).toInt32(); + bRet = true; } - } - catch( Exception& ) - { } return bRet; } @@ -1871,6 +1911,17 @@ // <-- } +bool SvXMLImport::isGeneratorVersionOlderThan( + sal_uInt16 const nOOoVersion, sal_uInt16 const nLOVersion) +{ + assert( (nLOVersion & LO_flag)); + assert(!(nOOoVersion & LO_flag)); + const sal_uInt16 nGeneratorVersion(getGeneratorVersion()); + return (nGeneratorVersion & LO_flag) + ? nGeneratorVersion < nLOVersion + : nGeneratorVersion < nOOoVersion; +} + bool SvXMLImport::isGraphicLoadOnDemandSupported() const { return mbIsGraphicLoadOnDemandSupported; diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index 3143910..08d8decf 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -2696,10 +2696,8 @@ void SdXMLObjectShapeContext::EndElement() { - // #i67705# - const sal_uInt16 nGeneratorVersion(GetImport().getGeneratorVersion()); - - if(nGeneratorVersion < SvXMLImport::OOo_34x) + if (GetImport().isGeneratorVersionOlderThan( + SvXMLImport::OOo_34x, SvXMLImport::LO_4x)) { // #i118485# // If it's an old file from us written before OOo3.4, we need to correct diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx index ba9c58b..af3362f 100644 --- a/xmloff/source/meta/xmlmetai.cxx +++ b/xmloff/source/meta/xmlmetai.cxx @@ -279,17 +279,27 @@ sBuildId = OUString("680$9134"); // fake NeoOffice as OpenOffice.org 2.2 release } } -// Is this really what we want / correct ? -#ifdef FIXME_REMOVE_WHEN_RE_BASE_COMPLETE - else + + if (i_rBuildId.startsWith("LibreOffice/")) { - if (i_rBuildId.startsWith("LibreOffice/3")) + OUStringBuffer sNumber; + for (sal_Int32 i = sizeof("LibreOffice/") - 1; + i < i_rBuildId.getLength(); ++i) { - // #118558# fake LibreOffice3 as OpenOffice.org 3.3 release - sBuildId = OUString::createFromAscii( "330$9567" ); + if (isdigit(i_rBuildId[i])) + { + sNumber.append(i_rBuildId[i]); + } + else if ('.' != i_rBuildId[i]) + { + break; + } + } + if (sNumber.getLength()) + { + sBuildId += (";" + sNumber.makeStringAndClear()); } } -#endif if ( !sBuildId.isEmpty() ) try { -- To view, visit https://gerrit.libreoffice.org/1761 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I44d8105eb537ac43fb9529a8b1b661ae0f2bba30 Gerrit-PatchSet: 1 Gerrit-Project: core Gerrit-Branch: libreoffice-4-0 Gerrit-Owner: Michael Stahl <mst...@redhat.com> _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice