KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > wstore > InfoLinkTag


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.wstore;
15 import java.util.*;
16 import java.sql.*;
17 import javax.servlet.*;
18 import javax.servlet.http.*;
19 import javax.servlet.jsp.*;
20 import javax.servlet.jsp.tagext.*;
21
22 import org.apache.ecs.*;
23 import org.apache.ecs.xhtml.*;
24 import org.apache.log4j.Logger;
25
26 import org.compiere.www.*;
27
28 /**
29  * Info Links (Menu).
30  * Creates Invoice/Payment/Asset/AddressInfo/PaymentInfo Link
31  * <pre>
32  * <cws:infoLink/>
33  * </pre>
34  *
35  * @author Jorg Janke
36  * @version $Id: InfoLinkTag.java,v 1.12 2003/09/05 04:55:42 jjanke Exp $
37  */

38 public class InfoLinkTag extends TagSupport
39 {
40     /** Logger */
41     private Logger log = Logger.getLogger (getClass());
42     /** One Line */
43     private boolean m_oneLine = false;
44
45     /**
46      * Set to one line
47      * @param var Y or something else
48      */

49     public void setOneLine (String JavaDoc var)
50     {
51         m_oneLine = "Y".equals(var);
52     } // setOneLine
53

54     /**
55      * Start Tag
56      * @return SKIP_BODY
57      * @throws JspException
58      */

59     public int doStartTag() throws JspException
60     {
61         HttpSession session = pageContext.getSession();
62         Properties ctx = (Properties)session.getAttribute(JSPEnv.CONTEXT_NAME);
63         if (ctx == null)
64         {
65             HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
66             ctx = JSPEnv.getCtx(request);
67         }
68         WebUser wu = (WebUser)session.getAttribute(WebUser.NAME);
69         if (wu != null && wu.isLoggedIn())
70         {
71             if (ctx != null)
72             {
73                 Info info = (Info)session.getAttribute(Info.NAME);
74                 if (info == null || wu.getAD_User_ID() != info.getAD_User_ID())
75                     session.setAttribute (Info.NAME, new Info (ctx, wu.getC_BPartner_ID(), wu.getAD_User_ID()));
76             }
77
78             //
79
log.debug("doStartTag - WebUser exists - " + wu);
80             //
81
JspWriter out = pageContext.getOut();
82             HtmlCode html = new HtmlCode();
83             //
84
if (wu.isCustomer())
85                 menuCustomer(html);
86             if (wu.isSalesRep())
87                 menuSalesRep(html);
88             menuAll (html);
89             //
90
html.output(out);
91         }
92         else
93         {
94             log.debug ("doStartTag - no WebUser");
95             if (session.getAttribute(Info.NAME) == null)
96                 session.setAttribute (Info.NAME, Info.getGeneral());
97         }
98         return (SKIP_BODY);
99     } // doStartTag
100

101     /**
102      * Add Customer Links
103      * @param html code
104      */

105     private void menuCustomer (HtmlCode html)
106     {
107         //
108
nl (html, true); // ------------
109
// --- Assets
110
a a = new a ("assets.jsp");
111         a.setClass ("menuMain");
112         a.addElement ("My Assets");
113         html.addElement (a);
114         //
115
nl (html, false);
116         // --- Invoices
117
a = new a ("invoices.jsp");
118         a.setClass ("menuMain");
119         a.addElement ("My Invoices");
120         html.addElement (a);
121         //
122
nl (html, false);
123         // --- Payments
124
a = new a ("payments.jsp");
125         a.setClass ("menuMain");
126         a.addElement ("My Payments");
127         html.addElement (a);
128         //
129
nl (html, false);
130         // --- Orders
131
a = new a ("orders.jsp");
132         a.setClass ("menuMain");
133         a.addElement ("My Orders");
134         html.addElement (a);
135         //
136
nl (html, false);
137         // --- Shipments
138
a = new a ("shipments.jsp");
139         a.setClass ("menuMain");
140         a.addElement ("My Shipments");
141         html.addElement (a);
142         //
143
} // menuCustomer
144

145     /**
146      * Add Links for all
147      * @param html code
148      */

149     private void menuAll (HtmlCode html)
150     {
151         nl (html, true); // ------------
152
// --- Requests
153
a a = new a ("requests.jsp");
154         a.setClass ("menuMain");
155         a.addElement ("My Requests");
156         html.addElement (a);
157         //
158
nl (html, false);
159         // --- Interest Area
160
a = new a ("info.jsp");
161         a.setClass ("menuMain");
162         a.addElement ("Interest Area");
163         html.addElement (a);
164         // a.setClass("menuDetail");
165
} // menuAll
166

167     /**
168      * Add Links for Sales Reps
169      * @param html code
170      */

171     private void menuSalesRep (HtmlCode html)
172     {
173         nl (html, true); // ------------
174
// --- Assigned Requests
175
a a = new a ("requests_sr.jsp");
176         a.setClass ("menuMain");
177         a.addElement ("Assigned Requests");
178         html.addElement (a);
179         //
180
nl (html, false);
181         // --- Advertisements
182
a = new a ("advertisements.jsp");
183         a.setClass ("menuMain");
184         a.addElement ("Advertisement");
185         html.addElement (a);
186     } // menuAll
187

188
189     /**
190      * Add New Line / Break
191      * @param html code
192      * @param hr insert HR rather BR
193      */

194     private void nl (HtmlCode html, boolean hr)
195     {
196         if (m_oneLine)
197             html.addElement("&nbsp;- ");
198         else if (hr)
199             html.addElement(new hr("90%", "left"));
200         else
201             html.addElement(new br());
202     } // nl
203

204     /**
205      * End Tag
206      * @return EVAL_PAGE
207      * @throws JspException
208      */

209     public int doEndTag() throws JspException
210     {
211         return EVAL_PAGE;
212     } // doEndTag
213

214 } // InfoLinkTag
215
Popular Tags