Branch data Line data Source code
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 "vbatemplate.hxx"
29 : : #include <vbahelper/vbahelper.hxx>
30 : : #include "wordvbahelper.hxx"
31 : : #include "vbaautotextentry.hxx"
32 : : #include <com/sun/star/text/XAutoTextContainer.hpp>
33 : : #include <comphelper/processfactory.hxx>
34 : : #include <comphelper/string.hxx>
35 : : #include <tools/urlobj.hxx>
36 : : #include <osl/file.hxx>
37 : :
38 : : using namespace ::ooo::vba;
39 : : using namespace ::com::sun::star;
40 : :
41 : 0 : String lcl_CheckGroupName( const String& rGroupName )
42 : : {
43 [ # # ]: 0 : String sRet;
44 : : //group name should contain only A-Z and a-z and spaces
45 [ # # ]: 0 : for( xub_StrLen i = 0; i < rGroupName.Len(); i++ )
46 : : {
47 : 0 : sal_Unicode cChar = rGroupName.GetChar(i);
48 [ # # ][ # # ]: 0 : if (comphelper::string::isalnumAscii(cChar) ||
[ # # ][ # # ]
[ # # ]
49 : : cChar == '_' || cChar == 0x20)
50 : : {
51 [ # # ]: 0 : sRet += cChar;
52 : : }
53 : : }
54 [ # # ][ # # ]: 0 : return comphelper::string::strip(sRet, ' ');
[ # # ][ # # ]
55 : : }
56 : :
57 : :
58 : 0 : SwVbaTemplate::SwVbaTemplate( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel, const rtl::OUString& rFullUrl )
59 : 0 : : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msFullUrl( rFullUrl )
60 : : {
61 : 0 : }
62 : :
63 : :
64 : 0 : SwVbaTemplate::~SwVbaTemplate()
65 : : {
66 [ # # ]: 0 : }
67 : :
68 : : rtl::OUString
69 : 0 : SwVbaTemplate::getName() throw ( css::uno::RuntimeException )
70 : : {
71 : 0 : rtl::OUString sName;
72 [ # # ]: 0 : if( !msFullUrl.isEmpty() )
73 : : {
74 [ # # ]: 0 : INetURLObject aURL( msFullUrl );
75 [ # # ][ # # ]: 0 : ::osl::File::getSystemPathFromFileURL( aURL.GetLastName(), sName );
[ # # ]
76 : : }
77 : 0 : return sName;
78 : : }
79 : :
80 : : rtl::OUString
81 : 0 : SwVbaTemplate::getPath() throw ( css::uno::RuntimeException )
82 : : {
83 : 0 : rtl::OUString sPath;
84 [ # # ]: 0 : if( !msFullUrl.isEmpty() )
85 : : {
86 [ # # ]: 0 : INetURLObject aURL( msFullUrl );
87 [ # # ]: 0 : rtl::OUString sURL( aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
88 [ # # ]: 0 : sURL = sURL.copy( 0, sURL.getLength() - aURL.GetLastName().getLength() - 1 );
89 [ # # ][ # # ]: 0 : ::osl::File::getSystemPathFromFileURL( sURL, sPath );
90 : : }
91 : 0 : return sPath;
92 : : }
93 : :
94 : : uno::Any SAL_CALL
95 : 0 : SwVbaTemplate::AutoTextEntries( const uno::Any& index ) throw (uno::RuntimeException)
96 : : {
97 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
98 [ # # ][ # # ]: 0 : uno::Reference< text::XAutoTextContainer > xAutoTextContainer( xMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
99 : :
100 : : // the default template is "Normal.dot" in Word.
101 [ # # ]: 0 : rtl::OUString sGroup( RTL_CONSTASCII_USTRINGPARAM("Normal") );
102 [ # # ]: 0 : rtl::OUString sName = getName();
103 : 0 : sal_Int32 nIndex = sName.lastIndexOf( sal_Unicode('.') );
104 [ # # ]: 0 : if( nIndex > 0 )
105 : : {
106 : 0 : sGroup = sName.copy( 0, sName.lastIndexOf( sal_Unicode('.') ) );
107 : : }
108 [ # # ][ # # ]: 0 : String sNewGroup = lcl_CheckGroupName( sGroup );
[ # # ]
109 : :
110 : 0 : uno::Reference< container::XIndexAccess > xGroup;
111 [ # # ][ # # ]: 0 : if( xAutoTextContainer->hasByName( sNewGroup ) )
[ # # ][ # # ]
112 : : {
113 [ # # ][ # # ]: 0 : xGroup.set( xAutoTextContainer->getByName( sNewGroup ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
114 : : }
115 : : else
116 : : {
117 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Auto Text Entry doesn't exist") ), uno::Reference< uno::XInterface >() );
118 : : }
119 : :
120 [ # # ][ # # ]: 0 : uno::Reference< XCollection > xCol( new SwVbaAutoTextEntries( this, mxContext, xGroup ) );
[ # # ][ # # ]
121 [ # # ]: 0 : if( index.hasValue() )
122 [ # # ][ # # ]: 0 : return xCol->Item( index, uno::Any() );
123 [ # # ][ # # ]: 0 : return uno::makeAny( xCol );
124 : : }
125 : :
126 : : rtl::OUString
127 : 0 : SwVbaTemplate::getServiceImplName()
128 : : {
129 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaTemplate"));
130 : : }
131 : :
132 : : uno::Sequence< rtl::OUString >
133 : 0 : SwVbaTemplate::getServiceNames()
134 : : {
135 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
136 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
137 : : {
138 : 0 : aServiceNames.realloc( 1 );
139 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Template" ) );
140 : : }
141 : 0 : return aServiceNames;
142 : : }
143 : :
144 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|