xref: /AOO42X/main/framework/test/typecfg/typecfg.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 #include <classes/servicemanager.hxx>
31 #include <classes/filtercache.hxx>
32 #include <macros/generic.hxx>
33 #include <macros/debug.hxx>
34 #include <services.h>
35 
36 //_________________________________________________________________________________________________________________
37 //  interface includes
38 //_________________________________________________________________________________________________________________
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 
43 //_________________________________________________________________________________________________________________
44 //  other includes
45 //_________________________________________________________________________________________________________________
46 #include <comphelper/processfactory.hxx>
47 #include <vos/process.hxx>
48 #include <rtl/ustring.hxx>
49 #include <rtl/ustrbuf.hxx>
50 
51 #include <vcl/event.hxx>
52 #include <vcl/svapp.hxx>
53 #include <vcl/wrkwin.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <stdio.h>
56 
57 //_________________________________________________________________________________________________________________
58 //  const
59 //_________________________________________________________________________________________________________________
60 
61 #define RDBFILE                                 DECLARE_ASCII("typecfg.rdb"     )
62 #define ARGUMENT_GENERATE_CFGVIEW               DECLARE_ASCII("-cfgview"        )
63 #define ARGUMENT_CHECK_FILTERREGISTRATION       DECLARE_ASCII("-registerfilter" )
64 #define ARGUMENT_GENERATE_TYPEDETECTION_XCD     DECLARE_ASCII("-generatexcd"    )
65 
66 //_________________________________________________________________________________________________________________
67 //  namespace
68 //_________________________________________________________________________________________________________________
69 
70 using namespace ::std                       ;
71 using namespace ::vos                       ;
72 using namespace ::rtl                       ;
73 using namespace ::framework                 ;
74 using namespace ::comphelper                ;
75 using namespace ::com::sun::star::uno       ;
76 using namespace ::com::sun::star::lang      ;
77 using namespace ::com::sun::star::container ;
78 using namespace ::com::sun::star::beans     ;
79 
80 //_________________________________________________________________________________________________________________
81 //  defines
82 //_________________________________________________________________________________________________________________
83 
84 //_________________________________________________________________________________________________________________
85 //  declarations
86 //_________________________________________________________________________________________________________________
87 
88 enum EMode
89 {
90     E_GENERATE_CFGVIEW              ,
91     E_CHECK_FILTERREGISTRATION      ,
92     E_GENERATE_TYPEDETECTION_XCD
93 };
94 
95 /*-***************************************************************************************************************/
96 class TypeApplication : public Application
97 {
98     //*************************************************************************************************************
99     public:
100 
101         void Main();
102 
103     //*************************************************************************************************************
104     private:
105 
106         void impl_parseCommandLine          ();
107         void impl_generateCFGView           ();
108         void impl_checkFilterRegistration   ();
109         void impl_generateTypeDetectionXCD  ();
110 
111     //*************************************************************************************************************
112     private:
113 
114         EMode                               m_eMode             ;
115         Reference< XMultiServiceFactory >   m_xServiceManager   ;
116 
117         FilterCache*                        m_pCache            ;
118 
119 };  //  class FilterApplication
120 
121 //_________________________________________________________________________________________________________________
122 //  global variables
123 //_________________________________________________________________________________________________________________
124 
125 TypeApplication gApplication;
126 
127 //*****************************************************************************************************************
Main()128 void TypeApplication::Main()
129 {
130     // Init global servicemanager and set it.
131     ServiceManager aManager;
132     m_xServiceManager = aManager.getSharedUNOServiceManager( RDBFILE );
133     setProcessServiceFactory( m_xServiceManager );
134 
135     m_pCache = new FilterCache;
136 
137     impl_parseCommandLine();
138 
139     switch( m_eMode )
140     {
141         case E_GENERATE_CFGVIEW                 :   impl_generateCFGView();
142                                                     break;
143         case E_CHECK_FILTERREGISTRATION         :   impl_checkFilterRegistration();
144                                                     break;
145         case E_GENERATE_TYPEDETECTION_XCD       :   impl_generateTypeDetectionXCD();
146                                                     break;
147     }
148 
149     delete m_pCache;
150     m_pCache = NULL;
151 }
152 
153 //*****************************************************************************************************************
impl_parseCommandLine()154 void TypeApplication::impl_parseCommandLine()
155 {
156     OStartupInfo    aInfo       ;
157     OUString        sArgument   ;
158     sal_Int32       nArgument   = 0                         ;
159     sal_Int32       nCount      = aInfo.getCommandArgCount();
160 
161     while( nArgument<nCount )
162     {
163         aInfo.getCommandArg( nArgument, sArgument );
164 
165         if( sArgument == ARGUMENT_GENERATE_CFGVIEW )
166         {
167             m_eMode = E_GENERATE_CFGVIEW;
168             break;
169         }
170         else
171         if( sArgument == ARGUMENT_CHECK_FILTERREGISTRATION )
172         {
173             m_eMode = E_CHECK_FILTERREGISTRATION;
174             break;
175         }
176         else
177         if( sArgument == ARGUMENT_GENERATE_TYPEDETECTION_XCD )
178         {
179             m_eMode = E_GENERATE_TYPEDETECTION_XCD;
180             break;
181         }
182 
183         ++nArgument;
184     }
185 }
186 
187 //*****************************************************************************************************************
impl_generateCFGView()188 void TypeApplication::impl_generateCFGView()
189 {
190     #ifdef ENABLE_FILTERCACHEDEBUG
191         // Cache use ref count!
192         FilterCache aCache;
193         aCache.impldbg_generateHTMLView();
194     #endif  //ENABLE_FILTERCACHEDEBUG
195 }
196 
197 //*****************************************************************************************************************
impl_checkFilterRegistration()198 void TypeApplication::impl_checkFilterRegistration()
199 {
200     Reference< XNameContainer > xFilterContainer( m_xServiceManager->createInstance( SERVICENAME_FILTERFACTORY ), UNO_QUERY );
201     LOG_ASSERT2( xFilterContainer.is()==sal_False, "TypeApplication::impl_checkFilterRegistration()", "Couldn't create filter factory!" )
202     if( xFilterContainer.is() == sal_True )
203     {
204         Sequence< PropertyValue > lProperties( 8 );
205 
206         lProperties[0].Name     =   DECLARE_ASCII("Type")               ;
207         lProperties[0].Value    <<= DECLARE_ASCII("MeinType")           ;
208 
209         lProperties[1].Name     =   DECLARE_ASCII("UIName")             ;
210         lProperties[1].Value    <<= DECLARE_ASCII("MeinUIName")         ;
211 
212         lProperties[2].Name     =   DECLARE_ASCII("UINames")            ;
213         lProperties[2].Value    <<= Sequence< PropertyValue >()         ;
214 
215         lProperties[3].Name     =   DECLARE_ASCII("DocumentService")    ;
216         lProperties[3].Value    <<= DECLARE_ASCII("MeinDocService")     ;
217 
218         lProperties[4].Name     =   DECLARE_ASCII("FilterService")      ;
219         lProperties[4].Value    <<= DECLARE_ASCII("MeinFilterService")  ;
220 
221         lProperties[5].Name     =   DECLARE_ASCII("Flags")              ;
222         lProperties[5].Value    <<= (sal_Int32)256                      ;
223 
224         lProperties[6].Name     =   DECLARE_ASCII("UserData")           ;
225         lProperties[6].Value    <<= Sequence< OUString >()              ;
226 
227         lProperties[7].Name     =   DECLARE_ASCII("FileFormatVersion")  ;
228         lProperties[7].Value    <<= (sal_Int32)0                        ;
229 
230         lProperties[8].Name     =   DECLARE_ASCII("TemplateName")       ;
231         lProperties[8].Value    <<= DECLARE_ASCII("MeinTemplate")       ;
232     }
233 }
234 
235 //*****************************************************************************************************************
impl_generateTypeDetectionXCD()236 void TypeApplication::impl_generateTypeDetectionXCD()
237 {
238     #ifdef ENABLE_GENERATEFILTERCACHE
239     // Cache use ref count!
240     FilterCache aCache                  ;
241     sal_Bool    bWriteable  =   sal_True;
242     sal_Unicode cSeparator  =   ','     ;
243     aCache.impldbg_generateXCD( "org.openoffice.Office.TypeDetection.xcd", bWriteable, cSeparator );
244     #endif  //ENABLE_GENERATEFILTERCACHE
245 }
246