xref: /aoo41x/main/sd/source/ui/dlg/TemplateScanner.cxx (revision 5b190011)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "TemplateScanner.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _COMPHELPER_SERVICEFACTORY_HXX
30cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <comphelper/documentconstants.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir #include <vos/mutex.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>
37cdf0e10cSrcweir #include <com/sun/star/frame/XDocumentTemplates.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <set>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir const ::rtl::OUString TITLE            = ::rtl::OUString::createFromAscii ("Title");
52cdf0e10cSrcweir const ::rtl::OUString TARGET_DIR_URL   = ::rtl::OUString::createFromAscii ("TargetDirURL");
53cdf0e10cSrcweir const ::rtl::OUString DESCRIPTION      = ::rtl::OUString::createFromAscii ("TypeDescription");
54cdf0e10cSrcweir const ::rtl::OUString TARGET_URL       = ::rtl::OUString::createFromAscii ("TargetURL");
55cdf0e10cSrcweir 
56cdf0e10cSrcweir const ::rtl::OUString DOCTEMPLATES     = ::rtl::OUString::createFromAscii ("com.sun.star.frame.DocumentTemplates");
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //  These strings are used to find impress templates in the tree of
59cdf0e10cSrcweir //  template files.  Should probably be determined dynamically.
60cdf0e10cSrcweir const ::rtl::OUString IMPRESS_BIN_TEMPLATE = ::rtl::OUString::createFromAscii ("application/vnd.stardivision.impress");
61cdf0e10cSrcweir const ::rtl::OUString IMPRESS_XML_TEMPLATE = MIMETYPE_VND_SUN_XML_IMPRESS;
62cdf0e10cSrcweir // The following id comes from the bugdoc in #i2764#.
63cdf0e10cSrcweir const ::rtl::OUString IMPRESS_XML_TEMPLATE_B = ::rtl::OUString::createFromAscii ("Impress 2.0");
64cdf0e10cSrcweir const ::rtl::OUString IMPRESS_XML_TEMPLATE_OASIS = MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir class FolderDescriptor
68cdf0e10cSrcweir {
69cdf0e10cSrcweir public:
70cdf0e10cSrcweir     FolderDescriptor (
71cdf0e10cSrcweir         int nPriority,
72cdf0e10cSrcweir         const ::rtl::OUString& rsTitle,
73cdf0e10cSrcweir         const ::rtl::OUString& rsTargetDir,
74cdf0e10cSrcweir         const ::rtl::OUString& rsContentIdentifier,
75cdf0e10cSrcweir         const Reference<com::sun::star::ucb::XCommandEnvironment>& rxFolderEnvironment)
76cdf0e10cSrcweir         : mnPriority(nPriority),
77cdf0e10cSrcweir           msTitle(rsTitle),
78cdf0e10cSrcweir           msTargetDir(rsTargetDir),
79cdf0e10cSrcweir           msContentIdentifier(rsContentIdentifier),
80cdf0e10cSrcweir           mxFolderEnvironment(rxFolderEnvironment)
81cdf0e10cSrcweir     { }
82cdf0e10cSrcweir     int mnPriority;
83cdf0e10cSrcweir     ::rtl::OUString msTitle;
84cdf0e10cSrcweir     ::rtl::OUString msTargetDir;
85cdf0e10cSrcweir     ::rtl::OUString msContentIdentifier;
86cdf0e10cSrcweir     //    Reference<sdbc::XResultSet> mxFolderResultSet;
87cdf0e10cSrcweir     Reference<com::sun::star::ucb::XCommandEnvironment> mxFolderEnvironment;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     class Comparator { public:
90cdf0e10cSrcweir         bool operator() (const FolderDescriptor& r1, const FolderDescriptor& r2)
91cdf0e10cSrcweir         { return r1.mnPriority < r2.mnPriority; }
92cdf0e10cSrcweir     };
93cdf0e10cSrcweir };
94cdf0e10cSrcweir 
95cdf0e10cSrcweir /** Use a heuristic based on the URL of a top-level template folder to
96cdf0e10cSrcweir     assign a priority that is used to sort the folders.
97cdf0e10cSrcweir */
98cdf0e10cSrcweir int Classify (const ::rtl::OUString&, const ::rtl::OUString& rsURL)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     int nPriority (0);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     if (rsURL.getLength() == 0)
103cdf0e10cSrcweir         nPriority = 100;
104cdf0e10cSrcweir     else if (rsURL.indexOf(::rtl::OUString::createFromAscii("presnt"))>=0)
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         nPriority = 30;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     else if (rsURL.indexOf(::rtl::OUString::createFromAscii("layout"))>=0)
109cdf0e10cSrcweir     {
110cdf0e10cSrcweir         nPriority = 20;
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir     else if (rsURL.indexOf(::rtl::OUString::createFromAscii("educate"))>=0)
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         nPriority = 40;
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir     else if (rsURL.indexOf(::rtl::OUString::createFromAscii("finance"))>=0)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         nPriority = 40;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     else
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         // All other folders are taken for user supplied and have the
123cdf0e10cSrcweir         // highest priority.
124cdf0e10cSrcweir         nPriority = 10;
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     return nPriority;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir } // end of anonymous namespace
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir namespace sd
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 
138cdf0e10cSrcweir class TemplateScanner::FolderDescriptorList
139cdf0e10cSrcweir     : public ::std::multiset<FolderDescriptor,FolderDescriptor::Comparator>
140cdf0e10cSrcweir {
141cdf0e10cSrcweir };
142cdf0e10cSrcweir 
143cdf0e10cSrcweir TemplateScanner::TemplateScanner (void)
144cdf0e10cSrcweir     : meState(INITIALIZE_SCANNING),
145cdf0e10cSrcweir       maFolderContent(),
146cdf0e10cSrcweir       mpTemplateDirectory(NULL),
147cdf0e10cSrcweir       maFolderList(),
148cdf0e10cSrcweir       mpLastAddedEntry(NULL),
149cdf0e10cSrcweir       mpFolderDescriptors(new FolderDescriptorList()),
150cdf0e10cSrcweir 	  mxTemplateRoot(),
151cdf0e10cSrcweir       mxFolderEnvironment(),
152cdf0e10cSrcweir       mxEntryEnvironment(),
153cdf0e10cSrcweir       mxFolderResultSet(),
154cdf0e10cSrcweir       mxEntryResultSet()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     //  empty;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 
162cdf0e10cSrcweir TemplateScanner::~TemplateScanner (void)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     mpFolderDescriptors.reset();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     // Delete all entries of the template list that have not been
167cdf0e10cSrcweir     // transferred to another object.
168cdf0e10cSrcweir     std::vector<TemplateDir*>::iterator I;
169cdf0e10cSrcweir     for (I=maFolderList.begin(); I!=maFolderList.end(); I++)
170cdf0e10cSrcweir         if (*I != NULL)
171cdf0e10cSrcweir             delete *I;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir TemplateScanner::State TemplateScanner::GetTemplateRoot (void)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     State eNextState (INITIALIZE_FOLDER_SCANNING);
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     Reference<lang::XMultiServiceFactory> xFactory = ::comphelper::getProcessServiceFactory ();
182cdf0e10cSrcweir     DBG_ASSERT (xFactory.is(), "TemplateScanner::GetTemplateRoot: xFactory is NULL");
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     if (xFactory.is())
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         Reference<frame::XDocumentTemplates> xTemplates (
187cdf0e10cSrcweir             xFactory->createInstance (DOCTEMPLATES), UNO_QUERY);
188cdf0e10cSrcweir         DBG_ASSERT (xTemplates.is(), "TemplateScanner::GetTemplateRoot: xTemplates is NULL");
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         if (xTemplates.is())
191cdf0e10cSrcweir             mxTemplateRoot = xTemplates->getContent();
192cdf0e10cSrcweir         else
193cdf0e10cSrcweir             eNextState = ERROR;
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     else
196cdf0e10cSrcweir         eNextState = ERROR;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     return eNextState;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
204cdf0e10cSrcweir TemplateScanner::State TemplateScanner::InitializeEntryScanning (void)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     State eNextState (SCAN_ENTRY);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     if (maFolderContent.isFolder())
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         mxEntryEnvironment = Reference<com::sun::star::ucb::XCommandEnvironment>();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         //  We are interested only in three properties: the entry's name,
213cdf0e10cSrcweir         //  its URL, and its content type.
214cdf0e10cSrcweir         Sequence<rtl::OUString> aProps (3);
215cdf0e10cSrcweir         aProps[0] = TITLE;
216cdf0e10cSrcweir         aProps[1] = TARGET_URL;
217cdf0e10cSrcweir         aProps[2] = DESCRIPTION;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         //  Create a cursor to iterate over the templates in this folders.
220cdf0e10cSrcweir         ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
221cdf0e10cSrcweir         mxEntryResultSet = Reference<com::sun::star::sdbc::XResultSet>(
222cdf0e10cSrcweir             maFolderContent.createCursor(aProps, eInclude));
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir     else
225cdf0e10cSrcweir         eNextState = ERROR;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     return eNextState;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir TemplateScanner::State TemplateScanner::ScanEntry (void)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     State eNextState (ERROR);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     Reference<com::sun::star::ucb::XContentAccess> xContentAccess (mxEntryResultSet, UNO_QUERY);
238cdf0e10cSrcweir     Reference<com::sun::star::sdbc::XRow> xRow (mxEntryResultSet, UNO_QUERY);
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     if (xContentAccess.is() && xRow.is() && mxEntryResultSet.is())
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         if (mxEntryResultSet->next())
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             ::rtl::OUString sTitle (xRow->getString (1));
245cdf0e10cSrcweir             ::rtl::OUString sTargetURL (xRow->getString (2));
246cdf0e10cSrcweir             ::rtl::OUString sContentType (xRow->getString (3));
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             ::rtl::OUString aId = xContentAccess->queryContentIdentifierString();
249cdf0e10cSrcweir             ::ucbhelper::Content  aContent = ::ucbhelper::Content (aId, mxEntryEnvironment);
250cdf0e10cSrcweir             if (aContent.isDocument ())
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 //  Check wether the entry is an impress template.  If so
253cdf0e10cSrcweir                 //  add a new entry to the resulting list (which is created
254cdf0e10cSrcweir                 //  first if necessary).
255cdf0e10cSrcweir                 if (    (sContentType == MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE)
256cdf0e10cSrcweir                     ||  (sContentType == IMPRESS_XML_TEMPLATE_OASIS)
257cdf0e10cSrcweir                     ||  (sContentType == IMPRESS_BIN_TEMPLATE)
258cdf0e10cSrcweir                     ||  (sContentType == IMPRESS_XML_TEMPLATE)
259cdf0e10cSrcweir                     ||  (sContentType == IMPRESS_XML_TEMPLATE_B))
260cdf0e10cSrcweir                 {
261cdf0e10cSrcweir                     mpLastAddedEntry = new TemplateEntry(sTitle, sTargetURL);
262cdf0e10cSrcweir                     mpTemplateDirectory->maEntries.push_back(mpLastAddedEntry);
263cdf0e10cSrcweir                 }
264cdf0e10cSrcweir             }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir             // Continue scanning entries.
267cdf0e10cSrcweir             eNextState = SCAN_ENTRY;
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir         else
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             if (mpTemplateDirectory->maEntries.empty())
272cdf0e10cSrcweir             {
273cdf0e10cSrcweir                 delete mpTemplateDirectory;
274cdf0e10cSrcweir                 mpTemplateDirectory = NULL;
275cdf0e10cSrcweir             }
276cdf0e10cSrcweir             else
277cdf0e10cSrcweir             {
278cdf0e10cSrcweir                 ::vos::OGuard aGuard(Application::GetSolarMutex());
279cdf0e10cSrcweir                 maFolderList.push_back(mpTemplateDirectory);
280cdf0e10cSrcweir             }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir             // Continue with scanning the next folder.
283cdf0e10cSrcweir             eNextState = SCAN_FOLDER;
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     return eNextState;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 
293cdf0e10cSrcweir TemplateScanner::State TemplateScanner::InitializeFolderScanning (void)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     State eNextState (ERROR);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     mxFolderResultSet = Reference<sdbc::XResultSet>();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     try
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         //  Create content for template folders.
302cdf0e10cSrcweir         mxFolderEnvironment = Reference<com::sun::star::ucb::XCommandEnvironment>();
303cdf0e10cSrcweir         ::ucbhelper::Content aTemplateDir (mxTemplateRoot, mxFolderEnvironment);
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         //  Define the list of properties we are interested in.
306cdf0e10cSrcweir         Sequence<rtl::OUString> aProps (2);
307cdf0e10cSrcweir         aProps[0] = TITLE;
308cdf0e10cSrcweir         aProps[1] = TARGET_DIR_URL;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir         //  Create an cursor to iterate over the template folders.
311cdf0e10cSrcweir         ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_ONLY;
312cdf0e10cSrcweir         mxFolderResultSet = Reference<sdbc::XResultSet>(
313cdf0e10cSrcweir             aTemplateDir.createCursor(aProps, eInclude));
314cdf0e10cSrcweir         if (mxFolderResultSet.is())
315cdf0e10cSrcweir             eNextState = GATHER_FOLDER_LIST;
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir     catch (::com::sun::star::uno::Exception&)
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir        eNextState = ERROR;
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     return eNextState;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 
328cdf0e10cSrcweir TemplateScanner::State TemplateScanner::GatherFolderList (void)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     State eNextState (ERROR);
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     Reference<com::sun::star::ucb::XContentAccess> xContentAccess (mxFolderResultSet, UNO_QUERY);
333cdf0e10cSrcweir     if (xContentAccess.is() && mxFolderResultSet.is())
334cdf0e10cSrcweir     {
335cdf0e10cSrcweir         while (mxFolderResultSet->next())
336cdf0e10cSrcweir         {
337cdf0e10cSrcweir             Reference<sdbc::XRow> xRow (mxFolderResultSet, UNO_QUERY);
338cdf0e10cSrcweir             if (xRow.is())
339cdf0e10cSrcweir             {
340cdf0e10cSrcweir                 ::rtl::OUString sTitle (xRow->getString (1));
341cdf0e10cSrcweir                 ::rtl::OUString sTargetDir (xRow->getString (2));
342cdf0e10cSrcweir                 ::rtl::OUString aId = xContentAccess->queryContentIdentifierString();
343cdf0e10cSrcweir 
344cdf0e10cSrcweir                 mpFolderDescriptors->insert(
345cdf0e10cSrcweir                     FolderDescriptor(
346cdf0e10cSrcweir                         Classify(sTitle,sTargetDir),
347cdf0e10cSrcweir                         sTitle,
348cdf0e10cSrcweir                         sTargetDir,
349cdf0e10cSrcweir                         aId,
350cdf0e10cSrcweir                         mxFolderEnvironment));
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         eNextState = SCAN_FOLDER;
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     return eNextState;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
363cdf0e10cSrcweir TemplateScanner::State TemplateScanner::ScanFolder (void)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     State eNextState (ERROR);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     if (mpFolderDescriptors->size() > 0)
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         FolderDescriptor aDescriptor (*mpFolderDescriptors->begin());
370cdf0e10cSrcweir         mpFolderDescriptors->erase(mpFolderDescriptors->begin());
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         ::rtl::OUString sTitle (aDescriptor.msTitle);
373cdf0e10cSrcweir         ::rtl::OUString sTargetDir (aDescriptor.msTargetDir);
374cdf0e10cSrcweir         ::rtl::OUString aId (aDescriptor.msContentIdentifier);
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         maFolderContent = ::ucbhelper::Content (aId, aDescriptor.mxFolderEnvironment);
377cdf0e10cSrcweir         if (maFolderContent.isFolder())
378cdf0e10cSrcweir         {
379cdf0e10cSrcweir             // Scan the folder and insert it into the list of template
380cdf0e10cSrcweir             // folders.
381cdf0e10cSrcweir             mpTemplateDirectory = new TemplateDir (sTitle, sTargetDir);
382cdf0e10cSrcweir             if (mpTemplateDirectory != NULL)
383cdf0e10cSrcweir             {
384cdf0e10cSrcweir                 // Continue with scanning all entries in the folder.
385cdf0e10cSrcweir                 eNextState = INITIALIZE_ENTRY_SCAN;
386cdf0e10cSrcweir             }
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir     else
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         eNextState = DONE;
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     return eNextState;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 
400cdf0e10cSrcweir void TemplateScanner::Scan (void)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir     while (HasNextStep())
403cdf0e10cSrcweir         RunNextStep();
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 
409cdf0e10cSrcweir std::vector<TemplateDir*>& TemplateScanner::GetFolderList (void)
410cdf0e10cSrcweir {
411cdf0e10cSrcweir     return maFolderList;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 
417cdf0e10cSrcweir void TemplateScanner::RunNextStep (void)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     switch (meState)
420cdf0e10cSrcweir     {
421cdf0e10cSrcweir         case INITIALIZE_SCANNING:
422cdf0e10cSrcweir             meState = GetTemplateRoot();
423cdf0e10cSrcweir             break;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir         case INITIALIZE_FOLDER_SCANNING:
426cdf0e10cSrcweir             meState = InitializeFolderScanning();
427cdf0e10cSrcweir             break;
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         case SCAN_FOLDER:
430cdf0e10cSrcweir             meState = ScanFolder();
431cdf0e10cSrcweir             break;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         case GATHER_FOLDER_LIST:
434cdf0e10cSrcweir             meState = GatherFolderList();
435cdf0e10cSrcweir             break;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         case INITIALIZE_ENTRY_SCAN:
438cdf0e10cSrcweir             meState = InitializeEntryScanning();
439cdf0e10cSrcweir             break;
440cdf0e10cSrcweir 
441cdf0e10cSrcweir         case SCAN_ENTRY:
442cdf0e10cSrcweir             meState = ScanEntry();
443cdf0e10cSrcweir             break;
444cdf0e10cSrcweir 		default:
445cdf0e10cSrcweir 			break;
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     switch (meState)
449cdf0e10cSrcweir     {
450cdf0e10cSrcweir         case DONE:
451cdf0e10cSrcweir         case ERROR:
452cdf0e10cSrcweir             mxTemplateRoot.clear();
453cdf0e10cSrcweir             mxTemplateRoot.clear();
454cdf0e10cSrcweir             mxFolderEnvironment.clear();
455cdf0e10cSrcweir             mxEntryEnvironment.clear();
456cdf0e10cSrcweir             mxFolderResultSet.clear();
457cdf0e10cSrcweir             mxEntryResultSet.clear();
458cdf0e10cSrcweir             mpLastAddedEntry = NULL;
459cdf0e10cSrcweir             break;
460cdf0e10cSrcweir 		default:
461cdf0e10cSrcweir 			break;
462cdf0e10cSrcweir     }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
468cdf0e10cSrcweir bool TemplateScanner::HasNextStep (void)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     switch (meState)
471cdf0e10cSrcweir     {
472cdf0e10cSrcweir         case DONE:
473cdf0e10cSrcweir         case ERROR:
474cdf0e10cSrcweir             return false;
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         default:
477cdf0e10cSrcweir             return true;
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 
484cdf0e10cSrcweir const TemplateEntry* TemplateScanner::GetLastAddedEntry (void) const
485cdf0e10cSrcweir {
486cdf0e10cSrcweir     return mpLastAddedEntry;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir }
490