com.enonic.xp.lib.schema.GetDynamicSiteHandler Maven / Gradle / Ivy
package com.enonic.xp.lib.schema;
import java.util.function.Supplier;
import com.enonic.xp.app.ApplicationKey;
import com.enonic.xp.lib.schema.mapper.SiteDescriptorMapper;
import com.enonic.xp.resource.DynamicSchemaResult;
import com.enonic.xp.resource.DynamicSchemaService;
import com.enonic.xp.script.bean.BeanContext;
import com.enonic.xp.script.bean.ScriptBean;
import com.enonic.xp.site.SiteDescriptor;
public final class GetDynamicSiteHandler
implements ScriptBean
{
private String application;
private Supplier dynamicSchemaServiceSupplier;
public void setApplication( final String application )
{
this.application = application;
}
public SiteDescriptorMapper execute()
{
final DynamicSchemaResult result =
dynamicSchemaServiceSupplier.get().getSite( ApplicationKey.from( this.application ) );
return result != null ? new SiteDescriptorMapper( result.getSchema(), result.getResource() ) : null;
}
@Override
public void initialize( final BeanContext context )
{
dynamicSchemaServiceSupplier = context.getService( DynamicSchemaService.class );
}
}