in src/main/java/org/apache/sling/feature/cpconverter/handlers/slinginitialcontent/BundleSlingInitialContentJarEntryExtractor.java [71:133]
void extractAndAddToAssembler(@NotNull BundleSlingInitialContentExtractContext context,
@NotNull SlingInitialContentBundleEntryMetaData slingInitialContentBundleEntryMetaData,
@NotNull Set<SlingInitialContentBundleEntryMetaData> collectedSlingInitialContentBundleEntries) throws IOException, ConverterException {
String repositoryPath = slingInitialContentBundleEntryMetaData.getRepositoryPath();
File file = slingInitialContentBundleEntryMetaData.getSourceFile();
PathEntry pathEntryValue = slingInitialContentBundleEntryMetaData.getPathEntry();
// all entry paths used by entry handlers start with "/"
String contentPackageEntryPath = SLASH + org.apache.jackrabbit.vault.util.Constants.ROOT_DIR + PlatformNameFormat.getPlatformPath(repositoryPath);
Path tmpDocViewInputFile = null;
try (InputStream bundleFileInputStream = new FileInputStream(file)) {
VaultPackageAssembler packageAssembler = assemblerProvider.initPackageAssemblerForPath(context, repositoryPath, pathEntryValue);
final ContentReader contentReader = contentReaderProvider.getContentReaderForEntry(file, pathEntryValue);
if (contentReader != null) {
// convert to docview xml
tmpDocViewInputFile = Files.createTempFile(context.getConverter().getTempDirectory().toPath(), "docview", ".xml");
try (OutputStream docViewOutput = Files.newOutputStream(tmpDocViewInputFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
repositoryPath = FilenameUtils.removeExtension(repositoryPath);
boolean isFileDescriptorEntry = isFileDescriptor(collectedSlingInitialContentBundleEntries, contentPackageEntryPath);
VaultContentXMLContentCreator contentCreator = new VaultContentXMLContentCreator(repositoryPath, docViewOutput, context.getNamespaceRegistry(), packageAssembler, isFileDescriptorEntry);
contentReader.parse(file.toURI().toURL(), contentCreator);
// finish is not always called through the ContentReader unfortunately
contentCreator.finish();
contentPackageEntryPath = contentCreator.getContentPackageEntryPath();
} catch (IOException e) {
throw new IOException("Can not parse " + file, e);
} catch (RepositoryException e) {
throw new IOException("Can not convert " + file + " to enhanced DocView format", e);
}
// remap CND files to make sure they are picked up by the NodeTypesEntryHandler
if (context.getNamespaceRegistry().getRegisteredCndSystemIds().contains(file.getName())) {
contentPackageEntryPath = "/META-INF/vault/" + Text.getName(file.getName()) + ".cnd";
}
}
try (Archive virtualArchive = SingleFileArchive.fromPathOrInputStream(tmpDocViewInputFile, bundleFileInputStream,
() -> Files.createTempFile(context.getConverter().getTempDirectory().toPath(), "initial-content", Text.getName(file.getName())), contentPackageEntryPath)) {
// in which content package should this end up?
if (tmpDocViewInputFile != null) {
packageAssembler.addEntry(contentPackageEntryPath, tmpDocViewInputFile.toFile());
} else {
packageAssembler.addEntry(contentPackageEntryPath, bundleFileInputStream);
}
parentFolderRepoInitHandler.addParentsForPath(contentPackageEntryPath);
}
} finally {
if (tmpDocViewInputFile != null) {
Files.delete(tmpDocViewInputFile);
}
}
}