diff options
Diffstat (limited to 'l10ntools/inc/xmlparse.hxx')
-rw-r--r-- | l10ntools/inc/xmlparse.hxx | 250 |
1 files changed, 125 insertions, 125 deletions
diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx index ac2252d2cedb..3ad046df062c 100644 --- a/l10ntools/inc/xmlparse.hxx +++ b/l10ntools/inc/xmlparse.hxx @@ -2,7 +2,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -52,19 +52,19 @@ using namespace ::rtl; using namespace std; #include <hash_map> /* std::hashmap*/ -#include <deque> /* std::deque*/ +#include <deque> /* std::deque*/ #include <iterator> /* std::iterator*/ -#include <list> /* std::list*/ -#include <vector> /* std::vector*/ -#define XML_NODE_TYPE_FILE 0x001 -#define XML_NODE_TYPE_ELEMENT 0x002 -#define XML_NODE_TYPE_DATA 0x003 -#define XML_NODE_TYPE_COMMENT 0x004 -#define XML_NODE_TYPE_DEFAULT 0x005 -#define MAX_LANGUAGES 99 +#include <list> /* std::list*/ +#include <vector> /* std::vector*/ +#define XML_NODE_TYPE_FILE 0x001 +#define XML_NODE_TYPE_ELEMENT 0x002 +#define XML_NODE_TYPE_DATA 0x003 +#define XML_NODE_TYPE_COMMENT 0x004 +#define XML_NODE_TYPE_DEFAULT 0x005 +#define MAX_LANGUAGES 99 -//#define TESTDRIVER /* use xml2gsi testclass */ +//#define TESTDRIVER /* use xml2gsi testclass */ //------------------------------------------------------------------------- /** Holds data of Attributes @@ -73,25 +73,25 @@ class XMLAttribute : public String { private: String sValue; - + public: /// creates an attribute - XMLAttribute( - const String &rName, // attributes name - const String &rValue // attributes data - ) + XMLAttribute( + const String &rName, // attributes name + const String &rValue // attributes data + ) : String( rName ), sValue( rValue ) {} /// getting value of an attribue const String &GetValue() { return sValue; } - + void setValue(const String &rValue){sValue=rValue;} /// returns true if two attributes are equal and have the same value - BOOL IsEqual( - const XMLAttribute &rAttribute // the attribute which has to be equal + BOOL IsEqual( + const XMLAttribute &rAttribute // the attribute which has to be equal ) - { + { return (( rAttribute == *this ) && ( rAttribute.sValue == sValue )); } }; @@ -149,18 +149,18 @@ private: static int dbgcnt; //int nParentPos; protected: - XMLParentNode( XMLParentNode *pPar ) - : XMLChildNode( pPar ), pChildList( NULL ) + XMLParentNode( XMLParentNode *pPar ) + : XMLChildNode( pPar ), pChildList( NULL ) { } XMLParentNode(): pChildList(NULL){ } /// Copyconstructor XMLParentNode( const XMLParentNode& ); - + XMLParentNode& operator=(const XMLParentNode& obj); virtual ~XMLParentNode(); - + public: virtual USHORT GetNodeType() = 0; @@ -169,21 +169,21 @@ public: XMLChildNodeList *GetChildList() { return pChildList; } /// adds a new child - void AddChild( - XMLChildNode *pChild /// the new child + void AddChild( + XMLChildNode *pChild /// the new child ); - void AddChild( - XMLChildNode *pChild , int pos /// the new child + void AddChild( + XMLChildNode *pChild , int pos /// the new child ); - + virtual int GetPosition( ByteString id ); int RemoveChild( XMLElement *pRefElement ); void RemoveAndDeleteAllChilds(); /// returns a child element which matches the given one XMLElement *GetChildElement( - XMLElement *pRefElement // the reference elelement + XMLElement *pRefElement // the reference elelement ); }; @@ -191,19 +191,19 @@ public: DECLARE_LIST( XMLStringList, XMLElement* ) -/// Mapping numeric Language code <-> XML Element +/// Mapping numeric Language code <-> XML Element typedef std::hash_map< ByteString ,XMLElement* , hashByteString,equalByteString > LangHashMap; /// Mapping XML Element string identifier <-> Language Map -typedef std::hash_map<ByteString , LangHashMap* , - hashByteString,equalByteString> XMLHashMap; +typedef std::hash_map<ByteString , LangHashMap* , + hashByteString,equalByteString> XMLHashMap; /// Mapping iso alpha string code <-> iso numeric code -typedef std::hash_map<ByteString, int, hashByteString,equalByteString> HashMap; +typedef std::hash_map<ByteString, int, hashByteString,equalByteString> HashMap; -/// Mapping XML tag names <-> have localizable strings -typedef std::hash_map<ByteString , BOOL , - hashByteString,equalByteString> TagMap; +/// Mapping XML tag names <-> have localizable strings +typedef std::hash_map<ByteString , BOOL , + hashByteString,equalByteString> TagMap; /** Holds information of a XML file, is root node of tree */ @@ -213,52 +213,52 @@ class XMLFile : public XMLParentNode { public: XMLFile() ; - XMLFile( + XMLFile( const String &rFileName // the file name, empty if created from memory stream ); XMLFile( const XMLFile& obj ) ; ~XMLFile(); - - ByteString* GetGroupID(std::deque<ByteString> &groupid); - void Print( XMLNode *pCur = NULL, USHORT nLevel = 0 ); + + ByteString* GetGroupID(std::deque<ByteString> &groupid); + void Print( XMLNode *pCur = NULL, USHORT nLevel = 0 ); virtual void SearchL10NElements( XMLParentNode *pCur, int pos = 0 ); - void Extract( XMLFile *pCur = NULL ); - void View(); -// void static Signal_handler(int signo);//void*,oslSignalInfo * pInfo); - void showType(XMLParentNode* node); + void Extract( XMLFile *pCur = NULL ); + void View(); +// void static Signal_handler(int signo);//void*,oslSignalInfo * pInfo); + void showType(XMLParentNode* node); XMLHashMap* GetStrings(){return XMLStrings;} - BOOL Write( ByteString &rFilename ); - BOOL Write( ofstream &rStream , XMLNode *pCur = NULL ); + BOOL Write( ByteString &rFilename ); + BOOL Write( ofstream &rStream , XMLNode *pCur = NULL ); bool CheckExportStatus( XMLParentNode *pCur = NULL );// , int pos = 0 ); XMLFile& operator=(const XMLFile& obj); - - virtual USHORT GetNodeType(); + + virtual USHORT GetNodeType(); /// returns file name const String &GetName() { return sFileName; } void SetName( const String &rFilename ) { sFileName = rFilename; } void SetFullName( const String &rFullFilename ) { sFullName = rFullFilename; } const std::vector<ByteString> getOrder(){ return order; } - + protected: // writes a string as UTF8 with dos line ends to a given stream void WriteString( ofstream &rStream, const String &sString ); - + // quotes the given text for writing to a file - void QuotHTML( String &rString ); + void QuotHTML( String &rString ); - void InsertL10NElement( XMLElement* pElement); + void InsertL10NElement( XMLElement* pElement); // DATA - String sFileName; + String sFileName; String sFullName; const ByteString ID,OLDREF,XML_LANG; - TagMap nodes_localize; + TagMap nodes_localize; XMLHashMap* XMLStrings; std::vector <ByteString> order; @@ -273,31 +273,31 @@ public: static void QuotHTML( String &rString ); /// UnQuot the XML characters and restore \n \t - static void UnQuotHTML ( String &rString ); - - /// Return the numeric iso language code - //USHORT GetLangByIsoLang( const ByteString &rIsoLang ); + static void UnQuotHTML ( String &rString ); + /// Return the numeric iso language code + //USHORT GetLangByIsoLang( const ByteString &rIsoLang ); + /// Return the alpha strings representation - ByteString GetIsoLangByIndex( USHORT nIndex ); - - static XMLUtil& Instance(); + ByteString GetIsoLangByIndex( USHORT nIndex ); + + static XMLUtil& Instance(); ~XMLUtil(); void dump(); private: - /// Mapping iso alpha string code <-> iso numeric code + /// Mapping iso alpha string code <-> iso numeric code HashMap lMap; - /// Mapping iso numeric code <-> iso alpha string code - ByteString isoArray[MAX_LANGUAGES]; + /// Mapping iso numeric code <-> iso alpha string code + ByteString isoArray[MAX_LANGUAGES]; static void UnQuotData( String &rString ); static void UnQuotTags( String &rString ); - XMLUtil(); - XMLUtil(const XMLUtil&); + XMLUtil(); + XMLUtil(const XMLUtil&); }; @@ -312,37 +312,37 @@ class XMLElement : public XMLParentNode private: String sElementName; XMLAttributeList *pAttributes; - ByteString project, + ByteString project, filename, id, sOldRef, resourceType, languageId; int nPos; - + protected: void Print(XMLNode *pCur, OUStringBuffer& buffer , bool rootelement); public: /// create a element node XMLElement(){} - XMLElement( - const String &rName, // the element name - XMLParentNode *Parent // parent node of this element - ): XMLParentNode( Parent ), - sElementName( rName ), + XMLElement( + const String &rName, // the element name + XMLParentNode *Parent // parent node of this element + ): XMLParentNode( Parent ), + sElementName( rName ), pAttributes( NULL ), - project(""), - filename(""), - id(""), - sOldRef(""), - resourceType(""), + project(""), + filename(""), + id(""), + sOldRef(""), + resourceType(""), languageId(""), nPos(0) { } ~XMLElement(); XMLElement(const XMLElement&); - + XMLElement& operator=(const XMLElement& obj); /// returns node type XML_NODE_ELEMENT virtual USHORT GetNodeType(); @@ -359,15 +359,15 @@ public: void ChangeLanguageTag( const String &rValue ); // Return a ASCII String representation of this object OString ToOString(); - + // Return a Unicode String representation of this object OUString ToOUString(); - - bool Equals(OUString refStr); + + bool Equals(OUString refStr); /// returns a attribute XMLAttribute *GetAttribute( - const String &rName // the attribute name + const String &rName // the attribute name ); void SetProject ( ByteString prj ){ project = prj; } void SetFileName ( ByteString fn ){ filename = fn; } @@ -375,10 +375,10 @@ public: void SetResourceType ( ByteString rt ){ resourceType = rt; } void SetLanguageId ( ByteString lid ){ languageId = lid; } void SetPos ( int nPos_in ){ nPos = nPos_in; } - void SetOldRef ( ByteString sOldRef_in ){ sOldRef = sOldRef_in; } + void SetOldRef ( ByteString sOldRef_in ){ sOldRef = sOldRef_in; } virtual int GetPos() { return nPos; } - ByteString GetProject() { return project; } + ByteString GetProject() { return project; } ByteString GetFileName() { return filename; } ByteString GetId() { return id; } ByteString GetOldref() { return sOldRef; } @@ -400,20 +400,20 @@ private: public: /// create a data node - XMLData( - const String &rData, // the initial data - XMLParentNode *Parent // the parent node of this data, typically a element node - ) - : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){} - XMLData( - const String &rData, // the initial data - XMLParentNode *Parent, // the parent node of this data, typically a element node + XMLData( + const String &rData, // the initial data + XMLParentNode *Parent // the parent node of this data, typically a element node + ) + : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){} + XMLData( + const String &rData, // the initial data + XMLParentNode *Parent, // the parent node of this data, typically a element node bool newCreated - ) - : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( newCreated ){} - + ) + : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( newCreated ){} + XMLData(const XMLData& obj); - + XMLData& operator=(const XMLData& obj); virtual USHORT GetNodeType(); @@ -422,12 +422,12 @@ public: bool isNew() { return isNewCreated; } /// adds new character data to the existing one - void AddData( - const String &rData // the new data - ); - - - + void AddData( + const String &rData // the new data + ); + + + }; //------------------------------------------------------------------------- @@ -442,17 +442,17 @@ private: public: /// create a comment node XMLComment( - const String &rComment, // the comment - XMLParentNode *Parent // the parent node of this comemnt, typically a element node + const String &rComment, // the comment + XMLParentNode *Parent // the parent node of this comemnt, typically a element node ) : XMLChildNode( Parent ), sComment( rComment ) {} virtual USHORT GetNodeType(); XMLComment( const XMLComment& obj ); - + XMLComment& operator=(const XMLComment& obj); - + /// returns the comment const String &GetComment() { return sComment; } }; @@ -469,15 +469,15 @@ private: public: /// create a comment node XMLDefault( - const String &rDefault, // the comment - XMLParentNode *Parent // the parent node of this comemnt, typically a element node + const String &rDefault, // the comment + XMLParentNode *Parent // the parent node of this comemnt, typically a element node ) : XMLChildNode( Parent ), sDefault( rDefault ) {} XMLDefault(const XMLDefault& obj); XMLDefault& operator=(const XMLDefault& obj); - + /// returns node type XML_NODE_TYPE_COMMENT virtual USHORT GetNodeType(); @@ -490,17 +490,17 @@ public: /** struct for error information, used by class SimpleXMLParser */ struct XMLError { - XML_Error eCode; // the error code - ULONG nLine; // error line number - ULONG nColumn; // error column number - String sMessage; // readable error message + XML_Error eCode; // the error code + ULONG nLine; // error line number + ULONG nColumn; // error column number + String sMessage; // readable error message }; //------------------------------------------------------------------------- /** validating xml parser, creates a document tree with xml nodes */ - + class SimpleXMLParser { @@ -511,21 +511,21 @@ private: XMLFile *pXMLFile; XMLParentNode *pCurNode; XMLData *pCurData; - - + + static void StartElementHandler( void *userData, const XML_Char *name, const XML_Char **atts ); static void EndElementHandler( void *userData, const XML_Char *name ); static void CharacterDataHandler( void *userData, const XML_Char *s, int len ); static void CommentHandler( void *userData, const XML_Char *data ); static void DefaultHandler( void *userData, const XML_Char *s, int len ); - - + + void StartElement( const XML_Char *name, const XML_Char **atts ); void EndElement( const XML_Char *name ); void CharacterData( const XML_Char *s, int len ); void Comment( const XML_Char *data ); void Default( const XML_Char *s, int len ); - + public: /// creates a new parser @@ -533,15 +533,15 @@ public: ~SimpleXMLParser(); /// parse a file, returns NULL on criticall errors - XMLFile *Execute( + XMLFile *Execute( const String &rFullFileName, - const String &rFileName, // the file name + const String &rFileName, // the file name XMLFile *pXMLFileIn // the XMLFile ); /// parse a memory stream, returns NULL on criticall errors - XMLFile *Execute( - SvMemoryStream *pStream // the stream + XMLFile *Execute( + SvMemoryStream *pStream // the stream ); /// returns an error struct |