aknlayoutcompiler/inc/MLAttributesParse.h
changeset 0 f58d6ec98e88
child 1 b700e12870ca
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef MLATTRIBUTESPARSE_H
       
    21 #define MLATTRIBUTESPARSE_H
       
    22 
       
    23 // disable "identifier was truncated to '255' characters in the browser information" warning
       
    24 #pragma warning (disable:4786)
       
    25 
       
    26 #include "LayoutCompilerErr.h"
       
    27 #include "MLAttributes.h"
       
    28 
       
    29 #include <avkon.hrh> // for logical font ids
       
    30 
       
    31 #include "SaxErrorHandler.h"
       
    32 
       
    33 #include <vector>
       
    34 #include <string>
       
    35 #include <iosfwd>
       
    36 #include <stack>
       
    37 
       
    38 using namespace std;
       
    39 
       
    40 
       
    41 //
       
    42 // defines
       
    43 //
       
    44 
       
    45 /**
       
    46  * this is the interface to the SAX handler
       
    47  */
       
    48 class MSaxLayoutAttributesHandler
       
    49 	{
       
    50 public:
       
    51 	typedef SAX::basic_Attributes<std::string> TAttribs; // this is XML Attribs, not to be confused with layout attibutes!
       
    52 	virtual MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs) { return this; };
       
    53 	virtual void HandleSaxEnd(const std::string& aElement) { };
       
    54 	};
       
    55 
       
    56 
       
    57 /**
       
    58  * this corresponds to an attribute set in the xml
       
    59  */
       
    60 class TMLAttributeSetParse : public TMLAttributeSet, public MSaxLayoutAttributesHandler
       
    61 	{
       
    62 public:
       
    63 	TMLAttributeSetParse(TMLAttributes* aAttributes);
       
    64 public: // from MSaxLayoutHandler
       
    65 	MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs);
       
    66 	void HandleSaxEnd(const std::string& aElement);
       
    67 public: // new methods
       
    68 	int CompId() const;
       
    69 	string Name() const;
       
    70 private:
       
    71 	void HandleSaxAttribute(const TAttribs& aAttribs);
       
    72 	void HandleSaxCalc(const TAttribs& aAttribs);
       
    73 private:
       
    74 	int iId;
       
    75 	int iCompId;
       
    76 	string iName;
       
    77 	TMLAttributeZoomLevels* iSaxZoomLevels;
       
    78 	};
       
    79 
       
    80 /**
       
    81  *  this corresponds to attributes in the xml
       
    82  */
       
    83 class TMLAttributesParse : public TMLAttributes, public MSaxLayoutAttributesHandler
       
    84 	{
       
    85 public:
       
    86 	static auto_ptr<TMLAttributesParse> Parse(const string& aLayName);
       
    87 	TMLAttributesParse();
       
    88 public: // from MSaxLayoutHandler
       
    89 	MSaxLayoutAttributesHandler* HandleSax(const std::string& aElement, const TAttribs& aAttribs);
       
    90 	void HandleSaxEnd(const std::string& aElement);
       
    91 private: // owned
       
    92 	TMLAttributeSetParse* iSaxAttributeSet;
       
    93 	};
       
    94 
       
    95 /**
       
    96  * this is the main SAX parser implementation
       
    97  */
       
    98 class TLayoutAttributesSaxParser : private SAX::basic_DefaultHandler<std::string>
       
    99 	{
       
   100 private:
       
   101 	typedef stack<MSaxLayoutAttributesHandler*> TSaxAttributesHandlerStack;
       
   102 	typedef SAX::basic_ErrorHandler<std::string>::SAXParseExceptionT TException;
       
   103 
       
   104 public:
       
   105 	TLayoutAttributesSaxParser(MSaxLayoutAttributesHandler* aHandler);
       
   106 	void Parse(const std::string& aFileName);
       
   107 
       
   108 private: // from basic_DefaultHandler
       
   109 	void startElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName, const SAX::basic_Attributes<std::string>& atts);
       
   110 	void endElement(const std::string& namespaceURI, const std::string& localName, const std::string& qName);
       
   111 
       
   112 	void warning(const TException& aException);
       
   113 	void error(const TException& aException);
       
   114 	void fatalError(const TException& aException);
       
   115 
       
   116 private:
       
   117 	TSaxAttributesHandlerStack iStack;	// stack content not owned
       
   118 	};
       
   119 
       
   120 
       
   121 #endif // MLATTRIBUTESPARSE_H
       
   122 
       
   123 // End of File