Vikings

          2007年12月18日 #

          Dom4j的CDATA問(wèn)題與UTF-8字符集

           

          本文轉(zhuǎn)自:http://www.b9527.net/?q=node/1124
           
          原文如下:
           

          1. 寫入文件的格式

          寫入 Xml 文件的時(shí)候默認(rèn)是全部?jī)?nèi)容寫為一行,這個(gè)可以通過(guò)加入 Format 來(lái)解決:

          OutputFormat format = OutputFormat.createPrettyPrint();

          2. Xml 中文問(wèn)題

          2.1 Xml 最好設(shè)為 UTF-8 格式,

          format.setEncoding("utf-8");

          2.2 不要用 FileWriter 輸出雙字節(jié),改為 FileOutputStream 輸出單字節(jié):

          XMLWriter output = new XMLWriter(new FileOutputStream(configFile), format);

          3. CDATA類型文本輸入

          Element conTblOpr = rowElement.addElement(XmlDBConstants.CON_TBL_OPR);// 加入節(jié)點(diǎn)

          DefaultCDATA conTblOprCdata = new DefaultCDATA(conTblOprField);// CDATA格式化

          conTblOpr.add(conTblOprCdata );// 加入CDATA文本

          Dom4j 里面已經(jīng)內(nèi)置了對(duì) CDATA 類型文本的支持,不要硬編碼去在文本兩邊加<![CDATA[***]]>。

           

          posted @ 2011-07-05 00:12 Vikings 閱讀(2224) | 評(píng)論 (0)編輯 收藏

          實(shí)施WebService Security[WS-Security1.0]的Encrypt和Sign模式(XFire+WSS4J)

          轉(zhuǎn)自:
          http://www.aygfsteel.com/security/archive/2006/08/08/xfire_wss4j.html

          thanks for springside

          鑒于很多系統(tǒng)需要實(shí)施WS-Security的標(biāo)準(zhǔn),我們?cè)赟pringSide中提供了XFire+WSS4J的Demo,本文介紹SpringSide中Spring+XFire+WSS4J的基本配置

          [WebService Server端配置]
          第一,創(chuàng)建一個(gè)基本的BookService
          public interface BookService {
              
          /** *//**
               * 按書名模糊查詢圖書
               
          */

              List findBooksByName(String name);

              
          /** *//**
               * 查找目錄下的所有圖書
               *
               * 
          @param categoryId 如果category為null或“all”, 列出所有圖書。
               
          */

              List findBooksByCategory(String categoryId);

              
          /** *//**
               * 列出所有分類.
               *
               * 
          @return List<Category>,或是null。
               
          */

              List getAllCategorys();
          }
          第二,接口擴(kuò)展,即Extend基本的BookService,在XFire中,不同的WSS4J策略需要針對(duì)不同的ServiceClass,否則<inHandlers>里面的定義會(huì)Overlap。


             <!--BookService 基類-->
              
          <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
                  
          <property name="serviceFactory" ref="xfire.serviceFactory"/>
                  
          <property name="xfire" ref="xfire"/>
              
          </bean>

              
          <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                  
          <property name="mappings">
                      
          <value>
                          /BookService=bookService
                          /BookServiceWSS4J=bookServiceWSS4J
                          /BookServiceWSS4JEnc=bookServiceWSS4JEnc
                          /BookServiceWSS4JSign=bookServiceWSS4JSign
                      
          </value>
                  
          </property>
              
          </bean>

             
          <!--(1)BookWebService 不需要認(rèn)證-->
              
          <bean id="bookService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
                  
          <property name="serviceFactory" ref="xfire.serviceFactory"/>
                  
          <property name="xfire" ref="xfire"/>
                  
          <property name="serviceBean" ref="bookManager"/>
                  
          <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookService"/>
              
          </bean>

              
          <!--  (3)BookWebService 使用 WSS4J驗(yàn)證-->
              
          <bean id="bookServiceWSS4J" class="org.codehaus.xfire.spring.remoting.XFireExporter">
                  
          <property name="serviceBean" ref="bookManager"/>
                  
          <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4J"/>
                  
          <property name="inHandlers">
                      
          <list>
                          
          <ref bean="domInHandler"/>
                          
          <ref bean="wss4jInHandler"/>
                          
          <ref bean="validateUserTokenHandler"/>
                      
          </list>
                  
          </property>
              
          </bean>

              
          <bean id="domInHandler" class="org.codehaus.xfire.util.dom.DOMInHandler"/>

              
          <bean id="wss4jInHandler" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
                  
          <property name="properties">
                      
          <props>
                          
          <prop key="action">UsernameToken</prop>
                          
          <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
                      
          </props>
                  
          </property>
              
          </bean>

              
          <bean id="validateUserTokenHandler" class="org.springside.bookstore.plugins.xfire.wss4j.WSS4JTokenHandler"/>
              
              
          <!--  (4)BookWebService 使用 WSS4J驗(yàn)證 Encrypt模式-->
              
          <bean id="bookServiceWSS4JEnc" class="org.codehaus.xfire.spring.remoting.XFireExporter">
                  
          <property name="serviceBean" ref="bookManager"/>
                  
          <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4JEnc"/>
                  
          <property name="inHandlers">
                      
          <list>
                          
          <ref bean="domInHandler"/>
                          
          <ref bean="wss4jInHandlerEnc"/>
                          
          <ref bean="validateUserTokenHandler"/>
                      
          </list>
                  
          </property>
              
          </bean>
                  
              
          <bean id="wss4jInHandlerEnc" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
                  
          <property name="properties">
                    
          <props>
                      
          <prop key="action">Encrypt</prop>
                      
          <prop key="decryptionPropFile">org/springside/bookstore/plugins/xfire/wss4j/insecurity_enc.properties</prop>
                      
          <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
                    
          </props>
                  
          </property>
              
          </bean>
              
              
          <!--  (5)BookWebService 使用 WSS4J驗(yàn)證 Signature模式-->
              
          <bean id="bookServiceWSS4JSign" class="org.codehaus.xfire.spring.remoting.XFireExporter">
                  
          <property name="serviceBean" ref="bookManager"/>
                  
          <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4JSign"/>
                  
          <property name="inHandlers">
                      
          <list>
                          
          <ref bean="domInHandler"/>
                          
          <ref bean="wss4jInHandlerSign"/>
                          
          <ref bean="validateUserTokenHandler"/>
                      
          </list>
                  
          </property>
              
          </bean>
              
              
          <bean id="wss4jInHandlerSign" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
                  
          <property name="properties">
                    
          <props>
                      
          <prop key="action">Signature</prop>
                      
          <prop key="signaturePropFile">org/springside/bookstore/plugins/xfire/wss4j/insecurity_sign.properties</prop>
                      
          <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
                    
          </props>
                  
          </property>
              
          </bean>
              
          </beans>

          posted @ 2008-10-29 01:55 Vikings 閱讀(379) | 評(píng)論 (0)編輯 收藏

          簡(jiǎn)化spring中的事務(wù)管理配置(ZT)

          <!-- Transactional proxy for the services -->  
              
          <bean id="baseTxProxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">  
                  
          <property name="transactionManager"><ref bean="transactionManager"/></property>  
                  
          <property name="transactionAttributes">  
                      
          <props>  
                          
          <prop key="*">PROPAGATION_REQUIRED</prop>  
                      
          </props>  
                  
          </property>  
              
          </bean>  
            
              
          <bean id="itemService" parent="baseTxProxy">  
                  
          <property name="target">  
                      
          <bean class="ItemServiceImpl" autowire="byName"/>  
                  
          </property>  
              
          </bean>  
          這樣的話baseTxProxy也可能被實(shí)例化。是不是加上abstract="true"屬性,把baseTxProxy只是當(dāng)作一個(gè)模板比較好?因?yàn)橹恍枰猧temservice這個(gè)bean。

          posted @ 2008-08-07 00:12 Vikings 閱讀(300) | 評(píng)論 (0)編輯 收藏

          使用java.awt.RenderingHints類設(shè)置參數(shù),改善圖片質(zhì)量

           

          如果想設(shè)置幾個(gè)呈現(xiàn)提示(RenderingHints),可以多次調(diào)用setRenderHint,或者創(chuàng)建值的完整映射,并使用Graphics2D的setRenderingHints方法一次把它們都設(shè)置好。

          java.awt.RenderingHints類 javadoc文檔連接:
          http://gceclub.sun.com.cn/Java_Docs/jdk6/docs/zh/api/java/awt/RenderingHints.html

          一般使用的代碼如下:

          RenderingHints rh=new RenderingHints(RenderingHints. KEY_ANTIALIASING,
                                                                  RenderingHints. VALUE_ANTIALIAS_ON);
          rh.put(RenderingHints.KEY_STROKE_CONTROL
                        , RenderingHints.VALUE_STROKE_PURE);
          rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION
                        , RenderingHints.ALPHA_INTERPOLATION_QUALITY);
          g2d.setRenderingHints(rh);

          找出一個(gè)給定系統(tǒng)的方法是判斷特定的繪制硬件(比如顯卡)在系統(tǒng)中是否可用,假設(shè)有一個(gè)假想的isAccelerated方法告訴系統(tǒng)是否可以使用一種類型的圖像加速。下面的代碼允許根據(jù)isAccelerated方法的結(jié)果來(lái)設(shè)置提示:
          //假設(shè)renderQuality是RenderingHints的私有類成員
          if(isAccelerated()){
                 renderQuality
          =new RenderingHints(RenderingHints. KEY_RENDERING, 
                                                                         RenderingHints. VALUE_RENDER_QUALITY);
          }
          else{
                 renderQuality
          =new RenderingHints(RenderingHints. KEY_RENDERING, 
                                                                         RenderingHints. VALUE_RENDER_SPEED);
          }

          這樣設(shè)置后比沒(méi)有設(shè)置效果會(huì)好點(diǎn)。但是和acdsee等圖片工具看起來(lái)還有差距。比較奇怪還需要設(shè)置什么參數(shù)才能優(yōu)化圖片質(zhì)量。。。

          另外,關(guān)于性能今天看到的一篇文章有點(diǎn)作用。。
          現(xiàn)在圖片預(yù)覽一樣存在Jprofile的大量?jī)?nèi)存使用的問(wèn)題.
          看到j(luò)avatar的blog: http://javatar.javaeye.com/blog/41098
          提及使用第三方的包 JMagicK: http://www.yeo.id.au/jmagick/ (Java接口)
          生成圖片預(yù)覽的方法,因?yàn)槟壳绊?xiàng)目面臨上線的壓力如果改變另外一種實(shí)現(xiàn)方式等于是從根部重構(gòu),面臨測(cè)試的壓力。。

          posted @ 2008-07-11 16:11 Vikings 閱讀(4039) | 評(píng)論 (0)編輯 收藏

          501 port not allow after EPSV ALL, active mode off錯(cuò)誤

          用sun的ftp包連接IBM aix服務(wù)器拋如下錯(cuò)誤:
          501 port not allow after EPSV ALL, active mode off

          原因:
          ftp要改為被動(dòng)passtive模式.

          解決方法:
          使用第三方包edtftpj-1.5.1.jar連接服務(wù)器,在連接前設(shè)置模式為passtive

          Demo
          ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          package app4;
          /**
           * <p>Title: </p>
           *
           * <p>Description: </p>
           *
           * <p>Copyright: Copyright (c) 2006</p>
           *
           * <p>Company: </p>
           *
           * @author not attributable
           * @version 1.0
           */
          import com.enterprisedt.net.ftp.FTPClient;
          import com.enterprisedt.net.ftp.FTPMessageCollector;
          import com.enterprisedt.net.ftp.FTPTransferType;
          import com.enterprisedt.net.ftp.FTPConnectMode;
          import com.enterprisedt.util.debug.Level;
          import com.enterprisedt.util.debug.Logger;
          import java.util.Date;
          import java.io.File;
          public class Demo {
              /**
               *  Log stream
               */
              private static Logger log = Logger.getLogger(Demo.class);
              public static void main(String[] args) {
                  // we want remote host, user name and password
          //        if (args.length < 3) {
          //            usage();
          //            System.exit(1);
          //        }
                  // assign args to make it clear
                  String host = "localhost";//args[0];
                  String user = "lijun2";//args[1];
                  String password = "836301";//args[2];
                  Logger.setLevel(Level.ALL);
                  FTPClient ftp = null;
                  try {
                      // set up client
                      log.info("Connecting");
                      ftp = new FTPClient(host);
                      FTPMessageCollector listener = new FTPMessageCollector();
                      ftp.setMessageListener(listener);
                      // login
                      log.info("Logging in");
                      ftp.login(user, password);
                      // set up passive ASCII transfers
                      log.debug("Setting up passive, ASCII transfers");
                      ftp.setConnectMode(FTPConnectMode.PASV);
                      ftp.setType(FTPTransferType.BINARY);
                      // get directory and print it to console           
                      log.debug("Directory before put:");
                      String[] files = ftp.dir(".", true);
                      for (int i = 0; i < files.length; i++)
                          log.debug(files[i]);
                      // copy file to server
                      System.out.println(new Date());
                      log.info("Putting file");
                      File loadfile = new File("a.ISO");
                     
                      ftp.put("a.ISO", "a.ISO");
                     
                      System.out.println(new Date());
                      // get directory and print it to console           
                      log.debug("Directory after put");
                      files = ftp.dir(".", true);
                      for (int i = 0; i < files.length; i++)
                          log.debug(files[i]);
                      // copy file from server
                     // log.info("Getting file");
                     // ftp.get("2005.doc" + ".copy", "2005.doc");
                      // delete file from server
                      //log.info("Deleting file");
                     // ftp.delete("test.txt");
                      // get directory and print it to console           
                     // log.debug("Directory after delete");
                      files = ftp.dir("", true);
                      for (int i = 0; i < files.length; i++)
                          log.debug(files[i]);
                      // Shut down client               
                      log.info("Quitting client");
                      ftp.quit();
                      String messages = listener.getLog();
                      log.debug("Listener log:");
                      log.debug(messages);
                      log.info("Test complete");
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
              public static void usage() {
                  System.out.println("Usage: Demo remotehost user password");
              }
          }

          posted @ 2008-07-03 00:18 Vikings 閱讀(1987) | 評(píng)論 (0)編輯 收藏

          IE6下 SELECT 標(biāo)記 忽略 Z-index BUG

          Bug描述: SELECT elements ignore Z-index ("windowed element" problem)
          連接:http://www.throbs.net/web/articles/IE-SELECT-bugs/#ieZIndex

          問(wèn)題原因:
          1. select  html標(biāo)記在IE6下的解析不管Z-index
          2. div 不能遮蓋select,

          解決思路:
          1. 在select上用iframe遮蓋
          2. 在iframe上用div遮蓋
          3. iframe的width,height,top,left與div一樣大.


          示例代碼
          #zindexDiv{
          position:absolute;
          z-index:50;
          width:expression(this.nextSibling.offsetWidth);
          height:expression(this.nextSibling.offsetHeight);
          top:expression(this.nextSibling.offsetTop);
          left:expression(this.nextSibling.offsetLeft);
          /*background-color:green;?ff????????,????????????????*/
          }

          #divUp{
          z-index:99;
          position:absolute;
          background-color:red;
          width:100;
          height:18;
          overflow:hidden;
          height:60px;
          }

          #ddlTest{
          width:200;
          z-index:1;
          }
          </style>


          <body>
          <iframe id="zindexDiv" frameborder="0"></iframe>
          <div id="divUp">aaaaaaa<br>bbbbbbb<br>ccccccc</div>

          posted @ 2008-06-27 11:04 Vikings 閱讀(1861) | 評(píng)論 (0)編輯 收藏

          MAVEN相關(guān)工具下載地址


          eclipse 3.2.2 下載地址:http://archive.eclipse.org/eclipse/downloads/drops/R-3.2.2-200702121330/download.php?dropFile=eclipse-SDK-3.2.2-win32.zip

          MyEclipse Enterprise Workbench 5.5.1 GA for Windows 98/2000/NT/XP/Vista (05/21/2007)   下載地址:http://www.myeclipseide.com/Downloads-index-req-getit-lid-83.html

          Maven 2.0.8 下載地址:
          http://apache.mirror.phpchina.com/maven/binaries/apache-maven-2.0.8-bin.zip

          Maven2的Eclipse插件:
          http://m2eclipse.codehaus.orgupdate

          Eclipse插件教程視頻
          http://m2eclipse.codehaus.org/Maven_2.0_Plugin_for_Eclipse.swf

          mirror鏡象網(wǎng)址
          <repositories>
          <repository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://mirrors.redv.com/maven2</url>
          </repository>
          </repositories>

          <pluginRepositories>
          <pluginRepository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://mirrors.redv.com/maven2</url>
          </pluginRepository>
          </pluginRepositories>

           

          posted @ 2008-03-13 20:35 Vikings 閱讀(1779) | 評(píng)論 (0)編輯 收藏

          IE7 打印分頁(yè)時(shí)的css樣式分頁(yè)問(wèn)題

          IE6下用
          style="page-break-before: always"
          可以打印分頁(yè).

          IE7下不行.這句css不起作用
          需要加上這句css
           <!--[if IE 7]><br style="height:0; line-height:0"><![endif]-->

          全部的css
          <div style="page-break-before: always;">
             <!--[if IE 7]><br style="height:0; line-height:0"><![endif]-->
          </div>

          posted @ 2007-12-24 08:31 Vikings 閱讀(2218) | 評(píng)論 (1)編輯 收藏

          java.net.URL 打開(kāi)Google搜索報(bào)403錯(cuò)

          可能會(huì)遇到“java.io.IOException: Server returned HTTP response code: 403 for URL”的錯(cuò)誤信息。
          通常是因?yàn)榉?wù)器的安全設(shè)置不接受Java程序作為客戶端訪問(wèn),解決方案是設(shè)置客戶端的User Agent


          URL httpUrl = new URL(rssURL);
          改為
          URLConnection con = new URL(url).openConnection();
          con.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)");

          posted @ 2007-12-18 14:41 Vikings 閱讀(1366) | 評(píng)論 (1)編輯 收藏

          主站蜘蛛池模板: 乌拉特前旗| 长治市| 江永县| 湟中县| 玉环县| 新蔡县| 会同县| 丁青县| 临清市| 巧家县| 平度市| 呼玛县| 石河子市| 拉萨市| 铜山县| 玛纳斯县| 化州市| 宁国市| 古丈县| 城市| 平湖市| 洱源县| 区。| 武安市| 巴彦县| 西乡县| 密云县| 伊金霍洛旗| 新宁县| 昌都县| 桓仁| 尼玛县| 衡南县| 道孚县| 淅川县| 万载县| 通化县| 墨玉县| 蕉岭县| 铁岭市| 渝北区|