示例#1
0
  public static String getFooter(String context) {
    try {
      FileReader fileReader =
          new FileReader(findResourceOnFileSystem("servletResponseTemplate.htm"));
      BufferedReader buffread = new BufferedReader(fileReader);
      String templateFile = "", line;
      StringBuffer SBreader = new StringBuffer();
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line).append("\n");
      }
      fileReader.close();
      buffread.close();
      templateFile = SBreader.toString();
      templateFile =
          templateFile.replaceAll(
              "BOTTOMGRAPHIC", CommonConfiguration.getURLToFooterGraphic(context));

      int end_header = templateFile.indexOf("INSERT_HERE");
      return (templateFile.substring(end_header + 11));
    } catch (Exception e) {
      // out.println("I couldn't find the template file to read from.");
      e.printStackTrace();
      String error =
          "An error occurred while attempting to read from an HTML template file. This probably will not affect the success of the operation you were trying to perform.</p></body></html>";
      return error;
    }
  }
示例#2
0
  /**
   * Load the dcu ids from a file into a vector
   *
   * @param name The name of the file
   * @return The output vector
   */
  private static ArrayList<Integer> loadFile(String name)
      throws java.io.FileNotFoundException, java.io.IOException {
    File inputFile;
    FileReader in;
    int i;
    String s = "";
    int c;
    boolean stop;
    ArrayList<String> lines = new ArrayList<String>();
    ArrayList<Integer> v = new ArrayList<Integer>();

    in = new FileReader(name);
    stop = false;
    c = in.read();
    while (c != -1) {
      if (c != '\n') {
        s = s + (char) c;
      } else {
        if (!s.equals("")) lines.add(s);
        s = "";
      }
      c = in.read();
    }
    in.close();

    for (String line : lines) {
      String[] result = line.split(" ");
      v.add(Integer.parseInt(result[5]));
    }

    return v;
  }
示例#3
0
  // Loads a String of text from a specified file.
  // This is generally used to load an email template for automated emailing
  public static String getText(String fileName) {
    try {
      StringBuffer SBreader = new StringBuffer();
      String line;
      FileReader fileReader = new FileReader(findResourceOnFileSystem(fileName));

      BufferedReader buffread = new BufferedReader(fileReader);
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line + "\n");
      }
      line = SBreader.toString();
      fileReader.close();
      buffread.close();
      return line;
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    }
  }
  public String obtenerServer() {
    String server = "";
    File archivo = null;
    FileReader fr = null;
    BufferedReader br = null;

    try {
      // Apertura del fichero y creacion de BufferedReader para poder
      // hacer una lectura comoda (disponer del metodo readLine()).
      // archivo = new File ("C:\\rpt\\server.txt");
      archivo = new File(objUtils.HostSystem + "server.txt");
      fr = new FileReader(archivo);
      br = new BufferedReader(fr);

      // Lectura del fichero
      String linea;
      while ((linea = br.readLine()) != null) {
        server = linea.toString();
        // System.out.println(server);
      }
      return server;
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    } finally {
      // En el finally cerramos el fichero, para asegurarnos
      // que se cierra tanto si todo va bien como si salta
      // una excepcion.
      try {
        if (null != fr) {
          fr.close();
        }
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
  }
示例#5
0
  public static String getHeader(HttpServletRequest request) {
    try {
      FileReader fileReader =
          new FileReader(findResourceOnFileSystem("servletResponseTemplate.htm"));
      BufferedReader buffread = new BufferedReader(fileReader);
      String templateFile = "", line;
      StringBuffer SBreader = new StringBuffer();
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line).append("\n");
      }
      fileReader.close();
      buffread.close();
      templateFile = SBreader.toString();

      String context = getContext(request);

      // process the CSS string
      templateFile =
          templateFile.replaceAll(
              "CSSURL", CommonConfiguration.getCSSURLLocation(request, context));

      // set the top header graphic
      templateFile =
          templateFile.replaceAll(
              "TOPGRAPHIC", CommonConfiguration.getURLToMastheadGraphic(context));

      int end_header = templateFile.indexOf("INSERT_HERE");
      return (templateFile.substring(0, end_header));
    } catch (Exception e) {
      // out.println("I couldn't find the template file to read from.");
      e.printStackTrace();
      String error =
          "<html><body><p>An error occurred while attempting to read from the template file servletResponseTemplate.htm. This probably will not affect the success of the operation you were trying to perform.";
      return error;
    }
  }