Line data Source code
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 : * Represente index source,index body and index index entry.
59 : ************************************************************************/
60 : #include "xfindex.hxx"
61 : #include "xfparagraph.hxx"
62 :
63 0 : XFIndex::XFIndex()
64 : {
65 0 : m_pTitle = NULL;
66 0 : m_eType = enumXFIndexTOC;
67 0 : m_bProtect = sal_True;
68 0 : m_bSeparator = sal_False;
69 0 : m_nMaxLevel = 0;
70 :
71 0 : for(sal_uInt16 i=1;i<MAX_TOC_LEVEL+1;i++)
72 : {
73 0 : m_aTOCSource[i].clear();
74 : }
75 0 : }
76 :
77 0 : XFIndex::~XFIndex()
78 : {
79 0 : if( m_pTitle )
80 0 : delete m_pTitle;
81 :
82 0 : for(sal_uInt16 i=1;i<MAX_TOC_LEVEL+1;i++)
83 : {
84 0 : m_aTOCSource[i].clear();
85 : }
86 :
87 0 : while(m_aTemplates.size()>0)
88 : {
89 0 : XFIndexTemplate * pTemplate = m_aTemplates.back();
90 0 : m_aTemplates.pop_back();
91 0 : delete pTemplate;pTemplate=NULL;
92 : }
93 0 : }
94 :
95 0 : void XFIndex::AddTemplate(rtl::OUString level, rtl::OUString style, XFIndexTemplate* templ)
96 : {
97 0 : templ->SetLevel( level );
98 0 : if(m_eType != enumXFIndexTOC) // TOC's styles are applied to template entries separately
99 : {
100 0 : templ->SetStyleName( style );
101 : }
102 0 : m_aTemplates.push_back( templ );
103 0 : }
104 :
105 0 : void XFIndex::SetProtected(sal_Bool protect)
106 : {
107 0 : m_bProtect = protect;
108 0 : }
109 :
110 0 : void XFIndex::SetSeparator(sal_Bool sep)
111 : {
112 0 : m_bSeparator = sep;
113 0 : }
114 :
115 0 : void XFIndex::AddTocSource(sal_uInt16 nLevel, const rtl::OUString sStyleName)
116 : {
117 0 : if (nLevel > MAX_TOC_LEVEL)
118 : {
119 0 : return;
120 : }
121 :
122 0 : m_aTOCSource[nLevel].push_back(sStyleName);
123 : }
124 :
125 0 : void XFIndex::ToXml(IXFStream *pStrm)
126 : {
127 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
128 0 : pAttrList->Clear();
129 0 : rtl::OUString strIndexName;
130 0 : rtl::OUString strTplName;
131 0 : rtl::OUString strSourceName;
132 :
133 0 : if(m_eType == enumXFIndexTOC )
134 : {
135 0 : strIndexName = A2OUSTR("text:table-of-content");
136 0 : strSourceName = A2OUSTR("text:table-of-content-source");
137 0 : strTplName = A2OUSTR("text:table-of-content-entry-template");
138 : }
139 0 : else if( m_eType == enumXFIndexAlphabetical )
140 : {
141 0 : strIndexName = A2OUSTR("text:alphabetical-index");
142 0 : strSourceName = A2OUSTR("text:alphabetical-index-source");
143 0 : strTplName = A2OUSTR("text:alphabetical-index-entry-template");
144 : }
145 0 : else if( m_eType == enumXFIndexUserIndex )
146 : {
147 0 : strIndexName = A2OUSTR("text:user-index");
148 0 : strSourceName = A2OUSTR("text:text:user-index-source");
149 0 : strTplName = A2OUSTR("text:user-index-entry-template");
150 : }
151 0 : else if( m_eType == enumXFIndexObject )
152 : {
153 0 : strIndexName = A2OUSTR("text:object-index");
154 0 : strSourceName = A2OUSTR("text:object-index-source");
155 0 : strTplName = A2OUSTR("text:object-index-entry-template");
156 : }
157 0 : else if( m_eType == enumXFIndexIllustration )
158 : {
159 0 : strIndexName = A2OUSTR("text:illustration-index");
160 0 : strSourceName = A2OUSTR("text:illustration-index-source");
161 0 : strTplName = A2OUSTR("text:illustration-index-entry-template");
162 : }
163 0 : else if( m_eType == enumXFIndexTableIndex )
164 : {
165 0 : strIndexName = A2OUSTR("text:table-index");
166 0 : strSourceName = A2OUSTR("text:table-index-source");
167 0 : strTplName = A2OUSTR("text:table-index-entry-template");
168 : }
169 :
170 0 : if( !GetStyleName().isEmpty() )
171 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), GetStyleName() );
172 0 : if( m_bProtect )
173 0 : pAttrList->AddAttribute( A2OUSTR("text:protected"), A2OUSTR("true") );
174 : else
175 0 : pAttrList->AddAttribute( A2OUSTR("text:protected"), A2OUSTR("false") );
176 :
177 0 : pAttrList->AddAttribute( A2OUSTR("text:name"), m_strTitle );
178 0 : pStrm->StartElement( strIndexName );
179 :
180 : //text:table-of-content-source:
181 0 : pAttrList->Clear();
182 :
183 0 : if(m_eType == enumXFIndexTOC )
184 : {
185 0 : pAttrList->AddAttribute( A2OUSTR("text:outline-level"), Int32ToOUString(10));
186 0 : pAttrList->AddAttribute( A2OUSTR("text:use-index-source-styles"), A2OUSTR("true"));
187 0 : pAttrList->AddAttribute( A2OUSTR("text:use-index-marks"), A2OUSTR("true"));
188 0 : pAttrList->AddAttribute( A2OUSTR("text:use-outline-level"), A2OUSTR("false"));
189 : }
190 0 : if (m_bSeparator)
191 0 : pAttrList->AddAttribute( A2OUSTR("text:alphabetical-separators"), A2OUSTR("true") );
192 :
193 0 : pStrm->StartElement( strSourceName );
194 : //title template:
195 0 : pAttrList->Clear();
196 :
197 0 : pStrm->StartElement( A2OUSTR("text:index-title-template") );
198 0 : pStrm->Characters( m_strTitle );
199 0 : pStrm->EndElement( A2OUSTR("text:index-title-template") );
200 :
201 : //entry templates:
202 0 : std::vector<XFIndexTemplate *>::iterator it;
203 0 : for (it = m_aTemplates.begin(); it != m_aTemplates.end(); ++it)
204 : {
205 0 : (*it)->SetTagName( strTplName);
206 0 : (*it)->ToXml(pStrm);
207 : }
208 :
209 : // by
210 0 : if(m_eType == enumXFIndexTOC )
211 : {
212 0 : for(sal_uInt16 i=1; i <= MAX_TOC_LEVEL; i++)
213 : {
214 0 : if (m_aTOCSource[i].empty())
215 : {
216 : // unnecessary to output this level
217 0 : continue;
218 : }
219 :
220 0 : pAttrList->Clear();
221 0 : pAttrList->AddAttribute( A2OUSTR("text:outline-level"), Int32ToOUString(i));
222 0 : pStrm->StartElement( A2OUSTR("text:index-source-styles") );
223 :
224 0 : std::vector<rtl::OUString>::iterator it_str;
225 0 : for (it_str = m_aTOCSource[i].begin(); it_str != m_aTOCSource[i].end(); ++it)
226 : {
227 0 : pAttrList->Clear();
228 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), *it_str);
229 0 : pStrm->StartElement( A2OUSTR("text:index-source-style") );
230 0 : pStrm->EndElement( A2OUSTR("text:index-source-style") );
231 : }
232 0 : pStrm->EndElement( A2OUSTR("text:index-source-styles") );
233 : }
234 : }
235 :
236 0 : pStrm->EndElement( strSourceName );
237 :
238 : //index-body:
239 0 : pAttrList->Clear();
240 0 : pStrm->StartElement( A2OUSTR("text:index-body") );
241 : //index-title:
242 0 : if(!m_strTitle.isEmpty())
243 : {
244 0 : pAttrList->AddAttribute( A2OUSTR("text:name"), m_strTitle + A2OUSTR("_Head") );
245 0 : pStrm->StartElement( A2OUSTR("text:index-title") );
246 0 : if( m_pTitle )
247 0 : m_pTitle->ToXml(pStrm);
248 0 : pStrm->EndElement( A2OUSTR("text:index-title") );
249 : }
250 :
251 0 : XFContentContainer::ToXml(pStrm);
252 0 : pStrm->EndElement( A2OUSTR("text:index-body") );
253 :
254 0 : pStrm->EndElement( strIndexName );
255 0 : }
256 :
257 :
258 0 : void XFIndexTemplate::ToXml(IXFStream *pStrm)
259 : {
260 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
261 0 : pAttrList->Clear();
262 :
263 0 : pAttrList->AddAttribute( A2OUSTR("text:outline-level"), m_nLevel );
264 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), m_strStyle );
265 0 : if( m_strTagName.isEmpty() )
266 0 : m_strTagName = A2OUSTR("text:table-of-content-entry-template");
267 0 : pStrm->StartElement( m_strTagName );
268 :
269 0 : for( size_t i=0; i<m_aEntries.size(); i++ )
270 : {
271 0 : pAttrList->Clear();
272 :
273 0 : switch( m_aEntries[i].first )
274 : {
275 : case enumXFIndexTemplateChapter:
276 0 : if(!m_aEntries[i].second.isEmpty())
277 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), m_aEntries[i].second );
278 :
279 0 : pStrm->StartElement( A2OUSTR("text:index-entry-chapter-number") );
280 0 : pStrm->EndElement( A2OUSTR("text:index-entry-chapter-number") );
281 0 : break;
282 : case enumXFIndexTemplateText:
283 0 : if(!m_aEntries[i].second.isEmpty())
284 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), m_aEntries[i].second );
285 :
286 0 : pStrm->StartElement( A2OUSTR("text:index-entry-text") );
287 0 : pStrm->EndElement( A2OUSTR("text:index-entry-text") );
288 0 : break;
289 : case enumXFIndexTemplateTab:
290 0 : if( m_eTabType != enumXFTabRight )
291 0 : pAttrList->AddAttribute( A2OUSTR("style:position"), DoubleToOUString(m_fTabLength) + A2OUSTR("cm") );
292 :
293 0 : if(!m_aEntries[i].second.isEmpty())
294 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), m_aEntries[i].second );
295 :
296 0 : switch(m_eTabType)
297 : {
298 : case enumXFTabLeft:
299 0 : pAttrList->AddAttribute( A2OUSTR("style:type"), A2OUSTR("left") );
300 0 : break;
301 : case enumXFTabCenter:
302 0 : pAttrList->AddAttribute( A2OUSTR("style:type"), A2OUSTR("center") );
303 0 : break;
304 : case enumXFTabRight:
305 0 : pAttrList->AddAttribute( A2OUSTR("style:type"), A2OUSTR("right") );
306 0 : break;
307 : case enumXFTabChar:
308 0 : pAttrList->AddAttribute( A2OUSTR("style:type"), A2OUSTR("char") );
309 0 : break;
310 : default:
311 0 : break;
312 : }
313 : //delimiter:
314 0 : if( m_eTabType == enumXFTabChar )
315 0 : pAttrList->AddAttribute( A2OUSTR("style:char"), m_strTabDelimiter );
316 : //leader char:
317 0 : if( !m_strTabLeader.isEmpty() )
318 0 : pAttrList->AddAttribute( A2OUSTR("style:leader-char"), m_strTabLeader );
319 :
320 0 : pStrm->StartElement( A2OUSTR("text:index-entry-tab-stop") );
321 0 : pStrm->EndElement( A2OUSTR("text:index-entry-tab-stop") );
322 0 : break;
323 : case enumXFIndexTemplatePage:
324 0 : if(!m_aEntries[i].second.isEmpty())
325 0 : pAttrList->AddAttribute( A2OUSTR("text:style-name"), m_aEntries[i].second );
326 :
327 0 : pStrm->StartElement( A2OUSTR("text:index-entry-page-number") );
328 0 : pStrm->EndElement( A2OUSTR("text:index-entry-page-number") );
329 0 : break;
330 : case enumXFIndexTemplateLinkStart:
331 0 : pStrm->StartElement( A2OUSTR("text:index-entry-link-start") );
332 0 : pStrm->EndElement( A2OUSTR("text:index-entry-link-start") );
333 0 : break;
334 : case enumXFIndexTemplateLinkEnd:
335 0 : pStrm->StartElement( A2OUSTR("text:index-entry-link-end") );
336 0 : pStrm->EndElement( A2OUSTR("text:index-entry-link-end") );
337 0 : break;
338 : case enumXFIndexTemplateSpan:
339 0 : pAttrList->Clear();
340 0 : pAttrList->AddAttribute(A2OUSTR("text:style-name"), GetStyleName());
341 0 : pStrm->StartElement( A2OUSTR("text:index-entry-span") );
342 0 : pStrm->Characters(m_aTextEntries[i]);
343 0 : pStrm->EndElement( A2OUSTR("text:index-entry-span") );
344 0 : break;
345 : case enumXFIndexTemplateBibliography:
346 0 : pStrm->StartElement( A2OUSTR("text:index-entry-bibliography") );
347 0 : pStrm->EndElement( A2OUSTR("text:index-entry-bibliography") );
348 0 : break;
349 : default:
350 0 : break;
351 : }
352 : }
353 :
354 0 : pStrm->EndElement( m_strTagName );
355 0 : }
356 :
357 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|