Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLIndexTOCStylesContext.hxx"
30 : : #include <com/sun/star/beans/XPropertySet.hpp>
31 : : #include <com/sun/star/container/XIndexReplace.hpp>
32 : : #include <xmloff/xmlictxt.hxx>
33 : : #include <xmloff/xmlimp.hxx>
34 : : #include <xmloff/txtimp.hxx>
35 : : #include "xmloff/xmlnmspe.hxx"
36 : : #include <xmloff/nmspmap.hxx>
37 : : #include <xmloff/xmltoken.hxx>
38 : : #include <sax/tools/converter.hxx>
39 : : #include <com/sun/star/uno/Sequence.hxx>
40 : : #include <rtl/ustring.hxx>
41 : :
42 : :
43 : : using namespace ::xmloff::token;
44 : :
45 : : using ::rtl::OUString;
46 : : using ::com::sun::star::beans::XPropertySet;
47 : : using ::com::sun::star::uno::Reference;
48 : : using ::com::sun::star::uno::Sequence;
49 : : using ::com::sun::star::uno::Any;
50 : : using ::com::sun::star::container::XIndexReplace;
51 : : using ::com::sun::star::xml::sax::XAttributeList;
52 : :
53 : :
54 : : const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles";
55 : :
56 [ # # ][ # # ]: 0 : TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext );
57 : :
58 : :
59 : 0 : XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
60 : : SvXMLImport& rImport,
61 : : Reference<XPropertySet> & rPropSet,
62 : : sal_uInt16 nPrfx,
63 : : const OUString& rLocalName )
64 : : : SvXMLImportContext(rImport, nPrfx, rLocalName)
65 : : , sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_LevelParagraphStyles))
66 [ # # ][ # # ]: 0 : , rTOCPropertySet(rPropSet)
67 : : {
68 : 0 : }
69 : :
70 : 0 : XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
71 : : {
72 [ # # ]: 0 : }
73 : :
74 : 0 : void XMLIndexTOCStylesContext::StartElement(
75 : : const Reference<XAttributeList> & xAttrList )
76 : : {
77 : : // find text:outline-level attribute
78 : 0 : sal_Int16 nCount = xAttrList->getLength();
79 [ # # ]: 0 : for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
80 : : {
81 : 0 : OUString sLocalName;
82 : 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
83 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
84 [ # # # # ]: 0 : &sLocalName );
85 [ # # ][ # # ]: 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
[ # # ]
86 [ # # ]: 0 : (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
87 : : {
88 : : sal_Int32 nTmp;
89 [ # # ][ # # ]: 0 : if (::sax::Converter::convertNumber(
90 [ # # ]: 0 : nTmp, xAttrList->getValueByIndex(nAttr), 1,
91 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->GetChapterNumbering()->
[ # # ]
[ # # # # ]
92 [ # # ][ # # ]: 0 : getCount()))
93 : : {
94 : : // API numbers 0..9, we number 1..10
95 : 0 : nOutlineLevel = nTmp-1;
96 : : }
97 : : }
98 : 0 : }
99 : 0 : }
100 : :
101 : 0 : void XMLIndexTOCStylesContext::EndElement()
102 : : {
103 : : // if valid...
104 [ # # ]: 0 : if (nOutlineLevel >= 0)
105 : : {
106 : : // copy vector into sequence
107 : 0 : const sal_Int32 nCount = aStyleNames.size();
108 [ # # ]: 0 : Sequence<OUString> aStyleNamesSequence(nCount);
109 [ # # ]: 0 : for(sal_Int32 i = 0; i < nCount; i++)
110 : : {
111 [ # # ]: 0 : aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
112 : : XML_STYLE_FAMILY_TEXT_PARAGRAPH,
113 [ # # ]: 0 : aStyleNames[i] );
114 : : }
115 : :
116 : : // get index replace
117 [ # # ][ # # ]: 0 : Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles);
118 : 0 : Reference<XIndexReplace> xIndexReplace;
119 [ # # ]: 0 : aAny >>= xIndexReplace;
120 : :
121 : : // set style names
122 [ # # ]: 0 : aAny <<= aStyleNamesSequence;
123 [ # # ][ # # ]: 0 : xIndexReplace->replaceByIndex(nOutlineLevel, aAny);
[ # # ]
124 : : }
125 : 0 : }
126 : :
127 : 0 : SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext(
128 : : sal_uInt16 p_nPrefix,
129 : : const OUString& rLocalName,
130 : : const Reference<XAttributeList> & xAttrList )
131 : : {
132 : : // check for index-source-style
133 [ # # # # ]: 0 : if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
[ # # ]
134 : 0 : IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
135 : : {
136 : : // find text:style-name attribute and record in aStyleNames
137 : 0 : sal_Int16 nCount = xAttrList->getLength();
138 [ # # ]: 0 : for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
139 : : {
140 : 0 : OUString sLocalName;
141 : 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
142 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
143 [ # # # # ]: 0 : &sLocalName );
144 [ # # ][ # # ]: 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
[ # # ]
145 [ # # ]: 0 : IsXMLToken( sLocalName, XML_STYLE_NAME ) )
146 : : {
147 [ # # ][ # # ]: 0 : aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
[ # # ]
148 : : }
149 : 0 : }
150 : : }
151 : :
152 : : // always return default context; we already got the interesting info
153 : : return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
154 : 0 : xAttrList);
155 : : }
156 : :
157 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|