星期三, 12月 07, 2011

[Alfresco] Lucene Search: Escaping special characters


今天測試開了特殊字元的帳號查看垃圾桶的檔案,在alfresco的web ui也爆炸了。
發現UID含特殊字元時,也要記得跳脫!!
you are using Lucene 1.4 or prior, there is no escape convenience utility. Instead, you must write your own. The characters that need to be escaped are: + - ! ( ) { } [ ] ^ " ~ * ? : \
Lucene 1.4 Escaping (More Complete)
// Some constants.
private static final String LUCENE_ESCAPE_CHARS = "[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\*\\?]";
private static final Pattern LUCENE_PATTERN = Pattern.compile(LUCENE_ESCAPE_CHARS);
private static final String REPLACEMENT_STRING = "\\\\$0";
 
// ... Then, in your code somewhere...
String userInput = // ...
String escaped = LUCENE_PATTERN.matcher(userInput).replaceAll(REPLACEMENT_STRING);
Query query = QueryParser.parse(escaped);
// ...


Reference:
Lucene: Escaping Special Characters

星期一, 12月 05, 2011

[Javascript] Characters to escape in JSON

 $("#exec").click(function(){
  var newPW = $("#newPW").val();
  console.log("old newPW:" + newPW);
  var testPW = 
  {
    test:newPW
  }
  //escape special charactors
  console.log("JSON.stringify:" + JSON.stringify(testPW));
 });
Reference:
Characters to escape in JSON

星期三, 11月 30, 2011

[Javascript] how to get local file path from fileinput using IE8 or IE9

http://stackoverflow.com/questions/5753442/how-can-i-get-the-local-filepath-from-the-fileinput-using-javascript-in-ie9



要達到這個效果需要IE用戶開啟二項設定:

  • ie8 and ie9 必需請用戶開啟允許使用ActiveXObject 

工具->網際網路選項->安全性->自訂等級->ActiveX控制項與外掛程式->將未標示成安全的ActiveX控制項初始化並執行指令碼設定為提示(安全性考量不要設為啟用)

  • ie9必需再設定允許上傳檔案存取本機路徑(不然file upload會顯示fakepath)
工具->網際網路選項->安全性->自訂等級->雜項->將檔案上傳到伺服器包括本機路徑設為啟用

星期六, 11月 26, 2011

星期四, 11月 24, 2011

Special Characters Supported for Passwords

Name of the CharacterCharacter
at sign@
percent sign%
plus sign+
backslash\
slash/
single quotation mark'
exclamation point!
number sign#
dollar sign$
caret^
question mark?
colon:
comma.
left parenthesis(
right parenthesis)
left brace{
right brace}
left bracket[
right bracket]
tilde~
grave accent
This character is also known as the backquote character.
The grave accent cannot be reproduced in this document.
hyphen-
underscore_

Reference:

星期日, 11月 20, 2011

URL decode/encode 觀念題

做網頁傳遞中文時常會用到URL decode/encode,
混亂的 URLEncode 說明了為什麼要使用URLEncode,
有興趣可以去讀一下。

[[Javascript 茶包筆記]] 小數點運算

JavaScript 要取到小數點下的指定位數,要四捨五入時有內建的toFixed()函數可使用,

例:
var num = new Number(13.3714);
document.write(num.toFixed());
document.write(num.toFixed(1));
document.write(num.toFixed(3));
document.write(num.toFixed(10));

結果:
13
13.4
13.371
13.3714000000

星期四, 11月 03, 2011

[Javascript] URL decode encode

使用Javascript來做URL編碼,請依需求來評估使用哪一種方法!!

Javascript escape, encodeURI, encodeURIComponent Encode後的結果,整理如下表:(請參考這裡)
文字類型英文數字中文Unescaped charactersReserved charactersScore
原始字串AZaz01堃-_.!~*'();,/?:@&=+$#
escape後AZaz01%u5803-_.%21%7E*%27%28%29%3B%2C/%3F%3A@%26%3D+%24%23
encodeURI後AZaz01%E5%A0%83-_.!~*'();,/?:@&=+$#
encodeURI
Component後
AZaz01%E5%A0%83-_.!~*'()%3B%2C%2F%3F%3A%40%26%3D%2B%24%2

星期三, 10月 19, 2011

[jQuery Plugin] jQuery File Upload FAQ

這篇主要記錄自已使用jQuery File Upload的一些問題,如果要基本的使用方法請參考這篇:


Q1: 上傳成功時發生Empty file upload result的情況
A1:V5 的伺服端接收上傳成功的訊息後,需回傳一個JSON Array,即時只有一個上傳檔案。例如:{["uploadfilename":"helloworld.jg"]}

