1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLLineNumberingExport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLLineNumberingExport.hxx"
34 #include "com/sun/star/beans/XPropertySet.hpp"
35 #include "com/sun/star/text/XLineNumberingProperties.hpp"
36 #include <com/sun/star/style/LineNumberPosition.hpp>
37 #include <xmloff/xmlexp.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include "xmlnmspe.hxx"
40 #include <xmloff/xmltoken.hxx>
41 #include <xmloff/xmlnume.hxx>
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star
;
46 using namespace ::xmloff::token
;
48 using ::rtl::OUString
;
49 using ::rtl::OUStringBuffer
;
50 using ::com::sun::star::beans::XPropertySet
;
51 using ::com::sun::star::text::XLineNumberingProperties
;
54 XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport
& rExp
)
55 : sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
56 , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
57 , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
58 , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
59 , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
60 , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
61 , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
62 , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
63 , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
64 , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
65 , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
70 SvXMLEnumMapEntry __READONLY_DATA aLineNumberPositionMap
[] =
72 { XML_LEFT
, style::LineNumberPosition::LEFT
},
73 { XML_RIGHT
, style::LineNumberPosition::RIGHT
},
74 { XML_INSIDE
, style::LineNumberPosition::INSIDE
},
75 { XML_OUTSIDE
, style::LineNumberPosition::OUTSIDE
},
76 { XML_TOKEN_INVALID
, 0 }
81 void XMLLineNumberingExport::Export()
83 // export element if we have line numbering info
84 Reference
<XLineNumberingProperties
> xSupplier(rExport
.GetModel(),
88 Reference
<XPropertySet
> xLineNumbering
=
89 xSupplier
->getLineNumberingProperties();
91 if (xLineNumbering
.is())
96 aAny
= xLineNumbering
->getPropertyValue(sCharStyleName
);
99 if (sTmp
.getLength() > 0)
101 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
102 rExport
.EncodeStyleName( sTmp
));
106 aAny
= xLineNumbering
->getPropertyValue(sIsOn
);
107 if (! *(sal_Bool
*)aAny
.getValue())
109 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
110 XML_NUMBER_LINES
, XML_FALSE
);
114 aAny
= xLineNumbering
->getPropertyValue(sCountEmptyLines
);
115 if (! *(sal_Bool
*)aAny
.getValue())
117 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
118 XML_COUNT_EMPTY_LINES
, XML_FALSE
);
122 aAny
= xLineNumbering
->getPropertyValue(sCountLinesInFrames
);
123 if (*(sal_Bool
*)aAny
.getValue())
125 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
126 XML_COUNT_IN_TEXT_BOXES
, XML_TRUE
);
130 aAny
= xLineNumbering
->getPropertyValue(sRestartAtEachPage
);
131 if (*(sal_Bool
*)aAny
.getValue())
133 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
134 XML_RESTART_ON_PAGE
, XML_TRUE
);
138 aAny
= xLineNumbering
->getPropertyValue(sDistance
);
139 sal_Int32 nLength
= 0;
144 rExport
.GetMM100UnitConverter().convertMeasure(sBuf
, nLength
);
145 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_OFFSET
,
146 sBuf
.makeStringAndClear());
150 OUStringBuffer sNumPosBuf
;
151 aAny
= xLineNumbering
->getPropertyValue(sNumberingType
);
152 sal_Int16 nFormat
= 0;
154 rExport
.GetMM100UnitConverter().convertNumFormat( sNumPosBuf
, nFormat
);
155 rExport
.AddAttribute(XML_NAMESPACE_STYLE
, XML_NUM_FORMAT
,
156 sNumPosBuf
.makeStringAndClear());
157 rExport
.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf
, nFormat
);
158 if( sNumPosBuf
.getLength() )
160 rExport
.AddAttribute(XML_NAMESPACE_STYLE
,
162 sNumPosBuf
.makeStringAndClear() );
166 aAny
= xLineNumbering
->getPropertyValue(sNumberPosition
);
167 sal_Int16 nPosition
= 0;
169 if (SvXMLUnitConverter::convertEnum(sNumPosBuf
, nPosition
,
170 aLineNumberPositionMap
))
172 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_NUMBER_POSITION
,
173 sNumPosBuf
.makeStringAndClear());
177 aAny
= xLineNumbering
->getPropertyValue(sInterval
);
178 sal_Int16 nLineInterval
= 0;
179 aAny
>>= nLineInterval
;
181 SvXMLUnitConverter::convertNumber(sBuf
,
182 (sal_Int32
)nLineInterval
);
183 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_INCREMENT
,
184 sBuf
.makeStringAndClear());
186 SvXMLElementExport
aConfigElem(rExport
, XML_NAMESPACE_TEXT
,
187 XML_LINENUMBERING_CONFIGURATION
,
191 aAny
= xLineNumbering
->getPropertyValue(sSeparatorText
);
194 if (sSeparator
.getLength() > 0)
198 aAny
= xLineNumbering
->getPropertyValue(sSeparatorInterval
);
199 sal_Int16 nLineDistance
= 0;
200 aAny
>>= nLineDistance
;
201 SvXMLUnitConverter::convertNumber(sBuf
,
202 (sal_Int32
)nLineDistance
);
203 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_INCREMENT
,
204 sBuf
.makeStringAndClear());
206 SvXMLElementExport
aSeparatorElem(rExport
, XML_NAMESPACE_TEXT
,
207 XML_LINENUMBERING_SEPARATOR
,
208 sal_True
, sal_False
);
209 rExport
.Characters(sSeparator
);
212 // else: no configuration: don't save -> default
214 // can't even get supplier: don't save -> default