bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLIndexTableSourceContext.cxx
blobba66fd5705c2af01e9ab8677330eefd79fd87457
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "XMLIndexTableSourceContext.hxx"
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XIndexReplace.hpp>
25 #include <com/sun/star/text/ReferenceFieldPart.hpp>
27 #include <sax/tools/converter.hxx>
29 #include "XMLIndexTemplateContext.hxx"
30 #include "XMLIndexTitleTemplateContext.hxx"
31 #include "XMLIndexTOCStylesContext.hxx"
32 #include <xmloff/xmlictxt.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/txtimp.hxx>
35 #include <xmloff/xmlnmspe.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include <rtl/ustring.hxx>
42 using namespace ::com::sun::star::text;
43 using namespace ::xmloff::token;
45 using ::com::sun::star::beans::XPropertySet;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::xml::sax::XAttributeList;
50 const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels";
51 const sal_Char sAPI_LabelCategory[] = "LabelCategory";
52 const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
55 TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
58 XMLIndexTableSourceContext::XMLIndexTableSourceContext(
59 SvXMLImport& rImport, sal_uInt16 nPrfx,
60 const OUString& rLocalName, Reference<XPropertySet> & rPropSet)
61 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
62 rPropSet, false)
63 , sCreateFromLabels(sAPI_CreateFromLabels)
64 , sLabelCategory(sAPI_LabelCategory)
65 , sLabelDisplayType(sAPI_LabelDisplayType)
66 , nDisplayFormat(0)
67 , bSequenceOK(false)
68 , bDisplayFormatOK(false)
69 , bUseCaption(true)
73 XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
77 static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
80 { XML_TEXT, ReferenceFieldPart::TEXT },
81 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
82 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
84 // wrong values that previous versions wrote:
85 { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER },
86 { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION },
88 { XML_TOKEN_INVALID, 0 }
91 void XMLIndexTableSourceContext::ProcessAttribute(
92 enum IndexSourceParamEnum eParam,
93 const OUString& rValue)
95 bool bTmp(false);
97 switch (eParam)
99 case XML_TOK_INDEXSOURCE_USE_CAPTION:
100 if (::sax::Converter::convertBool(bTmp, rValue))
102 bUseCaption = bTmp;
104 break;
106 case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
107 sSequence = rValue;
108 bSequenceOK = true;
109 break;
111 case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
113 sal_uInt16 nTmp;
114 if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
115 lcl_aReferenceTypeTokenMap))
117 nDisplayFormat = nTmp;
118 bDisplayFormatOK = true;
120 break;
123 default:
124 XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
125 break;
130 void XMLIndexTableSourceContext::EndElement()
132 Any aAny;
134 aAny.setValue(&bUseCaption, cppu::UnoType<bool>::get());
135 rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
137 if (bSequenceOK)
139 aAny <<= sSequence;
140 rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
143 if (bDisplayFormatOK)
145 aAny <<= nDisplayFormat;
146 rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
149 XMLIndexSourceBaseContext::EndElement();
153 SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
154 sal_uInt16 nPrefix,
155 const OUString& rLocalName,
156 const Reference<XAttributeList> & xAttrList )
158 if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
159 ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
161 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
162 nPrefix, rLocalName,
163 aLevelNameTableMap,
164 XML_TOKEN_INVALID, // no outline-level attr
165 aLevelStylePropNameTableMap,
166 aAllowedTokenTypesTable);
168 else
170 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
171 rLocalName,
172 xAttrList);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */