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 "XMLIndexTableSourceContext.hxx"
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 
32 #ifndef _COM_SUN_STAR_TEXT_REFERENCEFIELD_PART_HPP
33 #include <com/sun/star/text/ReferenceFieldPart.hpp>
34 #endif
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 using namespace ::com::sun::star::text;
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_CreateFromLabels[] = "CreateFromLabels";
59 const sal_Char sAPI_LabelCategory[] = "LabelCategory";
60 const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
61 
62 
63 TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
64 
65 
XMLIndexTableSourceContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet)66 XMLIndexTableSourceContext::XMLIndexTableSourceContext(
67 	SvXMLImport& rImport,
68 	sal_uInt16 nPrfx,
69 	const OUString& rLocalName,
70 	Reference<XPropertySet> & rPropSet) :
71 		XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
72 								  rPropSet, sal_False),
73 		sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLabels)),
74 		sLabelCategory(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelCategory)),
75 		sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelDisplayType)),
76 		bSequenceOK(sal_False),
77 		bDisplayFormatOK(sal_False),
78 		bUseCaption(sal_True)
79 {
80 }
81 
~XMLIndexTableSourceContext()82 XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
83 {
84 }
85 
86 static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] =
87 {
88 
89 	{ XML_TEXT,			        ReferenceFieldPart::TEXT },
90 	{ XML_CATEGORY_AND_VALUE,	ReferenceFieldPart::CATEGORY_AND_NUMBER },
91 	{ XML_CAPTION, 		        ReferenceFieldPart::ONLY_CAPTION },
92 
93 	// wrong values that previous versions wrote:
94 	{ XML_CHAPTER, 		        ReferenceFieldPart::CATEGORY_AND_NUMBER },
95 	{ XML_PAGE,			        ReferenceFieldPart::ONLY_CAPTION },
96 
97 	{ XML_TOKEN_INVALID, 		0 }
98 };
99 
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)100 void XMLIndexTableSourceContext::ProcessAttribute(
101 	enum IndexSourceParamEnum eParam,
102 	const OUString& rValue)
103 {
104 	sal_Bool bTmp;
105 
106 	switch (eParam)
107 	{
108 		case XML_TOK_INDEXSOURCE_USE_CAPTION:
109 			if (SvXMLUnitConverter::convertBool(bTmp, rValue))
110 			{
111 				bUseCaption = bTmp;
112 			}
113 			break;
114 
115 		case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
116 			sSequence = rValue;
117 			bSequenceOK = sal_True;
118 			break;
119 
120 		case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
121 		{
122  			sal_uInt16 nTmp;
123  		    if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
124  												lcl_aReferenceTypeTokenMap))
125 			{
126  				nDisplayFormat = nTmp;
127  				bDisplayFormatOK = sal_True;
128  			}
129 			break;
130 		}
131 
132 		default:
133 			XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
134 			break;
135 	}
136 }
137 
138 
EndElement()139 void XMLIndexTableSourceContext::EndElement()
140 {
141 	Any aAny;
142 
143 	aAny.setValue(&bUseCaption, ::getBooleanCppuType());
144 	rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
145 
146 	if (bSequenceOK)
147 	{
148 		aAny <<= sSequence;
149 		rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
150 	}
151 
152 	if (bDisplayFormatOK)
153 	{
154 		aAny <<= nDisplayFormat;
155 		rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
156 	}
157 
158 	XMLIndexSourceBaseContext::EndElement();
159 }
160 
161 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)162 SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
163 	sal_uInt16 nPrefix,
164 	const OUString& rLocalName,
165 	const Reference<XAttributeList> & xAttrList )
166 {
167 	if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
168 		 ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
169 	{
170 		return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
171 										   nPrefix, rLocalName,
172 										   aLevelNameTableMap,
173 										   XML_TOKEN_INVALID, // no outline-level attr
174 										   aLevelStylePropNameTableMap,
175 										   aAllowedTokenTypesTable);
176 	}
177 	else
178 	{
179 		return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
180 															 rLocalName,
181 															 xAttrList);
182 	}
183 
184 }
185