All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.config.metadata.compile.ComponentCompiler Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.config.metadata.compile;

import net.n2oapp.framework.api.exception.N2oException;
import net.n2oapp.framework.api.metadata.Component;
import net.n2oapp.framework.api.metadata.SourceComponent;
import net.n2oapp.framework.api.metadata.aware.ExtensionAttributesAware;
import net.n2oapp.framework.api.metadata.compile.CompileContext;
import net.n2oapp.framework.api.metadata.compile.CompileProcessor;
import net.n2oapp.framework.api.metadata.compile.building.Placeholders;
import net.n2oapp.framework.config.util.StylesResolver;

import static net.n2oapp.framework.api.metadata.local.util.CompileUtil.castDefault;

/**
 * Сборка компонента
 */
public abstract class ComponentCompiler>
        implements BaseSourceCompiler {

    protected void compileComponent(D compiled, S source, C context, CompileProcessor p) {
        if (getSrcProperty() == null) {
            compiled.setSrc(source.getSrc());
        } else {
            compiled.setSrc(castDefault(source.getSrc(), () -> p.resolve(Placeholders.property(getSrcProperty()), String.class)));
        }
        if (compiled.getSrc() == null)
            throw new N2oException("component src is required");
        compiled.setClassName(source.getCssClass());
        compiled.setStyle(StylesResolver.resolveStyles(source.getStyle()));
        compiled.setProperties(p.mapAndResolveAttributes(source));
    }

    /**
     * Свойство содержащее React компонент по умолчанию
     */
    protected String getSrcProperty() {
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy