in src/main/java/org/apache/sling/distribution/packaging/impl/importer/RepositoryDistributionPackageImporter.java [63:100]
public void importPackage(@NotNull ResourceResolver resourceResolver, @NotNull DistributionPackage distributionPackage) throws DistributionException {
Session session = null;
try {
session = authenticate();
int lastSlash = distributionPackage.getId().lastIndexOf('/');
String nodeName = Text.escape(lastSlash < 0 ? distributionPackage.getId() : distributionPackage.getId().substring(lastSlash + 1));
log.debug("importing package {} in {}", distributionPackage.getId(), nodeName);
if (session != null) {
Node addedNode = session.getNode(path).addNode(nodeName,
NodeType.NT_FILE);
Node contentNode = addedNode.addNode(JcrConstants.JCR_CONTENT, NodeType.NT_RESOURCE);
if (contentNode != null) {
InputStream inputStream = null;
try {
inputStream = distributionPackage.createInputStream();
contentNode.setProperty(JcrConstants.JCR_DATA, session.getValueFactory().createBinary(inputStream));
contentNode.setProperty("package.type", distributionPackage.getType());
session.save();
} finally {
IOUtils.closeQuietly(inputStream);
}
}
log.debug("package {} imported into the repository as node {} ",
distributionPackage.getId(), addedNode.getPath());
} else {
throw new Exception("could not get a Session to deliver package to the repository");
}
} catch (Exception e) {
throw new DistributionException(e);
} finally {
if (session != null) {
session.logout();
}
}
}