KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > core > CMSDirectoryFinder


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.core;
24
25 import java.io.*;
26 import org.meshcms.util.*;
27
28 /**
29  * Finds the CMS directory by searching for a sentinel file.
30  */

31 public class CMSDirectoryFinder extends DirectoryParser {
32   private Path cmsPath;
33   private boolean virtualSite;
34   private String JavaDoc idFileName;
35
36   /**
37    * Creates a new instance to search for the CMS directory using the
38    * given root.
39    *
40    * @param siteRoot initial directory to start the processing.
41    * @param virtualSite used to determine what file to search (virtual sites
42    * do not contain an admin directory, so a different file is searched).
43    */

44   public CMSDirectoryFinder(File siteRoot, boolean virtualSite) {
45     setRecursive(true);
46     setInitialDir(siteRoot);
47     this.virtualSite = virtualSite;
48     idFileName = virtualSite ? WebSite.CMS_ID_FILE : WebSite.ADMIN_ID_FILE;
49   }
50
51   protected void processFile(File file, Path path) {
52     //
53
}
54
55   protected boolean preProcessDirectory(File file, Path path) {
56     if (cmsPath != null) {
57       return false;
58     }
59
60     File vFile = new File(file, idFileName);
61
62     if (vFile.exists()) {
63       cmsPath = virtualSite ? path : path.getParent();
64       return false;
65     }
66
67     return true;
68   }
69
70   /**
71    * Performs the search and returns the result.
72    *
73    * @return the CMS Path
74    */

75   public Path getCMSPath() {
76     if (cmsPath == null) {
77       process();
78     }
79
80     return cmsPath;
81   }
82 }
83
Popular Tags