KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.text.*;
27 import java.util.*;
28 import org.meshcms.core.*;
29 import org.meshcms.util.*;
30 import com.opensymphony.module.sitemesh.*;
31
32 /**
33  * Writes the page title. Please note that since this tag is used within the
34  * <head> tag, the field to edit the page title are displayed by
35  * {@link PageBody}
36  */

37 public class PageTitle extends AbstractTag {
38   private String JavaDoc defaultTitle = " ";
39
40   public void setDefault(String JavaDoc defaultTitle) {
41     this.defaultTitle = Utils.noNull(defaultTitle);
42   }
43
44   public String JavaDoc getDefault() {
45     return defaultTitle;
46   }
47
48   public String JavaDoc getTitle() {
49     String JavaDoc title = null;
50     Page page = getPage();
51
52     if (page != null) {
53       title = page.getTitle();
54     }
55
56     if (Utils.isNullOrEmpty(title)) {
57       title = defaultTitle;
58     }
59
60     return title;
61   }
62
63   public void writeTag() throws IOException {
64     getOut().write(getTitle());
65   }
66
67   public void writeEditTag() throws IOException {
68     Locale locale = WebUtils.getPageLocale(pageContext);
69     ResourceBundle bundle = ResourceBundle.getBundle("org/meshcms/webui/Locales", locale);
70     MessageFormat formatter = new MessageFormat("", locale);
71
72     Object JavaDoc[] args = { getTitle() };
73     formatter.applyPattern(bundle.getString("editorTitle"));
74     getOut().write(formatter.format(args));
75   }
76 }
77
Popular Tags