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 "XMLIndexObjectSourceContext.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 using ::rtl::OUString;
46 using ::com::sun::star::beans::XPropertySet;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Any;
49 using ::com::sun::star::xml::sax::XAttributeList;
50 using ::xmloff::token::IsXMLToken;
51 using ::xmloff::token::XML_OBJECT_INDEX_ENTRY_TEMPLATE;
52 using ::xmloff::token::XML_TOKEN_INVALID;
53 
54 const sal_Char sAPI_CreateFromStarCalc[] = "CreateFromStarCalc";
55 const sal_Char sAPI_CreateFromStarChart[] = "CreateFromStarChart";
56 const sal_Char sAPI_CreateFromStarDraw[] = "CreateFromStarDraw";
57 const sal_Char sAPI_CreateFromStarImage[] = "CreateFromStarImage";
58 const sal_Char sAPI_CreateFromStarMath[] = "CreateFromStarMath";
59 const sal_Char sAPI_CreateFromOtherEmbeddedObjects[] = "CreateFromOtherEmbeddedObjects";
60 
61 
62 TYPEINIT1( XMLIndexObjectSourceContext, XMLIndexSourceBaseContext );
63 
XMLIndexObjectSourceContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet)64 XMLIndexObjectSourceContext::XMLIndexObjectSourceContext(
65 	SvXMLImport& rImport,
66 	sal_uInt16 nPrfx,
67 	const OUString& rLocalName,
68 	Reference<XPropertySet> & rPropSet) :
69 		XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
70 								  rPropSet, sal_False),
71 		sCreateFromStarCalc(RTL_CONSTASCII_USTRINGPARAM(
72 			sAPI_CreateFromStarCalc)),
73 		sCreateFromStarChart(RTL_CONSTASCII_USTRINGPARAM(
74 			sAPI_CreateFromStarChart)),
75 		sCreateFromStarDraw(RTL_CONSTASCII_USTRINGPARAM(
76 			sAPI_CreateFromStarDraw)),
77 		sCreateFromStarMath(RTL_CONSTASCII_USTRINGPARAM(
78 			sAPI_CreateFromStarMath)),
79 		sCreateFromOtherEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM(
80 			sAPI_CreateFromOtherEmbeddedObjects)),
81 		bUseCalc(sal_False),
82 		bUseChart(sal_False),
83 		bUseDraw(sal_False),
84 		bUseMath(sal_False),
85 		bUseOtherObjects(sal_False)
86 {
87 }
88 
~XMLIndexObjectSourceContext()89 XMLIndexObjectSourceContext::~XMLIndexObjectSourceContext()
90 {
91 }
92 
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)93 void XMLIndexObjectSourceContext::ProcessAttribute(
94 	enum IndexSourceParamEnum eParam,
95 	const OUString& rValue)
96 {
97 	switch (eParam)
98 	{
99 		sal_Bool bTmp;
100 
101 		case XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS:
102 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
103 			{
104 				bUseOtherObjects = bTmp;
105 			}
106 			break;
107 
108 		case XML_TOK_INDEXSOURCE_USE_SHEET:
109 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
110 			{
111 				bUseCalc = bTmp;
112 			}
113 			break;
114 
115 		case XML_TOK_INDEXSOURCE_USE_CHART:
116 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
117 			{
118 				bUseChart = bTmp;
119 			}
120 			break;
121 
122 		case XML_TOK_INDEXSOURCE_USE_DRAW:
123 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
124 			{
125 				bUseDraw = bTmp;
126 			}
127 			break;
128 
129 		case XML_TOK_INDEXSOURCE_USE_MATH:
130 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
131 			{
132 				bUseMath = bTmp;
133 			}
134 			break;
135 
136 		default:
137 			XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
138 			break;
139 	}
140 }
141 
EndElement()142 void XMLIndexObjectSourceContext::EndElement()
143 {
144 	Any aAny;
145 
146 	aAny.setValue(&bUseCalc, ::getBooleanCppuType());
147 	rIndexPropertySet->setPropertyValue(sCreateFromStarCalc, aAny);
148 
149 	aAny.setValue(&bUseChart, ::getBooleanCppuType());
150 	rIndexPropertySet->setPropertyValue(sCreateFromStarChart, aAny);
151 
152 	aAny.setValue(&bUseDraw, ::getBooleanCppuType());
153 	rIndexPropertySet->setPropertyValue(sCreateFromStarDraw, aAny);
154 
155 	aAny.setValue(&bUseMath, ::getBooleanCppuType());
156 	rIndexPropertySet->setPropertyValue(sCreateFromStarMath, aAny);
157 
158 	aAny.setValue(&bUseOtherObjects, ::getBooleanCppuType());
159 	rIndexPropertySet->setPropertyValue(sCreateFromOtherEmbeddedObjects, aAny);
160 
161 	XMLIndexSourceBaseContext::EndElement();
162 }
163 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)164 SvXMLImportContext* XMLIndexObjectSourceContext::CreateChildContext(
165 	sal_uInt16 nPrefix,
166 	const OUString& rLocalName,
167 	const Reference<XAttributeList> & xAttrList )
168 {
169 	if ( (XML_NAMESPACE_TEXT == nPrefix) &&
170 		 (IsXMLToken(rLocalName, XML_OBJECT_INDEX_ENTRY_TEMPLATE)) )
171 	{
172 		return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
173 										   nPrefix, rLocalName,
174 										   aLevelNameTableMap,
175 										   XML_TOKEN_INVALID, // no outline-level attr
176 										   aLevelStylePropNameTableMap,
177 										   aAllowedTokenTypesTable);
178 	}
179 	else
180 	{
181 		return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
182 															 rLocalName,
183 															 xAttrList);
184 	}
185 
186 }
187