KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > tag > UploadFormTag


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.repo.tag;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Writer JavaDoc;
21
22 import javax.portlet.RenderResponse;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.jsp.JspException JavaDoc;
25 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
26
27 import org.alfresco.web.app.Application;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 /**
32  * A non-JSF tag library that outputs the form tag for uploading files, this tag
33  * is sensitive to whether the application is running in servlet or portlet mode
34  *
35  * @author gavinc
36  */

37 public class UploadFormTag extends TagSupport JavaDoc
38 {
39    private static final long serialVersionUID = 4064734856565167835L;
40     
41    private static Log logger = LogFactory.getLog(UploadFormTag.class);
42    
43    /**
44     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
45     */

46    public int doStartTag() throws JspException JavaDoc
47    {
48       try
49       {
50          Writer JavaDoc out = pageContext.getOut();
51          
52          out.write("<form name='upload-form' acceptCharset='UTF-8' method='post' enctype='multipart/form-data' action='");
53          
54          if (Application.inPortalServer())
55          {
56             RenderResponse renderResp = (RenderResponse)pageContext.getRequest().
57                                    getAttribute("javax.portlet.response");
58             if (renderResp == null)
59             {
60                throw new IllegalStateException JavaDoc("RenderResponse object is null. The web application is not executing within a portal server!");
61             }
62             
63             out.write(renderResp.createActionURL().toString());
64             out.write("'>");
65          }
66          else
67          {
68             HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)pageContext.getRequest();
69             out.write(req.getContextPath());
70             out.write("/uploadFileServlet'>\n");
71             out.write("<input type='hidden' name='return-page' value='");
72             out.write(req.getContextPath() + "/faces" + req.getServletPath());
73             out.write("'>\n");
74          }
75       }
76       catch (IOException JavaDoc ioe)
77       {
78          throw new JspException JavaDoc(ioe.toString());
79       }
80       
81       return EVAL_BODY_INCLUDE;
82    }
83
84    public int doEndTag() throws JspException JavaDoc
85    {
86       try
87       {
88          pageContext.getOut().write("\n</form>");
89       }
90       catch (IOException JavaDoc ioe)
91       {
92          throw new JspException JavaDoc(ioe.toString());
93       }
94       
95       return super.doEndTag();
96    }
97 }
98
Popular Tags