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 javax.servlet.jsp.JspException;
19: import org.araneaframework.http.util.FileImportUtil;
20: import org.araneaframework.jsp.util.JspUtil;
21:
22: /**
23: * @author "Toomas Römer" <toomas@webmedia.ee>
24: *
25: * @jsp.tag
26: * name = "importStyles"
27: * body-content="empty"
28: * description = "Imports CSS files."
29: */
30: public class ImportStylesHtmlTag extends BaseFileImportTag {
31: public static final String DEFAULT_GROUP_NAME = "defaultStyles";
32:
33: private String media;
34:
35: public int doStartTag(Writer out) throws Exception {
36: // if filename specified we include the file
37: if (includeFileName != null) {
38: writeContent(out, includeFileName);
39: } else if (includeGroupName != null) {
40: writeContent(out, includeGroupName);
41: } else {
42: writeContent(out, DEFAULT_GROUP_NAME);
43: }
44: return EVAL_BODY_INCLUDE;
45: }
46:
47: /**
48: * @jsp.attribute
49: * type = "java.lang.String"
50: * required = "false"
51: * description = "The media type the css file should be applied to."
52: */
53: public void setMedia(String media) throws JspException {
54: this .media = (String) evaluate("media", media, String.class);
55: }
56:
57: protected void writeContent(Writer out, String srcFile)
58: throws Exception {
59: srcFile = FileImportUtil.getImportString(srcFile, pageContext
60: .getRequest());
61:
62: JspUtil.writeOpenStartTag(out, "link");
63: JspUtil.writeAttribute(out, "rel", "stylesheet");
64: JspUtil.writeAttribute(out, "type", "text/css");
65: JspUtil.writeAttribute(out, "href", srcFile, false);
66: JspUtil.writeAttribute(out, "media", this .media);
67: JspUtil.writeCloseStartEndTag(out);
68: out.write("\n");
69: }
70: }
|