Coverage Report - org.jtheque.core.managers.file.impl.XMLBackuper
 
Classes in this File Line Coverage Branch Coverage Complexity
XMLBackuper
0 %
0/14
0 %
0/4
1.333
 
 1  
 package org.jtheque.core.managers.file.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.file.IFileManager.XmlBackupVersion;
 21  
 import org.jtheque.core.managers.file.able.BackupWriter;
 22  
 import org.jtheque.core.managers.file.able.Backuper;
 23  
 import org.jtheque.core.managers.file.able.FileType;
 24  
 import org.jtheque.core.utils.file.XMLWriter;
 25  
 import org.jtheque.utils.bean.IntDate;
 26  
 import org.jtheque.utils.io.FileException;
 27  
 
 28  
 import java.io.File;
 29  
 import java.util.Collection;
 30  
 
 31  
 /**
 32  
  * A Backuper for the XML format.
 33  
  *
 34  
  * @author Baptiste Wicht
 35  
  */
 36  0
 public final class XMLBackuper implements Backuper {
 37  
     @Override
 38  
     public void backup(File file, Collection<BackupWriter> writers) throws FileException {
 39  0
         XMLWriter writer = new XMLWriter();
 40  
 
 41  0
         writeHeader(writer);
 42  
 
 43  0
         for (BackupWriter backupWriter : writers) {
 44  0
             backupWriter.write(writer);
 45  
         }
 46  
 
 47  0
         writer.write(file.getAbsolutePath());
 48  0
     }
 49  
 
 50  
     @Override
 51  
     public boolean canExportTo(FileType fileType) {
 52  0
         return fileType == FileType.XML;
 53  
     }
 54  
 
 55  
     /**
 56  
      * Write the header in the Document.
 57  
      *
 58  
      * @param writer The writer in which add the header.
 59  
      */
 60  
     private static void writeHeader(XMLWriter writer) {
 61  0
         writer.add("header");
 62  
 
 63  0
         writer.addOnly("date", Integer.toString(IntDate.today().intValue()));
 64  0
         writer.addOnly("file-version", Integer.toString(XmlBackupVersion.SECOND.ordinal()));
 65  0
         writer.addOnly("jtheque-version", Managers.getCore().getApplication().getVersion().getVersion());
 66  
 
 67  0
         writer.switchToParent();
 68  0
     }
 69  
 }