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