xref: /AOO41X/main/xmloff/source/text/XMLIndexSimpleEntryContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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 "XMLIndexSimpleEntryContext.hxx"
29 #include "XMLIndexTemplateContext.hxx"
30 #include <xmloff/xmlictxt.hxx>
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/txtimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmluconv.hxx>
37 
38 
39 //using namespace ::com::sun::star::text;
40 
41 using ::rtl::OUString;
42 using ::com::sun::star::beans::PropertyValue;
43 using ::com::sun::star::beans::PropertyValues;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Any;
47 using ::com::sun::star::xml::sax::XAttributeList;
48 using ::xmloff::token::IsXMLToken;
49 using ::xmloff::token::XML_STYLE_NAME;
50 
51 const sal_Char sAPI_TokenType[] = "TokenType";
52 const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
53 
54 TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext);
55 
XMLIndexSimpleEntryContext(SvXMLImport & rImport,const OUString & rEntry,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName)56 XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
57     SvXMLImport& rImport,
58     const OUString& rEntry,
59     XMLIndexTemplateContext& rTemplate,
60     sal_uInt16 nPrfx,
61     const OUString& rLocalName )
62 :   SvXMLImportContext(rImport, nPrfx, rLocalName)
63 ,   rEntryType(rEntry)
64 ,   bCharStyleNameOK(sal_False)
65 ,   rTemplateContext(rTemplate)
66 ,   nValues(1)
67 {
68 }
69 
~XMLIndexSimpleEntryContext()70 XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
71 {
72 }
73 
StartElement(const Reference<XAttributeList> & xAttrList)74 void XMLIndexSimpleEntryContext::StartElement(
75     const Reference<XAttributeList> & xAttrList)
76 {
77     // we know only one attribute: style-name
78     sal_Int16 nLength = xAttrList->getLength();
79     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
80     {
81         OUString sLocalName;
82         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
83             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
84                               &sLocalName );
85         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
86              IsXMLToken(sLocalName, XML_STYLE_NAME) )
87         {
88             sCharStyleName = xAttrList->getValueByIndex(nAttr);
89             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
90                 XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
91             // #142494#: Check if style exists
92             const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
93                 GetImport().GetTextImport()->GetTextStyles();
94             if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
95                 bCharStyleNameOK = sal_True;
96             else
97                 bCharStyleNameOK = sal_False;
98         }
99     }
100 
101     // if we have a style name, set it!
102     if (bCharStyleNameOK)
103     {
104         nValues++;
105     }
106 
107 }
108 
EndElement()109 void XMLIndexSimpleEntryContext::EndElement()
110 {
111     Sequence<PropertyValue> aValues(nValues);
112 
113     FillPropertyValues(aValues);
114     rTemplateContext.addTemplateEntry(aValues);
115 }
116 
FillPropertyValues(::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & rValues)117 void XMLIndexSimpleEntryContext::FillPropertyValues(
118     ::com::sun::star::uno::Sequence<
119         ::com::sun::star::beans::PropertyValue> & rValues)
120 {
121     // due to the limited number of subclasses, we fill the values
122     // directly into the slots. Subclasses will have to know they can
123     // only use slot so-and-so.
124 
125     Any aAny;
126 
127     // token type
128     rValues[0].Name = rTemplateContext.sTokenType;
129     aAny <<= rEntryType;
130     rValues[0].Value = aAny;
131 
132     // char style
133     if (bCharStyleNameOK)
134     {
135         rValues[1].Name = rTemplateContext.sCharacterStyleName;
136         aAny <<= GetImport().GetStyleDisplayName(
137                                     XML_STYLE_FAMILY_TEXT_TEXT,
138                                     sCharStyleName );
139         rValues[1].Value = aAny;
140     }
141 
142 }
143