xref: /trunk/main/tools/inc/tools/iparser.hxx (revision 8b851043)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef IPARSER_HXX
24 #define IPARSER_HXX
25 
26 #include <tools/string.hxx>
27 #include <tools/link.hxx>
28 #include <tools/stream.hxx>
29 #include "tools/toolsdllapi.h"
30 
31 // forwards
32 class Dir;
33 class GenericInformation;
34 class GenericInformationList;
35 
36 //
37 // class InformationParser
38 //
39 
40 /******************************************************************************
41 Purpose: reads generic information files into a simple structure in memory
42 ******************************************************************************/
43 
44 // information files used by this parser have following format:
45 
46 /*
47 
48 key [value]
49 {
50 	key [value]
51 	key [value]
52 	{
53 		key [value]
54 		...
55 		...
56 	}
57 }
58 key [value]
59 ...
60 ...
61 
62 */
63 
64 #define DEF_STAND_LST  "\\\\dev4\\data1\\b_server\\config\\stand.lst"
65 
66 // error codes:
67 
68 #define IP_NO_ERROR			0x0000
69 #define IP_UNEXPECTED_EOF	0x0001
70 
71 #define REPLACE_VARIABLES	sal_True
72 
73 class TOOLS_DLLPUBLIC InformationParser
74 {
75 private:
76 	sal_Bool bRecover;
77 	ByteString sOldLine;
78 
79 	ByteString sCurrentComment;
80 
81 	sal_Bool bReplaceVariables; // meaning %UPD and %VERSION
82 	sal_uInt16 nLevel;
83 	ByteString sUPD;
84 	ByteString sVersion;
85 
86 	Link aStatusLink;
87 	SvStream *pActStream;
88     UniString sStreamName;
89 
90 	sal_uInt16 nErrorCode;
91 	sal_uIntPtr nErrorLine;
92 	ByteString sErrorText;
93 	sal_uIntPtr nActLine;
94 
95 	// methods
96 	TOOLS_DLLPRIVATE ByteString &ReadLine();
97 	TOOLS_DLLPRIVATE GenericInformation *ReadKey( GenericInformationList *pExistingList );
98 	inline void Recover();
99 
100 protected:
101   sal_Bool Save( SvStream &rOutStream,
102 	     const GenericInformationList *pSaveList, sal_uInt16 nLevel, sal_Bool bStripped );
103 	GenericInformationList *Execute( SvStream &rSourceStream,
104 								GenericInformationList *pExistingList );
PrintStatus(ByteString & rStatus)105 	virtual void PrintStatus( ByteString &rStatus )
106 		{ if ( aStatusLink.IsSet()) aStatusLink.Call( &rStatus ); }
107 
108 public:
109 	InformationParser( sal_Bool bReplace = sal_False );
110 	virtual ~InformationParser();
111 
112 	// the following methods return NULL if any errors are detected
113 
114 	// reads a information file and stores the data in a
115 	// GenericInformationList
116 	GenericInformationList *Execute( SvMemoryStream &rSourceStream,
117 								GenericInformationList *pExistingList = NULL );
118 	GenericInformationList *Execute( SvFileStream &rSourceStream,
119 								GenericInformationList *pExistingList = NULL );
120 	GenericInformationList *Execute( UniString &rSourceFile,
121 								GenericInformationList *pExistingList = NULL );
122 	// reads all information files in the dir and stores the data in a
123 	// GenericInformationList => first key is the filename
124 	GenericInformationList *Execute( Dir &rDir,
125 								GenericInformationList *pExistingList = NULL );
126 
127   // save the InfrormationList to rSourceFile
128   // returns sal_False on error
129   sal_Bool Save( SvFileStream &rSourceStream,
130 	     const GenericInformationList *pSaveList );
131   sal_Bool Save( SvMemoryStream &rSourceStream,
132 	     const GenericInformationList *pSaveList );
133   sal_Bool Save( const UniString &rSourceFile,
134 	     const GenericInformationList *pSaveList );
135 
136 	sal_uInt16 GetErrorCode();
137 	ByteString &GetErrorText();
138 
SetStatusHdl(const Link & rHdl)139 	void SetStatusHdl( const Link &rHdl ) { aStatusLink = rHdl; }
140 };
141 
142 #endif
143 
144