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 : :
29 : : #include "sal/config.h"
30 : :
31 : : #include "export.hxx"
32 : : #include <stdio.h>
33 : : #include <osl/time.h>
34 : : #include <osl/process.h>
35 : : #include <rtl/strbuf.hxx>
36 : : #include <rtl/ustring.hxx>
37 : : #include <sal/macros.h>
38 : : #include <iostream>
39 : : #include <iomanip>
40 : : #include <time.h>
41 : : #include <stdlib.h>
42 : :
43 : : //
44 : : // class ResData();
45 : : //
46 : :
47 : : /*****************************************************************************/
48 : 0 : ResData::~ResData()
49 : : /*****************************************************************************/
50 : : {
51 : 0 : if ( pStringList ) {
52 : : // delete existing res. of type StringList
53 : 0 : for ( size_t i = 0; i < pStringList->size(); i++ ) {
54 : 0 : ExportListEntry* test = (*pStringList)[ i ];
55 : 0 : if( test != NULL ) delete test;
56 : : }
57 : 0 : delete pStringList;
58 : : }
59 : 0 : if ( pFilterList ) {
60 : : // delete existing res. of type FilterList
61 : 0 : for ( size_t i = 0; i < pFilterList->size(); i++ ) {
62 : 0 : ExportListEntry* test = (*pFilterList)[ i ];
63 : 0 : delete test;
64 : : }
65 : 0 : delete pFilterList;
66 : : }
67 : 0 : if ( pItemList ) {
68 : : // delete existing res. of type ItemList
69 : 0 : for ( size_t i = 0; i < pItemList->size(); i++ ) {
70 : 0 : ExportListEntry* test = (*pItemList)[ i ];
71 : 0 : delete test;
72 : : }
73 : 0 : delete pItemList;
74 : : }
75 : 0 : if ( pUIEntries ) {
76 : : // delete existing res. of type UIEntries
77 : 0 : for ( size_t i = 0; i < pUIEntries->size(); i++ ) {
78 : 0 : ExportListEntry* test = (*pUIEntries)[ i ];
79 : 0 : delete test;
80 : : }
81 : 0 : delete pUIEntries;
82 : : }
83 : 0 : }
84 : :
85 : : //
86 : : // class Export
87 : : //
88 : :
89 : : /*****************************************************************************/
90 : 0 : rtl::OString Export::sLanguages;
91 : 0 : rtl::OString Export::sForcedLanguages;
92 : : /*****************************************************************************/
93 : :
94 : : /*****************************************************************************/
95 : 0 : void Export::SetLanguages( std::vector<rtl::OString> val ){
96 : : /*****************************************************************************/
97 : 0 : aLanguages = val;
98 : 0 : isInitialized = true;
99 : 0 : }
100 : : /*****************************************************************************/
101 : 0 : std::vector<rtl::OString> Export::GetLanguages(){
102 : : /*****************************************************************************/
103 : 0 : return aLanguages;
104 : : }
105 : : /*****************************************************************************/
106 : 0 : std::vector<rtl::OString> Export::GetForcedLanguages(){
107 : : /*****************************************************************************/
108 : 0 : return aForcedLanguages;
109 : : }
110 : 0 : std::vector<rtl::OString> Export::aLanguages = std::vector<rtl::OString>();
111 : 0 : std::vector<rtl::OString> Export::aForcedLanguages = std::vector<rtl::OString>();
112 : :
113 : : /*****************************************************************************/
114 : 0 : rtl::OString Export::QuoteHTML( rtl::OString const &rString )
115 : : /*****************************************************************************/
116 : : {
117 : 0 : rtl::OStringBuffer sReturn;
118 : 0 : for ( sal_Int32 i = 0; i < rString.getLength(); i++ ) {
119 : 0 : rtl::OString sTemp = rString.copy( i );
120 : 0 : if ( sTemp.match( "<Arg n=" ) ) {
121 : 0 : while ( i < rString.getLength() && rString[i] != '>' ) {
122 : 0 : sReturn.append(rString[i]);
123 : 0 : i++;
124 : : }
125 : 0 : if ( rString[i] == '>' ) {
126 : 0 : sReturn.append('>');
127 : 0 : i++;
128 : : }
129 : : }
130 : 0 : if ( i < rString.getLength()) {
131 : 0 : switch ( rString[i]) {
132 : : case '<':
133 : 0 : sReturn.append("<");
134 : 0 : break;
135 : :
136 : : case '>':
137 : 0 : sReturn.append(">");
138 : 0 : break;
139 : :
140 : : case '\"':
141 : 0 : sReturn.append(""");
142 : 0 : break;
143 : :
144 : : case '\'':
145 : 0 : sReturn.append("'");
146 : 0 : break;
147 : :
148 : : case '&':
149 : 0 : if ((( i + 4 ) < rString.getLength()) &&
150 : 0 : ( rString.copy( i, 5 ) == "&" ))
151 : 0 : sReturn.append(rString[i]);
152 : : else
153 : 0 : sReturn.append("&");
154 : 0 : break;
155 : :
156 : : default:
157 : 0 : sReturn.append(rString[i]);
158 : 0 : break;
159 : : }
160 : : }
161 : 0 : }
162 : 0 : return sReturn.makeStringAndClear();
163 : : }
164 : :
165 : 0 : void Export::RemoveUTF8ByteOrderMarker( rtl::OString &rString )
166 : : {
167 : 0 : if( hasUTF8ByteOrderMarker( rString ) )
168 : 0 : rString = rString.copy(3);
169 : 0 : }
170 : :
171 : 0 : bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString )
172 : : {
173 : 0 : return rString.getLength() >= 3 && rString[0] == '\xEF' &&
174 : 0 : rString[1] == '\xBB' && rString[2] == '\xBF' ;
175 : : }
176 : :
177 : : /*****************************************************************************/
178 : 0 : rtl::OString Export::UnquoteHTML( rtl::OString const &rString )
179 : : /*****************************************************************************/
180 : : {
181 : 0 : rtl::OStringBuffer sReturn;
182 : 0 : for (sal_Int32 i = 0; i != rString.getLength();) {
183 : 0 : if (rString.match("&", i)) {
184 : 0 : sReturn.append('&');
185 : 0 : i += RTL_CONSTASCII_LENGTH("&");
186 : 0 : } else if (rString.match("<", i)) {
187 : 0 : sReturn.append('<');
188 : 0 : i += RTL_CONSTASCII_LENGTH("<");
189 : 0 : } else if (rString.match(">", i)) {
190 : 0 : sReturn.append('>');
191 : 0 : i += RTL_CONSTASCII_LENGTH(">");
192 : 0 : } else if (rString.match(""", i)) {
193 : 0 : sReturn.append('"');
194 : 0 : i += RTL_CONSTASCII_LENGTH(""");
195 : 0 : } else if (rString.match("'", i)) {
196 : 0 : sReturn.append('\'');
197 : 0 : i += RTL_CONSTASCII_LENGTH("'");
198 : : } else {
199 : 0 : sReturn.append(rString[i]);
200 : 0 : ++i;
201 : : }
202 : : }
203 : 0 : return sReturn.makeStringAndClear();
204 : : }
205 : :
206 : 0 : bool Export::isSourceLanguage(const rtl::OString &rLanguage)
207 : : {
208 : 0 : return !isAllowed(rLanguage);
209 : : }
210 : :
211 : 0 : bool Export::isAllowed(const rtl::OString &rLanguage)
212 : : {
213 : 0 : return !rLanguage.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"));
214 : : }
215 : :
216 : : bool Export::isInitialized = false;
217 : :
218 : : /*****************************************************************************/
219 : 0 : void Export::InitLanguages( bool bMergeMode ){
220 : : /*****************************************************************************/
221 : 0 : if( !isInitialized )
222 : : {
223 : 0 : rtl::OString sTmp;
224 : 0 : OStringBoolHashMap aEnvLangs;
225 : :
226 : 0 : sal_Int32 nIndex = 0;
227 : 0 : do
228 : : {
229 : 0 : rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
230 : 0 : sTmp = aToken.getToken(0, '=').trim();
231 : 0 : if( bMergeMode && !isAllowed( sTmp ) ){}
232 : 0 : else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
233 : 0 : aLanguages.push_back( sTmp );
234 : 0 : }
235 : : }
236 : : while ( nIndex >= 0 );
237 : :
238 : 0 : InitForcedLanguages( bMergeMode );
239 : 0 : isInitialized = true;
240 : : }
241 : 0 : }
242 : : /*****************************************************************************/
243 : 0 : void Export::InitForcedLanguages( bool bMergeMode ){
244 : : /*****************************************************************************/
245 : 0 : rtl::OString sTmp;
246 : 0 : OStringBoolHashMap aEnvLangs;
247 : :
248 : 0 : sal_Int32 nIndex = 0;
249 : 0 : do
250 : : {
251 : 0 : rtl::OString aToken = sForcedLanguages.getToken(0, ',', nIndex);
252 : :
253 : 0 : sTmp = aToken.getToken(0, '=').trim();
254 : 0 : if( bMergeMode && isAllowed( sTmp ) ){}
255 : 0 : else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) )
256 : 0 : aForcedLanguages.push_back( sTmp );
257 : : }
258 : 0 : while ( nIndex >= 0 );
259 : 0 : }
260 : :
261 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|