Bump for 3.6-28
[LibreOffice.git] / xmloff / source / text / XMLIndexTOCSourceContext.cxx
blob6ef66ac8ce7b146c479ac842804ce4324ca1f056
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "XMLIndexTOCSourceContext.hxx"
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/container/XIndexReplace.hpp>
34 #include <sax/tools/converter.hxx>
35 #include "XMLIndexTemplateContext.hxx"
36 #include "XMLIndexTitleTemplateContext.hxx"
37 #include "XMLIndexTOCStylesContext.hxx"
38 #include <xmloff/xmlictxt.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <rtl/ustring.hxx>
48 using namespace ::xmloff::token;
50 using ::rtl::OUString;
51 using ::com::sun::star::beans::XPropertySet;
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::uno::Any;
54 using ::com::sun::star::xml::sax::XAttributeList;
56 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
57 const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline";
58 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
59 const sal_Char sAPI_Level[] = "Level";
60 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
63 TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext );
65 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
66 SvXMLImport& rImport,
67 sal_uInt16 nPrfx,
68 const OUString& rLocalName,
69 Reference<XPropertySet> & rPropSet)
70 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True)
71 , sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks))
72 , sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level))
73 , sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline))
74 , sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles))
75 // use all chapters by default
76 , nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
77 , bUseOutline(sal_True)
78 , bUseMarks(sal_True)
79 , bUseParagraphStyles(sal_False)
83 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
87 void XMLIndexTOCSourceContext::ProcessAttribute(
88 enum IndexSourceParamEnum eParam,
89 const OUString& rValue)
91 switch (eParam)
93 case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL:
94 if ( IsXMLToken( rValue, XML_NONE ) )
96 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
97 // OUTLINE_LEVEL with values none|1..10. For backwards
98 // compatibility, 'none' must still be read.
99 bUseOutline = sal_False;
101 else
103 sal_Int32 nTmp;
104 if (::sax::Converter::convertNumber(
105 nTmp, rValue, 1, GetImport().GetTextImport()->
106 GetChapterNumbering()->getCount()))
108 bUseOutline = sal_True;
109 nOutlineLevel = nTmp;
112 break;
114 case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL:
116 bool bTmp(false);
117 if (::sax::Converter::convertBool(bTmp, rValue))
119 bUseOutline = bTmp;
121 break;
125 case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
127 bool bTmp(false);
128 if (::sax::Converter::convertBool(bTmp, rValue))
130 bUseMarks = bTmp;
132 break;
135 case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
137 bool bTmp(false);
138 if (::sax::Converter::convertBool(bTmp, rValue))
140 bUseParagraphStyles = bTmp;
142 break;
145 default:
146 // default: ask superclass
147 XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
148 break;
152 void XMLIndexTOCSourceContext::EndElement()
154 Any aAny;
156 aAny.setValue(&bUseMarks, ::getBooleanCppuType());
157 rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
159 aAny.setValue(&bUseOutline, ::getBooleanCppuType());
160 rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny);
162 aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType());
163 rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
165 aAny <<= (sal_Int16)nOutlineLevel;
166 rIndexPropertySet->setPropertyValue(sLevel, aAny);
168 // process common attributes
169 XMLIndexSourceBaseContext::EndElement();
173 SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext(
174 sal_uInt16 nPrefix,
175 const OUString& rLocalName,
176 const Reference<XAttributeList> & xAttrList )
178 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
179 IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) )
181 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
182 nPrefix, rLocalName,
183 aLevelNameTOCMap,
184 XML_OUTLINE_LEVEL,
185 aLevelStylePropNameTOCMap,
186 aAllowedTokenTypesTOC, sal_True );
188 else
190 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
191 rLocalName,
192 xAttrList);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */