%@ page language="java" pageEncoding="utf-8"%>
<%@ page import = "com.dreye.idict.DLog" %>
<%@ page import = "java.net.URLDecoder" %>
<%@ page import = "java.net.URLEncoder" %>
<%@ page import = "com.dreye.idict.EntryWord" %>
<%@ page import = "com.dreye.idict.IDictService" %>
<%@ page import = "com.dreye.idict.Base64" %>
<%@ page import = "com.dreye.idict.Dict" %>
<%@ page import = "java.util.Hashtable" %>
<%
String reurl = "dict_en.jsp";
String webserver = "www.dreye.com";
String webpath = "/db/web"; // vicky, audio, 2006/9/12
/******************************************************************************/
// get input parameters from end user
int nType = 0;
String account = null, password = null;
String id, w, dod, ver, charset;
String title_e, title_v, title_s, title_p, title_n;
String nomatch, usererror;
String strHistory = "";
String qword = "";
boolean isFindWord = false;
String dictAU = null;
/******************************************************************************/
id = request.getParameter("id");
w = request.getParameter("w");
dod = request.getParameter("dod");
ver = request.getParameter("ver");
if(dod == null || "".equals(dod))
dod = "0103";
if(id == null)
id = "0";
if(w == null || "".equals(w))
w = "A";
charset = "gbk";
if(ver == null){
if("0102".equals(dod) || "0201".equals(dod))
ver = "big5";
else
ver = "gb";
}
response.setContentType("text/html;charset=" + charset);
try {
nType = Integer.parseInt(request.getParameter("type"));
}
catch(Exception e) {
nType = 0;
}
String clientIP = request.getRemoteAddr();
StringBuffer slog = new StringBuffer();
slog.append("[").append(clientIP).append("] ").append(request.getMethod()).append(" ").append(request.getRequestURI());
if(request.getQueryString() != null)
slog.append("?").append(new String(URLDecoder.decode(request.getQueryString()).getBytes("iso-8859-1"), charset));
DLog.log(slog.toString());
//Properties prop = MyResource.getInstance().getProperties();
title_e = "Explain";//prop.getProperty("dict."+ver+".title_e");
title_v = "Variation";//prop.getProperty("dict."+ver+".title_v");
title_s = "Synonym/Antonym";//prop.getProperty("dict."+ver+".title_s");
title_p = "Prev";//prop.getProperty("dict."+ver+".title_p");
title_n = "Next";//prop.getProperty("dict."+ver+".title_n");
nomatch = "No match WORD or unsupported CHARSET!";//prop.getProperty("dict."+ver+".nomatch");
usererror = "Invalid ACCOUNT or PASSWORD, Try again!";//prop.getProperty("dict."+ver+".usererror");
String referer = request.getHeader("referer");
String extra_domain = "yahoo";
boolean adFlag = true; // 登录过后显示广告
if(referer != null && referer.length() > 7) {
referer = referer.toLowerCase() + "/";
int pos = referer.indexOf("/", 7);
if(pos > 0) {
// host name & port
referer = referer.substring(7, pos);
if(referer.startsWith(webserver)) {
// local domain
account = "dreye"; password = "dreye4dict";
adFlag = false; // 第二次连接不再显示广告窗口
}else{
// special third partner domain
pos = referer.indexOf(":");
if(pos > 0)
referer = referer.substring(0, pos);
}
}
//out.println(referer);
}
{
// 首先通过登录获取用户信息
if(account == null || password == null) {
account = (String)request.getParameter("account");
password = (String)request.getParameter("password");
}
// 从session获得登录信息
if(account == null || password == null) {
account = (String)session.getAttribute("USER_ACCOUNT");
password = (String)session.getAttribute("USER_PASSWORD");
}
// 不是登录,则通过referer来获取用户信息
if(account == null || password == null) {
if(referer != null) {
// 通过referer得到可是用线上辞典服务的帐户信息
Dict dict = new Dict();
Hashtable ht = dict.getAccountByReferer(referer);
dict.closedb();
if(ht != null) {
account = (String)ht.get("account");
password = (String)ht.get("password");
}
}
}
if(account != null) {
// 特定第三方网址来的访问不显示广告窗口
if(account.equals(extra_domain))
adFlag = false;
}
}
if(account == null || password == null) {
// 显示登录窗口
%>
online dictionary - Dr.eye iDictionary
<%
}else{
session.setAttribute("USER_ACCOUNT", account);
session.setAttribute("USER_PASSWORD", password);
EntryWord ew = null;
IDictService ids = new IDictService();
boolean newUserFlag = true;
boolean newCookieFlag = true;
Cookie[] cookies1 = request.getCookies();
if(cookies1 != null) {
Cookie thisCookie;
for(int i = 0; i < cookies1.length; i++) {
thisCookie = cookies1[i];
if(thisCookie.getName().equals("cookie_user_enter")) {
newUserFlag = (new Boolean(thisCookie.getValue())).booleanValue();
}
else if(thisCookie.getName().equals("cookie_cookie_enter")) {
newCookieFlag = (new Boolean(thisCookie.getValue())).booleanValue();
}
}
}
if(newUserFlag) {
// set cookie, stat users for online dictionary service
Cookie cookie = new Cookie("cookie_user_enter", "false");
// available before user's browser closed
response.addCookie(cookie);
}
if(newCookieFlag) {
// set cookie, stat users for online dictionary service
Cookie cookie = new Cookie("cookie_cookie_enter", "false");
cookie.setMaxAge(60*60*24*30); // one month
response.addCookie(cookie);
}
ids.setUserStat(newUserFlag);
ids.setCookieStat(newCookieFlag);
w = new String(w.getBytes("iso-8859-1"), charset);
switch(nType) {
case 1:
ew = ids.getQueryById(account, password, id, dod, ver, reurl);
break;
case 3:
ew = ids.getVary(account, password, id, dod, ver, reurl);
break;
case 4:
ew = ids.getAntSynonym(account, password, id, dod, ver, reurl);
break;
default:
ew = ids.getQuery(account, password, w, dod, ver, reurl);
break;
}
StringBuffer contentBuf = new StringBuffer();
StringBuffer menusb = new StringBuffer();
if( ew != null && ew.getError() == 0 ) {
isFindWord = true;
qword = ew.getQueryedWord();
if (qword==null||"".equals(qword)){
qword = w;
}
contentBuf.append(new String(Base64.decode(ew.getContent()), "utf-8"));
contentBuf.append("
");
//----------------------------------------------------------------------menu
if(ew.getContentFlag().equals("EXPLAIN")) {
menusb.append("").append(title_e).append(" | | ");
}else {
menusb.append("")
.append(title_e).append(" | | ");
}
if(ew.getContentFlag().equals("VARY")) {
menusb.append("").append(title_v).append(" | | ");
}else if (ew.getVaryFlag()) {
menusb.append("")
.append(title_v).append(" | | ");
}else{
menusb.append("").append(title_v).append(" | | ");
}
if(ew.getContentFlag().equals("ANTSYNONYMS")) {
menusb.append("").append(title_s).append(" | | ");
}else if (ew.getSynonymsFlag()) {
menusb.append("")
.append(title_s).append(" | | ");
}else{
menusb.append("").append(title_s).append(" | | ");
}
if (ew.getPrevId() > 0){
menusb.append("")
.append(title_p).append(" | | ");
}else{
menusb.append("").append(title_p).append(" | | ");
}
if (ew.getNextId() > 0){
menusb.append("")
.append(title_n).append(" | | ");
}else{
menusb.append("").append(title_n).append(" | | ");
}
// vicky, audio, 2006/9/12 -- start
{
String ww = "", wx = "";
String vm, vx;
java.io.File vmFile, vxFile;
String w0 = qword.substring(0,1).toUpperCase();
String word = qword;
word = word.replaceAll("/", "+");
word = word.replaceAll("\"", "\'");
word = word.replaceAll(";", "+");
word = word.replaceAll("\\?", "~");
word = word.replaceAll(":", "+");
if ( !( (w0.charAt(0) >= 'A' && w0.charAt(0) <= 'Z') || (w0.charAt(0) >= 'a' && w0.charAt(0) <= 'z') ) ){
w0 = "0";
}
for(int i=0; i= 'A' && word.charAt(i) <= 'Z')
ww += "!";
ww += word.substring(i,i+1);
}
int pos = ww.indexOf("@");
if (pos > 0){
wx = ww.substring(0, pos);
}else{
wx = ww + "@1";
}
vm = "/dict/audio/" + w0 + "/" + ww + ".mp3";
vmFile = new java.io.File(webpath + vm);
vx = "/dict/audio/" + w0 + "/" + wx + ".mp3";
vxFile = new java.io.File(webpath + vx);
if (vmFile.exists()) dictAU = "http://"+webserver+vm;
else if(vxFile.exists()) dictAU = "http://"+webserver+vx;
//out.println(dictAU);
//dictAU = "e:\\ND\\WebRoot\\audio\\0\\3!G.mp3";
if(dictAU != null) {
menusb.append("")
.append("Voice").append(" | | ");
contentBuf.append("");
}else{
menusb.append("").append("Voice").append(" | | ");
}
}
// vicky, audio, 2006/9/12 -- end
String strIsCross = "0";
Cookie[] cookies = request.getCookies();
if (cookies!=null){
for (int i = 0; i < cookies.length; i++){
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("iscross")){
strIsCross = c.getValue();
break;
}
}
}
if (strIsCross!=null&&"1".equals(strIsCross)){
menusb.append("").append("Crossquery ON").append(" | | ");
}else{
menusb.append("").append("Crossquery OFF").append(" | | ");
}
//----------------------------------------------------------------------menu
}else if (ew != null && ew.getError() == 1){
qword = w;
session.removeAttribute("USER_ACCOUNT");
session.removeAttribute("USER_PASSWORD");
contentBuf.append("").append(usererror).append("
");
}else{
qword = w;
contentBuf.append("").append(nomatch).append("
");
}
//----------------------------------------------------------------write Cookie
Cookie[] cookies = request.getCookies();
String strDict = "";
String strID = "";
if (isFindWord){
strDict = ew.getDod();
strID = String.valueOf(ew.getWordId());
}
if (cookies==null){
if (isFindWord){
strHistory = qword+"~!"+strID+"~!"+strDict+"~!"+nType+"^#&";
}else{
strHistory = qword+"~!"+"0"+"~!"+strDict+"~!"+"9"+"^#&";
}
Cookie c_en = new Cookie("history_en",URLEncoder.encode(strHistory));
// Cookie c_en = new Cookie("history_en",URLEncoder.encode(new String(strHistory.getBytes(charset), "ISO-8859-1")));
c_en.setMaxAge(60*60*24*30);
response.addCookie(c_en);
}else{
boolean isExistCookie = false;
String strTemp = "";
for (int i = 0; i < cookies.length; i++){
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("history_en")){
isExistCookie = true;
strTemp = URLDecoder.decode(c.getValue());
// strTemp = new String(URLDecoder.decode(c.getValue()).getBytes(), charset);
break;
}
}
if (isExistCookie){
if (!isFindWord){
nType = 9;
strID = "0";
}
strHistory = qword+"~!"+strID+"~!"+strDict+"~!"+nType;
String strHistory2 = qword+"~!"+strID+"~!"+strDict+"~!";
if (nType==1){
strHistory2 = strHistory2 + 0;
}
if (nType==0){
strHistory2 = strHistory2 + 1;
}
String[] tempList = strTemp.split("\\^\\#\\&");
strTemp = "";
for (int i=0;i8){
strHistory = "";
for (int j=0;j<8;j++){
strHistory += historyList[j] + "^#&";
}
}
Cookie c_en = new Cookie("history_en",URLEncoder.encode(strHistory));
// Cookie c_en = new Cookie("history_en",URLEncoder.encode(new String(strHistory.getBytes(charset), "ISO-8859-1")));
c_en.setMaxAge(60*60*24*30);
response.addCookie(c_en);
}else{
if (isFindWord){
strHistory = qword+"~!"+strID+"~!"+strDict+"~!"+nType+"^#&";
}else{
strHistory = qword+"~!"+"0"+"~!"+strDict+"~!"+"9"+"^#&";
}
Cookie c_en = new Cookie("history_en",URLEncoder.encode(strHistory));
// Cookie c_en = new Cookie("history_en",URLEncoder.encode(new String(strHistory.getBytes(charset), "ISO-8859-1")));
c_en.setMaxAge(60*60*24*30);
response.addCookie(c_en);
}
}
//----------------------------------------------------------------write Cookie
//-----------------------------------------------------------------read Cookie
StringBuffer historysb = new StringBuffer();
if (strHistory!=null&&!"".equals(strHistory)){
String[] historyList = strHistory.split("\\^\\#\\&");
for (int j=0;j1");
strShowWord = strShowWord.replaceAll("@2","2");
strShowWord = strShowWord.replaceAll("@3","3");
strShowWord = strShowWord.replaceAll("@4","4");
strShowWord = strShowWord.replaceAll("@5","5");
if(strShowDict != null){
if("0201".equals(strShowDict))
strShowDict = "CHT-ENG";
else if("0102".equals(strShowDict))
strShowDict = "ENG-CHT";
else if("0301".equals(strShowDict))
strShowDict = "CHS-ENG";
else if("0103".equals(strShowDict))
strShowDict = "ENG-CHS";
}else{
strShowDict = "ENG-CHS";
}
if (strShowTip!=null&&"1".equals(strShowTip)){
strShowTip = title_e;
}else if (strShowTip!=null&&"3".equals(strShowTip)){
strShowTip = title_v;
}else if (strShowTip!=null&&"4".equals(strShowTip)){
strShowTip = title_s;
}else if (strShowTip!=null&&"0".equals(strShowTip)){
strShowTip = title_e;
}else if (strShowTip!=null&&"9".equals(strShowTip)){
strShowTip = "No match word";
strShowDict = "";
strShowClass = "font_history_nofound";
strShowSplit = "";
}else{
strShowTip = "No match word";
strShowDict = "";
strShowClass = "font_history_nofound";
strShowSplit = "";
}
String str1= wordList[0].replaceAll("'","\\\\'").replaceAll("\"","~");
historysb.append("| | ").append(strShowWord)
.append(" |
| | ").append(strShowDict).append(strShowSplit)
.append(strShowTip).append(" |
");
}
}else{
}
//-----------------------------------------------------------------read Cookie
//menu show
String strMenuDict = "ENG-CHS";
if(strDict != null){
if("0201".equals(strDict))
strMenuDict = "CHT-ENG";
else if("0102".equals(strDict))
strMenuDict = "ENG-CHT";
else if("0301".equals(strDict))
strMenuDict = "CHS-ENG";
else if("0103".equals(strDict))
strMenuDict = "ENG-CHS";
}
%>
Dreye.com
| |
| |
|
|
|
|
|
|
| |
<%=contentBuf.toString()%>
|
| |
| |
|
| |
<%=historysb.toString()%> |
| |
|
|
|
|
<%
}
%>