01: /* Head.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Dec 13 10:49:25 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zhtml;
20:
21: import java.io.StringWriter;
22:
23: import org.zkoss.zk.ui.Execution;
24: import org.zkoss.zk.ui.Executions;
25: import org.zkoss.zk.fn.ZkFns;
26: import org.zkoss.zhtml.impl.AbstractTag;
27:
28: /**
29: * The HEAD tag.
30: *
31: * @author tomyeh
32: */
33: public class Head extends AbstractTag {
34: public Head() {
35: super ("head");
36: }
37:
38: //-- super --//
39: /** Don't generate the id attribute.
40: */
41: protected boolean shallHideId() {
42: return true;
43: }
44:
45: //--Component-//
46: public void redraw(java.io.Writer out) throws java.io.IOException {
47: final StringWriter bufout = new StringWriter();
48: super .redraw(bufout);
49: final StringBuffer buf = bufout.getBuffer();
50:
51: final String zktags = outZKHtmlTags();
52: if (zktags != null) {
53: final int j = buf.lastIndexOf("</head>");
54: if (j >= 0)
55: buf.insert(j, zktags);
56: else
57: buf.append(zktags);
58: }
59:
60: out.write(buf.toString());
61: out.write('\n');
62: }
63:
64: /** Generates the ZK specific HTML tags.
65: * @return the buffer holding the HTML tags, or null if already generated.
66: */
67: /*package*/static String outZKHtmlTags() {
68: final Execution exec = Executions.getCurrent();
69: final String ATTR_ACTION = "zk_argAction";
70: final String action = (String) exec.getAttribute(ATTR_ACTION);
71: if (action == null)
72: return null;
73:
74: final StringBuffer sb = new StringBuffer(512).append('\n')
75: .append(ZkFns.outLangStyleSheets()).append('\n')
76: .append(ZkFns.outLangJavaScripts(action)).append('\n');
77:
78: exec.removeAttribute(ATTR_ACTION); //turn off page.dsp's generation
79: return sb.toString();
80: }
81: }
|