📄 skinutil.java
字号:
package org.ehotsoft.yekki.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;
import org.apache.ecs.html.Script;
public final class SkinUtil
{
/*private static final long SECOND = 1000L;
private static final long MINUTE = 60000L;
private static final long HOUR = 0x36ee80L;
private static final long DAY = 0x5265c00L;
private static final long WEEK = 0x240c8400L;
private static final int MAX_COOKIE_AGE = 0x49d400;
private static final String DAYS_OF_WEEK[] = {
"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "六"
};
private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("EEEE, MMM d 'at' h:mm a");
private static final SimpleDateFormat yesterdayFormatter = new SimpleDateFormat("'昨天' h:mm a");
private static final int ENCODE_XORMASK = 90;
private static final char ENCODE_DELIMETER = 2;
private static final char ENCODE_CHAR_OFFSET1 = 65;
private static final char ENCODE_CHAR_OFFSET2 = 104;
*/
private SkinUtil() {
}
/*
public static final String dateToText(Date date) {
if(date == null)
return "";
long l = System.currentTimeMillis() - date.getTime();
if(l / 0x36ee80L < 1L)
{
long l1 = l / 60000L;
if(l1 == 0L)
return "不到一分钟前";
if(l1 == 1L)
return "一分钟前";
else
return l1 + " 分钟以前";
}
if(l / 0x5265c00L < 1L)
{
long l2 = l / 0x36ee80L;
if(l2 <= 1L)
return "一小时以前";
else
return l2 + " 小时以前";
}
if(l / 0x240c8400L < 1L)
{
double d = (double)l / 86400000D;
if(d <= 1.0D)
return yesterdayFormatter.format(date);
else
return dateFormatter.format(date);
} else
{
return dateFormatter.format(date);
}
}
private static String[] decodePasswordCookie(String s)
{
if(s == null || s.length() <= 0)
return null;
char ac[] = s.toCharArray();
byte abyte0[] = new byte[ac.length / 2];
int j = 0;
int k = 0;
for(; j < abyte0.length; j++)
{
int i = ac[k++] - 65;
i |= ac[k++] - 104 << 4;
abyte0[j] = (byte)(i ^ 90 + j);
}
s = new String(abyte0);
int l = s.indexOf(2);
String s1 = l >= 0 ? s.substring(0, l) : "";
String s2 = l >= 0 ? s.substring(l + 1) : "";
return (new String[] {
s1, s2
});
}
private static String encodePasswordCookie(String s, String s1)
{
StringBuffer stringbuffer = new StringBuffer();
if(s != null && s1 != null)
{
byte abyte0[] = (s + '\002' + s1).getBytes();
for(int j = 0; j < abyte0.length; j++)
{
int i = abyte0[j] ^ 90 + j;
stringbuffer.append((char)(65 + (i & 0xf)));
stringbuffer.append((char)(104 + (i >> 4 & 0xf)));
}
}
return stringbuffer.toString();
}
public static final Cookie getCookie(HttpServletRequest httpservletrequest, String s)
{
Cookie acookie[] = httpservletrequest.getCookies();
if(acookie == null || s == null || s.length() == 0)
return null;
for(int i = 0; i < acookie.length; i++)
if(acookie[i].getName().equals(s))
return acookie[i];
return null;
}
public static final String getCookieValue(HttpServletRequest httpservletrequest, String s)
{
Cookie cookie = getCookie(httpservletrequest, s);
if(cookie != null)
return cookie.getValue();
else
return null;
}
public static final long getLastVisited(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
{
return getLastVisited(httpservletrequest, httpservletresponse, true);
}
public static final long getLastVisited(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, boolean flag)
{
HttpSession httpsession = httpservletrequest.getSession();
long l = System.currentTimeMillis();
String s = (String)httpsession.getValue("yekki_last_visited");
if(s != null)
try
{
long l1 = Long.parseLong(s);
Cookie cookie = new Cookie("yekki_last_visited", Long.toString(l));
cookie.setMaxAge(0x278d00);
cookie.setPath("/");
httpservletresponse.addCookie(cookie);
return l1;
}
catch(NumberFormatException numberformatexception)
{
numberformatexception.printStackTrace();
}
long l2 = l;
s = getCookieValue(httpservletrequest, "yekki_last_visited");
if(s != null)
try
{
l2 = Long.parseLong(s);
}
catch(NumberFormatException _ex) { }
httpsession.putValue("yekki_last_visited", Long.toString(l2));
Cookie cookie1 = new Cookie("yekki_last_visited", Long.toString(l));
cookie1.setMaxAge(0x278d00);
cookie1.setPath("/");
httpservletresponse.addCookie(cookie1);
return l2;
}
public static final void invalidateCookie(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s)
{
Cookie cookie = new Cookie(s, null);
cookie.setMaxAge(0);
cookie.setPath("/");
httpservletresponse.addCookie(cookie);
}
public static final String quoteOriginal(String s, String s1, int i)
{
if(s == null || s.length() == 0)
return "";
int j = s.length();
StringBuffer stringbuffer = new StringBuffer(s.length());
for(int k = 0; k < j;)
{
String s2 = StringUtil.chopAtWord(s.substring(k), i);
k += s2.length() + 1;
stringbuffer.append(s1).append(s2.trim()).append("\\n");
}
return stringbuffer.toString();
}
public static final void remove(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s)
{
HttpSession httpsession = httpservletrequest.getSession();
httpsession.removeValue(s);
Cookie cookie = new Cookie(s, null);
cookie.setMaxAge(0);
cookie.setPath("/");
httpservletresponse.addCookie(cookie);
}
public static final String retrieve(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s)
{
return retrieve(httpservletrequest, httpservletresponse, s, false);
}
public static final String retrieve(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, boolean flag)
{
HttpSession httpsession = httpservletrequest.getSession();
String s1 = (String)httpsession.getValue(s);
if(s1 == null)
s1 = getCookieValue(httpservletrequest, s);
if(flag)
remove(httpservletrequest, httpservletresponse, s);
return s1;
}
public static final void store(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1)
{
store(httpservletrequest, httpservletresponse, s, s1, 0, false);
}
public static final void store(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1, int i)
{
store(httpservletrequest, httpservletresponse, s, s1, i, false);
}
public static final void store(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1, int i, boolean flag)
{
if(s == null)
return;
HttpSession httpsession = httpservletrequest.getSession();
if((String)httpsession.getValue(s) != null && !flag)
return;
httpsession.putValue(s, s1);
if(i > 0)
{
Cookie cookie = new Cookie(s, s1);
cookie.setMaxAge(i);
cookie.setPath("/");
httpservletresponse.addCookie(cookie);
}
}
*/
public static final void alert( JspWriter out, String info, int step ) {
Script script = new Script();
script.addElement( "alert( '" + info + "' );" );
script.addElement( "history.go( " + step + " );" );
try {
out.println( script.toString() );
}
catch ( IOException e ) {
//ignore
}
}
public static final void alert( JspWriter out, String info ) {
alert( out, info, -1 );
}
public static final void redirect( JspWriter out, String info, String url ) {
Script script = new Script();
script.addElement( "alert( '" + info + "' );" );
script.addElement( "window.location = '" + url + "';" );
try {
out.println( script );
}
catch ( IOException e ) {
//ignore
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -