diff options
Diffstat (limited to 'l10ntools/inc')
-rw-r--r-- | l10ntools/inc/cfgmerge.hxx | 208 | ||||
-rw-r--r-- | l10ntools/inc/export.hxx | 586 | ||||
-rw-r--r-- | l10ntools/inc/gsicheck.hxx | 131 | ||||
-rw-r--r-- | l10ntools/inc/helpmerge.hxx | 87 | ||||
-rw-r--r-- | l10ntools/inc/inireader.hxx | 52 | ||||
-rw-r--r-- | l10ntools/inc/l10ntools/directory.hxx | 54 | ||||
-rw-r--r-- | l10ntools/inc/l10ntools/file.hxx | 23 | ||||
-rw-r--r-- | l10ntools/inc/l10ntools/vosapp.hxx | 33 | ||||
-rw-r--r-- | l10ntools/inc/lngmerge.hxx | 69 | ||||
-rw-r--r-- | l10ntools/inc/makefile.mk | 51 | ||||
-rw-r--r-- | l10ntools/inc/pch/precompiled_l10ntools.cxx | 32 | ||||
-rw-r--r-- | l10ntools/inc/pch/precompiled_l10ntools.hxx | 35 | ||||
-rw-r--r-- | l10ntools/inc/srciter.hxx | 61 | ||||
-rw-r--r-- | l10ntools/inc/tagtest.hxx | 399 | ||||
-rw-r--r-- | l10ntools/inc/tokens.h | 112 | ||||
-rw-r--r-- | l10ntools/inc/treeconfig.hxx | 28 | ||||
-rw-r--r-- | l10ntools/inc/utf8conv.hxx | 47 | ||||
-rw-r--r-- | l10ntools/inc/wrdtrans.hxx | 90 | ||||
-rw-r--r-- | l10ntools/inc/wtranode.hxx | 121 | ||||
-rw-r--r-- | l10ntools/inc/wtratree.hxx | 162 | ||||
-rw-r--r-- | l10ntools/inc/xmlparse.hxx | 553 | ||||
-rw-r--r-- | l10ntools/inc/xmlutil.hxx | 9 | ||||
-rw-r--r-- | l10ntools/inc/xrmmerge.hxx | 161 |
23 files changed, 3104 insertions, 0 deletions
diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx new file mode 100644 index 000000000000..9f1c97f05af5 --- /dev/null +++ b/l10ntools/inc/cfgmerge.hxx @@ -0,0 +1,208 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cfgmerge.hxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CFG_MERGE_HXX +#define _CFG_MERGE_HXX + +#include <tools/string.hxx> +#include <tools/list.hxx> +#include <hash_map> + +typedef std::hash_map<ByteString , ByteString , hashByteString,equalByteString> + ByteStringHashMap; + + +// +// class CfgStackData +// + +class CfgStackData +{ +friend class CfgParser; +friend class CfgExport; +friend class CfgMerge; +private: + ByteString sTagType; + ByteString sIdentifier; + + ByteString sResTyp; + + ByteString sTextTag; + ByteString sEndTextTag; + + ByteStringHashMap sText; +public: + CfgStackData( const ByteString &rTag, const ByteString &rId ) + : sTagType( rTag ), sIdentifier( rId ) {}; + + ByteString &GetTagType() { return sTagType; } + ByteString &GetIdentifier() { return sIdentifier; } + +}; + +// +// class CfgStack +// + +DECLARE_LIST( CfgStackList, CfgStackData * ) + +class CfgStack : public CfgStackList +{ +public: + CfgStack() : CfgStackList( 10, 10 ) {} + ~CfgStack(); + + ULONG Push( CfgStackData *pStackData ); + CfgStackData *Push( const ByteString &rTag, const ByteString &rId ); + CfgStackData *Pop() { return Remove( Count() - 1 ); } + + CfgStackData *GetStackData( ULONG nPos = LIST_APPEND ); + + ByteString GetAccessPath( ULONG nPos = LIST_APPEND ); +}; + +// +// class CfgParser +// + +class CfgParser +{ +protected: + ByteString sCurrentResTyp; + ByteString sCurrentIsoLang; + ByteString sCurrentText; + + ByteString sLastWhitespace; + + CfgStack aStack; + CfgStackData *pStackData; + + BOOL bLocalize; + + virtual void WorkOnText( + ByteString &rText, + const ByteString &nLangIndex )=0; + + virtual void WorkOnRessourceEnd()=0; + + virtual void Output( const ByteString& rOutput )=0; + + void Error( const ByteString &rError ); + +private: + int ExecuteAnalyzedToken( int nToken, char *pToken ); + std::vector<ByteString> aLanguages; + void AddText( + ByteString &rText, + const ByteString &rIsoLang, + const ByteString &rResTyp ); + +BOOL IsTokenClosed( const ByteString &rToken ); + +public: + CfgParser(); + virtual ~CfgParser(); + + int Execute( int nToken, char * pToken ); +}; + +// +// class CfgOutputParser +// + +class CfgOutputParser : public CfgParser +{ +protected: + SvFileStream *pOutputStream; +public: + CfgOutputParser ( const ByteString &rOutputFile ); + virtual ~CfgOutputParser(); +}; + +// +// class CfgExport +// + +class CfgExport : public CfgOutputParser +{ +private: + ByteString sPrj; + ByteString sPath; + std::vector<ByteString> aLanguages; +protected: + void WorkOnText( + ByteString &rText, + const ByteString &rIsoLang + ); + + void WorkOnRessourceEnd(); + void Output( const ByteString& rOutput ); +public: + CfgExport( + const ByteString &rOutputFile, + const ByteString &rProject, + const ByteString &rFilePath + ); + ~CfgExport(); +}; + +// +// class CfgMerge +// + +class CfgMerge : public CfgOutputParser +{ +private: + MergeDataFile *pMergeDataFile; + std::vector<ByteString> aLanguages; + ResData *pResData; + + BOOL bGerman; + ByteString sFilename; + BOOL bEnglish; + +protected: + void WorkOnText( + ByteString &rText, + const ByteString &nLangIndex ); + + void WorkOnRessourceEnd(); + + void Output( const ByteString& rOutput ); +public: + CfgMerge( + const ByteString &rMergeSource, + const ByteString &rOutputFile, + ByteString &rFilename + ); + ~CfgMerge(); +}; + +#endif diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx new file mode 100644 index 000000000000..6d94297c25fb --- /dev/null +++ b/l10ntools/inc/export.hxx @@ -0,0 +1,586 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: export.hxx,v $ + * $Revision: 1.27 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _EXPORT_HXX +#define _EXPORT_HXX + +#ifndef L10NTOOLS_DIRECTORY_HXX +#define L10NTOOLS_DIRECTORY_HXX +#include <l10ntools/directory.hxx> +#endif + + +// #define MERGE_SOURCE_LANGUAGES <- To merge en-US and de resource + +#include <tools/string.hxx> +#include <tools/list.hxx> +#include <tools/stream.hxx> +#include <tools/fsys.hxx> +#include <osl/file.hxx> +#include <osl/file.h> + +#include <hash_map> /* std::hashmap*/ +#include <iterator> /* std::iterator*/ +#include <set> /* std::set*/ +#include <vector> /* std::vector*/ +#include <queue> +#include <string> + +#include <unistd.h> +#ifdef WNT +#include <direct.h> +#endif + +#define NO_TRANSLATE_ISO "x-no-translate" + +#define JAPANESE_ISO "ja" + + +struct eqstr{ + BOOL operator()(const char* s1, const char* s2) const{ + return strcmp(s1,s2)==0; + } +}; + +struct equalByteString{ + bool operator()( const ByteString& rKey1, const ByteString& rKey2 ) const { + return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL; + } +}; +struct lessByteString{ + bool operator()( const ByteString& rKey1, const ByteString& rKey2 ) const { + return rKey1.CompareTo( rKey2 )==COMPARE_LESS; + } +}; + +struct hashByteString{ + size_t operator()( const ByteString& rName ) const{ + std::hash< const char* > myHash; + return myHash( rName.GetBuffer() ); + } +}; + +class PFormEntrys; +class MergeData; +typedef std::set<ByteString , lessByteString > ByteStringSet; + +typedef std::hash_map<ByteString , ByteString , hashByteString,equalByteString> + ByteStringHashMap; + +typedef std::hash_map<ByteString , bool , hashByteString,equalByteString> + ByteStringBoolHashMap; + +typedef std::hash_map<ByteString , PFormEntrys* , hashByteString,equalByteString> + PFormEntrysHashMap; + +typedef std::hash_map<ByteString , MergeData* , hashByteString,equalByteString> + MergeDataHashMap; + +#define SOURCE_LANGUAGE ByteString("en-US") +#define LIST_REFID "LIST_REFID" + +typedef ByteStringHashMap ExportListEntry; + +DECLARE_LIST( ExportListBase, ExportListEntry * ) + +// +// class ExportList +// + +class ExportList : public ExportListBase +{ +private: + ULONG nSourceLanguageListEntryCount; + +public: + ExportList() : ExportListBase() { nSourceLanguageListEntryCount = 0; } + ULONG GetSourceLanguageListEntryCount() { return nSourceLanguageListEntryCount; } + void NewSourceLanguageListEntry() { nSourceLanguageListEntryCount++; } +}; + +#define REFID_NONE 0xFFFF + +// +// struct ResData +// + +/****************************************************************************** +* Purpose: holds mandatory data to export a single res (used with ResStack) +******************************************************************************/ + +#define ID_LEVEL_NULL 0x0000 +#define ID_LEVEL_AUTOID 0x0001 +#define ID_LEVEL_TEXT 0x0002 +#define ID_LEVEL_FIELDNAME 0x0003 +#define ID_LEVEL_ACCESSPATH 0x0004 +#define ID_LEVEL_IDENTIFIER 0x0005 +#define ID_LEVEL_LISTINDEX 0x0006 + +class ResData +{ +public: + ~ResData(); + BOOL SetId( const ByteString &rId, USHORT nLevel ); + + USHORT nWidth; + USHORT nChildIndex; + USHORT nIdLevel; + BOOL bChild; + BOOL bChildWithText; + + BOOL bText; + BOOL bHelpText; + BOOL bQuickHelpText; + BOOL bTitle; + BOOL bList; + + BOOL bRestMerged; + + ByteString sResTyp; + ByteString sId; + ByteString sGId; + ByteString sHelpId; + ByteString sFilename; + + ByteStringHashMap sText; + USHORT nTextRefId; + + ByteStringHashMap sHelpText; + USHORT nHelpTextRefId; + + ByteStringHashMap sQuickHelpText; + USHORT nQuickHelpTextRefId; + + ByteStringHashMap sTitle; + USHORT nTitleRefId; + + ByteString sTextTyp; + ByteStringHashMap aFallbackData; + ByteStringHashMap aMergedLanguages; + + ExportList *pStringList; + ExportList *pUIEntries; + ExportList *pItemList; + ExportList *pFilterList; + ExportList *pPairedList; + + ByteString sPForm; + + void Dump(); + void addFallbackData( ByteString& sId , const ByteString& sText ); + bool getFallbackData( ByteString& sId , ByteString& sText); + + void addMergedLanguage( ByteString& sLang ); + bool isMerged( ByteString& sLang ); + ResData( const ByteString &rPF, const ByteString &rGId ) + : + nWidth( 0 ), + nChildIndex( 0 ), + nIdLevel( ID_LEVEL_NULL ), + bChild( FALSE ), + bChildWithText( FALSE ), + bText( FALSE ), + bHelpText( FALSE ), + bQuickHelpText( FALSE ), + bTitle( FALSE ), + bList( FALSE ), + bRestMerged( FALSE ), + sGId( rGId ), + nTextRefId( REFID_NONE ), + nHelpTextRefId( REFID_NONE ), + nQuickHelpTextRefId( REFID_NONE ), + nTitleRefId( REFID_NONE ), + sTextTyp( "Text" ), + pStringList( NULL ), + pUIEntries( NULL ), + pItemList( NULL ), + pFilterList( NULL ), + pPairedList( NULL ), + sPForm( rPF ) + { + sGId.EraseAllChars( '\r' ); + sPForm.EraseAllChars( '\r' ); + }; + ResData( const ByteString &rPF, const ByteString &rGId , const ByteString &rFilename ) + : + nChildIndex( 0 ), + nIdLevel( ID_LEVEL_NULL ), + bChild( FALSE ), + bChildWithText( FALSE ), + bText( FALSE ), + bHelpText( FALSE ), + bQuickHelpText( FALSE ), + bTitle( FALSE ), + bList( FALSE ), + bRestMerged( FALSE ), + sGId( rGId ), + sFilename( rFilename ), + nTextRefId( REFID_NONE ), + nHelpTextRefId( REFID_NONE ), + nQuickHelpTextRefId( REFID_NONE ), + nTitleRefId( REFID_NONE ), + sTextTyp( "Text" ), + pStringList( NULL ), + pUIEntries( NULL ), + pItemList( NULL ), + pFilterList( NULL ), + pPairedList( NULL ), + sPForm( rPF ) + + { + sGId.EraseAllChars( '\r' ); + sPForm.EraseAllChars( '\r' ); + }; + + +}; + + +// +// class Export +// + +/****************************************************************************** +* Purpose: syntax check and export of *.src, called from lexer +******************************************************************************/ + +#define LIST_NON 0x0000 +#define LIST_STRING 0x0001 +#define LIST_FILTER 0x0002 +#define LIST_ITEM 0x0004 +#define LIST_PAIRED 0x0005 +#define LIST_UIENTRIES 0x0008 +#define STRING_TYP_TEXT 0x0010 +#define STRING_TYP_HELPTEXT 0x0020 +#define STRING_TYP_QUICKHELPTEXT 0x0040 +#define STRING_TYP_TITLE 0x0080 + +#define MERGE_MODE_NORMAL 0x0000 +#define MERGE_MODE_LIST 0x0001 + +DECLARE_LIST( ResStack, ResData * ) +// forwards +class WordTransformer; +class ParserQueue; + +class Export +{ +private: + WordTransformer *pWordTransformer; + + CharSet aCharSet; // used charset in src + + SvFileStream aOutput; + + ResStack aResStack; // stack for parsing recursive + + ByteString sActPForm; // hold cur. system + + BOOL bDefine; // cur. res. in a define? + BOOL bNextMustBeDefineEOL; // define but no \ at lineend + ULONG nLevel; // res. recursiv? how deep? + USHORT nList; // cur. res. is String- or FilterList + ByteString nListLang; + ULONG nListIndex; + ULONG nListLevel; + bool bSkipFile; + ByteString sProject; + ByteString sRoot; + BOOL bEnableExport; + BOOL bMergeMode; + ByteString sMergeSrc; + ByteString sLastListLine; + BOOL bError; // any errors while export? + BOOL bReadOver; + BOOL bDontWriteOutput; + ByteString sLastTextTyp; + static bool isInitialized; + ByteString sFilename; + + +public: + ParserQueue* pParseQueue; // public ? + static ByteString sLanguages; // public ? + static ByteString sForcedLanguages; // public ? + + + static bool skipProject( ByteString sPrj ) ; + static void InitLanguages( bool bMergeMode = false ); + static void InitForcedLanguages( bool bMergeMode = false ); + static std::vector<ByteString> GetLanguages(); + static std::vector<ByteString> GetForcedLanguages(); + + static void SetLanguages( std::vector<ByteString> val ); + static void RemoveUTF8ByteOrderMarker( ByteString &rString ); + static bool hasUTF8ByteOrderMarker( const ByteString &rString ); + static void RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ); + static bool fileHasUTF8ByteOrderMarker( const ByteString &rString ); + static ByteString GetIsoLangByIndex( USHORT nIndex ); + static void QuotHTML( ByteString &rString ); + static bool CopyFile( const ByteString& source , const ByteString& dest ); + + static void QuotHTMLXRM( ByteString &rString ); + static void UnquotHTML( ByteString &rString ); + + static const char* GetEnv( const char *pVar ); + static int getCurrentDirectory( rtl::OUString& base_fqurl , rtl::OUString& base ); + + static bool isSourceLanguage( const ByteString &sLanguage ); + static bool isAllowed( const ByteString &sLanguage ); + + static bool LanguageAllowed( const ByteString &nLanguage ); + static void Languages( std::vector<ByteString>::const_iterator& begin , std::vector<ByteString>::const_iterator& end ); + static void getRandomName( const ByteString& sPrefix , ByteString& sRandStr , const ByteString& sPostfix ); + static void getRandomName( ByteString& sRandStr ); + static void getCurrentDir( std::string& dir ); + + static void replaceEncoding( ByteString& rString ); + + static ByteString GetFallbackLanguage( const ByteString nLanguage ); + static void FillInFallbacks( ResData *pResData ); + static void FillInListFallbacks( ExportList *pList, const ByteString &nSource, const ByteString &nFallback ); + static ByteString GetTimeStamp(); + static BOOL ConvertLineEnds( ByteString sSource, ByteString sDestination ); + static ByteString GetNativeFile( ByteString sSource ); + static DirEntry GetTempFile(); + + static void DumpExportList( ByteString& sListName , ExportList& aList ); + static ByteString DumpMap( ByteString& sMapName , ByteStringHashMap& aMap ); + +private: + static std::vector<ByteString> aLanguages; + static std::vector<ByteString> aForcedLanguages; + + BOOL ListExists( ResData *pResData, USHORT nLst ); + + BOOL WriteData( ResData *pResData, BOOL bCreateNew = FALSE );// called befor dest. cur ResData + BOOL WriteExportList( ResData *pResData, ExportList *pExportList, + const ByteString &rTyp, BOOL bCreateNew = FALSE ); + + ByteString MergePairedList( ByteString& sLine , ByteString& sText ); + + ByteString FullId(); // creates cur. GID + + bool PairedListFallback( ByteString& sText , ResData& aResData ); + + ByteString GetPairedListID ( const ByteString& sText ); + ByteString GetPairedListString ( const ByteString& sText ); + ByteString StripList ( const ByteString& sText ); + + void UnmergeUTF8( ByteString& sOrig ); + void InsertListEntry( const ByteString &rText, const ByteString &rLine ); + void CleanValue( ByteString &rValue ); + ByteString GetText( const ByteString &rSource, int nToken ); + + BOOL PrepareTextToMerge( ByteString &rText, USHORT nTyp, + ByteString &nLangIndex, ResData *pResData ); + + void MergeRest( ResData *pResData, USHORT nMode = MERGE_MODE_NORMAL ); + void ConvertMergeContent( ByteString &rText ); + + void WriteToMerged( const ByteString &rText , bool bSDFContent ); + void SetChildWithText(); + + void CutComment( ByteString &rText ); + +public: + Export( const ByteString &rOutput, BOOL bWrite, + const ByteString &rPrj, const ByteString &rPrjRoot , const ByteString& rFile ); + Export( const ByteString &rOutput, BOOL bWrite, + const ByteString &rPrj, const ByteString &rPrjRoot, + const ByteString &rMergeSource , const ByteString& rFile ); + ~Export(); + + void Init(); + int Execute( int nToken, const char * pToken ); // called from lexer + void SetError() { bError = TRUE; } + BOOL GetError() { return bError; } +}; + + +// +// class PFormEntrys +// + +/****************************************************************************** +* Purpose: holds information of data to merge (one pform) +******************************************************************************/ + +class PFormEntrys : public ByteString +{ +friend class MergeDataFile; +private: + ByteString sHelpText; // empty string + ByteStringHashMap sText; + ByteStringBoolHashMap bTextFirst; + ByteStringHashMap sQuickHelpText; + ByteStringBoolHashMap bQuickHelpTextFirst; + ByteStringHashMap sTitle; + ByteStringBoolHashMap bTitleFirst; + +public: + PFormEntrys( const ByteString &rPForm ) : ByteString( rPForm ) {}; + ByteString Dump(); + void InsertEntry( + const ByteString &nId , + const ByteString &rText, + const ByteString &rQuickHelpText, + const ByteString &rTitle + ) + { + + sText[ nId ] = rText; + bTextFirst[ nId ] = true; + sQuickHelpText[ nId ] = rQuickHelpText; + bQuickHelpTextFirst[ nId ] = true; + sTitle[ nId ] = rTitle; + bTitleFirst[ nId ] = true; + } + BOOL GetText( ByteString &rReturn, USHORT nTyp, const ByteString &nLangIndex, BOOL bDel = FALSE ); +}; + +// +// class MergeData +// + +/****************************************************************************** +* Purpose: holds information of data to merge (one ressource) +******************************************************************************/ + +class MergeDataFile; + +class MergeData +{ +friend class MergeDataFile; +private: + ByteString sTyp; + ByteString sGID; + ByteString sLID; + ByteString sFilename; + PFormEntrysHashMap aMap; +public: + MergeData( const ByteString &rTyp, const ByteString &rGID, const ByteString &rLID , const ByteString &rFilename ) + : sTyp( rTyp ), sGID( rGID ), sLID( rLID ) , sFilename( rFilename ) {}; + ~MergeData(); + PFormEntrys* InsertEntry( const ByteString &rPForm ); + PFormEntrys* GetPFormEntrys( ResData *pResData ); + + void Insert( const ByteString& rPFO , PFormEntrys* pfEntrys ); + PFormEntrys* GetPFObject( const ByteString& rPFO ); + + ByteString Dump(); + BOOL operator==( ResData *pData ); +}; + +// +// class MergeDataFile +// + +/****************************************************************************** +* Purpose: holds information of data to merge +******************************************************************************/ + +class MergeDataFile +{ +private: + BOOL bErrorLog; + ByteString sErrorLog; + SvFileStream aErrLog; + ByteStringSet aLanguageSet; + MergeDataHashMap aMap; + ByteStringHashMap aLanguageMap; + std::vector<ByteString> aLanguageList; + ByteStringHashMap aFilenames; + + +public: + MergeDataFile( const ByteString &rFileName, const ByteString& rFile , BOOL bErrLog, CharSet aCharSet, bool bCaseSensitive = false ); + ~MergeDataFile(); + + + std::vector<ByteString> GetLanguages(); + MergeData *GetMergeData( ResData *pResData , bool bCaseSensitve = false ); + + PFormEntrys *GetPFormEntrys( ResData *pResData ); + PFormEntrys *GetPFormEntrysCaseSensitive( ResData *pResData ); + + void InsertEntry( const ByteString &rTYP, const ByteString &rGID, const ByteString &rLID, + const ByteString &rPFO, + const ByteString &nLang , const ByteString &rTEXT, + const ByteString &rQHTEXT, const ByteString &rTITLE , + const ByteString &sFilename , bool bCaseSensitive + ); + static USHORT GetLangIndex( USHORT nId ); + static ByteString CreateKey( const ByteString& rTYP , const ByteString& rGID , const ByteString& rLID , const ByteString& rFilename , bool bCaseSensitive = false ); + + ByteString Dump(); + void WriteError( const ByteString &rLine ); +}; + + +class QueueEntry +{ +public: + QueueEntry( int nTypVal , ByteString sLineVal ): nTyp( nTypVal ) , sLine( sLineVal ){}; + int nTyp; + ByteString sLine; +}; + +class ParserQueue +{ +public: + + ParserQueue( Export& aExportObj ); + ~ParserQueue(); + + inline void Push( const QueueEntry& aEntry ); + bool bCurrentIsM; // public ? + bool bNextIsM; // public ? + bool bLastWasM; // public ? + bool bMflag; // public ? + + void Close(); +private: + // Future / Next + std::queue<QueueEntry>* aQueueNext; + // Current + std::queue<QueueEntry>* aQueueCur; + // Ref + std::queue<QueueEntry>* aQref; + + Export& aExport; + bool bStart; + bool bStartNext; + + inline void Pop( std::queue<QueueEntry>& aQueue ); + +}; +#endif + diff --git a/l10ntools/inc/gsicheck.hxx b/l10ntools/inc/gsicheck.hxx new file mode 100644 index 000000000000..13debcfc7106 --- /dev/null +++ b/l10ntools/inc/gsicheck.hxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: gsicheck.hxx,v $ + * $Revision: 1.8.22.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _GSICHECK_HXX_ +#define _GSICHECK_HXX_ + +#include "tagtest.hxx" + +// +// class GSILine +// +enum LineFormat { FORMAT_GSI, FORMAT_SDF, FORMAT_UNKNOWN }; + +class GSILine : public ByteString +{ +private: + + ParserMessageList aMessages; + LineFormat aFormat; + ULONG nLineNumber; + + ByteString aUniqId; + ByteString aLineType; + ByteString aLangId; + ByteString aText; + ByteString aQuickHelpText; + ByteString aTitle; + + BOOL bOK; + BOOL bFixed; + + void ReassembleLine(); + +public: + GSILine( const ByteString &rLine, ULONG nLine ); + LineFormat GetLineFormat() const { return aFormat; } + ULONG GetLineNumber() const { return nLineNumber; } + + ByteString const GetUniqId() const { return aUniqId; } + ByteString const GetLineType() const { return aLineType; } + ByteString const GetLanguageId() const { return aLangId; } + ByteString const GetText() const { return aText; } + String const GetUText() const { return String( aText, RTL_TEXTENCODING_UTF8 ); } + ByteString const GetQuickHelpText() const { return aQuickHelpText; } + ByteString const GetTitle() const { return aTitle; } + + void SetUText( String &aNew ) { aText = ByteString( aNew, RTL_TEXTENCODING_UTF8 ); ReassembleLine(); } + void SetText( ByteString &aNew ) { aText = aNew; ReassembleLine(); } + void SetQuickHelpText( ByteString &aNew ) { aQuickHelpText = aNew; ReassembleLine(); } + void SetTitle( ByteString &aNew ) { aTitle = aNew; ReassembleLine(); } + + ParserMessageList* GetMessageList() { return &aMessages; }; + BOOL HasMessages(){ return ( aMessages.Count() > 0 ); }; + + BOOL IsOK() const { return bOK; } + void NotOK(); + + BOOL IsFixed() const { return bFixed; } + void SetFixed() { bFixed = TRUE; }; +}; + +// +// class GSIBlock +// + +DECLARE_LIST( GSIBlock_Impl, GSILine * ) + +class LazySvFileStream; + +class GSIBlock : public GSIBlock_Impl +{ +private: + GSILine *pSourceLine; + GSILine *pReferenceLine; + void PrintList( ParserMessageList *pList, ByteString aPrefix, GSILine *pLine ); + BOOL bPrintContext; + BOOL bCheckSourceLang; + BOOL bCheckTranslationLang; + BOOL bReference; + BOOL bAllowKeyIDs; + BOOL bAllowSuspicious; + + BOOL bHasBlockError; + + BOOL IsUTF8( const ByteString &aTestee, BOOL bFixTags, USHORT &nErrorPos, ByteString &aErrorMsg, BOOL &bHasBeenFixed, ByteString &aFixed ) const; + BOOL TestUTF8( GSILine* pTestee, BOOL bFixTags ); + BOOL HasSuspiciousChars( GSILine* pTestee, GSILine* pSource ); + +public: + GSIBlock( BOOL PbPrintContext, BOOL bSource, BOOL bTrans, BOOL bRef, BOOL bAllowKID, BOOL bAllowSusp ); + ~GSIBlock(); + void PrintMessage( ByteString aType, ByteString aMsg, ByteString aPrefix, ByteString aContext, ULONG nLine, ByteString aUniqueId = ByteString() ); + void PrintError( ByteString aMsg, ByteString aPrefix, ByteString aContext, ULONG nLine, ByteString aUniqueId = ByteString() ); + void InsertLine( GSILine* pLine, const ByteString aSourceLang); + void SetReferenceLine( GSILine* pLine ); + BOOL CheckSyntax( ULONG nLine, BOOL bRequireSourceLine, BOOL bFixTags ); + + void WriteError( LazySvFileStream &aErrOut, BOOL bRequireSourceLine ); + void WriteCorrect( LazySvFileStream &aOkOut, BOOL bRequireSourceLine ); + void WriteFixed( LazySvFileStream &aFixOut, BOOL bRequireSourceLine ); +}; + +#endif + diff --git a/l10ntools/inc/helpmerge.hxx b/l10ntools/inc/helpmerge.hxx new file mode 100644 index 000000000000..0ebfa7ed62a9 --- /dev/null +++ b/l10ntools/inc/helpmerge.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: helpmerge.hxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +// local includes +#include "export.hxx" +#include "xmlparse.hxx" +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/strbuf.hxx> +#include <memory> /* auto_ptr */ +#include "tools/isofallback.hxx" + +#define MOVEFILE_REPLACE_EXISTING 0x01 + +/// This Class is responsible for extracting/merging OpenOffice XML Helpfiles +class HelpParser +{ +private: + ByteString sHelpFile; + bool bUTF8; + bool bHasInputList; + +/// Copy fallback language String (ENUS,DE) into position of the numeric language iso code +/// @PRECOND 0 < langIdx_in < MAX_IDX + static void FillInFallbacks( LangHashMap& rElem_out, ByteString sLangIdx_in ); + +/// Debugmethod, prints the content of the map to stdout + static void Dump( LangHashMap* rElem_in , const ByteString sKey_in ); + +/// Debugmethod, prints the content of the map to stdout + static void Dump( XMLHashMap* rElem_in ) ; + + + +public: + HelpParser( const ByteString &rHelpFile, bool bUTF8 , bool bHasInputList ); + ~HelpParser(){}; + +/// Method creates/append a SDF file with the content of a parsed XML file +/// @PRECOND rHelpFile is valid + static bool CreateSDF( const ByteString &rSDFFile_in, const ByteString &rPrj_in, const ByteString &rRoot_in, + const ByteString &sHelpFile, XMLFile *pXmlFile, const ByteString &rGsi1 ); + + static void parse_languages( std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile ); + +/// Method merges the String from the SDFfile into XMLfile. Both Strings must +/// point to existing files. + bool Merge( const ByteString &rSDFFile_in, const ByteString &rDestinationFile_in , ByteString& sLanguage , MergeDataFile& aMergeDataFile ); + bool Merge( const ByteString &rSDFFile, const ByteString &rPathX , const ByteString &rPathY , bool bISO + , const std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir ); + +private: + static ByteString makeAbsolutePath( const ByteString& sHelpFile , const ByteString& rRoot_in ); + + ByteString GetOutpath( const ByteString& rPathX , const ByteString& sCur , const ByteString& rPathY ); + bool MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const ByteString& sLanguage , ByteString sPath ); + + void Process( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ); + void ProcessHelp( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ); + void MakeDir( const ByteString& sPath ); +}; diff --git a/l10ntools/inc/inireader.hxx b/l10ntools/inc/inireader.hxx new file mode 100644 index 000000000000..0861290adf9f --- /dev/null +++ b/l10ntools/inc/inireader.hxx @@ -0,0 +1,52 @@ +#include <string> +#include <hash_map> +#include <unicode/regex.h> + +using namespace std; + +namespace transex3 +{ + +struct eqstr +{ + bool operator()( const string s1 , const string s2) const + { + return s1.compare( s2 ) == 0; + } +}; + +typedef std::hash_map< string , string > stringmap; +typedef std::hash_map< string, stringmap* > INImap; + +class INIreader +{ + private: + UErrorCode section_status; + UErrorCode parameter_status; + RegexMatcher* section_match; + RegexMatcher* parameter_match; + + public: + INIreader(): section_status ( U_ZERO_ERROR ) , + parameter_status ( U_ZERO_ERROR ) + { + section_match = new RegexMatcher ( "^\\s*\\[([a-zA-Z0-9]*)\\].*" , 0 , section_status ); + parameter_match = new RegexMatcher ( "^\\s*([a-zA-Z0-9]*)\\s*=\\s*([a-zA-Z0-9 ]*).*" , 0 , parameter_status ) ; + } + ~INIreader() + { + delete section_match; + delete parameter_match; + } + // open "filename", fill hash_map with sections / paramaters + bool read( INImap& myMap , string& filename ); + + private: + bool is_section( string& line , string& section_str ); + bool is_parameter( string& line , string& parameter_key , string& parameter_value ); + inline void check_status( UErrorCode status ); + inline void toStlString ( const UnicodeString& str, string& stl_str ); + inline void trim( string& str ); +}; + +} diff --git a/l10ntools/inc/l10ntools/directory.hxx b/l10ntools/inc/l10ntools/directory.hxx new file mode 100644 index 000000000000..6b71f59435f7 --- /dev/null +++ b/l10ntools/inc/l10ntools/directory.hxx @@ -0,0 +1,54 @@ +#include <vector> +#include <algorithm> +#include <rtl/ustring.hxx> +#include <tools/string.hxx> + +#ifdef WNT +#else +#include <dirent.h> +#include <unistd.h> +#include <sys/stat.h> +#endif + +#include <stdio.h> + +#ifndef L10NTOOLS_FILE_HXX +#define L10NTOOLS_FILE_HXX +#include <l10ntools/file.hxx> +#endif + +namespace transex{ + +class Directory +{ + private: + rtl::OUString sDirectoryName; + rtl::OUString sFullName; + bool bSkipLinks; + + std::vector<Directory> aDirVec; + std::vector<File> aFileVec; + + public: + std::vector<Directory> getSubDirectories() { return aDirVec; } + std::vector<File> getFiles() { return aFileVec; } + + void readDirectory(); + void readDirectory( const rtl::OUString& sFullpath ); + void scanSubDir( int nLevels = 0 ); + + rtl::OUString getDirectoryName() { return sDirectoryName; } + rtl::OUString getFullName() { return sFullName ; } + void setSkipLinks( bool is_skipped ); + + void dump(); + Directory(){}; + + Directory( const rtl::OUString sFullPath ); + Directory( const rtl::OUString sFullPath , const rtl::OUString sEntry ) ; + Directory( const ByteString sFullPath ); + + static bool lessDir ( const Directory& rKey1, const Directory& rKey2 ) ; +}; + +} diff --git a/l10ntools/inc/l10ntools/file.hxx b/l10ntools/inc/l10ntools/file.hxx new file mode 100644 index 000000000000..e3a1a46b4ee8 --- /dev/null +++ b/l10ntools/inc/l10ntools/file.hxx @@ -0,0 +1,23 @@ +#include "rtl/ustring.hxx" + +namespace transex +{ + +class File +{ + private: + rtl::OUString sFileName; + rtl::OUString sFullName; + + public: + rtl::OUString getFileName(){ return sFileName; } + rtl::OUString getFullName(){ return sFullName; } + + File( const rtl::OUString sFile ); + File( const rtl::OUString sFullName , const rtl::OUString sFile ); + + static bool lessFile ( const File& rKey1, const File& rKey2 ); + +}; + +} diff --git a/l10ntools/inc/l10ntools/vosapp.hxx b/l10ntools/inc/l10ntools/vosapp.hxx new file mode 100644 index 000000000000..49e10e15e3d4 --- /dev/null +++ b/l10ntools/inc/l10ntools/vosapp.hxx @@ -0,0 +1,33 @@ +#ifndef VOSAPP_HXX +#define VOSAPP_HXX + +#include <sal/main.h> +#include <tools/solar.h> +#include <tools/string.hxx> +#include <vos/process.hxx> + +// Mininmal vcl/svapp compatibility without vcl dependence +class Application +{ +public: + USHORT GetCommandLineParamCount(); + XubString GetCommandLineParam( USHORT nParam ); + virtual void Main() = 0; +}; + +// Urg: Cut & Paste from svapp.cxx: we don't want to depend on vcl +USHORT Application::GetCommandLineParamCount() +{ + vos::OStartupInfo aStartInfo; + return (USHORT)aStartInfo.getCommandArgCount(); +} + +XubString Application::GetCommandLineParam( USHORT nParam ) +{ + vos::OStartupInfo aStartInfo; + rtl::OUString aParam; + aStartInfo.getCommandArg( nParam, aParam ); + return XubString( aParam ); +} + +#endif /* VOSAPP_HXX */ diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx new file mode 100644 index 000000000000..502889b27aa9 --- /dev/null +++ b/l10ntools/inc/lngmerge.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: lngmerge.hxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +// local includes +#include "export.hxx" + +DECLARE_LIST( LngLineList, ByteString * ) + +#define LNG_OK 0x0000 +#define LNG_FILE_NOTFOUND 0x0001 +#define LNG_COULD_NOT_OPEN 0x0002 +#define SDF_OK 0x0003 +#define SDF_FILE_NOTFOUND 0x0004 +#define SDF_COULD_NOT_OPEN 0x0005 + +// +// class LngParser +// + +class LngParser +{ +private: + USHORT nError; + LngLineList *pLines; + ByteString sSource; + BOOL bDBIsUTF8; + BOOL bULF; + bool bQuiet; + std::vector<ByteString> aLanguages; + + void FillInFallbacks( ByteStringHashMap Text ); + bool isNextGroup( ByteString &sGroup_out , ByteString &sLine_in); + void ReadLine( const ByteString &sLine_in , ByteStringHashMap &rText_inout ); + void WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout , + const ByteString &rPrj , + const ByteString &rRoot , const ByteString &sActFileName , const ByteString &sID ); +public: + LngParser( const ByteString &rLngFile, BOOL bUTF8, BOOL bULFFormat, bool bQuiet_in ); + ~LngParser(); + + BOOL CreateSDF( const ByteString &rSDFFile, const ByteString &rPrj, const ByteString &rRoot ); + BOOL Merge( const ByteString &rSDFFile, const ByteString &rDestinationFile , const ByteString &rPrj ); +}; diff --git a/l10ntools/inc/makefile.mk b/l10ntools/inc/makefile.mk new file mode 100644 index 000000000000..6a704d63e48f --- /dev/null +++ b/l10ntools/inc/makefile.mk @@ -0,0 +1,51 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.3 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=l10ntools +TARGET=inc + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + +.IF "$(ENABLE_PCH)"!="" +ALLTAR : \ + $(SLO)$/precompiled.pch \ + $(SLO)$/precompiled_ex.pch + +.ENDIF # "$(ENABLE_PCH)"!="" + diff --git a/l10ntools/inc/pch/precompiled_l10ntools.cxx b/l10ntools/inc/pch/precompiled_l10ntools.cxx new file mode 100644 index 000000000000..b6cac813375f --- /dev/null +++ b/l10ntools/inc/pch/precompiled_l10ntools.cxx @@ -0,0 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: precompiled_transex3.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_l10ntools.hxx" + diff --git a/l10ntools/inc/pch/precompiled_l10ntools.hxx b/l10ntools/inc/pch/precompiled_l10ntools.hxx new file mode 100644 index 000000000000..2ed3c72ad4ee --- /dev/null +++ b/l10ntools/inc/pch/precompiled_l10ntools.hxx @@ -0,0 +1,35 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: precompiled_transex3.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): Generated on 2006-09-01 17:50:15.326479 + +#ifdef PRECOMPILED_HEADERS +#endif + diff --git a/l10ntools/inc/srciter.hxx b/l10ntools/inc/srciter.hxx new file mode 100644 index 000000000000..7f80074cd651 --- /dev/null +++ b/l10ntools/inc/srciter.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: srciter.hxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef L10NTOOLS_DIRECTORY_HXX +#define L10NTOOLS_DIRECTORY_HXX +#include <l10ntools/directory.hxx> +#endif + +// class SourceTreeIterator +// + +class SourceTreeIterator +{ +private: + transex::Directory aRootDirectory; + bool bInExecute; + + void ExecuteDirectory( transex::Directory& pDirectory ); + +protected: + bool bLocal; + bool bSkipLinks; + +public: + SourceTreeIterator( const ByteString &rRootDirectory, const ByteString &rVersion , bool bLocal_in = false); + virtual ~SourceTreeIterator(); + + BOOL StartExecute(); + void EndExecute(); + + virtual void OnExecuteDirectory( const rtl::OUString &rDirectory ); +}; + + diff --git a/l10ntools/inc/tagtest.hxx b/l10ntools/inc/tagtest.hxx new file mode 100644 index 000000000000..811c4bf0e164 --- /dev/null +++ b/l10ntools/inc/tagtest.hxx @@ -0,0 +1,399 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tagtest.hxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TAGTEST_HXX_ +#define _TAGTEST_HXX_ + +#include <tools/string.hxx> +#include <tools/list.hxx> +#include <hash_map> /* std::hashmap*/ + +class GSILine; + +typedef USHORT TokenId; + +#define TOK_INVALIDPOS USHORT( 0xFFFF ) + +class ParserMessage; + +DECLARE_LIST( Impl_ParserMessageList, ParserMessage* ) +class ParserMessageList; + + +struct equalByteString{ + bool operator()( const ByteString& rKey1, const ByteString& rKey2 ) const { + return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL; + } +}; +struct lessByteString{ + bool operator()( const ByteString& rKey1, const ByteString& rKey2 ) const { + return rKey1.CompareTo( rKey2 )==COMPARE_LESS; + } +}; + +struct hashByteString{ + size_t operator()( const ByteString& rName ) const{ + std::hash< const char* > myHash; + return myHash( rName.GetBuffer() ); + } +}; + + + +typedef std::hash_map<ByteString , String , hashByteString,equalByteString> + StringHashMap; + +class TokenInfo +{ +private: + void SplitTag( ParserMessageList &rErrorList ); + + String aTagName; + StringHashMap aProperties; + BOOL bClosed; // tag is closed <sdnf/> + BOOL bCloseTag; // tag is close Tag </sdnf> + + + BOOL bIsBroken; + BOOL bHasBeenFixed; + BOOL bDone; + +public: + + String aTokenString; + TokenId nId; + USHORT nPos; // Position in String + + TokenInfo():bClosed(FALSE),bCloseTag(FALSE),bIsBroken(FALSE),bHasBeenFixed(FALSE),bDone(FALSE),nId( 0 ){;} +explicit TokenInfo( TokenId pnId, USHORT nP ):bClosed(FALSE),bCloseTag(FALSE),bIsBroken(FALSE),bHasBeenFixed(FALSE),bDone(FALSE),nId( pnId ),nPos(nP){;} +explicit TokenInfo( TokenId pnId, USHORT nP, String paStr ):bClosed(FALSE),bCloseTag(FALSE),bIsBroken(FALSE),bHasBeenFixed(FALSE),bDone(FALSE),aTokenString( paStr ),nId( pnId ),nPos(nP) {;} +explicit TokenInfo( TokenId pnId, USHORT nP, String paStr, ParserMessageList &rErrorList ); + + String GetTagName() const; + + String MakeTag() const; + + /** + Is the property to be ignored or does it have the default value anyways + **/ + BOOL IsPropertyRelevant( const ByteString &aName, const String &aValue ) const; + BOOL IsPropertyValueValid( const ByteString &aName, const String &aValue ) const; + /** + Does the property contain the same value for all languages + e.g.: the href in a link tag + **/ + BOOL IsPropertyInvariant( const ByteString &aName, const String &aValue ) const; + /** + a subset of IsPropertyInvariant but containing only those that are fixable + we dont wat to fix e.g.: ahelp :: visibility + **/ + BOOL IsPropertyFixable( const ByteString &aName ) const; + BOOL MatchesTranslation( TokenInfo& rInfo, BOOL bGenErrors, ParserMessageList &rErrorList, BOOL bFixTags = FALSE ) const; + + BOOL IsDone() const { return bDone; } + void SetDone( BOOL bNew = TRUE ) { bDone = bNew; } + + BOOL HasBeenFixed() const { return bHasBeenFixed; } + void SetHasBeenFixed( BOOL bNew = TRUE ) { bHasBeenFixed = bNew; } +}; + + +class ParserMessageList : public Impl_ParserMessageList +{ +public: + void AddError( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ); + void AddWarning( USHORT nErrorNr, ByteString aErrorText, const TokenInfo &rTag ); + + BOOL HasErrors(); +}; + + +#define TAG_GROUPMASK 0xF000 +#define TAG_GROUPSHIFT 12 + +#define TAG_GROUP( nTag ) (( nTag & TAG_GROUPMASK ) >> TAG_GROUPSHIFT ) +#define TAG_NOGROUP( nTag ) ( nTag & ~TAG_GROUPMASK ) // ~ = Bitweises NOT + +#define TAG_NOMORETAGS 0x0 + +#define TAG_GROUP_FORMAT 0x1 +#define TAG_ON 0x100 +#define TAG_BOLDON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x001 ) +#define TAG_BOLDOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x001 ) +#define TAG_ITALICON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x002 ) +#define TAG_ITALICOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x002 ) +#define TAG_UNDERLINEON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x004 ) +#define TAG_UNDERLINEOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x004 ) + +#define TAG_GROUP_NOTALLOWED 0x2 +#define TAG_HELPID ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x001 ) +#define TAG_MODIFY ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x002 ) +#define TAG_REFNR ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x004 ) + +#define TAG_GROUP_STRUCTURE 0x3 +#define TAG_NAME ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x001 ) +#define TAG_HREF ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x002 ) +#define TAG_AVIS ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x004 ) +#define TAG_AHID ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x008 ) + +#define TAG_TITEL ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x020 ) +#define TAG_KEY ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x040 ) +#define TAG_INDEX ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x080 ) + +#define TAG_REFSTART ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x100 ) + +#define TAG_GRAPHIC ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x200 ) +#define TAG_NEXTVERSION ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x400 ) + +#define TAG_GROUP_SYSSWITCH 0x4 +#define TAG_WIN ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x001 ) +#define TAG_UNIX ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x002 ) +#define TAG_MAC ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x004 ) +#define TAG_OS2 ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x008 ) + +#define TAG_GROUP_PROGSWITCH 0x5 +#define TAG_WRITER ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x001 ) +#define TAG_CALC ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x002 ) +#define TAG_DRAW ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x004 ) +#define TAG_IMPRESS ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x008 ) +#define TAG_SCHEDULE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x010 ) +#define TAG_IMAGE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x020 ) +#define TAG_MATH ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x040 ) +#define TAG_CHART ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x080 ) +#define TAG_OFFICE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x100 ) + + +#define TAG_GROUP_META 0x6 +#define TAG_OFFICEFULLNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x001 ) +#define TAG_OFFICENAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x002 ) +#define TAG_OFFICEPATH ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x004 ) +#define TAG_OFFICEVERSION ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x008 ) +#define TAG_PORTALNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x010 ) +#define TAG_PORTALFULLNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x020 ) +#define TAG_PORTALPATH ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x040 ) +#define TAG_PORTALVERSION ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x080 ) +#define TAG_PORTALSHORTNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x100 ) + + +#define TAG_GROUP_SINGLE 0x7 +#define TAG_REFINSERT ( TAG_GROUP_SINGLE << TAG_GROUPSHIFT | 0x001 ) + + +#define TAG_GROUP_MULTI 0x8 +#define TAG_END ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x010 ) +#define TAG_ELSE ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x020 ) +#define TAG_AEND ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x040 ) +#define TAG_VERSIONEND ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x080 ) +#define TAG_ENDGRAPHIC ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x100 ) + +#define TAG_GROUP_MISC 0x9 +#define TAG_COMMONSTART ( TAG_GROUP_MISC << TAG_GROUPSHIFT | 0x001 ) +#define TAG_COMMONEND ( TAG_GROUP_MISC << TAG_GROUPSHIFT | 0x002 ) + +#define TAG_UNKNOWN_TAG ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x800 ) + +DECLARE_LIST( TokenListImpl, TokenInfo* ) + +class TokenList : private TokenListImpl +{ +private: + + TokenList& operator =( const TokenList& rList ); +// { TokenListImpl::operator =( rList ); return *this; } + + +public: + using TokenListImpl::Count; + + + TokenList() : TokenListImpl(){}; + ~TokenList(){ Clear(); }; + + void Clear() + { + for ( ULONG i = 0 ; i < Count() ; i++ ) + delete TokenListImpl::GetObject( i ); + TokenListImpl::Clear(); + } + void Insert( TokenInfo p, ULONG nIndex = LIST_APPEND ) + { TokenListImpl::Insert( new TokenInfo(p), nIndex ); } +/* TokenInfo Remove( ULONG nIndex ) + { + TokenInfo aT = GetObject( nIndex ); + delete TokenListImpl::GetObject( nIndex ); + TokenListImpl::Remove( nIndex ); + return aT; + }*/ +// TokenInfo Remove( TokenInfo p ){ return Remove( GetPos( p ) ); } +// TokenInfo GetCurObject() const { return *TokenListImpl::GetCurObject(); } + TokenInfo& GetObject( ULONG nIndex ) const + { +// if ( TokenListImpl::GetObject(nIndex) ) + return *TokenListImpl::GetObject(nIndex); +// else +// return TokenInfo(); + } +/* ULONG GetPos( const TokenInfo p ) const + { + for ( ULONG i = 0 ; i < Count() ; i++ ) + if ( p == GetObject( i ) ) + return i; + return LIST_ENTRY_NOTFOUND; + }*/ + + TokenList( const TokenList& rList ); +/* { + for ( ULONG i = 0 ; i < rList.Count() ; i++ ) + { + Insert( rList.GetObject( i ), LIST_APPEND ); + } + }*/ +}; + +class ParserMessage +{ + USHORT nErrorNr; + ByteString aErrorText; + USHORT nTagBegin,nTagLength; + +protected: + ParserMessage( USHORT PnErrorNr, ByteString PaErrorText, const TokenInfo &rTag ); +public: + + USHORT GetErrorNr() { return nErrorNr; } + ByteString GetErrorText() { return aErrorText; } + + USHORT GetTagBegin() { return nTagBegin; } + USHORT GetTagLength() { return nTagLength; } + + virtual ~ParserMessage() {} + virtual BOOL IsError() =0; + virtual ByteString Prefix() =0; +}; + +class ParserError : public ParserMessage +{ +public: + ParserError( USHORT PnErrorNr, ByteString PaErrorText, const TokenInfo &rTag ); + + virtual BOOL IsError() {return TRUE;}; + virtual ByteString Prefix() {return "Error:"; }; +}; + +class ParserWarning : public ParserMessage +{ +public: + ParserWarning( USHORT PnErrorNr, ByteString PaErrorText, const TokenInfo &rTag ); + + virtual BOOL IsError() {return FALSE;}; + virtual ByteString Prefix() {return "Warning:"; }; +}; + +class SimpleParser +{ +private: + USHORT nPos; + String aSource; + String aLastToken; + TokenList aTokenList; + + TokenInfo aNextTag; // to store closetag in case of combined tags like <br/> + + String GetNextTokenString( ParserMessageList &rErrorList, USHORT &rTokeStartPos ); + +public: + SimpleParser(); + void Parse( String PaSource ); + TokenInfo GetNextToken( ParserMessageList &rErrorList ); + static String GetLexem( TokenInfo const &aToken ); + TokenList& GetTokenList(){ return aTokenList; } +}; + +class TokenParser +{ + BOOL match( const TokenInfo &aCurrentToken, const TokenId &aExpectedToken ); + BOOL match( const TokenInfo &aCurrentToken, const TokenInfo &aExpectedToken ); + void ParseError( USHORT nErrNr, ByteString aErrMsg, const TokenInfo &rTag ); + void Paragraph(); + void PfCase(); + void PfCaseBegin(); + void AppCase(); + void AppCaseBegin(); + void CaseEnd(); + void SimpleTag(); + void TagPair(); + void TagRef(); + + SimpleParser aParser; + TokenInfo aTag; + + TokenId nPfCaseOptions; + TokenId nAppCaseOptions; + BOOL bPfCaseActive ,bAppCaseActive; + + TokenId nActiveRefTypes; + + ParserMessageList *pErrorList; + +public: + TokenParser(); + void Parse( const String &aCode, ParserMessageList* pList ); +// ParserMessageList& GetErrors(){ return aErrorList; } +// BOOL HasErrors(){ return ( aErrorList.Count() > 0 ); } + TokenList& GetTokenList(){ return aParser.GetTokenList(); } +}; + +class LingTest +{ +private: + TokenParser aReferenceParser; + TokenParser aTesteeParser; + ParserMessageList aCompareWarningList; + void CheckTags( TokenList &aReference, TokenList &aTestee, BOOL bFixTags ); + BOOL IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens ); + String aFixedTestee; +public: + void CheckReference( GSILine *aReference ); + void CheckTestee( GSILine *aTestee, BOOL bHasSourceLine, BOOL bFixTags ); + +// ParserMessageList& GetReferenceErrors(){ return aReferenceParser.GetErrors(); } +// BOOL HasReferenceErrors(){ return aReferenceParser.HasErrors(); } + +// ParserMessageList& GetTesteeErrors(){ return aTesteeParser.GetErrors(); } +// BOOL HasTesteeErrors(){ return aTesteeParser.HasErrors(); } + + ParserMessageList& GetCompareWarnings(){ return aCompareWarningList; } + BOOL HasCompareWarnings(){ return ( aCompareWarningList.Count() > 0 ); } + + String GetFixedTestee(){ return aFixedTestee; } +}; + +#endif + diff --git a/l10ntools/inc/tokens.h b/l10ntools/inc/tokens.h new file mode 100644 index 000000000000..ef285f4c6361 --- /dev/null +++ b/l10ntools/inc/tokens.h @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tokens.h,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TOKENS_H +#define _TOKENS_H + +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +/* Tokens for parsing src files */ +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +#define IGNOREDTOKENS 400 /* #include | #pragma | //... | ... */ +#define COMMEND 401 /*... */ +#define DEFINEDRES 402 /* Text = { */ +#define ANYTOKEN 404 /* XYZ */ +#define UNKNOWNTOKEN 405 /* XYZ[ \t]$ */ +#define UNKNOWNCONSTRUCTION 406 /* XYZ ( xxx, yyy, zzz ) */ +#define UNKNOWNCHAR 407 /* . */ +/*------------------------------------------------------ */ +/* prev. tokens will not be executed */ +#define FILTER_LEVEL 500 +/* following tokens will be executed */ +/*------------------------------------------------------ */ +#define CONDITION 501 /* #if... | #endif ... | ... */ +#define EMPTYLINE 502 /* */ +#define RESSOURCE 503 /* Menu MID_TEST */ +#define RESSOURCEEXPR 504 /* Menu ( MID_TEST + .. ) */ +#define SMALRESSOURCE 505 /* PageItem { */ +#define TEXTLINE 506 /* TEXT = "hhh" */ +#define LONGTEXTLINE 507 /* TEXT = "hhh" TEST "HHH" ... */ +#define TEXT 508 /* "Something like this" */ +#define LEVELUP 509 /* { */ +#define LEVELDOWN 510 /* }; */ +#define APPFONTMAPPING 511 /* MAP_APPFONT(10,10) */ +#define ASSIGNMENT 512 /* Somathing = Anything */ +#define LISTASSIGNMENT 513 /* ...List [xyz]=... */ +#define LISTTEXT 514 /* < "Text" ... > */ +#define RSCDEFINE 515 /* #define MY_TEXT */ +#define RSCDEFINELEND 516 /* */ +#define NEWTEXTINRES 517 /* ### Achtung : Ne... */ +#define UIENTRIES 518 /* UIEntries = { */ +#define PRAGMA 519 /* #pragma ... */ +#define _LISTTEXT 521 /* { "Text" ... } */ +#define TEXTREFID 522 /* Text = 12345 */ +#define LISTRESID 523 /* < 12345; ... > */ +#define _LISTRESID 523 /* { 12345; ... } */ +#define NORMDEFINE 524 /* #define ... */ +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +/* Tokens for parsing cfg files */ +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +#define CFG_TAG 501 +#define CFG_TEXT_START 505 +#define CFG_TEXT_END 506 +#define CFG_TEXTCHAR 507 +#define CFG_CLOSETAG 508 +#define CFG_UNKNOWNTAG 509 +#define CFG_TOKEN_PACKAGE 600 +#define CFG_TOKEN_COMPONENT 601 +#define CFG_TOKEN_CONFIGNAME 602 +#define CFG_TOKEN_TEMPLATE 603 +#define CFG_TOKEN_OORNAME 604 +#define CFG_TOKEN_OORVALUE 605 +#define CFG_TOKEN_NO_TRANSLATE 606 + +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +/* Tokens for parsing xrm files */ +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +#define XRM_README_START 501 +#define XRM_README_END 502 +#define XRM_SECTION_START 503 +#define XRM_SECTION_END 504 +#define XRM_PARAGRAPH_START 505 +#define XRM_PARAGRAPH_END 506 +#define XRM_TEXT_START 507 +#define XRM_TEXT_END 508 +#define XRM_LIST_START 509 +#define XRM_LIST_END 510 +#define XML_TEXTCHAR 600 + + +#endif diff --git a/l10ntools/inc/treeconfig.hxx b/l10ntools/inc/treeconfig.hxx new file mode 100644 index 000000000000..96d693b0d376 --- /dev/null +++ b/l10ntools/inc/treeconfig.hxx @@ -0,0 +1,28 @@ +#include <vector> +#include <string> + +#include "inireader.hxx" + +namespace transex3{ + +class Treeconfig +{ + + private: + INIreader inireader; + INImap map; + bool has_config_file; + void getCurrentDir( string& dir ); + bool isConfigFilePresent(); + + public: + + Treeconfig() : has_config_file( false ) { parseConfig(); } + // read the config file, returns true in case a config file had been found + bool parseConfig(); + // returns a string vector containing all active repositories, returns true in case we are deep inside + // of a source tree. This could affect the behavour of the tool + bool getActiveRepositories( vector<string>& active_repos); +}; + +} diff --git a/l10ntools/inc/utf8conv.hxx b/l10ntools/inc/utf8conv.hxx new file mode 100644 index 000000000000..32e506edbda8 --- /dev/null +++ b/l10ntools/inc/utf8conv.hxx @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: utf8conv.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// global includes +#include <rtl/textcvt.h> +#include <tools/string.hxx> + +// +// class UTF8Converter +// + +class UTF8Converter +{ +private: + static void Convert( ByteString &rBuffer, rtl_TextEncoding nSourceENC, rtl_TextEncoding nDestENC ); + +public: + static ByteString ConvertToUTF8( const ByteString &rASCII, rtl_TextEncoding nEncoding ); + static ByteString ConvertFromUTF8( const ByteString &rUTF8, rtl_TextEncoding nEncoding ); +}; diff --git a/l10ntools/inc/wrdtrans.hxx b/l10ntools/inc/wrdtrans.hxx new file mode 100644 index 000000000000..efcb663204a6 --- /dev/null +++ b/l10ntools/inc/wrdtrans.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: wrdtrans.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +/* + +// OBSOLETE // + +#ifndef TX3_WRDTRANS_HXX +#define TX3_WRDTRANS_HXX + +// USED + // Base Classes + // Components +class WordTransTree; +class WordTrans_ErrorList; + // Parameters +#include <tools/string.hxx> + +class WordTransformer +{ + public: + enum E_Error + { + OK = 0, + ERROR_NO_WORDLIST, + ERROR_HOTKEY, + ERROR_OUTPUTSTRING_TOO_LONG, + OTHER_ERROR + }; + + // LIFECYCLE + WordTransformer(); + ~WordTransformer(); + BOOL LoadWordlist( /// @return False, if file could not be read, or there is already a wordlist loaded. + const ByteString & i_sWordlist_Filepath, + CharSet i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252, + CharSet i_nFileCharSet = RTL_TEXTENCODING_MS_1252 ); + + // OPERATIONS + USHORT Transform( /// @return The number of errors during transforming. + ByteString & io_sText); + + // INQUIRY + USHORT NrOfErrors() const; + E_Error GetError( + USHORT i_nNr, /// [0 .. NrOfErrors()-1], other values return an empty error. + ByteString * o_pErrorText = 0) const; /// If o_pErrorText != 0, the String is filled with the description of the error. + + private: + // SERVICE FUNCTION + void CreateError(); + + // DATA + WordTransTree * dpTransformer; + WordTrans_ErrorList * + dpErrors; +}; + + + +#endif + + +*/ diff --git a/l10ntools/inc/wtranode.hxx b/l10ntools/inc/wtranode.hxx new file mode 100644 index 000000000000..4d71fc160fff --- /dev/null +++ b/l10ntools/inc/wtranode.hxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: wtranode.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef TX3_WTRANODE_HXX +#define TX3_WTRANODE_HXX + +// USED + // Base Classes + // Components + // Parameters +#include <tools/string.hxx> + + +typedef UINT8 BRANCH_T; + + + +const BRANCH_T C_BR_ALPHABASE = 4; +const BRANCH_T C_NR_OF_BRANCHES = 34; + + + + +/** @task + This is a node of the parsing-tree which implements the fuctionality of + class WordTransTree. + WordTransTree is dependant of this class, but NOT the other way! +**/ +class WTT_Node // WordTransTree-Node +{ + public: + enum E_TokenType + { +// no_token = 0, + token_to_keep, + token_to_replace + }; + + // LIFECYCLE + WTT_Node( + UINT8 i_nValue, // Own branch-value. + WTT_Node * i_pDefaultBranch, + WTT_Node * i_pDefaultBranchForAlphas ); + void SetBranch( + UINT8 i_cBranch, + WTT_Node * i_pNode ); + void SetAsTokenToReplace( + const ByteString & i_sReplaceString ); + ~WTT_Node(); + + // OPERATIONS + WTT_Node * GetNextNode( + UINT8 i_cBranch ); /// [0 .. C_NR_OF_BRANCHES-1], sonst GPF !!! + + // INQUIRY + E_TokenType TokenType() const; + UINT8 Value() const; + BOOL IsOnDeleting() const; + const ByteString & ReplaceString() const; + + private: + // DATA + UINT8 nValue; + E_TokenType eType; + ByteString sReplaceString; + WTT_Node * aBranches[C_NR_OF_BRANCHES]; // Mostly DYN pointers. + char bIsOnDeleting; +}; + + +inline WTT_Node * +WTT_Node::GetNextNode(UINT8 i_cBranch) + { return aBranches[i_cBranch]; } +inline WTT_Node::E_TokenType +WTT_Node::TokenType() const + { return eType; } +inline UINT8 +WTT_Node::Value() const + { return nValue; } +inline BOOL +WTT_Node::IsOnDeleting() const + { return bIsOnDeleting; } +inline const ByteString & +WTT_Node::ReplaceString() const + { return sReplaceString; } + + + + +#endif + + + diff --git a/l10ntools/inc/wtratree.hxx b/l10ntools/inc/wtratree.hxx new file mode 100644 index 000000000000..67d63280449f --- /dev/null +++ b/l10ntools/inc/wtratree.hxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: wtratree.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#ifndef TX3_WTRATREE_HXX +#define TX3_WTRATREE_HXX + +// USED + // Base Classes + // Components + // Parameters +#include <tools/string.hxx> + +const INT16 C_NR_OF_WTT_RESULTS = 5; +const INT16 C_NR_OF_POSSIBLE_CHARS = 256; + + +typedef unsigned char u_char; +typedef const char * constr; + + +class WTT_Node; + + +/** @task + This class implements the functionality, that class WordTransformer + offers. + WordTransformer is dependant of this class, but NOT the other way! +**/ +class WordTransTree +{ + public: + enum E_Result + { + OK = 0, + HOTKEY_LOST, + OUTPUT_OVERFLOW + }; + + + // LIFECYCLE + WordTransTree( + CharSet i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252); + void SetCharSet( + CharSet i_nWorkingCharSet); + ~WordTransTree(); + + void AddWordPair( + const ByteString & i_sOldString, + const ByteString & i_sReplaceString ); + + // OPERATIONS + void InitTransformation( + const char * i_sInput, /// [!=0], a range of i_nInputLength must be valid memory for read. + UINT32 i_nInputLength, + UINT32 i_nOutputMaxLength = STRING_MAXLEN - 12 ); + E_Result TransformNextToken(); + + // INQUIRY + BOOL TextEndReached() const; + const char * Output() const; + + // These 3 functions are valid between two calls of + // TransformNextToken(): + E_Result CurResult() const; + ByteString CurReplacedString() const; + ByteString CurReplacingString() const; + char CurHotkey() const; + + private: + // SERVICE FUNCTONS + UINT8 CalculateBranch( + u_char i_cInputChar ) const; + + void Handle_Hotkey(); + void Handle_TokenToKeep(); + void Handle_TokenToTransform(); + + // DATA + // Fixed data + const u_char * sInput; + UINT32 nInputLength; + const u_char * pInputEnd; + + u_char * sOutput; // DYN + UINT32 nOutputMaxLength; + + WTT_Node * dpParsingTreeTop; // DYN + WTT_Node * pUnknownAlpha; + u_char cChar2Branch[C_NR_OF_POSSIBLE_CHARS]; + u_char c_AE, c_OE, c_UE, c_ae, c_oe, c_ue; + + // Working data + const u_char * pInputCurTokenStart; + const u_char * pInputPosition; + u_char * pOutputPosition; + WTT_Node * pCurParseNode; + + // Data which are valid only after a completed call to TransformNextToken() + E_Result eCurResult; + u_char cCurHotkey; // Letter wich is used as hotkey + u_char cCurHotkeySign; // Letter which is used to assign hotkey ('~'or '&') . +}; + + + + + + + +inline BOOL +WordTransTree::TextEndReached() const + { return pInputPosition == pInputEnd; } +inline const char * +WordTransTree::Output() const + { return TextEndReached() ? (constr) sOutput : ""; } +inline WordTransTree::E_Result +WordTransTree::CurResult() const + { return eCurResult; } +inline ByteString +WordTransTree::CurReplacedString() const + { return ByteString((constr) pInputCurTokenStart,pInputPosition-pInputCurTokenStart); } +inline char +WordTransTree::CurHotkey() const + { return cCurHotkey; } +inline UINT8 +WordTransTree::CalculateBranch(u_char i_cInputChar) const + { return cChar2Branch[i_cInputChar]; } + + + +#endif + + + diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx new file mode 100644 index 000000000000..18b047ef75c1 --- /dev/null +++ b/l10ntools/inc/xmlparse.hxx @@ -0,0 +1,553 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: xmlparse.hxx,v $ + * $Revision: 1.15 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef BOOTSTRP_XMLPARSE_HXX +#define BOOTSTRP_XMLPARSE_HXX + +#include <signal.h> +#include <expat.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include "tools/string.hxx" +#include "tools/list.hxx" +#define ENABLE_BYTESTRING_STREAM_OPERATORS +#include "tools/stream.hxx" +#include "tools/isofallback.hxx" +#include "export.hxx" +#include "xmlutil.hxx" + +#include <fstream> +#include <iostream> + +class XMLParentNode; +class XMLElement; + + +using namespace ::rtl; +using namespace std; + +#include <hash_map> /* std::hashmap*/ +#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 + + +//#define TESTDRIVER /* use xml2gsi testclass */ +//------------------------------------------------------------------------- + +/** Holds data of Attributes + */ +class XMLAttribute : public String +{ +private: + String sValue; + +public: + /// creates an attribute + 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 + ) + { + return (( rAttribute == *this ) && ( rAttribute.sValue == sValue )); + } +}; + +DECLARE_LIST( XMLAttributeList, XMLAttribute * ) + +//------------------------------------------------------------------------- + +/** Virtual base to handle different kinds of XML nodes + */ +class XMLNode +{ +protected: + XMLNode() {} + +public: + virtual USHORT GetNodeType() = 0; + virtual ~XMLNode() {} +}; + +//------------------------------------------------------------------------- + +/** Virtual base to handle different kinds of child nodes + */ +class XMLChildNode : public XMLNode +{ +private: + XMLParentNode *pParent; + +protected: + XMLChildNode( XMLParentNode *pPar ); + XMLChildNode():pParent( NULL ){}; + XMLChildNode( const XMLChildNode& obj); + XMLChildNode& operator=(const XMLChildNode& obj); +public: + virtual USHORT GetNodeType() = 0; + + /// returns the parent of this node + XMLParentNode *GetParent() { return pParent; } + virtual ~XMLChildNode(){}; +}; + +DECLARE_LIST( XMLChildNodeList, XMLChildNode * ) + +//------------------------------------------------------------------------- + +/** Virtual base to handle different kinds of parent nodes + */ +class XMLData; + +class XMLParentNode : public XMLChildNode +{ +private: + XMLChildNodeList *pChildList; + static int dbgcnt; + //int nParentPos; +protected: + 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; + + /// returns child list of this node + XMLChildNodeList *GetChildList() { return pChildList; } + + /// adds a new child + void AddChild( + XMLChildNode *pChild /// 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 + ); +}; + +//------------------------------------------------------------------------- + +DECLARE_LIST( XMLStringList, XMLElement* ) + +/// 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; + +/// Mapping iso alpha string code <-> iso numeric code +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; + +/** Holds information of a XML file, is root node of tree + */ + + +class XMLFile : public XMLParentNode +{ +public: + 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 ); + 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); + + XMLHashMap* GetStrings(){return XMLStrings;} + 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(); + + /// 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 InsertL10NElement( XMLElement* pElement); + + // DATA + String sFileName; + String sFullName; + + const ByteString ID,OLDREF,XML_LANG; + + TagMap nodes_localize; + XMLHashMap* XMLStrings; + + std::vector <ByteString> order; +}; + +/// An Utility class for XML +/// See RFC 3066 / #i8252# for ISO codes +class XMLUtil{ + +public: + /// Quot the XML characters and replace \n \t + 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 ); + + /// Return the alpha strings representation + ByteString GetIsoLangByIndex( USHORT nIndex ); + + static XMLUtil& Instance(); + ~XMLUtil(); + + void dump(); + +private: + /// Mapping iso alpha string code <-> iso numeric code + HashMap lMap; + + /// 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&); + +}; + + + +//------------------------------------------------------------------------- + +/** Hold information of an element node + */ +class XMLElement : public XMLParentNode +{ +private: + String sElementName; + XMLAttributeList *pAttributes; + 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 ), + pAttributes( NULL ), + 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(); + + /// returns element name + const String &GetName() { return sElementName; } + + /// returns list of attributes of this element + XMLAttributeList *GetAttributeList() { return pAttributes; } + + /// adds a new attribute to this element, typically used by parser + void AddAttribute( const String &rAttribute, const String &rValue ); + + 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); + + /// returns a attribute + XMLAttribute *GetAttribute( + const String &rName // the attribute name + ); + void SetProject ( ByteString prj ){ project = prj; } + void SetFileName ( ByteString fn ){ filename = fn; } + void SetId ( ByteString theId ){ id = theId; } + 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; } + + virtual int GetPos() { return nPos; } + ByteString GetProject() { return project; } + ByteString GetFileName() { return filename; } + ByteString GetId() { return id; } + ByteString GetOldref() { return sOldRef; } + ByteString GetResourceType(){ return resourceType; } + ByteString GetLanguageId() { return languageId; } + + +}; +//------------------------------------------------------------------------- + + +/** Holds character data + */ +class XMLData : public XMLChildNode +{ +private: + String sData; + bool isNewCreated; + +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 + bool newCreated + ) + : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( newCreated ){} + + XMLData(const XMLData& obj); + + XMLData& operator=(const XMLData& obj); + virtual USHORT GetNodeType(); + + /// returns the data + const String &GetData() { return sData; } + + bool isNew() { return isNewCreated; } + /// adds new character data to the existing one + void AddData( + const String &rData // the new data + ); + + + +}; + +//------------------------------------------------------------------------- + +/** Holds comments + */ +class XMLComment : public XMLChildNode +{ +private: + String sComment; + +public: + /// create a comment node + XMLComment( + 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; } +}; + +//------------------------------------------------------------------------- + +/** Holds additional file content like those for which no handler exists + */ +class XMLDefault : public XMLChildNode +{ +private: + String sDefault; + +public: + /// create a comment node + XMLDefault( + 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(); + + /// returns the comment + const String &GetDefault() { return sDefault; } +}; + +//------------------------------------------------------------------------- + +/** 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 +}; + +//------------------------------------------------------------------------- + +/** validating xml parser, creates a document tree with xml nodes + */ + + +class SimpleXMLParser +{ +private: + XML_Parser aParser; + XMLError aErrorInformation; + + 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 + SimpleXMLParser(); + ~SimpleXMLParser(); + + /// parse a file, returns NULL on criticall errors + XMLFile *Execute( + const String &rFullFileName, + 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 + ); + + /// returns an error struct + const XMLError &GetError() { return aErrorInformation; } +}; + +#endif diff --git a/l10ntools/inc/xmlutil.hxx b/l10ntools/inc/xmlutil.hxx new file mode 100644 index 000000000000..812f50b85c45 --- /dev/null +++ b/l10ntools/inc/xmlutil.hxx @@ -0,0 +1,9 @@ +#define ENGLISH_US 1 +#define ENGLISH_US_ISO "en-US" +#define ENGLISH_US_PROPERTY "en_US" +#define ENGLISH_US_INDEX 1 +#define GERMAN_DE 4 +#define GERMAN_DE_ISO "x-german" +#define GERMAN_DE_INDEX 3 +#define GERMAN_ISO2 "de-DE" + diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx new file mode 100644 index 000000000000..47be1ea7a038 --- /dev/null +++ b/l10ntools/inc/xrmmerge.hxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: xrmmerge.hxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// global includes +#include <tools/string.hxx> + +// +// XRMResParser +// + +class XRMResParser +{ +private: + ByteString sGID; + ByteString sLID; + + BOOL bError; + BOOL bText; + + bool sLocalized; + + ByteString sCurrentOpenTag; + ByteString sCurrentCloseTag; + ByteString sCurrentText; + std::vector<ByteString> aLanguages; + +protected: + ByteString GetAttribute( const ByteString &rToken, const ByteString &rAttribute ); + void Error( const ByteString &rError ); + + virtual void Output( const ByteString& rOutput )=0; + virtual void WorkOnText( + const ByteString &rOpenTag, + ByteString &rText + )=0; + virtual void EndOfText( + const ByteString &rOpenTag, + const ByteString &rCloseTag + )=0; + + ByteString GetGID() { return sGID; } + ByteString GetLID() { return sLID; } + + void ConvertStringToDBFormat( ByteString &rString ); + void ConvertStringToXMLFormat( ByteString &rString ); + +public: + XRMResParser(); + virtual ~XRMResParser(); + + int Execute( int nToken, char * pToken ); + + void SetError( BOOL bErr = TRUE ) { bError = bErr; } + BOOL GetError() { return bError; } +}; + +// +// class XRMResOutputParser +// + +class XRMResOutputParser : public XRMResParser +{ +private: + std::vector<ByteString> aLanguages; +protected: + SvFileStream *pOutputStream; +public: + XRMResOutputParser ( const ByteString &rOutputFile ); + virtual ~XRMResOutputParser(); +}; + +// +// XRMResExport +// + +class XRMResExport : public XRMResOutputParser +{ +private: + ResData *pResData; + ByteString sPrj; + ByteString sPath; + std::vector<ByteString> aLanguages; + +protected: + void WorkOnText( + const ByteString &rOpenTag, + ByteString &rText + ); + void EndOfText( + const ByteString &rOpenTag, + const ByteString &rCloseTag + ); + void Output( const ByteString& rOutput ); + +public: + XRMResExport( + const ByteString &rOutputFile, + const ByteString &rProject, + const ByteString &rFilePath + ); + virtual ~XRMResExport(); +}; + +// +// class XRMResMerge +// + +class XRMResMerge : public XRMResOutputParser +{ +private: + MergeDataFile *pMergeDataFile; + ByteString sFilename; + ResData *pResData; + std::vector<ByteString> aLanguages; + +protected: + void WorkOnText( + const ByteString &rOpenTag, + ByteString &rText + ); + void EndOfText( + const ByteString &rOpenTag, + const ByteString &rCloseTag + ); + void Output( const ByteString& rOutput ); +public: + XRMResMerge( + const ByteString &rMergeSource, + const ByteString &rOutputFile, + ByteString &rFilename + ); + virtual ~XRMResMerge(); +}; + |