hipp  1.0
hipp/gui/SVGHandler.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2011 Certec, Lund University, Sweden
00003 
00004     This file is part of HIPP.
00005 
00006     HIPP is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     HIPP is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with HIPP.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019  */
00020 
00021 //#include <xercesc/sax2/SAX2XMLReader.hpp>
00022 #include <xercesc/sax2/Attributes.hpp>
00023 #include <xercesc/sax2/DefaultHandler.hpp>
00024 #include <xercesc/sax/SAXParseException.hpp>
00025 #include <xercesc/sax/SAXException.hpp>
00026 #include <string>
00027 #include <boost/scoped_array.hpp>
00028 #include <boost/algorithm/string.hpp>
00029 #include <xercesc/util/XMLString.hpp>
00030 #include "HippShape.h"
00031 #include "HippPolyline.h"
00032 #include "HippLine.h"
00033 #include "HippEllipse.h"
00034 #include "HippRectangle.h"
00035 #include "HippBackground.h"
00036 
00037 #ifndef __SVGHANDLER_H__
00038 #define __SVGHANDLER_H__
00039 
00040 XERCES_CPP_NAMESPACE_USE
00041 using namespace std;
00042 
00043 namespace hipp {
00044 class SVGHandler : public xercesc::DefaultHandler
00045 {
00046 public:
00047         SVGHandler(void);
00048         ~SVGHandler(void);
00049         virtual void startDocument();
00050 
00051         virtual void endDocument();
00052 
00067         virtual void startElement(
00068                 const XMLCh* const uri, 
00069                 const XMLCh* const localname, 
00070                 const XMLCh* const qname, 
00071                 const xercesc::Attributes& attrs);
00072 
00073         virtual void endElement(
00074                 const XMLCh* const uri, 
00075                 const XMLCh* const localname,
00076                 const XMLCh* const qname);
00077 
00078         virtual void characters(
00079                 const XMLCh* const chars,
00080                 const XMLSize_t length);
00081 
00082     // -----------------------------------------------------------------------
00083     //  Handlers for the SAX ErrorHandler interface
00084     // -----------------------------------------------------------------------
00085         void warning(const SAXParseException& exc);
00086     void error(const SAXParseException& exc);
00087     void fatalError(const SAXParseException& exc);
00088 
00089     list<HippShape*> getShapes() const{
00090         return shapes;
00091     }
00092 
00093     static string toNativeString(const XMLCh* str)
00094     {
00095         boost::scoped_array<char> ptr(xercesc::XMLString::transcode(str));
00096         return string(ptr.get( ));
00097     }
00098 
00099     static string toLowerNativeString(const XMLCh* str){
00100                 string s = SVGHandler::toNativeString(str);
00101         boost::to_lower(s);
00102                 return s;
00103     }
00104 
00105 protected:
00106         template <typename T> T createShape(const xercesc::Attributes& attrs, ShapeType type);
00107 private:
00108     HippShape* current;
00109     list<HippShape*> shapes;
00110 };
00111 }
00112 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines