~ubuntu-branches/ubuntu/karmic/openoffice.org-l10n/karmic

« back to all changes in this revision

Viewing changes to ooo-build/scratch/sc-vba/testvba/main.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Chris Cheney
  • Date: 2008-01-08 23:17:08 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20080108231708-7f5yc4h021ikwgyz
Tags: 1:2.3.1-3ubuntu1
* Copy of the openoffice.org source.
  - debian/changelog: Change source name.
  - debian/control.in: Change source name.
  - debian/control: Regenerate control file.

* Resynchronise with Debian (r989). Remaining changes:
  - debian/broffice.org.postrm.in:
    . Change diversions to ubuntu bitmap filenames.
  - debian/broffice.org.preinst.in:
    . Change diversions to ubuntu bitmap filenames.
  - debian/control.2.in:
    . Add file for Ubuntu.
  - debian/control.in:
    . Change maintainer line.
    . Use imagemagick instead of graphicsmagick.
    . Change bzr repo location.
    . Use java-runtime-depends variable for java dependencies.
    . Make openoffice.org-core Depends on openoffice.org-hyphenation.
    . Add package openoffice.org-style-human.
    . Various other minor Ubuntu changes.
  - debian/control.l10n.in:
    . Add file for Ubuntu.
  - debian/control.lang.in:
    . Add L10N_COMMON to Depends.
  - debian/control.mozilla.in:
    . Add Xb-Npp-xxx tags according to "firefox distro add-on suport" spec.
  - debian/control.ubuntu.in:
    . Add file for Ubuntu.
  - debian/deppackage.postinst.in:
    . Add file for Ubuntu.
  - debian/module-po.map:
    . Add file for Ubuntu.
  - debian/ooo-build-ubuntu.diff:
    . Various Ubuntu specific changes to ooo-build.
  - debian/rules:
    . Add USE_LZMA_COMPRESS option.
    . Add USE_COMMON_DOCDIR option.
    . Add support to build on lpia.
    . Add support to build l10n as a separate source.
    . Add java-runtime-depends variable for java dependencies.
    . Add support to chmod +x programs in debian dir.
    . Add support to uuencode binary files in ubuntu dir.
    . Add support to Ubuntu specific bitmaps.
    . Use imagemagick instead of graphicsmagick.
    . Add support for openoffice.org-style-human package.
    . Add support for launchpad translations.
    . Various Ubuntu specific changes.
  - debian/scripts/convert2po:
    . Add file for Ubuntu.
  - debian/scripts/fix_image_rgb:
    . Use imagemagick instead of graphicsmagick.
  - debian/scripts/gsifilter.py:
    . Add file for Ubuntu.
  - debian/scripts/splitgsi:
    . Add file for Ubuntu.
  - debian/template.desktop.in:
    . Add NoDisplay=true.
  - ooo-build/configure.in:
    . Added support for Hardy.
  - ooo-build/distro-configs/UbuntuHardy.conf.in:
    . Added support for Hardy.
  - ooo-build/distro-configs/UbuntuHardy64.conf.in:
    . Added support for Hardy.
  - ooo-build/patches/src680/apply:
    . Added support for Hardy.
  - ooo-build/patches/src680/ubuntu-lpi.diff:
    . Updated patch.
  - ubuntu/*
    . Various Ubuntu specific changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "cppuhelper/bootstrap.hxx"
 
2
 
 
3
#include <com/sun/star/beans/Property.hpp>
 
4
#include <com/sun/star/beans/XPropertySet.hpp>
 
5
#include <com/sun/star/beans/XPropertySetInfo.hpp>
 
6
#include <com/sun/star/container/XNameAccess.hpp>
 
7
#include <com/sun/star/container/XNameContainer.hpp>
 
8
#include <com/sun/star/frame/XComponentLoader.hpp>
 
9
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
 
10
#include <com/sun/star/sheet/XSpreadsheet.hpp>
 
11
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
 
12
#include <com/sun/star/util/XCloseable.hpp>
 
13
#include <com/sun/star/uno/XComponentContext.hpp>
 
14
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
 
15
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
 
16
 
 
17
#include <tools/urlobj.hxx>
 
18
#include <osl/file.hxx>
 
19
 
 
20
#include <memory>
 
21
#include <iostream>
 
22
 
 
23
using namespace ::com::sun::star;
 
24
using namespace ::com::sun::star::sheet;
 
25
 
 
26
using ::com::sun::star::beans::Property;
 
27
using ::com::sun::star::beans::PropertyValue;
 
28
using ::com::sun::star::beans::XPropertySet;
 
29
using ::com::sun::star::beans::XPropertySetInfo;
 
30
using ::com::sun::star::container::XNameContainer;
 
31
using ::com::sun::star::lang::XComponent;
 
32
using ::com::sun::star::lang::XMultiComponentFactory;
 
33
using ::com::sun::star::frame::XComponentLoader;
 
34
using ::com::sun::star::uno::Reference;
 
35
using ::com::sun::star::uno::Sequence;
 
36
using ::com::sun::star::uno::UNO_QUERY;
 
37
using ::com::sun::star::uno::UNO_QUERY_THROW;
 
38
using ::com::sun::star::uno::XComponentContext;
 
39
using ::com::sun::star::uno::XInterface;
 
40
using ::com::sun::star::ucb::XSimpleFileAccess;
 
41
using ::rtl::OUString;
 
42
 
 
43
using ::std::auto_ptr;
 
44
 
 
45
const OUString EXTN = rtl::OUString::createFromAscii(".xls"); 
 
46
 
 
47
OUString convertToURL( const OUString& rPath )
 
48
{
 
49
        rtl::OUString aURL;
 
50
        INetURLObject aObj;
 
51
        aObj.SetURL( rPath );
 
52
        bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
 
53
        if ( bIsURL )
 
54
                aURL = rPath;
 
55
        else
 
56
                {
 
57
                osl::FileBase::getFileURLFromSystemPath( rPath, aURL );
 
58
                                if ( aURL.equals( rPath ) )
 
59
                                        throw uno::RuntimeException( rtl::OUString::createFromAscii( "could'nt convert " ).concat( rPath ).concat( rtl::OUString::createFromAscii( " to a URL, is it a fully qualified path name? " ) ), Reference< uno::XInterface >() );
 
60
                }
 
61
                return aURL;
 
62
}
 
63
 
 
64
OUString ascii(const sal_Char* cstr)
 
65
{
 
66
        return OUString::createFromAscii(cstr);
 
67
}
 
68
 
 
69
const sal_Char* getStr(const OUString& ou)
 
70
{
 
71
    return OUStringToOString(ou, RTL_TEXTENCODING_UTF8).getStr();
 
72
}
 
73
 
 
74
 
 
75
int usage( const char* pName )
 
76
{
 
77
        std::cerr << "usage: " << pName << "<path to testdocument dir> <output_directory>" << std::endl;
 
78
        return 1;
 
79
 
 
80
}
 
81
 
 
82
class TestVBA
 
83
{
 
84
private:
 
85
        Reference< XComponentContext >  mxContext;
 
86
        Reference< XMultiComponentFactory > mxMCF;
 
87
        Reference< XComponentLoader > mxCompLoader;
 
88
        Reference< XSimpleFileAccess > mxSFA;
 
89
        rtl::OUString msOutDirPath;
 
90
protected:
 
91
public:
 
92
        TestVBA( const Reference< XComponentContext >&  _xContext, 
 
93
                const Reference< XMultiComponentFactory >& _xMCF, 
 
94
                const Reference< XComponentLoader >& _xCompLoader, 
 
95
                const rtl::OUString& _outDirPath ) : mxContext( _xContext ), mxMCF( _xMCF ), 
 
96
mxCompLoader( _xCompLoader ), msOutDirPath( convertToURL( _outDirPath  ) ) 
 
97
        {
 
98
                mxSFA.set( mxMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), mxContext), uno::UNO_QUERY_THROW );
 
99
        } 
 
100
 
 
101
        rtl::OUString getLogLocation() throw (  beans::UnknownPropertyException,  lang::IllegalArgumentException, lang::WrappedTargetException,  uno::Exception ) 
 
102
        {
 
103
                rtl::OUString sLogLocation;
 
104
                Reference< XPropertySet > pathSettings( mxMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.comp.framework.PathSettings" ), mxContext), uno::UNO_QUERY_THROW );
 
105
                pathSettings->getPropertyValue( rtl::OUString::createFromAscii( "Work" ) ) >>= sLogLocation;
 
106
                sLogLocation = sLogLocation.concat( rtl::OUString::createFromAscii( "/" ) ).concat( rtl::OUString::createFromAscii( "HelperAPI-test.log" ) );
 
107
                return sLogLocation;
 
108
        }
 
109
 
 
110
        void init() 
 
111
        {
 
112
                // blow away previous logs?
 
113
        }
 
114
 
 
115
        void traverse( const rtl::OUString& sFileDirectory ) 
 
116
        {
 
117
                rtl::OUString sFileDirectoryURL = convertToURL( sFileDirectory );       
 
118
                if ( !mxSFA->isFolder( sFileDirectoryURL) ) 
 
119
                {
 
120
                        throw lang::IllegalArgumentException( rtl::OUString::createFromAscii( "not a directory: ").concat( sFileDirectoryURL ), Reference<uno::XInterface>(), 1 );
 
121
                }       
 
122
                // Getting all files and directories in the current directory
 
123
                Sequence<OUString> entries = mxSFA->getFolderContents( sFileDirectoryURL, sal_False );
 
124
                 
 
125
                // Iterating for each file and directory
 
126
                for ( sal_Int32 i = 0; i < entries.getLength(); ++i ) 
 
127
                {
 
128
                // Testing, if the entry in the list is a directory
 
129
                //
 
130
                //            if ( entries[ i ].isDirectory() ) 
 
131
                //            {
 
132
                //                // ignore Recursive call for the new directory
 
133
                //                // traverse( entries[ i ] );
 
134
                //            } 
 
135
                //            else 
 
136
                        rtl::OUString sUrl = entries[ i ];
 
137
                        if ( !mxSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCaseAsciiL( ".xls", 4 ) ) 
 
138
                                
 
139
                        {
 
140
                                try 
 
141
                                {
 
142
                                        OSL_TRACE( "processing %s",  rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() );
 
143
                                        // Loading the wanted document
 
144
                                        Sequence< PropertyValue > propertyValues(1);
 
145
                                        propertyValues[0].Name = rtl::OUString::createFromAscii( "Hidden" );
 
146
                                        propertyValues[0].Value <<= sal_False;
 
147
                                
 
148
                                        Reference< uno::XInterface > xDoc =     
 
149
                                                mxCompLoader->loadComponentFromURL( sUrl, rtl::OUString::createFromAscii( "_blank" ), 0, propertyValues);
 
150
                                        OUString logFileURL = convertToURL( getLogLocation() );
 
151
                                        try
 
152
                                        {
 
153
                                                Reference< script::provider::XScriptProviderSupplier > xSupplier( xDoc, uno::UNO_QUERY_THROW ) ; 
 
154
                                                if ( mxSFA->exists( logFileURL ) )      
 
155
                                                        mxSFA->kill( logFileURL );
 
156
                                        
 
157
                                                Reference< script::provider::XScriptProvider > xProv = xSupplier->getScriptProvider();
 
158
                                                Reference< script::provider::XScript > xScript = xProv->getScript( rtl::OUString::createFromAscii( "vnd.sun.star.script:Standard.TestMacros.Main?language=Basic&location=document" ));
 
159
                                                OSL_TRACE("Got script for doc %s", rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() );
 
160
                                                Sequence< uno::Any > aArgs;
 
161
                                                Sequence< sal_Int16 > aOutArgsIndex;
 
162
                                                Sequence< uno::Any > aOutArgs;
 
163
                                                
 
164
                                                xScript->invoke(aArgs, aOutArgsIndex, aOutArgs); 
 
165
                
 
166
                                                OUString fileName = sUrl.copy ( sUrl.lastIndexOf( '/' ) );
 
167
                                                OUString newLocation = msOutDirPath + fileName.copy ( 0, fileName.lastIndexOf( EXTN )  ) + rtl::OUString::createFromAscii( ".log" );
 
168
                                                mxSFA->move( logFileURL, newLocation );
 
169
                                                OSL_TRACE("new logfile location is %s ", rtl::OUStringToOString( newLocation, RTL_TEXTENCODING_UTF8 ).getStr() ); 
 
170
                                                
 
171
                                        }
 
172
                                        catch ( uno::Exception& e )
 
173
                                        {
 
174
                                                std::cerr << "Caught exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
 
175
                                        }
 
176
 
 
177
                                        // interface is supported, otherwise use XComponent.dispose
 
178
                                        Reference< util::XCloseable > xCloseable ( xDoc, uno::UNO_QUERY );
 
179
                
 
180
                                        if ( xCloseable.is() ) 
 
181
                                        {
 
182
                                                xCloseable->close(sal_False);
 
183
                                        } 
 
184
                                        else 
 
185
                                        {
 
186
                                                Reference< XComponent > xComp( xDoc, uno::UNO_QUERY_THROW );
 
187
                                        
 
188
                                                xComp->dispose();
 
189
                                        }
 
190
                                }
 
191
                                catch( uno::Exception& e ) 
 
192
                                {
 
193
                                        std::cerr << "Caught exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
 
194
                                }
 
195
                                
 
196
                        }
 
197
                }
 
198
        }       
 
199
};
 
200
 
 
201
void tryDispose( Reference< uno::XInterface > xIF, const char* sComp )
 
202
{
 
203
        Reference< lang::XComponent > xComponent( xIF, uno::UNO_QUERY );
 
204
        if ( xComponent.is() )
 
205
        {
 
206
                try
 
207
                {
 
208
                        xComponent->dispose();
 
209
                }       
 
210
                catch( uno::Exception& e )
 
211
                {
 
212
                        std::cerr << "tryDispose caught exception " <<rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << " while disposing " <<  sComp << std::endl;
 
213
                }
 
214
        }
 
215
}
 
216
int main( int argv, char** argc )
 
217
{
 
218
        if ( !( argv > 2 ) )
 
219
                return usage( argc[0] );
 
220
        try
 
221
        {
 
222
 
 
223
                OSL_TRACE("Attempting to bootstrap normal");
 
224
                Reference<XComponentContext> xCC = ::cppu::bootstrap();
 
225
                Reference<XMultiComponentFactory> xFactory = xCC->getServiceManager();
 
226
                OSL_TRACE("got servicemanager");
 
227
                Reference<XInterface> desktop = xFactory->createInstanceWithContext(
 
228
                ascii("com.sun.star.frame.Desktop"), xCC);
 
229
                OSL_TRACE("got desktop");
 
230
                Reference<frame::XComponentLoader> xLoader(desktop, UNO_QUERY_THROW);
 
231
                TestVBA* dTest = new TestVBA( xCC, xFactory, xLoader, ascii( argc[ 2 ] ) );
 
232
                dTest->traverse( ascii( argc[ 1 ] ) );
 
233
                delete dTest;
 
234
//              tryDispose( xLoader, "desktop" );
 
235
//              tryDispose( xCC, "remote context" );
 
236
 
 
237
        }
 
238
        catch( uno::Exception& e )
 
239
        {
 
240
                std::cerr << "Caught Exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
 
241
        }
 
242
 
 
243
}