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