X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-feature-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfigpusherfeature%2Finternal%2FFeatureConfigSnapshotHolder.java;h=7107cc994de7dd892ae9d362661bf011678f77bc;hp=5ab5c959f7fcd02d7742866fc35e3a37d6bf3152;hb=46306a374d717b1579987bd678f880e6f61f72e7;hpb=5448d6812e386bd56aec7209c4852c586a6163b3 diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java index 5ab5c959f7..7107cc994d 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java @@ -7,27 +7,28 @@ */ package org.opendaylight.controller.configpusherfeature.internal; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; 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; import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigSnapshot; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - /* * A ConfigSnapshotHolder that can track all the additional information * relavent to the fact we are getting these from a Feature. @@ -39,13 +40,13 @@ import com.google.common.collect.Lists; public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { private ConfigSnapshot unmarshalled = null; private ConfigFileInfo fileInfo = null; - private List featureChain = new ArrayList(); + private List 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); } @@ -56,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) @@ -87,7 +93,7 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { * We really care most about the underlying ConfigShapshot, so compute equality on that */ @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; }