com.exadel.aem.toolkit.plugin.writers.PackageEntryWriter Maven / Gradle / Ivy
/*
* Licensed 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 com.exadel.aem.toolkit.plugin.writers;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.function.BiConsumer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import com.exadel.aem.toolkit.api.annotations.meta.Scopes;
import com.exadel.aem.toolkit.api.handlers.Source;
import com.exadel.aem.toolkit.api.handlers.Target;
import com.exadel.aem.toolkit.plugin.adapters.DomAdapter;
import com.exadel.aem.toolkit.plugin.handlers.Handlers;
import com.exadel.aem.toolkit.plugin.handlers.common.DomHandler;
import com.exadel.aem.toolkit.plugin.maven.PluginRuntime;
import com.exadel.aem.toolkit.plugin.sources.ComponentSource;
import com.exadel.aem.toolkit.plugin.targets.Targets;
import com.exadel.aem.toolkit.plugin.utils.DialogConstants;
/**
* Base class for routines that render XML files inside a component folder within an AEM package
*/
abstract class PackageEntryWriter {
private static final DomHandler DOM_HANDLER = new DomHandler();
/* -----------------------------
Class fields and constructors
----------------------------- */
private final Transformer transformer;
/**
* Basic constructor
* @param transformer {@code Transformer} instance used to serialize XML DOM document to an output stream
*/
PackageEntryWriter(Transformer transformer) {
this.transformer = transformer;
}
/* -----------------------
Common instance members
----------------------- */
/**
* Gets the scope associated with this {@code PackageEntryWriter} instance
* @return String value representing a valid scope
* @see com.exadel.aem.toolkit.api.annotations.meta.Scopes
*/
abstract String getScope();
/**
* Gets whether this {@link Source} representing a Java class is processable by this particular {@code
* PackageEntryWriter} implementation
* @param source The {@code Source} that refers to a class under consideration
* @return True or false
*/
abstract boolean canProcess(Source source);
/**
* Retrieves the {@link com.exadel.aem.toolkit.api.handlers.Handler} or handler chain associated with the current
* instance. The returned value is used for populating the {@code Target} artifact created by this package entry
* writer with data
* @return {@code BiConsumer} object representing the handler or handler chain
*/
BiConsumer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy