Removed sonar warnings.
[controller.git] / opendaylight / config / config-persister-feature-adapter / src / main / java / org / opendaylight / controller / configpusherfeature / internal / FeatureConfigSnapshotHolder.java
index 1bce5f236414242c3523adbbebb5a551559d1fb1..70f736689577d6d7b3dbc655372d318873eec7d6 100644 (file)
@@ -20,6 +20,10 @@ import java.util.SortedSet;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
 import org.apache.karaf.features.ConfigFileInfo;
 import org.apache.karaf.features.Feature;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
@@ -36,13 +40,13 @@ import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigS
 public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
     private ConfigSnapshot unmarshalled = null;
     private ConfigFileInfo fileInfo = null;
-    private List<Feature> featureChain = new ArrayList<Feature>();
+    private List<Feature> featureChain = new ArrayList<>();
 
     /*
      * @param holder - FeatureConfigSnapshotHolder that we
      * @param feature - new
      */
-    public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder, final Feature feature) throws JAXBException {
+    public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder, final Feature feature) throws JAXBException, XMLStreamException {
         this(holder.fileInfo,holder.getFeature());
         this.featureChain.add(feature);
     }
@@ -53,16 +57,21 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
      * @param fileInfo - ConfigFileInfo to read into the ConfigSnapshot
      * @param feature - Feature the ConfigFileInfo was attached to
      */
-    public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo, final Feature feature) throws JAXBException {
+    public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo, final Feature feature) throws JAXBException, XMLStreamException {
         Preconditions.checkNotNull(fileInfo);
         Preconditions.checkNotNull(fileInfo.getFinalname());
         Preconditions.checkNotNull(feature);
         this.fileInfo = fileInfo;
         this.featureChain.add(feature);
+        // TODO extract utility method for umarshalling config snapshots
         JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
         Unmarshaller um = jaxbContext.createUnmarshaller();
-        File file = new File(fileInfo.getFinalname());
-        unmarshalled = ((ConfigSnapshot) um.unmarshal(file));
+        XMLInputFactory xif = XMLInputFactory.newFactory();
+        xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
+        xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
+
+        XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
+        unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
     }
     /*
      * (non-Javadoc)