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-21 13:44:07 +0000
commit5bb1adb5881e24b7bca98e39638b130531849a7e (patch)
treec32e9758fd7c3dd609f6059be01c6a2fa370f082
parentca4aa39e66ea728f5d6b004ddd678e076d1ffa60 (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. (cherry picked from commit bea63709d05514555d5283279cd66439f4ceed73) Conflicts: xmloff/source/core/xmlimp.cxx Change-Id: I44d8105eb537ac43fb9529a8b1b661ae0f2bba30 Reviewed-on: https://gerrit.libreoffice.org/1761 Reviewed-by: Thorsten Behrens <tbehrens@suse.com> Tested-by: Thorsten Behrens <tbehrens@suse.com>
-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 125728fbb726..3a5d1e087b18 100644
--- a/xmloff/inc/xmloff/xmlimp.hxx
+++ b/xmloff/inc/xmloff/xmlimp.hxx
@@ -422,8 +422,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 d6e29df6ff17..858f838d1cc4 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 ) )
{
@@ -1838,29 +1887,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(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 @@ 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
{