1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/core/fasttokenhandler.hxx"
29 
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include "oox/helper/helper.hxx"
32 #include "oox/token/tokenmap.hxx"
33 
34 namespace oox {
35 namespace core {
36 
37 // ============================================================================
38 
39 using namespace ::com::sun::star::uno;
40 
41 using ::rtl::OUString;
42 
43 // ============================================================================
44 
45 OUString SAL_CALL FastTokenHandler_getImplementationName()
46 {
47     return CREATE_OUSTRING( "com.sun.star.comp.oox.core.FastTokenHandler" );
48 }
49 
50 Sequence< OUString > SAL_CALL FastTokenHandler_getSupportedServiceNames()
51 {
52     Sequence< OUString > aServiceNames( 1 );
53     aServiceNames[ 0 ] = CREATE_OUSTRING( "com.sun.star.xml.sax.FastTokenHandler" );
54     return aServiceNames;
55 }
56 
57 Reference< XInterface > SAL_CALL FastTokenHandler_createInstance( const Reference< XComponentContext >& /*rxContext*/ ) throw (Exception)
58 {
59     return static_cast< ::cppu::OWeakObject* >( new FastTokenHandler );
60 }
61 
62 // ============================================================================
63 
64 FastTokenHandler::FastTokenHandler() :
65     mrTokenMap( StaticTokenMap::get() )
66 {
67 }
68 
69 FastTokenHandler::~FastTokenHandler()
70 {
71 }
72 
73 // XServiceInfo
74 
75 OUString SAL_CALL FastTokenHandler::getImplementationName() throw (RuntimeException)
76 {
77     return FastTokenHandler_getImplementationName();
78 }
79 
80 sal_Bool SAL_CALL FastTokenHandler::supportsService( const OUString& rServiceName ) throw (RuntimeException)
81 {
82     Sequence< OUString > aServiceNames = FastTokenHandler_getSupportedServiceNames();
83     for( sal_Int32 nIndex = 0, nLength = aServiceNames.getLength(); nIndex < nLength; ++nIndex )
84         if( aServiceNames[ nIndex ] == rServiceName )
85             return sal_True;
86     return sal_False;
87 }
88 
89 Sequence< OUString > SAL_CALL FastTokenHandler::getSupportedServiceNames() throw (RuntimeException)
90 {
91     return FastTokenHandler_getSupportedServiceNames();
92 }
93 
94 // XFastTokenHandler
95 
96 sal_Int32 FastTokenHandler::getToken( const OUString& rIdentifier ) throw( RuntimeException )
97 {
98     return mrTokenMap.getTokenFromUnicode( rIdentifier );
99 }
100 
101 OUString FastTokenHandler::getIdentifier( sal_Int32 nToken ) throw( RuntimeException )
102 {
103     return mrTokenMap.getUnicodeTokenName( nToken );
104 }
105 
106 Sequence< sal_Int8 > FastTokenHandler::getUTF8Identifier( sal_Int32 nToken ) throw( RuntimeException )
107 {
108     return mrTokenMap.getUtf8TokenName( nToken );
109 }
110 
111 sal_Int32 FastTokenHandler::getTokenFromUTF8( const Sequence< sal_Int8 >& rIdentifier ) throw( RuntimeException )
112 {
113     return mrTokenMap.getTokenFromUtf8( rIdentifier );
114 }
115 
116 // ============================================================================
117 
118 } // namespace core
119 } // namespace oox
120