1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 
28 #include "XMLIndexTabStopEntryContext.hxx"
29 #include "XMLIndexTemplateContext.hxx"
30 #include <xmloff/xmlictxt.hxx>
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/txtimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <rtl/ustring.hxx>
38 #include <tools/debug.hxx>
39 
40 using namespace ::xmloff::token;
41 
42 using ::rtl::OUString;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Any;
46 using ::com::sun::star::beans::PropertyValue;
47 using ::com::sun::star::xml::sax::XAttributeList;
48 
49 
50 TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
51 
XMLIndexTabStopEntryContext(SvXMLImport & rImport,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName)52 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
53 	SvXMLImport& rImport,
54 	XMLIndexTemplateContext& rTemplate,
55 	sal_uInt16 nPrfx,
56 	const OUString& rLocalName ) :
57 		XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
58                                    rTemplate, nPrfx, rLocalName),
59 		sLeaderChar(),
60 		nTabPosition(0),
61 		bTabPositionOK(sal_False),
62 		bTabRightAligned(sal_False),
63 		bLeaderCharOK(sal_False),
64         bWithTab(sal_True) // #i21237#
65 {
66 }
67 
~XMLIndexTabStopEntryContext()68 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
69 {
70 }
71 
StartElement(const Reference<XAttributeList> & xAttrList)72 void XMLIndexTabStopEntryContext::StartElement(
73 	const Reference<XAttributeList> & xAttrList)
74 {
75 	// process three attributes: type, position, leader char
76 	sal_Int16 nLength = xAttrList->getLength();
77 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
78 	{
79 		OUString sLocalName;
80 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
81 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
82 							  &sLocalName );
83 		OUString sAttr = xAttrList->getValueByIndex(nAttr);
84 		if (XML_NAMESPACE_STYLE == nPrefix)
85 		{
86 			if ( IsXMLToken( sLocalName, XML_TYPE ) )
87 			{
88 				// if it's neither left nor right, value is
89 				// ignored. Since left is default, we only need to
90 				// check for right
91 				bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
92 			}
93 			else if ( IsXMLToken( sLocalName, XML_POSITION ) )
94 			{
95 				sal_Int32 nTmp;
96 				if (GetImport().GetMM100UnitConverter().
97 										convertMeasure(nTmp, sAttr))
98 				{
99 					nTabPosition = nTmp;
100 					bTabPositionOK = sal_True;
101 				}
102 			}
103 			else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
104 			{
105 				sLeaderChar = sAttr;
106 				// valid only, if we have a char!
107 				bLeaderCharOK = (sAttr.getLength() > 0);
108 			}
109             // #i21237#
110             else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
111             {
112                 sal_Bool bTmp;
113                 if (SvXMLUnitConverter::convertBool(bTmp, sAttr))
114                     bWithTab = bTmp;
115             }
116 			// else: unknown style: attribute -> ignore
117 		}
118 		// else: no style attribute -> ignore
119 	}
120 
121 	// how many entries? #i21237#
122     nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
123 
124     // now try parent class (for character style)
125     XMLIndexSimpleEntryContext::StartElement( xAttrList );
126 }
127 
FillPropertyValues(Sequence<PropertyValue> & rValues)128 void XMLIndexTabStopEntryContext::FillPropertyValues(
129     Sequence<PropertyValue> & rValues)
130 {
131     // fill vlues from parent class (type + style name)
132     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
133 
134     // get values array and next entry to be written;
135 	sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
136     PropertyValue* pValues = rValues.getArray();
137 
138 	// right aligned?
139 	pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
140 	pValues[nNextEntry].Value.setValue( &bTabRightAligned,
141                                         ::getBooleanCppuType());
142 	nNextEntry++;
143 
144 	// position
145 	if (bTabPositionOK)
146 	{
147 		pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
148 		pValues[nNextEntry].Value <<= nTabPosition;
149 		nNextEntry++;
150 	}
151 
152 	// leader char
153 	if (bLeaderCharOK)
154 	{
155 		pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
156 		pValues[nNextEntry].Value <<= sLeaderChar;
157 		nNextEntry++;
158 	}
159 
160     // tab character #i21237#
161  	pValues[nNextEntry].Name =
162         OUString( RTL_CONSTASCII_USTRINGPARAM("WithTab") );
163 	pValues[nNextEntry].Value.setValue( &bWithTab,
164                                         ::getBooleanCppuType());
165 	nNextEntry++;
166 
167     // check whether we really filled all elements of the sequence
168     DBG_ASSERT( nNextEntry == rValues.getLength(),
169                 "length incorrectly precumputed!" );
170 }
171