use of org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager in project winery by eclipse.
the class CsarImporter method importNamespacePrefixes.
/**
* Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
* extracted using JAXB and stored in the NamespacesResource
*
* @param rootPath the root path of the extracted CSAR
*/
private void importNamespacePrefixes(Path rootPath) {
NamespaceManager namespaceManager = targetRepository.getNamespaceManager();
Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
Path json = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_JSON);
if (Files.exists(properties) || Files.exists(json)) {
NamespaceManager localNamespaceManager;
if (Files.exists(properties)) {
PropertiesConfiguration pconf = new PropertiesConfiguration();
try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) {
pconf.read(propertyReader);
localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf);
} catch (IOException | ConfigurationException e) {
CsarImporter.LOGGER.debug(e.getMessage(), e);
return;
}
} else {
localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
}
for (String s : localNamespaceManager.getAllNamespaces().keySet()) {
boolean addToStorage = false;
String namespace = s;
if (namespaceManager.hasPermanentProperties(namespace)) {
String storedPrefix = namespaceManager.getPrefix(namespace);
// QUICK HACK to check whether the prefix is a generated one
// We assume we know the internal generation routine
Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
if (m.matches()) {
// the stored prefix is a generated one
// replace it by the one stored in the exported properties
addToStorage = true;
}
} else {
addToStorage = true;
}
if (addToStorage) {
String prefix = localNamespaceManager.getPrefix(namespace);
namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
}
}
}
}
Aggregations