Ejemplo n.º 1
0
 /**
  * Write Data to the existing XML File.
  *
  * @param filePath the path to the file to which the data needs to be written
  * @param actualData the actual data that needs to be written to the file.
  */
 @Override
 public void writeData(String filePath, Map<String, List<Map<String, Object>>> actualData) {
   try {
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setNamespaceAware(true);
     DocumentBuilder db = dbf.newDocumentBuilder();
     // File xml = new File(filePath);
     ResourceLoader resource = new ResourceLoader(filePath);
     Document document = db.parse(resource.getInputStream());
     Binder<Node> binder = getJAXBContext().createBinder();
     binder.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
     InputTestData testData = (InputTestData) binder.unmarshal(document);
     updateTestMethods(testData, actualData);
     binder.updateXML(testData);
     TransformerFactory tf = TransformerFactory.newInstance();
     Transformer t = tf.newTransformer();
     t.transform(new DOMSource(document), new StreamResult(resource.getFileOutputStream()));
   } catch (ParserConfigurationException e) {
     LOG.error(
         "Ignoring the write operation as ParserConfigurationException occured while parsing the file : "
             + filePath,
         e);
   } catch (SAXException e) {
     LOG.error(
         "Ignoring the write operation as SAXException occured while parsing the file : "
             + filePath,
         e);
   } catch (IOException e) {
     LOG.error(
         "Ignoring the write operation as IOException occured while parsing the file : "
             + filePath,
         e);
   } catch (JAXBException e) {
     LOG.error(
         "Ignoring the write operation as JAXBException occured while parsing the file : "
             + filePath,
         e);
   } catch (TransformerException e) {
     LOG.error(
         "Ignoring the write operation as TransformerException occured while parsing the file : "
             + filePath,
         e);
   }
 }