merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / layerdefaultremover.cxx
blob6cfe71a9d69eca634c5bf71bda49d5dfe4357ef7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layerdefaultremover.cxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "layerdefaultremover.hxx"
36 // -----------------------------------------------------------------------------
38 namespace configmgr
40 // -----------------------------------------------------------------------------
41 namespace backend
43 // -----------------------------------------------------------------------------
44 namespace uno = ::com::sun::star::uno;
45 // -----------------------------------------------------------------------------
47 LayerDefaultRemover::LayerDefaultRemover(uno::Reference< backenduno::XLayerHandler > const & _xResultHandler)
48 :m_xResultHandler(_xResultHandler)
51 // -----------------------------------------------------------------------------
53 LayerDefaultRemover::~LayerDefaultRemover( )
56 // -----------------------------------------------------------------------------
58 bool LayerDefaultRemover::hasPendingProperty()
60 return m_aPropName.Name.getLength()!=0;
62 // -----------------------------------------------------------------------------
64 void LayerDefaultRemover::clearPendingProperty()
66 m_aPropName = PropertyStruct();
68 // -----------------------------------------------------------------------------
70 void SAL_CALL LayerDefaultRemover::startLayer( )
71 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
73 clearPendingProperty();
74 m_xResultHandler->startLayer();
76 // -----------------------------------------------------------------------------
78 void SAL_CALL LayerDefaultRemover::endLayer( )
79 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
81 if (hasPendingProperty())
83 sal_Char const * pMsg =
84 "LayerDefaultRemover: Illegal property started operation";
85 raiseMalformedDataException(pMsg);
87 if (!m_aNodeStack.empty())
89 sal_Char const * pMsg =
90 "LayerDefaultRemover: Illegal node started operation";
91 raiseMalformedDataException(pMsg);
93 m_xResultHandler->endLayer();
95 // -----------------------------------------------------------------------------
97 void SAL_CALL LayerDefaultRemover::overrideNode( const rtl::OUString& aName, sal_Int16 aAttributes, sal_Bool bClear )
98 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
100 if (hasPendingProperty())
102 sal_Char const * pMsg =
103 "LayerDefaultRemover: Illegal property started operation";
104 raiseMalformedDataException(pMsg);
106 if (aAttributes == 0 && !bClear)
108 m_aNodeStack.push_back(aName);
110 else
112 playBackNodeStack();
113 m_xResultHandler->overrideNode(aName,aAttributes,bClear);
116 // -----------------------------------------------------------------------------
118 void SAL_CALL LayerDefaultRemover::addOrReplaceNode( const rtl::OUString& aName, sal_Int16 aAttributes )
119 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
121 playBackNodeStack();
122 m_xResultHandler->addOrReplaceNode(aName, aAttributes);
124 // -----------------------------------------------------------------------------
126 void SAL_CALL LayerDefaultRemover::addOrReplaceNodeFromTemplate( const rtl::OUString& aName, const backenduno::TemplateIdentifier& aTemplate, sal_Int16 aAttributes )
127 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
129 playBackNodeStack();
130 m_xResultHandler->addOrReplaceNodeFromTemplate(aName,aTemplate,aAttributes);
132 // -----------------------------------------------------------------------------
134 void SAL_CALL LayerDefaultRemover::endNode( )
135 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
137 if (hasPendingProperty())
139 sal_Char const * pMsg =
140 "LayerDefaultRemover: Illegal property started operation";
141 raiseMalformedDataException(pMsg);
143 if (m_aNodeStack.empty())
145 m_xResultHandler->endNode();
147 else
149 m_aNodeStack.pop_back();
152 // -----------------------------------------------------------------------------
154 void SAL_CALL LayerDefaultRemover::dropNode( const rtl::OUString& aName )
155 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
157 playBackNodeStack();
158 m_xResultHandler->dropNode(aName);
160 // -----------------------------------------------------------------------------
162 void SAL_CALL LayerDefaultRemover::addProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType )
163 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
165 playBackNodeStack();
166 m_xResultHandler->addProperty (aName,aAttributes,aType);
168 // -----------------------------------------------------------------------------
170 void SAL_CALL LayerDefaultRemover::addPropertyWithValue( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue )
171 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
173 playBackNodeStack();
174 m_xResultHandler->addPropertyWithValue(aName,aAttributes,aValue);
176 // -----------------------------------------------------------------------------
178 void SAL_CALL LayerDefaultRemover::overrideProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType, sal_Bool bClear )
179 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
181 if (hasPendingProperty())
183 sal_Char const * pMsg =
184 "LayerDefaultRemover: Illegal property started operation";
185 raiseMalformedDataException(pMsg);
187 if (aAttributes != 0 || bClear)
189 m_aPropName.Name=rtl::OUString();
190 playBackNodeStack();
191 m_xResultHandler->overrideProperty(aName,aAttributes,aType,bClear);
193 else
195 m_aPropName.Name = aName;
196 m_aPropName.Type = aType;
199 // -----------------------------------------------------------------------------
201 void SAL_CALL LayerDefaultRemover::endProperty( )
202 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
204 if (hasPendingProperty())
206 clearPendingProperty();
208 else
209 m_xResultHandler->endProperty();
211 // -----------------------------------------------------------------------------
213 void SAL_CALL LayerDefaultRemover::setPropertyValue( const uno::Any& aValue )
214 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
216 playBackNodeStack(true);
217 m_xResultHandler->setPropertyValue(aValue);
219 // -----------------------------------------------------------------------------
221 void SAL_CALL LayerDefaultRemover::setPropertyValueForLocale( const uno::Any& aValue, const rtl::OUString& aLocale )
222 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
224 playBackNodeStack(true);
225 m_xResultHandler->setPropertyValueForLocale(aValue,aLocale);
227 // -----------------------------------------------------------------------------
229 void LayerDefaultRemover::playBackNodeStack(bool bPlayProperty)
231 if (!bPlayProperty && hasPendingProperty())
233 sal_Char const * pMsg =
234 "LayerDefaultRemover: Illegal property started operation";
235 raiseMalformedDataException(pMsg);
237 if ( !hasPendingProperty() && bPlayProperty && !m_aNodeStack.empty() )
239 sal_Char const * pMsg =
240 "LayerDefaultRemover: Illegal Operation: Operation requires a started property";
241 raiseMalformedDataException(pMsg);
243 if (!m_aNodeStack.empty())
245 for (std::vector<rtl::OUString>::iterator aIter = m_aNodeStack.begin();
246 aIter != m_aNodeStack.end(); aIter++)
248 m_xResultHandler->overrideNode(*aIter, 0,false);
250 m_aNodeStack.clear();
252 if (bPlayProperty)
254 if (hasPendingProperty())
256 m_xResultHandler->overrideProperty(m_aPropName.Name,0,m_aPropName.Type,false);
257 clearPendingProperty();
261 // -----------------------------------------------------------------------------
263 void LayerDefaultRemover::raiseMalformedDataException(sal_Char const * pMsg)
265 OSL_ASSERT(pMsg);
266 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
268 throw backenduno::MalformedDataException( sMsg, *this, uno::Any() );
271 // -----------------------------------------------------------------------------
272 // -----------------------------------------------------------------------------
273 // -----------------------------------------------------------------------------
274 } // namespace
276 // -----------------------------------------------------------------------------
277 } // namespace