Commit e2bf78c5 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

OdfFile Reader

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62593 954022d7-b5bf-4e40-9824-e11837661b57
parent f1f07e8f
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_LITE_READER;_USE_XMLLITE_READER_;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
......
...@@ -26,14 +26,15 @@ namespace common { ...@@ -26,14 +26,15 @@ namespace common {
// //
// add_attributes, add_child_element, add_text // add_attributes, add_child_element, add_text
class read_doc_element { class read_doc_element
{
public: public:
bool read_sax( xml::sax * Reader); bool read_sax( xml::sax * Reader);
virtual ~read_doc_element() = 0; virtual ~read_doc_element() = 0;
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name) = 0;
private: private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ) = 0; virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ) = 0;
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name) = 0;
virtual void add_text(const std::wstring & Text) = 0; virtual void add_text(const std::wstring & Text) = 0;
}; };
......
/// \brief Simple API XML // Simple XML
#pragma once #pragma once
...@@ -39,7 +39,6 @@ public: ...@@ -39,7 +39,6 @@ public:
}; };
public: public:
virtual unsigned int attrCount() = 0;
//virtual std::wstring baseURI() = 0; //virtual std::wstring baseURI() = 0;
virtual unsigned int depth() = 0; virtual unsigned int depth() = 0;
...@@ -55,24 +54,23 @@ public: ...@@ -55,24 +54,23 @@ public:
//// Returns "u://1" for the element <xyz:abc xmlns:xyz="u://1" />. //// Returns "u://1" for the element <xyz:abc xmlns:xyz="u://1" />.
//virtual std::wstring namespaceUri() = 0; //virtual std::wstring namespaceUri() = 0;
virtual NodeType nodeType() = 0; virtual NodeType nodeType() = 0;
virtual std::wstring value() = 0; virtual std::wstring value() = 0;
virtual unsigned int attrCount() = 0;
//virtual std::wstring value() = 0;
virtual bool attrDefault() = 0;
// <element attribute="123"></element> false // <element attribute="123"></element> false
// <element attribute="123"/> - true // <element attribute="123"/> - true
virtual bool isEmptyElement() = 0; virtual bool isEmptyElement() = 0;
virtual bool isEof() = 0;
virtual bool moveToAttrFirst() = 0; virtual bool moveToAttrFirst() = 0;
virtual bool moveToAttrNext() = 0; virtual bool moveToAttrNext() = 0;
virtual void moveToAttrOwner() = 0; virtual bool moveToAttrOwner() = 0;
virtual bool attrDefault() = 0;
virtual NodeType next() = 0;
//virtual unsigned int readChunk(wchar_t * Buffer, unsigned int Size) = 0;
virtual NodeType next(int Depth) = 0;
virtual ~sax() = 0; virtual ~sax() = 0;
}; };
...@@ -81,10 +79,6 @@ public: ...@@ -81,10 +79,6 @@ public:
inline sax::~sax() {}; inline sax::~sax() {};
sax_ptr create_sax(const wchar_t * FileName); sax_ptr create_sax(const wchar_t * FileName);
//sax_ptr create_sax(shared_ptr< std::istream >::Type istreamPtr);
//sax_ptr create_sax(std::istream & istreamVal);
//sax_ptr create_sax(const std::string & String);
} // namespace xml } // namespace xml
} // namespace cpdoccore } // namespace cpdoccore
......
...@@ -11,7 +11,9 @@ namespace common { ...@@ -11,7 +11,9 @@ namespace common {
bool read_doc_element::read_sax( xml::sax * Reader ) bool read_doc_element::read_sax( xml::sax * Reader )
{ {
xml::attributes_wc_ptr attrb = xml::read_attributes( Reader ); const unsigned int currentDepth = Reader->depth();
xml::attributes_wc_ptr attrb = xml::read_attributes( Reader );
add_attributes( attrb ); add_attributes( attrb );
#ifdef _DEBUG #ifdef _DEBUG
...@@ -21,15 +23,24 @@ bool read_doc_element::read_sax( xml::sax * Reader ) ...@@ -21,15 +23,24 @@ bool read_doc_element::read_sax( xml::sax * Reader )
} }
#endif #endif
if (Reader->isEmptyElement()) //const std::wstring value = Reader->value();
return false;
//if (value.length() > 0)
//{
// add_text(value);
//}
const unsigned int currentDepth = Reader->depth();
xml::NodeType nodeType = Reader->nodeType(); xml::NodeType nodeType = Reader->nodeType();
if (Reader->isEmptyElement())
{
return false;
}
while (true) while (true)
{ {
nodeType = Reader->next(currentDepth);
if (nodeType == xml::typeEOF || nodeType == xml::typeNone ) break; if (nodeType == xml::typeEOF || nodeType == xml::typeNone ) break;
if (Reader->depth() <= currentDepth + 1 && nodeType == xml::typeEndElement) break; if (Reader->depth() <= currentDepth + 1 && nodeType == xml::typeEndElement) break;
...@@ -38,8 +49,9 @@ bool read_doc_element::read_sax( xml::sax * Reader ) ...@@ -38,8 +49,9 @@ bool read_doc_element::read_sax( xml::sax * Reader )
{ {
case xml::typeElement: case xml::typeElement:
{ {
const std::wstring namespacePrefix = Reader->namespacePrefix(); const std::wstring namespacePrefix = Reader->namespacePrefix();
const std::wstring localName = Reader->nodeLocalName(); const std::wstring localName = Reader->nodeLocalName();
add_child_element(Reader, namespacePrefix, localName); add_child_element(Reader, namespacePrefix, localName);
} }
break; break;
...@@ -51,8 +63,6 @@ bool read_doc_element::read_sax( xml::sax * Reader ) ...@@ -51,8 +63,6 @@ bool read_doc_element::read_sax( xml::sax * Reader )
} }
break; break;
} }
nodeType = Reader->next();
} }
return true; return true;
} }
......
...@@ -19,7 +19,7 @@ bool create_element_and_read(xml::sax * Reader, ...@@ -19,7 +19,7 @@ bool create_element_and_read(xml::sax * Reader,
{ {
if (office_element_ptr elm = office_element_creator::get()->create(Ns, Name, Context, isRoot)) if (office_element_ptr elm = office_element_creator::get()->create(Ns, Name, Context, isRoot))
{ {
elm->read_sax( Reader ); elm->read_sax( Reader );
elm->afterReadContent(); elm->afterReadContent();
if (_Element) // if (_Element) //
......
...@@ -30,9 +30,9 @@ public: ...@@ -30,9 +30,9 @@ public:
void xlsx_convert(oox::xlsx_conversion_context & Context); void xlsx_convert(oox::xlsx_conversion_context & Context);
void pptx_convert(oox::pptx_conversion_context & Context); void pptx_convert(oox::pptx_conversion_context & Context);
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name);
private: private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ); virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name);
virtual void add_text(const std::wstring & Text); virtual void add_text(const std::wstring & Text);
document_context * getContext(); document_context * getContext();
......
...@@ -63,10 +63,17 @@ content_xml_t_ptr read_file_content(const fs::wpath & Path) ...@@ -63,10 +63,17 @@ content_xml_t_ptr read_file_content(const fs::wpath & Path)
//content_file.open(Path); //content_file.open(Path);
// if (content_file) // if (content_file)
{ {
xml::sax_ptr sax = xml::create_sax( /*content_file*/ Path.string().c_str()); xml::sax_ptr Reader = xml::create_sax( /*content_file*/ Path.string().c_str());
content_xml_t_ptr result( new content_xml_t() ); content_xml_t_ptr result( new content_xml_t() );
result->read_sax(sax.get());
const std::wstring namespacePrefix = Reader->namespacePrefix();
const std::wstring localName = Reader->nodeLocalName();
result->add_child_element(Reader.get(), namespacePrefix, localName);
//result->read_sax(sax.get());
return result; return result;
} }
//else //else
//{ //{
......
...@@ -99,8 +99,8 @@ void not_applicable_element(const std::wstring & Current, xml::sax * Reader, con ...@@ -99,8 +99,8 @@ void not_applicable_element(const std::wstring & Current, xml::sax * Reader, con
_CP_LOG(error) << ss.str(); _CP_LOG(error) << ss.str();
#endif #endif
if (Reader) //if (Reader)
_skip_element::skip_element_.read_sax(Reader); // _skip_element::skip_element_.read_sax(Reader);
} }
void not_applicable_element(const office_element * CurrentElm, xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name) void not_applicable_element(const office_element * CurrentElm, xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
......
...@@ -162,9 +162,9 @@ attributes_wc_ptr read_attributes(sax * SaxReader) ...@@ -162,9 +162,9 @@ attributes_wc_ptr read_attributes(sax * SaxReader)
{ {
if (!SaxReader->attrDefault()) if (!SaxReader->attrDefault())
{ {
const std::wstring prefix = SaxReader->namespacePrefix(); const std::wstring prefix = SaxReader->namespacePrefix();
const std::wstring name = SaxReader->nodeLocalName(); const std::wstring name = SaxReader->nodeLocalName();
const std::wstring value = SaxReader->value(); const std::wstring value = SaxReader->value();
if (prefix.length() < 1 && name.length() < 1 && value.length() < 1) if (prefix.length() < 1 && name.length() < 1 && value.length() < 1)
break; break;
......
...@@ -9,29 +9,10 @@ ...@@ -9,29 +9,10 @@
namespace cpdoccore { namespace cpdoccore {
namespace xml { namespace xml {
sax_ptr create_sax(const wchar_t * FileName) sax_ptr create_sax(const wchar_t * FileName)
{ {
return create_sax_xmllite(FileName); return create_sax_xmllite(FileName);
} }
//sax_ptr create_sax(shared_ptr< std::istream >::Type istreamPtr)
//{
// return create_sax_xmllite(istreamPtr);
//}
//
//sax_ptr create_sax(std::istream & istreamVal)
//{
// return create_sax_xmllite(istreamVal);
//}
/*
sax_ptr create_sax(const std::string & String)
{
shared_ptr< ::std::stringstream >::Type stream( new ::std::stringstream );
(*stream) << String;
return create_sax(stream);
}
*/
} }
} }
...@@ -27,7 +27,6 @@ public: ...@@ -27,7 +27,6 @@ public:
saxXmlLiteReader(); saxXmlLiteReader();
public: public:
virtual unsigned int attrCount();
//virtual std::wstring baseURI(); //virtual std::wstring baseURI();
virtual unsigned int depth(); virtual unsigned int depth();
...@@ -43,22 +42,23 @@ public: ...@@ -43,22 +42,23 @@ public:
//// Returns "u://1" for the element <xyz:abc xmlns:xyz="u://1" />. //// Returns "u://1" for the element <xyz:abc xmlns:xyz="u://1" />.
//virtual std::wstring namespaceUri(); //virtual std::wstring namespaceUri();
virtual NodeType nodeType(); virtual NodeType nodeType();
virtual std::wstring value(); virtual std::wstring value();
//virtual std::wstring attValue();
virtual unsigned int attrCount();
virtual bool attrDefault();
// <element attribute="123"></element> false // <element attribute="123"></element> false
// <element attribute="123"/> - true // <element attribute="123"/> - true
virtual bool isEmptyElement(); virtual bool isEmptyElement();
virtual bool isEof();
//virtual bool moveToAttrByName(const wchar_t * Name, const wchar_t * nsURI); //virtual bool moveToAttrByName(const wchar_t * Name, const wchar_t * nsURI);
virtual bool moveToAttrFirst(); virtual bool moveToAttrFirst();
virtual bool moveToAttrNext(); virtual bool moveToAttrNext();
virtual void moveToAttrOwner(); virtual bool moveToAttrOwner();
virtual bool attrDefault();
virtual NodeType next(); virtual NodeType next(int Depth);
//virtual unsigned int readChunk(wchar_t * Buffer, unsigned int Size); //virtual unsigned int readChunk(wchar_t * Buffer, unsigned int Size);
...@@ -107,10 +107,9 @@ saxXmlLiteReader::saxXmlLiteReader(const wchar_t * FileName) ...@@ -107,10 +107,9 @@ saxXmlLiteReader::saxXmlLiteReader(const wchar_t * FileName)
xml_->FromFile(FileName); xml_->FromFile(FileName);
if (xml_->ReadNextNode() == false) bool res;
{
xml_ = NULL; res = xml_->ReadNextNode();
}
} }
unsigned int saxXmlLiteReader::attrCount() unsigned int saxXmlLiteReader::attrCount()
...@@ -181,12 +180,17 @@ NodeType saxXmlLiteReader::nodeType() ...@@ -181,12 +180,17 @@ NodeType saxXmlLiteReader::nodeType()
XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader()); XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader());
return NodeTypeConvert(nTempType); return NodeTypeConvert(nTempType);
} }
//std::wstring saxXmlLiteReader::nodeValue()
//{
// if (xml_.IsInit() == false) return _T("");
//
// return xml_->GetText3();
//}
std::wstring saxXmlLiteReader::value() std::wstring saxXmlLiteReader::value()
{ {
if (xml_.IsInit() == false) return _T(""); if (xml_.IsInit() == false) return _T("");
return xml_->GetText3(); return xml_->GetText();
} }
...@@ -199,45 +203,25 @@ bool saxXmlLiteReader::isEmptyElement() ...@@ -199,45 +203,25 @@ bool saxXmlLiteReader::isEmptyElement()
return xml_->IsEmptyNode(); return xml_->IsEmptyNode();
} }
bool saxXmlLiteReader::isEof()
{
if (xml_.IsInit() == false) return true;
return false;
}
bool saxXmlLiteReader::moveToAttrFirst() bool saxXmlLiteReader::moveToAttrFirst()
{ {
if (xml_.IsInit() == false) return false; if (xml_.IsInit() == false) return false;
if (S_OK != xml_->MoveToFirstAttribute()) return xml_->MoveToFirstAttribute();
{
throw error(error::internalErr);
}
return true;
} }
bool saxXmlLiteReader::moveToAttrNext() bool saxXmlLiteReader::moveToAttrNext()
{ {
if (xml_.IsInit() == false) return false; if (xml_.IsInit() == false) return false;
if (S_OK !=xml_->MoveToNextAttribute()) return xml_->MoveToNextAttribute();
{
throw error(error::internalErr);
}
return true;
} }
void saxXmlLiteReader::moveToAttrOwner() bool saxXmlLiteReader::moveToAttrOwner()
{ {
if (xml_.IsInit() == false) return; if (xml_.IsInit() == false) return false;
if (S_OK != xml_->MoveToElement()) return xml_->MoveToElement();
{
throw error(error::internalErr);
}
} }
bool saxXmlLiteReader::attrDefault() bool saxXmlLiteReader::attrDefault()
...@@ -247,11 +231,9 @@ bool saxXmlLiteReader::attrDefault() ...@@ -247,11 +231,9 @@ bool saxXmlLiteReader::attrDefault()
return (FALSE != xmlTextReaderIsDefault(xml_->getNativeReader())); return (FALSE != xmlTextReaderIsDefault(xml_->getNativeReader()));
} }
NodeType saxXmlLiteReader::next() NodeType saxXmlLiteReader::next(int Depth)
{ {
int nCurDepth = xml_->GetDepth(); if (xml_->ReadNextSiblingNode2(Depth))
if (xml_->ReadNextSiblingNode(nCurDepth))
{ {
XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader()); XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader());
return NodeTypeConvert(nTempType); return NodeTypeConvert(nTempType);
...@@ -283,15 +265,5 @@ sax_ptr create_sax_xmllite(const wchar_t * FileName) ...@@ -283,15 +265,5 @@ sax_ptr create_sax_xmllite(const wchar_t * FileName)
return sax_ptr( new saxXmlLiteReader(FileName) ); return sax_ptr( new saxXmlLiteReader(FileName) );
} }
//sax_ptr create_sax_xmllite( shared_ptr< std::istream >::Type istreamPtr)
//{
// return sax_ptr( new saxXmlLiteReader(istreamPtr) );
//}
//
//sax_ptr create_sax_xmllite( std::istream & istreamVal )
//{
// return sax_ptr( new saxXmlLiteReader(istreamVal) );
//}
} }
} }
...@@ -10,8 +10,6 @@ namespace cpdoccore { ...@@ -10,8 +10,6 @@ namespace cpdoccore {
namespace xml { namespace xml {
sax_ptr create_sax_xmllite(const wchar_t * FileName); sax_ptr create_sax_xmllite(const wchar_t * FileName);
//sax_ptr create_sax_xmllite( shared_ptr< std::istream >::Type istreamPtr);
//sax_ptr create_sax_xmllite( std::istream & istreamVal );
} }
} }
\ No newline at end of file
...@@ -321,14 +321,6 @@ ...@@ -321,14 +321,6 @@
RelativePath="..\include\cpdoccore\xml\sax.h" RelativePath="..\include\cpdoccore\xml\sax.h"
> >
</File> </File>
<File
RelativePath="..\include\cpdoccore\xml\serialize.h"
>
</File>
<File
RelativePath="..\include\cpdoccore\xml\serialize_attributes.h"
>
</File>
<File <File
RelativePath="..\include\cpdoccore\xml\simple_xml_writer.h" RelativePath="..\include\cpdoccore\xml\simple_xml_writer.h"
> >
......
...@@ -422,7 +422,39 @@ namespace XmlUtils ...@@ -422,7 +422,39 @@ namespace XmlUtils
return false; return false;
} }
inline bool ReadTillEnd(int nDepth = -2) inline bool ReadNextSiblingNode2(int nDepth)
{
if ( !IsValid() )
return false;
XmlNodeType eNodeType = XmlNodeType_None;
int nCurDepth = -1;
while ( 1 == xmlTextReaderRead(reader) )
{
int nTempType = xmlTextReaderNodeType(reader);
int nTempDepth = xmlTextReaderDepth(reader);
if(-1 == nTempType || -1 == nTempDepth)
return false;
eNodeType = (XmlNodeType)nTempType;
nCurDepth = nTempDepth;
if (nCurDepth < nDepth)
break;
if (( XmlNodeType_Element == eNodeType && nCurDepth == nDepth + 1 )
|| ((XmlNodeType_Text == eNodeType ||
XmlNodeType_Whitespace == eNodeType) && nCurDepth == nDepth + 1) )
return true;
else if ( XmlNodeType_EndElement == eNodeType && nCurDepth == nDepth )
return false;
}
return false;
}
inline bool ReadTillEnd(int nDepth = -2)
{ {
if ( !IsValid() ) if ( !IsValid() )
return false; return false;
...@@ -548,6 +580,26 @@ namespace XmlUtils ...@@ -548,6 +580,26 @@ namespace XmlUtils
return sResult; return sResult;
} }
//inline std::wstring GetText3()
//{
// if ( !IsValid() )
// return _T("");
// std::wstring sResult;
// if ( 0 != xmlTextReaderIsEmptyElement(reader) )
// return sResult;
// int nDepth = GetDepth();
// XmlNodeType eNodeType = XmlNodeType_EndElement;
// while ( Read( eNodeType ) && GetDepth() >= nDepth && XmlNodeType_EndElement != eNodeType )
// {
// if ( eNodeType == XmlNodeType_Text || eNodeType == XmlNodeType_Whitespace || eNodeType == XmlNodeType_SIGNIFICANT_WHITESPACE )
// sResult += GetText();
// }
// return sResult;
//}
inline CString GetOuterXml() inline CString GetOuterXml()
{ {
return GetXml(false); return GetXml(false);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<Configurations> <Configurations>
<Configuration <Configuration
Name="Debug|Win32" Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)" OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4" ConfigurationType="4"
UseOfATL="0" UseOfATL="0"
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
</Configuration> </Configuration>
<Configuration <Configuration
Name="Release|Win32" Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)" OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4" ConfigurationType="4"
CharacterSet="2" CharacterSet="2"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment