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 ::rtl::OUString;
37 : using ::com::sun::star::beans::XPropertySet;
38 : using ::com::sun::star::uno::Reference;
39 : using ::com::sun::star::uno::Any;
40 : using ::com::sun::star::xml::sax::XAttributeList;
41 : using ::xmloff::token::IsXMLToken;
42 : using ::xmloff::token::XML_USER_INDEX_ENTRY_TEMPLATE;
43 : using ::xmloff::token::XML_OUTLINE_LEVEL;
44 :
45 :
46 : const sal_Char sAPI_CreateFromEmbeddedObjects[] = "CreateFromEmbeddedObjects";
47 : const sal_Char sAPI_CreateFromGraphicObjects[] = "CreateFromGraphicObjects";
48 : const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
49 : const sal_Char sAPI_CreateFromTables[] = "CreateFromTables";
50 : const sal_Char sAPI_CreateFromTextFrames[] = "CreateFromTextFrames";
51 : const sal_Char sAPI_UseLevelFromSource[] = "UseLevelFromSource";
52 : const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
53 : const sal_Char sAPI_UserIndexName[] = "UserIndexName";
54 :
55 :
56 0 : TYPEINIT1(XMLIndexUserSourceContext, XMLIndexSourceBaseContext);
57 :
58 :
59 0 : XMLIndexUserSourceContext::XMLIndexUserSourceContext(
60 : SvXMLImport& rImport,
61 : sal_uInt16 nPrfx,
62 : const OUString& rLocalName,
63 : Reference<XPropertySet> & rPropSet) :
64 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
65 : rPropSet, sal_True),
66 : sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM(
67 : sAPI_CreateFromEmbeddedObjects)),
68 : sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM(
69 : sAPI_CreateFromGraphicObjects)),
70 : sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)),
71 : sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromTables)),
72 : sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM(
73 : sAPI_CreateFromTextFrames)),
74 : sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM(
75 : sAPI_UseLevelFromSource)),
76 : sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(
77 : sAPI_CreateFromLevelParagraphStyles)),
78 : sUserIndexName(RTL_CONSTASCII_USTRINGPARAM(sAPI_UserIndexName)),
79 : bUseObjects(sal_False),
80 : bUseGraphic(sal_False),
81 : bUseMarks(sal_False),
82 : bUseTables(sal_False),
83 : bUseFrames(sal_False),
84 : bUseLevelFromSource(sal_False),
85 0 : bUseLevelParagraphStyles(sal_False)
86 : {
87 0 : }
88 :
89 0 : XMLIndexUserSourceContext::~XMLIndexUserSourceContext()
90 : {
91 0 : }
92 :
93 0 : void XMLIndexUserSourceContext::ProcessAttribute(
94 : enum IndexSourceParamEnum eParam,
95 : const OUString& rValue)
96 : {
97 0 : bool bTmp(false);
98 :
99 0 : switch (eParam)
100 : {
101 : case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
102 0 : if (::sax::Converter::convertBool(bTmp, rValue))
103 : {
104 0 : bUseMarks = bTmp;
105 : }
106 0 : break;
107 :
108 : case XML_TOK_INDEXSOURCE_USE_OBJECTS:
109 0 : if (::sax::Converter::convertBool(bTmp, rValue))
110 : {
111 0 : bUseObjects = bTmp;
112 : }
113 0 : break;
114 :
115 : case XML_TOK_INDEXSOURCE_USE_GRAPHICS:
116 0 : if (::sax::Converter::convertBool(bTmp, rValue))
117 : {
118 0 : bUseGraphic = bTmp;
119 : }
120 0 : break;
121 :
122 : case XML_TOK_INDEXSOURCE_USE_TABLES:
123 0 : if (::sax::Converter::convertBool(bTmp, rValue))
124 : {
125 0 : bUseTables = bTmp;
126 : }
127 0 : break;
128 :
129 : case XML_TOK_INDEXSOURCE_USE_FRAMES:
130 0 : if (::sax::Converter::convertBool(bTmp, rValue))
131 : {
132 0 : bUseFrames = bTmp;
133 : }
134 0 : break;
135 :
136 : case XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS:
137 0 : if (::sax::Converter::convertBool(bTmp, rValue))
138 : {
139 0 : bUseLevelFromSource = bTmp;
140 : }
141 0 : break;
142 :
143 : case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
144 0 : if (::sax::Converter::convertBool(bTmp, rValue))
145 : {
146 0 : bUseLevelParagraphStyles = bTmp;
147 : }
148 0 : break;
149 :
150 : case XML_TOK_INDEXSOURCE_USER_INDEX_NAME:
151 0 : sIndexName = rValue;
152 0 : break;
153 :
154 : default:
155 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
156 0 : break;
157 : }
158 0 : }
159 :
160 :
161 0 : void XMLIndexUserSourceContext::EndElement()
162 : {
163 0 : Any aAny;
164 :
165 0 : aAny.setValue(&bUseObjects, ::getBooleanCppuType());
166 0 : rIndexPropertySet->setPropertyValue(sCreateFromEmbeddedObjects, aAny);
167 :
168 0 : aAny.setValue(&bUseGraphic, ::getBooleanCppuType());
169 0 : rIndexPropertySet->setPropertyValue(sCreateFromGraphicObjects, aAny);
170 :
171 0 : aAny.setValue(&bUseLevelFromSource, ::getBooleanCppuType());
172 0 : rIndexPropertySet->setPropertyValue(sUseLevelFromSource, aAny);
173 :
174 0 : aAny.setValue(&bUseMarks, ::getBooleanCppuType());
175 0 : rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
176 :
177 0 : aAny.setValue(&bUseTables, ::getBooleanCppuType());
178 0 : rIndexPropertySet->setPropertyValue(sCreateFromTables, aAny);
179 :
180 0 : aAny.setValue(&bUseFrames, ::getBooleanCppuType());
181 0 : rIndexPropertySet->setPropertyValue(sCreateFromTextFrames, aAny);
182 :
183 0 : aAny.setValue(&bUseLevelParagraphStyles, ::getBooleanCppuType());
184 0 : rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
185 :
186 0 : if( !sIndexName.isEmpty() )
187 : {
188 0 : aAny <<= sIndexName;
189 0 : rIndexPropertySet->setPropertyValue(sUserIndexName, aAny);
190 : }
191 :
192 0 : XMLIndexSourceBaseContext::EndElement();
193 0 : }
194 :
195 :
196 0 : SvXMLImportContext* XMLIndexUserSourceContext::CreateChildContext(
197 : sal_uInt16 nPrefix,
198 : const OUString& rLocalName,
199 : const Reference<XAttributeList> & xAttrList )
200 : {
201 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
202 0 : (IsXMLToken(rLocalName, XML_USER_INDEX_ENTRY_TEMPLATE)) )
203 : {
204 0 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
205 : nPrefix, rLocalName,
206 : aLevelNameTOCMap,
207 : XML_OUTLINE_LEVEL,
208 : aLevelStylePropNameTOCMap,
209 0 : aAllowedTokenTypesUser);
210 : }
211 : else
212 : {
213 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
214 : rLocalName,
215 0 : xAttrList);
216 : }
217 :
218 : }
219 :
220 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|