xref: /trunk/main/sw/source/filter/html/htmlfld.cxx (revision 3b32dd21)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 
29 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
30 #include <com/sun/star/document/XDocumentProperties.hpp>
31 
32 #include "docsh.hxx"
33 #include <svtools/htmltokn.h>
34 #include <svl/zformat.hxx>
35 #include <unotools/useroptions.hxx>
36 #include <fmtfld.hxx>
37 #include <ndtxt.hxx>
38 #include <doc.hxx>
39 #include <fldbas.hxx>
40 #include <docufld.hxx>
41 #include <flddat.hxx>
42 #include <htmlfld.hxx>
43 #include <swhtml.hxx>
44 
45 using namespace nsSwDocInfoSubType;
46 using namespace ::com::sun::star;
47 
48 struct HTMLNumFmtTblEntry
49 {
50 	const sal_Char *pName;
51 	NfIndexTableOffset eFmt;
52 };
53 
54 static HTMLOptionEnum __FAR_DATA aHTMLFldTypeTable[] =
55 {
56 	{ OOO_STRING_SW_HTML_FT_author,	RES_AUTHORFLD		},
57 	{ OOO_STRING_SW_HTML_FT_sender,	RES_EXTUSERFLD		},
58 	{ "DATE",    RES_DATEFLD			},
59 	{ "TIME",    RES_TIMEFLD			},
60 	{ OOO_STRING_SW_HTML_FT_datetime,RES_DATETIMEFLD		},
61 	{ OOO_STRING_SW_HTML_FT_page,	RES_PAGENUMBERFLD	},
62 	{ OOO_STRING_SW_HTML_FT_docinfo, RES_DOCINFOFLD		},
63 	{ OOO_STRING_SW_HTML_FT_docstat, RES_DOCSTATFLD		},
64 	{ OOO_STRING_SW_HTML_FT_filename,RES_FILENAMEFLD		},
65 	{ 0,				0					}
66 };
67 
68 static HTMLNumFmtTblEntry __FAR_DATA aHTMLDateFldFmtTable[] =
69 {
70 	{ "SSYS", 		NF_DATE_SYSTEM_SHORT 	},
71 	{ "LSYS", 		NF_DATE_SYSTEM_LONG 	},
72 	{ "DMY", 		NF_DATE_SYS_DDMMYY, 	},
73 	{ "DMYY", 		NF_DATE_SYS_DDMMYYYY, 	},
74 	{ "DMMY", 		NF_DATE_SYS_DMMMYY, 	},
75 	{ "DMMYY", 		NF_DATE_SYS_DMMMYYYY, 	},
76 	{ "DMMMY", 		NF_DATE_DIN_DMMMMYYYY 	},
77 	{ "DMMMYY", 		NF_DATE_DIN_DMMMMYYYY 	},
78 	{ "DDMMY", 		NF_DATE_SYS_NNDMMMYY 	},
79 	{ "DDMMMY", 		NF_DATE_SYS_NNDMMMMYYYY },
80 	{ "DDMMMYY", 	NF_DATE_SYS_NNDMMMMYYYY },
81 	{ "DDDMMMY", 	NF_DATE_SYS_NNNNDMMMMYYYY },
82 	{ "DDDMMMYY", 	NF_DATE_SYS_NNNNDMMMMYYYY },
83 	{ "MY", 			NF_DATE_SYS_MMYY 		},
84 	{ "MD", 			NF_DATE_DIN_MMDD 		},
85 	{ "YMD", 		NF_DATE_DIN_YYMMDD 		},
86 	{ "YYMD", 		NF_DATE_DIN_YYYYMMDD 	},
87 	{ 0,					NF_NUMERIC_START }
88 };
89 
90 static HTMLNumFmtTblEntry __FAR_DATA aHTMLTimeFldFmtTable[] =
91 {
92 	{ "SYS", 	 NF_TIME_HHMMSS },
93 	{ "SSMM24", 	 NF_TIME_HHMM },
94 	{ "SSMM12", 	 NF_TIME_HHMMAMPM },
95 	{ 0,				 NF_NUMERIC_START }
96 };
97 
98 static HTMLOptionEnum __FAR_DATA aHTMLPageNumFldFmtTable[] =
99 {
100 	{ OOO_STRING_SW_HTML_FF_uletter, 	 SVX_NUM_CHARS_UPPER_LETTER },
101 	{ OOO_STRING_SW_HTML_FF_lletter, 	 SVX_NUM_CHARS_LOWER_LETTER },
102 	{ OOO_STRING_SW_HTML_FF_uroman, 		 SVX_NUM_ROMAN_UPPER },
103 	{ OOO_STRING_SW_HTML_FF_lroman, 		 SVX_NUM_ROMAN_LOWER },
104 	{ OOO_STRING_SW_HTML_FF_arabic,	 	 SVX_NUM_ARABIC },
105 	{ OOO_STRING_SW_HTML_FF_none, 		 SVX_NUM_NUMBER_NONE },
106 	{ OOO_STRING_SW_HTML_FF_char, 		 SVX_NUM_CHAR_SPECIAL },
107 	{ OOO_STRING_SW_HTML_FF_page, 		 SVX_NUM_PAGEDESC },
108 	{ OOO_STRING_SW_HTML_FF_ulettern, 	 SVX_NUM_CHARS_UPPER_LETTER_N },
109 	{ OOO_STRING_SW_HTML_FF_llettern, 	 SVX_NUM_CHARS_LOWER_LETTER_N },
110 	{ 0,					 0 }
111 };
112 
113 
114 static HTMLOptionEnum __FAR_DATA aHTMLExtUsrFldSubTable[] =
115 {
116 	{ OOO_STRING_SW_HTML_FS_company,		 EU_COMPANY },
117 	{ OOO_STRING_SW_HTML_FS_firstname,	 EU_FIRSTNAME },
118 	{ OOO_STRING_SW_HTML_FS_name,		 EU_NAME },
119 	{ OOO_STRING_SW_HTML_FS_shortcut,	 EU_SHORTCUT },
120 	{ OOO_STRING_SW_HTML_FS_street,		 EU_STREET },
121 	{ OOO_STRING_SW_HTML_FS_country,      EU_COUNTRY },
122 	{ OOO_STRING_SW_HTML_FS_zip,          EU_ZIP },
123 	{ OOO_STRING_SW_HTML_FS_city,         EU_CITY },
124 	{ OOO_STRING_SW_HTML_FS_title,        EU_TITLE },
125 	{ OOO_STRING_SW_HTML_FS_position,     EU_POSITION },
126 	{ OOO_STRING_SW_HTML_FS_pphone,       EU_PHONE_PRIVATE },
127 	{ OOO_STRING_SW_HTML_FS_cphone,       EU_PHONE_COMPANY },
128 	{ OOO_STRING_SW_HTML_FS_fax,          EU_FAX },
129 	{ OOO_STRING_SW_HTML_FS_email,        EU_EMAIL },
130 	{ OOO_STRING_SW_HTML_FS_state,        EU_STATE },
131 	{ 0,					 0 }
132 };
133 
134 static HTMLOptionEnum __FAR_DATA aHTMLAuthorFldFmtTable[] =
135 {
136 	{ OOO_STRING_SW_HTML_FF_name,		 AF_NAME },
137 	{ OOO_STRING_SW_HTML_FF_shortcut,	 AF_SHORTCUT },
138 	{ 0,					 0 }
139 };
140 
141 static HTMLOptionEnum __FAR_DATA aHTMLPageNumFldSubTable[] =
142 {
143 	{ OOO_STRING_SW_HTML_FS_random,		 PG_RANDOM },
144 	{ OOO_STRING_SW_HTML_FS_next,		 PG_NEXT },
145 	{ OOO_STRING_SW_HTML_FS_prev,		 PG_PREV },
146 	{ 0,					 0	}
147 };
148 
149 // UGLY: these are extensions of nsSwDocInfoSubType (in inc/docufld.hxx)
150 //       these are necessary for importing document info fields written by
151 //       older versions of OOo (< 3.0) which did not have DI_CUSTOM fields
152 	const SwDocInfoSubType DI_INFO1			=  DI_SUBTYPE_END + 1;
153 	const SwDocInfoSubType DI_INFO2			=  DI_SUBTYPE_END + 2;
154 	const SwDocInfoSubType DI_INFO3			=  DI_SUBTYPE_END + 3;
155 	const SwDocInfoSubType DI_INFO4			=  DI_SUBTYPE_END + 4;
156 
157 static HTMLOptionEnum __FAR_DATA aHTMLDocInfoFldSubTable[] =
158 {
159 	{ OOO_STRING_SW_HTML_FS_title, 	 DI_TITEL },
160 	{ OOO_STRING_SW_HTML_FS_theme, 	 DI_THEMA },
161 	{ OOO_STRING_SW_HTML_FS_keys, 	 DI_KEYS },
162 	{ OOO_STRING_SW_HTML_FS_comment,  DI_COMMENT },
163 	{ "INFO1", 	 DI_INFO1 },
164 	{ "INFO2", 	 DI_INFO2 },
165 	{ "INFO3", 	 DI_INFO3 },
166 	{ "INFO4", 	 DI_INFO4 },
167 	{ OOO_STRING_SW_HTML_FS_custom, 	 DI_CUSTOM },
168 	{ OOO_STRING_SW_HTML_FS_create, 	 DI_CREATE },
169 	{ OOO_STRING_SW_HTML_FS_change, 	 DI_CHANGE },
170 	{ 0,				 0 }
171 };
172 
173 static HTMLOptionEnum __FAR_DATA aHTMLDocInfoFldFmtTable[] =
174 {
175 	{ OOO_STRING_SW_HTML_FF_author, 	 DI_SUB_AUTHOR },
176 	{ OOO_STRING_SW_HTML_FF_time, 	 DI_SUB_TIME },
177 	{ OOO_STRING_SW_HTML_FF_date, 	 DI_SUB_DATE },
178 	{ 0,				 0 }
179 };
180 
181 static HTMLOptionEnum __FAR_DATA aHTMLDocStatFldSubTable[] =
182 {
183 	{ OOO_STRING_SW_HTML_FS_page, 	 DS_PAGE },
184 	{ OOO_STRING_SW_HTML_FS_para, 	 DS_PARA },
185 	{ OOO_STRING_SW_HTML_FS_word, 	 DS_WORD },
186 	{ OOO_STRING_SW_HTML_FS_char, 	 DS_CHAR },
187 	{ OOO_STRING_SW_HTML_FS_tbl, 	 DS_TBL },
188 	{ OOO_STRING_SW_HTML_FS_grf, 	 DS_GRF },
189 	{ OOO_STRING_SW_HTML_FS_ole, 	 DS_OLE },
190 	{ 0,				 0 }
191 };
192 
193 static HTMLOptionEnum __FAR_DATA aHTMLFileNameFldFmtTable[] =
194 {
195 	{ OOO_STRING_SW_HTML_FF_name, 	 	FF_NAME },
196 	{ OOO_STRING_SW_HTML_FF_pathname, 	FF_PATHNAME },
197 	{ OOO_STRING_SW_HTML_FF_path, 	 	FF_PATH },
198 	{ OOO_STRING_SW_HTML_FF_name_noext,	FF_NAME_NOEXT },
199 	{ 0,				 	0 }
200 };
201 
202 /*  */
203 
GetNumType(const String & rStr,sal_uInt16 nDfltType)204 sal_uInt16 SwHTMLParser::GetNumType( const String& rStr, sal_uInt16 nDfltType )
205 {
206 	sal_uInt16 nType = nDfltType;
207 	const HTMLOptionEnum *pOptEnums = aHTMLPageNumFldFmtTable;
208 	while( pOptEnums->pName )
209 		if( !rStr.EqualsIgnoreCaseAscii( pOptEnums->pName ) )
210 			pOptEnums++;
211 		else
212 			break;
213 
214 	if( pOptEnums->pName )
215 		nType = pOptEnums->nValue;
216 
217 	return nType;
218 }
219 
220 
NewField()221 void SwHTMLParser::NewField()
222 {
223 	sal_Bool bKnownType = sal_False, bFixed = sal_False,
224 		 bHasNumFmt = sal_False, bHasNumValue = sal_False;
225     sal_uInt16 nType = 0;
226 	String aValue, aNumFmt, aNumValue, aName;
227 	const HTMLOption *pSubOption=0, *pFmtOption=0;
228 
229 	const HTMLOptions *pHTMLOptions = GetOptions();
230 	sal_uInt16 i;
231 
232 	for( i = pHTMLOptions->Count(); i; )
233 	{
234 		const HTMLOption *pOption = (*pHTMLOptions)[--i];
235 		switch( pOption->GetToken() )
236 		{
237 		case HTML_O_TYPE:
238 			bKnownType = pOption->GetEnum( nType, aHTMLFldTypeTable );
239 			break;
240 		case HTML_O_SUBTYPE:
241 			pSubOption = pOption;
242 			break;
243 		case HTML_O_FORMAT:
244 			pFmtOption = pOption;
245 			break;
246 		case HTML_O_NAME:
247 			aName = pOption->GetString();
248 			break;
249 		case HTML_O_VALUE:
250 			aValue = pOption->GetString();
251 			break;
252 		case HTML_O_SDNUM:
253 			aNumFmt = pOption->GetString();
254 			bHasNumFmt = sal_True;
255 			break;
256 		case HTML_O_SDVAL:
257 			aNumValue = pOption->GetString();
258 			bHasNumValue = sal_True;
259 			break;
260 		case HTML_O_SDFIXED:
261 			bFixed = sal_True;
262 			break;
263 		}
264 	}
265 
266 	if( !bKnownType )
267 		return;
268 
269 	// Autor und Absender werden nur als als variables Feld eingefuegt,
270 	// wenn man das Dok selbst als letztes geaendert hat oder es noch
271 	// niemend geandert hat und man das Dok erstellt hat. Sonst
272 	// wird ein Fixed-Feld daraus gemacht.
273 	if( !bFixed &&
274 		(RES_EXTUSERFLD == (RES_FIELDS)nType ||
275 		 RES_AUTHORFLD == (RES_FIELDS)nType) )
276 	{
277 		SvtUserOptions aOpt;
278 		const String& rUser = aOpt.GetFullName();
279         SwDocShell *pDocShell(pDoc->GetDocShell());
280         DBG_ASSERT(pDocShell, "no SwDocShell");
281         if (pDocShell) {
282             uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
283                 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
284             uno::Reference<document::XDocumentProperties> xDocProps(
285                 xDPS->getDocumentProperties());
286             DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
287             const String& rChanged = xDocProps->getModifiedBy();
288             const String& rCreated = xDocProps->getAuthor();
289             if( !rUser.Len() ||
290                 (rChanged.Len() ? rUser != rChanged : rUser != rCreated) )
291                 bFixed = sal_True;
292         }
293 	}
294 
295 	sal_uInt16 nWhich = nType;
296 	if( RES_DATEFLD==nType || RES_TIMEFLD==nType )
297 		nWhich = RES_DATETIMEFLD;
298 
299 	SwFieldType* pType = pDoc->GetSysFldType( nWhich );
300 	SwField *pFld = 0;
301 	sal_Bool bInsOnEndTag = sal_False;
302 
303 	switch( (RES_FIELDS)nType )
304 	{
305 	case RES_EXTUSERFLD:
306 		if( pSubOption )
307 		{
308 			sal_uInt16 nSub;
309 			sal_uLong nFmt = 0;
310 			if( bFixed )
311 			{
312 				nFmt |= AF_FIXED;
313 				bInsOnEndTag = sal_True;
314 			}
315 			if( pSubOption->GetEnum( nSub, aHTMLExtUsrFldSubTable ) )
316 				pFld = new SwExtUserField( (SwExtUserFieldType*)pType,
317 										   nSub, nFmt );
318 		}
319 		break;
320 
321 	case RES_AUTHORFLD:
322 		{
323 			sal_uInt16 nFmt = AF_NAME;
324 			if( pFmtOption )
325 				pFmtOption->GetEnum( nFmt, aHTMLAuthorFldFmtTable );
326 			if( bFixed )
327 			{
328 				nFmt |= AF_FIXED;
329 				bInsOnEndTag = sal_True;
330 			}
331 
332 			pFld = new SwAuthorField( (SwAuthorFieldType *)pType, nFmt );
333 		}
334 		break;
335 
336 	case RES_DATEFLD:
337 	case RES_TIMEFLD:
338 		{
339             sal_uLong nNumFmt = 0;
340 			sal_uLong nTime = Time().GetTime(), nDate = Date().GetDate();
341             sal_uInt16 nSub = 0;
342 			sal_Bool bValidFmt = sal_False;
343 			HTMLNumFmtTblEntry * pFmtTbl;
344 
345 			if( RES_DATEFLD==nType )
346 			{
347 				nSub = DATEFLD;
348 				pFmtTbl = aHTMLDateFldFmtTable;
349 				if( aValue.Len() )
350 					nDate = (sal_uLong)aValue.ToInt32();
351 			}
352 			else
353 			{
354 				nSub = TIMEFLD;
355 				pFmtTbl = aHTMLTimeFldFmtTable;
356 				if( aValue.Len() )
357 					nTime = (sal_uLong)aValue.ToInt32();
358 			}
359 			if( aValue.Len() )
360 				nSub |= FIXEDFLD;
361 
362 			SvNumberFormatter *pFormatter =	pDoc->GetNumberFormatter();
363 			if( pFmtOption )
364 			{
365 				const String& rFmt = pFmtOption->GetString();
366 				for( sal_uInt16 k = 0; pFmtTbl[k].pName; k++ )
367 				{
368 					if( rFmt.EqualsIgnoreCaseAscii( pFmtTbl[k].pName ) )
369 					{
370 						nNumFmt = pFormatter->GetFormatIndex(
371 										pFmtTbl[k].eFmt, LANGUAGE_SYSTEM);
372 						bValidFmt = sal_True;
373 						break;
374 					}
375 				}
376 			}
377 			if( !bValidFmt )
378 				nNumFmt = pFormatter->GetFormatIndex( pFmtTbl[i].eFmt,
379 													  LANGUAGE_SYSTEM);
380 
381 			pFld = new SwDateTimeField( (SwDateTimeFieldType *)pType,
382 										  nSub, nNumFmt );
383 
384 			if (nSub & FIXEDFLD)
385                 ((SwDateTimeField *)pFld)->SetDateTime( DateTime(Date(nDate), Time(nTime)) );
386 		}
387 		break;
388 
389 	case RES_DATETIMEFLD:
390 		if( bHasNumFmt )
391 		{
392 			sal_uInt16 nSub = 0;
393 
394 			SvNumberFormatter *pFormatter =	pDoc->GetNumberFormatter();
395 			sal_uInt32 nNumFmt;
396 			LanguageType eLang;
397 			double dValue = GetTableDataOptionsValNum(
398 								nNumFmt, eLang, aNumValue, aNumFmt,
399 								*pDoc->GetNumberFormatter() );
400 			short nFmtType = pFormatter->GetType( nNumFmt );
401 			switch( nFmtType )
402 			{
403 			case NUMBERFORMAT_DATE:	nSub = DATEFLD;	break;
404 			case NUMBERFORMAT_TIME: nSub = TIMEFLD; break;
405 			}
406 
407 			if( nSub )
408 			{
409 				if( bHasNumValue )
410 					nSub |= FIXEDFLD;
411 
412 				pFld = new SwDateTimeField( (SwDateTimeFieldType *)pType,
413 												  nSub, nNumFmt );
414 				if( bHasNumValue )
415 					((SwDateTimeField *)pFld)->SetValue( dValue );
416 			}
417 		}
418 		break;
419 
420 	case RES_PAGENUMBERFLD:
421 		if( pSubOption )
422 		{
423 			sal_uInt16 nSub;
424 			if( pSubOption->GetEnum( nSub, aHTMLPageNumFldSubTable ) )
425 			{
426 				sal_uInt16 nFmt = SVX_NUM_PAGEDESC;
427 				if( pFmtOption )
428 					pFmtOption->GetEnum( nFmt, aHTMLPageNumFldFmtTable );
429 
430 				short nOff = 0;
431 
432 				if( (SvxExtNumType)nFmt!=SVX_NUM_CHAR_SPECIAL && aValue.Len() )
433 					nOff = (short)aValue.ToInt32();
434 				else if( (SwPageNumSubType)nSub == PG_NEXT  )
435 					nOff = 1;
436 				else if( (SwPageNumSubType)nSub == PG_PREV  )
437 					nOff = -1;
438 
439 				if( (SvxExtNumType)nFmt==SVX_NUM_CHAR_SPECIAL &&
440 					(SwPageNumSubType)nSub==PG_RANDOM )
441 					nFmt = SVX_NUM_PAGEDESC;
442 
443 				pFld = new SwPageNumberField( (SwPageNumberFieldType *)pType, nSub, nFmt, nOff );
444 				if( (SvxExtNumType)nFmt==SVX_NUM_CHAR_SPECIAL )
445 					((SwPageNumberField *)pFld)->SetUserString( aValue );
446 			}
447 		}
448 		break;
449 
450 	case RES_DOCINFOFLD:
451 		if( pSubOption )
452 		{
453 			sal_uInt16 nSub;
454 			if( pSubOption->GetEnum( nSub, aHTMLDocInfoFldSubTable ) )
455 			{
456 				sal_uInt16 nExtSub = 0;
457 				if( DI_CREATE==(SwDocInfoSubType)nSub ||
458 					DI_CHANGE==(SwDocInfoSubType)nSub )
459 				{
460 					nExtSub = DI_SUB_AUTHOR;
461 					if( pFmtOption )
462 						pFmtOption->GetEnum( nExtSub, aHTMLDocInfoFldFmtTable );
463 					nSub |= nExtSub;
464 				}
465 
466 				sal_uInt32 nNumFmt = 0;
467 				double dValue = 0;
468 				if( bHasNumFmt && (DI_SUB_DATE==nExtSub || DI_SUB_TIME==nExtSub) )
469 				{
470 					LanguageType eLang;
471 					dValue = GetTableDataOptionsValNum(
472 									nNumFmt, eLang, aNumValue, aNumFmt,
473 									*pDoc->GetNumberFormatter() );
474 					bFixed &= bHasNumValue;
475 				}
476 				else
477 					bHasNumValue = sal_False;
478 
479                 if( nSub >= DI_INFO1 && nSub <= DI_INFO4 && aName.Len() == 0 )
480                 {
481                     // backward compatibility for OOo 2:
482                     // map to names stored in AddMetaUserDefined
483                     aName = m_InfoNames[nSub - DI_INFO1];
484                     nSub = DI_CUSTOM;
485                 }
486 
487 				if( bFixed )
488 				{
489 					nSub |= DI_SUB_FIXED;
490 					bInsOnEndTag = sal_True;
491 				}
492 
493 				pFld = new SwDocInfoField( (SwDocInfoFieldType *)pType,
494 											 nSub, aName, nNumFmt );
495 				if( bHasNumValue )
496 					((SwDocInfoField*)pFld)->SetValue( dValue );
497 			}
498 		}
499 		break;
500 
501 	case RES_DOCSTATFLD:
502 		if( pSubOption )
503 		{
504 			sal_uInt16 nSub;
505 			if( pSubOption->GetEnum( nSub, aHTMLDocStatFldSubTable ) )
506 			{
507 				sal_uInt16 nFmt = SVX_NUM_ARABIC;
508 				if( pFmtOption )
509 					pFmtOption->GetEnum( nFmt, aHTMLPageNumFldFmtTable );
510 				pFld = new SwDocStatField( (SwDocStatFieldType *)pType,
511 											 nSub, nFmt );
512 				bUpdateDocStat |= (DS_PAGE != nFmt);
513 			}
514 		}
515 		break;
516 
517 	case RES_FILENAMEFLD:
518 		{
519 			sal_uInt16 nFmt = FF_NAME;
520 			if( pFmtOption )
521 				pFmtOption->GetEnum( nFmt, aHTMLFileNameFldFmtTable );
522 			if( bFixed )
523 			{
524 				nFmt |= FF_FIXED;
525 				bInsOnEndTag = sal_True;
526 			}
527 
528 			pFld = new SwFileNameField( (SwFileNameFieldType *)pType, nFmt );
529 		}
530 		break;
531 	default:
532 		;
533 	}
534 
535 	if( pFld )
536 	{
537 		if( bInsOnEndTag )
538 		{
539 			pField = pFld;
540 		}
541 		else
542 		{
543             pDoc->InsertPoolItem( *pPam, SwFmtFld(*pFld), 0 );
544 			delete pFld;
545 		}
546 		bInField = sal_True;
547 	}
548 }
549 
EndField()550 void SwHTMLParser::EndField()
551 {
552 	if( pField )
553 	{
554 		switch( pField->Which() )
555 		{
556 		case RES_DOCINFOFLD:
557 			ASSERT( ((SwDocInfoField*)pField)->IsFixed(),
558 					"DokInfo-Feld haette nicht gemerkt werden muessen" );
559 			((SwDocInfoField*)pField)->SetExpansion( aContents );
560 			break;
561 
562 		case RES_EXTUSERFLD:
563 			ASSERT( ((SwExtUserField*)pField)->IsFixed(),
564 					"ExtUser-Feld haette nicht gemerkt werden muessen" );
565 			((SwExtUserField*)pField)->SetExpansion( aContents );
566 			break;
567 
568 		case RES_AUTHORFLD:
569 			ASSERT( ((SwAuthorField*)pField)->IsFixed(),
570 					"Author-Feld haette nicht gemerkt werden muessen" );
571 			((SwAuthorField*)pField)->SetExpansion( aContents );
572 			break;
573 
574 		case RES_FILENAMEFLD:
575 			ASSERT( ((SwFileNameField*)pField)->IsFixed(),
576 					"FileName-Feld haette nicht gemerkt werden muessen" );
577 			((SwFileNameField*)pField)->SetExpansion( aContents );
578 			break;
579 		}
580 
581         pDoc->InsertPoolItem( *pPam, SwFmtFld(*pField), 0 );
582 		delete pField;
583 		pField = 0;
584 	}
585 
586 	bInField = sal_False;
587 	aContents.Erase();
588 }
589 
InsertFieldText()590 void SwHTMLParser::InsertFieldText()
591 {
592 	if( pField )
593 	{
594 		// das aktuelle Textstueck an den Text anhaengen
595 		aContents += aToken;
596 	}
597 }
598 
InsertCommentText(const sal_Char * pTag)599 void SwHTMLParser::InsertCommentText( const sal_Char *pTag )
600 {
601 	sal_Bool bEmpty = aContents.Len() == 0;
602 	if( !bEmpty )
603 		aContents += '\n';
604 
605 	aContents += aToken;
606 	if( bEmpty && pTag )
607 	{
608 		String aTmp( aContents );
609 		aContents.AssignAscii( "HTML: <" );
610 		aContents.AppendAscii( pTag );
611 		aContents.Append( '>' );
612 		aContents.Append( aTmp );
613 	}
614 }
615 
InsertComment(const String & rComment,const sal_Char * pTag)616 void SwHTMLParser::InsertComment( const String& rComment, const sal_Char *pTag )
617 {
618     String aComment( rComment );
619     if( pTag )
620     {
621         aComment.AppendAscii( "</" );
622         aComment.AppendAscii( pTag );
623         aComment.Append( '>' );
624     }
625 
626     // MIB 24.06.97: Wenn ein PostIt nach einen Space eingefuegt
627     // werden soll, fuegen wir es vor dem Space ein. Dann gibt es
628     // weniger Probleme beim Formatieren (bug #40483#)
629     xub_StrLen nPos = pPam->GetPoint()->nContent.GetIndex();
630     SwTxtNode *pTxtNd = pPam->GetNode()->GetTxtNode();
631     sal_Bool bMoveFwd = sal_False;
632     if( nPos>0 && pTxtNd && ' '==pTxtNd->GetTxt().GetChar(nPos-1) )
633     {
634         bMoveFwd = sal_True;
635 
636         sal_uLong nNodeIdx = pPam->GetPoint()->nNode.GetIndex();
637         xub_StrLen nIdx = pPam->GetPoint()->nContent.GetIndex();
638         for( sal_uInt16 i = aSetAttrTab.Count(); i > 0; )
639         {
640             _HTMLAttr *pAttr = aSetAttrTab[--i];
641             if( pAttr->GetSttParaIdx() != nNodeIdx ||
642                 pAttr->GetSttCnt() != nIdx )
643                 break;
644 
645             if( RES_TXTATR_FIELD == pAttr->pItem->Which() &&
646                 RES_SCRIPTFLD == ((const SwFmtFld *)pAttr->pItem)->GetField()->GetTyp()->Which() )
647             {
648                 bMoveFwd = sal_False;
649                 break;
650             }
651         }
652 
653         if( bMoveFwd )
654             pPam->Move( fnMoveBackward );
655     }
656 
657     SwPostItField aPostItFld(
658         (SwPostItFieldType*)pDoc->GetSysFldType( RES_POSTITFLD ),
659         aComment,
660         aEmptyStr,
661         aEmptyStr,
662         aEmptyStr,
663         DateTime() );
664     InsertAttr( SwFmtFld( aPostItFld ) );
665 
666     if( bMoveFwd )
667         pPam->Move( fnMoveForward );
668 }
669 
670