From 83e1044d939285f90a3e1adbc67d1c4d08cb5c58 Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Wed, 13 Mar 2013 20:54:06 +0100 Subject: Cleanup pptx comment import patch a bit. This cleans up 856756ec77ac64d1caee6c1b80c3641d4e487b2d a bit: * add vim footer for new file * use UpperCamelCase for class names * use const references for parameter / bulk object passing * indent properly * don't mix private/public class members randomly * use customary exception object, actually handle the error * stick comment classes into oox namespace * use 'ma' class member prefixes where applicable Change-Id: I98021415331e62a8ee583ecfd27829f7dbfbc498 --- oox/inc/oox/ppt/comments.hxx | 100 +++++++++++----------- oox/inc/oox/ppt/presentationfragmenthandler.hxx | 6 +- oox/inc/oox/ppt/slidefragmenthandler.hxx | 11 ++- oox/inc/oox/ppt/slidepersist.hxx | 15 ++-- oox/source/ppt/presentationfragmenthandler.cxx | 106 +++++++++++++++--------- oox/source/ppt/slidefragmenthandler.cxx | 41 ++++----- 6 files changed, 154 insertions(+), 125 deletions(-) (limited to 'oox') diff --git a/oox/inc/oox/ppt/comments.hxx b/oox/inc/oox/ppt/comments.hxx index 44ea442c614c..81bcb78eaea9 100644 --- a/oox/inc/oox/ppt/comments.hxx +++ b/oox/inc/oox/ppt/comments.hxx @@ -11,16 +11,15 @@ #ifndef OOX_PPT_COMMENTS_HXX #define OOX_PPT_COMMENTS_HXX -#define ELEMENT_NOT_FOUND 0 - -using rtl::OUString; #include #include //split function to tokenize for date time #include +#include +namespace oox { namespace ppt { -struct commentAuthor +struct CommentAuthor { ::rtl::OUString clrIdx; ::rtl::OUString id; @@ -29,17 +28,18 @@ struct commentAuthor ::rtl::OUString name; }; -class commentAuthorList +class CommentAuthorList { private: - std::vector cmAuthorLst; + std::vector cmAuthorLst; + public: - void setValues( commentAuthorList list) + void setValues(const CommentAuthorList& list) { - std::vector::iterator it; - for(it=list.cmAuthorLst.begin();it!=list.cmAuthorLst.end();it++) + std::vector::const_iterator it; + for(it = list.cmAuthorLst.begin(); it != list.cmAuthorLst.end(); ++it) { - commentAuthor temp; + CommentAuthor temp; cmAuthorLst.push_back(temp); cmAuthorLst.back().clrIdx = it->clrIdx; cmAuthorLst.back().id = it->id; @@ -49,18 +49,20 @@ class commentAuthorList } } - std::vector getCmAuthorLst() + const std::vector& getCmAuthorLst() const { return cmAuthorLst; } - void addAuthor(commentAuthor _author) + + void addAuthor(const CommentAuthor& _author) { cmAuthorLst.push_back(_author); } - friend class comment; + + friend class Comment; }; -class comment +class Comment { private: ::rtl::OUString authorId; @@ -71,21 +73,36 @@ class comment ::rtl::OUString text; ::com::sun::star::util::DateTime aDateTime; + //DateTime is saved as : 2013-01-10T15:53:26.000 + void setDateTime (::rtl::OUString datetime) + { + std::string _datetime = rtl::OUStringToOString(datetime, RTL_TEXTENCODING_UTF8).getStr(); + std::vector _dt; + boost::split( _dt, _datetime, boost::is_any_of( "-:T" ) ); + aDateTime.Year = atoi(_dt.at(0).c_str()); + aDateTime.Month = atoi(_dt.at(1).c_str()); + aDateTime.Day = atoi(_dt.at(2).c_str()); + aDateTime.Hours = atoi(_dt.at(3).c_str()); + aDateTime.Minutes = atoi(_dt.at(4).c_str()); + aDateTime.HundredthSeconds = atoi(_dt.at(5).c_str()); + std::vector::iterator i; + } + public: - void setAuthorId(::rtl::OUString _aId) + void setAuthorId(const ::rtl::OUString& _aId) { authorId = _aId; } - void setdt(::rtl::OUString _dt) + void setdt(const ::rtl::OUString& _dt) { dt=_dt; setDateTime(_dt); } - void setidx(::rtl::OUString _idx) + void setidx(const ::rtl::OUString& _idx) { idx=_idx; } - void setPoint(::rtl::OUString _x, ::rtl::OUString _y) + void setPoint(const ::rtl::OUString& _x, const ::rtl::OUString& _y) { x=_x; y=_y; @@ -94,28 +111,10 @@ class comment { text = rtl::OUString::createFromAscii ( _text.c_str() ); } - void setText(rtl::OUString _text) + void setText(const rtl::OUString& _text) { text = _text; } - - private: - //DateTime is saved as : 2013-01-10T15:53:26.000 - void setDateTime (::rtl::OUString datetime) - { - std::string _datetime = rtl::OUStringToOString(datetime, RTL_TEXTENCODING_UTF8).getStr(); - std::vector _dt; - boost::split( _dt, _datetime, boost::is_any_of( "-:T" ) ); - aDateTime.Year = atoi(_dt.at(0).c_str()); - aDateTime.Month = atoi(_dt.at(1).c_str()); - aDateTime.Day = atoi(_dt.at(2).c_str()); - aDateTime.Hours = atoi(_dt.at(3).c_str()); - aDateTime.Minutes = atoi(_dt.at(4).c_str()); - aDateTime.HundredthSeconds = atoi(_dt.at(5).c_str()); - std::vector::iterator i; - } - - public: ::rtl::OUString getAuthorId() { return authorId; @@ -154,42 +153,43 @@ class comment std::string temp = rtl::OUStringToOString(get_Y(), RTL_TEXTENCODING_UTF8).getStr(); return atoi(temp.c_str()); } - OUString getAuthor ( commentAuthorList list ) + OUString getAuthor ( const CommentAuthorList& list ) { std::string temp = rtl::OUStringToOString(authorId, RTL_TEXTENCODING_UTF8).getStr(); int aId = atoi(temp.c_str()); - std::vector::iterator it; - for(it = list.cmAuthorLst.begin(); it != list.cmAuthorLst.end(); it++) + std::vector::const_iterator it; + for(it = list.cmAuthorLst.begin(); it != list.cmAuthorLst.end(); ++it) { temp = rtl::OUStringToOString(it->id, RTL_TEXTENCODING_UTF8).getStr(); int list_aId = atoi(temp.c_str()); std::string temp_a =rtl::OUStringToOString(it->name, RTL_TEXTENCODING_UTF8).getStr(); if(list_aId == aId) - { return it->name; - } - + return it->name; } - OUString _unknown = "Anonymous"; - return _unknown; + return OUString("Anonymous"); } }; -class commentList +class CommentList { public: - std::vector cmLst; + std::vector cmLst; int getSize () { return (int)cmLst.size(); } - comment getCommentAtIndex (int index) + const Comment& getCommentAtIndex (int index) { if(index < (int)cmLst.size() && index >= 0) return cmLst.at(index); else - throw ELEMENT_NOT_FOUND; + throw css::lang::IllegalArgumentException(); } }; -#endif \ No newline at end of file +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/inc/oox/ppt/presentationfragmenthandler.hxx b/oox/inc/oox/ppt/presentationfragmenthandler.hxx index 8730352bc238..f6d0feb0897e 100644 --- a/oox/inc/oox/ppt/presentationfragmenthandler.hxx +++ b/oox/inc/oox/ppt/presentationfragmenthandler.hxx @@ -42,9 +42,6 @@ public: virtual ~PresentationFragmentHandler() throw(); virtual void finalizeImport(); virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ); -private: - commentAuthorList AuthorList; - int readCommentAuthors; // read commentAuthors.xml only once protected: bool importSlide( const ::oox::core::FragmentHandlerRef& rxSlideFragmentHandler, @@ -63,6 +60,9 @@ private: ::com::sun::star::awt::Size maNotesSize; std::vector< CustomShow > maCustomShowList; + + CommentAuthorList maAuthorList; + bool mbCommentAuthorsRead; // read commentAuthors.xml only once }; } } diff --git a/oox/inc/oox/ppt/slidefragmenthandler.hxx b/oox/inc/oox/ppt/slidefragmenthandler.hxx index 6cd50ab9f7c7..b3a9c6745e87 100644 --- a/oox/inc/oox/ppt/slidefragmenthandler.hxx +++ b/oox/inc/oox/ppt/slidefragmenthandler.hxx @@ -39,7 +39,10 @@ public: virtual void finalizeImport(); virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ); - void onCharacters( const ::rtl::OUString& rChars ); + virtual void onCharacters( const ::rtl::OUString& rChars ); + + const ::std::vector< rtl::OUString>& getCharVector() { return maCharVector; } + protected: SlidePersistPtr mpSlidePersistPtr; ShapeLocation meShapeLocation; @@ -47,11 +50,7 @@ protected: private: ::rtl::OUString maSlideName; PropertyMap maSlideProperties; -private: - ::std::vector< rtl::OUString> charVector; // handle char in OnCharacters -public: - ::std::vector< rtl::OUString> getCharVector(void) { return charVector; } - + ::std::vector< rtl::OUString> maCharVector; // handle char in OnCharacters }; } } diff --git a/oox/inc/oox/ppt/slidepersist.hxx b/oox/inc/oox/ppt/slidepersist.hxx index 68caa18db34e..10274117b678 100644 --- a/oox/inc/oox/ppt/slidepersist.hxx +++ b/oox/inc/oox/ppt/slidepersist.hxx @@ -31,7 +31,6 @@ #include #include #include "oox/core/fragmenthandler.hxx" - #include "oox/ppt/comments.hxx" #include @@ -118,14 +117,8 @@ public: ::oox::drawingml::ShapePtr getShape( const ::rtl::OUString & id ) { return maShapeMap[ id ]; } ::oox::drawingml::ShapeIdMap& getShapeMap() { return maShapeMap; } - //comments -private: - commentList commentsList; - commentAuthorList commentAuthors; - -public: - commentList* getCommentsList() { return &commentsList; } - commentAuthorList* getCommentAuthors() { return &commentAuthors; } + CommentList& getCommentsList() { return maCommentsList; } + CommentAuthorList& getCommentAuthors() { return maCommentAuthors; } private: rtl::OUString maPath; @@ -155,6 +148,10 @@ private: std::map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > > maAnimNodesMap; std::map< ::rtl::OUString, ::oox::drawingml::ShapePtr > maShapeMap; + + // slide comments + CommentList maCommentsList; + CommentAuthorList maCommentAuthors; }; } } diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index bbf826764cec..d38d815a8514 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -43,7 +43,7 @@ #include "oox/ppt/pptimport.hxx" #include -#include //for comments +#include using namespace ::com::sun::star; using namespace ::oox::core; @@ -59,6 +59,7 @@ namespace oox { namespace ppt { PresentationFragmentHandler::PresentationFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath ) throw() : FragmentHandler2( rFilter, rFragmentPath ) , mpTextListStyle( new TextListStyle ) +, mbCommentAuthorsRead(false) { TextParagraphPropertiesVector& rParagraphDefaulsVector( mpTextListStyle->getListStyle() ); TextParagraphPropertiesVector::iterator aParagraphDefaultIter( rParagraphDefaulsVector.begin() ); @@ -276,46 +277,76 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, sal_Bool bFirst } } - if( !aCommentFragmentPath.isEmpty() && readCommentAuthors == 0 ) - {// Comments are present and commentAuthors.xml has still not been read - readCommentAuthors = 1; //set to true - rtl::OUString aCommentAuthorsFragmentPath = "ppt/commentAuthors.xml"; - Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY ); - Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() ); - SlidePersistPtr pCommentAuthorsPersistPtr( new SlidePersist( rFilter, sal_False, sal_True, xCommentAuthorsPage, - ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) ); - FragmentHandlerRef xCommentAuthorsFragmentHandler( new SlideFragmentHandler( getFilter(), aCommentAuthorsFragmentPath, pCommentAuthorsPersistPtr, Slide ) ); - - importSlide( xCommentAuthorsFragmentHandler, pCommentAuthorsPersistPtr ); - AuthorList.setValues(*(pCommentAuthorsPersistPtr->getCommentAuthors())); - } - if( !aCommentFragmentPath.isEmpty() ) - { Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY ); - Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() ); - SlidePersistPtr pCommentsPersistPtr( new SlidePersist( rFilter, sal_False, sal_True, xCommentsPage, - ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) ); - FragmentHandlerRef xCommentsFragmentHandler( new SlideFragmentHandler( getFilter(), aCommentFragmentPath, pCommentsPersistPtr, Slide ) ); - pCommentsPersistPtr->getCommentsList()->cmLst.clear(); - importSlide( xCommentsFragmentHandler, pCommentsPersistPtr ); - SlideFragmentHandler *comment_handler = dynamic_cast(xCommentsFragmentHandler.get()); - pCommentsPersistPtr->getCommentsList()->cmLst.back().setText( comment_handler->getCharVector().back() );//set comment chars for last comment on slide - - pCommentsPersistPtr->getCommentAuthors()->setValues(AuthorList); - //insert all comments from commentsList - for(int i=0; igetCommentsList()->getSize(); i++) - { + if( !mbCommentAuthorsRead && !aCommentFragmentPath.isEmpty() ) + { + // Comments are present and commentAuthors.xml has still not been read + mbCommentAuthorsRead = true; + rtl::OUString aCommentAuthorsFragmentPath = "ppt/commentAuthors.xml"; + Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY ); + Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() ); + SlidePersistPtr pCommentAuthorsPersistPtr( + new SlidePersist( rFilter, sal_False, sal_True, xCommentAuthorsPage, + ShapePtr( + new PPTShape( + Slide, "com.sun.star.drawing.GroupShape" ) ), + mpTextListStyle ) ); + FragmentHandlerRef xCommentAuthorsFragmentHandler( + new SlideFragmentHandler( getFilter(), + aCommentAuthorsFragmentPath, + pCommentAuthorsPersistPtr, + Slide ) ); + + importSlide( xCommentAuthorsFragmentHandler, pCommentAuthorsPersistPtr ); + maAuthorList.setValues( pCommentAuthorsPersistPtr->getCommentAuthors() ); + } + if( !aCommentFragmentPath.isEmpty() ) + { + Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY ); + Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() ); + SlidePersistPtr pCommentsPersistPtr( + new SlidePersist( + rFilter, sal_False, sal_True, xCommentsPage, + ShapePtr( + new PPTShape( + Slide, "com.sun.star.drawing.GroupShape" ) ), + mpTextListStyle ) ); + + FragmentHandlerRef xCommentsFragmentHandler( + new SlideFragmentHandler( + getFilter(), + aCommentFragmentPath, + pCommentsPersistPtr, + Slide ) ); + pCommentsPersistPtr->getCommentsList().cmLst.clear(); + importSlide( xCommentsFragmentHandler, pCommentsPersistPtr ); + + //set comment chars for last comment on slide + SlideFragmentHandler* comment_handler = + dynamic_cast(xCommentsFragmentHandler.get()); + pCommentsPersistPtr->getCommentsList().cmLst.back().setText( + comment_handler->getCharVector().back() ); + pCommentsPersistPtr->getCommentAuthors().setValues(maAuthorList); + + //insert all comments from commentsList + for(int i=0; igetCommentsList().getSize(); i++) + { + try { + Comment aComment = pCommentsPersistPtr->getCommentsList().getCommentAtIndex(i); uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW ); uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() ); - int nPosX = pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getIntX(); - int nPosY = pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getIntY(); - xAnnotation->setPosition( geometry::RealPoint2D( ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87 , ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) ); - xAnnotation->setAuthor( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getAuthor(AuthorList) ); - xAnnotation->setDateTime( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).getDateTime() ); + int nPosX = aComment.getIntX(); + int nPosY = aComment.getIntY(); + xAnnotation->setPosition( + geometry::RealPoint2D( + ::oox::drawingml::convertEmuToHmm( nPosX ) * 15.87, + ::oox::drawingml::convertEmuToHmm( nPosY ) * 15.87 ) ); + xAnnotation->setAuthor( aComment.getAuthor(maAuthorList) ); + xAnnotation->setDateTime( aComment.getDateTime() ); uno::Reference< text::XText > xText( xAnnotation->getTextRange() ); - xText->setString( pCommentsPersistPtr->getCommentsList()->getCommentAtIndex(i).get_text()); - } - + xText->setString( aComment.get_text()); + } catch( css::lang::IllegalArgumentException& ) {} } + } } } catch( uno::Exception& ) @@ -365,7 +396,6 @@ void PresentationFragmentHandler::finalizeImport() try { int nPagesImported = 0; - readCommentAuthors = 0; // as commentAuthors.xml has not been read still while (aIter!=aEnd) { if ( rxStatusIndicator.is() ) diff --git a/oox/source/ppt/slidefragmenthandler.cxx b/oox/source/ppt/slidefragmenthandler.cxx index 5d69d3443cdd..6f0cf755bf76 100644 --- a/oox/source/ppt/slidefragmenthandler.cxx +++ b/oox/source/ppt/slidefragmenthandler.cxx @@ -39,7 +39,6 @@ #include "oox/ppt/pptimport.hxx" -using rtl::OUString; using namespace ::com::sun::star; using namespace ::oox::core; using namespace ::oox::drawingml; @@ -192,38 +191,42 @@ SlideFragmentHandler::~SlideFragmentHandler() throw() //for Comments case PPT_TOKEN( cmLst ): - break; + break; case PPT_TOKEN( cm ): - - if(!mpSlidePersistPtr->getCommentsList()->cmLst.empty()) - { mpSlidePersistPtr->getCommentsList()->cmLst.back().setText( getCharVector().back() ); // set comment text for earlier comment + if(!mpSlidePersistPtr->getCommentsList().cmLst.empty()) + { + // set comment text for earlier comment + mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() ); } - mpSlidePersistPtr->getCommentsList()->cmLst.push_back(comment()); // insert a new comment in vector commentsList - mpSlidePersistPtr->getCommentsList()->cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString())); //set AuthorId - mpSlidePersistPtr->getCommentsList()->cmLst.back().setdt(rAttribs.getString(XML_dt, OUString())); //set dt - mpSlidePersistPtr->getCommentsList()->cmLst.back().setidx(rAttribs.getString(XML_idx, OUString())); //set idx + // insert a new comment in vector commentsList + mpSlidePersistPtr->getCommentsList().cmLst.push_back(Comment()); + mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString())); + mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString())); + mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString())); break; case PPT_TOKEN( pos ): - mpSlidePersistPtr->getCommentsList()->cmLst.back().setPoint(rAttribs.getString(XML_x, OUString()),rAttribs.getString(XML_y, OUString())); //set x , set y + mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint( + rAttribs.getString(XML_x, OUString()), + rAttribs.getString(XML_y, OUString())); break; - //case PPT_TOKEN( text ): case PPT_TOKEN( cmAuthor ): - commentAuthor _author; - _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString()); //set clrIdx - _author.id = rAttribs.getString(XML_id, OUString()); // set id - _author.initials = rAttribs.getString(XML_initials, OUString()); // set initials - _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString()); // set lastIdx - _author.name = rAttribs.getString(XML_name, OUString()); //set name - mpSlidePersistPtr->getCommentAuthors()->addAuthor(_author); // insert a new comment Author in cmAuthorList + CommentAuthor _author; + _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString()); + _author.id = rAttribs.getString(XML_id, OUString()); + _author.initials = rAttribs.getString(XML_initials, OUString()); + _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString()); + _author.name = rAttribs.getString(XML_name, OUString()); + mpSlidePersistPtr->getCommentAuthors().addAuthor(_author); + break; } return this; } void SlideFragmentHandler::onCharacters( const OUString& rChars) { - charVector.push_back(rChars); + maCharVector.push_back(rChars); } void SlideFragmentHandler::finalizeImport() { -- cgit