PageRenderTime 88ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/libreoffice-3.6.0.2/cpputools/source/registercomponent/registercomponent.cxx

#
C++ | 848 lines | 748 code | 63 blank | 37 comment | 117 complexity | 93859222ef121f38be012984a62cc0f7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, LGPL-3.0
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2000, 2010 Oracle and/or its affiliates.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <vector>
  32. #include "sal/main.h"
  33. #include <rtl/strbuf.hxx>
  34. #include <rtl/ustrbuf.hxx>
  35. #include <cppuhelper/servicefactory.hxx>
  36. #include <cppuhelper/shlib.hxx>
  37. #include <com/sun/star/container/XSet.hpp>
  38. #include <com/sun/star/container/XContentEnumerationAccess.hpp>
  39. #include <com/sun/star/registry/XImplementationRegistration2.hpp>
  40. #include <com/sun/star/registry/XSimpleRegistry.hpp>
  41. #include <com/sun/star/lang/XComponent.hpp>
  42. #include <algorithm>
  43. #include <osl/process.h>
  44. #include <osl/diagnose.h>
  45. #include <osl/thread.h>
  46. #include <osl/file.hxx>
  47. #ifdef SAL_UNX
  48. #define SEPARATOR '/'
  49. #else
  50. #define SEPARATOR '\\'
  51. #endif
  52. using namespace ::rtl;
  53. using namespace ::osl;
  54. using namespace ::cppu;
  55. using namespace ::std;
  56. using namespace ::com::sun::star::uno;
  57. using namespace ::com::sun::star::lang;
  58. using namespace ::com::sun::star::registry;
  59. using com::sun::star::container::XSet;
  60. using com::sun::star::container::XContentEnumerationAccess;
  61. using com::sun::star::container::XEnumeration;
  62. namespace {
  63. OUString replacePrefix(OUString const & url, OUString const & prefix) {
  64. sal_Int32 i = url.lastIndexOf('/');
  65. // Backward compatibility with stoc/source/implementationregistration/
  66. // implreg.cxx:1.27 l. 1892:
  67. if (i == -1) {
  68. i = url.lastIndexOf('\\');
  69. }
  70. return prefix + url.copy(i + 1);
  71. }
  72. }
  73. sal_Bool isFileUrl(const OUString& fileName)
  74. {
  75. if (fileName.indexOf(OUString(RTL_CONSTASCII_USTRINGPARAM("file://"))) == 0 )
  76. return sal_True;
  77. return sal_False;
  78. }
  79. OUString convertToFileUrl(const OUString& fileName)
  80. {
  81. if ( isFileUrl(fileName) )
  82. {
  83. return fileName;
  84. }
  85. OUString uUrlFileName;
  86. if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
  87. {
  88. OUString uWorkingDir;
  89. if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None) {
  90. OSL_ASSERT(false);
  91. }
  92. if (FileBase::getAbsoluteFileURL(uWorkingDir, fileName, uUrlFileName)
  93. != FileBase::E_None)
  94. {
  95. OSL_ASSERT(false);
  96. }
  97. } else
  98. {
  99. if (FileBase::getFileURLFromSystemPath(fileName, uUrlFileName)
  100. != FileBase::E_None)
  101. {
  102. OSL_ASSERT(false);
  103. }
  104. }
  105. return uUrlFileName;
  106. }
  107. static void usingRegisterImpl()
  108. {
  109. fprintf(stderr, "usage: regcomp -register|revoke -r registryfile -c locationUrl [-br registryfile] [-l componentLoaderUrl] [-s] [-classpath path]\n");
  110. fprintf(stderr, " Parameters:\n");
  111. fprintf(stderr, " -register\n"
  112. " register a new component.\n");
  113. fprintf(stderr, " -revoke\n"
  114. " revoke a component.\n");
  115. fprintf(stderr, " -br registryfile\n"
  116. " the name of the registry used for bootstrapping\n"
  117. " regcomp. The option can be given twice, each\n"
  118. " one followed by exactly one registry file.\n"
  119. " The registries are used to access both types and\n"
  120. " registered components.\n");
  121. fprintf(stderr, " -r registryfile\n"
  122. " the name of the target registry (will be created\n"
  123. " if it does not exists). The file name may match\n"
  124. " with one of the filenames given with the -br option.\n");
  125. fprintf(stderr, " -c locationUrls\n"
  126. " the location of a component (a url to a shared\n"
  127. " library or a absolute url to a .jar file) or a\n"
  128. " list of urls seperated by ';' or ' '. Note if a\n"
  129. " list of urls is specified, the components must\n"
  130. " all need the same loader (quoting is possible with\n"
  131. " \\ or \"\").\n");
  132. fprintf(stderr, " -l componentLoaderUrl\n"
  133. " the name of the needed loader. If no loader is\n"
  134. " specified and the components have a .jar suffix,\n"
  135. " the default is com.sun.star.loader.Java2.\n"
  136. " Otherwise, the default is\n"
  137. " com.sun.star.loader.SharedLibrary\n"
  138. " -s\n"
  139. " silent, regcomp prints messages only on error.\n"
  140. " -wop\n"
  141. " register the component name only without path\n"
  142. " -wop=prefix\n"
  143. " register the component name with path replaced\n"
  144. " by given prefix\n"
  145. " -classpath path\n"
  146. " sets the java classpath to path (overwriting the\n"
  147. " current classpath environment variable). Note that\n"
  148. " in case you start regcomp e.g. within an office\n"
  149. " environment, the classpath entries in the\n"
  150. " configuration still have precedence over this\n"
  151. " option.\n");
  152. }
  153. class IllegalArgument
  154. {
  155. public:
  156. IllegalArgument(const OString& rMessage)
  157. : m_message(rMessage)
  158. {}
  159. OString m_message;
  160. };
  161. struct Options
  162. {
  163. Options()
  164. : bRegister(sal_False)
  165. , bRevoke(sal_False)
  166. , bSilent( sal_False )
  167. , bPrefix( sal_False )
  168. {}
  169. sal_Bool bRegister;
  170. sal_Bool bRevoke;
  171. sal_Bool bSilent;
  172. sal_Bool bPrefix;
  173. OUString sPrefix;
  174. OUString sProgramName;
  175. OUString sBootRegName;
  176. OUString sBootRegName2;
  177. OUString sRegName;
  178. OUString sComponentUrls;
  179. OUString sLoaderName;
  180. };
  181. sal_Bool parseOptions(int ac, char* av[], Options& rOptions, sal_Bool bCmdFile)
  182. throw( IllegalArgument )
  183. {
  184. sal_Bool ret = sal_True;
  185. sal_uInt16 i=0;
  186. sal_Bool bLoaderExplicitlyGiven = sal_False;
  187. rOptions.sProgramName = OUString::createFromAscii(av[i++]);
  188. if (!bCmdFile)
  189. {
  190. bCmdFile = sal_True;
  191. if (ac < 2)
  192. {
  193. usingRegisterImpl();
  194. ret = sal_False;
  195. }
  196. }
  197. for (; i < ac; i++)
  198. {
  199. if (av[i][0] == '-')
  200. {
  201. switch (av[i][1])
  202. {
  203. case 'r':
  204. if (strcmp(av[i], "-register") == 0)
  205. {
  206. rOptions.bRegister = sal_True;
  207. } else
  208. if (strcmp(av[i], "-revoke") == 0)
  209. {
  210. rOptions.bRevoke = sal_True;
  211. } else
  212. if (av[i][2] == '\0')
  213. {
  214. if (i < ac - 1 && av[i+1][0] != '-')
  215. {
  216. i++;
  217. rOptions.sRegName = OStringToOUString(av[i], osl_getThreadTextEncoding());
  218. } else
  219. {
  220. OString tmp("'-r', please check");
  221. if (i <= ac - 1)
  222. {
  223. tmp += " your input '" + OString(av[i+1]) + "'";
  224. }
  225. throw IllegalArgument(tmp);
  226. }
  227. } else
  228. {
  229. rOptions.sRegName = OStringToOUString(av[i]+2, osl_getThreadTextEncoding());
  230. }
  231. break;
  232. case 'b':
  233. if (av[i][2] != 'r')
  234. {
  235. OString tmp("'-b', invalid option!");
  236. throw IllegalArgument(tmp);
  237. }
  238. if (av[i][3] == '\0')
  239. {
  240. if (i < ac - 1 && av[i+1][0] != '-')
  241. {
  242. i++;
  243. OUString regName = OStringToOUString(av[i], osl_getThreadTextEncoding());
  244. if( rOptions.sBootRegName.isEmpty() )
  245. {
  246. rOptions.sBootRegName = regName;
  247. }
  248. else
  249. {
  250. rOptions.sBootRegName2 = regName;
  251. }
  252. } else
  253. {
  254. OString tmp("'-br', please check");
  255. if (i <= ac - 1)
  256. {
  257. tmp += " your input '" + OString(av[i+1]) + "'";
  258. }
  259. throw IllegalArgument(tmp);
  260. }
  261. } else
  262. {
  263. rOptions.sBootRegName = OStringToOUString(av[i]+3, osl_getThreadTextEncoding());
  264. }
  265. break;
  266. case 'c':
  267. {
  268. OUString sUrls;
  269. if (av[i][2] == '\0')
  270. {
  271. if (i < ac - 1 && av[i+1][0] != '-')
  272. {
  273. i++;
  274. sUrls = OStringToOUString(av[i], osl_getThreadTextEncoding());
  275. } else
  276. {
  277. OString tmp("'-c', please check");
  278. if (i <= ac - 1)
  279. {
  280. tmp += " your input '" + OString(av[i+1]) + "'";
  281. }
  282. throw IllegalArgument(tmp);
  283. }
  284. }
  285. else if( 0 == strncmp( av[i] , "-classpath" ,10 ) )
  286. {
  287. i++;
  288. if( i < ac )
  289. {
  290. rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("CLASSPATH"));
  291. rtl::OUString envValue(av[i], strlen(av[i]), osl_getThreadTextEncoding());
  292. osl_setEnvironment(envVar.pData, envValue.pData);
  293. }
  294. break;
  295. }
  296. else
  297. {
  298. sUrls = OStringToOUString(av[i]+2, osl_getThreadTextEncoding());
  299. }
  300. if (!rOptions.sComponentUrls.isEmpty())
  301. {
  302. OUString tmp(rOptions.sComponentUrls + OUString(";", 1, osl_getThreadTextEncoding()) + sUrls);
  303. rOptions.sComponentUrls = tmp;
  304. } else
  305. {
  306. rOptions.sComponentUrls = sUrls;
  307. }
  308. break;
  309. }
  310. case 'l':
  311. {
  312. if (av[i][2] == '\0')
  313. {
  314. if (i < ac - 1 && av[i+1][0] != '-')
  315. {
  316. i++;
  317. rOptions.sLoaderName = OUString::createFromAscii(av[i]);
  318. bLoaderExplicitlyGiven = sal_True;
  319. } else
  320. {
  321. OString tmp("'-l', please check");
  322. if (i <= ac - 1)
  323. {
  324. tmp += " your input '" + OString(av[i+1]) + "'";
  325. }
  326. throw IllegalArgument(tmp);
  327. }
  328. } else
  329. {
  330. bLoaderExplicitlyGiven = sal_True;
  331. rOptions.sLoaderName = OUString::createFromAscii(av[i]+2);
  332. }
  333. break;
  334. }
  335. case 's':
  336. {
  337. if( av[i][2] == 0 )
  338. {
  339. rOptions.bSilent = sal_True;
  340. }
  341. else
  342. {
  343. rtl::OStringBuffer buf;
  344. buf.append( "Unknown error " );
  345. buf.append( av[i] );
  346. throw IllegalArgument( av[i] );
  347. }
  348. break;
  349. }
  350. case 'e':
  351. {
  352. if( av[i][2] == 'n' && av[i][3] == 'v' && av[i][4] == ':' )
  353. {
  354. // bootstrap variable, ignore it
  355. break;
  356. }
  357. }
  358. case 'w':
  359. {
  360. if (strcmp(av[i], "-wop") == 0)
  361. {
  362. rOptions.bPrefix = sal_True;
  363. rOptions.sPrefix = OUString();
  364. // in case there are multiple -wops
  365. break;
  366. }
  367. else if (
  368. strncmp(av[i], "-wop=", RTL_CONSTASCII_LENGTH("-wop="))
  369. == 0)
  370. {
  371. rOptions.bPrefix = sal_True;
  372. rOptions.sPrefix = OStringToOUString(
  373. av[i] + RTL_CONSTASCII_LENGTH("-wop="),
  374. osl_getThreadTextEncoding());
  375. break;
  376. }
  377. }
  378. default:
  379. {
  380. OString tmp( "unknown option " );
  381. tmp += av[i];
  382. throw IllegalArgument( tmp );
  383. }
  384. }
  385. } else
  386. {
  387. if (av[i][0] == '@')
  388. {
  389. FILE* cmdFile = fopen(av[i]+1, "r");
  390. if( cmdFile == NULL )
  391. {
  392. usingRegisterImpl();
  393. ret = sal_False;
  394. } else
  395. {
  396. fseek( cmdFile , 0 , SEEK_END );
  397. sal_Int32 nLen = ftell( cmdFile);
  398. fseek( cmdFile, 0, SEEK_SET );
  399. // 2 chars per string is a upper limit for the number of
  400. // substrings ( at least one separator char needed for fscanf).
  401. char ** rargv = (char **)rtl_allocateMemory( nLen * sizeof( char* ) /2);
  402. if( ! rargv )
  403. {
  404. OStringBuffer buf;
  405. buf.append( "Not enough memory for reading command file " );
  406. buf.append( av[i] +1 );
  407. buf.append( " with length " );
  408. buf.append( nLen );
  409. buf.append( "." );
  410. throw IllegalArgument( buf.makeStringAndClear() );
  411. }
  412. char *buffer = ( char * )rtl_allocateMemory( nLen +1 );
  413. if( ! buffer )
  414. {
  415. OStringBuffer buf;
  416. buf.append( "Not enough memory for reading command file " );
  417. buf.append( av[i] +1 );
  418. buf.append( " with length " );
  419. buf.append( nLen );
  420. buf.append( "." );
  421. throw IllegalArgument( buf.makeStringAndClear() );
  422. }
  423. // we start at one to omit argv[0]
  424. sal_Int32 rargc = 1;
  425. rargv[0] = av[0];
  426. while ( fscanf(cmdFile, "%s", buffer) != EOF )
  427. {
  428. rargv[rargc]= (char * )rtl_allocateMemory( strlen( buffer ) +1 );
  429. if( ! rargv[rargc] )
  430. {
  431. OStringBuffer buf;
  432. buf.append( "Not enough memory for reading command file " );
  433. buf.append( av[i] +1 );
  434. buf.append( " with length " );
  435. buf.append( nLen );
  436. buf.append( "." );
  437. throw IllegalArgument( buf.makeStringAndClear() );
  438. }
  439. strcpy( rargv[rargc] , buffer ); // #100211# - checked
  440. rargc++;
  441. }
  442. fclose(cmdFile);
  443. parseOptions(rargc, rargv, rOptions, bCmdFile);
  444. for (long j=1; j < rargc; j++)
  445. {
  446. rtl_freeMemory(rargv[j]);
  447. }
  448. rtl_freeMemory( buffer );
  449. rtl_freeMemory( rargv );
  450. }
  451. } else
  452. {
  453. usingRegisterImpl();
  454. ret = sal_False;
  455. }
  456. }
  457. }
  458. if( ! bLoaderExplicitlyGiven )
  459. {
  460. if ( rOptions.sComponentUrls.getLength() > 4 &&
  461. rOptions.sComponentUrls.matchAsciiL(
  462. ".jar" , 4 , rOptions.sComponentUrls.getLength() - 4 ) )
  463. {
  464. if( ! rOptions.bSilent )
  465. {
  466. printf( "using loader com.sun.star.loader.Java2\n" );
  467. }
  468. rOptions.sLoaderName = OUString(
  469. RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.Java2"));
  470. }
  471. else
  472. {
  473. rOptions.sLoaderName = OUString(
  474. RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary") );
  475. }
  476. }
  477. return ret;
  478. }
  479. struct DoIt
  480. {
  481. sal_Bool _bRegister;
  482. sal_Bool _bRevoke;
  483. sal_Bool _bSilent;
  484. sal_Bool _bPrefix;
  485. OUString _sPrefix;
  486. OString _sRegName;
  487. OUString _sLoaderName;
  488. Reference<XImplementationRegistration2> _xImplRegistration;
  489. Reference<XSimpleRegistry> _xReg;
  490. sal_uInt32 * _exitCode;
  491. DoIt(sal_Bool bRegister,
  492. sal_Bool bRevoke,
  493. sal_Bool bSilent,
  494. sal_Bool bPrefix,
  495. const OUString & sPrefix,
  496. const Reference<XSimpleRegistry> & xReg,
  497. const OString & sRegName,
  498. const Reference<XImplementationRegistration2> & xImplRegistration,
  499. const OUString & sLoaderName,
  500. sal_uInt32 * exitCode)
  501. throw();
  502. void operator()(const OUString & url) throw();
  503. };
  504. DoIt::DoIt(sal_Bool bRegister,
  505. sal_Bool bRevoke,
  506. sal_Bool bSilent,
  507. sal_Bool bPrefix,
  508. const OUString & sPrefix,
  509. const Reference<XSimpleRegistry> & xReg,
  510. const OString & sRegName,
  511. const Reference<XImplementationRegistration2> & xImplRegistration,
  512. const OUString & sLoaderName,
  513. sal_uInt32 * exitCode) throw()
  514. : _bRegister(bRegister),
  515. _bRevoke(bRevoke),
  516. _bSilent( bSilent ),
  517. _bPrefix( bPrefix ),
  518. _sPrefix( sPrefix ),
  519. _sRegName(sRegName),
  520. _sLoaderName(sLoaderName),
  521. _xImplRegistration(xImplRegistration),
  522. _xReg(xReg),
  523. _exitCode(exitCode)
  524. {}
  525. void DoIt::operator() (const OUString & url) throw()
  526. {
  527. OString sUrl = OUStringToOString(url, osl_getThreadTextEncoding());
  528. if (_bRegister)
  529. {
  530. try
  531. {
  532. Reference<XImplementationRegistration2> _xImplRegistration2(_xImplRegistration, UNO_QUERY);
  533. if ( _bPrefix ) {
  534. _xImplRegistration->registerImplementationWithLocation(
  535. _sLoaderName, url, replacePrefix(url, _sPrefix), _xReg);
  536. } else {
  537. _xImplRegistration->registerImplementation(_sLoaderName, url, _xReg);
  538. }
  539. if ( ! _bSilent )
  540. {
  541. fprintf(stderr, "register component '%s' in registry '%s' successful!\n", sUrl.getStr(), _sRegName.getStr());
  542. }
  543. }
  544. catch(CannotRegisterImplementationException & cannotRegisterImplementationException) {
  545. OString aMessage(OUStringToOString(cannotRegisterImplementationException.Message, RTL_TEXTENCODING_ASCII_US));
  546. fprintf(stderr, "register component '%s' in registry '%s' failed!\n", sUrl.getStr(), _sRegName.getStr());
  547. fprintf(stderr, "error (CannotRegisterImplementationException): %s\n", aMessage.getStr());
  548. ++ (*_exitCode);
  549. }
  550. catch( RuntimeException & e )
  551. {
  552. OString aMessage(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US));
  553. fprintf(stderr, "register component '%s' in registry '%s' failed!\n", sUrl.getStr(), _sRegName.getStr());
  554. fprintf(stderr, "error (RuntimeException): %s\n", aMessage.getStr());
  555. ++ (*_exitCode);
  556. }
  557. }
  558. else if(_bRevoke)
  559. {
  560. try
  561. {
  562. sal_Bool bRet = _xImplRegistration->revokeImplementation(url, _xReg);
  563. if (bRet)
  564. {
  565. if ( ! _bSilent )
  566. fprintf(stderr, "revoke component '%s' from registry '%s' successful!\n", sUrl.getStr(), _sRegName.getStr());
  567. }
  568. else
  569. {
  570. fprintf(stderr, "revoke component '%s' from registry '%s' failed!\n", sUrl.getStr(), _sRegName.getStr());
  571. ++ (*_exitCode);
  572. }
  573. }
  574. catch( RuntimeException & e )
  575. {
  576. OString aMessage(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US));
  577. fprintf( stderr,
  578. "revoke component '%s' from registry '%s' failed!\n",
  579. sUrl.getStr(),
  580. _sRegName.getStr() );
  581. fprintf( stderr, "RuntimeException: %s\n" , aMessage.getStr());
  582. ++ (*_exitCode);
  583. }
  584. }
  585. }
  586. static bool hasService(
  587. const Reference< XMultiServiceFactory > &xSMgr,
  588. const sal_Char * service )
  589. {
  590. bool ret = false;
  591. Reference< XContentEnumerationAccess > access( xSMgr, UNO_QUERY );
  592. if( access.is( ))
  593. {
  594. Reference< XEnumeration > enumeration = access->createContentEnumeration(
  595. OUString::createFromAscii( service ) );
  596. if( enumeration.is() && enumeration->hasMoreElements() )
  597. {
  598. ret = true;
  599. }
  600. }
  601. return ret;
  602. }
  603. static void bootstrap(
  604. Options & opt ,
  605. Reference< XMultiServiceFactory > &xSMgr,
  606. Reference< XSimpleRegistry > & reg ) throw ( Exception )
  607. {
  608. if( opt.sRegName.equals( opt.sBootRegName2 ) )
  609. {
  610. OUString tmp2 = opt.sBootRegName;
  611. opt.sBootRegName = opt.sBootRegName2;
  612. opt.sBootRegName2 = tmp2;
  613. }
  614. if ( opt.sRegName.equals(opt.sBootRegName) )
  615. {
  616. if( !opt.sBootRegName2.isEmpty() )
  617. {
  618. xSMgr = createRegistryServiceFactory(
  619. convertToFileUrl(opt.sRegName),
  620. convertToFileUrl(opt.sBootRegName2),
  621. sal_False );
  622. }
  623. else
  624. {
  625. xSMgr = createRegistryServiceFactory(
  626. convertToFileUrl(opt.sRegName) , sal_False );
  627. }
  628. }
  629. else
  630. {
  631. if( !opt.sBootRegName2.isEmpty() )
  632. {
  633. xSMgr = createRegistryServiceFactory(
  634. convertToFileUrl( opt.sBootRegName2 ),
  635. convertToFileUrl( opt.sBootRegName ),
  636. sal_True );
  637. }
  638. else if ( !opt.sBootRegName.isEmpty() )
  639. {
  640. xSMgr = createRegistryServiceFactory(
  641. convertToFileUrl( opt.sBootRegName ),
  642. sal_True );
  643. }
  644. else
  645. {
  646. xSMgr = createServiceFactory();
  647. }
  648. reg = Reference< XSimpleRegistry >(
  649. xSMgr->createInstance(
  650. rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"))), UNO_QUERY);
  651. if (reg.is())
  652. {
  653. try
  654. {
  655. reg->open( convertToFileUrl(opt.sRegName), sal_False, sal_True);
  656. if (!reg->isValid())
  657. {
  658. fprintf(stderr, "ERROR: open|create registry '%s' failed!\n",
  659. OUStringToOString(opt.sRegName, osl_getThreadTextEncoding() ).getStr());
  660. exit(1);
  661. }
  662. }
  663. catch( InvalidRegistryException & e)
  664. {
  665. OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
  666. fprintf(stderr,
  667. "ERROR: create registry '%s' failed!\n"
  668. "InvalidRegistryException: %s\n",
  669. OUStringToOString( opt.sRegName, osl_getThreadTextEncoding()).getStr(),
  670. o.getStr() );
  671. exit(1);
  672. }
  673. }
  674. }
  675. if( ! opt.sLoaderName.compareToAscii( "com.sun.star.loader.Java2" ) &&
  676. ! hasService( xSMgr, "com.sun.star.loader.Java2" ) )
  677. {
  678. // we know our java loader, so we check, whether a java-loader is
  679. // registered
  680. Reference< XInterface > r = loadSharedLibComponentFactory(
  681. OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.uno" SAL_DLLEXTENSION)),
  682. OUString(),
  683. OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.JavaVirtualMachine")),
  684. xSMgr,
  685. Reference< XRegistryKey > () );
  686. Reference< XInterface > r2 = loadSharedLibComponentFactory(
  687. OUString(RTL_CONSTASCII_USTRINGPARAM("javaloader.uno" SAL_DLLEXTENSION)),
  688. OUString(),
  689. OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.JavaComponentLoader")),
  690. xSMgr,
  691. Reference< XRegistryKey > () );
  692. Reference <XSet> xSet( xSMgr, UNO_QUERY );
  693. if( r.is() && r2.is() && xSet.is() )
  694. {
  695. xSet->insert( makeAny( r ) );
  696. xSet->insert( makeAny( r2 ) );
  697. }
  698. }
  699. }
  700. SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
  701. {
  702. sal_Bool bRet = sal_False;
  703. sal_uInt32 exitCode = 0;
  704. Options aOptions;
  705. try
  706. {
  707. if ( !parseOptions(argc, argv, aOptions, sal_False) )
  708. {
  709. exit(1);
  710. }
  711. }
  712. catch ( IllegalArgument& e)
  713. {
  714. fprintf(stderr, "ERROR: %s\n", e.m_message.getStr());
  715. exit(1);
  716. }
  717. if( aOptions.sRegName.isEmpty() )
  718. {
  719. fprintf( stderr, "ERROR: target registry missing (-r option)\n" );
  720. exit( 1 );
  721. }
  722. if ( aOptions.sComponentUrls.isEmpty() )
  723. {
  724. fprintf(stderr, "ERROR: no component url is specified!\n");
  725. exit(1);
  726. }
  727. Reference< XMultiServiceFactory > xSMgr;
  728. Reference< XSimpleRegistry > xReg;
  729. try
  730. {
  731. bootstrap( aOptions, xSMgr ,xReg );
  732. }
  733. catch( Exception& e )
  734. {
  735. fprintf(stderr, "ERROR: create ServiceManager failed!\n");
  736. if ( !e.Message.isEmpty() )
  737. {
  738. fprintf(stderr, "ERROR description: %s\n",
  739. OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
  740. }
  741. exit(1);
  742. }
  743. Reference<XImplementationRegistration2> xImplRegistration(
  744. xSMgr->createInstance(
  745. OUString(RTL_CONSTASCII_USTRINGPARAM(
  746. "com.sun.star.registry.ImplementationRegistration"))),
  747. UNO_QUERY);
  748. if (xImplRegistration.is())
  749. {
  750. sal_Int32 index = 0;
  751. vector<OUString> urls;
  752. OUString urlListWithSemikolon = aOptions.sComponentUrls;
  753. do {
  754. OUString aToken = urlListWithSemikolon.getToken( 0, ';', index);
  755. fprintf(stderr, "%s\n", OUStringToOString(aToken, osl_getThreadTextEncoding()).getStr());
  756. urls.push_back(aToken);
  757. } while ( index >= 0 );
  758. OString sRegName = OUStringToOString( aOptions.sRegName, osl_getThreadTextEncoding() );
  759. if(aOptions.bRegister || aOptions.bRevoke)
  760. {
  761. for_each(urls.begin(), urls.end(),
  762. DoIt(aOptions.bRegister, aOptions.bRevoke, aOptions.bSilent,
  763. aOptions.bPrefix, aOptions.sPrefix,
  764. xReg, sRegName, xImplRegistration,
  765. aOptions.sLoaderName, &exitCode));
  766. }
  767. else
  768. {
  769. ++ exitCode;
  770. usingRegisterImpl();
  771. }
  772. }
  773. else
  774. {
  775. fprintf(stderr, "Component registration service could not be loaded!\n");
  776. exitCode++;
  777. }
  778. if (!bRet && xReg.is() && xReg->isValid())
  779. xReg->close();
  780. Reference< XComponent > xComponent( xSMgr, UNO_QUERY );
  781. if ( xComponent.is() )
  782. xComponent->dispose();
  783. return exitCode;
  784. }
  785. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */