mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
106 lines
4.8 KiB
C++
106 lines
4.8 KiB
C++
#include "stdafx.h"
|
|
#include "OOXReader.h"
|
|
#include "OOXSettingsReader.h"
|
|
#include "OOXFontTableReader.h"
|
|
#include "OOXStyleTableReader.h"
|
|
#include "OOXNumberingReader.h"
|
|
#include "OOXDocumentReader.h"
|
|
#include "OOXAppReader.h"
|
|
#include "OOXCoreReader.h"
|
|
#include "OOXFootnotesReader.h"
|
|
#include "OOXThemeReader.h"
|
|
|
|
OOXReader::OOXReader( RtfDocument& oDocument,CString path ): m_oDocument(oDocument)
|
|
{
|
|
m_sPath = path;
|
|
m_nCurItap = 0;
|
|
}
|
|
bool OOXReader::Parse()
|
|
{
|
|
CString sRelsPath = m_sPath + _T("\\_rels\\.rels");
|
|
m_oRelsReader.Init( sRelsPath );
|
|
CAtlArray<CString> m_aPath;
|
|
m_oRelsReader.GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), m_aPath);
|
|
CString sDocFullPath = m_sPath + _T("\\") + m_aPath[0];
|
|
|
|
m_sDocumentPath = GetFolder( sDocFullPath );
|
|
|
|
//âûäåëÿåì èìÿ document.xml
|
|
OOXRelsReaderPtr oDocumentRelsReader;
|
|
int nSlashIndex = sDocFullPath.ReverseFind( '\\' );
|
|
CString sName = sDocFullPath.Right( sDocFullPath.GetLength() - nSlashIndex - 1) ;
|
|
|
|
//ïðîâåðÿåì íàëè÷èå document.xml rels
|
|
CString sDocumentRelsPath = m_sDocumentPath + _T("\\_rels\\") + sName + _T(".rels");
|
|
if( ::GetFileAttributes( sDocumentRelsPath ) != DWORD(-1) )
|
|
{
|
|
oDocumentRelsReader = OOXRelsReaderPtr( new OOXRelsReader() );
|
|
oDocumentRelsReader->Init( sDocumentRelsPath );
|
|
}
|
|
|
|
ReaderParameter oReaderParameter;
|
|
oReaderParameter.oReader = this;
|
|
oReaderParameter.oDocument = &m_oDocument;
|
|
oReaderParameter.oRels = oDocumentRelsReader;
|
|
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"), m_aPath) )
|
|
{ //âàæíî ÷òîáû ïåðâûìè ÷èòàëèñü èìåííî settings (íàïðèìåð äëÿ footnote)
|
|
OOXSettingsReader oSettingsReader( m_sDocumentPath + _T("\\") + m_aPath[0] );
|
|
oSettingsReader.Parse( oReaderParameter );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"), m_aPath) )
|
|
{
|
|
OOXFontTableReader oFontTableReader( m_sDocumentPath + _T("\\") + m_aPath[0] );
|
|
oFontTableReader.Parse( oReaderParameter );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"), m_aPath) )
|
|
{
|
|
OOXThemeReader oThemeReader( m_sDocumentPath + _T("\\") + m_aPath[0] );
|
|
oThemeReader.Parse( oReaderParameter );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"), m_aPath) )
|
|
{
|
|
OOXNumberingReader oNumberingReader;
|
|
oNumberingReader.Parse(oReaderParameter, m_sDocumentPath + _T("\\") + m_aPath[0] );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"), m_aPath) )
|
|
{
|
|
OOXStyleTableReader oStyleTableReader( m_sDocumentPath + _T("\\") + m_aPath[0] );
|
|
oStyleTableReader.Parse( oReaderParameter );
|
|
}
|
|
if( true == m_oRelsReader.GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"), m_aPath) )
|
|
{
|
|
OOXAppReader oDocPropAppReader( m_sPath + _T("\\") + m_aPath[0]);
|
|
oDocPropAppReader.Parse(oReaderParameter );
|
|
}
|
|
if( true == m_oRelsReader.GetByType( _T("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"), m_aPath) )
|
|
{
|
|
OOXCoreReader oDocPropCoreReader( m_sPath + _T("\\") + m_aPath[0]);
|
|
oDocPropCoreReader.Parse(oReaderParameter );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"), m_aPath) )
|
|
{
|
|
OOXFootnotesReader oFootnotesReader;
|
|
oFootnotesReader.Parse( oReaderParameter, m_sDocumentPath + _T("\\") + m_aPath[0], true );
|
|
}
|
|
if( true == oDocumentRelsReader->GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"), m_aPath) )
|
|
{
|
|
OOXFootnotesReader oEndnotesReader;
|
|
oEndnotesReader.Parse( oReaderParameter, m_sDocumentPath + _T("\\") + m_aPath[0], false );
|
|
}
|
|
|
|
if( true == m_oRelsReader.GetByType( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), m_aPath) )
|
|
{
|
|
OOXDocumentReader oDocReader( m_sPath + _T("\\") + m_aPath[0]);
|
|
//÷èòàåì äîêóìåíò
|
|
oDocReader.Parse( oReaderParameter );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
CString OOXReader::GetFolder( CString sDocPath )
|
|
{
|
|
int nLastSlash = sDocPath.ReverseFind('\\');
|
|
CString sLeft = sDocPath.Left(nLastSlash );
|
|
return sLeft;
|
|
} |