Allow initial config xml files to start with xml header. 73/4273/1
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 15 Jan 2014 15:35:34 +0000 (16:35 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Wed, 15 Jan 2014 15:35:34 +0000 (16:35 +0100)
E.g.

<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->

Change-Id: Ie6ce587d3d44b2b357b48616d0a596e332c65c98
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/config/config-persister-directory-autodetect-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/autodetect/FileType.java

index 03654eb..779a887 100644 (file)
@@ -23,6 +23,7 @@ enum FileType {
     plaintext, xml;
 
     public static final String XML_STORAGE_FIRST_LINE = "<" + ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME + ">";
+    private static final String XML_FILE_DEFINITION_LINE = "<?xml";
 
     static FileType getFileType(File file) {
         String firstLine = readFirstLine(file);
@@ -35,7 +36,10 @@ enum FileType {
     }
 
     private static boolean isXmlStorage(String firstLine) {
-        return firstLine.startsWith(XML_STORAGE_FIRST_LINE);
+        boolean isXml = false;
+        isXml |= firstLine.startsWith(XML_STORAGE_FIRST_LINE);
+        isXml |= firstLine.startsWith(XML_FILE_DEFINITION_LINE);
+        return isXml;
     }
 
     private static boolean isPlaintextStorage(String firstLine) {