Parse

package com.huaweisymantec.rmc.mail;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.huaweisymantec.rmc.core.dao.InfoDAO;
import com.huaweisymantec.rmc.core.domain.Info;


@Component
public class Parse {

private HibernateTemplate ht;

public HibernateTemplate getHt() {
return ht;
}
  @Resource
public void setHt(HibernateTemplate ht) {
this.ht = ht;
}

Examine examine=new Examine();

Examinee examinee=new Examinee();

public  void parse()
  {
 
  String s=null; 

  try
{
  File f=new File("C:\\youjian.txt");
  FileReader fr=new FileReader(f);
 
  BufferedReader br=new BufferedReader(fr);
  int i=0;
  int j=0;
  while((s=br.readLine())!=null)
  { 

  for(String in : s.split("\n"))
  {
 
   
       for(String regex : new String[]{":.*(.$)"})
      {
       
      i++;
    examinee.examine(in, regex,i);
   
  
      }
      
   
       for(String regex : new String[]{"[a-zA-Z]*(\\s*)[a-zA-Z]*(\\s*)[a-zA-Z]*:"})
      {
     
      j++;
    examine.examine(in, regex,j);
  
      }
  }

   }

  try
  {
   ht.save(examine.info);
 
/*    Configuration cfg = new AnnotationConfiguration();
    

     SessionFactory sf = cfg.configure().buildSessionFactory();
     Session session = sf.openSession();

     session.beginTransaction();
     session.save(examine.info);
     session.getTransaction().commit();

     session.close();
     sf.close(); 
  */
  }catch(Exception eee)
  {
  System.out.println("存入数据库时产生错误");
  eee.printStackTrace();
  }

 
  br.close();
  fr.close();
 
 
}catch(Exception e)
{
e.printStackTrace();
System.out.println("没有该文件");
}
  }



}

你可能感兴趣的:(DAO,Hibernate,orm,F#,J#)