1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
63 #include "lwpglobalmgr.hxx"
64 #include "lwpfribtext.hxx"
65 #include "lwpcharsetmgr.hxx"
66 #include "lwphyperlinkmgr.hxx"
67 #include "lwptools.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include "xfilter/xftextspan.hxx"
70 #include "xfilter/xfbookmark.hxx"
71 #include "xfilter/xfentry.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "xfilter/xfcrossref.hxx"
74 #include "xfilter/xfpagenumber.hxx"
75 #include "xfilter/xfdocfield.hxx"
76 #include "xfilter/xfdatestyle.hxx"
77 #include "xfilter/xftimestyle.hxx"
78 #include "xfilter/xfdate.hxx"
79 #include "xfilter/xfannotation.hxx"
81 LwpFribText::LwpFribText( LwpPara
*pPara
, sal_Bool bNoUnicode
)
82 : LwpFrib(pPara
), m_bNoUnicode(bNoUnicode
)
85 void LwpFribText::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
89 rtl_TextEncoding rEncode
;
92 rEncode
= RTL_TEXTENCODING_ISO_8859_1
;
96 if (m_pModifiers
&& m_pModifiers
->CodePage
)
97 rEncode
= LwpCharSetMgr::GetInstance()->
98 GetTextCharEncoding(m_pModifiers
->CodePage
);
100 rEncode
= LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
102 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
106 void LwpFribText::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
110 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
111 if (pHyperlink
->GetHyperlinkFlag())
112 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
114 LwpFrib::ConvertChars(pXFPara
,GetText());
118 * @short: Reading mothed of paranumber frib.
119 * @param: pObjStrm wordpro object stream.
120 * @param: len length of the frib
122 void LwpFribParaNumber::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
124 pObjStrm
->QuickRead(&m_nStyleID
, sizeof(m_nStyleID
));
125 pObjStrm
->QuickRead(&m_nNumberChar
, sizeof(m_nNumberChar
));
126 pObjStrm
->QuickRead(&m_nLevel
, sizeof(m_nLevel
));
127 pObjStrm
->QuickRead(&m_nStart
, sizeof(m_nStart
));
131 * @short: default constructor of LwpFribDocVar
133 LwpFribDocVar::LwpFribDocVar(LwpPara
* pPara
)
134 : LwpFrib(pPara
), m_nType(0), m_pName(new LwpAtomHolder
)
138 * @short: destructor of LwpFribDocVar
140 LwpFribDocVar::~LwpFribDocVar()
149 * @short: Reading mothed of document variable frib.
150 * @param: pObjStrm wordpro object stream.
151 * @param: len length of the frib
153 void LwpFribDocVar::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
155 pObjStrm
->QuickRead(&m_nType
, sizeof(m_nType
));
156 m_pName
->Read(pObjStrm
);
160 * @short: register style for doc field (text style,date style)
164 void LwpFribDocVar::RegisterStyle(LwpFoundry
* pFoundry
)
166 LwpFrib::RegisterStyle(pFoundry
);
171 case DATELASTREVISION
:
173 // m_TimeStyle = LwpTools::RegisterDefaultTimeStyle();
174 RegisterDefaultTimeStyle();
178 RegisterTotalTimeStyle();
186 * @short: register default time style for doc field
190 void LwpFribDocVar::RegisterDefaultTimeStyle()
192 XFDateStyle
* pDateStyle
= new XFDateStyle
;//use the default format
194 pDateStyle
->AddMonth();
195 pDateStyle
->AddText(A2OUSTR("/"));
196 pDateStyle
->AddMonthDay();
197 pDateStyle
->AddText(A2OUSTR("/"));
198 pDateStyle
->AddYear();
199 pDateStyle
->AddText(A2OUSTR(","));
200 pDateStyle
->AddHour();
201 pDateStyle
->AddText(A2OUSTR(":"));
202 pDateStyle
->AddMinute();
203 pDateStyle
->AddText(A2OUSTR(":"));
204 pDateStyle
->AddSecond(sal_True
,0);
206 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
207 m_TimeStyle
= pXFStyleManager
->AddStyle(pDateStyle
)->GetStyleName();
209 void LwpFribDocVar::RegisterTotalTimeStyle()
211 XFTimeStyle
* pTimeStyle
= new XFTimeStyle
;//use the default format
212 pTimeStyle
->SetTruncate(sal_False
);
213 pTimeStyle
->AddMinute();
214 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
215 m_TimeStyle
= pXFStyleManager
->AddStyle(pTimeStyle
)->GetStyleName();
219 * @short: convert the doc info field
223 void LwpFribDocVar::XFConvert(XFContentContainer
* pXFPara
)
225 XFContent
* pContent
=NULL
;
230 pContent
= new XFFileName
;
231 static_cast<XFFileName
*>(pContent
)->SetType(A2OUSTR("FileName"));
236 pContent
= new XFFileName
;
237 static_cast<XFFileName
*>(pContent
)->SetType(A2OUSTR("Path"));
241 pContent
= new XFDescription
;
245 pContent
= new XFCreateTime
;
246 pContent
->SetStyleName(m_TimeStyle
);
249 case DATELASTREVISION
:
251 pContent
= new XFLastEditTime
;
252 pContent
->SetStyleName(m_TimeStyle
);
256 pContent
= new XFPageCount
;
259 pContent
= new XFWordCount
;
262 pContent
= new XFCharCount
;
266 pContent
= new XFTotalEditTime
;
267 pContent
->SetStyleName(m_TimeStyle
);
271 pContent
= new XFKeywords
;
274 pContent
= new XFInitialCreator
;
278 /* pContent = new XFAnnotation;
279 XFTextContent* pSpan = new XFTextContent();
280 pSpan->SetText(A2OUSTR("Document Size is Here"));
281 XFParagraph* pPara = new XFParagraph;
283 static_cast<XFAnnotation*>(pContent)->Add(pPara);
286 OUString text
= A2OUSTR("<Document Size>");
287 LwpFrib::ConvertChars(pXFPara
,text
);
292 OUString text
= A2OUSTR("<Smart master>");
293 LwpFrib::ConvertChars(pXFPara
,text
);
298 OUString text
= A2OUSTR("<Division name>");
299 LwpFrib::ConvertChars(pXFPara
,text
);
304 OUString text
= A2OUSTR("<Section name>");
305 LwpFrib::ConvertChars(pXFPara
,text
);
308 case VERSIONCREATEBY
:
310 OUString text
= A2OUSTR("<Version Creat by>");
311 LwpFrib::ConvertChars(pXFPara
,text
);
314 case VERSIONCREATEDATE
:
316 OUString text
= A2OUSTR("<Version Creat date>");
317 LwpFrib::ConvertChars(pXFPara
,text
);
320 case VERSIONOTHEREDITORS
:
322 OUString text
= A2OUSTR("<Version other Editors>");
323 LwpFrib::ConvertChars(pXFPara
,text
);
328 OUString text
= A2OUSTR("<Version Name>");
329 LwpFrib::ConvertChars(pXFPara
,text
);
334 OUString text
= A2OUSTR("<Version Numbers>");
335 LwpFrib::ConvertChars(pXFPara
,text
);
340 OUString text
= A2OUSTR("<All Version Name>");
341 LwpFrib::ConvertChars(pXFPara
,text
);
346 OUString text
= A2OUSTR("<Version Remark>");
347 LwpFrib::ConvertChars(pXFPara
,text
);
350 case DOCUMENTCATEGORY
:
352 OUString text
= A2OUSTR("<Document Category>");
353 LwpFrib::ConvertChars(pXFPara
,text
);
356 case VERSIONLASTDATE
:
358 OUString text
= A2OUSTR("<Version Last Modify Date>");
359 LwpFrib::ConvertChars(pXFPara
,text
);
362 case VERSIONLASTEDITOR
:
364 OUString text
= A2OUSTR("<Version Last Editor>");
365 LwpFrib::ConvertChars(pXFPara
,text
);
370 OUString text
= A2OUSTR("<Last Editor>");
371 LwpFrib::ConvertChars(pXFPara
,text
);
376 OUString text
= A2OUSTR("<Other Editors>");
377 LwpFrib::ConvertChars(pXFPara
,text
);
382 OUString text
= A2OUSTR("<Number of Revision>");
383 LwpFrib::ConvertChars(pXFPara
,text
);
389 if (m_ModFlag
)//(m_pModifiers)
391 XFTextSpan
*pSpan
= new XFTextSpan
;
392 pSpan
->SetStyleName(GetStyleName());
393 pSpan
->Add(pContent
);
397 pXFPara
->Add(pContent
);
401 * @short: Read unicode
405 void LwpFribUnicode::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
409 rtl_TextEncoding rEncode
;
411 if (m_pModifiers
&& m_pModifiers
->CodePage
)
412 rEncode
= LwpCharSetMgr::GetInstance()->
413 GetTextCharEncoding(m_pModifiers
->CodePage
);
415 rEncode
= LwpCharSetMgr::GetInstance()->GetTextCharEncoding();
417 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
421 pObjStrm
->SeekRel(len
);
424 void LwpFribUnicode::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
428 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
429 if (pHyperlink
->GetHyperlinkFlag())
430 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
432 LwpFrib::ConvertChars(pXFPara
,GetText());
436 * @short: Read page number
440 void LwpFribPageNumber::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
442 m_nNumStyle
= pObjStrm
->QuickReaduInt16();
443 m_aBefText
.Read(pObjStrm
);
444 m_aAfterText
.Read(pObjStrm
);
445 m_nStartNum
= pObjStrm
->QuickReaduInt16();
446 m_nStartOnPage
= pObjStrm
->QuickReaduInt16();
447 m_nFlag
= pObjStrm
->QuickReaduInt16();
450 void LwpFribPageNumber::XFConvert(XFContentContainer
* pXFPara
)
452 if (m_nNumStyle
== 0x0)
454 XFPageNumber
* pNum
= new XFPageNumber
;
455 // pNum->SetSelect(A2OUSTR("current"));
459 pNum
->SetNumFmt(A2OUSTR("1"));
462 pNum
->SetNumFmt(A2OUSTR("A"));
465 pNum
->SetNumFmt(A2OUSTR("a"));
468 pNum
->SetNumFmt(A2OUSTR("I"));
471 pNum
->SetNumFmt(A2OUSTR("i"));
474 OUString styleName
= GetStyleName();
475 if (m_aBefText
.str().getLength()>0)
477 OUString textStr
= m_aBefText
.str();
478 XFTextSpan
*pBef
= new XFTextSpan(textStr
,styleName
);
481 if (m_ModFlag
)//(m_pModifiers)
483 XFTextSpan
*pSpan
= new XFTextSpan
;
484 pSpan
->SetStyleName(styleName
);
490 if (m_aAfterText
.str().getLength()>0)
492 OUString textStr
= m_aAfterText
.str();
493 XFTextSpan
*pAfter
= new XFTextSpan(textStr
,styleName
);
494 pXFPara
->Add(pAfter
);