Q2:使用Jsp無法順利jQuery樣版無法順利套用
A2:解法在這篇討論

Uploaded filename and size is not displayed in JSP???
The plugin template use the same syntax of Expression Language (EL) used by jsp and so ${name} and ${sizef} variables are evaluated in jsp and replaced with "" and "" . To avoid this you have to replace ${name} and ${sizef} with ${"${name}"} ${"${sizef}"}.

Q3: Firefox 4 fails when uploading empty file

 can confirm this issue with the basic File Upload plugin and Firefox 5.
However this seems to be a bug in the implementation of the FormData/XHR implementation of Firefox/Gecko.
Feel free to submit a bug report here: https://bugzilla.mozilla.org
IE跟Chrome上傳0KB檔案都是正常的。

Q4: How to cancel upload queues?
 $("#yourbutton").click(function (e) {
  //invoking a click event on all the upload row cancel buttons.
  $(".cancel button").click();
 });

星期二, 10月 04, 2011

[jQuery Plugin] jQuery Templates 樣版

由於AJAX技術愈來愈多人使用,搭配回傳的JSON格式產生UI已經是非常普遍的做法,
但如果搭配樣版的觀念來動態Bind資料,想必是更省事,最近使用的jQuery-File-Upload元件,
也使用樣版來產生UI。

以下是一些學習連結:
jQuery Templates Plugin筆記1by黑暗執行緒 

[JSP] JSP頁面引用bigd-5編碼的Javascript

想不到也有人遇到過同樣的問題XD~


Reference:[Tips] 在 utf-8 頁面 使用 big5 的 Javascript 檔之前在上線網站的時候, Clark 遇到在 utf-8 的網頁下要include big5 的 js 的問題,當時出現的問題是由於big5 的 js 檔中有中文字,include 到 utf-8 的 page 上時就造成 javascript error 或文字變成亂碼,當時趕著上線,所以就選擇將原來的 js 另存一份成為 utf-8 格式的 js 。就這樣使用了到現在將近一年,最近正在改這個 js 檔時發現為什麼不延用一份共用的 js ,而去另外自已建一份呢?一測試之下終於回想到當初的原因。由於在這陣子 Clark 也處理過類似問題,得到的結論是,在語法中下 charset="big5" 就可以讓 browser 不依照該 page 的 encoding 去做解譯,所以顯示的結果就正常了!

經過修改,顯示一切正常,其他Browser也沒有發現問題,上線!

星期一, 10月 03, 2011

[Tomcat] Linux系列關掉所有java程式後啟動tomcat流程

本篇記綠同事的流程XD

//首先砍掉所有運行的java程式
>pkill -9 java

//查詢java的程序還在不在,有的話會列process id。
>pgrep java

//使用替代pgrep java類似的指令
>ps aus | grep java

//開啟tomcat
>./startup.sh

星期一, 9月 26, 2011

[Java,Tomcat] 第一次使用DBCP就上手

本篇文章記錄安裝Tomcat的DBCP(Data Base Connection Pool)過程

測試環境:
Apache Tomcat/6.0.29
JVM1.6.0_21-b06
Connector/J 5.1.5 (the official JDBC Driver)mysql-connector-java-5.1.5-bin.jar

星期五, 9月 23, 2011

[jQuery plugin] jQuery Validator addMethod always return false

今天在做驗證帳號是否已存在的時遇到的問題。 當觸發驗證規則時,由於是非同步的呼叫,會造成Validator總是會回傳驗證失敗。 只要將jQuery 預設的ajax方法,多帶入async:false即可。


$.validator.addMethod( "conflictaccount" , function(value,element){ console.log("account:" + value); var isValidate = true; $.checkUserAccount( { async:false,//avoid value of return is false endpoint : HOSTNAME, ticket : TICKET, uid: value, callback:function(data){ if(data.verify){ //confilct account // console.log("confilct"); isValidate = false; }else{ // console.log("Not Conflict"); isValidate = true; } } }); // console.log("isValidate:" + isValidate); return isValidate; });

 註:$.checkUserAccount裡面是call $ajax的方法。

星期四, 9月 08, 2011

[Linux] Tomcat logs

Tip:/APP/TOMCAT安裝目錄

使用Putty查看Tomcat logs


1.進入logs directory
$cd /APP/TOMCAT/logs

2.監看logs
#持續刷新logs,缺點看的數量會被putty的視窗限制住
$tail -f catalina.out

or

#-n 加行數查看
$tail -n 1000 catalina.out

or

#加上grep搜尋
$tail -n 1000 catalina.out | grep 搜尋的字

清空所有Logs
$echo > catalina.out

其他你感興趣的文章

Related Posts with Thumbnails