KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > taglib > content > AssetUrlTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.deliver.taglib.content;
25
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.JspTagException JavaDoc;
28
29 import org.infoglue.deliver.taglib.component.ComponentLogicTag;
30
31 /**
32  * This is an attempt to make an TagLib for attempts to get a AssetUrl:s from a content referenced by a component
33  * in a JSP.
34  *
35  * <%@ taglib uri="infoglue" prefix="infoglue" %>
36  *
37  * <infoglue:component.AssetUrl propertyName="Logotype" assetKey="logotype"/>
38  *
39  * @author Mattias Bogeblad
40  */

41
42 public class AssetUrlTag extends ComponentLogicTag
43 {
44     private static final long serialVersionUID = 3546080250652931383L;
45
46     private Integer JavaDoc contentId;
47     private String JavaDoc propertyName;
48     private String JavaDoc assetKey;
49     private boolean useInheritance = true;
50     
51     public AssetUrlTag()
52     {
53         super();
54     }
55     
56     public int doEndTag() throws JspException JavaDoc
57     {
58         try
59         {
60             if(contentId != null)
61             {
62                 if(assetKey != null)
63                     produceResult(getController().getAssetUrl(contentId, assetKey));
64                 else
65                     produceResult(getController().getAssetUrl(contentId));
66             }
67             else if(propertyName != null)
68             {
69                 if(assetKey != null)
70                     produceResult(getComponentLogic().getAssetUrl(propertyName, assetKey, useInheritance));
71                 else
72                     produceResult(getComponentLogic().getAssetUrl(propertyName, useInheritance));
73             }
74             else
75             {
76                 throw new JspException JavaDoc("You must supply either contentId or propertyName");
77             }
78         }
79         catch(Exception JavaDoc e)
80         {
81             throw new JspTagException JavaDoc("ComponentLogic.getAssetUrl Error: " + e.getMessage());
82         }
83         
84         return EVAL_PAGE;
85     }
86
87     public void setAssetKey(String JavaDoc assetKey)
88     {
89         this.assetKey = assetKey;
90     }
91
92     public void setPropertyName(String JavaDoc propertyName) throws JspException JavaDoc
93     {
94         this.propertyName = evaluateString("assetUrl", "propertyName", propertyName);
95     }
96     
97     public void setUseInheritance(boolean useInheritance)
98     {
99         this.useInheritance = useInheritance;
100     }
101     
102     public void setContentId(String JavaDoc contentId) throws JspException JavaDoc
103     {
104         this.contentId = evaluateInteger("assetUrl", "contentId", contentId);
105     }
106 }
Popular Tags