KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MClick


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.model;
15
16 import java.util.*;
17 import java.sql.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Actual Click
23  *
24  * @author Jorg Janke
25  * @version $Id: MClick.java,v 1.2 2003/08/08 16:14:35 jjanke Exp $
26  */

27 public class MClick extends X_W_Click
28 {
29
30     /**
31      * Actual Click
32      * @param ctx context
33      * @param W_Click_ID ID
34      */

35     public MClick (Properties ctx, int W_Click_ID)
36     {
37         super (ctx, W_Click_ID);
38         if (W_Click_ID == 0)
39             setProcessed (false);
40     } // MClick
41

42     /**
43      * Actual Click
44      * @param ctx context
45      * @param TargetURL url
46      */

47     public MClick (Properties ctx, String JavaDoc TargetURL)
48     {
49         this (ctx, 0);
50         setTargetURL(TargetURL);
51         setW_ClickCount_ID(0);
52     } // MClick
53

54
55     public void setTargetURL(String JavaDoc TargetURL)
56     {
57         super.setTargetURL(TargetURL);
58     }
59
60     /**
61      * Set Click Count.
62      * Find it if id = 0
63      * @param W_ClickCount_ID id
64      */

65     public void setW_ClickCount_ID (int W_ClickCount_ID)
66     {
67         // specific id
68
if (W_ClickCount_ID != 0)
69         {
70             super.setW_ClickCount_ID (W_ClickCount_ID);
71             return;
72         }
73         // clean up url
74
String JavaDoc url = getTargetURL();
75         if (url == null || url.length() == 0)
76             return;
77         String JavaDoc exactURL = url;
78         // remove everything before first / .
79
if (url.startsWith("http://"))
80             url = url.substring(7);
81         int dot = url.indexOf('.');
82         int slash = url.indexOf('/');
83         while (dot > slash && slash != -1)
84         {
85             url = url.substring(slash+1);
86             dot = url.indexOf('.');
87             slash = url.indexOf('/');
88         }
89         // remove everything after /
90
if (slash != -1)
91             url = url.substring(0, slash);
92         log.debug("setW_ClickCount_ID for " + exactURL + " - " + url);
93         //
94
String JavaDoc sql = "SELECT W_ClickCount_ID, TargetURL FROM W_ClickCount WHERE TargetURL LIKE ?";
95         int exactW_ClickCount_ID = 0;
96         PreparedStatement pstmt = null;
97         try
98         {
99             pstmt = DB.prepareStatement(sql);
100             pstmt.setString(1, "%" + url + "%");
101             ResultSet rs = pstmt.executeQuery();
102             while (rs.next())
103             {
104                 W_ClickCount_ID = rs.getInt(1);
105                 if (exactURL.equals(rs.getString(2)))
106                     exactW_ClickCount_ID = W_ClickCount_ID;
107             }
108             rs.close();
109             pstmt.close();
110             pstmt = null;
111         }
112         catch (SQLException ex)
113         {
114             log.error("", ex);
115         }
116         try
117         {
118             if (pstmt != null)
119                 pstmt.close();
120         }
121         catch (SQLException ex1)
122         {
123         }
124         pstmt = null;
125         // Set Click Count
126
if (exactW_ClickCount_ID != 0)
127             W_ClickCount_ID = exactW_ClickCount_ID;
128         if (W_ClickCount_ID == 0)
129         {
130             log.warn ("setW_ClickCount_ID - not found for " + exactURL + " - " + url);
131             return;
132         }
133         setProcessed(true);
134         super.setW_ClickCount_ID (W_ClickCount_ID);
135     } // setW_ClickCount_ID
136

137
138
139 } // MClick
140
Popular Tags