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 :
21 : #include "dp_help.hrc"
22 : #include "dp_backend.h"
23 : #include "dp_helpbackenddb.hxx"
24 : #include "dp_ucb.h"
25 : #include "rtl/uri.hxx"
26 : #include "osl/file.hxx"
27 : #include "rtl/bootstrap.hxx"
28 : #include "ucbhelper/content.hxx"
29 : #include "comphelper/servicedecl.hxx"
30 : #include "svl/inettype.hxx"
31 : #include "uno/current_context.hxx"
32 : #include "unotools/pathoptions.hxx"
33 :
34 : #if !defined(ANDROID) && !defined(IOS)
35 : #include <helpcompiler/compilehelp.hxx>
36 : #include <helpcompiler/HelpIndexer.hxx>
37 : #endif
38 : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
39 : #include <com/sun/star/util/XMacroExpander.hpp>
40 : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
41 : #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
42 : #include <com/sun/star/script/XInvocation.hpp>
43 : #include "boost/optional.hpp"
44 :
45 : using namespace ::dp_misc;
46 : using namespace ::com::sun::star;
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::ucb;
49 : using ::rtl::OUString;
50 :
51 : namespace dp_registry {
52 : namespace backend {
53 : namespace help {
54 : namespace {
55 :
56 : //==============================================================================
57 0 : 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 );
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 );
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< ::rtl::OUString > SAL_CALL getRegistrationDataURL()
87 : throw (deployment::ExtensionRemovedException, css::uno::RuntimeException);
88 : };
89 : friend class PackageImpl;
90 :
91 : // PackageRegistryBackend
92 : virtual Reference<deployment::XPackage> bindPackage_(
93 : OUString const & url, OUString const & mediaType,
94 : sal_Bool bRemoved, OUString const & identifier,
95 : Reference<XCommandEnvironment> const & xCmdEnv );
96 :
97 : void implProcessHelp( PackageImpl * package, bool doRegisterPackage,
98 : Reference<ucb::XCommandEnvironment> const & xCmdEnv);
99 : void implCollectXhpFiles( const rtl::OUString& aDir,
100 : std::vector< rtl::OUString >& o_rXhpFileVector );
101 :
102 : void addDataToDb(OUString const & url, HelpBackendDb::Data const & data);
103 : ::boost::optional<HelpBackendDb::Data> readDataFromDb(OUString const & url);
104 : bool hasActiveEntry(OUString const & url);
105 : void revokeEntryFromDb(OUString const & url);
106 : bool activateEntry(OUString const & url);
107 :
108 : Reference< ucb::XSimpleFileAccess3 > getFileAccess( void );
109 : Reference< ucb::XSimpleFileAccess3 > m_xSFA;
110 :
111 : const Reference<deployment::XPackageTypeInfo> m_xHelpTypeInfo;
112 : Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
113 : std::auto_ptr<HelpBackendDb> m_backendDb;
114 :
115 : public:
116 : BackendImpl( Sequence<Any> const & args,
117 : Reference<XComponentContext> const & xComponentContext );
118 :
119 : // XPackageRegistry
120 : virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
121 : getSupportedPackageTypes() throw (RuntimeException);
122 : virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
123 : throw (deployment::DeploymentException,
124 : uno::RuntimeException);
125 :
126 : };
127 :
128 : //______________________________________________________________________________
129 0 : BackendImpl::BackendImpl(
130 : Sequence<Any> const & args,
131 : Reference<XComponentContext> const & xComponentContext )
132 : : PackageRegistryBackend( args, xComponentContext ),
133 : m_xHelpTypeInfo( new Package::TypeInfo(
134 : OUSTR("application/vnd.sun.star.help"),
135 : rtl::OUString(),
136 : getResourceString(RID_STR_HELP),
137 0 : RID_IMG_HELP ) ),
138 0 : m_typeInfos( 1 )
139 : {
140 0 : m_typeInfos[ 0 ] = m_xHelpTypeInfo;
141 0 : if (!transientMode())
142 : {
143 0 : OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml"));
144 : m_backendDb.reset(
145 0 : 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 0 : ::std::list<OUString> folders = m_backendDb->getAllDataUrls();
153 0 : deleteUnusedFolders(OUString(), folders);
154 : }
155 0 : }
156 :
157 : // XPackageRegistry
158 : //______________________________________________________________________________
159 : Sequence< Reference<deployment::XPackageTypeInfo> >
160 0 : BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
161 : {
162 0 : return m_typeInfos;
163 : }
164 :
165 0 : void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
166 : throw (deployment::DeploymentException,
167 : uno::RuntimeException)
168 : {
169 0 : if (m_backendDb.get())
170 0 : m_backendDb->removeEntry(url);
171 0 : }
172 :
173 : // PackageRegistryBackend
174 : //______________________________________________________________________________
175 0 : Reference<deployment::XPackage> BackendImpl::bindPackage_(
176 : OUString const & url, OUString const & mediaType_,
177 : sal_Bool bRemoved, OUString const & identifier,
178 : Reference<XCommandEnvironment> const & xCmdEnv )
179 : {
180 : // we don't support auto detection:
181 0 : if (mediaType_.isEmpty())
182 : throw lang::IllegalArgumentException(
183 0 : StrCannotDetectMediaType::get() + url,
184 0 : 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.equalsIgnoreAsciiCaseAscii("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.equalsIgnoreAsciiCaseAscii( "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(
271 : OUSTR("Failed to get the BackendImpl"),
272 0 : static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
273 : }
274 0 : return pBackend;
275 : }
276 :
277 0 : bool BackendImpl::PackageImpl::extensionContainsCompiledHelp()
278 : {
279 0 : bool bCompiled = true;
280 0 : rtl::OUString aExpandedHelpURL = dp_misc::expandUnoRcUrl(getURL());
281 :
282 0 : ::osl::Directory helpFolder(aExpandedHelpURL);
283 0 : if ( helpFolder.open() == ::osl::File::E_None)
284 : {
285 : //iterate over the contents of the help folder
286 : //We assume that all folders withing the help folder contain language specific
287 : //help files. If just one of them does not contain compiled help then this
288 : //function returns false.
289 0 : ::osl::DirectoryItem item;
290 0 : ::osl::File::RC errorNext = ::osl::File::E_None;
291 0 : while ((errorNext = helpFolder.getNextItem(item)) == ::osl::File::E_None)
292 : {
293 : //No find the language folders
294 0 : ::osl::FileStatus stat(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |osl_FileStatus_Mask_FileURL);
295 0 : if (item.getFileStatus(stat) == ::osl::File::E_None)
296 : {
297 0 : if (stat.getFileType() != ::osl::FileStatus::Directory)
298 0 : continue;
299 :
300 : //look if there is the folder help.idxl in the language folder
301 0 : OUString compUrl(stat.getFileURL() + OUSTR("/help.idxl"));
302 0 : ::osl::Directory compiledFolder(compUrl);
303 0 : if (compiledFolder.open() != ::osl::File::E_None)
304 : {
305 0 : bCompiled = false;
306 : break;
307 0 : }
308 : }
309 : else
310 : {
311 : //Error
312 : OSL_ASSERT(0);
313 0 : bCompiled = false;
314 : break;
315 : }
316 0 : }
317 0 : if (errorNext != ::osl::File::E_NOENT
318 : && errorNext != ::osl::File::E_None)
319 : {
320 : //Error
321 : OSL_ASSERT(0);
322 0 : bCompiled = false;
323 0 : }
324 : }
325 0 : return bCompiled;
326 : }
327 :
328 : //______________________________________________________________________________
329 : beans::Optional< beans::Ambiguous<sal_Bool> >
330 0 : BackendImpl::PackageImpl::isRegistered_(
331 : ::osl::ResettableMutexGuard &,
332 : ::rtl::Reference<AbortChannel> const &,
333 : Reference<XCommandEnvironment> const & )
334 : {
335 0 : BackendImpl * that = getMyBackend();
336 :
337 0 : bool bReg = false;
338 0 : if (that->hasActiveEntry(getURL()))
339 0 : bReg = true;
340 :
341 0 : return beans::Optional< beans::Ambiguous<sal_Bool> >( true, beans::Ambiguous<sal_Bool>( bReg, false ) );
342 : }
343 :
344 : //______________________________________________________________________________
345 0 : void BackendImpl::PackageImpl::processPackage_(
346 : ::osl::ResettableMutexGuard &,
347 : bool doRegisterPackage,
348 : bool /* startup */,
349 : ::rtl::Reference<AbortChannel> const & abortChannel,
350 : Reference<XCommandEnvironment> const & xCmdEnv )
351 : {
352 : (void)doRegisterPackage;
353 : (void)abortChannel;
354 : (void)xCmdEnv;
355 :
356 0 : BackendImpl* that = getMyBackend();
357 0 : that->implProcessHelp( this, doRegisterPackage, xCmdEnv);
358 0 : }
359 :
360 0 : beans::Optional< OUString > BackendImpl::PackageImpl::getRegistrationDataURL()
361 : throw (deployment::ExtensionRemovedException,
362 : css::uno::RuntimeException)
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 !defined(ANDROID) && !defined(IOS)
392 0 : const OUString sHelpFolder = createFolder(OUString(), xCmdEnv);
393 0 : data.dataUrl = sHelpFolder;
394 :
395 0 : Reference< ucb::XSimpleFileAccess3 > xSFA = getFileAccess();
396 0 : rtl::OUString aHelpURL = xPackage->getURL();
397 0 : rtl::OUString aExpandedHelpURL = dp_misc::expandUnoRcUrl( aHelpURL );
398 0 : rtl::OUString aName = xPackage->getName();
399 0 : if( !xSFA->isFolder( aExpandedHelpURL ) )
400 : {
401 0 : rtl::OUString aErrStr = getResourceString( RID_STR_HELPPROCESSING_GENERAL_ERROR );
402 0 : aErrStr += rtl::OUString("No help folder" );
403 0 : OWeakObject* oWeakThis = static_cast<OWeakObject *>(this);
404 : throw deployment::DeploymentException( rtl::OUString(), oWeakThis,
405 0 : makeAny( uno::Exception( aErrStr, oWeakThis ) ) );
406 : }
407 :
408 : // Scan languages
409 0 : Sequence< rtl::OUString > aLanguageFolderSeq = xSFA->getFolderContents( aExpandedHelpURL, true );
410 0 : sal_Int32 nLangCount = aLanguageFolderSeq.getLength();
411 0 : const rtl::OUString* pSeq = aLanguageFolderSeq.getConstArray();
412 0 : for( sal_Int32 iLang = 0 ; iLang < nLangCount ; ++iLang )
413 : {
414 0 : rtl::OUString aLangURL = pSeq[iLang];
415 0 : if( xSFA->isFolder( aLangURL ) )
416 : {
417 0 : std::vector< rtl::OUString > aXhpFileVector;
418 :
419 : // calculate jar file URL
420 0 : sal_Int32 indexStartSegment = aLangURL.lastIndexOf('/');
421 : // for example "/en"
422 : OUString langFolderURLSegment(
423 : aLangURL.copy(
424 0 : indexStartSegment + 1, aLangURL.getLength() - indexStartSegment - 1));
425 :
426 : //create the folder in the "temporary folder"
427 0 : ::ucbhelper::Content langFolderContent;
428 0 : const OUString langFolderDest = makeURL(sHelpFolder, langFolderURLSegment);
429 0 : const OUString langFolderDestExpanded = ::dp_misc::expandUnoRcUrl(langFolderDest);
430 : ::dp_misc::create_folder(
431 : &langFolderContent,
432 0 : langFolderDest, xCmdEnv);
433 :
434 0 : const OUString aHelpStr("help");
435 0 : const OUString aSlash("/");
436 :
437 : rtl::OUString aJarFile(
438 0 : makeURL(sHelpFolder, langFolderURLSegment + aSlash + aHelpStr +
439 0 : OUSTR(".jar")));
440 0 : aJarFile = ::dp_misc::expandUnoRcUrl(aJarFile);
441 :
442 : rtl::OUString aEncodedJarFilePath = rtl::Uri::encode(
443 : aJarFile, rtl_UriCharClassPchar,
444 : rtl_UriEncodeIgnoreEscapes,
445 0 : RTL_TEXTENCODING_UTF8 );
446 0 : rtl::OUString aDestBasePath = rtl::OUString("vnd.sun.star.zip://" );
447 0 : aDestBasePath += aEncodedJarFilePath;
448 0 : aDestBasePath += rtl::OUString("/" );
449 :
450 0 : sal_Int32 nLenLangFolderURL = aLangURL.getLength() + 1;
451 :
452 0 : Sequence< rtl::OUString > aSubLangSeq = xSFA->getFolderContents( aLangURL, true );
453 0 : sal_Int32 nSubLangCount = aSubLangSeq.getLength();
454 0 : const rtl::OUString* pSubLangSeq = aSubLangSeq.getConstArray();
455 0 : for( sal_Int32 iSubLang = 0 ; iSubLang < nSubLangCount ; ++iSubLang )
456 : {
457 0 : rtl::OUString aSubFolderURL = pSubLangSeq[iSubLang];
458 0 : if( !xSFA->isFolder( aSubFolderURL ) )
459 0 : continue;
460 :
461 0 : implCollectXhpFiles( aSubFolderURL, aXhpFileVector );
462 :
463 : // Copy to package (later: move?)
464 0 : rtl::OUString aDestPath = aDestBasePath;
465 0 : rtl::OUString aPureFolderName = aSubFolderURL.copy( nLenLangFolderURL );
466 0 : aDestPath += aPureFolderName;
467 0 : xSFA->copy( aSubFolderURL, aDestPath );
468 0 : }
469 :
470 : // Call compiler
471 0 : sal_Int32 nXhpFileCount = aXhpFileVector.size();
472 0 : rtl::OUString* pXhpFiles = new rtl::OUString[nXhpFileCount];
473 0 : for( sal_Int32 iXhp = 0 ; iXhp < nXhpFileCount ; ++iXhp )
474 : {
475 0 : rtl::OUString aXhpFile = aXhpFileVector[iXhp];
476 0 : rtl::OUString aXhpRelFile = aXhpFile.copy( nLenLangFolderURL );
477 0 : pXhpFiles[iXhp] = aXhpRelFile;
478 0 : }
479 :
480 0 : rtl::OUString aOfficeHelpPath( SvtPathOptions().GetHelpPath() );
481 0 : rtl::OUString aOfficeHelpPathFileURL;
482 0 : ::osl::File::getFileURLFromSystemPath( aOfficeHelpPath, aOfficeHelpPathFileURL );
483 :
484 0 : HelpProcessingErrorInfo aErrorInfo;
485 : bool bSuccess = compileExtensionHelp(
486 : aOfficeHelpPathFileURL, aHelpStr, aLangURL,
487 : nXhpFileCount, pXhpFiles,
488 0 : langFolderDestExpanded, aErrorInfo );
489 :
490 0 : if( bSuccess )
491 : {
492 0 : rtl::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 = rtl::OUString("en" );
498 :
499 0 : rtl::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 : rtl::OUString aErrStr;
517 0 : if( nErrStrId != 0 )
518 : {
519 0 : aErrStr = getResourceString( nErrStrId );
520 :
521 : // Remoce CR/LF
522 0 : rtl::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 += rtl::OUString(" in " );
542 :
543 : rtl::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 += rtl::OUString(", line " );
549 0 : aErrStr += ::rtl::OUString::valueOf( aErrorInfo.m_nXMLParsingLine );
550 0 : }
551 0 : }
552 : }
553 :
554 0 : OWeakObject* oWeakThis = static_cast<OWeakObject *>(this);
555 : throw deployment::DeploymentException( rtl::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 rtl::OUString& aDir,
576 : std::vector< rtl::OUString >& o_rXhpFileVector )
577 : {
578 0 : Reference< ucb::XSimpleFileAccess3 > xSFA = getFileAccess();
579 :
580 : // Scan xhp files recursively
581 0 : Sequence< rtl::OUString > aSeq = xSFA->getFolderContents( aDir, true );
582 0 : sal_Int32 nCount = aSeq.getLength();
583 0 : const rtl::OUString* pSeq = aSeq.getConstArray();
584 0 : for( sal_Int32 i = 0 ; i < nCount ; ++i )
585 : {
586 0 : rtl::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 : rtl::OUString aExt = aURL.copy( nLastDot + 1 );
597 0 : if( aExt.equalsIgnoreAsciiCase( rtl::OUString("xhp" ) ) )
598 0 : o_rXhpFileVector.push_back( aURL );
599 : }
600 : }
601 0 : }
602 0 : }
603 :
604 0 : Reference< ucb::XSimpleFileAccess3 > BackendImpl::getFileAccess( void )
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 : ::rtl::OUString(
617 : "dp_registry::backend::help::BackendImpl::getFileAccess(), "
618 : "could not instatiate SimpleFileAccess." ),
619 0 : Reference< XInterface >() );
620 : }
621 : }
622 0 : return m_xSFA;
623 : }
624 :
625 : } // anon namespace
626 :
627 : namespace sdecl = comphelper::service_decl;
628 1 : sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
629 1 : extern sdecl::ServiceDecl const serviceDecl(
630 : serviceBI,
631 : "com.sun.star.comp.deployment.help.PackageRegistryBackend",
632 : BACKEND_SERVICE_NAME );
633 :
634 : } // namespace help
635 : } // namespace backend
636 3 : } // namespace dp_registry
637 :
638 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|