2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:14:01 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 09:39:38 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_xmloff.hxx"
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
|
|
|
|
#include <com/sun/star/xml/dom/XSAXDocumentBuilder.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
2005-10-17 13:00:16 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
#include <tools/debug.hxx>
|
2006-11-01 13:51:44 +00:00
|
|
|
|
2007-06-27 14:19:39 +00:00
|
|
|
#include <xmloff/xmlmetai.hxx>
|
|
|
|
#include <xmloff/xmlimp.hxx>
|
|
|
|
#include <xmloff/nmspmap.hxx>
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
2008-02-26 12:38:09 +00:00
|
|
|
#include "xmlnmspe.hxx"
|
2001-06-29 20:07:26 +00:00
|
|
|
|
2004-11-17 12:05:00 +00:00
|
|
|
|
2005-09-05 13:55:08 +00:00
|
|
|
using ::rtl::OUString;
|
2005-10-17 13:00:16 +00:00
|
|
|
using ::rtl::OUStringBuffer;
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace com::sun::star;
|
2001-06-15 16:16:59 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/// builds a DOM tree from SAX events, by forwarding to SAXDocumentBuilder
|
|
|
|
class XMLDocumentBuilderContext : public SvXMLImportContext
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
private:
|
2008-02-26 12:38:09 +00:00
|
|
|
::com::sun::star::uno::Reference<
|
|
|
|
::com::sun::star::xml::sax::XDocumentHandler> mxDocBuilder;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
public:
|
2008-02-26 12:38:09 +00:00
|
|
|
XMLDocumentBuilderContext(SvXMLImport& rImport, USHORT nPrfx,
|
|
|
|
const ::rtl::OUString& rLName,
|
|
|
|
const ::com::sun::star::uno::Reference<
|
|
|
|
::com::sun::star::xml::sax::XAttributeList>& xAttrList,
|
|
|
|
const ::com::sun::star::uno::Reference<
|
|
|
|
::com::sun::star::xml::sax::XDocumentHandler>& rDocBuilder);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
virtual ~XMLDocumentBuilderContext();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
|
|
|
|
const rtl::OUString& rLocalName,
|
|
|
|
const ::com::sun::star::uno::Reference<
|
|
|
|
::com::sun::star::xml::sax::XAttributeList>& xAttrList );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
virtual void StartElement( const ::com::sun::star::uno::Reference<
|
|
|
|
::com::sun::star::xml::sax::XAttributeList >& xAttrList );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
virtual void Characters( const ::rtl::OUString& rChars );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
virtual void EndElement();
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
XMLDocumentBuilderContext::XMLDocumentBuilderContext(SvXMLImport& rImport,
|
|
|
|
USHORT nPrfx, const ::rtl::OUString& rLName,
|
|
|
|
const uno::Reference<xml::sax::XAttributeList>&,
|
|
|
|
const uno::Reference<xml::sax::XDocumentHandler>& rDocBuilder) :
|
|
|
|
SvXMLImportContext( rImport, nPrfx, rLName ),
|
|
|
|
mxDocBuilder(rDocBuilder)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
XMLDocumentBuilderContext::~XMLDocumentBuilderContext()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
SvXMLImportContext *
|
|
|
|
XMLDocumentBuilderContext::CreateChildContext( USHORT nPrefix,
|
|
|
|
const rtl::OUString& rLocalName,
|
|
|
|
const uno::Reference< xml::sax::XAttributeList>& rAttrs)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
return new XMLDocumentBuilderContext(
|
|
|
|
GetImport(), nPrefix, rLocalName, rAttrs, mxDocBuilder);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
void XMLDocumentBuilderContext::StartElement(
|
|
|
|
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
mxDocBuilder->startElement(
|
|
|
|
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), GetLocalName()),
|
|
|
|
xAttrList);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
void XMLDocumentBuilderContext::Characters( const ::rtl::OUString& rChars )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
mxDocBuilder->characters(rChars);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
void XMLDocumentBuilderContext::EndElement()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
mxDocBuilder->endElement(
|
|
|
|
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), GetLocalName()));
|
|
|
|
}
|
2006-11-01 13:51:44 +00:00
|
|
|
|
2005-10-17 13:00:16 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
//===========================================================================
|
2008-01-04 15:12:52 +00:00
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
SvXMLMetaDocumentContext::SvXMLMetaDocumentContext(SvXMLImport& rImport,
|
|
|
|
USHORT nPrfx, const rtl::OUString& rLName,
|
|
|
|
const uno::Reference<document::XDocumentProperties>& xDocProps,
|
|
|
|
const uno::Reference<xml::sax::XDocumentHandler>& xDocBuilder) :
|
|
|
|
SvXMLImportContext( rImport, nPrfx, rLName ),
|
|
|
|
mxDocProps(xDocProps),
|
|
|
|
mxDocBuilder(xDocBuilder)
|
|
|
|
{
|
|
|
|
DBG_ASSERT(xDocProps.is(), "SvXMLMetaDocumentContext: no document props");
|
|
|
|
DBG_ASSERT(xDocBuilder.is(), "SvXMLMetaDocumentContext: no document hdlr");
|
|
|
|
// here are no attributes
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
SvXMLMetaDocumentContext::~SvXMLMetaDocumentContext()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
SvXMLImportContext *SvXMLMetaDocumentContext::CreateChildContext(
|
|
|
|
USHORT nPrefix, const rtl::OUString& rLocalName,
|
|
|
|
const uno::Reference<xml::sax::XAttributeList>& rAttrs)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
|
|
|
|
IsXMLToken(rLocalName, XML_META) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
return new XMLDocumentBuilderContext(
|
|
|
|
GetImport(), nPrefix, rLocalName, rAttrs, mxDocBuilder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
|
|
|
|
void SvXMLMetaDocumentContext::StartElement(
|
|
|
|
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
2001-09-11 04:19:20 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
mxDocBuilder->startDocument();
|
|
|
|
// hardcode office:document-meta (necessary in case of flat file ODF)
|
|
|
|
mxDocBuilder->startElement(
|
|
|
|
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(),
|
|
|
|
GetXMLToken(XML_DOCUMENT_META)), xAttrList);
|
2001-09-11 04:19:20 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
void SvXMLMetaDocumentContext::EndElement()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
// hardcode office:document-meta (necessary in case of flat file ODF)
|
|
|
|
mxDocBuilder->endElement(
|
|
|
|
GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(),
|
|
|
|
GetXMLToken(XML_DOCUMENT_META)));
|
|
|
|
mxDocBuilder->endDocument();
|
|
|
|
initDocumentProperties();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
void SvXMLMetaDocumentContext::initDocumentProperties()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
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));
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-26 12:47:18 +00:00
|
|
|
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 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
OUString sBuildId;
|
|
|
|
// skip to second product
|
|
|
|
sal_Int32 nBegin = i_rBuildId.indexOf( ' ' );
|
|
|
|
if ( nBegin != -1 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
// skip to build information
|
|
|
|
nBegin = i_rBuildId.indexOf( '/', nBegin );
|
|
|
|
if ( nBegin != -1 )
|
2008-01-29 15:14:18 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
sal_Int32 nEnd = i_rBuildId.indexOf( 'm', nBegin );
|
|
|
|
if ( nEnd != -1 )
|
|
|
|
{
|
|
|
|
OUStringBuffer sBuffer(
|
|
|
|
i_rBuildId.copy( nBegin+1, nEnd-nBegin-1 ) );
|
|
|
|
const OUString sBuildCompare(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM( "$Build-" ) );
|
|
|
|
nBegin = i_rBuildId.indexOf( sBuildCompare, nEnd );
|
|
|
|
if ( nBegin != -1 )
|
|
|
|
{
|
|
|
|
sBuffer.append( (sal_Unicode)'$' );
|
|
|
|
sBuffer.append( i_rBuildId.copy(
|
|
|
|
nBegin + sBuildCompare.getLength() ) );
|
|
|
|
sBuildId = sBuffer.makeStringAndClear();
|
|
|
|
}
|
|
|
|
}
|
2008-01-29 15:14:18 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
if ( sBuildId.getLength() == 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-02-26 12:38:09 +00:00
|
|
|
if ((i_rBuildId.compareToAscii(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("StarOffice 7") ) == 0) ||
|
|
|
|
(i_rBuildId.compareToAscii(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("StarSuite 7") ) == 0) ||
|
|
|
|
(i_rBuildId.compareToAscii(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("OpenOffice.org 1") ) == 0))
|
|
|
|
{
|
|
|
|
sBuildId = OUString::createFromAscii( "645$8687" );
|
|
|
|
}
|
2008-08-01 12:27:24 +00:00
|
|
|
if ((i_rBuildId.compareToAscii( RTL_CONSTASCII_STRINGPARAM("NeoOffice/2") ) == 0) )
|
|
|
|
{
|
|
|
|
sBuildId = OUString::createFromAscii( "680$9134" ); // fake NeoOffice as OpenOffice.org 2.2 release
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 12:38:09 +00:00
|
|
|
if ( sBuildId.getLength() ) try
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-08-26 12:47:18 +00:00
|
|
|
if( xImportInfo.is() )
|
2008-02-26 12:38:09 +00:00
|
|
|
{
|
|
|
|
const OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("BuildId"));
|
|
|
|
uno::Reference< beans::XPropertySetInfo > xSetInfo(
|
2009-08-26 12:47:18 +00:00
|
|
|
xImportInfo->getPropertySetInfo());
|
2008-02-26 12:38:09 +00:00
|
|
|
if( xSetInfo.is() && xSetInfo->hasPropertyByName( aPropName ) )
|
2009-08-26 12:47:18 +00:00
|
|
|
xImportInfo->setPropertyValue( aPropName, uno::makeAny( sBuildId ) );
|
2008-02-26 12:38:09 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2008-02-26 12:38:09 +00:00
|
|
|
catch( uno::Exception& )
|
2004-11-17 12:05:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|