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