1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: elementformatter.cxx,v $
*
* $Revision: 1.15 $
*
* last change: $Author: obo $ $Date: 2006-09-16 15:33:34 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_configmgr.hxx"
#include "elementformatter.hxx"
#ifndef CONFIGMGR_XML_STRINGS_HXX_
#include "xmlstrings.hxx"
#endif
#ifndef CONFIGMGR_TYPECONVERTER_HXX
#include "typeconverter.hxx"
#endif
#ifndef CONFIGMGR_MISC_ATTRIBUTELIST_HXX
#include "attributelist.hxx"
#endif
#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif
#include <com/sun/star/configuration/backend/SchemaAttribute.hpp>
#include <com/sun/star/configuration/backend/NodeAttribute.hpp>
// -----------------------------------------------------------------------------
namespace configmgr
{
// -----------------------------------------------------------------------------
namespace xml
{
// -----------------------------------------------------------------------------
namespace uno = ::com::sun::star::uno;
namespace sax = ::com::sun::star::xml::sax;
// -----------------------------------------------------------------------------
ElementFormatter::ElementFormatter()
: m_aElementType(ElementType::unknown)
, m_xAttributes()
{
}
// -----------------------------------------------------------------------------
ElementFormatter::~ElementFormatter()
{
}
// -----------------------------------------------------------------------------
void ElementFormatter::reset()
{
m_aElementType = ElementType::unknown;
m_xAttributes.clear();
}
// -----------------------------------------------------------------------------
void ElementFormatter::addAttribute(OUString const & _anAttributeName, OUString const & _aValue)
{
OSL_PRECOND(m_xAttributes.is(),"Trying to add an attribute to a non-existing list");
m_xAttributes->addAttribute(_anAttributeName,
XML_ATTRTYPE_CDATA,
_aValue);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addAttribute(OUString const & _anAttributeName, bool _bValue)
{
OSL_PRECOND(m_xAttributes.is(),"Trying to add an attribute to a non-existing list");
m_xAttributes->addAttribute(_anAttributeName,
XML_ATTRTYPE_CDATA,
_bValue ? ATTR_VALUE_TRUE : ATTR_VALUE_FALSE);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addNamespaces()
{
static OUString const sNamespaceDecl( RTL_CONSTASCII_USTRINGPARAM("xmlns:") );
addAttribute( sNamespaceDecl.concat(NS_PREFIX_OOR), static_cast<OUString const &>(NS_URI_OOR));
addAttribute( sNamespaceDecl.concat(NS_PREFIX_XS ), static_cast<OUString const &>(NS_URI_XS ));
}
// -----------------------------------------------------------------------------
void ElementFormatter::prepareElement(ElementInfo const& _aInfo)
{
if (!m_xAttributes.is())
{
m_xAttributes.set( new AttributeListImpl() );
addNamespaces();
}
else
m_xAttributes->clear();
m_aElementType = _aInfo.type;
addName(_aInfo.name);
addNodeFlags(_aInfo.flags);
addOperation(_aInfo.op);
}
// -----------------------------------------------------------------------------
void ElementFormatter::prepareSimpleElement(ElementType::Enum _eType)
{
if (!m_xAttributes.is())
{
m_xAttributes.set( new AttributeListImpl() );
addNamespaces();
}
else
m_xAttributes->clear();
m_aElementType = _eType;
}
// -----------------------------------------------------------------------------
void ElementFormatter::addName(OUString const & _aName)
{
if (_aName.getLength())
{
switch( m_aElementType )
{
case ElementType::schema:
case ElementType::layer:
{
sal_Int32 nIndex = _aName.lastIndexOf('.');
OUString aNodeName = _aName.copy(nIndex + 1);
addAttribute(ATTR_NAME, aNodeName);
OSL_ENSURE(nIndex > 0,"Found component root element without a package part in its name");
if (nIndex > 0)
{
OUString aPackage = _aName.copy(0, nIndex);
addAttribute(ATTR_PACKAGE, aPackage);
}
}
break;
default:
addAttribute(ATTR_NAME, _aName);
break;
}
}
}
// -----------------------------------------------------------------------------
inline
void ElementFormatter::maybeAddFlag(FlagsType _eFlags, FlagsType _eSelect, OUString const & _anAttributeName, bool _bValue)
{
if (_eFlags & _eSelect) addAttribute(_anAttributeName,_bValue);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addNodeFlags(FlagsType _eFlags)
{
using namespace ::com::sun::star::configuration::backend;
maybeAddFlag(_eFlags,SchemaAttribute::REQUIRED, ATTR_FLAG_NULLABLE, false);
maybeAddFlag(_eFlags,SchemaAttribute::LOCALIZED, ATTR_FLAG_LOCALIZED);
maybeAddFlag(_eFlags,SchemaAttribute::EXTENSIBLE, ATTR_FLAG_EXTENSIBLE);
maybeAddFlag(_eFlags,NodeAttribute::FINALIZED, ATTR_FLAG_FINALIZED);
maybeAddFlag(_eFlags,NodeAttribute::MANDATORY, ATTR_FLAG_MANDATORY);
maybeAddFlag(_eFlags,NodeAttribute::READONLY, ATTR_FLAG_READONLY);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addOperation(Operation::Enum _eOp)
{
switch (_eOp)
{
case Operation::none: break;
case Operation::modify: break ; //addAttribute(ATTR_OPERATION, static_cast<OUString const &>(OPERATION_MODIFY)); break;
case Operation::clear: OSL_ENSURE(false,"'clear' operation is not yet supported"); break ;
//addAttribute(ATTR_OPERATION, static_cast<OUString const &>(OPERATION_CLEAR)); break;
case Operation::replace: addAttribute(ATTR_OPERATION, static_cast<OUString const &>(OPERATION_REPLACE)); break;
case Operation::fuse: addAttribute(ATTR_OPERATION, static_cast<OUString const &>(OPERATION_FUSE)); break;
case Operation::remove: addAttribute(ATTR_OPERATION, static_cast<OUString const &>(OPERATION_REMOVE)); break;
case Operation::unknown:
OSL_ENSURE(false, "ElementFormatter: Trying to add attribute for 'unknown' operation");
break;
default:
OSL_ENSURE(false, "ElementFormatter: Trying to add attribute for invalid operation");
break;
}
}
// -----------------------------------------------------------------------------
void ElementFormatter::addInstanceType(OUString const & /*_aElementType*/, OUString const & /*_aElementTypeModule*/)
{
}
// -----------------------------------------------------------------------------
static ::rtl::OUString toXmlTypeName(const uno::TypeClass& _rTypeClass)
{
::rtl::OUString aRet;
switch(_rTypeClass)
{
case uno::TypeClass_BOOLEAN: aRet = VALUETYPE_BOOLEAN; break;
case uno::TypeClass_SHORT: aRet = VALUETYPE_SHORT; break;
case uno::TypeClass_LONG: aRet = VALUETYPE_INT; break;
case uno::TypeClass_HYPER: aRet = VALUETYPE_LONG; break;
case uno::TypeClass_DOUBLE: aRet = VALUETYPE_DOUBLE; break;
case uno::TypeClass_STRING: aRet = VALUETYPE_STRING; break;
case uno::TypeClass_SEQUENCE: aRet = VALUETYPE_BINARY; break;
case uno::TypeClass_ANY: aRet = VALUETYPE_ANY; break;
default:
OSL_ENSURE(false,"Cannot get type name: unknown typeclass");
break;
}
return aRet;
}
// -----------------------------------------------------------------------------
void ElementFormatter::addPropertyValueType(uno::Type const& _aType)
{
if (_aType == uno::Type()) return;
bool bList = false;
uno::Type aSimpleType = getBasicType(_aType, bList);
uno::TypeClass aSimpleTypeClass = aSimpleType.getTypeClass();
OUString aSimpleTypeName = toXmlTypeName(aSimpleTypeClass);
OUString sNsPrefix = (bList || aSimpleTypeClass == uno::TypeClass_ANY) ?
OUString( NS_PREFIX_OOR ) : OUString( NS_PREFIX_XS );
rtl::OUStringBuffer aTypeNameBuf(sNsPrefix);
if (sNsPrefix.getLength())
aTypeNameBuf. append(k_NS_SEPARATOR);
aTypeNameBuf. append(aSimpleTypeName);
if (bList)
aTypeNameBuf. append(VALUETYPE_LIST_SUFFIX);
addAttribute( ATTR_VALUETYPE, aTypeNameBuf.makeStringAndClear());
}
// -----------------------------------------------------------------------------
void ElementFormatter::addLanguage(OUString const & _sLanguage)
{
OSL_ENSURE(_sLanguage.getLength(), "ElementFormatter: Trying to add empty language attribute");
addAttribute(EXT_ATTR_LANGUAGE, _sLanguage);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addIsNull(bool _bIsNull)
{
addAttribute( EXT_ATTR_NULL, _bIsNull);
}
// -----------------------------------------------------------------------------
void ElementFormatter::addSeparator(OUString const& _sSeparator)
{
addAttribute( ATTR_VALUESEPARATOR, _sSeparator);
}
// -----------------------------------------------------------------------------
OUString ElementFormatter::getElementTag() const
{
switch (m_aElementType)
{
case ElementType::schema: return OUString( TAG_SCHEMA );
case ElementType::layer: return OUString( TAG_LAYER );
case ElementType::component: return OUString( TAG_COMPONENT );
case ElementType::templates: return OUString( TAG_TEMPLATES );
case ElementType::property: return OUString( TAG_PROP );
case ElementType::node: return OUString( TAG_NODE );
case ElementType::group: return OUString( TAG_GROUP );
case ElementType::set: return OUString( TAG_SET );
case ElementType::import: return OUString( TAG_IMPORT );
case ElementType::instance: return OUString( TAG_INSTANCE );
case ElementType::item_type: return OUString( TAG_ITEMTYPE );
case ElementType::value: return OUString( TAG_VALUE );
case ElementType::uses: return OUString( TAG_USES );
case ElementType::unknown:
OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for 'unknown' element type");
break;
case ElementType::other:
OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for 'other' element type");
break;
default:
OSL_ENSURE(false, "ElementFormatter: Trying to get Tag for invalid element type");
break;
}
return OUString();
}
// -----------------------------------------------------------------------------
uno::Reference< sax::XAttributeList > ElementFormatter::getElementAttributes() const
{
return m_xAttributes.get();
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
} // namespace
} // namespace
|