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 <config_features.h>
21 :
22 : #include "dp_help.hrc"
23 : #include "dp_backend.h"
24 : #include "dp_helpbackenddb.hxx"
25 : #include "dp_ucb.h"
26 : #include <rtl/uri.hxx>
27 : #include <osl/file.hxx>
28 : #include <rtl/bootstrap.hxx>
29 : #include <ucbhelper/content.hxx>
30 : #include <comphelper/servicedecl.hxx>
31 : #include <svl/inettype.hxx>
32 : #include <uno/current_context.hxx>
33 : #include <unotools/pathoptions.hxx>
34 :
35 : #if HAVE_FEATURE_DESKTOP
36 : #include <helpcompiler/compilehelp.hxx>
37 : #include <helpcompiler/HelpIndexer.hxx>
38 : #endif
39 : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
40 : #include <com/sun/star/util/XMacroExpander.hpp>
41 : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
42 : #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
43 : #include <com/sun/star/script/XInvocation.hpp>
44 : #include <boost/optional.hpp>
45 :
46 : using namespace ::dp_misc;
47 : using namespace ::com::sun::star;
48 : using namespace ::com::sun::star::uno;
49 : using namespace ::com::sun::star::ucb;
50 :
51 : namespace dp_registry {
52 : namespace backend {
53 : namespace help {
54 : namespace {
55 :
56 :
57 392 : class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
58 : {
59 0 : class PackageImpl : public ::dp_registry::backend::Package
60 : {
61 : BackendImpl * getMyBackend() const;
62 :
63 : // Package
64 : virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
65 : ::osl::ResettableMutexGuard & guard,
66 : ::rtl::Reference<AbortChannel> const & abortChannel,
67 : Reference<XCommandEnvironment> const & xCmdEnv ) SAL_OVERRIDE;
68 : virtual void processPackage_(
69 : ::osl::ResettableMutexGuard & guard,
70 : bool registerPackage,
71 : bool startup,
72 : ::rtl::Reference<AbortChannel> const & abortChannel,
73 : Reference<XCommandEnvironment> const & xCmdEnv ) SAL_OVERRIDE;
74 :
75 :
76 : public:
77 : PackageImpl(
78 : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
79 : OUString const & url, OUString const & name,
80 : Reference<deployment::XPackageTypeInfo> const & xPackageType,
81 : bool bRemoved, OUString const & identifier);
82 :
83 : bool extensionContainsCompiledHelp();
84 :
85 : //XPackage
86 : virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL()
87 : throw (deployment::DeploymentException, deployment::ExtensionRemovedException,
88 : css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 : };
90 : friend class PackageImpl;
91 :
92 : // PackageRegistryBackend
93 : virtual Reference<deployment::XPackage> bindPackage_(
94 : OUString const & url, OUString const & mediaType,
95 : bool bRemoved, OUString const & identifier,
96 : Reference<XCommandEnvironment> const & xCmdEnv ) SAL_OVERRIDE;
97 :
98 : void implProcessHelp( PackageImpl * package, bool doRegisterPackage,
99 : Reference<ucb::XCommandEnvironment> const & xCmdEnv);
100 : void implCollectXhpFiles( const OUString& aDir,
101 : std::vector< OUString >& o_rXhpFileVector );
102 :
103 : void addDataToDb(OUString const & url, HelpBackendDb::Data const & data);
104 : ::boost::optional<HelpBackendDb::Data> readDataFromDb(OUString const & url);
105 : bool hasActiveEntry(OUString const & url);
106 : void revokeEntryFromDb(OUString const & url);
107 : bool activateEntry(OUString const & url);
108 :
109 : Reference< ucb::XSimpleFileAccess3 > getFileAccess();
110 : Reference< ucb::XSimpleFileAccess3 > m_xSFA;
111 :
112 : const Reference<deployment::XPackageTypeInfo> m_xHelpTypeInfo;
113 : Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
114 : std::unique_ptr<HelpBackendDb> m_backendDb;
115 :
116 : public:
117 : BackendImpl( Sequence<Any> const & args,
118 : Reference<XComponentContext> const & xComponentContext );
119 :
120 : // XPackageRegistry
121 : virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
122 : getSupportedPackageTypes() throw (RuntimeException, std::exception) SAL_OVERRIDE;
123 : virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
124 : throw (deployment::DeploymentException,
125 : uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 :
127 : };
128 :
129 :
130 392 : BackendImpl::BackendImpl(
131 : Sequence<Any> const & args,
132 : Reference<XComponentContext> const & xComponentContext )
133 : : PackageRegistryBackend( args, xComponentContext ),
134 : m_xHelpTypeInfo( new Package::TypeInfo("application/vnd.sun.star.help",
135 : OUString(),
136 : getResourceString(RID_STR_HELP),
137 392 : RID_IMG_HELP ) ),
138 784 : m_typeInfos( 1 )
139 : {
140 392 : m_typeInfos[ 0 ] = m_xHelpTypeInfo;
141 392 : if (!transientMode())
142 : {
143 392 : OUString dbFile = makeURL(getCachePath(), "backenddb.xml");
144 : m_backendDb.reset(
145 392 : new HelpBackendDb(getComponentContext(), dbFile));
146 :
147 : //clean up data folders which are no longer used.
148 : //This must not be done in the same process where the help files
149 : //are still registers. Only after revoking and restarting OOo the folders
150 : //can be removed. This works now, because the extension manager is a singleton
151 : //and the backends are only create once per process.
152 784 : ::std::list<OUString> folders = m_backendDb->getAllDataUrls();
153 784 : deleteUnusedFolders(OUString(), folders);
154 : }
155 392 : }
156 :
157 : // XPackageRegistry
158 :
159 : Sequence< Reference<deployment::XPackageTypeInfo> >
160 392 : BackendImpl::getSupportedPackageTypes() throw (RuntimeException, std::exception)
161 : {
162 392 : return m_typeInfos;
163 : }
164 :
165 0 : void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
166 : throw (deployment::DeploymentException,
167 : uno::RuntimeException, std::exception)
168 : {
169 0 : if (m_backendDb.get())
170 0 : m_backendDb->removeEntry(url);
171 0 : }
172 :
173 : // PackageRegistryBackend
174 :
175 3 : Reference<deployment::XPackage> BackendImpl::bindPackage_(
176 : OUString const & url, OUString const & mediaType_,
177 : bool bRemoved, OUString const & identifier,
178 : Reference<XCommandEnvironment> const & xCmdEnv )
179 : {
180 : // we don't support auto detection:
181 3 : if (mediaType_.isEmpty())
182 : throw lang::IllegalArgumentException(
183 6 : StrCannotDetectMediaType::get() + url,
184 9 : static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
185 :
186 0 : OUString type, subType;
187 0 : INetContentTypeParameterList params;
188 0 : if (INetContentTypes::parse( mediaType_, type, subType, ¶ms ))
189 : {
190 0 : if (type.equalsIgnoreAsciiCase("application"))
191 : {
192 0 : OUString name;
193 0 : if (!bRemoved)
194 : {
195 : ::ucbhelper::Content ucbContent(
196 0 : url, xCmdEnv, getComponentContext() );
197 0 : name = StrTitle::getTitle( ucbContent );
198 : }
199 :
200 0 : if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.help"))
201 : {
202 : return new PackageImpl(
203 : this, url, name, m_xHelpTypeInfo, bRemoved,
204 0 : identifier);
205 0 : }
206 : }
207 : }
208 : throw lang::IllegalArgumentException(
209 0 : StrUnsupportedMediaType::get() + mediaType_,
210 : static_cast<OWeakObject *>(this),
211 0 : static_cast<sal_Int16>(-1) );
212 : }
213 :
214 0 : void BackendImpl::addDataToDb(
215 : OUString const & url, HelpBackendDb::Data const & data)
216 : {
217 0 : if (m_backendDb.get())
218 0 : m_backendDb->addEntry(url, data);
219 0 : }
220 :
221 0 : ::boost::optional<HelpBackendDb::Data> BackendImpl::readDataFromDb(
222 : OUString const & url)
223 : {
224 0 : ::boost::optional<HelpBackendDb::Data> data;
225 0 : if (m_backendDb.get())
226 0 : data = m_backendDb->getEntry(url);
227 0 : return data;
228 : }
229 :
230 0 : bool BackendImpl::hasActiveEntry(OUString const & url)
231 : {
232 0 : if (m_backendDb.get())
233 0 : return m_backendDb->hasActiveEntry(url);
234 0 : return false;
235 : }
236 :
237 0 : void BackendImpl::revokeEntryFromDb(OUString const & url)
238 : {
239 0 : if (m_backendDb.get())
240 0 : m_backendDb->revokeEntry(url);
241 0 : }
242 :
243 0 : bool BackendImpl::activateEntry(OUString const & url)
244 : {
245 0 : if (m_backendDb.get())
246 0 : return m_backendDb->activateEntry(url);
247 0 : return false;
248 : }
249 :
250 :
251 0 : BackendImpl::PackageImpl::PackageImpl(
252 : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
253 : OUString const & url, OUString const & name,
254 : Reference<deployment::XPackageTypeInfo> const & xPackageType,
255 : bool bRemoved, OUString const & identifier)
256 : : Package( myBackend, url, name, name, xPackageType, bRemoved,
257 0 : identifier)
258 : {
259 0 : }
260 :
261 : // Package
262 0 : BackendImpl * BackendImpl::PackageImpl::getMyBackend() const
263 : {
264 0 : BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
265 0 : if (NULL == pBackend)
266 : {
267 : //May throw a DisposedException
268 0 : check();
269 : //We should never get here...
270 : throw RuntimeException("Failed to get the BackendImpl",
271 0 : static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
272 : }
273 0 : return pBackend;
274 : }
275 :
276 0 : bool BackendImpl::PackageImpl::extensionContainsCompiledHelp()
277 : {
278 0 : bool bCompiled = true;
279 0 : OUString aExpandedHelpURL = dp_misc::expandUnoRcUrl(getURL());
280 :
281 0 : ::osl::Directory helpFolder(aExpandedHelpURL);
282 0 : if ( helpFolder.open() == ::osl::File::E_None)
283 : {
284 : //iterate over the contents of the help folder
285 : //We assume that all folders within the help folder contain language specific
286 : //help files. If just one of them does not contain compiled help then this
287 : //function returns false.
288 0 : ::osl::DirectoryItem item;
289 0 : ::osl::File::RC errorNext = ::osl::File::E_None;
290 0 : while ((errorNext = helpFolder.getNextItem(item)) == ::osl::File::E_None)
291 : {
292 : //No find the language folders
293 0 : ::osl::FileStatus stat(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |osl_FileStatus_Mask_FileURL);
294 0 : if (item.getFileStatus(stat) == ::osl::File::E_None)
295 : {
296 0 : if (stat.getFileType() != ::osl::FileStatus::Directory)
297 0 : continue;
298 :
299 : //look if there is the folder help.idxl in the language folder
300 0 : OUString compUrl(stat.getFileURL() + "/help.idxl");
301 0 : ::osl::Directory compiledFolder(compUrl);
302 0 : if (compiledFolder.open() != ::osl::File::E_None)
303 : {
304 0 : bCompiled = false;
305 0 : break;
306 0 : }
307 : }
308 : else
309 : {
310 : //Error
311 : OSL_ASSERT(false);
312 0 : bCompiled = false;
313 0 : break;
314 : }
315 0 : }
316 0 : if (errorNext != ::osl::File::E_NOENT
317 0 : && errorNext != ::osl::File::E_None)
318 : {
319 : //Error
320 : OSL_ASSERT(false);
321 0 : bCompiled = false;
322 0 : }
323 : }
324 0 : return bCompiled;
325 : }
326 :
327 :
328 : beans::Optional< beans::Ambiguous<sal_Bool> >
329 0 : BackendImpl::PackageImpl::isRegistered_(
330 : ::osl::ResettableMutexGuard &,
331 : ::rtl::Reference<AbortChannel> const &,
332 : Reference<XCommandEnvironment> const & )
333 : {
334 0 : BackendImpl * that = getMyBackend();
335 :
336 0 : bool bReg = false;
337 0 : if (that->hasActiveEntry(getURL()))
338 0 : bReg = true;
339 :
340 0 : return beans::Optional< beans::Ambiguous<sal_Bool> >( true, beans::Ambiguous<sal_Bool>( bReg, false ) );
341 : }
342 :
343 :
344 0 : void BackendImpl::PackageImpl::processPackage_(
345 : ::osl::ResettableMutexGuard &,
346 : bool doRegisterPackage,
347 : bool /* startup */,
348 : ::rtl::Reference<AbortChannel> const & abortChannel,
349 : Reference<XCommandEnvironment> const & xCmdEnv )
350 : {
351 : (void)doRegisterPackage;
352 : (void)abortChannel;
353 : (void)xCmdEnv;
354 :
355 0 : BackendImpl* that = getMyBackend();
356 0 : that->implProcessHelp( this, doRegisterPackage, xCmdEnv);
357 0 : }
358 :
359 0 : beans::Optional< OUString > BackendImpl::PackageImpl::getRegistrationDataURL()
360 : throw (deployment::DeploymentException,
361 : deployment::ExtensionRemovedException,
362 : css::uno::RuntimeException, std::exception)
363 : {
364 0 : if (m_bRemoved)
365 0 : throw deployment::ExtensionRemovedException();
366 :
367 : ::boost::optional<HelpBackendDb::Data> data =
368 0 : getMyBackend()->readDataFromDb(getURL());
369 :
370 0 : if (data && getMyBackend()->hasActiveEntry(getURL()))
371 0 : return beans::Optional<OUString>(true, data->dataUrl);
372 :
373 0 : return beans::Optional<OUString>(true, OUString());
374 : }
375 :
376 0 : void BackendImpl::implProcessHelp(
377 : PackageImpl * package, bool doRegisterPackage,
378 : Reference<ucb::XCommandEnvironment> const & xCmdEnv)
379 : {
380 0 : Reference< deployment::XPackage > xPackage(package);
381 : OSL_ASSERT(xPackage.is());
382 0 : if (doRegisterPackage)
383 : {
384 : //revive already processed help if possible
385 0 : if ( !activateEntry(xPackage->getURL()))
386 : {
387 0 : HelpBackendDb::Data data;
388 0 : data.dataUrl = xPackage->getURL();
389 0 : if (!package->extensionContainsCompiledHelp())
390 : {
391 : #if HAVE_FEATURE_DESKTOP
392 0 : const OUString sHelpFolder = createFolder(OUString(), xCmdEnv);
393 0 : data.dataUrl = sHelpFolder;
394 :
395 0 : Reference< ucb::XSimpleFileAccess3 > xSFA = getFileAccess();
396 0 : OUString aHelpURL = xPackage->getURL();
397 0 : OUString aExpandedHelpURL = dp_misc::expandUnoRcUrl( aHelpURL );
398 0 : if( !xSFA->isFolder( aExpandedHelpURL ) )
399 : {
400 0 : OUString aErrStr = getResourceString( RID_STR_HELPPROCESSING_GENERAL_ERROR );
401 0 : aErrStr += "No help folder";
402 0 : OWeakObject* oWeakThis = static_cast<OWeakObject *>(this);
403 : throw deployment::DeploymentException( OUString(), oWeakThis,
404 0 : makeAny( uno::Exception( aErrStr, oWeakThis ) ) );
405 : }
406 :
407 : // Scan languages
408 0 : Sequence< OUString > aLanguageFolderSeq = xSFA->getFolderContents( aExpandedHelpURL, true );
409 0 : sal_Int32 nLangCount = aLanguageFolderSeq.getLength();
410 0 : const OUString* pSeq = aLanguageFolderSeq.getConstArray();
411 0 : for( sal_Int32 iLang = 0 ; iLang < nLangCount ; ++iLang )
412 : {
413 0 : OUString aLangURL = pSeq[iLang];
414 0 : if( xSFA->isFolder( aLangURL ) )
415 : {
416 0 : std::vector< OUString > aXhpFileVector;
417 :
418 : // calculate jar file URL
419 0 : sal_Int32 indexStartSegment = aLangURL.lastIndexOf('/');
420 : // for example "/en"
421 : OUString langFolderURLSegment(
422 : aLangURL.copy(
423 0 : indexStartSegment + 1, aLangURL.getLength() - indexStartSegment - 1));
424 :
425 : //create the folder in the "temporary folder"
426 0 : ::ucbhelper::Content langFolderContent;
427 0 : const OUString langFolderDest = makeURL(sHelpFolder, langFolderURLSegment);
428 0 : const OUString langFolderDestExpanded = ::dp_misc::expandUnoRcUrl(langFolderDest);
429 : ::dp_misc::create_folder(
430 : &langFolderContent,
431 0 : langFolderDest, xCmdEnv);
432 :
433 0 : const OUString aHelpStr("help");
434 0 : const OUString aSlash("/");
435 :
436 : OUString aJarFile(
437 0 : makeURL(sHelpFolder, langFolderURLSegment + aSlash + aHelpStr + ".jar"));
438 0 : aJarFile = ::dp_misc::expandUnoRcUrl(aJarFile);
439 :
440 : OUString aEncodedJarFilePath = rtl::Uri::encode(
441 : aJarFile, rtl_UriCharClassPchar,
442 : rtl_UriEncodeIgnoreEscapes,
443 0 : RTL_TEXTENCODING_UTF8 );
444 0 : OUString aDestBasePath = "vnd.sun.star.zip://";
445 0 : aDestBasePath += aEncodedJarFilePath;
446 0 : aDestBasePath += "/" ;
447 :
448 0 : sal_Int32 nLenLangFolderURL = aLangURL.getLength() + 1;
449 :
450 0 : Sequence< OUString > aSubLangSeq = xSFA->getFolderContents( aLangURL, true );
451 0 : sal_Int32 nSubLangCount = aSubLangSeq.getLength();
452 0 : const OUString* pSubLangSeq = aSubLangSeq.getConstArray();
453 0 : for( sal_Int32 iSubLang = 0 ; iSubLang < nSubLangCount ; ++iSubLang )
454 : {
455 0 : OUString aSubFolderURL = pSubLangSeq[iSubLang];
456 0 : if( !xSFA->isFolder( aSubFolderURL ) )
457 0 : continue;
458 :
459 0 : implCollectXhpFiles( aSubFolderURL, aXhpFileVector );
460 :
461 : // Copy to package (later: move?)
462 0 : OUString aDestPath = aDestBasePath;
463 0 : OUString aPureFolderName = aSubFolderURL.copy( nLenLangFolderURL );
464 0 : aDestPath += aPureFolderName;
465 0 : xSFA->copy( aSubFolderURL, aDestPath );
466 0 : }
467 :
468 : // Call compiler
469 0 : sal_Int32 nXhpFileCount = aXhpFileVector.size();
470 0 : OUString* pXhpFiles = new OUString[nXhpFileCount];
471 0 : for( sal_Int32 iXhp = 0 ; iXhp < nXhpFileCount ; ++iXhp )
472 : {
473 0 : OUString aXhpFile = aXhpFileVector[iXhp];
474 0 : OUString aXhpRelFile = aXhpFile.copy( nLenLangFolderURL );
475 0 : pXhpFiles[iXhp] = aXhpRelFile;
476 0 : }
477 :
478 0 : OUString aOfficeHelpPath( SvtPathOptions().GetHelpPath() );
479 0 : OUString aOfficeHelpPathFileURL;
480 0 : ::osl::File::getFileURLFromSystemPath( aOfficeHelpPath, aOfficeHelpPathFileURL );
481 :
482 0 : HelpProcessingErrorInfo aErrorInfo;
483 : bool bSuccess = compileExtensionHelp(
484 : aOfficeHelpPathFileURL, aHelpStr, aLangURL,
485 : nXhpFileCount, pXhpFiles,
486 0 : langFolderDestExpanded, aErrorInfo );
487 :
488 0 : delete[] pXhpFiles;
489 :
490 0 : if( bSuccess )
491 : {
492 0 : OUString aLang;
493 0 : sal_Int32 nLastSlash = aLangURL.lastIndexOf( '/' );
494 0 : if( nLastSlash != -1 )
495 0 : aLang = aLangURL.copy( nLastSlash + 1 );
496 : else
497 0 : aLang = "en";
498 :
499 0 : OUString aMod("help");
500 :
501 0 : HelpIndexer aIndexer(aLang, aMod, langFolderDestExpanded, langFolderDestExpanded);
502 0 : aIndexer.indexDocuments();
503 : }
504 :
505 0 : if( !bSuccess )
506 : {
507 0 : sal_uInt16 nErrStrId = 0;
508 0 : switch( aErrorInfo.m_eErrorClass )
509 : {
510 : case HELPPROCESSING_GENERAL_ERROR:
511 0 : case HELPPROCESSING_INTERNAL_ERROR: nErrStrId = RID_STR_HELPPROCESSING_GENERAL_ERROR; break;
512 0 : case HELPPROCESSING_XMLPARSING_ERROR: nErrStrId = RID_STR_HELPPROCESSING_XMLPARSING_ERROR; break;
513 : default: ;
514 : };
515 :
516 0 : OUString aErrStr;
517 0 : if( nErrStrId != 0 )
518 : {
519 0 : aErrStr = getResourceString( nErrStrId );
520 :
521 : // Remoce CR/LF
522 0 : OUString aErrMsg( aErrorInfo.m_aErrorMsg );
523 0 : sal_Unicode nCR = 13, nLF = 10;
524 0 : sal_Int32 nSearchCR = aErrMsg.indexOf( nCR );
525 0 : sal_Int32 nSearchLF = aErrMsg.indexOf( nLF );
526 : sal_Int32 nCopy;
527 0 : if( nSearchCR != -1 || nSearchLF != -1 )
528 : {
529 0 : if( nSearchCR == -1 )
530 0 : nCopy = nSearchLF;
531 0 : else if( nSearchLF == -1 )
532 0 : nCopy = nSearchCR;
533 : else
534 0 : nCopy = ( nSearchCR < nSearchLF ) ? nSearchCR : nSearchLF;
535 :
536 0 : aErrMsg = aErrMsg.copy( 0, nCopy );
537 : }
538 0 : aErrStr += aErrMsg;
539 0 : if( nErrStrId == RID_STR_HELPPROCESSING_XMLPARSING_ERROR && !aErrorInfo.m_aXMLParsingFile.isEmpty() )
540 : {
541 0 : aErrStr += " in ";
542 :
543 : OUString aDecodedFile = rtl::Uri::decode( aErrorInfo.m_aXMLParsingFile,
544 0 : rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
545 0 : aErrStr += aDecodedFile;
546 0 : if( aErrorInfo.m_nXMLParsingLine != -1 )
547 : {
548 0 : aErrStr += ", line ";
549 0 : aErrStr += OUString::number( aErrorInfo.m_nXMLParsingLine );
550 0 : }
551 0 : }
552 : }
553 :
554 0 : OWeakObject* oWeakThis = static_cast<OWeakObject *>(this);
555 : throw deployment::DeploymentException( OUString(), oWeakThis,
556 0 : makeAny( uno::Exception( aErrStr, oWeakThis ) ) );
557 0 : }
558 : }
559 0 : }
560 : #else
561 : (void) xCmdEnv;
562 : #endif
563 : }
564 : //Writing the data entry replaces writing the flag file. If we got to this
565 : //point the registration was successful.
566 0 : addDataToDb(xPackage->getURL(), data);
567 : }
568 : } //if (doRegisterPackage)
569 : else
570 : {
571 0 : revokeEntryFromDb(xPackage->getURL());
572 0 : }
573 0 : }
574 :
575 0 : void BackendImpl::implCollectXhpFiles( const OUString& aDir,
576 : std::vector< OUString >& o_rXhpFileVector )
577 : {
578 0 : Reference< ucb::XSimpleFileAccess3 > xSFA = getFileAccess();
579 :
580 : // Scan xhp files recursively
581 0 : Sequence< OUString > aSeq = xSFA->getFolderContents( aDir, true );
582 0 : sal_Int32 nCount = aSeq.getLength();
583 0 : const OUString* pSeq = aSeq.getConstArray();
584 0 : for( sal_Int32 i = 0 ; i < nCount ; ++i )
585 : {
586 0 : OUString aURL = pSeq[i];
587 0 : if( xSFA->isFolder( aURL ) )
588 : {
589 0 : implCollectXhpFiles( aURL, o_rXhpFileVector );
590 : }
591 : else
592 : {
593 0 : sal_Int32 nLastDot = aURL.lastIndexOf( '.' );
594 0 : if( nLastDot != -1 )
595 : {
596 0 : OUString aExt = aURL.copy( nLastDot + 1 );
597 0 : if( aExt.equalsIgnoreAsciiCase( "xhp" ) )
598 0 : o_rXhpFileVector.push_back( aURL );
599 : }
600 : }
601 0 : }
602 0 : }
603 :
604 0 : Reference< ucb::XSimpleFileAccess3 > BackendImpl::getFileAccess()
605 : {
606 0 : if( !m_xSFA.is() )
607 : {
608 0 : Reference<XComponentContext> const & xContext = getComponentContext();
609 0 : if( xContext.is() )
610 : {
611 0 : m_xSFA = ucb::SimpleFileAccess::create(xContext);
612 : }
613 0 : if( !m_xSFA.is() )
614 : {
615 : throw RuntimeException(
616 : "dp_registry::backend::help::BackendImpl::getFileAccess(), "
617 0 : "could not instatiate SimpleFileAccess." );
618 : }
619 : }
620 0 : return m_xSFA;
621 : }
622 :
623 : } // anon namespace
624 :
625 : namespace sdecl = comphelper::service_decl;
626 111 : sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
627 111 : extern sdecl::ServiceDecl const serviceDecl(
628 : serviceBI,
629 : "com.sun.star.comp.deployment.help.PackageRegistryBackend",
630 : BACKEND_SERVICE_NAME );
631 :
632 : } // namespace help
633 : } // namespace backend
634 333 : } // namespace dp_registry
635 :
636 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|