summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-01-18 23:40:13 +0100
committerMichael Stahl <mstahl@redhat.com>2013-01-18 23:46:33 +0100
commitbea63709d05514555d5283279cd66439f4ceed73 (patch)
treec78a2134e3f49b842f4b24acd68d8d1736cda682
parent0669d78ea76ab9bfeff27ea02d785973f3720d6b (diff)
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
-rw-r--r--xmloff/inc/xmloff/xmlimp.hxx8
-rw-r--r--xmloff/source/core/xmlimp.cxx89
-rw-r--r--xmloff/source/draw/ximpshap.cxx6
-rw-r--r--xmloff/source/meta/xmlmetai.cxx24
4 files changed, 97 insertions, 30 deletions
diff --git a/xmloff/inc/xmloff/xmlimp.hxx b/xmloff/inc/xmloff/xmlimp.hxx
index 4fac73753165..d97fe847ceda 100644
--- a/xmloff/inc/xmloff/xmlimp.hxx
+++ b/xmloff/inc/xmloff/xmlimp.hxx
@@ -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)
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 3cdd3194cc15..6b492ef217ee 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -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;
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 314391038ac8..08d8decfb59a 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -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
diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx
index ba9c58b22544..af3362fc777b 100644
--- a/xmloff/source/meta/xmlmetai.cxx
+++ b/xmloff/source/meta/xmlmetai.cxx
@@ -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
{