Commit eb6007e157b2313f7d562fbe354fcf48305caa6c

Authored by gibran
1 parent 0049dc9e

Criação de nova classe TesteEseloProperties

src/main/java/br/com/ases/infra/TesteEseloProperties.java 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +package br.com.ases.infra;
  2 +
  3 +import java.io.BufferedReader;
  4 +import java.io.File;
  5 +import java.io.FileInputStream;
  6 +import java.io.FileNotFoundException;
  7 +import java.io.IOException;
  8 +import java.util.Properties;
  9 +
  10 +import javax.servlet.ServletContext;
  11 +
  12 +import java.io.FileReader;
  13 +
  14 +import br.com.caelum.vraptor.Resource;
  15 +import br.com.caelum.vraptor.ioc.ApplicationScoped;
  16 +
  17 +@Resource
  18 +@ApplicationScoped
  19 +public class TesteEseloProperties {
  20 + private static String PROPERTIES_PATH = "/WEB-INF/testeEselo.properties";
  21 + private static String path;
  22 + private Properties properties = new Properties();
  23 +
  24 + public TesteEseloProperties()
  25 + {
  26 +
  27 + }
  28 +
  29 + public TesteEseloProperties(ServletContext servletContext) {
  30 + try {
  31 + this.properties.load(servletContext.getResourceAsStream(PROPERTIES_PATH));
  32 + this.path = servletContext.getRealPath(PROPERTIES_PATH);
  33 + } catch (IOException e) {
  34 + e.printStackTrace();
  35 + }
  36 + }
  37 +
  38 + public BufferedReader getListaTesteEselo() {
  39 +
  40 + File arquivo = new File(path);
  41 +
  42 + BufferedReader reader = null;
  43 +
  44 + try {
  45 +
  46 + reader = new BufferedReader(new FileReader(arquivo));
  47 +
  48 + } catch (FileNotFoundException e) {
  49 + // TODO Auto-generated catch block
  50 + e.printStackTrace();
  51 + }
  52 +
  53 +
  54 + return reader;
  55 +
  56 + }
  57 +
  58 + public String getTesteEselo(String key) {
  59 +
  60 + return this.properties.getProperty(key);
  61 +
  62 + }
  63 +}
... ...