KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.opensymphony.module.sitemesh.*;
28
29 /**
30  * This tag must include all others in a theme file. This is required to enclose
31  * all other tags in an HTML form while editing the page. Usually this tag is
32  * the first child of <code>&lt;body&gt;</code>:
33  *
34  * <pre> &lt;body&gt;&lt;cms:editor&gt;
35  * <em>... (html and other MeshCMS tags) ...</em>
36  * &lt;/cms:editor&gt;&lt;/body&gt;</pre>
37  *
38  * <em>Important note:</em> since a form can't be enclosed in another form, you
39  * must surround any other form in your theme with a &lt;cms:ifnotediting&gt;
40  * tag:
41  *
42  * <pre> &lt;body&gt;&lt;cms:editor&gt;
43  * <em>... (html and other MeshCMS tags) ...</em>
44  * &lt;cms:ifnotediting&gt;&lt;form action='youraction'&gt;
45  * <em>... your form ...</em>
46  * &lt;/form&gt;&lt;/cms:ifnotediting&gt;
47  * <em>... (html and other MeshCMS tags) ...</em>
48  * &lt;/cms:editor&gt;&lt;/body&gt;</pre>
49  *
50  * This way your form won't be displayed while editing.
51  */

52 public class Editor extends AbstractTag {
53   public int doEndTag() {
54     if (isEdit) {
55       try {
56         getOut().write("</form>");
57       } catch (IOException ex) {
58         pageContext.getServletContext().log("Can't write", ex);
59       }
60     }
61
62     return EVAL_PAGE;
63   }
64
65   public void writeTag() throws IOException {
66     // nothing to do here
67
}
68
69   public void writeEditTag() throws IOException {
70     Writer w = getOut();
71     w.write("<form id='editor' name='editor' action=\"" + afp +
72       "/savepage.jsp\" method='post'>\n");
73
74     HTMLPage htmlPage = (HTMLPage) getPage();
75     String JavaDoc[] keys = htmlPage.getPropertyKeys();
76
77     for (int i = 0; i < keys.length; i++) {
78       if (!keys[i].equals(PageAssembler.EMAIL_PARAM) &&
79           !keys[i].equals(PageAssembler.MODULES_PARAM) &&
80           !keys[i].equals("title")) {
81         w.write("<input type='hidden' name='" + keys[i] + "' value=\"" +
82             htmlPage.getProperty(keys[i]) + "\" />\n");
83       }
84     }
85
86     w.write("<input type='hidden' name='pagepath' value=\"" +
87       pagePath + "\" />");
88   }
89
90   public int getStartTagReturnValue() {
91     return EVAL_BODY_INCLUDE;
92   }
93 }
94
Popular Tags