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 "sal/config.h"
21 :
22 : #include <cassert>
23 :
24 : #include "boost/noncopyable.hpp"
25 : #include "com/sun/star/uno/Any.hxx"
26 : #include "com/sun/star/uno/Reference.hxx"
27 : #include "com/sun/star/uno/RuntimeException.hpp"
28 : #include "com/sun/star/uno/Sequence.hxx"
29 : #include "com/sun/star/uno/XInterface.hpp"
30 : #include "osl/file.h"
31 : #include "osl/file.hxx"
32 : #include "rtl/string.h"
33 : #include "rtl/string.hxx"
34 : #include "rtl/textcvt.h"
35 : #include "rtl/textenc.h"
36 : #include "rtl/ustrbuf.hxx"
37 : #include "rtl/ustring.h"
38 : #include "rtl/ustring.hxx"
39 : #include "sal/log.hxx"
40 : #include "sal/types.h"
41 : #include "xmlreader/span.hxx"
42 :
43 : #include "data.hxx"
44 : #include "groupnode.hxx"
45 : #include "localizedpropertynode.hxx"
46 : #include "localizedvaluenode.hxx"
47 : #include "modifications.hxx"
48 : #include "node.hxx"
49 : #include "nodemap.hxx"
50 : #include "propertynode.hxx"
51 : #include "type.hxx"
52 : #include "writemodfile.hxx"
53 :
54 : namespace configmgr {
55 :
56 : class Components;
57 :
58 : namespace {
59 :
60 0 : OString convertToUtf8(
61 : OUString const & text, sal_Int32 offset, sal_Int32 length)
62 : {
63 : assert(offset <= text.getLength() && text.getLength() - offset >= length);
64 0 : OString s;
65 0 : if (!rtl_convertUStringToString(
66 0 : &s.pData, text.pData->buffer + offset, length,
67 : RTL_TEXTENCODING_UTF8,
68 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
69 0 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
70 : {
71 : throw css::uno::RuntimeException(
72 : "cannot convert to UTF-8",
73 0 : css::uno::Reference< css::uno::XInterface >());
74 : }
75 0 : return s;
76 : }
77 :
78 : struct TempFile: public boost::noncopyable {
79 : OUString url;
80 : oslFileHandle handle;
81 : bool closed;
82 :
83 0 : TempFile(): handle(0), closed(false) {}
84 :
85 : ~TempFile();
86 : };
87 :
88 0 : TempFile::~TempFile() {
89 0 : if (handle != 0) {
90 0 : if (!closed) {
91 0 : oslFileError e = osl_closeFile(handle);
92 0 : if (e != osl_File_E_None) {
93 : SAL_WARN("configmgr", "osl_closeFile failed with " << +e);
94 : }
95 : }
96 0 : osl::FileBase::RC e = osl::File::remove(url);
97 0 : if (e != osl::FileBase::E_None) {
98 : SAL_WARN(
99 : "configmgr",
100 : "osl::File::remove(" << url << ") failed with " << +e);
101 : }
102 : }
103 0 : }
104 :
105 0 : void writeData_(oslFileHandle handle, char const * begin, sal_Int32 length) {
106 : assert(length >= 0);
107 : sal_uInt64 n;
108 0 : if ((osl_writeFile(handle, begin, static_cast< sal_uInt32 >(length), &n) !=
109 0 : osl_File_E_None) ||
110 0 : n != static_cast< sal_uInt32 >(length))
111 : {
112 : throw css::uno::RuntimeException(
113 0 : "write failure", css::uno::Reference< css::uno::XInterface >());
114 : }
115 0 : }
116 :
117 0 : void writeValueContent_(oslFileHandle handle, sal_Bool value) {
118 0 : if (value) {
119 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("true"));
120 : } else {
121 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("false"));
122 : }
123 0 : }
124 :
125 0 : void writeValueContent_(oslFileHandle handle, sal_Int16 value) {
126 0 : writeData(handle, OString::number(value));
127 0 : }
128 :
129 0 : void writeValueContent_(oslFileHandle handle, sal_Int32 value) {
130 0 : writeData(handle, OString::number(value));
131 0 : }
132 :
133 0 : void writeValueContent_(oslFileHandle handle, sal_Int64 value) {
134 0 : writeData(handle, OString::number(value));
135 0 : }
136 :
137 0 : void writeValueContent_(oslFileHandle handle, double value) {
138 0 : writeData(handle, OString::number(value));
139 0 : }
140 :
141 0 : void writeValueContent_(oslFileHandle handle, const OUString& value) {
142 0 : writeValueContent(handle, value);
143 0 : }
144 :
145 0 : void writeValueContent_(
146 : oslFileHandle handle, css::uno::Sequence< sal_Int8 > const & value)
147 : {
148 0 : for (sal_Int32 i = 0; i < value.getLength(); ++i) {
149 : static char const hexDigit[16] = {
150 : '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
151 : 'D', 'E', 'F' };
152 0 : writeData_(handle, hexDigit + ((value[i] >> 4) & 0xF), 1);
153 0 : writeData_(handle, hexDigit + (value[i] & 0xF), 1);
154 : }
155 0 : }
156 :
157 0 : template< typename T > void writeSingleValue(
158 : oslFileHandle handle, css::uno::Any const & value)
159 : {
160 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(">"));
161 0 : T val = T();
162 0 : value >>= val;
163 0 : writeValueContent_(handle, val);
164 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</value>"));
165 0 : }
166 :
167 0 : template< typename T > void writeListValue(
168 : oslFileHandle handle, css::uno::Any const & value)
169 : {
170 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(">"));
171 0 : css::uno::Sequence< T > val;
172 0 : value >>= val;
173 0 : for (sal_Int32 i = 0; i < val.getLength(); ++i) {
174 0 : if (i != 0) {
175 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(" "));
176 : }
177 0 : writeValueContent_(handle, val[i]);
178 : }
179 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</value>"));
180 0 : }
181 :
182 0 : template< typename T > void writeItemListValue(
183 : oslFileHandle handle, css::uno::Any const & value)
184 : {
185 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(">"));
186 0 : css::uno::Sequence< T > val;
187 0 : value >>= val;
188 0 : for (sal_Int32 i = 0; i < val.getLength(); ++i) {
189 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<it>"));
190 0 : writeValueContent_(handle, val[i]);
191 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</it>"));
192 : }
193 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</value>"));
194 0 : }
195 :
196 0 : void writeValue(oslFileHandle handle, Type type, css::uno::Any const & value) {
197 0 : switch (type) {
198 : case TYPE_BOOLEAN:
199 0 : writeSingleValue< sal_Bool >(handle, value);
200 0 : break;
201 : case TYPE_SHORT:
202 0 : writeSingleValue< sal_Int16 >(handle, value);
203 0 : break;
204 : case TYPE_INT:
205 0 : writeSingleValue< sal_Int32 >(handle, value);
206 0 : break;
207 : case TYPE_LONG:
208 0 : writeSingleValue< sal_Int64 >(handle, value);
209 0 : break;
210 : case TYPE_DOUBLE:
211 0 : writeSingleValue< double >(handle, value);
212 0 : break;
213 : case TYPE_STRING:
214 0 : writeSingleValue< OUString >(handle, value);
215 0 : break;
216 : case TYPE_HEXBINARY:
217 0 : writeSingleValue< css::uno::Sequence< sal_Int8 > >(handle, value);
218 0 : break;
219 : case TYPE_BOOLEAN_LIST:
220 0 : writeListValue< sal_Bool >(handle, value);
221 0 : break;
222 : case TYPE_SHORT_LIST:
223 0 : writeListValue< sal_Int16 >(handle, value);
224 0 : break;
225 : case TYPE_INT_LIST:
226 0 : writeListValue< sal_Int32 >(handle, value);
227 0 : break;
228 : case TYPE_LONG_LIST:
229 0 : writeListValue< sal_Int64 >(handle, value);
230 0 : break;
231 : case TYPE_DOUBLE_LIST:
232 0 : writeListValue< double >(handle, value);
233 0 : break;
234 : case TYPE_STRING_LIST:
235 0 : writeItemListValue< OUString >(handle, value);
236 0 : break;
237 : case TYPE_HEXBINARY_LIST:
238 0 : writeItemListValue< css::uno::Sequence< sal_Int8 > >(handle, value);
239 0 : break;
240 : default: // TYPE_ERROR, TYPE_NIL, TYPE_ANY
241 : assert(false); // this cannot happen
242 : }
243 0 : }
244 :
245 0 : void writeNode(
246 : Components & components, oslFileHandle handle,
247 : rtl::Reference< Node > const & parent, OUString const & name,
248 : rtl::Reference< Node > const & node)
249 : {
250 : static xmlreader::Span const typeNames[] = {
251 : xmlreader::Span(), xmlreader::Span(), xmlreader::Span(),
252 : // TYPE_ERROR, TYPE_NIL, TYPE_ANY
253 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:boolean")),
254 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:short")),
255 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:int")),
256 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:long")),
257 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:double")),
258 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:string")),
259 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("xs:hexBinary")),
260 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:boolean-list")),
261 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:short-list")),
262 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:int-list")),
263 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:long-list")),
264 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:double-list")),
265 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:string-list")),
266 0 : xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("oor:hexBinary-list")) };
267 0 : switch (node->kind()) {
268 : case Node::KIND_PROPERTY:
269 : {
270 0 : PropertyNode * prop = static_cast< PropertyNode * >(node.get());
271 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\""));
272 0 : writeAttributeValue(handle, name);
273 : writeData_(
274 0 : handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"fuse\""));
275 0 : Type type = prop->getStaticType();
276 0 : Type dynType = getDynamicType(prop->getValue(components));
277 : assert(dynType != TYPE_ERROR);
278 0 : if (type == TYPE_ANY) {
279 0 : type = dynType;
280 0 : if (type != TYPE_NIL) {
281 : writeData_(
282 0 : handle, RTL_CONSTASCII_STRINGPARAM(" oor:type=\""));
283 : writeData_(
284 0 : handle, typeNames[type].begin, typeNames[type].length);
285 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\""));
286 : }
287 : }
288 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("><value"));
289 0 : if (dynType == TYPE_NIL) {
290 : writeData_(
291 0 : handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>"));
292 : } else {
293 0 : writeValue(handle, type, prop->getValue(components));
294 : }
295 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</prop>"));
296 : }
297 0 : break;
298 : case Node::KIND_LOCALIZED_PROPERTY:
299 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\""));
300 0 : writeAttributeValue(handle, name);
301 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"fuse\">"));
302 0 : for (NodeMap::const_iterator i(node->getMembers().begin());
303 0 : i != node->getMembers().end(); ++i)
304 : {
305 0 : writeNode(components, handle, node, i->first, i->second);
306 : }
307 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</prop>"));
308 0 : break;
309 : case Node::KIND_LOCALIZED_VALUE:
310 : {
311 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<value"));
312 0 : if (!name.isEmpty()) {
313 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(" xml:lang=\""));
314 0 : writeAttributeValue(handle, name);
315 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\""));
316 : }
317 0 : Type type = static_cast< LocalizedPropertyNode * >(parent.get())->
318 0 : getStaticType();
319 : css::uno::Any value(
320 0 : static_cast< LocalizedValueNode * >(node.get())->getValue());
321 0 : Type dynType = getDynamicType(value);
322 : assert(dynType != TYPE_ERROR);
323 0 : if (type == TYPE_ANY) {
324 0 : type = dynType;
325 0 : if (type != TYPE_NIL) {
326 : writeData_(
327 0 : handle, RTL_CONSTASCII_STRINGPARAM(" oor:type=\""));
328 : writeData_(
329 0 : handle, typeNames[type].begin, typeNames[type].length);
330 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\""));
331 : }
332 : }
333 0 : if (dynType == TYPE_NIL) {
334 : writeData_(
335 0 : handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>"));
336 : } else {
337 0 : writeValue(handle, type, value);
338 0 : }
339 : }
340 0 : break;
341 : case Node::KIND_GROUP:
342 : case Node::KIND_SET:
343 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<node oor:name=\""));
344 0 : writeAttributeValue(handle, name);
345 0 : if (!node->getTemplateName().isEmpty()) { // set member
346 : writeData_(
347 0 : handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"replace"));
348 : }
349 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\">"));
350 0 : for (NodeMap::const_iterator i(node->getMembers().begin());
351 0 : i != node->getMembers().end(); ++i)
352 : {
353 0 : writeNode(components, handle, node, i->first, i->second);
354 : }
355 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</node>"));
356 0 : break;
357 : case Node::KIND_ROOT:
358 : assert(false); // this cannot happen
359 0 : break;
360 : }
361 0 : }
362 :
363 0 : void writeModifications(
364 : Components & components, oslFileHandle handle,
365 : OUString const & parentPathRepresentation,
366 : rtl::Reference< Node > const & parent, OUString const & nodeName,
367 : rtl::Reference< Node > const & node,
368 : Modifications::Node const & modifications)
369 : {
370 : // It is never necessary to write oor:finalized or oor:mandatory attributes,
371 : // as they cannot be set via the UNO API.
372 0 : if (modifications.children.empty()) {
373 : assert(parent.is());
374 : // components themselves have no parent but must have children
375 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<item oor:path=\""));
376 0 : writeAttributeValue(handle, parentPathRepresentation);
377 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\">"));
378 0 : if (node.is()) {
379 0 : writeNode(components, handle, parent, nodeName, node);
380 : } else {
381 0 : switch (parent->kind()) {
382 : case Node::KIND_LOCALIZED_PROPERTY:
383 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<value"));
384 0 : if (!nodeName.isEmpty()) {
385 : writeData_(
386 0 : handle, RTL_CONSTASCII_STRINGPARAM(" xml:lang=\""));
387 0 : writeAttributeValue(handle, nodeName);
388 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\""));
389 : }
390 : writeData_(
391 0 : handle, RTL_CONSTASCII_STRINGPARAM(" oor:op=\"remove\"/>"));
392 0 : break;
393 : case Node::KIND_GROUP:
394 : assert(
395 : static_cast< GroupNode * >(parent.get())->isExtensible());
396 : writeData_(
397 0 : handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\""));
398 0 : writeAttributeValue(handle, nodeName);
399 : writeData_(
400 : handle,
401 0 : RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"remove\"/>"));
402 0 : break;
403 : case Node::KIND_SET:
404 : writeData_(
405 0 : handle, RTL_CONSTASCII_STRINGPARAM("<node oor:name=\""));
406 0 : writeAttributeValue(handle, nodeName);
407 : writeData_(
408 : handle,
409 0 : RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"remove\"/>"));
410 0 : break;
411 : default:
412 : assert(false); // this cannot happen
413 0 : break;
414 : }
415 : }
416 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("</item>\n"));
417 : } else {
418 : assert(node.is());
419 : OUString pathRep(
420 0 : parentPathRepresentation + "/" +
421 0 : Data::createSegment(node->getTemplateName(), nodeName));
422 0 : for (Modifications::Node::Children::const_iterator i(
423 0 : modifications.children.begin());
424 0 : i != modifications.children.end(); ++i)
425 : {
426 : writeModifications(
427 0 : components, handle, pathRep, node, i->first,
428 0 : node->getMember(i->first), i->second);
429 0 : }
430 : }
431 0 : }
432 :
433 : }
434 :
435 0 : void writeData(oslFileHandle handle, OString const & text) {
436 0 : writeData_(handle, text.getStr(), text.getLength());
437 0 : }
438 :
439 0 : void writeAttributeValue(oslFileHandle handle, OUString const & value) {
440 0 : sal_Int32 i = 0;
441 0 : sal_Int32 j = i;
442 0 : for (; j < value.getLength(); ++j) {
443 : assert(
444 : value[j] == 0x0009 || value[j] == 0x000A || value[j] == 0x000D ||
445 : (value[j] >= 0x0020 && value[j] != 0xFFFE && value[j] != 0xFFFF));
446 0 : switch(value[j]) {
447 : case '\x09':
448 0 : writeData(handle, convertToUtf8(value, i, j - i));
449 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("	"));
450 0 : i = j + 1;
451 0 : break;
452 : case '\x0A':
453 0 : writeData(handle, convertToUtf8(value, i, j - i));
454 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("
"));
455 0 : i = j + 1;
456 0 : break;
457 : case '\x0D':
458 0 : writeData(handle, convertToUtf8(value, i, j - i));
459 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("
"));
460 0 : i = j + 1;
461 0 : break;
462 : case '"':
463 0 : writeData(handle, convertToUtf8(value, i, j - i));
464 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("""));
465 0 : i = j + 1;
466 0 : break;
467 : case '&':
468 0 : writeData(handle, convertToUtf8(value, i, j - i));
469 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("&"));
470 0 : i = j + 1;
471 0 : break;
472 : case '<':
473 0 : writeData(handle, convertToUtf8(value, i, j - i));
474 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<"));
475 0 : i = j + 1;
476 0 : break;
477 : default:
478 0 : break;
479 : }
480 : }
481 0 : writeData(handle, convertToUtf8(value, i, j - i));
482 0 : }
483 :
484 0 : void writeValueContent(oslFileHandle handle, OUString const & value) {
485 0 : sal_Int32 i = 0;
486 0 : sal_Int32 j = i;
487 0 : for (; j < value.getLength(); ++j) {
488 0 : sal_Unicode c = value[j];
489 0 : if ((c < 0x0020 && c != 0x0009 && c != 0x000A && c != 0x000D) ||
490 0 : c == 0xFFFE || c == 0xFFFF)
491 : {
492 0 : writeData(handle, convertToUtf8(value, i, j - i));
493 : writeData_(
494 0 : handle, RTL_CONSTASCII_STRINGPARAM("<unicode oor:scalar=\""));
495 : writeData(
496 0 : handle, OString::number(c));
497 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("\"/>"));
498 0 : i = j + 1;
499 0 : } else if (c == '\x0D') {
500 0 : writeData(handle, convertToUtf8(value, i, j - i));
501 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("
"));
502 0 : i = j + 1;
503 0 : } else if (c == '&') {
504 0 : writeData(handle, convertToUtf8(value, i, j - i));
505 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("&"));
506 0 : i = j + 1;
507 0 : } else if (c == '<') {
508 0 : writeData(handle, convertToUtf8(value, i, j - i));
509 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM("<"));
510 0 : i = j + 1;
511 0 : } else if (c == '>') {
512 : // "MUST, for compatibility, be escaped [...] when it appears in the
513 : // string ']]>'":
514 0 : writeData(handle, convertToUtf8(value, i, j - i));
515 0 : writeData_(handle, RTL_CONSTASCII_STRINGPARAM(">"));
516 0 : i = j + 1;
517 : }
518 : }
519 0 : writeData(handle, convertToUtf8(value, i, j - i));
520 0 : }
521 :
522 0 : void writeModFile(
523 : Components & components, OUString const & url, Data const & data)
524 : {
525 0 : sal_Int32 i = url.lastIndexOf('/');
526 : assert(i != -1);
527 0 : OUString dir(url.copy(0, i));
528 0 : switch (osl::Directory::createPath(dir)) {
529 : case osl::FileBase::E_None:
530 : case osl::FileBase::E_EXIST:
531 0 : break;
532 : case osl::FileBase::E_ACCES:
533 : SAL_INFO(
534 : "configmgr",
535 : ("cannot create registrymodifications.xcu path (E_ACCES); changes"
536 : " will be lost"));
537 0 : return;
538 : default:
539 : throw css::uno::RuntimeException(
540 0 : "cannot create directory " + dir,
541 0 : css::uno::Reference< css::uno::XInterface >());
542 : }
543 0 : TempFile tmp;
544 0 : switch (osl::FileBase::createTempFile(&dir, &tmp.handle, &tmp.url)) {
545 : case osl::FileBase::E_None:
546 0 : break;
547 : case osl::FileBase::E_ACCES:
548 : SAL_INFO(
549 : "configmgr",
550 : ("cannot create temp registrymodifications.xcu (E_ACCES); changes"
551 : " will be lost"));
552 0 : return;
553 : default:
554 : throw css::uno::RuntimeException(
555 0 : "cannot create temporary file in " + dir,
556 0 : css::uno::Reference< css::uno::XInterface >());
557 : }
558 : writeData_(
559 : tmp.handle,
560 : RTL_CONSTASCII_STRINGPARAM(
561 : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<oor:items"
562 : " xmlns:oor=\"http://openoffice.org/2001/registry\""
563 : " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
564 0 : " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"));
565 : //TODO: Do not write back information about those removed items that did not
566 : // come from the .xcs/.xcu files, anyway (but had been added dynamically
567 : // instead):
568 0 : for (Modifications::Node::Children::const_iterator j(
569 0 : data.modifications.getRoot().children.begin());
570 0 : j != data.modifications.getRoot().children.end(); ++j)
571 : {
572 : writeModifications(
573 0 : components, tmp.handle, "", rtl::Reference< Node >(), j->first,
574 0 : Data::findNode(Data::NO_LAYER, data.getComponents(), j->first),
575 0 : j->second);
576 : }
577 0 : writeData_(tmp.handle, RTL_CONSTASCII_STRINGPARAM("</oor:items>\n"));
578 0 : oslFileError e = osl_closeFile(tmp.handle);
579 0 : tmp.closed = true;
580 0 : if (e != osl_File_E_None) {
581 : throw css::uno::RuntimeException(
582 0 : "cannot close " + tmp.url,
583 0 : css::uno::Reference< css::uno::XInterface >());
584 : }
585 0 : if (osl::File::move(tmp.url, url) != osl::FileBase::E_None) {
586 : throw css::uno::RuntimeException(
587 0 : "cannot move " + tmp.url,
588 0 : css::uno::Reference< css::uno::XInterface >());
589 : }
590 0 : tmp.handle = 0;
591 : }
592 :
593 : }
594 :
595 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|