posts - 41, comments - 15, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          2014年6月24日

          有時候在客戶端使用svg畫圖,而在服務器端需要同樣的圖片,在服務器端重新畫一遍是非常費事的。這時候我們就可以利用已有的svg直接通過下面的類轉換成png格式。

          使用這個方法需要引用batic相關的包,maven pom文件如下:

          <!-- svg 生成png格式圖片  -->
          <dependency><groupId>batik</groupId><artifactId>batik-svggen</artifactId><version>1.6</version></dependency>        
          <dependency><groupId>batik</groupId><artifactId>batik-awt-util</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-bridge</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-css</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-dom</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-gvt</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-parser</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-script</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-svg-dom</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-transcoder</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-util</artifactId><version>1.6</version></dependency>
          <dependency><groupId>batik</groupId><artifactId>batik-xml</artifactId><version>1.6</version></dependency>
          <!-- 此處不能使用2.9.1版本,使用2.9.1生成png會失敗 -->
          <dependency><groupId>xerces</groupId><artifactId>xercesImpl</artifactId><version>2.5.0</version></dependency>
          <dependency><groupId>xml-apis</groupId><artifactId>xmlParserAPIs</artifactId><version>2.0.2</version></dependency>
          <dependency><groupId>org.axsl.org.w3c.dom.svg</groupId><artifactId>svg-dom-java</artifactId><version>1.1</version></dependency>
          <dependency><groupId>xml-apis</groupId>    <artifactId>xml-apis</artifactId><version>2.0.0</version></dependency>
          <dependency><groupId>org.w3c.css</groupId> <artifactId>sac</artifactId>    <version>1.3</version></dependency>
          <!-- svg 生成png格式圖片結束  -->
          package com.yhb.web.util;
          import java.io.ByteArrayInputStream;
          import java.io.File;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;
          import java.io.UnsupportedEncodingException;
          import java.net.URL;
          import org.apache.batik.transcoder.TranscoderException;
          import org.apache.batik.transcoder.TranscoderInput;
          import org.apache.batik.transcoder.TranscoderOutput;
          import org.apache.batik.transcoder.image.PNGTranscoder;
          public final class FileUtil {
          /** 
               *@Description: 將svg字符串轉換為png 
               *@Author: 
               *@param svgCode svg代碼 
               *@param pngFilePath  保存的路徑 
               *@throws IOException io異常 
               *@throws TranscoderException svg代碼異常 
              */  
          public static void convertToPng(String svgCode,String pngFilePath) throws IOException,TranscoderException{  
           
                  File file = new File (pngFilePath);  
            
                  FileOutputStream outputStream = null;  
                  try {  
                      file.createNewFile ();  
                      outputStream = new FileOutputStream (file);  
                      convertToPng (svgCode, outputStream);  
                  } finally {  
                      if (outputStream != null) {  
                          try {  
                              outputStream.close ();  
                          } catch (IOException e) {  
                              e.printStackTrace ();  
                          }  
                      }  
                  }  
              }  
          /** 
               *@Description: 將svgCode轉換成png文件,直接輸出到流中 
               *@param svgCode svg代碼 
               *@param outputStream 輸出流 
               *@throws TranscoderException 異常 
               *@throws IOException io異常 
               */  
              public static void convertToPng(String svgCode,OutputStream outputStream) throws TranscoderException,IOException{  
                  try {  
                  byte[] bytes = svgCode.getBytes ("UTF-8");  
                      PNGTranscoder t = new PNGTranscoder ();  
                      TranscoderInput input = new TranscoderInput (new ByteArrayInputStream (bytes));  
                      TranscoderOutput output = new TranscoderOutput (outputStream);  
                      t.transcode (input, output);  
                      outputStream.flush ();  
                  } finally {  
                      if (outputStream != null) {  
                          try {  
                              outputStream.close ();  
                          } catch (IOException e) {  
                              e.printStackTrace ();  
                          }  
                      }  
                  }  
              }  
          }

          posted @ 2015-10-19 15:17 yuhaibo736 閱讀(317) | 評論 (0)編輯 收藏

          方法1: 設定環境變量
          set NLS_SORT=SCHINESE_RADICAL_M ;export NLS_SORT (sh)
          or setenv NLS_SORT SCHINESE_RADICAL_M (csh)
          or regedit 
          HKLC/SOFTWARE/ORACLE/home0/NLS_SORT        (win)

          方法2: 在session中修改
          alter session set NLS_SORT='SCHINESE_RADICAL_M'

          方法3: 直接使用NLSSORT函數 (推薦)
          select name,id from t
          order by NLSSORT(name,'NLS_SORT = SCHINESE_STROKE_M')

          設置NLS_SORT值:

          SCHINESE_RADICAL_M 按照部首(第一順序)、筆劃(第二順序)排序 

          SCHINESE_STROKE_M 按照筆劃(第一順序)、部首(第二順序)排序 

          SCHINESE_PINYIN_M 按照拼音排序

          posted @ 2014-08-29 14:13 yuhaibo736 閱讀(1288) | 評論 (0)編輯 收藏

              在IBATIS中,框架內置了對OSCache的支持,如果我們想使用EHCache,則需要通過我們手工實現來完成二級緩存的功能機制。

              在mybatis中,開發組織只提供了一些默認的二級緩存實現的機制,并沒有直接內置的支持OSCache和EHCache等二級緩存機制,而是作為一個集成jar包來提供二級緩存的實現,在官方網站上我們可以找到mybatis-ehcache-1.0.1-bundle.zip,mybatis-oscache-1.0.1-bundle.zip等ehcache和oscache提供二級緩存的獨立工具包. 這里我就拿oscache在mybatis中的使用來舉例說明:

                 1.   將mybatis-oscache-1.0.1-bundle.zip中涉及到的jar包放入到classpath路徑下 
                       maven下可以這樣配置
                         <dependencies>  
                              
          ... 

                              <dependency> 

                                  <groupId>org.mybatis.caches</groupId> 

                                  <artifactId>mybatis-oscache</artifactId>      
                                   <version>1.0.2-SNAPSHOT</version> 

                              </dependency>             

                              <dependency>
                                  <groupId>javax.jms</groupId>
                                  <artifactId>jms</artifactId>
                                  <version>1.1</version>
                              </dependency>

                              <dependency>
                                   <groupId>opensymphony</groupId>
                                   <artifactId>oscache</artifactId>
                                   <version>2.4</version>
                                   <exclusions>       
                                         <exclusion>
                                             <groupId>com.sun.jdmk</groupId>
                                             <artifactId>jmxtools</artifactId>
                                         </exclusion>
                                     <exclusion>
                                     <groupId>com.sun.jmx</groupId>
                                     <artifactId>jmxri</artifactId>
                                 </exclusion>
                               </exclusions>
                          </dependency>

                              ... 

                          </dependencies>

                 2.   在mapper文件中的配置如下:

                       <mapper namespace="org.test.AuthMapper" >         

                           <cache  type="org.mybatis.caches.oscache.OSCache"/>

                       </mapper>
                      注意下面兩點
                       (a)在
          <select id="getAuth" parameterType="Map" resultType="Auth"  useCache="false">中使用useCache="false"或useCache="true"來決定是否使用二級緩存。    
                       (b)在增刪改中<insert id="insertAuth" parameterType="Auth"  flushCache="true">使用flushCache="true"或flushCache="flase"來決定對這些進行操作后清空該xml文件中所有查詢語句的二級緩存。 

                 3.  在src目錄下創建一個oscache.properties的屬性文件,在里面指定緩存的各種屬性的設置:
                       cache.memory=true             
                       cache.path=c:\\myapp\\cache
                       cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
                       cache.persistence.overflow.only=true
                       cache.capacity=100000

                      

          posted @ 2014-08-11 18:22 yuhaibo736 閱讀(2733) | 評論 (0)編輯 收藏

          import java.awt.Color;
          import java.io.FileOutputStream;

          import com.itextpdf.text.BaseColor;
          import com.itextpdf.text.Document;
          import com.itextpdf.text.Element;
          import com.itextpdf.text.Font;
          import com.itextpdf.text.PageSize;
          import com.itextpdf.text.Phrase;
          import com.itextpdf.text.Rectangle;
          import com.itextpdf.text.pdf.BaseFont;
          import com.itextpdf.text.pdf.PdfPCell;
          import com.itextpdf.text.pdf.PdfPTable;
          import com.itextpdf.text.pdf.PdfWriter;

          public class CellEvents {


           /**
            * @param args
            */
           public static void main(String[] args) {
            Object[] objArr = new Object[]{100,20,300};
            
            Document document = new Document(PageSize.A4.rotate(),50,50,50,50);
            try{
             //bfSongti = BaseFont.createFont("/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
             Font songtiSFivefont = new Font(BaseFont.createFont("/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 9f);//宋體小五號字
                   //設置存放位置
                   PdfWriter.getInstance(document, new FileOutputStream("D:/test.pdf"));
                   document.open();
           
                   PdfPTable table = new PdfPTable(5);
             table.setSpacingBefore(10f);
             table.getDefaultCell().setPadding(5);
             //HowbuyBorderPdfPTableEvent event = new HowbuyBorderPdfPTableEvent();
             //table.setTableEvent(event);
             //table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
             table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
             PdfPCell cellTitle = new PdfPCell(new Phrase("總資產\n(萬元)",songtiSFivefont));
             cellTitle.setBorderWidth(2f);
             cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
             cellTitle.setMinimumHeight(25);
             table.addCell(cellTitle);
           
             cellTitle = new PdfPCell(new Phrase(""));
             cellTitle.setBorder(Rectangle.NO_BORDER);
             cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cellTitle);
             
             cellTitle = new PdfPCell(new Phrase("當前收益\n(萬元)",songtiSFivefont));
             cellTitle.setBorderWidth(2f);
             cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cellTitle);
           
             cellTitle = new PdfPCell(new Phrase("",songtiSFivefont));
             cellTitle.setBorder(Rectangle.NO_BORDER);
             cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cellTitle);
             
             
             cellTitle = new PdfPCell(new Phrase("累計收益\n(萬元)",songtiSFivefont));
             cellTitle.setBorderWidth(2f);
             cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cellTitle);
             
             float[] widths2 = { 24.5f, 12.25f,24.5f,12.25f,24.5f};

             table.setWidths(widths2);
             
             table.setHorizontalAlignment(Element.ALIGN_LEFT);//
             table.setWidthPercentage(70);
             double zzc = objArr[0]==null ? 0:Double.parseDouble(objArr[0].toString());
             double dqsy = objArr[1]==null ? 0:Double.parseDouble(objArr[1].toString());
             double ljsy = objArr[2]==null ? 0:Double.parseDouble(objArr[2].toString());
             PdfPCell cell1 = new PdfPCell(new Phrase(String.valueOf(zzc),songtiSFivefont));
             cell1.setBorderWidth(2f);
             cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
             cell1.setMinimumHeight(20);
             table.addCell(cell1);
             
             cell1 = new PdfPCell(new Phrase("",songtiSFivefont));
             cell1.setBorder(Rectangle.NO_BORDER);
             cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cell1);
             
             cell1 = new PdfPCell(new Phrase(String.valueOf(dqsy),songtiSFivefont));
             cell1.setBorderWidth(2f);
             cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cell1);
             
             cell1 = new PdfPCell(new Phrase("",songtiSFivefont));
             cell1.setBorder(Rectangle.NO_BORDER);
             cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cell1);
             
             cell1 = new PdfPCell(new Phrase(String.valueOf(ljsy),songtiSFivefont));
             cell1.setBorderWidth(2f);
             cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
             cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
             table.addCell(cell1);
             document.add(table);
            }catch(Exception ex){
             ex.printStackTrace();
            }
                  document.close();

           }

          }

          posted @ 2014-06-24 16:27 yuhaibo736 閱讀(1466) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 龙川县| 稷山县| 本溪| 吴川市| 四会市| 玉田县| 周宁县| 哈巴河县| 益阳市| 临朐县| 石门县| 红河县| 泸水县| 噶尔县| 洛南县| 康定县| 潢川县| 偃师市| 民县| 大丰市| 英超| 阿鲁科尔沁旗| 登封市| 伊宁市| 漳州市| 繁峙县| 永顺县| 彰武县| 湘潭市| 怀仁县| 夏邑县| 阿克陶县| 广饶县| 台中县| 泰来县| 德格县| 庆阳市| 大兴区| 林西县| 辽阳市| 桦甸市|