summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2011-03-01 16:05:30 +0100
committerMichael Stahl <mst@openoffice.org>2011-03-01 16:05:30 +0100
commitbedbe4e2871440b5d276e97c2894c05cc4b6fcda (patch)
tree502866e5925479c498b03e2f4a32aefe6d0d6620 /xmloff
parent3c5facfce42a0dbe362d6b9fa5ac374fd76f51a1 (diff)
sw34bf04: #i103539#: always import meta.xml, to extract the BuildId:
SvXMLMetaDocumentContext: refactor to not require DocumentProperties, and always set the BuildId from the meta:generator element. {Sc,Sd,Sw}XMLImport::CreateMetaContext(): always create context. sc, sd: add OrganizerMode property to ODF import.
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/xmloff/xmlmetai.hxx10
-rw-r--r--xmloff/source/draw/sdxmlimp.cxx21
-rw-r--r--xmloff/source/meta/xmlmetai.cxx113
3 files changed, 94 insertions, 50 deletions
diff --git a/xmloff/inc/xmloff/xmlmetai.hxx b/xmloff/inc/xmloff/xmlmetai.hxx
index efdd1d3f024f..2ddd51920054 100644
--- a/xmloff/inc/xmloff/xmlmetai.hxx
+++ b/xmloff/inc/xmloff/xmlmetai.hxx
@@ -25,8 +25,8 @@
*
************************************************************************/
-#ifndef _XMLOFF_XMLMETAI_HXX
-#define _XMLOFF_XMLMETAI_HXX
+#ifndef XMLOFF_XMLMETAI_HXX
+#define XMLOFF_XMLMETAI_HXX
#include "sal/config.h"
#include "xmloff/dllapi.h"
@@ -69,12 +69,6 @@ public:
virtual void EndElement();
-protected:
- /// initialize DocumentProperties object with DOM and base URL
- void initDocumentProperties();
- // set the BuildId property at the importer
- void setBuildId(const ::rtl::OUString & i_rBuildId);
-
public:
static void setBuildId(const ::rtl::OUString & rGenerator,
const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& xImportInfo );
diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx
index 578b3eefc719..7b69609fafe9 100644
--- a/xmloff/source/draw/sdxmlimp.cxx
+++ b/xmloff/source/draw/sdxmlimp.cxx
@@ -30,15 +30,11 @@
#include <tools/string.hxx>
-#ifndef _XMLOFF_XMLMETAI_HXX
#include <xmloff/xmlscripti.hxx>
-#endif
#include "sdxmlimp_impl.hxx"
#include "ximpbody.hxx"
-#ifndef _SFX_XMLMETAI_HXX
#include <xmloff/xmlmetai.hxx>
-#endif
#include "ximpstyl.hxx"
#include "xmloff/xmlnmspe.hxx"
#include <xmloff/xmltoken.hxx>
@@ -447,6 +443,17 @@ void SAL_CALL SdXMLImport::initialize( const uno::Sequence< uno::Any >& aArgumen
if( xInfoSetInfo->hasPropertyByName( msPreview ) )
xInfoSet->getPropertyValue( msPreview ) >>= mbPreview;
+
+ ::rtl::OUString const sOrganizerMode(
+ RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
+ if (xInfoSetInfo->hasPropertyByName(sOrganizerMode))
+ {
+ sal_Bool bStyleOnly(sal_False);
+ if (xInfoSet->getPropertyValue(sOrganizerMode) >>= bStyleOnly)
+ {
+ mbLoadDoc = !bStyleOnly;
+ }
+ }
}
}
@@ -765,7 +772,7 @@ SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName,
{
SvXMLImportContext* pContext = 0L;
- if (!IsStylesOnlyMode() && (getImportFlags() & IMPORT_META))
+ if (getImportFlags() & IMPORT_META)
{
uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
@@ -773,9 +780,11 @@ SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName,
uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<document::XDocumentProperties> const xDocProps(
+ (IsStylesOnlyMode()) ? 0 : xDPS->getDocumentProperties());
pContext = new SvXMLMetaDocumentContext(*this,
XML_NAMESPACE_OFFICE, rLocalName,
- xDPS->getDocumentProperties(), xDocBuilder);
+ xDocProps, xDocBuilder);
}
if(!pContext)
diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx
index e2ba207e5cd6..9f5aebece935 100644
--- a/xmloff/source/meta/xmlmetai.cxx
+++ b/xmloff/source/meta/xmlmetai.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/xml/dom/XSAXDocumentBuilder.hpp>
+#include <com/sun/star/xml/xpath/XXPathAPI.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
@@ -124,6 +125,71 @@ void XMLDocumentBuilderContext::EndElement()
//===========================================================================
+static void
+lcl_initDocumentProperties(SvXMLImport & rImport,
+ uno::Reference<xml::sax::XDocumentHandler> const& xDocBuilder,
+ uno::Reference<document::XDocumentProperties> const& xDocProps)
+{
+ uno::Sequence< uno::Any > aSeq(1);
+ uno::Reference< xml::dom::XSAXDocumentBuilder > const xDB(xDocBuilder,
+ uno::UNO_QUERY_THROW);
+ aSeq[0] <<= xDB->getDocument();
+ uno::Reference< lang::XInitialization > const xInit(xDocProps,
+ uno::UNO_QUERY_THROW);
+ try {
+ xInit->initialize(aSeq);
+ rImport.SetStatistics(xDocProps->getDocumentStatistics());
+ // convert all URLs from relative to absolute
+ xDocProps->setTemplateURL(rImport.GetAbsoluteReference(
+ xDocProps->getTemplateURL()));
+ xDocProps->setAutoloadURL(rImport.GetAbsoluteReference(
+ xDocProps->getAutoloadURL()));
+ SvXMLMetaDocumentContext::setBuildId(
+ xDocProps->getGenerator(), rImport.getImportInfo());
+ } catch (uno::RuntimeException) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SvXMLMetaDocumentContext::initDocumentProperties: "
+ "properties init exception"),
+ rImport, makeAny(e));
+ }
+}
+
+static void
+lcl_initGenerator(SvXMLImport & rImport,
+ uno::Reference<xml::sax::XDocumentHandler> const& xDocBuilder)
+{
+ uno::Reference< xml::dom::XSAXDocumentBuilder > const xDB(xDocBuilder,
+ uno::UNO_QUERY_THROW);
+ uno::Reference< xml::dom::XDocument > const xDoc(xDB->getDocument(),
+ uno::UNO_SET_THROW);
+ try {
+ uno::Reference< xml::xpath::XXPathAPI > const xPath(
+ rImport.getServiceFactory()->createInstance(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.xml.xpath.XPathAPI"))),
+ uno::UNO_QUERY_THROW );
+ xPath->registerNS(GetXMLToken(XML_NP_OFFICE),GetXMLToken(XML_N_OFFICE));
+ xPath->registerNS(GetXMLToken(XML_NP_META), GetXMLToken(XML_N_META));
+
+ ::rtl::OUString const expr(RTL_CONSTASCII_USTRINGPARAM(
+ "string(/office:document-meta/office:meta/meta:generator)"));
+ uno::Reference< xml::xpath::XXPathObject > const xObj(
+ xPath->eval(xDoc.get(), expr), uno::UNO_SET_THROW);
+ OUString const value(xObj->getString());
+ SvXMLMetaDocumentContext::setBuildId(value, rImport.getImportInfo());
+ } catch (uno::RuntimeException) {
+ throw;
+ } catch (uno::Exception & e) {
+ throw lang::WrappedTargetRuntimeException(
+ ::rtl::OUString::createFromAscii(
+ "SvXMLMetaDocumentContext::initGenerator: exception"),
+ rImport, makeAny(e));
+ }
+}
+
SvXMLMetaDocumentContext::SvXMLMetaDocumentContext(SvXMLImport& rImport,
sal_uInt16 nPrfx, const rtl::OUString& rLName,
const uno::Reference<document::XDocumentProperties>& xDocProps,
@@ -132,8 +198,9 @@ SvXMLMetaDocumentContext::SvXMLMetaDocumentContext(SvXMLImport& rImport,
mxDocProps(xDocProps),
mxDocBuilder(xDocBuilder)
{
- DBG_ASSERT(xDocProps.is(), "SvXMLMetaDocumentContext: no document props");
- DBG_ASSERT(xDocBuilder.is(), "SvXMLMetaDocumentContext: no document hdlr");
+// #i103539#: must always read meta.xml for generator, xDocProps unwanted then
+// OSL_ENSURE(xDocProps.is(), "SvXMLMetaDocumentContext: no document props");
+ OSL_ENSURE(xDocBuilder.is(), "SvXMLMetaDocumentContext: no document hdlr");
// here are no attributes
}
@@ -166,6 +233,7 @@ void SvXMLMetaDocumentContext::StartElement(
mxDocBuilder->startElement(
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(),
GetXMLToken(XML_DOCUMENT_META)), xAttrList);
+
}
void SvXMLMetaDocumentContext::EndElement()
@@ -175,43 +243,16 @@ void SvXMLMetaDocumentContext::EndElement()
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(),
GetXMLToken(XML_DOCUMENT_META)));
mxDocBuilder->endDocument();
- initDocumentProperties();
-}
-
-void SvXMLMetaDocumentContext::initDocumentProperties()
-{
- uno::Sequence< uno::Any > aSeq(1);
- uno::Reference< xml::dom::XSAXDocumentBuilder > xDB (mxDocBuilder,
- uno::UNO_QUERY_THROW);
- aSeq[0] <<= xDB->getDocument();
- uno::Reference< lang::XInitialization > xInit(mxDocProps,
- uno::UNO_QUERY_THROW);
- try {
- xInit->initialize(aSeq);
- GetImport().SetStatistics(mxDocProps->getDocumentStatistics());
- // convert all URLs from relative to absolute
- mxDocProps->setTemplateURL(GetImport().GetAbsoluteReference(
- mxDocProps->getTemplateURL()));
- mxDocProps->setAutoloadURL(GetImport().GetAbsoluteReference(
- mxDocProps->getAutoloadURL()));
- setBuildId(mxDocProps->getGenerator());
- } catch (uno::RuntimeException) {
- throw;
- } catch (uno::Exception & e) {
- throw lang::WrappedTargetRuntimeException(
- ::rtl::OUString::createFromAscii(
- "SvXMLMetaDocumentContext::initDocumentProperties: "
- "properties init exception"),
- GetImport(), makeAny(e));
+ if (mxDocProps.is())
+ {
+ lcl_initDocumentProperties(GetImport(), mxDocBuilder, mxDocProps);
+ }
+ else
+ {
+ lcl_initGenerator(GetImport(), mxDocBuilder);
}
}
-void SvXMLMetaDocumentContext::setBuildId(const ::rtl::OUString & i_rBuildId)
-{
- SvXMLMetaDocumentContext::setBuildId( i_rBuildId, GetImport().getImportInfo() );
-}
-
-//static
void SvXMLMetaDocumentContext::setBuildId(::rtl::OUString const& i_rBuildId, const uno::Reference<beans::XPropertySet>& xImportInfo )
{
OUString sBuildId;