Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLIndexTableSourceContext.cxx
blobe79f6e8dc8b3fcf2b8e99a226cbcd7ed79e1d5ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexTableSourceContext.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexTableSourceContext.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
39 #ifndef _COM_SUN_STAR_TEXT_REFERENCEFIELD_PART_HPP
40 #include <com/sun/star/text/ReferenceFieldPart.hpp>
41 #endif
42 #include "XMLIndexTemplateContext.hxx"
43 #include "XMLIndexTitleTemplateContext.hxx"
44 #include "XMLIndexTOCStylesContext.hxx"
45 #include <xmloff/xmlictxt.hxx>
46 #include <xmloff/xmlimp.hxx>
47 #include <xmloff/txtimp.hxx>
48 #include "xmlnmspe.hxx"
49 #include <xmloff/nmspmap.hxx>
50 #include <xmloff/xmltoken.hxx>
51 #include <xmloff/xmluconv.hxx>
52 #include <tools/debug.hxx>
53 #include <rtl/ustring.hxx>
56 using namespace ::com::sun::star::text;
57 using namespace ::xmloff::token;
59 using ::rtl::OUString;
60 using ::com::sun::star::beans::XPropertySet;
61 using ::com::sun::star::uno::Reference;
62 using ::com::sun::star::uno::Any;
63 using ::com::sun::star::xml::sax::XAttributeList;
65 const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels";
66 const sal_Char sAPI_LabelCategory[] = "LabelCategory";
67 const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
70 TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
73 XMLIndexTableSourceContext::XMLIndexTableSourceContext(
74 SvXMLImport& rImport,
75 sal_uInt16 nPrfx,
76 const OUString& rLocalName,
77 Reference<XPropertySet> & rPropSet) :
78 XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
79 rPropSet, sal_False),
80 sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLabels)),
81 sLabelCategory(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelCategory)),
82 sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelDisplayType)),
83 bSequenceOK(sal_False),
84 bDisplayFormatOK(sal_False),
85 bUseCaption(sal_True)
89 XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
93 static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] =
96 { XML_TEXT, ReferenceFieldPart::TEXT },
97 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
98 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
100 // wrong values that previous versions wrote:
101 { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER },
102 { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION },
104 { XML_TOKEN_INVALID, 0 }
107 void XMLIndexTableSourceContext::ProcessAttribute(
108 enum IndexSourceParamEnum eParam,
109 const OUString& rValue)
111 sal_Bool bTmp;
113 switch (eParam)
115 case XML_TOK_INDEXSOURCE_USE_CAPTION:
116 if (SvXMLUnitConverter::convertBool(bTmp, rValue))
118 bUseCaption = bTmp;
120 break;
122 case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
123 sSequence = rValue;
124 bSequenceOK = sal_True;
125 break;
127 case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
129 sal_uInt16 nTmp;
130 if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
131 lcl_aReferenceTypeTokenMap))
133 nDisplayFormat = nTmp;
134 bDisplayFormatOK = sal_True;
136 break;
139 default:
140 XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
141 break;
146 void XMLIndexTableSourceContext::EndElement()
148 Any aAny;
150 aAny.setValue(&bUseCaption, ::getBooleanCppuType());
151 rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
153 if (bSequenceOK)
155 aAny <<= sSequence;
156 rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
159 if (bDisplayFormatOK)
161 aAny <<= nDisplayFormat;
162 rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
165 XMLIndexSourceBaseContext::EndElement();
169 SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
170 sal_uInt16 nPrefix,
171 const OUString& rLocalName,
172 const Reference<XAttributeList> & xAttrList )
174 if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
175 ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
177 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
178 nPrefix, rLocalName,
179 aLevelNameTableMap,
180 XML_TOKEN_INVALID, // no outline-level attr
181 aLevelStylePropNameTableMap,
182 aAllowedTokenTypesTable);
184 else
186 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
187 rLocalName,
188 xAttrList);