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 #include "lwpdocdata.hxx"
56 #include "xfilter/xfofficemeta.hxx"
57 #include "localtime.hxx"
58 #include <rtl/ustrbuf.hxx>
59 #include "lwpfilehdr.hxx"
60 #include "lwpglobalmgr.hxx"
62 //std::map<sal_uInt16,LwpEditorAttr*> LwpDocData::m_EditorAttrMap;
64 LwpDocData::LwpDocData(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
65 :LwpObject(objHdr
, pStrm
)//m_pEditorAttrList(0)
68 LwpDocData::~LwpDocData()
71 void LwpDocData::SkipExtra(LwpSvStream
* pStream
)
74 pStream
->Read(&extra
,2);
77 pStream
->SeekRel(extra
);
78 pStream
->Read(&extra
,2);
81 void LwpDocData::SkipAtomHandler(LwpSvStream
* pStream
)
85 pStream
->Read(&disksize
,2);
86 pStream
->Read(&len
,2);
87 if(len
)pStream
->SeekRel(disksize
-2);
89 void LwpDocData::Read()
92 //////////////////////////////////////////////////////////////////////////
95 m_DocOptions
.nOptionFlag
= m_pObjStrm
->QuickReaduInt16();
97 m_DocOptions
.encrypt1password
.Read(m_pObjStrm
);
99 m_DocOptions
.encrypt2password
.Read(m_pObjStrm
);
101 m_DocOptions
.characterSet
.Read(m_pObjStrm
);
103 m_DocOptions
.grammerSet
.Read(m_pObjStrm
);
105 m_DocOptions
.nMarginMarks
= m_pObjStrm
->QuickReaduInt16();
106 //cMarginMarksLocation
107 m_DocOptions
.nMarginMarksLocation
= m_pObjStrm
->QuickReaduInt16();
109 m_DocOptions
.nMarginMarksChar
= m_pObjStrm
->QuickReaduInt16();
110 m_pObjStrm
->SkipExtra();
111 //////////////////////////////////////////////////////////////////////////
114 m_DocInfo
.description
.Read(m_pObjStrm
);
116 m_DocInfo
.keywords
.Read(m_pObjStrm
);
118 m_DocInfo
.createdBy
.Read(m_pObjStrm
);
120 m_DocInfo
.nCreationTime
= m_pObjStrm
->QuickReadInt32();
121 LtgLocalTime(m_DocInfo
.nCreationTime
,m_nCreationTime
);
123 m_DocInfo
.nLastRevisionTime
= m_pObjStrm
->QuickReadInt32();
124 LtgLocalTime(m_DocInfo
.nLastRevisionTime
,m_nLastRevisionTime
);
126 m_DocInfo
.nTotalEditTime
= m_pObjStrm
->QuickReadInt32();
128 m_nTotalEditTime
.tm_hour
= m_DocInfo
.nTotalEditTime
/ 60;
129 m_nTotalEditTime
.tm_min
= m_DocInfo
.nTotalEditTime
% 60;
130 m_nTotalEditTime
.tm_sec
= 0;
132 m_DocInfo
.cpVerDocInfo
.ReadIndexed(m_pObjStrm
);
135 m_DocInfo
.nNumEditedBy
= m_pObjStrm
->QuickReaduInt16();
136 LwpAtomHolder
* pCDLNList
= new LwpAtomHolder
[m_DocInfo
.nNumEditedBy
];
137 LwpAtomHolder
* pEditorList
= new LwpAtomHolder
[m_DocInfo
.nNumEditedBy
];
139 for ( i
= 0; i
< m_DocInfo
.nNumEditedBy
; i
++)
142 pCDLNList
[i
].Read(m_pObjStrm
); //cName
143 m_pObjStrm
->SkipExtra();
145 pEditorList
[i
].Read(m_pObjStrm
); //cName
146 m_pObjStrm
->SkipExtra();
149 m_pObjStrm
->SkipExtra();
152 delete [] pEditorList
;
153 //////////////////////////////////////////////////////////////////////////
156 m_DocControl
.cGreeting
.Read(m_pObjStrm
);
158 m_DocControl
.nFlags
= m_pObjStrm
->QuickReaduInt16();
160 //cDocControlProtection
161 m_DocControl
.nDocControlProtection
= m_pObjStrm
->QuickReaduInt16();
163 m_DocControl
.nLen1
= m_pObjStrm
->QuickReaduInt16();
164 //skip doc control password string
165 m_pObjStrm
->SeekRel(m_DocControl
.nLen1
);
168 m_DocControl
.nFileProtection
= m_pObjStrm
->QuickReaduInt16();
170 m_DocControl
.nLen2
= m_pObjStrm
->QuickReaduInt16();
171 //skip file password string
172 m_pObjStrm
->SeekRel(m_DocControl
.nLen2
);
175 m_DocControl
.nAutoVersioning
= m_pObjStrm
->QuickReaduInt16();
176 //cDocControlOnlyEditor
177 m_DocControl
.cDocControlOnlyEditor
.Read(m_pObjStrm
);
178 //cEditorVerification
179 m_DocControl
.nEditorVerification
= m_pObjStrm
->QuickReaduInt16();
181 m_pObjStrm
->SkipExtra();
182 //////////////////////////////////////////////////////////////////////////
185 sal_uInt16 numeditors
= m_pObjStrm
->QuickReaduInt16();
186 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
188 for (i
= 0;i
<numeditors
;i
++)
190 LwpEditorAttr
* pEditorAttr
= new LwpEditorAttr
;
192 pEditorAttr
->cName
.Read(m_pObjStrm
);
194 pEditorAttr
->cInitials
.Read(m_pObjStrm
);
196 pEditorAttr
->cHiLiteColor
.Read(m_pObjStrm
);
199 pEditorAttr
->nID
= m_pObjStrm
->QuickReaduInt16();
202 //CFontAttributeOverride --cAttrBits
203 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cAttrBits
= m_pObjStrm
->QuickReaduInt16();
204 //CFontAttributeOverride --cAttrOverrideBits
205 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cAttrOverrideBits
= m_pObjStrm
->QuickReaduInt16();
206 //CFontAttributeOverride --cAttrApplyBits
207 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cAttrApplyBits
= m_pObjStrm
->QuickReaduInt16();
208 //CFontAttributeOverride --cAttrOverrideBits2
209 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cAttrOverrideBits2
= m_pObjStrm
->QuickReaduInt8();
210 //CFontAttributeOverride --cAttrApplyBits2
211 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cAttrApplyBits2
= m_pObjStrm
->QuickReaduInt8();
212 //CFontAttributeOverride --cCase
213 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cCase
= m_pObjStrm
->QuickReaduInt8();
214 //CFontAttributeOverride --cUnder
215 pEditorAttr
->cInsFontOver
.cFontAttributeOverride
.cUnder
= m_pObjStrm
->QuickReaduInt8();
216 m_pObjStrm
->SkipExtra();
217 //CFontDescriptionOverrideBase--cOverrideBits
218 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cOverrideBits
= m_pObjStrm
->QuickReaduInt8();
219 //CFontDescriptionOverrideBase--cApplyBits
220 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cApplyBits
= m_pObjStrm
->QuickReaduInt8();
221 //CFontDescriptionOverrideBase--cPointSize
222 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cPointSize
= m_pObjStrm
->QuickReadInt32();
223 //CFontDescriptionOverrideBase--cOverstrike
224 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cOverstrike
= m_pObjStrm
->QuickReaduInt8();
225 //CFontDescriptionOverrideBase--cTightness
226 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cTightness
= m_pObjStrm
->QuickReaduInt16();
227 //CFontDescriptionOverrideBase--cColor
228 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cColor
.Read(m_pObjStrm
);
230 //CFontDescriptionOverrideBase--cBackgroundColor
231 pEditorAttr
->cInsFontOver
.cFontDescriptionOverrideBase
.cBackgroundColor
.Read(m_pObjStrm
);
233 m_pObjStrm
->SkipExtra();
235 pEditorAttr
->cInsFontOver
.cFaceName
.Read(m_pObjStrm
);
237 pEditorAttr
->cInsFontOver
.cAltFaceName
.Read(m_pObjStrm
);
238 m_pObjStrm
->SkipExtra();
241 //CFontAttributeOverride --cAttrBits
242 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cAttrBits
= m_pObjStrm
->QuickReaduInt16();
243 //CFontAttributeOverride --cAttrOverrideBits
244 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cAttrOverrideBits
= m_pObjStrm
->QuickReaduInt16();
245 //CFontAttributeOverride --cAttrApplyBits
246 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cAttrApplyBits
= m_pObjStrm
->QuickReaduInt16();
247 //CFontAttributeOverride --cAttrOverrideBits2
248 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cAttrOverrideBits2
= m_pObjStrm
->QuickReaduInt8();
249 //CFontAttributeOverride --cAttrApplyBits2
250 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cAttrApplyBits2
= m_pObjStrm
->QuickReaduInt8();
251 //CFontAttributeOverride --cCase
252 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cCase
= m_pObjStrm
->QuickReaduInt8();
253 //CFontAttributeOverride --cUnder
254 pEditorAttr
->cDelFontOver
.cFontAttributeOverride
.cUnder
= m_pObjStrm
->QuickReaduInt8();
255 m_pObjStrm
->SkipExtra();
256 //CFontDescriptionOverrideBase--cOverrideBits
257 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cOverrideBits
= m_pObjStrm
->QuickReaduInt8();
258 //CFontDescriptionOverrideBase--cApplyBits
259 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cApplyBits
= m_pObjStrm
->QuickReaduInt8();
260 //CFontDescriptionOverrideBase--cPointSize
261 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cPointSize
= m_pObjStrm
->QuickReadInt32();
262 //CFontDescriptionOverrideBase--cOverstrike
263 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cOverstrike
= m_pObjStrm
->QuickReaduInt8();
264 //CFontDescriptionOverrideBase--cTightness
265 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cTightness
= m_pObjStrm
->QuickReaduInt16();
266 //CFontDescriptionOverrideBase--cColor
267 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cColor
.Read(m_pObjStrm
);
269 //CFontDescriptionOverrideBase--cBackgroundColor
270 pEditorAttr
->cDelFontOver
.cFontDescriptionOverrideBase
.cBackgroundColor
.Read(m_pObjStrm
);
272 m_pObjStrm
->SkipExtra();
274 pEditorAttr
->cDelFontOver
.cFaceName
.Read(m_pObjStrm
);
276 pEditorAttr
->cDelFontOver
.cAltFaceName
.Read(m_pObjStrm
);
277 m_pObjStrm
->SkipExtra();
280 pEditorAttr
->nAbilities
= m_pObjStrm
->QuickReaduInt16();
282 pEditorAttr
->nLocks
= m_pObjStrm
->QuickReaduInt16();
284 pEditorAttr
->nSuggestions
= m_pObjStrm
->QuickReaduInt16();
287 //m_pEditorAttrList[i].cDelTextAttr.Read(m_pObjStrm);
288 if (m_pObjStrm
->QuickReadBool())
290 pEditorAttr
->cDelTextAttr
.cOverride
.cValues
= m_pObjStrm
->QuickReaduInt16();
291 pEditorAttr
->cDelTextAttr
.cOverride
.cOverride
= m_pObjStrm
->QuickReaduInt16();
292 pEditorAttr
->cDelTextAttr
.cOverride
.cApply
= m_pObjStrm
->QuickReaduInt16();
293 m_pObjStrm
->SkipExtra();
294 pEditorAttr
->cDelTextAttr
.cHideLevels
= m_pObjStrm
->QuickReaduInt16();
296 if (LwpFileHeader::m_nFileRevision
>= 0x000b)
298 pEditorAttr
->cDelTextAttr
.cBaselineOffset
= m_pObjStrm
->QuickReadInt32();
302 pEditorAttr
->cDelTextAttr
.cBaselineOffset
= 0;
305 m_pObjStrm
->SkipExtra();
307 m_pObjStrm
->SkipExtra();
309 pGlobal
->SetEditorAttrMap(pEditorAttr
->nID
, pEditorAttr
);
312 rtl::OUString
LwpDocData::DateTimeToOUString(LtTm
& dt
)
314 rtl::OUStringBuffer buf
;
315 buf
.append((sal_Int32
)dt
.tm_year
);
316 buf
.append( A2OUSTR("-") );
317 buf
.append((sal_Int32
)dt
.tm_mon
);
318 buf
.append( A2OUSTR("-") );
319 buf
.append((sal_Int32
)dt
.tm_mday
);
320 buf
.append( A2OUSTR("T") );
321 buf
.append((sal_Int32
)dt
.tm_hour
);
322 buf
.append( A2OUSTR(":") );
323 buf
.append((sal_Int32
)dt
.tm_min
);
324 buf
.append( A2OUSTR(":") );
325 buf
.append((sal_Int32
)dt
.tm_sec
);
326 buf
.append( A2OUSTR(".") );
327 buf
.append((sal_Int32
)0);
329 return buf
.makeStringAndClear();
331 rtl::OUString
LwpDocData::TimeToOUString(LtTm
& dt
)
334 rtl::OUStringBuffer buf
;
335 buf
.append( A2OUSTR("PT") );
336 buf
.append((sal_Int32
)dt
.tm_hour
);
337 buf
.append( A2OUSTR("H") );
338 buf
.append((sal_Int32
)dt
.tm_min
);
339 buf
.append( A2OUSTR("M") );
340 buf
.append((sal_Int32
)dt
.tm_sec
);
341 buf
.append( A2OUSTR("S") );
343 return buf
.makeStringAndClear();
345 void LwpDocData::Parse(IXFStream
*pOutputStream
)
347 //<!DOCTYPE office:document-meta PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
348 //<office:document-meta xmlns:office="http://openoffice.org/2000/office" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" office:version="1.0">
349 //</office:document-meta>
351 xfMeta
.SetCreator(m_DocInfo
.createdBy
.str());
352 xfMeta
.SetDescription(m_DocInfo
.description
.str());
353 xfMeta
.SetKeywords(m_DocInfo
.keywords
.str());
354 xfMeta
.SetCreationTime(DateTimeToOUString(m_nCreationTime
));
355 xfMeta
.SetLastTime(DateTimeToOUString(m_nLastRevisionTime
));
356 xfMeta
.SetEditTime(TimeToOUString(m_nTotalEditTime
));
357 xfMeta
.ToXml(pOutputStream
);
360 OUString LwpDocData::GetEditorName(sal_uInt8 nID)
362 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
363 iter = m_EditorAttrMap.find(nID);
364 if (iter != m_EditorAttrMap.end())
365 return iter->second->cName.str();
369 XFColor LwpDocData::GetHighLightColor(sal_uInt8 nID)
371 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
373 iter = m_EditorAttrMap.find(nID);
374 if (iter != m_EditorAttrMap.end())
376 LwpColor aLwpColor = iter->second->cHiLiteColor;
377 XFColor aColor(aLwpColor.GetRed(),aLwpColor.GetGreen(),aLwpColor.GetBlue());
382 XFColor aColor(255,255,0);//yellow
386 void LwpDocData::Reset()
388 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
389 for (iter =m_EditorAttrMap.begin();iter != m_EditorAttrMap.end(); iter++)
394 m_EditorAttrMap.clear();