Skip to content

Commit

Permalink
Migrate to @autoConfiguration
Browse files Browse the repository at this point in the history
Convert Groovy classes to Java
  • Loading branch information
rainboyan committed Apr 23, 2023
1 parent 6a4d1a1 commit 10d5d6c
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 329 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.grails.scaffolding;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;

import grails.web.mapping.LinkGenerator;

import org.grails.datastore.mapping.model.MappingContext;
import org.grails.scaffolding.markup.ContextMarkupRenderer;
import org.grails.scaffolding.markup.ContextMarkupRendererImpl;
import org.grails.scaffolding.markup.DomainMarkupRenderer;
Expand All @@ -23,32 +28,34 @@ public class ScaffoldingBeanConfiguration {

@Bean
@ConditionalOnMissingBean
public ContextMarkupRenderer contextMarkupRenderer() {
return new ContextMarkupRendererImpl();
public ContextMarkupRenderer contextMarkupRenderer(ObjectProvider<MessageSource> messageSources) {
return new ContextMarkupRendererImpl(messageSources.getIfAvailable());
}

@Bean
@ConditionalOnMissingBean
public DomainMarkupRenderer domainMarkupRenderer() {
return new DomainMarkupRendererImpl();
public DomainMarkupRenderer domainMarkupRenderer(DomainModelService domainModelService, PropertyMarkupRenderer propertyMarkupRenderer,
ContextMarkupRenderer contextMarkupRenderer) {
return new DomainMarkupRendererImpl(domainModelService, propertyMarkupRenderer, contextMarkupRenderer);
}

@Bean
@ConditionalOnMissingBean
public PropertyMarkupRenderer propertyMarkupRenderer() {
return new PropertyMarkupRendererImpl();
public PropertyMarkupRenderer propertyMarkupRenderer(DomainInputRendererRegistry domainInputRendererRegistry,
DomainOutputRendererRegistry domainOutputRendererRegistry) {
return new PropertyMarkupRendererImpl(domainInputRendererRegistry, domainOutputRendererRegistry);
}

@Bean
@ConditionalOnMissingBean
public DomainPropertyFactory domainPropertyFactory() {
return new DomainPropertyFactoryImpl();
public DomainPropertyFactory domainPropertyFactory(ObjectProvider<MappingContext> grailsDomainClassMappingContext) {
return new DomainPropertyFactoryImpl(grailsDomainClassMappingContext.getIfAvailable());
}

@Bean
@ConditionalOnMissingBean
public DomainModelService domainModelService() {
return new DomainModelServiceImpl();
public DomainModelService domainModelService(DomainPropertyFactory domainPropertyFactory) {
return new DomainModelServiceImpl(domainPropertyFactory);
}

@Bean
Expand All @@ -65,8 +72,9 @@ public DomainOutputRendererRegistry domainOutputRendererRegistry() {

@Bean
@ConditionalOnMissingBean
public DomainRendererRegisterer domainRendererRegisterer() {
return new DomainRendererRegisterer();
public DomainRendererRegisterer domainRendererRegisterer(DomainInputRendererRegistry domainInputRendererRegistry, DomainOutputRendererRegistry domainOutputRendererRegistry,
ObjectProvider<LinkGenerator> grailsLinkGenerator) {
return new DomainRendererRegisterer(domainInputRendererRegistry, domainOutputRendererRegistry, grailsLinkGenerator.getIfAvailable());
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.grails.scaffolding.markup
package org.grails.scaffolding.markup;

import org.grails.scaffolding.model.property.DomainProperty
import org.grails.datastore.mapping.model.PersistentEntity
import java.util.List;

import groovy.lang.Closure;
import groovy.xml.MarkupBuilder;

import org.grails.datastore.mapping.model.PersistentEntity;
import org.grails.scaffolding.model.property.DomainProperty;

/**
* Used to output context surrounding any given content. Context is any markup that will be rendered
* along with any markup for domain property input or output. Input is used in this class to mean
* any HTML input type element (A way to retrieve users input). Output is used in this class to mean
* the display of a domain property on the page.
*
* An example of what might be returned with {@link #inputContext(DomainProperty,Closure)}
* <p>
* An example of what might be returned with {@link #inputContext(DomainProperty, Closure)}
* <pre>{@code
* { ->
* div([class: "form-group"]) {
Expand All @@ -21,70 +26,70 @@
*
* @author James Kleeh
*/
interface ContextMarkupRenderer {
public interface ContextMarkupRenderer {

/**
* Defines the context for rendering a list of domain class instances
*
* @param domainClass The domain class to be rendered
* @param properties The properties to be rendered
* @param content The content to be rendered for each property
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param properties The properties to be rendered
* @param content The content to be rendered for each property
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure listOutputContext(PersistentEntity domainClass, List<DomainProperty> properties, Closure content)
Closure listOutputContext(PersistentEntity domainClass, List<DomainProperty> properties, Closure content);

/**
* Defines the context for rendering a list of domain class properties inputs (form)
*
* @param domainClass The domain class to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure inputContext(PersistentEntity domainClass, Closure content)
Closure inputContext(PersistentEntity domainClass, Closure content);

/**
* Defines the context for rendering a single domain class property input (select, textarea, etc)
*
* @param property The domain property to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure inputContext(DomainProperty property, Closure content)
Closure inputContext(DomainProperty property, Closure content);

/**
* Defines the context for rendering a list domain class properties (show page)
*
* @param domainClass The domain class to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure outputContext(PersistentEntity domainClass, Closure content)
Closure outputContext(PersistentEntity domainClass, Closure content);

/**
* Defines the context for rendering a single domain class property output
*
* @param property The domain property to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure outputContext(DomainProperty property, Closure content)
Closure outputContext(DomainProperty property, Closure content);

/**
* Defines the context for rendering a the output of an embedded domain class property
*
* @param property The domain property to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure embeddedOutputContext(DomainProperty property, Closure content)
Closure embeddedOutputContext(DomainProperty property, Closure content);

/**
* Defines the context for rendering a the input of an embedded domain class property
*
* @param property The domain property to be rendered
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link groovy.xml.MarkupBuilder}
* @param content The content to be rendered
* @return The closure to be passed to an instance of {@link MarkupBuilder}
*/
Closure embeddedInputContext(DomainProperty property, Closure content)
Closure embeddedInputContext(DomainProperty property, Closure content);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import groovy.transform.CompileStatic
import org.grails.datastore.mapping.model.PersistentEntity
import org.springframework.context.MessageSource

import javax.annotation.Resource

/**
* @see {@link ContextMarkupRenderer}
* @author James Kleeh
*/
class ContextMarkupRendererImpl implements ContextMarkupRenderer {

@Resource
MessageSource messageSource
private MessageSource messageSource

ContextMarkupRendererImpl(MessageSource messageSource) {
this.messageSource = messageSource
}

@CompileStatic
protected String getDefaultTableHeader(DomainProperty property) {
Expand All @@ -37,7 +38,7 @@ class ContextMarkupRendererImpl implements ContextMarkupRenderer {
@CompileStatic
protected String resolveMessage(List<String> keysInPreferenceOrder, String defaultMessage) {
def message = keysInPreferenceOrder.findResult { key ->
messageSource.getMessage(key, [].toArray(), defaultMessage, Locale.default) ?: null
this.messageSource.getMessage(key, [].toArray(), defaultMessage, Locale.default) ?: null
}
message ?: defaultMessage
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package org.grails.scaffolding.markup
package org.grails.scaffolding.markup;

import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.datastore.mapping.model.PersistentEntity;

/**
* Used to output markup that represents a given domain class.
*
* @author James Kleeh
*/
interface DomainMarkupRenderer {
public interface DomainMarkupRenderer {

/**
* Designed to render a "show" page that will display a single domain class instance.
*
* @param domainClass The domain class to be rendered
* @return The rendered html
*/
String renderOutput(PersistentEntity domainClass)
String renderOutput(PersistentEntity domainClass);

/**
* Designed to render a "list" page that will display a list of domain class instances.
*
* @param domainClass The domain class to be rendered
* @return The rendered html
*/
String renderListOutput(PersistentEntity domainClass)

String renderListOutput(PersistentEntity domainClass);

/**
* Designed to render a form that will allow users to create or edit domain class instances.
*
* @param domainClass The domain class to be rendered
* @return The rendered html
*/
String renderInput(PersistentEntity domainClass)
String renderInput(PersistentEntity domainClass);

}
}
Loading

0 comments on commit 10d5d6c

Please sign in to comment.