Google Code Prettify

2011年4月25日 星期一

讓Ext JS 2 支援IE9

增加下列語法即可

if (typeof Range.prototype.createContextualFragment == "undefined") {
Range.prototype.createContextualFragment = function(html) {
var doc = this.startContainer.ownerDocument;
var container = doc.createElement("div");
container
.innerHTML = html;
var frag = doc.createDocumentFragment(), n;
while ( (n = container.firstChild) ) {
frag
.appendChild(n);
}
return frag;
};
}

2011年3月9日 星期三

GraphicsMagick 安裝

GraphicsMagick 據說效能比 ImageMagick好,是ImageMagick的分支


./configure --with-quantum-depth=8 (8、16、32 數字越低,轉圖效率越高)
--with-gslib=yes
--disable-openmp (開閉OpenMP)
--enable-shared

顯示有缺套件時需自行安裝
yum install libjpeg libjpeg-devel zlib zlib-devel libpng libpng-devel bzip2 bzip2-devel lcms lcms-devel librsvg2 librsvg2-devel libxml2 libxml2-devel libtiff libtiff-devel libwmf libwmf-devel libXau libXau-devel

2011年3月7日 星期一

ImageMagick pdf to jpg

安裝 ImageMagick

安裝 ghostscript (PDF 額外套件),未安裝會出現 error/pdf.c/ReadPDFImage 錯誤
unix 環境
  1. ghostscript-8.70.tar.gz
  2. ghostscript-fonts-std-8.11.tar.gz 解壓縮到 /usr/local/share/ghostscript/fonts
windows 環境
  1. gs871w32.exe
  2. 設定path C:\Program Files\gs\gs8.71\bin
執行指令即可轉換檔案 convert -verbose 1.pdf 1.jpg

2010年5月21日 星期五

OpenOffice service

一般網路上的教學都是使用下列指令
soffice -headless -accept="socket,host=localhost,port=8100;urp;StarOffice.Service" -nofirststartwizard

但如果使用非管理者的帳號啟動上列指令,可能會發生部分目錄下的轉檔失敗。
可以改用下列指令啟動
soffice.bin -accept="socket,host=localhost,port=8100;urp;StarOffice.Service" -headless
-nofirststartwizard

2009年6月26日 星期五

Dynamic Web service client

//多個回傳參數用法

String wsdl = "http://localhost:8080/SOA-DO1/PortTypeBndPort?WSDL";

org.apache.axis.client.Service service = new org.apache.axis.client.Service();

Call call = service.createCall();
call.setTargetEndpointAddress(wsdl);
call.setOperationName(new QName("http://schemas.xmlsoap.org/wsdl/soap/","Add"));

//Input
call.addParameter( "machineid",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "passcode",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "uid",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "url",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "note",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.addParameter( "handle_time",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);

//Output
call.addParameter( "status",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "message",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "time",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);
call.addParameter( "sno",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.OUT);

call.setUseSOAPAction(true);
call.setSOAPActionURI("do1.soa.com/PortType/Add");

String machineid = "sdfs";
String passcode = "sdfsf";
String uid = "C123456789";
String url = "http://www.google.com.tw";
String note = "測試網站-新增測試";
String handle_time = "";


List list = new ArrayList();
list.add(machineid);
list.add(passcode);
list.add(uid);
list.add(url);
list.add(note);
list.add(handle_time);


Object [] inputParams = list.toArray();
List outputParams = new ArrayList();

//取得第一個回傳值
outputParams.add(call.invoke(inputParams));

//取得剩餘的回傳值
outputParams.addAll(call.getOutputValues());

for(int i=0;i<outputParams.size();i++){
      System.out.println(i+"="+outputParams.get(i));
}

2009年5月18日 星期一

fedora10 安裝PostgreSQL8.3.7

建立群組與使用者

     groupadd postgres
     useradd -g postgres postgres

安裝RPM source安裝方式可參考這裡

     rpm --import http://yum.pgsqlrpms.org/RPM-GPG-KEY-PGDG

     rpm -ivh postgresql-libs-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-debuginfo-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-docs-8.3.7-1PGDG.fc10.i386.rpm

     rpm -ivh postgresql-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-devel-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-server-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-plperl-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-plpython-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh postgresql-test-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh uuid-1.6.1-3.fc9.i386.rpm
     rpm -ivh uuid-pgsql-1.6.1-3.fc9.i386.rpm
     rpm -ivh postgresql-contrib-8.3.7-1PGDG.fc10.i386.rpm
     rpm -ivh tcl-8.5.3-1.fc10.i386.rpm
     rpm -ivh postgresql-pltcl-8.3.7-1PGDG.fc10.i386.rpm

---------------------------------------------------------------------------
初始化DB

     service postgresql initdb -D /var/lib/pgsql/data -E UTF-8 --locale=zh_TW

修改設定檔

     cd /var/lib/pgsql/data

     vi postgresql.conf

          listen_addresses = '*'
           port=5432

     vi pg_hba.conf

          host all all 192.168.0.0/16 trust


修改iptables,開放5432 port連線
     vi /etc/sysconfig/iptables

           -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
     service iptables restart

     service postgresql start
     ps auxww | grep ^postgres


設定開機時啟動

     chkconfig postgresql on

Spring MultiActionController 也能應用在檔案下載功能

public ModelAndView download(HttpServletRequest req, HttpServletResponse res) throws Exception {
     String sno = req.getParameter("abc");

     try{
          List list = dao.Select("select * from abc_file where abc="+abc);
          if(list.size() != 0){
               Map map = (Map) list.get(0);
               String file_name = map.get("file_name")==null?"":(String)map.get("file_name");
               Long file_size = map.get("file_size")==null?Long.valueOf(0):(Long)map.get("file_size");
               byte[] file_contents = (byte[]) map.get("file_contents");
               String content_type = map.get("content_type")==null?"":(String)map.get("content_type");

               String agent = req.getHeader("User-Agent");

               res.reset();

               if(agent.indexOf("MSIE") != -1){
                    file_name = URLEncoder.encode(file_name,"UTF8");
               }else{
                    file_name = new String(file_name.getBytes("UTF-8"),"ISO8859-1");
               }

               res.setHeader("Content-disposition","attachment; filename="+file_name);
               res.setContentLength(file_size.intValue());
               res.setContentType(content_type);

               BufferedOutputStream ou = new BufferedOutputStream(res.getOutputStream());
               ou.write(file_contents);
               ou.flush();
               ou.close();
          }

     } catch ( Exception e ) {
          logger.error(e);
          throw e;
     }

     return null;
}