1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexTOCSourceContext.cxx,v $
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(
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
)
84 , bUseParagraphStyles(sal_False
)
88 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
92 void XMLIndexTOCSourceContext::ProcessAttribute(
93 enum IndexSourceParamEnum eParam
,
94 const OUString
& rValue
)
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
;
109 if (SvXMLUnitConverter::convertNumber(
110 nTmp
, rValue
, 1, GetImport().GetTextImport()->
111 GetChapterNumbering()->getCount()))
113 bUseOutline
= sal_True
;
114 nOutlineLevel
= nTmp
;
119 case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL
:
122 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
130 case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS
:
133 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
140 case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES
:
143 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
145 bUseParagraphStyles
= bTmp
;
151 // default: ask superclass
152 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
157 void XMLIndexTOCSourceContext::EndElement()
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(
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
,
190 aLevelStylePropNameTOCMap
,
191 aAllowedTokenTypesTOC
, sal_True
);
195 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,