Exemple #1
0
  /**
   * Load anual configuration xml file from disk and parse
   *
   * @return Anual configuration java bean
   * @throws CRUDException
   */
  public static UserConfiguration loadAnualConfigurationFromXML() throws CRUDException {
    FileReader fr = null;
    StringBuffer strBuffer = new StringBuffer();
    try {
      // Read from file
      File archivo = ConfigurationUtils.getAnualConfigurationFile();
      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(UserConfiguration.class);
      final UserConfiguration userRead =
          (UserConfiguration)
              jaxbContext.createUnmarshaller().unmarshal(new StringReader(strBuffer.toString()));
      return userRead;
    } catch (Exception e) {
      throw new CRUDException(e);
    } finally {
      if (fr != null)
        try {
          fr.close();
        } catch (IOException e) {
          throw new CRUDException(e);
        }
    }
  }
Exemple #2
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);
        }
    }
  }