KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > tags > PageScriptsTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
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
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core.tags;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
28
29 import org.apache.struts.taglib.TagUtils;
30
31 import com.sslexplorer.core.CoreScript;
32 import com.sslexplorer.core.CoreServlet;
33
34 /**
35  * @author Brett Smith <brett@3sp.com>
36  */

37 public class PageScriptsTag extends BodyTagSupport JavaDoc {
38     private String JavaDoc position = String.valueOf(CoreScript.AFTER_BODY_START);
39
40     /**
41      *
42      */

43     public PageScriptsTag() {
44         super();
45     }
46
47     public int doEndTag() throws JspException JavaDoc {
48         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
49         List JavaDoc l = new ArrayList JavaDoc();
50         for(Iterator JavaDoc i = CoreServlet.getServlet().getPageScripts().iterator(); i.hasNext(); ) {
51             CoreScript script = (CoreScript)i.next();
52             if(script.getPosition() == Integer.parseInt(position)) {
53                 l.add(script);
54             }
55         }
56         for(Iterator JavaDoc i = l.iterator(); i.hasNext(); ) {
57             CoreScript script = (CoreScript)i.next();
58             buf.append("\n<script");
59             if(script.getLanguage() != null) {
60                 buf.append(" language=\"");
61                 buf.append(script.getLanguage());
62                 buf.append("\"");
63             }
64             if(script.getType() != null) {
65                 buf.append(" type=\"");
66                 buf.append(script.getType());
67                 buf.append("\"");
68             }
69             if(script.getPath() != null) {
70                 buf.append(" SRC=\"");
71                 buf.append(script.getPath());
72                 buf.append("\">\n");
73                 buf.append("document.write(\"Included JS file not found\")");
74                 buf.append("</script>");
75             }
76             else {
77                 if(script.getScript() != null) {
78                     buf.append(">");
79                     buf.append(script.getScript());
80                     buf.append("</script>");
81                 }
82                 else {
83                     buf.append(">\n");
84                     buf.append("document.write(\"Included JS file not found\")");
85                     buf.append("</script>");
86                 }
87             }
88             
89             buf.append("\n");
90         }
91         TagUtils.getInstance().write(pageContext, buf.toString());
92         return (EVAL_PAGE);
93     }
94     
95     /**
96      * @return Returns the position.
97      */

98     public String JavaDoc getPosition() {
99         return position;
100     }
101
102     /**
103      * @param position The position to set.
104      */

105     public void setPosition(String JavaDoc position) {
106         this.position = position;
107     }
108 }
109
Popular Tags