Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "XMLIndexUserSourceContext.hxx"
21 : #include <com/sun/star/beans/XPropertySet.hpp>
22 : #include <com/sun/star/container/XIndexReplace.hpp>
23 : #include <sax/tools/converter.hxx>
24 : #include "XMLIndexTemplateContext.hxx"
25 : #include "XMLIndexTitleTemplateContext.hxx"
26 : #include "XMLIndexTOCStylesContext.hxx"
27 : #include <xmloff/xmlictxt.hxx>
28 : #include <xmloff/xmlimp.hxx>
29 : #include <xmloff/txtimp.hxx>
30 : #include <xmloff/xmlnmspe.hxx>
31 : #include <xmloff/nmspmap.hxx>
32 : #include <xmloff/xmltoken.hxx>
33 : #include <rtl/ustring.hxx>
34 :
35 :
36 : using ::com::sun::star::beans::XPropertySet;
37 : using ::com::sun::star::uno::Reference;
38 : using ::com::sun::star::uno::Any;
39 : using ::com::sun::star::xml::sax::XAttributeList;
40 : using ::xmloff::token::IsXMLToken;
41 : using ::xmloff::token::XML_USER_INDEX_ENTRY_TEMPLATE;
42 : using ::xmloff::token::XML_OUTLINE_LEVEL;
43 :
44 :
45 : const sal_Char sAPI_CreateFromEmbeddedObjects[] = "CreateFromEmbeddedObjects";
46 : const sal_Char sAPI_CreateFromGraphicObjects[] = "CreateFromGraphicObjects";
47 : const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
48 : const sal_Char sAPI_CreateFromTables[] = "CreateFromTables";
49 : const sal_Char sAPI_CreateFromTextFrames[] = "CreateFromTextFrames";
50 : const sal_Char sAPI_UseLevelFromSource[] = "UseLevelFromSource";
51 : const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
52 : const sal_Char sAPI_UserIndexName[] = "UserIndexName";
53 :
54 :
55 0 : TYPEINIT1(XMLIndexUserSourceContext, XMLIndexSourceBaseContext);
56 :
57 :
58 4 : XMLIndexUserSourceContext::XMLIndexUserSourceContext(
59 : SvXMLImport& rImport,
60 : sal_uInt16 nPrfx,
61 : const OUString& rLocalName,
62 : Reference<XPropertySet> & rPropSet) :
63 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
64 : rPropSet, true),
65 : sCreateFromEmbeddedObjects(sAPI_CreateFromEmbeddedObjects),
66 : sCreateFromGraphicObjects(sAPI_CreateFromGraphicObjects),
67 : sCreateFromMarks(sAPI_CreateFromMarks),
68 : sCreateFromTables(sAPI_CreateFromTables),
69 : sCreateFromTextFrames(sAPI_CreateFromTextFrames),
70 : sUseLevelFromSource(sAPI_UseLevelFromSource),
71 : sCreateFromLevelParagraphStyles(sAPI_CreateFromLevelParagraphStyles),
72 : sUserIndexName(sAPI_UserIndexName),
73 : bUseObjects(false),
74 : bUseGraphic(false),
75 : bUseMarks(false),
76 : bUseTables(false),
77 : bUseFrames(false),
78 : bUseLevelFromSource(false),
79 4 : bUseLevelParagraphStyles(false)
80 : {
81 4 : }
82 :
83 8 : XMLIndexUserSourceContext::~XMLIndexUserSourceContext()
84 : {
85 8 : }
86 :
87 8 : void XMLIndexUserSourceContext::ProcessAttribute(
88 : enum IndexSourceParamEnum eParam,
89 : const OUString& rValue)
90 : {
91 8 : bool bTmp(false);
92 :
93 8 : switch (eParam)
94 : {
95 : case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
96 4 : if (::sax::Converter::convertBool(bTmp, rValue))
97 : {
98 4 : bUseMarks = bTmp;
99 : }
100 4 : break;
101 :
102 : case XML_TOK_INDEXSOURCE_USE_OBJECTS:
103 0 : if (::sax::Converter::convertBool(bTmp, rValue))
104 : {
105 0 : bUseObjects = bTmp;
106 : }
107 0 : break;
108 :
109 : case XML_TOK_INDEXSOURCE_USE_GRAPHICS:
110 0 : if (::sax::Converter::convertBool(bTmp, rValue))
111 : {
112 0 : bUseGraphic = bTmp;
113 : }
114 0 : break;
115 :
116 : case XML_TOK_INDEXSOURCE_USE_TABLES:
117 0 : if (::sax::Converter::convertBool(bTmp, rValue))
118 : {
119 0 : bUseTables = bTmp;
120 : }
121 0 : break;
122 :
123 : case XML_TOK_INDEXSOURCE_USE_FRAMES:
124 0 : if (::sax::Converter::convertBool(bTmp, rValue))
125 : {
126 0 : bUseFrames = bTmp;
127 : }
128 0 : break;
129 :
130 : case XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS:
131 0 : if (::sax::Converter::convertBool(bTmp, rValue))
132 : {
133 0 : bUseLevelFromSource = bTmp;
134 : }
135 0 : break;
136 :
137 : case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
138 0 : if (::sax::Converter::convertBool(bTmp, rValue))
139 : {
140 0 : bUseLevelParagraphStyles = bTmp;
141 : }
142 0 : break;
143 :
144 : case XML_TOK_INDEXSOURCE_USER_INDEX_NAME:
145 4 : sIndexName = rValue;
146 4 : break;
147 :
148 : default:
149 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
150 0 : break;
151 : }
152 8 : }
153 :
154 :
155 4 : void XMLIndexUserSourceContext::EndElement()
156 : {
157 4 : Any aAny;
158 :
159 4 : aAny.setValue(&bUseObjects, ::getBooleanCppuType());
160 4 : rIndexPropertySet->setPropertyValue(sCreateFromEmbeddedObjects, aAny);
161 :
162 4 : aAny.setValue(&bUseGraphic, ::getBooleanCppuType());
163 4 : rIndexPropertySet->setPropertyValue(sCreateFromGraphicObjects, aAny);
164 :
165 4 : aAny.setValue(&bUseLevelFromSource, ::getBooleanCppuType());
166 4 : rIndexPropertySet->setPropertyValue(sUseLevelFromSource, aAny);
167 :
168 4 : aAny.setValue(&bUseMarks, ::getBooleanCppuType());
169 4 : rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
170 :
171 4 : aAny.setValue(&bUseTables, ::getBooleanCppuType());
172 4 : rIndexPropertySet->setPropertyValue(sCreateFromTables, aAny);
173 :
174 4 : aAny.setValue(&bUseFrames, ::getBooleanCppuType());
175 4 : rIndexPropertySet->setPropertyValue(sCreateFromTextFrames, aAny);
176 :
177 4 : aAny.setValue(&bUseLevelParagraphStyles, ::getBooleanCppuType());
178 4 : rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
179 :
180 4 : if( !sIndexName.isEmpty() )
181 : {
182 4 : aAny <<= sIndexName;
183 4 : rIndexPropertySet->setPropertyValue(sUserIndexName, aAny);
184 : }
185 :
186 4 : XMLIndexSourceBaseContext::EndElement();
187 4 : }
188 :
189 :
190 44 : SvXMLImportContext* XMLIndexUserSourceContext::CreateChildContext(
191 : sal_uInt16 nPrefix,
192 : const OUString& rLocalName,
193 : const Reference<XAttributeList> & xAttrList )
194 : {
195 88 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
196 44 : (IsXMLToken(rLocalName, XML_USER_INDEX_ENTRY_TEMPLATE)) )
197 : {
198 40 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
199 : nPrefix, rLocalName,
200 : aSvLevelNameTOCMap,
201 : XML_OUTLINE_LEVEL,
202 : aLevelStylePropNameTOCMap,
203 40 : aAllowedTokenTypesUser);
204 : }
205 : else
206 : {
207 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
208 : rLocalName,
209 4 : xAttrList);
210 : }
211 :
212 : }
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|