LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwp9reader.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 101 0.0 %
Date: 2014-04-14 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : #include "lwp9reader.hxx"
      57             : #include "lwpglobalmgr.hxx"
      58             : #include "lwpunoheader.hxx"
      59             : #include "lwparrowstyles.hxx"
      60             : #include "lwpobjhdr.hxx"
      61             : #include "lwpdoc.hxx"
      62             : #include "xfilter/xfstylemanager.hxx"
      63             : #include "lwpdocdata.hxx"
      64             : #include "lwpbookmarkmgr.hxx"
      65             : #include "lwpchangemgr.hxx"
      66             : #include <tools/stream.hxx>
      67             : 
      68           0 : Lwp9Reader::Lwp9Reader (LwpSvStream* pInputStream, IXFStream* pStream)
      69             :     : m_pDocStream(pInputStream)
      70             :     , m_pStream(pStream)
      71             :     , m_pObjMgr(NULL)
      72           0 :     , m_LwpFileHdr()
      73           0 : {}
      74             : 
      75             : /**
      76             :  * @descr   The entrance of Word Pro 9 import filter.
      77             :  **/
      78           0 : void Lwp9Reader::Read()
      79             : {
      80           0 :     LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance(m_pDocStream);
      81             :     try
      82             :     {
      83           0 :         m_pObjMgr = pGlobal->GetLwpObjFactory();
      84             : 
      85           0 :         ReadFileHeader();
      86             :         //Does not support Word Pro 96 and previous versions
      87           0 :         if(LwpFileHeader::m_nFileRevision>=0x000B)
      88             :         {
      89           0 :             ReadIndex();
      90           0 :             ParseDocument();
      91             :         }
      92             :     }
      93           0 :     catch(...)
      94             :     {
      95           0 :         LwpGlobalMgr::DeleteInstance();
      96           0 :         throw;
      97             :     }
      98           0 :     LwpGlobalMgr::DeleteInstance();
      99           0 : }
     100             : 
     101             : /**
     102             :  * @descr   Read the OLE objects.
     103             :  */
     104           0 : void Lwp9Reader::ReadOleObjects()
     105             : {
     106           0 : }
     107             : /**
     108             :  * @descr   Read the LWP7 object.
     109             :  */
     110           0 : void Lwp9Reader::ReadFileHeader()
     111             : {
     112           0 :     m_pDocStream->Seek(LwpSvStream::LWP_STREAM_BASE);
     113             : 
     114             :     //Remember to initialize the LwpFileHeader::m_nFileRevision first.
     115           0 :     LwpFileHeader::m_nFileRevision = 0;
     116             : 
     117           0 :     LwpObjectHeader objHdr;
     118           0 :     objHdr.Read(*m_pDocStream);
     119           0 :     sal_Int64 pos = m_pDocStream->Tell();
     120           0 :     m_LwpFileHdr.Read(m_pDocStream);
     121           0 :     m_pDocStream->Seek(pos+objHdr.GetSize());
     122             : 
     123           0 : }
     124             : 
     125             : /**
     126             :  * @descr  Read the index objects at the end of the WordProData stream
     127             :  */
     128           0 : void Lwp9Reader::ReadIndex()
     129             : {
     130           0 :     sal_Int64 oldpos = m_pDocStream->Tell();
     131           0 :     sal_uInt32 rootoffset = m_LwpFileHdr.GetRootIndexOffset();
     132           0 :     m_pDocStream->Seek(rootoffset + LwpSvStream::LWP_STREAM_BASE);
     133           0 :     m_pObjMgr->ReadIndex(m_pDocStream);
     134           0 :     m_pDocStream->Seek(oldpos);
     135           0 : }
     136             : 
     137             : /**
     138             :  * @descr   Read all objects
     139             :  *      This function is  replaced by the read on demand model
     140             :  *      Reserverd for future use
     141             : */
     142           0 : void Lwp9Reader::DumpAllObjects()
     143             : {
     144           0 :     sal_Int64 nFileSize = GetFileSize();
     145           0 :     sal_Int64 nFilePos = m_pDocStream->Tell();
     146             : 
     147             :     while(true)
     148             :     {
     149           0 :         LwpObjectHeader objHdr;
     150           0 :         objHdr.Read(*m_pDocStream);
     151           0 :         nFilePos = m_pDocStream->Tell();
     152             :         //Stop when reaching the index object
     153           0 :         if(objHdr.GetTag() >= VO_ROOTLEAFOBJINDEX)
     154             :         {
     155           0 :             break;
     156             :         }
     157             :         //Stop when the length exceeds the file length
     158           0 :         if(nFilePos + objHdr.GetSize() > nFileSize)
     159             :         {
     160             :             assert(false);
     161           0 :             break;
     162             :         }
     163           0 :         m_pObjMgr->CreateObject(objHdr.GetTag(), objHdr);
     164           0 :         m_pDocStream->Seek(nFilePos+objHdr.GetSize());
     165           0 :     }
     166           0 : }
     167             : 
     168             : /**
     169             :  * @descr   Get file size
     170             : */
     171           0 : sal_Int64 Lwp9Reader::GetFileSize()
     172             : {
     173           0 :     sal_Int64 pos = m_pDocStream->Tell();
     174           0 :     m_pDocStream->Seek(0);
     175             : 
     176           0 :     sal_Int64 size = m_pDocStream->Seek( STREAM_SEEK_TO_END);
     177           0 :     m_pDocStream->Seek(pos);
     178           0 :     return(size);
     179             : }
     180             : 
     181             : /**
     182             :  * @descr       Parse all document content
     183             : */
     184           0 : void Lwp9Reader::ParseDocument()
     185             : {
     186           0 :     WriteDocHeader();
     187             : 
     188             :     //Get root document
     189           0 :     LwpDocument* doc = dynamic_cast<LwpDocument*> ( m_LwpFileHdr.GetDocID()->obj() );
     190             : 
     191           0 :     if (!doc)
     192           0 :         return;
     193             : 
     194             :     //Parse Doc Data
     195           0 :     LwpDocData *pDocData = dynamic_cast<LwpDocData*>((doc->GetDocData())->obj());
     196           0 :     if (pDocData!=NULL)
     197           0 :         pDocData->Parse(m_pStream);
     198             : 
     199             :     //Register Styles
     200           0 :     RegisteArrowStyles();
     201           0 :     doc->RegisterStyle();
     202           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     203           0 :     pXFStyleManager->ToXml(m_pStream);
     204             : 
     205             :     //Parse document content
     206           0 :     m_pStream->GetAttrList()->Clear();
     207           0 :     m_pStream->StartElement( "office:body" );
     208             : 
     209             :     //Parse change list, add by
     210           0 :     LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     211           0 :     LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
     212           0 :     pChangeMgr->ConvertAllChange(m_pStream);
     213             : 
     214           0 :     doc->Parse(m_pStream);
     215           0 :     m_pStream->EndElement("office:body");
     216             : 
     217           0 :     WriteDocEnd();
     218             : }
     219             : 
     220             : /**
     221             :  * @descr   Write xml document header
     222             :  */
     223           0 : void Lwp9Reader::WriteDocHeader()
     224             : {
     225           0 :     m_pStream->StartDocument();
     226             : 
     227           0 :     IXFAttrList *pAttrList = m_pStream->GetAttrList();
     228             : 
     229           0 :     pAttrList->AddAttribute( "xmlns:office", "http://openoffice.org/2000/office" );
     230           0 :     pAttrList->AddAttribute( "xmlns:style", "http://openoffice.org/2000/style" );
     231           0 :     pAttrList->AddAttribute( "xmlns:text", "http://openoffice.org/2000/text" );
     232           0 :     pAttrList->AddAttribute( "xmlns:table", "http://openoffice.org/2000/table" );
     233           0 :     pAttrList->AddAttribute( "xmlns:draw", "http://openoffice.org/2000/drawing" );
     234             : 
     235           0 :     pAttrList->AddAttribute( "xmlns:fo", "http://www.w3.org/1999/XSL/Format" );
     236           0 :     pAttrList->AddAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
     237           0 :     pAttrList->AddAttribute( "xmlns:number", "http://openoffice.org/2000/datastyle" );
     238           0 :     pAttrList->AddAttribute( "xmlns:svg", "http://www.w3.org/2000/svg" );
     239           0 :     pAttrList->AddAttribute( "xmlns:chart", "http://openoffice.org/2000/chart" );
     240             : 
     241           0 :     pAttrList->AddAttribute( "xmlns:dr3d", "http://openoffice.org/2000/dr3d" );
     242           0 :     pAttrList->AddAttribute( "xmlns:math", "http://www.w3.org/1998/Math/MathML" );
     243           0 :     pAttrList->AddAttribute( "xmlns:form", "http://openoffice.org/2000/form" );
     244           0 :     pAttrList->AddAttribute( "xmlns:script", "http://openoffice.org/2000/script" );
     245           0 :     pAttrList->AddAttribute( "xmlns:dc", "http://purl.org/dc/elements/1.1/" );
     246             : 
     247           0 :     pAttrList->AddAttribute( "xmlns:meta", "http://openoffice.org/2000/meta" );
     248           0 :     pAttrList->AddAttribute( "office:class", "text");
     249           0 :     pAttrList->AddAttribute( "office:version", "1.0");
     250             : 
     251           0 :     m_pStream->StartElement( "office:document" );
     252           0 :     pAttrList->Clear();
     253             : 
     254           0 : }
     255             : /**
     256             :  * @descr   Write xml document end
     257             :  */
     258           0 : void Lwp9Reader::WriteDocEnd()
     259             : {
     260           0 :     m_pStream->EndElement("office:document");
     261           0 :     m_pStream->EndDocument();
     262           0 : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10