- 论坛徽章:
- 0
|
package com.wm.affnet.util;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.wm.affnet.dao.impl.BaseDao;
import com.wm.affnet.xml.Node;
import com.wm.affnet.xml.XmlDocument;
public class AffUtils {
public static Hashtable hashDelims;
public static Vector delimNames;
public static Hashtable hashOmniPages;
public static String strOmniBaseTag = " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \"; \n"
+ " var s_server=\"\"; \n"
+ " var s_channel=\"\"; \n"
+ " var s_campaign=\"\"; \n"
+ " var s_prop1=\"TBD\"; \n"
+ " var s_prop2=\"TBD\"; \n"
+ " var s_eVar9=\"TBD\"; \n"
+ " var s_eVar15=\"TBD\"; \n"
+ " //--> \n"
+ " \n"
+ " \n"
+ " \n" + " \n" + " \n"
+ " \n" + " ";
static {
hashDelims = new Hashtable();
hashDelims.put("CSV", ",");
hashDelims.put("TSV", " ");
hashDelims.put("PIPE", "|");
hashDelims.put("XML", "XML");
delimNames = new Vector();
delimNames.add("CSV");
delimNames.add("TSV");
delimNames.add("PIPE");
delimNames.add("XML");
hashOmniPages = new Hashtable();
hashOmniPages.put("aff_home.jsp", "Affiliate Home");
hashOmniPages.put("aff_benefits.jsp", "Affiliate Benefits");
hashOmniPages.put("aff_newsletter.jsp", "Affiliate Newsletters");
hashOmniPages.put("aff_faqs.jsp", "Affiliate FAQ");
hashOmniPages.put("aff_contactus.jsp", "Affiliate Contact Us");
hashOmniPages.put("aff_member_home.jsp", "Affiliate Member Home");
hashOmniPages.put("aff_banners.jsp", "Affiliate Get Banners");
hashOmniPages.put("aff_getdatafeeds.jsp", "Affiliate Get Data Feeds");
hashOmniPages.put("aff_custom_url.jsp", "Affiliate Create Link");
hashOmniPages.put("aff_manage_account.jsp", "Affiliate Manage Account");
hashOmniPages.put("aff_login.jsp", "Affiliate Sign In/Register");
hashOmniPages.put("aff_create_account.jsp", "Affiliate Create Account");
hashOmniPages.put("aff_custom_url_gl.jsp", "Affiliate Get Link");
hashOmniPages.put("aff_become_member.jsp", "Affiliate Join Now");
hashOmniPages.put("aff_rss.jsp", "Affiliate RSS Page");
}
public static String getDelim(String strFileFormat) {
return (String) hashDelims.get(strFileFormat);
}
public static String nvl(String x, String def) {
return (x == null ? def : x);
}
public static String nvl(String x) {
return (x == null ? "" : x).trim();
}
public static boolean isnull(String x) {
return ((x == null || x == "") ? true : false);
}
public static boolean isNull(String x) {
return ((nvl(x).length() == 0) ? true : false);
}
public static boolean isrequestnull(String x) {
return (x == null || x == "" || x == "null" ? true : false);
}
public static String iif(String param1, String param2, String param3, String param4) {
return (param1.equals(param2) ? param3 : param4);
}
public static String iif(boolean param1, boolean param2, String param3, String param4) {
return (param1 == param2 ? param3 : param4);
}
public static String iif(int param1, int param2, String param3, String param4) {
return (param1 == param2 ? param3 : param4);
}
public static boolean isValidEmail(String strEmail) {
Pattern p = Pattern.compile(Constants.EMAIL_REGEX);
// Match the given string with the pattern
Matcher m = p.matcher(strEmail);
// check whether match is found
return m.matches();
}
public static String getSelected(String strFeedValue, String strFeedType) {
return ("\"" + strFeedValue + "\" " + (strFeedValue.equals(strFeedType) ? "SELECTED" : ""));
}
public static String getNewsDate() {
return ((new java.util.Date()).toString());
}
public static boolean isAlphaNumeric(String strWord) {
Pattern p = Pattern.compile("^[\\w]+$");
// Match the given string with the pattern
Matcher m = p.matcher(strWord);
// check whether match is found
return m.matches();
}
public static boolean isUSPhone(String strPhone) {
Pattern p = Pattern.compile("^[0-9]{3}-[0-9]{3}-[0-9]{4}$");
Matcher m = p.matcher(strPhone);
return m.matches();
}
public static boolean isIntlPhone(String strPhone) {
Pattern p = Pattern.compile("^[0-9]{11,12}$");
Matcher m = p.matcher(strPhone);
return m.matches();
}
public static boolean isName(String strCharVal) {
return isRegEx("^[a-zA-Z
[url=file://\\-\\'\\.]*$]\\-\\'\\.]*$[/url]
", strCharVal);
}
public static boolean isAllChar(String strCharVal) {
Pattern p = Pattern.compile("^[a-zA-Z ]*$");
Matcher m = p.matcher(strCharVal);
return m.matches();
}
public static boolean isRegEx(String strRegEx, String strRegVal) {
Pattern p = Pattern.compile(strRegEx);
Matcher m = p.matcher(strRegVal);
return m.matches();
}
public static String getFileStamp() {
Calendar calendar = new GregorianCalendar();
Date date = calendar.getTime();
DateFormat format1 = new SimpleDateFormat("yyyyMMddhhmmss");
return format1.format(date);
}
public static void sendEmailMessage(String senderId, String subjectText, String emailText) {
SendEmail.messageSend(senderId, Constants.CONTACT_EMAIL_ALIAS, subjectText, emailText);
}
public static String getPageName(String strPageJsp) {
return AffUtils.nvl((String) hashOmniPages.get(strPageJsp));
}
public static String getOmnitureTag(String strPageName) {
return strOmniBaseTag.replaceFirst("", getPageName(strPageName));
}
/**
* @param:
* String p_str, String p_delim
* @content
* Transform String.
* If p_str is null,just need return " "; If p_str contains p_delim,just
* delete p_delim from p_str and add the new p_str into ""; any other
* case,just return p_str directly.
* @return
* It will return String value.
*/
public static String transformString(String p_str, String p_delim) {
if (p_str == null) {
return " ";
} else if (p_str.indexOf(p_delim) > 0) {
return "\"" + p_str.replace("\"", " ") + "\"";
} else {
return p_str;
}
}
/**
* Get a XML format file.
* The affiliate client can choose File Format XML from the jsp page
* It will return String value.
*/
public static String generateXml(ResultSet rs, String strFeedType) {
if (rs == null) {
return "";
}
XmlDocument document = new XmlDocument();
Node node = new Node("wmdatafeed");
node.setAttribute("feed", strFeedType);
try {
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
for (int i = 1; rs.next(); i++) {
Node product = new Node("product");
product.setAttribute("num", String.valueOf(i));
for (int j = 1; j ",">"));
}
product.addChild(child);
}
node.addChild(product);
}
document.addChild(node);
} catch (SQLException e) {
e.printStackTrace();
} finally{
BaseDao.closeResultSet(rs);
}
return document.toString();
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103458/showart_2032709.html |
|