1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexSimpleEntryContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexSimpleEntryContext.hxx"
36 #include "XMLIndexTemplateContext.hxx"
37 #include <xmloff/xmlictxt.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/txtimp.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
46 //using namespace ::com::sun::star::text;
48 using ::rtl::OUString
;
49 using ::com::sun::star::beans::PropertyValue
;
50 using ::com::sun::star::beans::PropertyValues
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::uno::Sequence
;
53 using ::com::sun::star::uno::Any
;
54 using ::com::sun::star::xml::sax::XAttributeList
;
55 using ::xmloff::token::IsXMLToken
;
56 using ::xmloff::token::XML_STYLE_NAME
;
58 const sal_Char sAPI_TokenType
[] = "TokenType";
59 const sal_Char sAPI_CharacterStyleName
[] = "CharacterStyleName";
61 TYPEINIT1( XMLIndexSimpleEntryContext
, SvXMLImportContext
);
63 XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
65 const OUString
& rEntry
,
66 XMLIndexTemplateContext
& rTemplate
,
68 const OUString
& rLocalName
)
69 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
71 , bCharStyleNameOK(sal_False
)
72 , rTemplateContext(rTemplate
)
77 XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
81 void XMLIndexSimpleEntryContext::StartElement(
82 const Reference
<XAttributeList
> & xAttrList
)
84 // we know only one attribute: style-name
85 sal_Int16 nLength
= xAttrList
->getLength();
86 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
89 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
90 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
92 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
93 IsXMLToken(sLocalName
, XML_STYLE_NAME
) )
95 sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
96 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
97 XML_STYLE_FAMILY_TEXT_TEXT
, sCharStyleName
);
98 // #142494#: Check if style exists
99 const Reference
< ::com::sun::star::container::XNameContainer
> & rStyles
=
100 GetImport().GetTextImport()->GetTextStyles();
101 if( rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
) )
102 bCharStyleNameOK
= sal_True
;
104 bCharStyleNameOK
= sal_False
;
108 // if we have a style name, set it!
109 if (bCharStyleNameOK
)
116 void XMLIndexSimpleEntryContext::EndElement()
118 Sequence
<PropertyValue
> aValues(nValues
);
120 FillPropertyValues(aValues
);
121 rTemplateContext
.addTemplateEntry(aValues
);
124 void XMLIndexSimpleEntryContext::FillPropertyValues(
125 ::com::sun::star::uno::Sequence
<
126 ::com::sun::star::beans::PropertyValue
> & rValues
)
128 // due to the limited number of subclasses, we fill the values
129 // directly into the slots. Subclasses will have to know they can
130 // only use slot so-and-so.
135 rValues
[0].Name
= rTemplateContext
.sTokenType
;
137 rValues
[0].Value
= aAny
;
140 if (bCharStyleNameOK
)
142 rValues
[1].Name
= rTemplateContext
.sCharacterStyleName
;
143 aAny
<<= GetImport().GetStyleDisplayName(
144 XML_STYLE_FAMILY_TEXT_TEXT
,
146 rValues
[1].Value
= aAny
;