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 
24 #ifndef _URLPARAMETER_HXX_
25 #define _URLPARAMETER_HXX_
26 
27 #include <rtl/ustring.hxx>
28 #include <rtl/string.hxx>
29 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
32 #include <com/sun/star/io/XActiveDataSink.hpp>
33 #include <com/sun/star/io/XOutputStream.hpp>
34 #include <com/sun/star/ucb/Command.hpp>
35 
36 namespace chelp {
37 
38 
39 	class Databases;
40 
41 
42 	class DbtToStringConverter
43 	{
44 	public:
45 
DbtToStringConverter(const sal_Char * ptr,sal_Int32 len)46 		DbtToStringConverter( const sal_Char* ptr,sal_Int32 len )
47 			: m_len( len ),
48               m_ptr( ptr )
49 		{
50 		}
51 
52 
getHash()53 		rtl::OUString getHash()
54 		{
55 			if( m_ptr )
56 			{
57 				sal_Int32 sizeOfFile = ( sal_Int32 ) m_ptr[0];
58 				rtl::OUString Hash( m_ptr+1,sizeOfFile,RTL_TEXTENCODING_UTF8 );
59 				sal_Int32 idx;
60 				if( ( idx = Hash.indexOf( sal_Unicode( '#' ) ) ) != -1 )
61 					return Hash.copy( 1+idx );
62 			}
63 			return rtl::OUString();
64 		}
65 
66 
getFile()67 		rtl::OUString getFile()
68 		{
69 			if( ! m_ptr )
70 				return rtl::OUString();
71 
72 			sal_Int32 sizeOfFile = ( sal_Int32 ) m_ptr[0];
73 			rtl::OUString File( m_ptr+1,sizeOfFile,RTL_TEXTENCODING_UTF8 );
74 			sal_Int32 idx;
75 			if( ( idx = File.indexOf( sal_Unicode( '#' ) ) ) != -1 )
76 				return File.copy( 0,idx );
77 			else
78 				return File;
79 		}
80 
81 
getDatabase()82 		rtl::OUString getDatabase()
83 		{
84 			if( ! m_ptr )
85 				return rtl::OUString();
86 
87 			sal_Int32 sizeOfDatabase = ( int ) m_ptr[ 1+ ( sal_Int32 ) m_ptr[0] ];
88 			return rtl::OUString( m_ptr + 2 + ( sal_Int32 ) m_ptr[0],sizeOfDatabase,RTL_TEXTENCODING_UTF8 );
89 		}
90 
91 
getTitle()92 		rtl::OUString getTitle()
93 		{
94 			if( ! m_ptr ) // || getHash().getLength() )
95 				return rtl::OUString();
96 
97 			sal_Int32 sizeOfTitle =
98 				( sal_Int32 ) m_ptr[  2 + m_ptr[0] +  ( sal_Int32 ) m_ptr[ 1+ ( sal_Int32 ) m_ptr[0] ] ];
99 			return rtl::OUString( m_ptr + 3 + m_ptr[0] +  ( sal_Int32 ) m_ptr[ 1+ ( sal_Int32 ) m_ptr[0] ],
100 								  sizeOfTitle,
101 								  RTL_TEXTENCODING_UTF8 );
102 		}
103 
104 
105 	private:
106 
107 		sal_Int32 m_len;
108 
109 		const sal_Char* m_ptr;
110 
111 	};
112 
113 
114 
115 
116 	class URLParameter
117 	{
118 	public:
119 
120 		URLParameter( const rtl::OUString& aURL,
121 					  Databases* pDatabases )
122 			throw( com::sun::star::ucb::IllegalIdentifierException );
123 
isPicture()124 		bool isPicture() 		{ return m_aModule.compareToAscii("picture") == 0; }
isActive()125 		bool isActive()         { return m_aActive.getLength() > 0 && m_aActive.compareToAscii( "true" ) == 0; }
isQuery()126 		bool isQuery()          { return m_aId.compareToAscii("") == 0 && m_aQuery.compareToAscii("") != 0; }
isEntryForModule()127 		bool isEntryForModule() { return m_aId.compareToAscii("start") == 0 || m_bStart; }
isFile()128 		bool isFile()           { return m_aId.compareToAscii( "" ) != 0; }
isModule()129 		bool isModule()         { return m_aId.compareToAscii("") == 0 && m_aModule.compareToAscii("") != 0; }
isRoot()130 		bool isRoot()           { return m_aModule.compareToAscii("") == 0; }
131 		bool isErrorDocument();
132 
get_url()133 		rtl::OUString get_url() { return m_aURL; }
134 
135 		rtl::OUString get_id();
136 
137 		rtl::OUString get_tag();
138 
139 		//  Not called for an directory
140 
get_path()141 		rtl::OUString get_path()   { return get_the_path(); }
142 
get_eid()143 		rtl::OUString get_eid()    { return m_aEid; }
144 
145 		rtl::OUString get_title();
146 
get_jar()147 		rtl::OUString get_jar()      { return get_the_jar(); }
148 
get_ExtensionRegistryPath()149 		rtl::OUString get_ExtensionRegistryPath()    { return m_aExtensionRegistryPath; }
150 
get_module()151 		rtl::OUString get_module()   { return m_aModule; }
152 
get_dbpar()153         rtl::OUString get_dbpar()    {
154             if( m_aDbPar.getLength() ) return m_aDbPar;
155             else return m_aModule;
156         }
157 
get_prefix()158 		rtl::OUString get_prefix()   { return m_aPrefix; }
159 
160 		rtl::OUString get_language();
161 
get_device()162 		rtl::OUString get_device()   { return m_aDevice; }
163 
164 		rtl::OUString get_program();
165 
get_query()166 		rtl::OUString get_query()    { return m_aQuery; }
167 
get_scope()168 		rtl::OUString get_scope()    { return m_aScope; }
169 
get_system()170 		rtl::OUString get_system()   { return m_aSystem; }
171 
get_hitCount()172 		sal_Int32     get_hitCount() { return m_nHitCount; }
173 
174 		rtl::OString getByName( const char* par );
175 
176 		void open( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
177 				   const com::sun::star::ucb::Command& aCommand,
178 				   sal_Int32 CommandId,
179 				   const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& Environment,
180 				   const com::sun::star::uno::Reference< com::sun::star::io::XActiveDataSink >& xDataSink );
181 
182 		void open( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
183 				   const com::sun::star::ucb::Command& aCommand,
184 				   sal_Int32 CommandId,
185 				   const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& Environment,
186 				   const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xDataSink );
187 
188 	private:
189 
190 		Databases* m_pDatabases;
191 
192 		bool m_bHelpDataFileRead;
193 		bool m_bStart;
194 		bool m_bUseDB;
195 
196 		rtl::OUString  m_aURL;
197 
198 		rtl::OUString  m_aTag;
199 		rtl::OUString  m_aId;
200 		rtl::OUString  m_aPath;
201 		rtl::OUString  m_aModule;
202 		rtl::OUString  m_aTitle;
203 		rtl::OUString  m_aJar;
204 		rtl::OUString  m_aExtensionRegistryPath;
205 		rtl::OUString  m_aEid;
206 		rtl::OUString  m_aDbPar;
207 
208 		rtl::OUString  m_aDefaultLanguage;
209 		rtl::OUString  m_aLanguage;
210 
211 		rtl::OUString  m_aPrefix;
212 		rtl::OUString  m_aDevice;
213 		rtl::OUString  m_aProgram;
214 		rtl::OUString  m_aSystem;
215 		rtl::OUString  m_aActive;
216 
217 		rtl::OUString  m_aQuery;
218 		rtl::OUString  m_aScope;
219 
220 		rtl::OUString m_aExpr;
221 
222 		sal_Int32      m_nHitCount;                // The default maximum hitcount
223 
224 
225 		// private methods
226 
227 		void init( bool bDefaultLanguageIsInitialized );
228 
229 		rtl::OUString get_the_tag();
230 
231 		rtl::OUString get_the_path();
232 
233 		rtl::OUString get_the_title();
234 
235 		rtl::OUString get_the_jar();
236 
237 		void readHelpDataFile();
238 
239 		void parse() throw( com::sun::star::ucb::IllegalIdentifierException );
240 
241 		bool scheme();
242 
243 		bool module();
244 
245 		bool name( bool modulePresent );
246 
247 		bool query();
248 
249 	};   // end class URLParameter
250 
251 
252 }  // end namespace chelp
253 
254 #endif
255