01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.fileimport;
16:
17: import java.io.Writer;
18: import org.araneaframework.http.util.FileImportUtil;
19: import org.araneaframework.jsp.util.JspUtil;
20:
21: /**
22: * @author "Toomas Römer" <toomas@webmedia.ee>
23: *
24: * @jsp.tag
25: * name = "importScripts"
26: * body-content="empty"
27: * description = "Imports js files"
28: */
29: public class ImportScriptsHtmlTag extends BaseFileImportTag {
30: public static final String DEFAULT_GROUP_NAME = "defaultScripts";
31:
32: public int doStartTag(Writer out) throws Exception {
33: // if filename specified we include the file
34: if (includeFileName != null) {
35: writeContent(out, includeFileName);
36: }
37: // if groupname specified we include the group
38: else if (includeGroupName != null) {
39: writeContent(out, includeGroupName);
40: }
41: // we default to the default group name
42: else {
43: writeContent(out, DEFAULT_GROUP_NAME);
44: }
45: return EVAL_BODY_INCLUDE;
46: }
47:
48: protected void writeContent(Writer out, String srcFile)
49: throws Exception {
50: writeHtmlScriptsInclude(out, FileImportUtil.getImportString(
51: srcFile, pageContext.getRequest()));
52: out.write("\n");
53: }
54:
55: public static void writeHtmlScriptsInclude(Writer out,
56: String srcFile) throws Exception {
57: JspUtil.writeOpenStartTag(out, "script");
58: JspUtil.writeAttribute(out, "language", "JavaScript1.2");
59: JspUtil.writeAttribute(out, "type", "text/javascript");
60: JspUtil.writeAttribute(out, "src", srcFile, false);
61: JspUtil.writeCloseStartTag(out);
62: JspUtil.writeEndTag(out, "script");
63: out.write("\n");
64: }
65: }
|