xref: /aoo42x/main/tools/inc/tools/iparser.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef IPARSER_HXX
28 #define IPARSER_HXX
29 
30 #include <tools/string.hxx>
31 #include <tools/link.hxx>
32 #include <tools/stream.hxx>
33 #include "tools/toolsdllapi.h"
34 
35 // forwards
36 class Dir;
37 class GenericInformation;
38 class GenericInformationList;
39 
40 //
41 // class InformationParser
42 //
43 
44 /******************************************************************************
45 Purpose: reads generic information files into a simple structure in memory
46 ******************************************************************************/
47 
48 // information files used by this parser have following format:
49 
50 /*
51 
52 key [value]
53 {
54 	key [value]
55 	key [value]
56 	{
57 		key [value]
58 		...
59 		...
60 	}
61 }
62 key [value]
63 ...
64 ...
65 
66 */
67 
68 #define DEF_STAND_LST  "\\\\dev4\\data1\\b_server\\config\\stand.lst"
69 
70 // error codes:
71 
72 #define IP_NO_ERROR			0x0000
73 #define IP_UNEXPECTED_EOF	0x0001
74 
75 #define REPLACE_VARIABLES	sal_True
76 
77 class TOOLS_DLLPUBLIC InformationParser
78 {
79 private:
80 	sal_Bool bRecover;
81 	ByteString sOldLine;
82 
83 	ByteString sCurrentComment;
84 
85 	sal_Bool bReplaceVariables; // meaning %UPD and %VERSION
86 	sal_uInt16 nLevel;
87 	ByteString sUPD;
88 	ByteString sVersion;
89 
90 	Link aStatusLink;
91 	SvStream *pActStream;
92     UniString sStreamName;
93 
94 	sal_uInt16 nErrorCode;
95 	sal_uIntPtr nErrorLine;
96 	ByteString sErrorText;
97 	sal_uIntPtr nActLine;
98 
99 	// methods
100 	TOOLS_DLLPRIVATE ByteString &ReadLine();
101 	TOOLS_DLLPRIVATE GenericInformation *ReadKey( GenericInformationList *pExistingList );
102 	inline void Recover();
103 
104 protected:
105   sal_Bool Save( SvStream &rOutStream,
106 	     const GenericInformationList *pSaveList, sal_uInt16 nLevel, sal_Bool bStripped );
107 	GenericInformationList *Execute( SvStream &rSourceStream,
108 								GenericInformationList *pExistingList );
109 	virtual void PrintStatus( ByteString &rStatus )
110 		{ if ( aStatusLink.IsSet()) aStatusLink.Call( &rStatus ); }
111 
112 public:
113 	InformationParser( sal_Bool bReplace = sal_False );
114 	virtual ~InformationParser();
115 
116 	// the following methods return NULL if any errors are detected
117 
118 	// reads a information file and stores the data in a
119 	// GenericInformationList
120 	GenericInformationList *Execute( SvMemoryStream &rSourceStream,
121 								GenericInformationList *pExistingList = NULL );
122 	GenericInformationList *Execute( SvFileStream &rSourceStream,
123 								GenericInformationList *pExistingList = NULL );
124 	GenericInformationList *Execute( UniString &rSourceFile,
125 								GenericInformationList *pExistingList = NULL );
126 	// reads all information files in the dir and stores the data in a
127 	// GenericInformationList => first key is the filename
128 	GenericInformationList *Execute( Dir &rDir,
129 								GenericInformationList *pExistingList = NULL );
130 
131   // save the InfrormationList to rSourceFile
132   // returns sal_False on error
133   sal_Bool Save( SvFileStream &rSourceStream,
134 	     const GenericInformationList *pSaveList );
135   sal_Bool Save( SvMemoryStream &rSourceStream,
136 	     const GenericInformationList *pSaveList );
137   sal_Bool Save( const UniString &rSourceFile,
138 	     const GenericInformationList *pSaveList );
139 
140 	sal_uInt16 GetErrorCode();
141 	ByteString &GetErrorText();
142 
143 	void SetStatusHdl( const Link &rHdl ) { aStatusLink = rHdl; }
144 };
145 
146 #endif
147 
148