2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-11-30 15:46:20 +00:00
|
|
|
|
|
|
|
#include "XMLIndexMarkExport.hxx"
|
2016-06-02 15:06:06 +02:00
|
|
|
#include <o3tl/any.hxx>
|
2000-11-30 15:46:20 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2001-05-14 12:01:56 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
#include <sax/tools/converter.hxx>
|
2007-06-27 14:57:59 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <xmloff/xmlnmspe.hxx>
|
2007-06-27 14:57:59 +00:00
|
|
|
#include <xmloff/xmlexp.hxx>
|
2000-11-30 15:46:20 +00:00
|
|
|
|
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
|
|
|
|
2000-11-30 15:46:20 +00:00
|
|
|
using ::com::sun::star::beans::XPropertySet;
|
2001-05-14 12:01:56 +00:00
|
|
|
using ::com::sun::star::beans::XPropertySetInfo;
|
2000-11-30 15:46:20 +00:00
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
|
|
|
|
|
|
|
|
XMLIndexMarkExport::XMLIndexMarkExport(
|
2012-08-15 16:18:53 +02:00
|
|
|
SvXMLExport& rExp)
|
2013-02-26 22:00:44 +01:00
|
|
|
: sLevel("Level")
|
|
|
|
, sUserIndexName("UserIndexName")
|
|
|
|
, sPrimaryKey("PrimaryKey")
|
|
|
|
, sSecondaryKey("SecondaryKey")
|
|
|
|
, sDocumentIndexMark("DocumentIndexMark")
|
|
|
|
, sIsStart("IsStart")
|
|
|
|
, sIsCollapsed("IsCollapsed")
|
|
|
|
, sAlternativeText("AlternativeText")
|
|
|
|
, sTextReading("TextReading")
|
|
|
|
, sPrimaryKeyReading("PrimaryKeyReading")
|
|
|
|
, sSecondaryKeyReading("SecondaryKeyReading")
|
|
|
|
, sMainEntry("IsMainEntry")
|
2006-06-19 17:40:20 +00:00
|
|
|
, rExport(rExp)
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
const enum XMLTokenEnum lcl_pTocMarkNames[] =
|
|
|
|
{ XML_TOC_MARK, XML_TOC_MARK_START, XML_TOC_MARK_END };
|
|
|
|
const enum XMLTokenEnum lcl_pUserIndexMarkName[] =
|
|
|
|
{ XML_USER_INDEX_MARK,
|
|
|
|
XML_USER_INDEX_MARK_START, XML_USER_INDEX_MARK_END };
|
|
|
|
const enum XMLTokenEnum lcl_pAlphaIndexMarkName[] =
|
|
|
|
{ XML_ALPHABETICAL_INDEX_MARK,
|
|
|
|
XML_ALPHABETICAL_INDEX_MARK_START,
|
|
|
|
XML_ALPHABETICAL_INDEX_MARK_END };
|
2000-11-30 15:46:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
XMLIndexMarkExport::~XMLIndexMarkExport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLIndexMarkExport::ExportIndexMark(
|
|
|
|
const Reference<XPropertySet> & rPropSet,
|
2014-04-07 16:42:18 +02:00
|
|
|
bool bAutoStyles)
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
|
|
|
/// index marks have no styles!
|
|
|
|
if (!bAutoStyles)
|
|
|
|
{
|
2015-11-10 10:29:15 +01:00
|
|
|
const enum XMLTokenEnum * pElements = nullptr;
|
2000-11-30 15:46:20 +00:00
|
|
|
sal_Int8 nElementNo = -1;
|
|
|
|
|
|
|
|
// get index mark
|
|
|
|
Any aAny;
|
|
|
|
aAny = rPropSet->getPropertyValue(sDocumentIndexMark);
|
|
|
|
Reference<XPropertySet> xIndexMarkPropSet;
|
|
|
|
aAny >>= xIndexMarkPropSet;
|
|
|
|
|
|
|
|
// common: handling of start, end, collapsed entries and
|
|
|
|
// alternative text
|
|
|
|
|
|
|
|
// collapsed/alternative text entry?
|
|
|
|
aAny = rPropSet->getPropertyValue(sIsCollapsed);
|
2016-06-10 15:52:05 +02:00
|
|
|
if (*o3tl::doAccess<bool>(aAny))
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
|
|
|
// collapsed entry: needs alternative text
|
|
|
|
nElementNo = 0;
|
|
|
|
|
|
|
|
aAny = xIndexMarkPropSet->getPropertyValue(sAlternativeText);
|
|
|
|
OUString sTmp;
|
|
|
|
aAny >>= sTmp;
|
2012-01-26 17:05:51 -02:00
|
|
|
DBG_ASSERT(!sTmp.isEmpty(),
|
2000-11-30 15:46:20 +00:00
|
|
|
"collapsed index mark without alternative text");
|
2001-06-29 20:07:26 +00:00
|
|
|
rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STRING_VALUE, sTmp);
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// start and end entries: has ID
|
|
|
|
aAny = rPropSet->getPropertyValue(sIsStart);
|
2016-06-10 15:52:05 +02:00
|
|
|
nElementNo = *o3tl::doAccess<bool>(aAny) ? 1 : 2;
|
2000-11-30 15:46:20 +00:00
|
|
|
|
|
|
|
// generate ID
|
|
|
|
OUStringBuffer sBuf;
|
|
|
|
GetID(sBuf, xIndexMarkPropSet);
|
2001-06-29 20:07:26 +00:00
|
|
|
rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
|
|
|
|
sBuf.makeStringAndClear());
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// distinguish between TOC, user, alphab. index marks by
|
|
|
|
// asking for specific properties
|
|
|
|
// Export attributes for -mark-start and -mark elements,
|
|
|
|
// but not for -mark-end
|
2001-05-14 12:01:56 +00:00
|
|
|
Reference<XPropertySetInfo> xPropertySetInfo =
|
|
|
|
xIndexMarkPropSet->getPropertySetInfo();
|
2001-06-15 09:37:08 +00:00
|
|
|
if (xPropertySetInfo->hasPropertyByName(sUserIndexName))
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
// user index mark
|
2001-06-29 20:07:26 +00:00
|
|
|
pElements = lcl_pUserIndexMarkName;
|
2000-11-30 15:46:20 +00:00
|
|
|
if (nElementNo != 2)
|
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
ExportUserIndexMarkAttributes(xIndexMarkPropSet);
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-14 12:01:56 +00:00
|
|
|
else if (xPropertySetInfo->hasPropertyByName(sPrimaryKey))
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
|
|
|
// alphabetical index mark
|
2001-06-29 20:07:26 +00:00
|
|
|
pElements = lcl_pAlphaIndexMarkName;
|
2000-11-30 15:46:20 +00:00
|
|
|
if (nElementNo != 2)
|
|
|
|
{
|
|
|
|
ExportAlphabeticalIndexMarkAttributes(xIndexMarkPropSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
// table of content:
|
2001-06-29 20:07:26 +00:00
|
|
|
pElements = lcl_pTocMarkNames;
|
2000-11-30 15:46:20 +00:00
|
|
|
if (nElementNo != 2)
|
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
ExportTOCMarkAttributes(xIndexMarkPropSet);
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// export element
|
2015-11-10 10:29:15 +01:00
|
|
|
DBG_ASSERT(pElements != nullptr, "illegal element array");
|
2000-11-30 15:46:20 +00:00
|
|
|
DBG_ASSERT(nElementNo >= 0, "illegal name array index");
|
|
|
|
DBG_ASSERT(nElementNo <= 2, "illegal name array index");
|
|
|
|
|
2015-11-10 10:29:15 +01:00
|
|
|
if ((pElements != nullptr) && (nElementNo != -1))
|
2000-11-30 15:46:20 +00:00
|
|
|
{
|
|
|
|
SvXMLElementExport aElem(rExport,
|
|
|
|
XML_NAMESPACE_TEXT,
|
2001-06-29 20:07:26 +00:00
|
|
|
pElements[nElementNo],
|
2014-03-28 16:28:51 +02:00
|
|
|
false, false);
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLIndexMarkExport::ExportTOCMarkAttributes(
|
|
|
|
const Reference<XPropertySet> & rPropSet)
|
|
|
|
{
|
|
|
|
// outline level
|
2006-07-19 15:37:40 +00:00
|
|
|
sal_Int16 nLevel = 0;
|
2000-11-30 15:46:20 +00:00
|
|
|
Any aAny = rPropSet->getPropertyValue(sLevel);
|
|
|
|
aAny >>= nLevel;
|
|
|
|
OUStringBuffer sBuf;
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
::sax::Converter::convertNumber(sBuf, static_cast<sal_Int32>(nLevel + 1));
|
2001-06-29 20:07:26 +00:00
|
|
|
rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
|
2000-11-30 15:46:20 +00:00
|
|
|
sBuf.makeStringAndClear());
|
|
|
|
}
|
|
|
|
|
2012-10-11 17:52:52 +02:00
|
|
|
static void lcl_ExportPropertyString( SvXMLExport& rExport,
|
2002-07-03 15:18:46 +00:00
|
|
|
const Reference<XPropertySet> & rPropSet,
|
2011-07-30 23:51:40 +02:00
|
|
|
const OUString & sProperty,
|
2002-07-03 15:18:46 +00:00
|
|
|
XMLTokenEnum eToken,
|
|
|
|
Any& rAny )
|
|
|
|
{
|
|
|
|
rAny = rPropSet->getPropertyValue( sProperty );
|
|
|
|
|
|
|
|
OUString sValue;
|
|
|
|
if( rAny >>= sValue )
|
|
|
|
{
|
2012-01-26 17:05:51 -02:00
|
|
|
if( !sValue.isEmpty() )
|
2002-07-03 15:18:46 +00:00
|
|
|
{
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, sValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 17:52:52 +02:00
|
|
|
static void lcl_ExportPropertyBool( SvXMLExport& rExport,
|
2003-03-27 17:21:03 +00:00
|
|
|
const Reference<XPropertySet> & rPropSet,
|
2011-07-30 23:51:40 +02:00
|
|
|
const OUString & sProperty,
|
2003-03-27 17:21:03 +00:00
|
|
|
XMLTokenEnum eToken,
|
|
|
|
Any& rAny )
|
|
|
|
{
|
|
|
|
rAny = rPropSet->getPropertyValue( sProperty );
|
|
|
|
|
2014-04-07 16:42:18 +02:00
|
|
|
bool bValue;
|
2003-03-27 17:21:03 +00:00
|
|
|
if( rAny >>= bValue )
|
|
|
|
{
|
|
|
|
if( bValue )
|
|
|
|
{
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, XML_TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-30 15:46:20 +00:00
|
|
|
void XMLIndexMarkExport::ExportUserIndexMarkAttributes(
|
|
|
|
const Reference<XPropertySet> & rPropSet)
|
|
|
|
{
|
|
|
|
// name of user index
|
|
|
|
// (unless it's the default index; then it has no name)
|
2002-07-03 15:18:46 +00:00
|
|
|
Any aAny;
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sUserIndexName, XML_INDEX_NAME, aAny );
|
2001-06-15 09:37:08 +00:00
|
|
|
|
|
|
|
// additionally export outline level; just reuse ExportTOCMarkAttributes
|
|
|
|
ExportTOCMarkAttributes( rPropSet );
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XMLIndexMarkExport::ExportAlphabeticalIndexMarkAttributes(
|
|
|
|
const Reference<XPropertySet> & rPropSet)
|
|
|
|
{
|
|
|
|
// primary and secondary keys (if available)
|
2002-07-03 15:18:46 +00:00
|
|
|
Any aAny;
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sTextReading, XML_STRING_VALUE_PHONETIC, aAny );
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKey, XML_KEY1, aAny );
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKeyReading, XML_KEY1_PHONETIC, aAny );
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKey, XML_KEY2, aAny );
|
|
|
|
lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKeyReading, XML_KEY2_PHONETIC, aAny );
|
2003-03-27 17:21:03 +00:00
|
|
|
lcl_ExportPropertyBool( rExport, rPropSet, sMainEntry, XML_MAIN_ENTRY, aAny );
|
2000-11-30 15:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XMLIndexMarkExport::GetID(
|
|
|
|
OUStringBuffer& sBuf,
|
|
|
|
const Reference<XPropertySet> & rPropSet)
|
|
|
|
{
|
|
|
|
// HACK: use address of object to form identifier
|
2006-06-19 17:40:20 +00:00
|
|
|
sal_Int64 nId = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(rPropSet.get()));
|
2016-10-31 10:27:02 +02:00
|
|
|
sBuf.append("IMark");
|
2000-11-30 15:46:20 +00:00
|
|
|
sBuf.append(nId);
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|