1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 
28 #include "XMLIndexTOCSourceContext.hxx"
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include "XMLIndexTemplateContext.hxx"
32 #include "XMLIndexTitleTemplateContext.hxx"
33 #include "XMLIndexTOCStylesContext.hxx"
34 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/xmlimp.hxx>
36 #include <xmloff/txtimp.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <tools/debug.hxx>
42 #include <rtl/ustring.hxx>
43 
44 
45 
46 using namespace ::xmloff::token;
47 
48 using ::rtl::OUString;
49 using ::com::sun::star::beans::XPropertySet;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::xml::sax::XAttributeList;
53 
54 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
55 const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline";
56 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
57 const sal_Char sAPI_Level[] = "Level";
58 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
59 
60 
61 TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext );
62 
XMLIndexTOCSourceContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet)63 XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
64 	SvXMLImport& rImport,
65 	sal_uInt16 nPrfx,
66 	const OUString& rLocalName,
67 	Reference<XPropertySet> & rPropSet)
68 :	XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True)
69 ,	sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks))
70 ,	sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level))
71 ,	sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline))
72 ,	sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles))
73 	// use all chapters by default
74 ,	nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
75 ,	bUseOutline(sal_True)
76 ,	bUseMarks(sal_True)
77 ,	bUseParagraphStyles(sal_False)
78 {
79 }
80 
~XMLIndexTOCSourceContext()81 XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext()
82 {
83 }
84 
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)85 void XMLIndexTOCSourceContext::ProcessAttribute(
86 	enum IndexSourceParamEnum eParam,
87 	const OUString& rValue)
88 {
89 	switch (eParam)
90 	{
91 		case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL:
92 			if ( IsXMLToken( rValue, XML_NONE ) )
93 			{
94                 // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of
95                 // OUTLINE_LEVEL with values none|1..10. For backwards
96                 // compatibility, 'none' must still be read.
97 				bUseOutline = sal_False;
98 			}
99 			else
100 			{
101 				sal_Int32 nTmp;
102 				if (SvXMLUnitConverter::convertNumber(
103 					nTmp, rValue, 1, GetImport().GetTextImport()->
104 					GetChapterNumbering()->getCount()))
105 				{
106 					bUseOutline = sal_True;
107 					nOutlineLevel = nTmp;
108 				}
109 			}
110 			break;
111 
112 		case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL:
113         {
114 			sal_Bool bTmp;
115 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
116 			{
117 				bUseOutline = bTmp;
118 			}
119 			break;
120 		}
121 
122 
123 		case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
124 		{
125 			sal_Bool bTmp;
126 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
127 			{
128 				bUseMarks = bTmp;
129 			}
130 			break;
131 		}
132 
133 		case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
134 		{
135 			sal_Bool bTmp;
136 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
137 			{
138 				bUseParagraphStyles = bTmp;
139 			}
140 			break;
141 		}
142 
143 		default:
144 			// default: ask superclass
145 			XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
146 			break;
147 	}
148 }
149 
EndElement()150 void XMLIndexTOCSourceContext::EndElement()
151 {
152 	Any aAny;
153 
154 	aAny.setValue(&bUseMarks, ::getBooleanCppuType());
155 	rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
156 
157 	aAny.setValue(&bUseOutline, ::getBooleanCppuType());
158 	rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny);
159 
160 	aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType());
161 	rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
162 
163 	aAny <<= (sal_Int16)nOutlineLevel;
164 	rIndexPropertySet->setPropertyValue(sLevel, aAny);
165 
166 	// process common attributes
167 	XMLIndexSourceBaseContext::EndElement();
168 }
169 
170 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)171 SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext(
172 	sal_uInt16 nPrefix,
173 	const OUString& rLocalName,
174 	const Reference<XAttributeList> & xAttrList )
175 {
176 	if ( (XML_NAMESPACE_TEXT == nPrefix) &&
177 		 IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) )
178 	{
179 		return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
180 										   nPrefix, rLocalName,
181 										   aLevelNameTOCMap,
182 										   XML_OUTLINE_LEVEL,
183 										   aLevelStylePropNameTOCMap,
184 										   aAllowedTokenTypesTOC, sal_True );
185 	}
186 	else
187 	{
188 		return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
189 															 rLocalName,
190 															 xAttrList);
191 	}
192 }
193