KickJava   Java API By Example, From Geeks To Geeks.

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


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

37 public class PageHead extends AbstractTag {
38   public void writeTag() throws IOException {
39     Writer w = getOut();
40     ((HTMLPage) getPage()).writeHead(w);
41     Locale locale = (Locale) pageContext.getAttribute(HitFilter.LOCALE_ATTRIBUTE,
42         PageContext.REQUEST_SCOPE);
43
44     if (locale != null) {
45       w.write("\n<meta http-equiv=\"Content-Language\" content=\"" + locale + "\" />");
46     }
47
48     String JavaDoc redir = (String JavaDoc) request.getAttribute(SetLocale.REDIRECT_ATTRIBUTE);
49
50     if (redir != null) {
51       if (userInfo == null || userInfo.isGuest()) {
52         w.write("\n<meta http-equiv=\"refresh\" content=\"0; url=" + redir + "\" />");
53       } else {
54         Locale pl = WebUtils.getPageLocale(pageContext);
55         ResourceBundle bundle =
56             ResourceBundle.getBundle("org/meshcms/webui/Locales", pl);
57         w.write("\n<script type='text/javascript'>alert(\"" +
58             bundle.getString("pageRedirectionAlert") + "\");</script>");
59       }
60     }
61   }
62
63   public void writeEditTag() throws IOException {
64     Path linkListPath = new Path(ap, "tinymce_linklist.jsp");
65     linkListPath = linkListPath.getRelativeTo(webSite.getDirectory(pagePath));
66     Locale locale = WebUtils.getPageLocale(pageContext);
67     ResourceBundle bundle = ResourceBundle.getBundle("org/meshcms/webui/Locales", locale);
68     String JavaDoc langCode = bundle.getString("TinyMCELangCode");
69
70     if (Utils.isNullOrEmpty(langCode)) {
71       langCode = locale.getLanguage();
72     }
73
74     Writer w = getOut();
75     ((HTMLPage) getPage()).writeHead(w);
76     w.write("\n<script type='text/javascript' SRC='" +
77       cp + '/' + (webSite.getFile(webSite.getCMSPath().add("tiny_mce")).exists() ?
78       webSite.getCMSPath() : webSite.getAdminScriptsPath()) +
79       "/tiny_mce/tiny_mce.js'></script>\n");
80     w.write("<script type='text/javascript'>\n");
81     w.write("// <![CDATA[\n");
82     w.write(" var contextPath = \"" + cp + "\";\n");
83     w.write(" var adminPath = \"" + webSite.getAdminPath() + "\";\n");
84     w.write(" var languageCode = \"" + langCode + "\";\n");
85     w.write(" var linkListPath = \"" + linkListPath + "\";\n");
86     w.write(" var cssPath = \"" + WebUtils.getFullThemeCSS(request) + "\";\n");
87     w.write("// ]]>\n");
88     w.write("</script>\n");
89     w.write("<script type='text/javascript' SRC='" +
90       cp + '/' + webSite.getAdminScriptsPath() + "/editor.js'></script>\n");
91
92     w.write("<script type='text/javascript' SRC='" + cp + '/' +
93       (webSite.getFile(webSite.getCMSPath().add("tinymce_init.js")).exists() ?
94       webSite.getCMSPath() : webSite.getAdminScriptsPath()) +
95       "/tinymce_init.js'></script>");
96   }
97 }
98
Popular Tags