update dev300-m58
[ooovba.git] / xmloff / source / text / XMLIndexTOCSourceContext.cxx
blobe1ad1b9975b0e596a8ec7d0e7978f3e7727d852d
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: XMLIndexTOCSourceContext.cxx,v $
10 * $Revision: 1.12 $
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 "XMLIndexTOCSourceContext.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include "XMLIndexTemplateContext.hxx"
39 #include "XMLIndexTitleTemplateContext.hxx"
40 #include "XMLIndexTOCStylesContext.hxx"
41 #include <xmloff/xmlictxt.hxx>
42 #include <xmloff/xmlimp.hxx>
43 #include <xmloff/txtimp.hxx>
44 #include "xmlnmspe.hxx"
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <tools/debug.hxx>
49 #include <rtl/ustring.hxx>
53 using namespace ::xmloff::token;
55 using ::rtl::OUString;
56 using ::com::sun::star::beans::XPropertySet;
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::uno::Any;
59 using ::com::sun::star::xml::sax::XAttributeList;
61 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
62 const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline";
63 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
64 const sal_Char sAPI_Level[] = "Level";
65 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
68 TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext );
70 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
71 SvXMLImport& rImport,
72 sal_uInt16 nPrfx,
73 const OUString& rLocalName,
74 Reference<XPropertySet> & rPropSet)
75 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True)
76 , sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks))
77 , sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level))
78 , sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline))
79 , sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles))
80 // use all chapters by default
81 , nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
82 , bUseOutline(sal_True)
83 , bUseMarks(sal_True)
84 , bUseParagraphStyles(sal_False)
88 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
92 void XMLIndexTOCSourceContext::ProcessAttribute(
93 enum IndexSourceParamEnum eParam,
94 const OUString& rValue)
96 switch (eParam)
98 case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL:
99 if ( IsXMLToken( rValue, XML_NONE ) )
101 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
102 // OUTLINE_LEVEL with values none|1..10. For backwards
103 // compatibility, 'none' must still be read.
104 bUseOutline = sal_False;
106 else
108 sal_Int32 nTmp;
109 if (SvXMLUnitConverter::convertNumber(
110 nTmp, rValue, 1, GetImport().GetTextImport()->
111 GetChapterNumbering()->getCount()))
113 bUseOutline = sal_True;
114 nOutlineLevel = nTmp;
117 break;
119 case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL:
121 sal_Bool bTmp;
122 if (SvXMLUnitConverter::convertBool(bTmp, rValue))
124 bUseOutline = bTmp;
126 break;
130 case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
132 sal_Bool bTmp;
133 if (SvXMLUnitConverter::convertBool(bTmp, rValue))
135 bUseMarks = bTmp;
137 break;
140 case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
142 sal_Bool bTmp;
143 if (SvXMLUnitConverter::convertBool(bTmp, rValue))
145 bUseParagraphStyles = bTmp;
147 break;
150 default:
151 // default: ask superclass
152 XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
153 break;
157 void XMLIndexTOCSourceContext::EndElement()
159 Any aAny;
161 aAny.setValue(&bUseMarks, ::getBooleanCppuType());
162 rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
164 aAny.setValue(&bUseOutline, ::getBooleanCppuType());
165 rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny);
167 aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType());
168 rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
170 aAny <<= (sal_Int16)nOutlineLevel;
171 rIndexPropertySet->setPropertyValue(sLevel, aAny);
173 // process common attributes
174 XMLIndexSourceBaseContext::EndElement();
178 SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext(
179 sal_uInt16 nPrefix,
180 const OUString& rLocalName,
181 const Reference<XAttributeList> & xAttrList )
183 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
184 IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) )
186 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
187 nPrefix, rLocalName,
188 aLevelNameTOCMap,
189 XML_OUTLINE_LEVEL,
190 aLevelStylePropNameTOCMap,
191 aAllowedTokenTypesTOC, sal_True );
193 else
195 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
196 rLocalName,
197 xAttrList);