+ protected Optional<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolder(final ConfigFileInfo c) {
+ try {
+ return Optional.of(new FeatureConfigSnapshotHolder(c, this));
+ } catch (final JAXBException e) {
+ LOG.warn("Unable to parse configuration snapshot. Config from '{}' will be IGNORED. " +
+ "Note that subsequent config files may fail due to this problem. " +
+ "Xml markup in this file needs to be fixed, for detailed information see enclosed exception.",
+ c.getFinalname(), e);
+ } catch (final XMLStreamException e) {
+ // Files that cannot be loaded are ignored as non config subsystem files e.g. jetty.xml
+ LOG.debug("Unable to read configuration file '{}'. Not a configuration snapshot",
+ c.getFinalname(), e);
+ }
+ return Optional.absent();
+ }
+
+ private static boolean isConfigSnapshot(String fileName) {
+ if(!Files.getFileExtension(fileName).equals(CONFIG_FILE_SUFFIX)) {
+ return false;
+ }
+
+ if(fileName.endsWith("jetty.xml")) {
+ // Special case - ignore the jetty.xml file as it contains a DTD and causes a "Connection refused"
+ // error when it tries to go out to the network to retrieve it. We don't want it trying to go out
+ // to the network nor do we want an error logged trying to parse it.
+ return false;
+ }
+
+ File file = new File(System.getProperty("karaf.home"), fileName);
+ try(FileInputStream fis = new FileInputStream(file)) {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ builderFactory.setNamespaceAware(true);
+ builderFactory.setCoalescing(true);
+ builderFactory.setIgnoringElementContentWhitespace(true);
+ builderFactory.setIgnoringComments(true);
+
+ Element root = builderFactory.newDocumentBuilder().parse(fis).getDocumentElement();
+ return ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME.equals(root.getLocalName());
+ } catch (Exception e) {
+ LOG.error("Could not parse XML file {}", file, e);
+ return false;
+ }
+ }
+