xref: /trunk/main/xmloff/source/text/XMLIndexTabStopEntryContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 
32 #include "XMLIndexTabStopEntryContext.hxx"
33 #include "XMLIndexTemplateContext.hxx"
34 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/xmlimp.hxx>
36 #include <xmloff/txtimp.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include "xmloff/xmlnmspe.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <rtl/ustring.hxx>
42 #include <tools/debug.hxx>
43 
44 using namespace ::xmloff::token;
45 
46 using ::rtl::OUString;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Any;
50 using ::com::sun::star::beans::PropertyValue;
51 using ::com::sun::star::xml::sax::XAttributeList;
52 
53 
54 TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
55 
56 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
57     SvXMLImport& rImport,
58     XMLIndexTemplateContext& rTemplate,
59     sal_uInt16 nPrfx,
60     const OUString& rLocalName ) :
61         XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
62                                    rTemplate, nPrfx, rLocalName),
63         sLeaderChar(),
64         nTabPosition(0),
65         bTabPositionOK(sal_False),
66         bTabRightAligned(sal_False),
67         bLeaderCharOK(sal_False),
68         bWithTab(sal_True) // #i21237#
69 {
70 }
71 
72 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
73 {
74 }
75 
76 void XMLIndexTabStopEntryContext::StartElement(
77     const Reference<XAttributeList> & xAttrList)
78 {
79     // process three attributes: type, position, leader char
80     sal_Int16 nLength = xAttrList->getLength();
81     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
82     {
83         OUString sLocalName;
84         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
85             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
86                               &sLocalName );
87         OUString sAttr = xAttrList->getValueByIndex(nAttr);
88         if (XML_NAMESPACE_STYLE == nPrefix)
89         {
90             if ( IsXMLToken( sLocalName, XML_TYPE ) )
91             {
92                 // if it's neither left nor right, value is
93                 // ignored. Since left is default, we only need to
94                 // check for right
95                 bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
96             }
97             else if ( IsXMLToken( sLocalName, XML_POSITION ) )
98             {
99                 sal_Int32 nTmp;
100                 if (GetImport().GetMM100UnitConverter().
101                                         convertMeasure(nTmp, sAttr))
102                 {
103                     nTabPosition = nTmp;
104                     bTabPositionOK = sal_True;
105                 }
106             }
107             else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
108             {
109                 sLeaderChar = sAttr;
110                 // valid only, if we have a char!
111                 bLeaderCharOK = (sAttr.getLength() > 0);
112             }
113             // #i21237#
114             else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
115             {
116                 sal_Bool bTmp;
117                 if (SvXMLUnitConverter::convertBool(bTmp, sAttr))
118                     bWithTab = bTmp;
119             }
120             // else: unknown style: attribute -> ignore
121         }
122         // else: no style attribute -> ignore
123     }
124 
125     // how many entries? #i21237#
126     nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
127 
128     // now try parent class (for character style)
129     XMLIndexSimpleEntryContext::StartElement( xAttrList );
130 }
131 
132 void XMLIndexTabStopEntryContext::FillPropertyValues(
133     Sequence<PropertyValue> & rValues)
134 {
135     // fill vlues from parent class (type + style name)
136     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
137 
138     // get values array and next entry to be written;
139     sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
140     PropertyValue* pValues = rValues.getArray();
141 
142     // right aligned?
143     pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
144     pValues[nNextEntry].Value.setValue( &bTabRightAligned,
145                                         ::getBooleanCppuType());
146     nNextEntry++;
147 
148     // position
149     if (bTabPositionOK)
150     {
151         pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
152         pValues[nNextEntry].Value <<= nTabPosition;
153         nNextEntry++;
154     }
155 
156     // leader char
157     if (bLeaderCharOK)
158     {
159         pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
160         pValues[nNextEntry].Value <<= sLeaderChar;
161         nNextEntry++;
162     }
163 
164     // tab character #i21237#
165     pValues[nNextEntry].Name =
166         OUString( RTL_CONSTASCII_USTRINGPARAM("WithTab") );
167     pValues[nNextEntry].Value.setValue( &bWithTab,
168                                         ::getBooleanCppuType());
169     nNextEntry++;
170 
171     // check whether we really filled all elements of the sequence
172     DBG_ASSERT( nNextEntry == rValues.getLength(),
173                 "length incorrectly precumputed!" );
174 }
175