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 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;USE_LITE_READER;_USE_XMLLITE_READER_;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
......
......@@ -26,14 +26,15 @@ namespace common {
//
// add_attributes, add_child_element, add_text
class read_doc_element {
class read_doc_element
{
public:
bool read_sax( xml::sax * Reader);
virtual ~read_doc_element() = 0;
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name) = 0;
private:
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;
};
......
/// \brief Simple API XML
// Simple XML
#pragma once
......@@ -39,7 +39,6 @@ public:
};
public:
virtual unsigned int attrCount() = 0;
//virtual std::wstring baseURI() = 0;
virtual unsigned int depth() = 0;
......@@ -58,20 +57,19 @@ public:
virtual NodeType nodeType() = 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"/> - true
virtual bool isEmptyElement() = 0;
virtual bool isEof() = 0;
virtual bool moveToAttrFirst() = 0;
virtual bool moveToAttrNext() = 0;
virtual void moveToAttrOwner() = 0;
virtual bool attrDefault() = 0;
virtual bool moveToAttrOwner() = 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;
......@@ -81,10 +79,6 @@ public:
inline sax::~sax() {};
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 cpdoccore
......
......@@ -11,6 +11,8 @@ namespace common {
bool read_doc_element::read_sax( xml::sax * Reader )
{
const unsigned int currentDepth = Reader->depth();
xml::attributes_wc_ptr attrb = xml::read_attributes( Reader );
add_attributes( attrb );
......@@ -21,15 +23,24 @@ bool read_doc_element::read_sax( xml::sax * Reader )
}
#endif
if (Reader->isEmptyElement())
return false;
//const std::wstring value = Reader->value();
const unsigned int currentDepth = Reader->depth();
//if (value.length() > 0)
//{
// add_text(value);
//}
xml::NodeType nodeType = Reader->nodeType();
if (Reader->isEmptyElement())
{
return false;
}
while (true)
{
nodeType = Reader->next(currentDepth);
if (nodeType == xml::typeEOF || nodeType == xml::typeNone ) break;
if (Reader->depth() <= currentDepth + 1 && nodeType == xml::typeEndElement) break;
......@@ -40,6 +51,7 @@ bool read_doc_element::read_sax( xml::sax * Reader )
{
const std::wstring namespacePrefix = Reader->namespacePrefix();
const std::wstring localName = Reader->nodeLocalName();
add_child_element(Reader, namespacePrefix, localName);
}
break;
......@@ -51,8 +63,6 @@ bool read_doc_element::read_sax( xml::sax * Reader )
}
break;
}
nodeType = Reader->next();
}
return true;
}
......
......@@ -30,9 +30,9 @@ public:
void xlsx_convert(oox::xlsx_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:
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);
document_context * getContext();
......
......@@ -63,10 +63,17 @@ content_xml_t_ptr read_file_content(const fs::wpath & Path)
//content_file.open(Path);
// 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() );
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;
}
//else
//{
......
......@@ -99,8 +99,8 @@ void not_applicable_element(const std::wstring & Current, xml::sax * Reader, con
_CP_LOG(error) << ss.str();
#endif
if (Reader)
_skip_element::skip_element_.read_sax(Reader);
//if (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)
......
......@@ -9,29 +9,10 @@
namespace cpdoccore {
namespace xml {
sax_ptr create_sax(const wchar_t * FileName)
{
sax_ptr create_sax(const wchar_t * 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:
saxXmlLiteReader();
public:
virtual unsigned int attrCount();
//virtual std::wstring baseURI();
virtual unsigned int depth();
......@@ -46,19 +45,20 @@ public:
virtual NodeType nodeType();
virtual std::wstring value();
//virtual std::wstring attValue();
virtual unsigned int attrCount();
virtual bool attrDefault();
// <element attribute="123"></element> false
// <element attribute="123"/> - true
virtual bool isEmptyElement();
virtual bool isEof();
//virtual bool moveToAttrByName(const wchar_t * Name, const wchar_t * nsURI);
virtual bool moveToAttrFirst();
virtual bool moveToAttrNext();
virtual void moveToAttrOwner();
virtual bool attrDefault();
virtual bool moveToAttrOwner();
virtual NodeType next();
virtual NodeType next(int Depth);
//virtual unsigned int readChunk(wchar_t * Buffer, unsigned int Size);
......@@ -107,10 +107,9 @@ saxXmlLiteReader::saxXmlLiteReader(const wchar_t * FileName)
xml_->FromFile(FileName);
if (xml_->ReadNextNode() == false)
{
xml_ = NULL;
}
bool res;
res = xml_->ReadNextNode();
}
unsigned int saxXmlLiteReader::attrCount()
......@@ -181,12 +180,17 @@ NodeType saxXmlLiteReader::nodeType()
XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader());
return NodeTypeConvert(nTempType);
}
//std::wstring saxXmlLiteReader::nodeValue()
//{
// if (xml_.IsInit() == false) return _T("");
//
// return xml_->GetText3();
//}
std::wstring saxXmlLiteReader::value()
{
if (xml_.IsInit() == false) return _T("");
return xml_->GetText3();
return xml_->GetText();
}
......@@ -199,45 +203,25 @@ bool saxXmlLiteReader::isEmptyElement()
return xml_->IsEmptyNode();
}
bool saxXmlLiteReader::isEof()
{
if (xml_.IsInit() == false) return true;
return false;
}
bool saxXmlLiteReader::moveToAttrFirst()
{
if (xml_.IsInit() == false) return false;
if (S_OK != xml_->MoveToFirstAttribute())
{
throw error(error::internalErr);
}
return true;
return xml_->MoveToFirstAttribute();
}
bool saxXmlLiteReader::moveToAttrNext()
{
if (xml_.IsInit() == false) return false;
if (S_OK !=xml_->MoveToNextAttribute())
{
throw error(error::internalErr);
}
return true;
return xml_->MoveToNextAttribute();
}
void saxXmlLiteReader::moveToAttrOwner()
bool saxXmlLiteReader::moveToAttrOwner()
{
if (xml_.IsInit() == false) return;
if (xml_.IsInit() == false) return false;
if (S_OK != xml_->MoveToElement())
{
throw error(error::internalErr);
}
return xml_->MoveToElement();
}
bool saxXmlLiteReader::attrDefault()
......@@ -247,11 +231,9 @@ bool saxXmlLiteReader::attrDefault()
return (FALSE != xmlTextReaderIsDefault(xml_->getNativeReader()));
}
NodeType saxXmlLiteReader::next()
NodeType saxXmlLiteReader::next(int Depth)
{
int nCurDepth = xml_->GetDepth();
if (xml_->ReadNextSiblingNode(nCurDepth))
if (xml_->ReadNextSiblingNode2(Depth))
{
XmlUtils::XmlNodeType nTempType = (XmlUtils::XmlNodeType)xmlTextReaderNodeType(xml_->getNativeReader());
return NodeTypeConvert(nTempType);
......@@ -283,15 +265,5 @@ sax_ptr create_sax_xmllite(const wchar_t * 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 {
namespace xml {
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 @@
RelativePath="..\include\cpdoccore\xml\sax.h"
>
</File>
<File
RelativePath="..\include\cpdoccore\xml\serialize.h"
>
</File>
<File
RelativePath="..\include\cpdoccore\xml\serialize_attributes.h"
>
</File>
<File
RelativePath="..\include\cpdoccore\xml\simple_xml_writer.h"
>
......
......@@ -420,6 +420,38 @@ namespace XmlUtils
return false;
}
return false;
}
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)
......@@ -548,6 +580,26 @@ namespace XmlUtils
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()
{
return GetXml(false);
......
......@@ -19,7 +19,7 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
UseOfATL="0"
......@@ -145,7 +145,7 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
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