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:59:37 +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:59:37 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:59:37 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:59:37 +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:59:37 +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:59:37 +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
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "XMLFootnoteImportContext.hxx"
|
|
|
|
|
2006-06-19 17:39:29 +00:00
|
|
|
#include <rtl/ustring.hxx>
|
2007-06-27 14:57:59 +00:00
|
|
|
#include <xmloff/xmlimp.hxx>
|
|
|
|
#include <xmloff/txtimp.hxx>
|
|
|
|
#include <xmloff/nmspmap.hxx>
|
2010-04-16 23:04:00 +02:00
|
|
|
#include "xmloff/xmlnmspe.hxx"
|
2007-06-27 14:57:59 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-09-27 14:58:45 +00:00
|
|
|
#include "XMLFootnoteBodyImportContext.hxx"
|
2001-07-19 12:16:33 +00:00
|
|
|
#include "XMLTextListBlockContext.hxx"
|
|
|
|
#include "XMLTextListItemContext.hxx"
|
2008-10-01 06:34:11 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <com/sun/star/xml/sax/XAttributeList.hpp>
|
|
|
|
#include <com/sun/star/text/XTextContent.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/text/XFootnote.hpp>
|
|
|
|
|
|
|
|
|
2008-03-12 10:01:03 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::text;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::xml::sax;
|
2001-06-15 16:16:59 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
TYPEINIT1(XMLFootnoteImportContext, SvXMLImportContext);
|
|
|
|
|
|
|
|
const sal_Char sAPI_service_footnote[] = "com.sun.star.text.Footnote";
|
|
|
|
const sal_Char sAPI_service_endnote[] = "com.sun.star.text.Endnote";
|
|
|
|
|
2000-09-27 14:58:45 +00:00
|
|
|
enum XMLFootnoteChildToken {
|
2004-07-13 07:31:41 +00:00
|
|
|
XML_TOK_FTN_NOTE_CITATION,
|
|
|
|
XML_TOK_FTN_NOTE_BODY
|
2000-09-27 14:58:45 +00:00
|
|
|
};
|
|
|
|
|
2010-12-06 10:36:18 +00:00
|
|
|
static SvXMLTokenMapEntry aFootnoteChildTokenMap[] =
|
2000-09-27 14:58:45 +00:00
|
|
|
{
|
2004-07-13 07:31:41 +00:00
|
|
|
{ XML_NAMESPACE_TEXT, XML_NOTE_CITATION,
|
|
|
|
XML_TOK_FTN_NOTE_CITATION },
|
|
|
|
{ XML_NAMESPACE_TEXT, XML_NOTE_BODY, XML_TOK_FTN_NOTE_BODY },
|
2000-09-27 14:58:45 +00:00
|
|
|
XML_TOKEN_MAP_END
|
|
|
|
};
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
XMLFootnoteImportContext::XMLFootnoteImportContext(
|
|
|
|
SvXMLImport& rImport,
|
|
|
|
XMLTextImportHelper& rHlp,
|
|
|
|
sal_uInt16 nPrfx,
|
2006-06-19 17:39:29 +00:00
|
|
|
const OUString& rLocalName )
|
|
|
|
: SvXMLImportContext(rImport, nPrfx, rLocalName)
|
|
|
|
, sPropertyReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId"))
|
2008-10-01 06:34:11 +00:00
|
|
|
, mbListContextPushed(false)
|
2006-06-19 17:39:29 +00:00
|
|
|
, rHelper(rHlp)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLFootnoteImportContext::StartElement(
|
|
|
|
const Reference<XAttributeList> & xAttrList)
|
|
|
|
{
|
|
|
|
// create footnote
|
2000-09-27 14:58:45 +00:00
|
|
|
Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
|
|
|
|
UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if( xFactory.is() )
|
|
|
|
{
|
|
|
|
// create endnote or footnote
|
2004-07-13 07:31:41 +00:00
|
|
|
sal_Bool bIsEndnote = sal_False;
|
|
|
|
sal_Int16 nLength = xAttrList->getLength();
|
|
|
|
for(sal_Int16 nAttr1 = 0; nAttr1 < nLength; nAttr1++)
|
|
|
|
{
|
|
|
|
OUString sLocalName;
|
|
|
|
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
|
|
|
|
GetKeyByAttrName( xAttrList->getNameByIndex(nAttr1),
|
|
|
|
&sLocalName );
|
|
|
|
if( XML_NAMESPACE_TEXT == nPrefix && IsXMLToken( sLocalName,
|
|
|
|
XML_NOTE_CLASS ) )
|
|
|
|
{
|
|
|
|
const OUString& rValue = xAttrList->getValueByIndex( nAttr1 );
|
|
|
|
if( IsXMLToken( rValue, XML_ENDNOTE ) )
|
|
|
|
bIsEndnote = sal_True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
Reference<XInterface> xIfc = xFactory->createInstance(
|
|
|
|
bIsEndnote ?
|
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_endnote)) :
|
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_footnote)) );
|
|
|
|
|
|
|
|
// attach footnote to document
|
|
|
|
Reference<XTextContent> xTextContent(xIfc, UNO_QUERY);
|
|
|
|
rHelper.InsertTextContent(xTextContent);
|
|
|
|
|
|
|
|
// process id attribute
|
2004-07-13 07:31:41 +00:00
|
|
|
for(sal_Int16 nAttr2 = 0; nAttr2 < nLength; nAttr2++)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
OUString sLocalName;
|
|
|
|
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
|
2004-07-13 07:31:41 +00:00
|
|
|
GetKeyByAttrName( xAttrList->getNameByIndex(nAttr2),
|
2000-09-18 16:07:07 +00:00
|
|
|
&sLocalName );
|
|
|
|
|
|
|
|
if ( (XML_NAMESPACE_TEXT == nPrefix) &&
|
2001-06-29 20:07:26 +00:00
|
|
|
IsXMLToken( sLocalName, XML_ID ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// get ID ...
|
|
|
|
Reference<XPropertySet> xPropertySet(xTextContent, UNO_QUERY);
|
|
|
|
Any aAny =xPropertySet->getPropertyValue(sPropertyReferenceId);
|
2006-07-19 15:37:17 +00:00
|
|
|
sal_Int16 nID = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
aAny >>= nID;
|
|
|
|
|
|
|
|
// ... and insert into map
|
|
|
|
rHelper.InsertFootnoteID(
|
2004-07-13 07:31:41 +00:00
|
|
|
xAttrList->getValueByIndex(nAttr2),
|
2000-09-18 16:07:07 +00:00
|
|
|
nID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save old cursor and install new one
|
|
|
|
xOldCursor = rHelper.GetCursor();
|
|
|
|
Reference<XText> xText(xTextContent, UNO_QUERY);
|
|
|
|
rHelper.SetCursor(xText->createTextCursor());
|
|
|
|
|
2001-07-19 12:16:33 +00:00
|
|
|
// remember old list item and block (#89891#) and reset them
|
|
|
|
// for the footnote
|
2008-10-01 06:34:11 +00:00
|
|
|
rHelper.PushListContext();
|
|
|
|
mbListContextPushed = true;
|
2001-07-19 12:16:33 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// remember footnote (for CreateChildContext)
|
|
|
|
Reference<XFootnote> xNote(xTextContent, UNO_QUERY);
|
|
|
|
xFootnote = xNote;
|
|
|
|
}
|
|
|
|
// else: ignore footnote! Content will be merged into document.
|
|
|
|
}
|
|
|
|
|
2006-06-19 17:39:29 +00:00
|
|
|
void XMLFootnoteImportContext::Characters(const OUString&)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// ignore characters! Text must be contained in paragraphs!
|
|
|
|
// rHelper.InsertString(rString);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLFootnoteImportContext::EndElement()
|
|
|
|
{
|
|
|
|
// get rid of last dummy paragraph
|
2001-03-09 06:23:23 +00:00
|
|
|
rHelper.DeleteParagraph();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// reinstall old cursor
|
|
|
|
rHelper.SetCursor(xOldCursor);
|
2001-07-19 12:16:33 +00:00
|
|
|
|
|
|
|
// reinstall old list item
|
2008-10-01 06:34:11 +00:00
|
|
|
if (mbListContextPushed) {
|
|
|
|
rHelper.PopListContext();
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2000-09-27 14:58:45 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
SvXMLImportContext *XMLFootnoteImportContext::CreateChildContext(
|
2006-06-19 17:39:29 +00:00
|
|
|
sal_uInt16 p_nPrefix,
|
2000-09-18 16:07:07 +00:00
|
|
|
const OUString& rLocalName,
|
|
|
|
const Reference<XAttributeList> & xAttrList )
|
|
|
|
{
|
2000-09-27 14:58:45 +00:00
|
|
|
SvXMLImportContext* pContext = NULL;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-09-27 14:58:45 +00:00
|
|
|
SvXMLTokenMap aTokenMap(aFootnoteChildTokenMap);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-06-19 17:39:29 +00:00
|
|
|
switch(aTokenMap.Get(p_nPrefix, rLocalName))
|
2000-09-27 14:58:45 +00:00
|
|
|
{
|
2004-07-13 07:31:41 +00:00
|
|
|
case XML_TOK_FTN_NOTE_CITATION:
|
2000-09-27 14:58:45 +00:00
|
|
|
{
|
|
|
|
// little hack: we only care for one attribute of the citation
|
|
|
|
// element. We handle that here, and then return a
|
|
|
|
// default context.
|
2001-01-02 13:41:38 +00:00
|
|
|
sal_Int16 nLength = xAttrList->getLength();
|
|
|
|
for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-09-27 14:58:45 +00:00
|
|
|
OUString sLocalName;
|
|
|
|
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
|
|
|
|
GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
|
|
|
|
&sLocalName );
|
|
|
|
|
|
|
|
if ( (nPrefix == XML_NAMESPACE_TEXT) &&
|
2001-06-29 20:07:26 +00:00
|
|
|
IsXMLToken( sLocalName, XML_LABEL ) )
|
2000-09-27 14:58:45 +00:00
|
|
|
{
|
|
|
|
xFootnote->setLabel(xAttrList->getValueByIndex(nAttr));
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2000-09-27 14:58:45 +00:00
|
|
|
|
|
|
|
// ignore content: return default context
|
|
|
|
pContext = new SvXMLImportContext(GetImport(),
|
2006-06-19 17:39:29 +00:00
|
|
|
p_nPrefix, rLocalName);
|
2000-09-27 14:58:45 +00:00
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 07:31:41 +00:00
|
|
|
case XML_TOK_FTN_NOTE_BODY:
|
2000-09-27 14:58:45 +00:00
|
|
|
// return footnote body
|
|
|
|
pContext = new XMLFootnoteBodyImportContext(GetImport(),
|
2006-06-19 17:39:29 +00:00
|
|
|
p_nPrefix, rLocalName);
|
2000-09-27 14:58:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// default:
|
2006-06-19 17:39:29 +00:00
|
|
|
pContext = SvXMLImportContext::CreateChildContext(p_nPrefix,
|
2000-09-27 14:58:45 +00:00
|
|
|
rLocalName,
|
|
|
|
xAttrList);
|
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2000-09-27 14:58:45 +00:00
|
|
|
|
|
|
|
return pContext;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|