KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > taglib > SearchFile


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.taglib;
24
25 import java.io.*;
26 import org.meshcms.core.*;
27 import org.meshcms.util.*;
28
29 /**
30  * Writes the path of the theme folder. Often used to access files included in
31  * that folder.
32  */

33 public final class SearchFile extends AbstractTag {
34   private String JavaDoc name;
35   private String JavaDoc defaultName;
36
37   public void writeTag() throws IOException {
38     if (!Utils.isNullOrEmpty(name)) {
39       Path found = null;
40       Path currentPath = webSite.getDirectory(pagePath);
41
42       while (found == null && !currentPath.isRelative()) {
43         Path p = currentPath.add(name);
44         currentPath = currentPath.getParent();
45
46         if (webSite.getFile(p).exists()) {
47           found = p;
48         }
49       }
50
51       if (found == null && defaultName != null) {
52         Path themePath = (Path) request.getAttribute(HitFilter.THEME_PATH_ATTRIBUTE);
53
54         if (themePath != null) {
55           themePath = themePath.add(defaultName);
56
57           if (webSite.getFile(themePath).exists()) {
58             found = themePath;
59           }
60         }
61       }
62
63       if (found != null) {
64         getOut().write(cp + '/' + found);
65       }
66     }
67   }
68
69   public String JavaDoc getName() {
70     return name;
71   }
72
73   public void setName(String JavaDoc name) {
74     this.name = name;
75   }
76
77   public String JavaDoc getDefaultName() {
78     return defaultName;
79   }
80
81   public void setDefaultName(String JavaDoc defaultName) {
82     this.defaultName = defaultName;
83   }
84 }
85
Popular Tags