01: /*
02: * MeshCMS - A simple CMS based on SiteMesh
03: * Copyright (C) 2004-2007 Luciano Vernaschi
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
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 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
49: : WebSite.ADMIN_ID_FILE;
50: }
51:
52: protected void processFile(File file, Path path) {
53: //
54: }
55:
56: protected boolean preProcessDirectory(File file, Path path) {
57: if (cmsPath != null) {
58: return false;
59: }
60:
61: File vFile = new File(file, idFileName);
62:
63: if (vFile.exists()) {
64: cmsPath = virtualSite ? path : path.getParent();
65: return false;
66: }
67:
68: return true;
69: }
70:
71: /**
72: * Performs the search and returns the result.
73: *
74: * @return the CMS Path
75: */
76: public Path getCMSPath() {
77: if (cmsPath == null) {
78: process();
79: }
80:
81: return cmsPath;
82: }
83: }
|