1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include "sal/config.h"
34 #include <osl/process.h>
35 #include <rtl/strbuf.hxx>
36 #include <rtl/ustring.hxx>
37 #include <sal/macros.h>
47 /*****************************************************************************/
49 /*****************************************************************************/
52 // delete existing res. of type StringList
53 for ( size_t i
= 0; i
< pStringList
->size(); i
++ ) {
54 ExportListEntry
* test
= (*pStringList
)[ i
];
55 if( test
!= NULL
) delete test
;
60 // delete existing res. of type FilterList
61 for ( size_t i
= 0; i
< pFilterList
->size(); i
++ ) {
62 ExportListEntry
* test
= (*pFilterList
)[ i
];
68 // delete existing res. of type ItemList
69 for ( size_t i
= 0; i
< pItemList
->size(); i
++ ) {
70 ExportListEntry
* test
= (*pItemList
)[ i
];
76 // delete existing res. of type UIEntries
77 for ( size_t i
= 0; i
< pUIEntries
->size(); i
++ ) {
78 ExportListEntry
* test
= (*pUIEntries
)[ i
];
89 /*****************************************************************************/
90 rtl::OString
Export::sLanguages
;
91 rtl::OString
Export::sForcedLanguages
;
92 /*****************************************************************************/
94 /*****************************************************************************/
95 void Export::SetLanguages( std::vector
<rtl::OString
> val
){
96 /*****************************************************************************/
100 /*****************************************************************************/
101 std::vector
<rtl::OString
> Export::GetLanguages(){
102 /*****************************************************************************/
105 /*****************************************************************************/
106 std::vector
<rtl::OString
> Export::GetForcedLanguages(){
107 /*****************************************************************************/
108 return aForcedLanguages
;
110 std::vector
<rtl::OString
> Export::aLanguages
= std::vector
<rtl::OString
>();
111 std::vector
<rtl::OString
> Export::aForcedLanguages
= std::vector
<rtl::OString
>();
113 /*****************************************************************************/
114 rtl::OString
Export::QuoteHTML( rtl::OString
const &rString
)
115 /*****************************************************************************/
117 rtl::OStringBuffer sReturn
;
118 for ( sal_Int32 i
= 0; i
< rString
.getLength(); i
++ ) {
119 rtl::OString sTemp
= rString
.copy( i
);
120 if ( sTemp
.match( "<Arg n=" ) ) {
121 while ( i
< rString
.getLength() && rString
[i
] != '>' ) {
122 sReturn
.append(rString
[i
]);
125 if ( rString
[i
] == '>' ) {
130 if ( i
< rString
.getLength()) {
131 switch ( rString
[i
]) {
133 sReturn
.append("<");
137 sReturn
.append(">");
141 sReturn
.append(""");
145 sReturn
.append("'");
149 if ((( i
+ 4 ) < rString
.getLength()) &&
150 ( rString
.copy( i
, 5 ) == "&" ))
151 sReturn
.append(rString
[i
]);
153 sReturn
.append("&");
157 sReturn
.append(rString
[i
]);
162 return sReturn
.makeStringAndClear();
165 void Export::RemoveUTF8ByteOrderMarker( rtl::OString
&rString
)
167 if( hasUTF8ByteOrderMarker( rString
) )
168 rString
= rString
.copy(3);
171 bool Export::hasUTF8ByteOrderMarker( const rtl::OString
&rString
)
173 return rString
.getLength() >= 3 && rString
[0] == '\xEF' &&
174 rString
[1] == '\xBB' && rString
[2] == '\xBF' ;
177 /*****************************************************************************/
178 rtl::OString
Export::UnquoteHTML( rtl::OString
const &rString
)
179 /*****************************************************************************/
181 rtl::OStringBuffer sReturn
;
182 for (sal_Int32 i
= 0; i
!= rString
.getLength();) {
183 if (rString
.match("&", i
)) {
185 i
+= RTL_CONSTASCII_LENGTH("&");
186 } else if (rString
.match("<", i
)) {
188 i
+= RTL_CONSTASCII_LENGTH("<");
189 } else if (rString
.match(">", i
)) {
191 i
+= RTL_CONSTASCII_LENGTH(">");
192 } else if (rString
.match(""", i
)) {
194 i
+= RTL_CONSTASCII_LENGTH(""");
195 } else if (rString
.match("'", i
)) {
196 sReturn
.append('\'');
197 i
+= RTL_CONSTASCII_LENGTH("'");
199 sReturn
.append(rString
[i
]);
203 return sReturn
.makeStringAndClear();
206 bool Export::isSourceLanguage(const rtl::OString
&rLanguage
)
208 return !isAllowed(rLanguage
);
211 bool Export::isAllowed(const rtl::OString
&rLanguage
)
213 return !rLanguage
.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"));
216 bool Export::isInitialized
= false;
218 /*****************************************************************************/
219 void Export::InitLanguages( bool bMergeMode
){
220 /*****************************************************************************/
224 OStringBoolHashMap aEnvLangs
;
226 sal_Int32 nIndex
= 0;
229 rtl::OString aToken
= sLanguages
.getToken(0, ',', nIndex
);
230 sTmp
= aToken
.getToken(0, '=').trim();
231 if( bMergeMode
&& !isAllowed( sTmp
) ){}
232 else if( !( (sTmp
[0]=='x' || sTmp
[0]=='X') && sTmp
[1]=='-' ) ){
233 aLanguages
.push_back( sTmp
);
236 while ( nIndex
>= 0 );
238 InitForcedLanguages( bMergeMode
);
239 isInitialized
= true;
242 /*****************************************************************************/
243 void Export::InitForcedLanguages( bool bMergeMode
){
244 /*****************************************************************************/
246 OStringBoolHashMap aEnvLangs
;
248 sal_Int32 nIndex
= 0;
251 rtl::OString aToken
= sForcedLanguages
.getToken(0, ',', nIndex
);
253 sTmp
= aToken
.getToken(0, '=').trim();
254 if( bMergeMode
&& isAllowed( sTmp
) ){}
255 else if( !( (sTmp
[0]=='x' || sTmp
[0]=='X') && sTmp
[1]=='-' ) )
256 aForcedLanguages
.push_back( sTmp
);
258 while ( nIndex
>= 0 );
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */