blob: fe237756433f1ff5fff9171d593948f90996f613 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.distribution.packaging.impl.importer;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.distribution.component.impl.DistributionComponentConstants;
import org.apache.sling.distribution.component.impl.SettingsUtils;
import org.apache.sling.distribution.event.impl.DistributionEventFactory;
import org.apache.sling.distribution.common.DistributionException;
import org.apache.sling.distribution.packaging.DistributionPackage;
import org.apache.sling.distribution.packaging.impl.DistributionPackageImporter;
import org.apache.sling.distribution.packaging.DistributionPackageInfo;
import org.apache.sling.distribution.packaging.DistributionPackageBuilder;
/**
* OSGi configuration factory for {@link LocalDistributionPackageImporter}s.
*/
@Component(label = "Apache Sling Distribution Importer - Local Package Importer Factory",
metatype = true,
configurationFactory = true,
specVersion = "1.1",
policy = ConfigurationPolicy.REQUIRE)
@Service(value = DistributionPackageImporter.class)
@Property(name="webconsole.configurationFactory.nameHint", value="Importer name: {name}")
public class LocalDistributionPackageImporterFactory implements DistributionPackageImporter {
/**
* name of this importer.
*/
@Property(label = "Name", description = "The name of the importer.")
private static final String NAME = DistributionComponentConstants.PN_NAME;
@Property(name = "packageBuilder.target", label = "Package Builder", description = "The target reference for the DistributionPackageBuilder used to create distribution packages, " +
"e.g. use target=(name=...) to bind to services by name.", value = SettingsUtils.COMPONENT_NAME_DEFAULT)
@Reference(name = "packageBuilder")
private DistributionPackageBuilder packageBuilder;
@Reference
private DistributionEventFactory eventFactory;
private DistributionPackageImporter importer;
@Activate
public void activate(Map<String, Object> config) {
String name = PropertiesUtil.toString(config.get(NAME), null);
importer = new LocalDistributionPackageImporter(name, eventFactory, packageBuilder);
}
public void importPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionPackage distributionPackage) throws DistributionException {
importer.importPackage(resourceResolver, distributionPackage);
}
@Nonnull
public DistributionPackageInfo importStream(@Nonnull ResourceResolver resourceResolver, @Nonnull InputStream stream) throws DistributionException {
return importer.importStream(resourceResolver, stream);
}
}