Search in sources :

Example 1 with TailorConfiguration

use of org.springframework.roo.addon.tailor.config.TailorConfiguration in project spring-roo by spring-projects.

the class TailorParser method mapXmlToTailorConfiguration.

/**
 * Maps the XML file contents to a TailorConfiguration object. It is
 * possible to have multiple configurations in tailor.xml
 *
 * @param root
 * @return list of tailor configurations
 */
public static List<TailorConfiguration> mapXmlToTailorConfiguration(final Element root) {
    final List<Element> elTailors = XmlUtils.findElements("/tailorconfiguration/tailor", root);
    if (elTailors.isEmpty()) {
        logTailorXMLInvalid("no <tailor> definitions found in <tailorconfiguration> root element");
        return null;
    }
    final List<TailorConfiguration> configs = new ArrayList<TailorConfiguration>();
    for (final Element eTailor : elTailors) {
        final TailorConfiguration config = parseTailorConfiguration(eTailor);
        if (config != null) {
            configs.add(config);
        }
    }
    return configs;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) TailorConfiguration(org.springframework.roo.addon.tailor.config.TailorConfiguration)

Example 2 with TailorConfiguration

use of org.springframework.roo.addon.tailor.config.TailorConfiguration in project spring-roo by spring-projects.

the class TailorParser method parseTailorConfiguration.

/**
 * Maps the single XML tailor configuration to a TailorConfiguration object.
 *
 * @param tailor element
 * @return tailor configurations
 */
public static TailorConfiguration parseTailorConfiguration(final Element elTailor) {
    if (StringUtils.isBlank(elTailor.getAttribute("name"))) {
        logTailorXMLInvalid("<tailor> must have a name attribute");
        return null;
    }
    final TailorConfiguration result = new TailorConfiguration(elTailor.getAttribute("name"), elTailor.getAttribute("description"));
    final String activeAttribute = elTailor.getAttribute("activate");
    if (StringUtils.isNotBlank(activeAttribute)) {
        final boolean isActive = "true".equalsIgnoreCase(activeAttribute) || "yes".equalsIgnoreCase(activeAttribute);
        result.setActive(isActive);
    }
    final List<Element> elConfigs = XmlUtils.findElements("config", elTailor);
    if (elConfigs.isEmpty()) {
        logTailorXMLInvalid("<tailor> must have <config> child elements");
        return null;
    }
    for (final Element elConfig : elConfigs) {
        final String command = elConfig.getAttribute("command");
        if (StringUtils.isBlank(command)) {
            logTailorXMLInvalid("found <config> without command attribute");
            return null;
        }
        final CommandConfiguration newCmdConfig = new CommandConfiguration();
        newCmdConfig.setCommandName(command);
        final List<Element> elActions = XmlUtils.findElements("action", elConfig);
        for (final Element elAction : elActions) {
            // Determine the action type
            if (StringUtils.isBlank(elAction.getAttribute("type"))) {
                logTailorXMLInvalid("found <action> without type attribute");
                return null;
            }
            final ActionConfig newAction = new ActionConfig(elAction.getAttribute("type"));
            final NamedNodeMap attributes = elAction.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                final Node item = attributes.item(i);
                final String attributeKey = item.getNodeName();
                if (!"type".equals(attributeKey)) {
                    newAction.setAttribute(attributeKey, item.getNodeValue());
                }
            }
            newCmdConfig.addAction(newAction);
        }
        result.addCommandConfig(newCmdConfig);
    }
    return result;
}
Also used : ActionConfig(org.springframework.roo.addon.tailor.actions.ActionConfig) NamedNodeMap(org.w3c.dom.NamedNodeMap) CommandConfiguration(org.springframework.roo.addon.tailor.config.CommandConfiguration) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) TailorConfiguration(org.springframework.roo.addon.tailor.config.TailorConfiguration)

Example 3 with TailorConfiguration

use of org.springframework.roo.addon.tailor.config.TailorConfiguration in project spring-roo by spring-projects.

the class DefaultTailorImpl method execute.

private void execute(final CommandTransformation commandTrafo) {
    final TailorConfiguration configuration = configLocator.getActiveTailorConfiguration();
    if (configuration == null) {
        return;
    }
    final CommandConfiguration commandConfig = configuration.getCommandConfigFor(commandTrafo.getInputCommand());
    if (commandConfig == null) {
        return;
    }
    logInDevelopmentMode(Level.INFO, "Tailor: detected " + commandTrafo.getInputCommand());
    for (final ActionConfig config : commandConfig.getActions()) {
        final Action component = actionLocator.getAction(config.getActionTypeId());
        if (component != null) {
            logInDevelopmentMode(Level.INFO, "\tTailoring: " + component.getDescription(config));
            component.execute(commandTrafo, config);
        } else {
            logInDevelopmentMode(Level.WARNING, "\tTailoring: Couldn't find action '" + config.getActionTypeId());
        }
    }
}
Also used : ActionConfig(org.springframework.roo.addon.tailor.actions.ActionConfig) Action(org.springframework.roo.addon.tailor.actions.Action) CommandConfiguration(org.springframework.roo.addon.tailor.config.CommandConfiguration) TailorConfiguration(org.springframework.roo.addon.tailor.config.TailorConfiguration)

Example 4 with TailorConfiguration

use of org.springframework.roo.addon.tailor.config.TailorConfiguration in project spring-roo by spring-projects.

the class TailorCommands method tailorList.

/**
 * This method lists all available tailor configurations in the the Roo
 * shell.
 *
 * @param type
 */
@CliCommand(value = "tailor list", help = "List available tailor configurations.")
public void tailorList() {
    LOGGER.info("Available tailor configurations: ");
    final Map<String, TailorConfiguration> configs = configLocator.getAvailableConfigurations();
    final TailorConfiguration activeConfig = configLocator.getActiveTailorConfiguration();
    final Iterator<String> iterator = configs.keySet().iterator();
    while (iterator.hasNext()) {
        final String configName = iterator.next();
        final String isActive = activeConfig != null && configName.equals(activeConfig.getName()) ? " [ ACTIVE ] " : "";
        LOGGER.info("\to " + configName + isActive + " - " + configs.get(configName).getDescription());
    }
}
Also used : TailorConfiguration(org.springframework.roo.addon.tailor.config.TailorConfiguration) CliCommand(org.springframework.roo.shell.CliCommand)

Aggregations

TailorConfiguration (org.springframework.roo.addon.tailor.config.TailorConfiguration)4 ActionConfig (org.springframework.roo.addon.tailor.actions.ActionConfig)2 CommandConfiguration (org.springframework.roo.addon.tailor.config.CommandConfiguration)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 Action (org.springframework.roo.addon.tailor.actions.Action)1 CliCommand (org.springframework.roo.shell.CliCommand)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1