1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfgfilter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_desktop.hxx"
34 #include "cfgfilter.hxx"
36 #include <com/sun/star/beans/NamedValue.hpp>
37 #include <unotools/textsearch.hxx>
40 using namespace com::sun::star
;
41 using namespace com::sun::star::uno
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::beans
;
44 using namespace com::sun::star::configuration::backend
;
48 CConfigFilter::CConfigFilter(const strings_v
* include
, const strings_v
* exclude
)
49 : m_pvInclude(include
)
50 , m_pvExclude(exclude
)
54 void SAL_CALL
CConfigFilter::initialize(const Sequence
< Any
>& seqArgs
)
58 for (sal_Int32 i
=0; i
< seqArgs
.getLength(); i
++)
60 if (seqArgs
[i
] >>= nv
)
62 if (nv
.Name
.equalsAscii("Source"))
63 nv
.Value
>>= m_xSourceLayer
;
64 if (nv
.Name
.equalsAscii("ComponentName"))
65 nv
.Value
>>= m_aCurrentComponent
;
68 if (m_aCurrentComponent
.getLength() == 0)
69 m_aCurrentComponent
= OUString::createFromAscii("unknown.component");
71 if (!m_xSourceLayer
.is()) {
78 void CConfigFilter::pushElement(rtl::OUString aName
, sal_Bool bUse
)
81 if (!m_elementStack
.empty()) {
82 aPath
= m_elementStack
.top().path
; // or use base path
83 aPath
+= OUString::createFromAscii("/");
92 m_elementStack
.push(elem
);
95 sal_Bool
CConfigFilter::checkCurrentElement()
97 return m_elementStack
.top().use
;
100 sal_Bool
CConfigFilter::checkElement(rtl::OUString aName
)
103 sal_Bool bResult
= sal_False
;
105 // get full pathname for element
107 if (!m_elementStack
.empty())
108 aFullPath
= m_elementStack
.top().path
+ OUString::createFromAscii("/");
112 // check whether any include patterns patch this path
113 for (strings_v::const_iterator i_in
= m_pvInclude
->begin();
114 i_in
!= m_pvInclude
->end(); i_in
++)
116 // pattern is beginning of path
117 // or path is a begiing for pattern
118 if (i_in
->match(aFullPath
.copy(0, i_in
->getLength()>aFullPath
.getLength()
119 ? aFullPath
.getLength() : i_in
->getLength()), 0))
122 break; // one match is enough
125 // if match is found, check for exclusion
128 for (strings_v::const_iterator i_ex
= m_pvExclude
->begin();
129 i_ex
!= m_pvExclude
->end(); i_ex
++)
131 if (aFullPath
.match(*i_ex
, 0)) // pattern is beginning of path
134 break; // one is enough...
141 void CConfigFilter::popElement()
143 m_elementStack
.pop();
147 void SAL_CALL
CConfigFilter::readData(
148 const Reference
< configuration::backend::XLayerHandler
>& layerHandler
)
150 com::sun::star::lang::NullPointerException
, lang::WrappedTargetException
,
151 com::sun::star::configuration::backend::MalformedDataException
)
153 // when readData is called, the submitted handler will be stored
154 // in m_xLayerHandler. we will then submit ourself as a handler to
155 // the SourceLayer in m_xSourceLayer.
156 // when the source calls our handler functions we will use the patterns that
157 // where given in the ctor to decide whther they should be relaied to the caller
159 if (m_xSourceLayer
.is() && layerHandler
.is())
161 m_xLayerHandler
= layerHandler
;
162 m_xSourceLayer
->readData(Reference
<XLayerHandler
>(static_cast< XLayerHandler
* >(this)));
165 throw NullPointerException();
170 void SAL_CALL
CConfigFilter::startLayer()
171 throw(::com::sun::star::lang::WrappedTargetException
)
173 m_xLayerHandler
->startLayer();
176 void SAL_CALL
CConfigFilter::endLayer()
178 ::com::sun::star::configuration::backend::MalformedDataException
,
179 ::com::sun::star::lang::WrappedTargetException
)
181 m_xLayerHandler
->endLayer();
184 void SAL_CALL
CConfigFilter::overrideNode(
185 const OUString
& aName
,
186 sal_Int16 aAttributes
,
189 ::com::sun::star::configuration::backend::MalformedDataException
,
190 ::com::sun::star::lang::WrappedTargetException
)
192 if (checkElement(aName
))
194 m_xLayerHandler
->overrideNode(aName
, aAttributes
, bClear
);
198 pushElement(aName
, sal_False
);
201 void SAL_CALL
CConfigFilter::addOrReplaceNode(
202 const OUString
& aName
,
203 sal_Int16 aAttributes
)
205 ::com::sun::star::configuration::backend::MalformedDataException
,
206 ::com::sun::star::lang::WrappedTargetException
)
208 if (checkElement(aName
))
210 m_xLayerHandler
->addOrReplaceNode(aName
, aAttributes
);
214 pushElement(aName
, sal_False
);
217 void SAL_CALL
CConfigFilter::addOrReplaceNodeFromTemplate(
218 const OUString
& aName
,
219 const com::sun::star::configuration::backend::TemplateIdentifier
& aTemplate
,
220 sal_Int16 aAttributes
)
222 ::com::sun::star::configuration::backend::MalformedDataException
,
223 ::com::sun::star::lang::WrappedTargetException
)
225 if (checkElement(aName
))
227 m_xLayerHandler
->addOrReplaceNodeFromTemplate(aName
, aTemplate
, aAttributes
);
231 pushElement(aName
, sal_False
);
234 void SAL_CALL
CConfigFilter::endNode()
236 ::com::sun::star::configuration::backend::MalformedDataException
,
237 ::com::sun::star::lang::WrappedTargetException
)
239 if (checkCurrentElement())
241 m_xLayerHandler
->endNode();
246 void SAL_CALL
CConfigFilter::dropNode(
247 const OUString
& aName
)
249 ::com::sun::star::configuration::backend::MalformedDataException
,
250 ::com::sun::star::lang::WrappedTargetException
)
252 // does not get pushed
253 if (checkElement(aName
))
255 m_xLayerHandler
->dropNode(aName
);
259 void SAL_CALL
CConfigFilter::overrideProperty(
260 const OUString
& aName
,
261 sal_Int16 aAttributes
,
265 ::com::sun::star::configuration::backend::MalformedDataException
,
266 ::com::sun::star::lang::WrappedTargetException
)
268 if (checkElement(aName
)){
269 m_xLayerHandler
->overrideProperty(aName
, aAttributes
, aType
, bClear
);
273 pushElement(aName
, sal_False
);
276 void SAL_CALL
CConfigFilter::setPropertyValue(
279 ::com::sun::star::configuration::backend::MalformedDataException
,
280 ::com::sun::star::lang::WrappedTargetException
)
282 if (checkCurrentElement())
283 m_xLayerHandler
->setPropertyValue(aValue
);
286 void SAL_CALL
CConfigFilter::setPropertyValueForLocale(
288 const OUString
& aLocale
)
290 ::com::sun::star::configuration::backend::MalformedDataException
,
291 ::com::sun::star::lang::WrappedTargetException
)
293 if (checkCurrentElement())
294 m_xLayerHandler
->setPropertyValueForLocale(aValue
, aLocale
);
297 void SAL_CALL
CConfigFilter::endProperty()
299 ::com::sun::star::configuration::backend::MalformedDataException
,
300 ::com::sun::star::lang::WrappedTargetException
)
302 if (checkCurrentElement())
304 m_xLayerHandler
->endProperty();
310 void SAL_CALL
CConfigFilter::addProperty(
311 const rtl::OUString
& aName
,
312 sal_Int16 aAttributes
,
315 ::com::sun::star::configuration::backend::MalformedDataException
,
316 ::com::sun::star::lang::WrappedTargetException
)
318 if (checkElement(aName
))
319 m_xLayerHandler
->addProperty(aName
, aAttributes
, aType
);
322 void SAL_CALL
CConfigFilter::addPropertyWithValue(
323 const rtl::OUString
& aName
,
324 sal_Int16 aAttributes
,
327 ::com::sun::star::configuration::backend::MalformedDataException
,
328 ::com::sun::star::lang::WrappedTargetException
)
330 // add property with value doesn't push the property
331 if (checkElement(aName
))
332 m_xLayerHandler
->addPropertyWithValue(aName
, aAttributes
, aValue
);
336 } // namespace desktop