Skip to content

Commit

Permalink
apply the source code as suggested in editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanhb committed Nov 19, 2021
1 parent 8d2a567 commit c3ff22a
Show file tree
Hide file tree
Showing 51 changed files with 2,844 additions and 2,861 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
root = true

[*]
indent_style = space
indent_size = 4
indent_style = tab
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Auto detect text files and perform LF normalization
# disable auto normalization of platform line ending.
* text=auto
* text=lf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package nz.net.ultraq.thymeleaf;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import nz.net.ultraq.thymeleaf.decorators.DecorateProcessor;
import nz.net.ultraq.thymeleaf.decorators.SortingStrategy;
import nz.net.ultraq.thymeleaf.decorators.TitlePatternProcessor;
Expand All @@ -30,6 +27,10 @@
import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

/**
* A dialect for Thymeleaf that lets you build layouts and reusable templates in
* order to improve code reuse
Expand All @@ -39,73 +40,73 @@
*/
public class LayoutDialect extends AbstractProcessorDialect {

public static final String DIALECT_NAME = "Layout";
public static final String DIALECT_PREFIX = "layout";
public static final int DIALECT_PRECEDENCE = 10;
public static final String DIALECT_NAME = "Layout";
public static final String DIALECT_PREFIX = "layout";
public static final int DIALECT_PRECEDENCE = 10;

private final boolean autoHeadMerging;
private final SortingStrategy sortingStrategy;
private final boolean autoHeadMerging;
private final SortingStrategy sortingStrategy;

/**
* Constructor, configure the layout dialect.
*
* @param sortingStrategy
* @param autoHeadMerging Experimental option, set to {@code false} to skip
* the automatic merging of an HTML {@code <head>} section.
*/
public LayoutDialect(SortingStrategy sortingStrategy, boolean autoHeadMerging) {
super(DIALECT_NAME, DIALECT_PREFIX, DIALECT_PRECEDENCE);
this.sortingStrategy = sortingStrategy;
this.autoHeadMerging = autoHeadMerging;
}
/**
* Constructor, configure the layout dialect.
*
* @param sortingStrategy
* @param autoHeadMerging Experimental option, set to {@code false} to skip
* the automatic merging of an HTML {@code <head>} section.
*/
public LayoutDialect(SortingStrategy sortingStrategy, boolean autoHeadMerging) {
super(DIALECT_NAME, DIALECT_PREFIX, DIALECT_PRECEDENCE);
this.sortingStrategy = sortingStrategy;
this.autoHeadMerging = autoHeadMerging;
}

/**
* Constructor, configure the layout dialect.
*
* @param sortingStrategy
*/
public LayoutDialect(SortingStrategy sortingStrategy) {
this(sortingStrategy, true);
}
/**
* Constructor, configure the layout dialect.
*
* @param sortingStrategy
*/
public LayoutDialect(SortingStrategy sortingStrategy) {
this(sortingStrategy, true);
}

/**
* Constructor, configure the layout dialect.
*/
@SuppressWarnings("deprecation")
public LayoutDialect() {
this(new nz.net.ultraq.thymeleaf.decorators.strategies.AppendingStrategy());
}
/**
* Constructor, configure the layout dialect.
*/
@SuppressWarnings("deprecation")
public LayoutDialect() {
this(new nz.net.ultraq.thymeleaf.decorators.strategies.AppendingStrategy());
}

/**
* Returns the layout dialect's processors.
*
* @param dialectPrefix
* @return All of the processors for HTML and XML template modes.
*/
@Override
@SuppressWarnings("deprecation")
public Set<IProcessor> getProcessors(String dialectPrefix) {
return new LinkedHashSet<>(Arrays.asList(
// Processors available in the HTML template mode
new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix),
new DecorateProcessor(TemplateMode.HTML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.decorators.DecoratorProcessor(TemplateMode.HTML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.includes.IncludeProcessor(TemplateMode.HTML, dialectPrefix),
new InsertProcessor(TemplateMode.HTML, dialectPrefix),
new ReplaceProcessor(TemplateMode.HTML, dialectPrefix),
new FragmentProcessor(TemplateMode.HTML, dialectPrefix),
new CollectFragmentProcessor(TemplateMode.HTML, dialectPrefix),
new TitlePatternProcessor(TemplateMode.HTML, dialectPrefix),
// Processors available in the XML template mode
new StandardXmlNsTagProcessor(TemplateMode.XML, dialectPrefix),
new DecorateProcessor(TemplateMode.XML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.decorators.DecoratorProcessor(TemplateMode.XML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.includes.IncludeProcessor(TemplateMode.XML, dialectPrefix),
new InsertProcessor(TemplateMode.XML, dialectPrefix),
new ReplaceProcessor(TemplateMode.XML, dialectPrefix),
new FragmentProcessor(TemplateMode.XML, dialectPrefix),
new CollectFragmentProcessor(TemplateMode.XML, dialectPrefix)
));
}
/**
* Returns the layout dialect's processors.
*
* @param dialectPrefix
* @return All of the processors for HTML and XML template modes.
*/
@Override
@SuppressWarnings("deprecation")
public Set<IProcessor> getProcessors(String dialectPrefix) {
return new LinkedHashSet<>(Arrays.asList(
// Processors available in the HTML template mode
new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix),
new DecorateProcessor(TemplateMode.HTML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.decorators.DecoratorProcessor(TemplateMode.HTML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.includes.IncludeProcessor(TemplateMode.HTML, dialectPrefix),
new InsertProcessor(TemplateMode.HTML, dialectPrefix),
new ReplaceProcessor(TemplateMode.HTML, dialectPrefix),
new FragmentProcessor(TemplateMode.HTML, dialectPrefix),
new CollectFragmentProcessor(TemplateMode.HTML, dialectPrefix),
new TitlePatternProcessor(TemplateMode.HTML, dialectPrefix),
// Processors available in the XML template mode
new StandardXmlNsTagProcessor(TemplateMode.XML, dialectPrefix),
new DecorateProcessor(TemplateMode.XML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.decorators.DecoratorProcessor(TemplateMode.XML, dialectPrefix, sortingStrategy, autoHeadMerging),
new nz.net.ultraq.thymeleaf.includes.IncludeProcessor(TemplateMode.XML, dialectPrefix),
new InsertProcessor(TemplateMode.XML, dialectPrefix),
new ReplaceProcessor(TemplateMode.XML, dialectPrefix),
new FragmentProcessor(TemplateMode.XML, dialectPrefix),
new CollectFragmentProcessor(TemplateMode.XML, dialectPrefix)
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,90 +15,91 @@
*/
package nz.net.ultraq.thymeleaf.context.extensions;

import javax.annotation.Nonnull;
import nz.net.ultraq.thymeleaf.internal.Supplier;
import org.thymeleaf.DialectConfiguration;
import org.thymeleaf.context.IContext;
import org.thymeleaf.context.IEngineContext;
import org.thymeleaf.context.IExpressionContext;
import org.thymeleaf.dialect.IProcessorDialect;

import javax.annotation.Nonnull;

/**
* Meta-programming extensions to the {@link IContext} class.
*
* @author Emanuel Rabina
*/
public class IContextExtensions {

private static final String DIALECT_PREFIX_PREFIX = "DialectPrefix::";
private static final String DIALECT_PREFIX_PREFIX = "DialectPrefix::";

/**
* Enables use of the {@code value = context[key]} syntax over the context
* object, is a synonym for the {@code getVariable} method.
*
* @param self
* @param name Name of the variable on the context to retrieve.
* @return The variable value, or {@code null} if the variable isn't mapped
* to anything on the context.
*/
public static Object getAt(IContext self, String name) {
return self.getVariable(name);
}
/**
* Enables use of the {@code value = context[key]} syntax over the context
* object, is a synonym for the {@code getVariable} method.
*
* @param self
* @param name Name of the variable on the context to retrieve.
* @return The variable value, or {@code null} if the variable isn't mapped
* to anything on the context.
*/
public static Object getAt(IContext self, String name) {
return self.getVariable(name);
}

/**
* Retrieves an item from the context, or creates one on the context if it
* doesn't yet exist.
*
* @param <T>
* @param self
* @param key
* @param closure
* @return The item cached on the context through the given key, or first
* constructed through the closure.
*/
public static <T> T getOrCreate(@Nonnull IContext self, @Nonnull String key, Supplier<T> closure) {
@SuppressWarnings("unchecked")
T result = (T) getAt(self, key);
if (result == null) {
result = closure.get();
putAt(self, key, result);
}
return result;
}
/**
* Retrieves an item from the context, or creates one on the context if it
* doesn't yet exist.
*
* @param <T>
* @param self
* @param key
* @param closure
* @return The item cached on the context through the given key, or first
* constructed through the closure.
*/
public static <T> T getOrCreate(@Nonnull IContext self, @Nonnull String key, Supplier<T> closure) {
@SuppressWarnings("unchecked")
T result = (T) getAt(self, key);
if (result == null) {
result = closure.get();
putAt(self, key, result);
}
return result;
}

/**
* Returns the configured prefix for the given dialect. If the dialect
* prefix has not been configured.
*
* @param self
* @param dialectClass
* @return The configured prefix for the dialect, or {@code null} if the
* dialect being queried hasn't been configured.
*/
public static String getPrefixForDialect(@Nonnull IContext self, Class<? extends IProcessorDialect> dialectClass) {
return getOrCreate(self, DIALECT_PREFIX_PREFIX + dialectClass.getName(), () -> {
for (DialectConfiguration dialectConfig : ((IExpressionContext) self).getConfiguration().getDialectConfigurations()) {
if (dialectClass.isInstance(dialectConfig.getDialect())) {
if (dialectConfig.isPrefixSpecified()) {
return dialectConfig.getPrefix();
}
return ((IProcessorDialect) dialectConfig.getDialect()).getPrefix();
}
}
return null;
});
}
/**
* Returns the configured prefix for the given dialect. If the dialect
* prefix has not been configured.
*
* @param self
* @param dialectClass
* @return The configured prefix for the dialect, or {@code null} if the
* dialect being queried hasn't been configured.
*/
public static String getPrefixForDialect(@Nonnull IContext self, Class<? extends IProcessorDialect> dialectClass) {
return getOrCreate(self, DIALECT_PREFIX_PREFIX + dialectClass.getName(), () -> {
for (DialectConfiguration dialectConfig : ((IExpressionContext) self).getConfiguration().getDialectConfigurations()) {
if (dialectClass.isInstance(dialectConfig.getDialect())) {
if (dialectConfig.isPrefixSpecified()) {
return dialectConfig.getPrefix();
}
return ((IProcessorDialect) dialectConfig.getDialect()).getPrefix();
}
}
return null;
});
}

/**
* Enables use of the {@code context[key] = value} syntax over the context
* object, is a synonym for the {@code setVariable} method.
*
* @param self
* @param name Name of the variable to map the value to.
* @param value The value to set.
*/
public static void putAt(IContext self, String name, Object value) {
((IEngineContext) self).setVariable(name, value);
}
/**
* Enables use of the {@code context[key] = value} syntax over the context
* object, is a synonym for the {@code setVariable} method.
*
* @param self
* @param name Name of the variable to map the value to.
* @param value The value to set.
*/
public static void putAt(IContext self, String name, Object value) {
((IEngineContext) self).setVariable(name, value);
}

}
Loading

0 comments on commit c3ff22a

Please sign in to comment.