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 #include <iostream>
25 #include <string.h>
26 #include <ooxml/resourceids.hxx>
27 #include "OOXMLFastTokenHandler.hxx"
28 #include "gperffasttoken.hxx"
29
30 namespace writerfilter {
31 namespace ooxml
32 {
33
34 using namespace ::std;
35
OOXMLFastTokenHandler(css::uno::Reference<css::uno::XComponentContext> const & context)36 OOXMLFastTokenHandler::OOXMLFastTokenHandler
37 (css::uno::Reference< css::uno::XComponentContext > const & context)
38 : m_xContext(context)
39 {}
40
41 // ::com::sun::star::xml::sax::XFastTokenHandler:
getToken(const::rtl::OUString & Identifier)42 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getToken(const ::rtl::OUString & Identifier)
43 throw (css::uno::RuntimeException)
44 {
45 ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
46
47 struct tokenmap::token * pToken =
48 tokenmap::Perfect_Hash::in_word_set
49 (OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr(),
50 Identifier.getLength());
51
52 if (pToken != NULL)
53 nResult = pToken->nToken;
54
55 #ifdef DEBUG_TOKEN
56 clog << "getToken: "
57 << OUStringToOString(Identifier, RTL_TEXTENCODING_ASCII_US).getStr()
58 << ", " << nResult
59 << endl;
60 #endif
61
62 return nResult;
63 }
64
getIdentifier(::sal_Int32 Token)65 ::rtl::OUString SAL_CALL OOXMLFastTokenHandler::getIdentifier(::sal_Int32 Token)
66 throw (css::uno::RuntimeException)
67 {
68 ::rtl::OUString sResult;
69
70 #if 0
71 //FIXME this is broken: tokenmap::wordlist is not indexed by Token!
72 if ( Token >= 0 || Token < OOXML_FAST_TOKENS_END )
73 {
74 static ::rtl::OUString aTokens[OOXML_FAST_TOKENS_END];
75
76 if (aTokens[Token].getLength() == 0)
77 aTokens[Token] = ::rtl::OUString::createFromAscii
78 (tokenmap::wordlist[Token].name);
79 }
80 #else
81 (void) Token;
82 #endif
83
84 return sResult;
85 }
86
getUTF8Identifier(::sal_Int32 Token)87 css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifier(::sal_Int32 Token)
88 throw (css::uno::RuntimeException)
89 {
90 #if 0
91 if ( Token < 0 || Token >= OOXML_FAST_TOKENS_END )
92 #endif
93 return css::uno::Sequence< ::sal_Int8 >();
94
95 #if 0
96 //FIXME this is broken: tokenmap::wordlist is not indexed by Token!
97 return css::uno::Sequence< ::sal_Int8 >(reinterpret_cast< const sal_Int8 *>(tokenmap::wordlist[Token].name), strlen(tokenmap::wordlist[Token].name));
98 #else
99 (void) Token;
100 #endif
101 }
102
getTokenFromUTF8(const css::uno::Sequence<::sal_Int8> & Identifier)103 ::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8
104 (const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException)
105 {
106 ::sal_Int32 nResult = OOXML_FAST_TOKENS_END;
107
108 struct tokenmap::token * pToken =
109 tokenmap::Perfect_Hash::in_word_set
110 (reinterpret_cast<const char *>(Identifier.getConstArray()),
111 Identifier.getLength());
112
113 if (pToken != NULL)
114 nResult = pToken->nToken;
115
116 #ifdef DEBUG_TOKEN
117 clog << "getTokenFromUTF8: "
118 << string(reinterpret_cast<const char *>
119 (Identifier.getConstArray()), Identifier.getLength())
120 << ", " << nResult
121 << (pToken == NULL ? ", failed" : "") << endl;
122 #endif
123
124 return nResult;
125 }
126
127 }}
128