1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 19 import org.compiere.util.*; 20 21 27 public class MClick extends X_W_Click 28 { 29 30 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 } 42 47 public MClick (Properties ctx, String TargetURL) 48 { 49 this (ctx, 0); 50 setTargetURL(TargetURL); 51 setW_ClickCount_ID(0); 52 } 54 55 public void setTargetURL(String TargetURL) 56 { 57 super.setTargetURL(TargetURL); 58 } 59 60 65 public void setW_ClickCount_ID (int W_ClickCount_ID) 66 { 67 if (W_ClickCount_ID != 0) 69 { 70 super.setW_ClickCount_ID (W_ClickCount_ID); 71 return; 72 } 73 String url = getTargetURL(); 75 if (url == null || url.length() == 0) 76 return; 77 String exactURL = url; 78 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 if (slash != -1) 91 url = url.substring(0, slash); 92 log.debug("setW_ClickCount_ID for " + exactURL + " - " + url); 93 String 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 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 } 137 138 139 } | Popular Tags |