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(
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
)
79 , bUseParagraphStyles(sal_False
)
83 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
87 void XMLIndexTOCSourceContext::ProcessAttribute(
88 enum IndexSourceParamEnum eParam
,
89 const OUString
& rValue
)
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
;
104 if (::sax::Converter::convertNumber(
105 nTmp
, rValue
, 1, GetImport().GetTextImport()->
106 GetChapterNumbering()->getCount()))
108 bUseOutline
= sal_True
;
109 nOutlineLevel
= nTmp
;
114 case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL
:
117 if (::sax::Converter::convertBool(bTmp
, rValue
))
125 case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS
:
128 if (::sax::Converter::convertBool(bTmp
, rValue
))
135 case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES
:
138 if (::sax::Converter::convertBool(bTmp
, rValue
))
140 bUseParagraphStyles
= bTmp
;
146 // default: ask superclass
147 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
152 void XMLIndexTOCSourceContext::EndElement()
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(
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
,
185 aLevelStylePropNameTOCMap
,
186 aAllowedTokenTypesTOC
, sal_True
);
190 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */