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 阅读(295) | 评论 (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 阅读(1271) | 评论 (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 阅读(2718) | 评论 (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 阅读(1446) | 评论 (0)编辑 收藏