xref: /aoo42x/main/sd/source/ui/inc/TemplateScanner.hxx (revision c45d927a)
1*c45d927aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c45d927aSAndrew Rist  * distributed with this work for additional information
6*c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9*c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c45d927aSAndrew Rist  *
11*c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c45d927aSAndrew Rist  *
13*c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15*c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c45d927aSAndrew Rist  * specific language governing permissions and limitations
18*c45d927aSAndrew Rist  * under the License.
19*c45d927aSAndrew Rist  *
20*c45d927aSAndrew Rist  *************************************************************/
21*c45d927aSAndrew Rist 
22*c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _TEMPLATE_SCANNER_HXX
25cdf0e10cSrcweir #define _TEMPLATE_SCANNER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "tools/AsynchronousTask.hxx"
28cdf0e10cSrcweir #include "sddllapi.h"
29cdf0e10cSrcweir #include <ucbhelper/content.hxx>
30cdf0e10cSrcweir #include <tools/string.hxx>
31cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vector>
34cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace ucb {
37cdf0e10cSrcweir class XContent;
38cdf0e10cSrcweir class XCommandEnvironment;
39cdf0e10cSrcweir } } } }
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sdbc {
42cdf0e10cSrcweir class XResultSet;
43cdf0e10cSrcweir } } } }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace sd {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /** Representation of a template or layout file.
48cdf0e10cSrcweir */
49cdf0e10cSrcweir class TemplateEntry
50cdf0e10cSrcweir {
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir     TemplateEntry   (const String& rsTitle, const String& rsPath)
53cdf0e10cSrcweir         :   msTitle(rsTitle), msPath(rsPath) {}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     String msTitle;
56cdf0e10cSrcweir     String msPath;
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir /** Representation of a template or layout folder.
63cdf0e10cSrcweir */
64cdf0e10cSrcweir class TemplateDir
65cdf0e10cSrcweir {
66cdf0e10cSrcweir public:
67cdf0e10cSrcweir     TemplateDir (const String& rsRegion, const String& rsUrl )
68cdf0e10cSrcweir         :   msRegion(rsRegion), msUrl(rsUrl), maEntries() {}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     String msRegion;
71cdf0e10cSrcweir     String msUrl;
72cdf0e10cSrcweir     ::std::vector<TemplateEntry*> maEntries;
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /** This class scans the template folders for impress templates.  There are
79cdf0e10cSrcweir     two ways to use this class.
80cdf0e10cSrcweir     1. The old and deprecated way is to call Scan() to scan all templates
81cdf0e10cSrcweir     and collect the supported ones in a tree structure.  This structure is
82cdf0e10cSrcweir     returned by GetFolderList().
83cdf0e10cSrcweir     2. The new way implements the AsynchronousTask interface.  Call
84cdf0e10cSrcweir     RunNextStep() as long HasNextStep() returns <TRUE/>.  After every step
85cdf0e10cSrcweir     GetLastAddedEntry() returns the template that was scanned (and has a
86cdf0e10cSrcweir     supported format) last.  When a step does not add a new template then
87cdf0e10cSrcweir     the value of the previous step is returned.
88cdf0e10cSrcweir */
89cdf0e10cSrcweir class SD_DLLPUBLIC TemplateScanner
90cdf0e10cSrcweir     : public ::sd::tools::AsynchronousTask
91cdf0e10cSrcweir {
92cdf0e10cSrcweir public:
93cdf0e10cSrcweir     /** Create a new template scanner and prepare but do not execute the scanning.
94cdf0e10cSrcweir     */
95cdf0e10cSrcweir     TemplateScanner (void);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /** The destructor deletes any remaining entries of the local list of
98cdf0e10cSrcweir         templates.
99cdf0e10cSrcweir     */
100cdf0e10cSrcweir     virtual ~TemplateScanner (void);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /** Execute the actual scanning of templates.  When this method
103cdf0e10cSrcweir         terminates the result can be obtained by calling the
104cdf0e10cSrcweir         <member>GetTemplateList</member> method.
105cdf0e10cSrcweir     */
106cdf0e10cSrcweir     void Scan (void);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /** Return the list of template folders.  It lies in the responsibility
109cdf0e10cSrcweir         of the caller to take ownership of some or all entries and remove
110cdf0e10cSrcweir         them from the returned list.  All entries that remain until the
111cdf0e10cSrcweir         destructor is called will be destroyed.
112cdf0e10cSrcweir     */
113cdf0e10cSrcweir     std::vector<TemplateDir*>& GetFolderList (void);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     /** Implementation of the AsynchronousTask interface method.
116cdf0e10cSrcweir     */
117cdf0e10cSrcweir     virtual void RunNextStep (void);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     /** Implementation of the AsynchronousTask interface method.
120cdf0e10cSrcweir     */
121cdf0e10cSrcweir     virtual bool HasNextStep (void);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     /** Return the TemplateDir object that was last added to
124cdf0e10cSrcweir         mpTemplateDirectory.
125cdf0e10cSrcweir         @return
126cdf0e10cSrcweir             <NULL/> is returned either before the template scanning is
127cdf0e10cSrcweir             started or after it has ended.
128cdf0e10cSrcweir     */
129cdf0e10cSrcweir     const TemplateEntry* GetLastAddedEntry (void) const;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir private:
132cdf0e10cSrcweir     /** The current state determines which step will be executed next by
133cdf0e10cSrcweir         RunNextStep().
134cdf0e10cSrcweir     */
135cdf0e10cSrcweir     enum State {
136cdf0e10cSrcweir         INITIALIZE_SCANNING,
137cdf0e10cSrcweir         INITIALIZE_FOLDER_SCANNING,
138cdf0e10cSrcweir         GATHER_FOLDER_LIST,
139cdf0e10cSrcweir         SCAN_FOLDER,
140cdf0e10cSrcweir         INITIALIZE_ENTRY_SCAN,
141cdf0e10cSrcweir         SCAN_ENTRY,
142cdf0e10cSrcweir         DONE,
143cdf0e10cSrcweir         ERROR
144cdf0e10cSrcweir     };
145cdf0e10cSrcweir     State meState;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     ::ucbhelper::Content maFolderContent;
148cdf0e10cSrcweir     TemplateDir* mpTemplateDirectory;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /** The data structure that is to be filled with information about the
151cdf0e10cSrcweir         template files.
152cdf0e10cSrcweir     */
153cdf0e10cSrcweir      std::vector<TemplateDir*> maFolderList;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** This member points into the maFolderList to the member that was most
156cdf0e10cSrcweir         recently added.
157cdf0e10cSrcweir     */
158cdf0e10cSrcweir     TemplateEntry* mpLastAddedEntry;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     /** The folders that are collected by GatherFolderList().
161cdf0e10cSrcweir     */
162cdf0e10cSrcweir     class FolderDescriptorList;
163cdf0e10cSrcweir     ::boost::scoped_ptr<FolderDescriptorList> mpFolderDescriptors;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     /** Set of state variables used by the methods
166cdf0e10cSrcweir         InitializeFolderScanning(), GatherFolderList(), ScanFolder(),
167cdf0e10cSrcweir         InitializeEntryScanning(), and ScanEntry().
168cdf0e10cSrcweir     */
169cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::ucb::XContent> mxTemplateRoot;
170cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxFolderEnvironment;
171cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> mxEntryEnvironment;
172cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxFolderResultSet;
173cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::sdbc::XResultSet> mxEntryResultSet;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     /** Obtain the root folder of the template folder hierarchy.  The result
176cdf0e10cSrcweir         is stored in mxTemplateRoot for later use.
177cdf0e10cSrcweir     */
178cdf0e10cSrcweir     State GetTemplateRoot (void);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     /** Initialize the scanning of folders.  This is called exactly once.
181cdf0e10cSrcweir         @return
182cdf0e10cSrcweir             Returns one of the two states ERROR or GATHER_FOLDER_LIST.
183cdf0e10cSrcweir     */
184cdf0e10cSrcweir     State InitializeFolderScanning (void);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     /** Collect all available top-level folders in an ordered list which can
187cdf0e10cSrcweir         then be processed by ScanFolder().
188cdf0e10cSrcweir         @return
189cdf0e10cSrcweir             Returns one of the two states ERROR or SCAN_FOLDER.
190cdf0e10cSrcweir     */
191cdf0e10cSrcweir     State GatherFolderList (void);
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     /** From the list of top-level folders collected by GatherFolderList()
194cdf0e10cSrcweir         the one with highest priority is processed.
195cdf0e10cSrcweir         @return
196cdf0e10cSrcweir             Returns one of the states ERROR, DONE, or INITILIZE_ENTRY_SCAN.
197cdf0e10cSrcweir     */
198cdf0e10cSrcweir     State ScanFolder (void);
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     /** Initialize the scanning of entries of a top-level folder.
201cdf0e10cSrcweir         @return
202cdf0e10cSrcweir             Returns one of the states ERROR or SCAN_ENTRY.
203cdf0e10cSrcweir     */
204cdf0e10cSrcweir     State InitializeEntryScanning (void);
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     /** Scan one entry.  When this entry matches the recognized template
207cdf0e10cSrcweir         types it is appended to the result set.
208cdf0e10cSrcweir         @return
209cdf0e10cSrcweir             Returns one of the states ERROR, SCAN_ENTRY, or SCAN_FOLDER.
210cdf0e10cSrcweir     */
211cdf0e10cSrcweir     State ScanEntry (void);
212cdf0e10cSrcweir };
213cdf0e10cSrcweir 
214cdf0e10cSrcweir } // end of namespace sd
215cdf0e10cSrcweir 
216cdf0e10cSrcweir #endif
217