1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "XMLIndexTabStopEntryContext.hxx"
23 #include <sax/tools/converter.hxx>
25 #include "XMLIndexTemplateContext.hxx"
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include <rtl/ustring.hxx>
32 #include <sal/log.hxx>
34 using namespace ::xmloff::token
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::beans::PropertyValue
;
39 using ::com::sun::star::xml::sax::XAttributeList
;
42 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
44 XMLIndexTemplateContext
& rTemplate
,
46 const OUString
& rLocalName
) :
47 XMLIndexSimpleEntryContext(rImport
, "TokenTabStop",
48 rTemplate
, nPrfx
, rLocalName
),
51 bTabPositionOK(false),
52 bTabRightAligned(false),
54 bWithTab(true) // #i21237#
58 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
62 void XMLIndexTabStopEntryContext::StartElement(
63 const Reference
<XAttributeList
> & xAttrList
)
65 // process three attributes: type, position, leader char
66 sal_Int16 nLength
= xAttrList
->getLength();
67 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
70 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
71 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
73 OUString sAttr
= xAttrList
->getValueByIndex(nAttr
);
74 if (XML_NAMESPACE_STYLE
== nPrefix
)
76 if ( IsXMLToken( sLocalName
, XML_TYPE
) )
78 // if it's neither left nor right, value is
79 // ignored. Since left is default, we only need to
81 bTabRightAligned
= IsXMLToken( sAttr
, XML_RIGHT
);
83 else if ( IsXMLToken( sLocalName
, XML_POSITION
) )
86 if (GetImport().GetMM100UnitConverter().
87 convertMeasureToCore(nTmp
, sAttr
))
90 bTabPositionOK
= true;
93 else if ( IsXMLToken( sLocalName
, XML_LEADER_CHAR
) )
96 // valid only, if we have a char!
97 bLeaderCharOK
= !sAttr
.isEmpty();
100 else if ( IsXMLToken( sLocalName
, XML_WITH_TAB
) )
103 if (::sax::Converter::convertBool(bTmp
, sAttr
))
106 // else: unknown style: attribute -> ignore
108 // else: no style attribute -> ignore
111 // how many entries? #i21237#
112 m_nValues
+= 2 + (bTabPositionOK
? 1 : 0) + (bLeaderCharOK
? 1 : 0);
114 // now try parent class (for character style)
115 XMLIndexSimpleEntryContext::StartElement( xAttrList
);
118 void XMLIndexTabStopEntryContext::FillPropertyValues(
119 Sequence
<PropertyValue
> & rValues
)
121 // fill values from parent class (type + style name)
122 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
124 // get values array and next entry to be written;
125 sal_Int32 nNextEntry
= m_bCharStyleNameOK
? 2 : 1;
126 PropertyValue
* pValues
= rValues
.getArray();
129 pValues
[nNextEntry
].Name
= "TabStopRightAligned";
130 pValues
[nNextEntry
].Value
<<= bTabRightAligned
;
136 pValues
[nNextEntry
].Name
= "TabStopPosition";
137 pValues
[nNextEntry
].Value
<<= nTabPosition
;
144 pValues
[nNextEntry
].Name
= "TabStopFillCharacter";
145 pValues
[nNextEntry
].Value
<<= sLeaderChar
;
149 // tab character #i21237#
150 pValues
[nNextEntry
].Name
= "WithTab";
151 pValues
[nNextEntry
].Value
<<= bWithTab
;
154 // check whether we really filled all elements of the sequence
155 SAL_WARN_IF( nNextEntry
!= rValues
.getLength(), "xmloff",
156 "length incorrectly precomputed!" );
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */