xref: /trunk/main/xmloff/source/text/XMLIndexTOCSourceContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 
32 #include "XMLIndexTOCSourceContext.hxx"
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/container/XIndexReplace.hpp>
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 <xmloff/xmluconv.hxx>
45 #include <tools/debug.hxx>
46 #include <rtl/ustring.hxx>
47 
48 
49 
50 using namespace ::xmloff::token;
51 
52 using ::rtl::OUString;
53 using ::com::sun::star::beans::XPropertySet;
54 using ::com::sun::star::uno::Reference;
55 using ::com::sun::star::uno::Any;
56 using ::com::sun::star::xml::sax::XAttributeList;
57 
58 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
59 const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline";
60 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
61 const sal_Char sAPI_Level[] = "Level";
62 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
63 
64 
65 TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext );
66 
67 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
68     SvXMLImport& rImport,
69     sal_uInt16 nPrfx,
70     const OUString& rLocalName,
71     Reference<XPropertySet> & rPropSet)
72 :   XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True)
73 ,   sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks))
74 ,   sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level))
75 ,   sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline))
76 ,   sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles))
77     // use all chapters by default
78 ,   nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
79 ,   bUseOutline(sal_True)
80 ,   bUseMarks(sal_True)
81 ,   bUseParagraphStyles(sal_False)
82 {
83 }
84 
85 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
86 {
87 }
88 
89 void XMLIndexTOCSourceContext::ProcessAttribute(
90     enum IndexSourceParamEnum eParam,
91     const OUString& rValue)
92 {
93     switch (eParam)
94     {
95         case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL:
96             if ( IsXMLToken( rValue, XML_NONE ) )
97             {
98                 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
99                 // OUTLINE_LEVEL with values none|1..10. For backwards
100                 // compatibility, 'none' must still be read.
101                 bUseOutline = sal_False;
102             }
103             else
104             {
105                 sal_Int32 nTmp;
106                 if (SvXMLUnitConverter::convertNumber(
107                     nTmp, rValue, 1, GetImport().GetTextImport()->
108                     GetChapterNumbering()->getCount()))
109                 {
110                     bUseOutline = sal_True;
111                     nOutlineLevel = nTmp;
112                 }
113             }
114             break;
115 
116         case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL:
117         {
118             sal_Bool bTmp;
119             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
120             {
121                 bUseOutline = bTmp;
122             }
123             break;
124         }
125 
126 
127         case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
128         {
129             sal_Bool bTmp;
130             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
131             {
132                 bUseMarks = bTmp;
133             }
134             break;
135         }
136 
137         case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
138         {
139             sal_Bool bTmp;
140             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
141             {
142                 bUseParagraphStyles = bTmp;
143             }
144             break;
145         }
146 
147         default:
148             // default: ask superclass
149             XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
150             break;
151     }
152 }
153 
154 void XMLIndexTOCSourceContext::EndElement()
155 {
156     Any aAny;
157 
158     aAny.setValue(&bUseMarks, ::getBooleanCppuType());
159     rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
160 
161     aAny.setValue(&bUseOutline, ::getBooleanCppuType());
162     rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny);
163 
164     aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType());
165     rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
166 
167     aAny <<= (sal_Int16)nOutlineLevel;
168     rIndexPropertySet->setPropertyValue(sLevel, aAny);
169 
170     // process common attributes
171     XMLIndexSourceBaseContext::EndElement();
172 }
173 
174 
175 SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext(
176     sal_uInt16 nPrefix,
177     const OUString& rLocalName,
178     const Reference<XAttributeList> & xAttrList )
179 {
180     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
181          IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) )
182     {
183         return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
184                                            nPrefix, rLocalName,
185                                            aLevelNameTOCMap,
186                                            XML_OUTLINE_LEVEL,
187                                            aLevelStylePropNameTOCMap,
188                                            aAllowedTokenTypesTOC, sal_True );
189     }
190     else
191     {
192         return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
193                                                              rLocalName,
194                                                              xAttrList);
195     }
196 }
197