Kaydet (Commit) bea63709 authored tarafından Michael Stahl's avatar Michael Stahl

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.

Change-Id: I44d8105eb537ac43fb9529a8b1b661ae0f2bba30
üst 0669d78e
......@@ -423,8 +423,16 @@ public:
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)
......
......@@ -157,6 +157,31 @@ void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
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 @@ namespace
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 ) )
{
......@@ -1769,29 +1818,20 @@ void SvXMLImport::initXForms()
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( "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;
}
......@@ -1802,6 +1842,17 @@ sal_uInt16 SvXMLImport::getGeneratorVersion() const
// <--
}
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;
......
......@@ -2696,10 +2696,8 @@ void SdXMLObjectShapeContext::StartElement( const ::com::sun::star::uno::Referen
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
......
......@@ -279,17 +279,27 @@ void SvXMLMetaDocumentContext::setBuildId(::rtl::OUString const& i_rBuildId, con
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)
{
if (isdigit(i_rBuildId[i]))
{
sNumber.append(i_rBuildId[i]);
}
else if ('.' != i_rBuildId[i])
{
break;
}
}
if (sNumber.getLength())
{
// #118558# fake LibreOffice3 as OpenOffice.org 3.3 release
sBuildId = OUString::createFromAscii( "330$9567" );
sBuildId += (";" + sNumber.makeStringAndClear());
}
}
#endif
if ( !sBuildId.isEmpty() ) try
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment