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