@Override public void replaceAll(Map<String, NamespaceProperties> map) { this.namespaceProperties = map; this.save(); }
@Override public boolean hasPermanentProperties(String namespace) { Map<String, NamespaceProperties> map = this.loadNamespacePropertiesFromFile(); return map.containsKey(namespace) && Objects.nonNull(map.get(namespace).getPrefix()) && !map.get(namespace).getPrefix().isEmpty(); }
localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
@Override public String getPrefix(String namespace) { return getNamespaceProperties(Objects.isNull(namespace) ? "" : namespace).getPrefix(); }
@NonNull public NamespaceProperties getNamespaceProperties(String namespace) { NamespaceProperties properties = this.namespaceProperties.get(namespace); if (Objects.isNull(properties)) { properties = new NamespaceProperties(namespace, generatePrefix(namespace)); } return properties; }
public JsonBasedNamespaceManager(File file) { Objects.requireNonNull(file); this.file = file; this.objectMapper = new ObjectMapper(); this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT); this.namespaceProperties = this.loadNamespacePropertiesFromFile(); this.namespaceProperties.put(Namespaces.TOSCA_NAMESPACE, new NamespaceProperties(Namespaces.TOSCA_NAMESPACE, "tosca", "Predefined TOSCA elements", "", false) ); this.namespaceProperties.put(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, new NamespaceProperties(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "winery", "TOSCA extension by Eclipse Winery", "", false) ); this.namespaceProperties.put(Namespaces.W3C_NAMESPACE_URI, new NamespaceProperties(Namespaces.W3C_NAMESPACE_URI, "xmlns", "W3C XML namespace", "", false) ); this.namespaceProperties.put(Namespaces.W3C_XML_SCHEMA_NS_URI, new NamespaceProperties(Namespaces.W3C_XML_SCHEMA_NS_URI, "xsd", "W3C XML schema namespace", "", false) ); this.namespaceProperties.put(Namespaces.EXAMPLE_NAMESPACE_URI, new NamespaceProperties(Namespaces.EXAMPLE_NAMESPACE_URI, "ex", "Namespace for creating examples", "", false) ); }
@Override public NamespaceManager getNamespaceManager() { NamespaceManager manager; RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId()); manager = new JsonBasedNamespaceManager(ref2AbsolutePath(ref).toFile()); Configuration configuration = this.getConfiguration(new NamespacesId()); if (!configuration.isEmpty()) { ConfigurationBasedNamespaceManager old = new ConfigurationBasedNamespaceManager(configuration); manager.replaceAll(old.getAllNamespaces()); try { forceDelete(BackendUtils.getRefOfConfiguration(new NamespacesId())); } catch (IOException e) { LOGGER.error("Could not remove old namespace configuration.", e); } } return manager; }
@Override public void clear() { this.namespaceProperties.clear(); this.save(); }
@Override public void removeNamespaceProperties(String namespace) { this.namespaceProperties.remove(namespace); this.save(); }
@Override public void setNamespaceProperties(String namespace, NamespaceProperties properties) { this.namespaceProperties.put(namespace, properties); this.save(); }
@Override public void addAllPermanent(Collection<NamespaceProperties> properties) { properties.forEach(prop -> this.namespaceProperties.put(prop.getNamespace(), prop)); this.save(); }