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 "XMLIndexTabStopEntryContext.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 #include <rtl/ustring.hxx>
38cdf0e10cSrcweir #include <tools/debug.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::xmloff::token;
41cdf0e10cSrcweir
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::uno::Any;
46cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
47cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
48cdf0e10cSrcweir
49cdf0e10cSrcweir
50cdf0e10cSrcweir TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
51cdf0e10cSrcweir
XMLIndexTabStopEntryContext(SvXMLImport & rImport,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName)52cdf0e10cSrcweir XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
53cdf0e10cSrcweir SvXMLImport& rImport,
54cdf0e10cSrcweir XMLIndexTemplateContext& rTemplate,
55cdf0e10cSrcweir sal_uInt16 nPrfx,
56cdf0e10cSrcweir const OUString& rLocalName ) :
57cdf0e10cSrcweir XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
58cdf0e10cSrcweir rTemplate, nPrfx, rLocalName),
59cdf0e10cSrcweir sLeaderChar(),
60cdf0e10cSrcweir nTabPosition(0),
61cdf0e10cSrcweir bTabPositionOK(sal_False),
62cdf0e10cSrcweir bTabRightAligned(sal_False),
63cdf0e10cSrcweir bLeaderCharOK(sal_False),
64cdf0e10cSrcweir bWithTab(sal_True) // #i21237#
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
~XMLIndexTabStopEntryContext()68cdf0e10cSrcweir XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
StartElement(const Reference<XAttributeList> & xAttrList)72cdf0e10cSrcweir void XMLIndexTabStopEntryContext::StartElement(
73cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir // process three attributes: type, position, leader char
76cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength();
77cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir OUString sLocalName;
80cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
81cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
82cdf0e10cSrcweir &sLocalName );
83cdf0e10cSrcweir OUString sAttr = xAttrList->getValueByIndex(nAttr);
84cdf0e10cSrcweir if (XML_NAMESPACE_STYLE == nPrefix)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir if ( IsXMLToken( sLocalName, XML_TYPE ) )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // if it's neither left nor right, value is
89cdf0e10cSrcweir // ignored. Since left is default, we only need to
90cdf0e10cSrcweir // check for right
91cdf0e10cSrcweir bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_POSITION ) )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir sal_Int32 nTmp;
96cdf0e10cSrcweir if (GetImport().GetMM100UnitConverter().
97cdf0e10cSrcweir convertMeasure(nTmp, sAttr))
98cdf0e10cSrcweir {
99cdf0e10cSrcweir nTabPosition = nTmp;
100cdf0e10cSrcweir bTabPositionOK = sal_True;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir sLeaderChar = sAttr;
106cdf0e10cSrcweir // valid only, if we have a char!
107cdf0e10cSrcweir bLeaderCharOK = (sAttr.getLength() > 0);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir // #i21237#
110cdf0e10cSrcweir else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir sal_Bool bTmp;
113cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, sAttr))
114cdf0e10cSrcweir bWithTab = bTmp;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir // else: unknown style: attribute -> ignore
117cdf0e10cSrcweir }
118cdf0e10cSrcweir // else: no style attribute -> ignore
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir // how many entries? #i21237#
122cdf0e10cSrcweir nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
123cdf0e10cSrcweir
124cdf0e10cSrcweir // now try parent class (for character style)
125cdf0e10cSrcweir XMLIndexSimpleEntryContext::StartElement( xAttrList );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
FillPropertyValues(Sequence<PropertyValue> & rValues)128cdf0e10cSrcweir void XMLIndexTabStopEntryContext::FillPropertyValues(
129cdf0e10cSrcweir Sequence<PropertyValue> & rValues)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir // fill vlues from parent class (type + style name)
132cdf0e10cSrcweir XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
133cdf0e10cSrcweir
134cdf0e10cSrcweir // get values array and next entry to be written;
135cdf0e10cSrcweir sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
136cdf0e10cSrcweir PropertyValue* pValues = rValues.getArray();
137cdf0e10cSrcweir
138cdf0e10cSrcweir // right aligned?
139cdf0e10cSrcweir pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
140cdf0e10cSrcweir pValues[nNextEntry].Value.setValue( &bTabRightAligned,
141cdf0e10cSrcweir ::getBooleanCppuType());
142cdf0e10cSrcweir nNextEntry++;
143cdf0e10cSrcweir
144cdf0e10cSrcweir // position
145cdf0e10cSrcweir if (bTabPositionOK)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
148cdf0e10cSrcweir pValues[nNextEntry].Value <<= nTabPosition;
149cdf0e10cSrcweir nNextEntry++;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir // leader char
153cdf0e10cSrcweir if (bLeaderCharOK)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
156cdf0e10cSrcweir pValues[nNextEntry].Value <<= sLeaderChar;
157cdf0e10cSrcweir nNextEntry++;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir // tab character #i21237#
161cdf0e10cSrcweir pValues[nNextEntry].Name =
162cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("WithTab") );
163cdf0e10cSrcweir pValues[nNextEntry].Value.setValue( &bWithTab,
164cdf0e10cSrcweir ::getBooleanCppuType());
165cdf0e10cSrcweir nNextEntry++;
166cdf0e10cSrcweir
167cdf0e10cSrcweir // check whether we really filled all elements of the sequence
168cdf0e10cSrcweir DBG_ASSERT( nNextEntry == rValues.getLength(),
169cdf0e10cSrcweir "length incorrectly precumputed!" );
170cdf0e10cSrcweir }
171