LibreOffice Module lotuswordpro (master) 1
xfindex.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/*************************************************************************
57 * @file
58 * Represents index source, index body and index entry.
59 ************************************************************************/
61#include <xfilter/xfindex.hxx>
62
65 , m_bProtect(true)
66 , m_bSeparator(false)
67{}
68
70{
71}
72
73void XFIndex::AddTemplate(const OUString& level, const OUString& style, XFIndexTemplate* templ)
74{
75 templ->SetLevel( level );
76 if(m_eType != enumXFIndexTOC) // TOC's styles are applied to template entries separately
77 {
78 templ->SetStyleName( style );
79 }
80 m_aTemplates.push_back( templ );
81}
82
83void XFIndex::SetProtected(bool protect)
84{
85 m_bProtect = protect;
86}
87
89{
90 m_bSeparator = sep;
91}
92
93void XFIndex::AddTocSource(sal_uInt16 nLevel, const OUString& sStyleName)
94{
95 if (nLevel > MAX_TOC_LEVEL)
96 {
97 return;
98 }
99
100 m_aTOCSource[nLevel].push_back(sStyleName);
101}
102
104{
105 IXFAttrList *pAttrList = pStrm->GetAttrList();
106 pAttrList->Clear();
107 OUString strIndexName;
108 OUString strTplName;
109 OUString strSourceName;
110
111 if(m_eType == enumXFIndexTOC )
112 {
113 strIndexName = "text:table-of-content";
114 strSourceName = "text:table-of-content-source";
115 strTplName = "text:table-of-content-entry-template";
116 }
117 else if( m_eType == enumXFIndexAlphabetical )
118 {
119 strIndexName = "text:alphabetical-index";
120 strSourceName = "text:alphabetical-index-source";
121 strTplName = "text:alphabetical-index-entry-template";
122 }
123 else if( m_eType == enumXFIndexUserIndex )
124 {
125 strIndexName = "text:user-index";
126 strSourceName = "text:text:user-index-source";
127 strTplName = "text:user-index-entry-template";
128 }
129 else if( m_eType == enumXFIndexObject )
130 {
131 strIndexName = "text:object-index";
132 strSourceName = "text:object-index-source";
133 strTplName = "text:object-index-entry-template";
134 }
135 else if( m_eType == enumXFIndexIllustration )
136 {
137 strIndexName = "text:illustration-index";
138 strSourceName = "text:illustration-index-source";
139 strTplName = "text:illustration-index-entry-template";
140 }
141 else if( m_eType == enumXFIndexTableIndex )
142 {
143 strIndexName = "text:table-index";
144 strSourceName = "text:table-index-source";
145 strTplName = "text:table-index-entry-template";
146 }
147
148 if( !GetStyleName().isEmpty() )
149 pAttrList->AddAttribute( "text:style-name", GetStyleName() );
150 if( m_bProtect )
151 pAttrList->AddAttribute( "text:protected", "true" );
152 else
153 pAttrList->AddAttribute( "text:protected", "false" );
154
155 pAttrList->AddAttribute( "text:name", m_strTitle );
156 pStrm->StartElement( strIndexName );
157
158 //text:table-of-content-source:
159 pAttrList->Clear();
160
161 if(m_eType == enumXFIndexTOC )
162 {
163 pAttrList->AddAttribute( "text:outline-level", OUString::number(10));
164 pAttrList->AddAttribute( "text:use-index-source-styles", "true");
165 pAttrList->AddAttribute( "text:use-index-marks", "true");
166 pAttrList->AddAttribute( "text:use-outline-level", "false");
167 }
168 if (m_bSeparator)
169 pAttrList->AddAttribute( "text:alphabetical-separators", "true" );
170
171 pStrm->StartElement( strSourceName );
172 //title template:
173 pAttrList->Clear();
174
175 pStrm->StartElement( "text:index-title-template" );
176 pStrm->Characters( m_strTitle );
177 pStrm->EndElement( "text:index-title-template" );
178
179 //entry templates:
180 for (auto const& elem : m_aTemplates)
181 {
182 elem->SetTagName( strTplName);
183 elem->ToXml(pStrm);
184 }
185
186 // by
187 if(m_eType == enumXFIndexTOC )
188 {
189 for(sal_uInt16 i=1; i <= MAX_TOC_LEVEL; i++)
190 {
191 if (m_aTOCSource[i].empty())
192 {
193 // unnecessary to output this level
194 continue;
195 }
196
197 pAttrList->Clear();
198 pAttrList->AddAttribute( "text:outline-level", OUString::number(i));
199 pStrm->StartElement( "text:index-source-styles" );
200
201 for (auto const& elemTOCSource : m_aTOCSource[i])
202 {
203 pAttrList->Clear();
204 pAttrList->AddAttribute( "text:style-name", elemTOCSource);
205 pStrm->StartElement( "text:index-source-style" );
206 pStrm->EndElement( "text:index-source-style" );
207 }
208 pStrm->EndElement( "text:index-source-styles" );
209 }
210 }
211
212 pStrm->EndElement( strSourceName );
213
214 //index-body:
215 pAttrList->Clear();
216 pStrm->StartElement( "text:index-body" );
217 //index-title:
218 if(!m_strTitle.isEmpty())
219 {
220 pAttrList->AddAttribute( "text:name", m_strTitle + "_Head" );
221 pStrm->StartElement( "text:index-title" );
222 pStrm->EndElement( "text:index-title" );
223 }
224
226 pStrm->EndElement( "text:index-body" );
227
228 pStrm->EndElement( strIndexName );
229}
230
232{
233 IXFAttrList *pAttrList = pStrm->GetAttrList();
234 pAttrList->Clear();
235
236 pAttrList->AddAttribute( "text:outline-level", m_nLevel );
237 pAttrList->AddAttribute( "text:style-name", m_strStyle );
238 if( m_strTagName.isEmpty() )
239 m_strTagName = "text:table-of-content-entry-template";
240 pStrm->StartElement( m_strTagName );
241
242 for( size_t i=0; i<m_aEntries.size(); i++ )
243 {
244 pAttrList->Clear();
245
246 switch( m_aEntries[i].first )
247 {
249 if(!m_aEntries[i].second.isEmpty())
250 pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
251
252 pStrm->StartElement( "text:index-entry-chapter-number" );
253 pStrm->EndElement( "text:index-entry-chapter-number" );
254 break;
256 if(!m_aEntries[i].second.isEmpty())
257 pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
258
259 pStrm->StartElement( "text:index-entry-text" );
260 pStrm->EndElement( "text:index-entry-text" );
261 break;
264 pAttrList->AddAttribute( "style:position", OUString::number(m_fTabLength) + "cm" );
265
266 if(!m_aEntries[i].second.isEmpty())
267 pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
268
269 switch(m_eTabType)
270 {
271 case enumXFTabLeft:
272 pAttrList->AddAttribute( "style:type", "left" );
273 break;
274 case enumXFTabCenter:
275 pAttrList->AddAttribute( "style:type", "center" );
276 break;
277 case enumXFTabRight:
278 pAttrList->AddAttribute( "style:type", "right" );
279 break;
280 case enumXFTabChar:
281 pAttrList->AddAttribute( "style:type", "char" );
282 break;
283 default:
284 break;
285 }
286 //delimiter:
288 pAttrList->AddAttribute( "style:char", m_strTabDelimiter );
289 //leader char:
290 if( !m_strTabLeader.isEmpty() )
291 pAttrList->AddAttribute( "style:leader-char", m_strTabLeader );
292
293 pStrm->StartElement( "text:index-entry-tab-stop" );
294 pStrm->EndElement( "text:index-entry-tab-stop" );
295 break;
297 if(!m_aEntries[i].second.isEmpty())
298 pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
299
300 pStrm->StartElement( "text:index-entry-page-number" );
301 pStrm->EndElement( "text:index-entry-page-number" );
302 break;
304 pStrm->StartElement( "text:index-entry-link-start" );
305 pStrm->EndElement( "text:index-entry-link-start" );
306 break;
308 pStrm->StartElement( "text:index-entry-link-end" );
309 pStrm->EndElement( "text:index-entry-link-end" );
310 break;
312 pAttrList->Clear();
313 pAttrList->AddAttribute("text:style-name", GetStyleName());
314 pStrm->StartElement( "text:index-entry-span" );
315 pStrm->Characters(m_aTextEntries[i]);
316 pStrm->EndElement( "text:index-entry-span" );
317 break;
319 pStrm->StartElement( "text:index-entry-bibliography" );
320 pStrm->EndElement( "text:index-entry-bibliography" );
321 break;
322 default:
323 break;
324 }
325 }
326
327 pStrm->EndElement( m_strTagName );
328}
329
330/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual void Characters(const OUString &oustr)=0
@descr output text node.
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
virtual void ToXml(IXFStream *pStrm) override
@descr Output to OOo model or local file.
const OUString & GetStyleName() const
: return the style name.
Definition: xfcontent.hxx:95
Index template.
Definition: xfindex.hxx:79
OUString m_strStyle
Definition: xfindex.hxx:118
OUString m_nLevel
Definition: xfindex.hxx:117
std::map< sal_uInt16, OUString > m_aTextEntries
Definition: xfindex.hxx:126
OUString m_strTabDelimiter
Definition: xfindex.hxx:121
OUString m_strTagName
Definition: xfindex.hxx:123
void SetStyleName(const OUString &style) override
@descr Set style.
Definition: xfindex.hxx:188
std::vector< TOCTEMPLATE_ENTRY_TYPE > m_aEntries
Definition: xfindex.hxx:125
OUString m_strTabLeader
Definition: xfindex.hxx:122
void SetLevel(const OUString &level)
@descr Set template level.
Definition: xfindex.hxx:184
virtual void ToXml(IXFStream *pStrm) override
Definition: xfindex.cxx:231
enumXFTab m_eTabType
Definition: xfindex.hxx:119
double m_fTabLength
Definition: xfindex.hxx:120
OUString m_strTitle
Definition: xfindex.hxx:167
XFIndex()
Definition: xfindex.cxx:63
bool m_bSeparator
Definition: xfindex.hxx:169
void SetProtected(bool protect)
@descr Set if protected index to prevent handy-revise.
Definition: xfindex.cxx:83
bool m_bProtect
Definition: xfindex.hxx:168
enumXFIndex m_eType
Definition: xfindex.hxx:166
void SetSeparator(bool sep)
@descr Set separator.
Definition: xfindex.cxx:88
virtual ~XFIndex() override
Definition: xfindex.cxx:69
void AddTemplate(const OUString &level, const OUString &style, XFIndexTemplate *templ)
@descr Add index template entry.
Definition: xfindex.cxx:73
virtual void ToXml(IXFStream *pStrm) override
@descr Output to OOo model or local file.
Definition: xfindex.cxx:103
void AddTocSource(sal_uInt16 nLevel, const OUString &sStyleName)
Definition: xfindex.cxx:93
std::vector< OUString > m_aTOCSource[MAX_TOC_LEVEL+1]
Definition: xfindex.hxx:174
std::vector< rtl::Reference< XFIndexTemplate > > m_aTemplates
Definition: xfindex.hxx:171
const EnumerationType m_eType
int i
constexpr OUStringLiteral first
@ enumXFIndexObject
Definition: xfdefs.hxx:445
@ enumXFIndexUserIndex
Definition: xfdefs.hxx:444
@ enumXFIndexIllustration
Definition: xfdefs.hxx:446
@ enumXFIndexTableIndex
Definition: xfdefs.hxx:447
@ enumXFIndexTOC
Definition: xfdefs.hxx:442
@ enumXFIndexAlphabetical
Definition: xfdefs.hxx:443
@ enumXFIndexTemplateLinkEnd
Definition: xfdefs.hxx:458
@ enumXFIndexTemplateBibliography
Definition: xfdefs.hxx:460
@ enumXFIndexTemplateSpan
Definition: xfdefs.hxx:459
@ enumXFIndexTemplateTab
Definition: xfdefs.hxx:455
@ enumXFIndexTemplateText
Definition: xfdefs.hxx:454
@ enumXFIndexTemplateLinkStart
Definition: xfdefs.hxx:457
@ enumXFIndexTemplateChapter
Definition: xfdefs.hxx:453
@ enumXFIndexTemplatePage
Definition: xfdefs.hxx:456
@ enumXFTabChar
Definition: xfdefs.hxx:235
@ enumXFTabRight
Definition: xfdefs.hxx:234
@ enumXFTabCenter
Definition: xfdefs.hxx:233
@ enumXFTabLeft
Definition: xfdefs.hxx:232
#define MAX_TOC_LEVEL
Definition: xfindex.hxx:173