Ejemplo n.º 1
0
  /**
   * Load anual hours xml file from disk and parse
   *
   * @return AnualHours java bean
   * @throws CRUDException
   */
  public static AnualHours loadAnualHoursFromXML() throws CRUDException {
    StringBuffer strBuffer = new StringBuffer();
    FileReader fr = null;
    try {
      // Read from file
      File archivo = ConfigurationUtils.getInputHoursFile();
      fr = new FileReader(archivo);
      BufferedReader br = new BufferedReader(fr);
      String str;
      while ((str = br.readLine()) != null) strBuffer.append(str);

      // Parse the XML
      final JAXBContext jaxbContext = JAXBContext.newInstance(AnualHours.class);
      final AnualHours aHours =
          (AnualHours)
              jaxbContext.createUnmarshaller().unmarshal(new StringReader(strBuffer.toString()));
      return aHours;
    } catch (Exception e) {
      throw new CRUDException(e);
    } finally {
      if (fr != null)
        try {
          fr.close();
        } catch (IOException e) {
          throw new CRUDException(e);
        }
    }
  }
Ejemplo n.º 2
0
  /**
   * Persist the anual hours
   *
   * @param aHours anual hours java bean
   * @throws CRUDException
   */
  public static void saveAnualHours(AnualHours aHours) throws CRUDException {
    FileWriter fichero = null;
    try {
      // write it out as XML
      final JAXBContext jaxbContext = JAXBContext.newInstance(AnualHours.class);
      StringWriter writer = new StringWriter();
      jaxbContext.createMarshaller().marshal(aHours, writer);

      // Write to a file
      fichero = new FileWriter(ConfigurationUtils.getInputHoursFile());
      PrintWriter pw = new PrintWriter(fichero);
      pw.println(writer);
    } catch (Exception e) {
      throw new CRUDException(e);
    } finally {
      if (fichero != null)
        try {
          fichero.close();
        } catch (IOException e) {
          throw new CRUDException(e);
        }
    }
  }
Ejemplo n.º 3
0
  /**
   * Persist the anual hours
   *
   * @param anualConfig anual configuration java bean
   * @throws CRUDException
   */
  public static void saveAnualConfiguration(UserConfiguration anualConfig) throws CRUDException {
    JAXBContext jaxbContext;
    FileWriter fichero = null;
    try {
      jaxbContext = JAXBContext.newInstance(UserConfiguration.class);
      StringWriter writer = new StringWriter();
      jaxbContext.createMarshaller().marshal(anualConfig, writer);

      // Write to a file
      fichero = new FileWriter(ConfigurationUtils.getAnualConfigurationFile());
      PrintWriter pw = new PrintWriter(fichero);
      pw.println(writer);
    } catch (Exception e) {
      throw new CRUDException(e);
    } finally {
      if (fichero != null)
        try {
          fichero.close();
        } catch (IOException e) {
          throw new CRUDException(e);
        }
    }
  }