1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "XMLIndexSimpleEntryContext.hxx"
29cdf0e10cSrcweir #include "XMLIndexTemplateContext.hxx"
30cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
32cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
33cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
34cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
36cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //using namespace ::com::sun::star::text;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
43cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValues;
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
46cdf0e10cSrcweir using ::com::sun::star::uno::Any;
47cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
48cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
49cdf0e10cSrcweir using ::xmloff::token::XML_STYLE_NAME;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir const sal_Char sAPI_TokenType[] = "TokenType";
52cdf0e10cSrcweir const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
53cdf0e10cSrcweir 
54cdf0e10cSrcweir TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext);
55cdf0e10cSrcweir 
XMLIndexSimpleEntryContext(SvXMLImport & rImport,const OUString & rEntry,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName)56cdf0e10cSrcweir XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
57cdf0e10cSrcweir 	SvXMLImport& rImport,
58cdf0e10cSrcweir 	const OUString& rEntry,
59cdf0e10cSrcweir 	XMLIndexTemplateContext& rTemplate,
60cdf0e10cSrcweir 	sal_uInt16 nPrfx,
61cdf0e10cSrcweir 	const OUString& rLocalName )
62cdf0e10cSrcweir :	SvXMLImportContext(rImport, nPrfx, rLocalName)
63cdf0e10cSrcweir ,	rEntryType(rEntry)
64cdf0e10cSrcweir ,	bCharStyleNameOK(sal_False)
65cdf0e10cSrcweir ,	rTemplateContext(rTemplate)
66cdf0e10cSrcweir ,	nValues(1)
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
~XMLIndexSimpleEntryContext()70cdf0e10cSrcweir XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
StartElement(const Reference<XAttributeList> & xAttrList)74cdf0e10cSrcweir void XMLIndexSimpleEntryContext::StartElement(
75cdf0e10cSrcweir 	const Reference<XAttributeList> & xAttrList)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	// we know only one attribute: style-name
78cdf0e10cSrcweir 	sal_Int16 nLength = xAttrList->getLength();
79cdf0e10cSrcweir 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		OUString sLocalName;
82cdf0e10cSrcweir 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
83cdf0e10cSrcweir 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
84cdf0e10cSrcweir 							  &sLocalName );
85cdf0e10cSrcweir 		if ( (XML_NAMESPACE_TEXT == nPrefix) &&
86cdf0e10cSrcweir 			 IsXMLToken(sLocalName, XML_STYLE_NAME) )
87cdf0e10cSrcweir 		{
88cdf0e10cSrcweir 			sCharStyleName = xAttrList->getValueByIndex(nAttr);
89cdf0e10cSrcweir             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
90cdf0e10cSrcweir                 XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
91cdf0e10cSrcweir             // #142494#: Check if style exists
92cdf0e10cSrcweir             const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
93cdf0e10cSrcweir                 GetImport().GetTextImport()->GetTextStyles();
94cdf0e10cSrcweir             if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
95cdf0e10cSrcweir                 bCharStyleNameOK = sal_True;
96cdf0e10cSrcweir             else
97cdf0e10cSrcweir                 bCharStyleNameOK = sal_False;
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	// if we have a style name, set it!
102cdf0e10cSrcweir 	if (bCharStyleNameOK)
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		nValues++;
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
EndElement()109cdf0e10cSrcweir void XMLIndexSimpleEntryContext::EndElement()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	Sequence<PropertyValue> aValues(nValues);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	FillPropertyValues(aValues);
114cdf0e10cSrcweir 	rTemplateContext.addTemplateEntry(aValues);
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
FillPropertyValues(::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & rValues)117cdf0e10cSrcweir void XMLIndexSimpleEntryContext::FillPropertyValues(
118cdf0e10cSrcweir 	::com::sun::star::uno::Sequence<
119cdf0e10cSrcweir 		::com::sun::star::beans::PropertyValue> & rValues)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	// due to the limited number of subclasses, we fill the values
122cdf0e10cSrcweir 	// directly into the slots. Subclasses will have to know they can
123cdf0e10cSrcweir 	// only use slot so-and-so.
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	Any aAny;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// token type
128cdf0e10cSrcweir 	rValues[0].Name = rTemplateContext.sTokenType;
129cdf0e10cSrcweir 	aAny <<= rEntryType;
130cdf0e10cSrcweir 	rValues[0].Value = aAny;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	// char style
133cdf0e10cSrcweir 	if (bCharStyleNameOK)
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		rValues[1].Name = rTemplateContext.sCharacterStyleName;
136cdf0e10cSrcweir 		aAny <<= GetImport().GetStyleDisplayName(
137cdf0e10cSrcweir 									XML_STYLE_FAMILY_TEXT_TEXT,
138cdf0e10cSrcweir 									sCharStyleName );
139cdf0e10cSrcweir 		rValues[1].Value = aAny;
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir }
143