Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "XMLIndexSimpleEntryContext.hxx"
21 : #include "XMLIndexTemplateContext.hxx"
22 : #include <xmloff/xmlictxt.hxx>
23 : #include <xmloff/xmlimp.hxx>
24 : #include <xmloff/txtimp.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include "xmloff/xmlnmspe.hxx"
27 : #include <xmloff/xmltoken.hxx>
28 : #include <xmloff/xmluconv.hxx>
29 :
30 : using ::rtl::OUString;
31 : using ::com::sun::star::beans::PropertyValue;
32 : using ::com::sun::star::beans::PropertyValues;
33 : using ::com::sun::star::uno::Reference;
34 : using ::com::sun::star::uno::Sequence;
35 : using ::com::sun::star::uno::Any;
36 : using ::com::sun::star::xml::sax::XAttributeList;
37 : using ::xmloff::token::IsXMLToken;
38 : using ::xmloff::token::XML_STYLE_NAME;
39 :
40 : const sal_Char sAPI_TokenType[] = "TokenType";
41 : const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
42 :
43 0 : TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext);
44 :
45 0 : XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
46 : SvXMLImport& rImport,
47 : const OUString& rEntry,
48 : XMLIndexTemplateContext& rTemplate,
49 : sal_uInt16 nPrfx,
50 : const OUString& rLocalName )
51 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
52 : , rEntryType(rEntry)
53 : , bCharStyleNameOK(sal_False)
54 : , rTemplateContext(rTemplate)
55 0 : , nValues(1)
56 : {
57 0 : }
58 :
59 0 : XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
60 : {
61 0 : }
62 :
63 0 : void XMLIndexSimpleEntryContext::StartElement(
64 : const Reference<XAttributeList> & xAttrList)
65 : {
66 : // we know only one attribute: style-name
67 0 : sal_Int16 nLength = xAttrList->getLength();
68 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
69 : {
70 0 : OUString sLocalName;
71 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
72 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
73 0 : &sLocalName );
74 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
75 0 : IsXMLToken(sLocalName, XML_STYLE_NAME) )
76 : {
77 0 : sCharStyleName = xAttrList->getValueByIndex(nAttr);
78 0 : OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
79 0 : XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
80 : // #142494#: Check if style exists
81 : const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
82 0 : GetImport().GetTextImport()->GetTextStyles();
83 0 : if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
84 0 : bCharStyleNameOK = sal_True;
85 : else
86 0 : bCharStyleNameOK = sal_False;
87 : }
88 0 : }
89 :
90 : // if we have a style name, set it!
91 0 : if (bCharStyleNameOK)
92 : {
93 0 : nValues++;
94 : }
95 :
96 0 : }
97 :
98 0 : void XMLIndexSimpleEntryContext::EndElement()
99 : {
100 0 : Sequence<PropertyValue> aValues(nValues);
101 :
102 0 : FillPropertyValues(aValues);
103 0 : rTemplateContext.addTemplateEntry(aValues);
104 0 : }
105 :
106 0 : void XMLIndexSimpleEntryContext::FillPropertyValues(
107 : ::com::sun::star::uno::Sequence<
108 : ::com::sun::star::beans::PropertyValue> & rValues)
109 : {
110 : // due to the limited number of subclasses, we fill the values
111 : // directly into the slots. Subclasses will have to know they can
112 : // only use slot so-and-so.
113 :
114 0 : Any aAny;
115 :
116 : // token type
117 0 : rValues[0].Name = rTemplateContext.sTokenType;
118 0 : aAny <<= rEntryType;
119 0 : rValues[0].Value = aAny;
120 :
121 : // char style
122 0 : if (bCharStyleNameOK)
123 : {
124 0 : rValues[1].Name = rTemplateContext.sCharacterStyleName;
125 0 : aAny <<= GetImport().GetStyleDisplayName(
126 : XML_STYLE_FAMILY_TEXT_TEXT,
127 0 : sCharStyleName );
128 0 : rValues[1].Value = aAny;
129 0 : }
130 :
131 0 : }
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|