public static void storeTypes(Path path, String namespace, String id) { LOGGER.debug("Store type: {}", id); try { MediaType mediaType = MediaTypes.MEDIATYPE_XSD; TImport.Builder builder = new TImport.Builder(Namespaces.XML_NS); builder.setNamespace(namespace); builder.setLocation(id + ".xsd"); GenericImportId rid = new XSDImportId(namespace, id, false); TDefinitions definitions = BackendUtils.createWrapperDefinitions(rid); definitions.getImport().add(builder.build()); CsarImporter.storeDefinitions(rid, definitions); RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(rid); List<File> files = Files.list(path).filter(Files::isRegularFile) .map(Path::toFile).collect(Collectors.toList()); for (File file : files) { BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); RepositoryFileReference fileRef = new RepositoryFileReference(ref.getParent(), file.getName()); RepositoryFactory.getRepository().putContentToFile(fileRef, stream, mediaType); } } catch (IllegalArgumentException | IOException e) { throw new IllegalStateException(e); } }
/** * Finds out all imports belonging to the given namespace */ private Set<XSDImportId> getImportsOfNamespace(final Namespace namespace) { Objects.requireNonNull(namespace); // implemented using a straight-forward solution: get ALL XSD definitions and filter out the matching ones Set<XSDImportId> allImports = RepositoryFactory.getRepository().getAllDefinitionsChildIds(XSDImportId.class); return allImports.stream().filter(imp -> imp.getNamespace().equals(namespace)).collect(Collectors.toSet()); }
rid = new XSDImportId(namespace, id, false); } else { rid = new GenericImportId(namespace, id, false, type);
if (id.getNamespace().getDecoded().equals(item.getNamespace())) { result.add(item.getName());
if (element.getNamespaceURI().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) { ns = element.getAttribute("targetNamespace"); importId = new XSDImportId(ns, id, false); } else {
/** * @param getType true: XSConstants.TYPE_DEFINITION; false: XSConstants.ELEMENT_DECLARATION */ private List<NamespaceAndDefinedLocalNames> getAllXsdDefinitions(boolean getType) { MutableMultimap<Namespace, String> data = Multimaps.mutable.list.empty(); SortedSet<XSDImportId> allImports = RepositoryFactory.getRepository().getAllDefinitionsChildIds(XSDImportId.class); for (XSDImportId id : allImports) { final List<String> allDefinedLocalNames = getAllDefinedLocalNames(id, getType); data.putAll(id.getNamespace(), allDefinedLocalNames); } List<NamespaceAndDefinedLocalNames> result = Lists.mutable.empty(); data.forEachKeyMultiValues((namespace, strings) -> { final NamespaceAndDefinedLocalNames namespaceAndDefinedLocalNames = new NamespaceAndDefinedLocalNames(namespace); strings.forEach(localName -> namespaceAndDefinedLocalNames.addLocalName(localName)); result.add(namespaceAndDefinedLocalNames); }); return result; }
XSDImportId importId = new XSDImportId(winerysPropertiesDefinition.getNamespace(), elementName, false); try { RepositoryFactory.getRepository().forceDelete(importId);