Skip to content

Commit

Permalink
@releng different fixes
Browse files Browse the repository at this point in the history
- remove BackgroundGradient as we need now to use StyleGuide.gradients (cf. GH-24, GH-111),
- remove FlexModel's prefix of id introduced in GH-24 since GH-143 fixes the core issue,
- fixes a few sonar bugs & smells
  • Loading branch information
npeltier committed Sep 16, 2020
1 parent 1e93731 commit ceec7ac
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public String getKey() {
}

String computeMinHeight(Breakpoint breakpoint, SlingHttpServletRequest request) {
Long minHeight = RequestUtil.getFromRespProps(request, breakpoint, PN_MINHEIGHT, Long.class);
Long minHeight = RequestUtil.getFromRespProps(request, breakpoint, PN_MINHEIGHT);
if ( minHeight != null) {
String minHeightType = RequestUtil.getFromRespProps(request, breakpoint, PN_MINHEIGHT_TYPE, String.class);
String minHeightType = RequestUtil.getFromRespProps(request, breakpoint, PN_MINHEIGHT_TYPE);
if (minHeightType != null) {
return MIN_HEIGHT_PREFIX + minHeight.toString() + minHeightType;
}
Expand All @@ -81,7 +81,7 @@ String computeGapContainer(Long gap) {
SlingHttpServletRequest request) {
List<String> rules = null;
String minHeight = computeMinHeight(breakpoint, request);
Long gap = RequestUtil.getFromRespProps(request, breakpoint, PN_GAP, Long.class);
Long gap = RequestUtil.getFromRespProps(request, breakpoint, PN_GAP);
gap = gap != null ? gap / 2 : null;
String gapContainer = computeGapContainer(gap);
if (StringUtils.isNotBlank(minHeight) || StringUtils.isNotBlank(gapContainer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private String buildWidth(Breakpoint breakpoint, SlingHttpServletRequest request
}

private String buildCustomWidth(ValueMap properties, String width) {
if (StringUtils.equals(width, "custom")) {
if (StringUtils.equals(width, PV_CUSTOM)) {
long value = properties.get(PN_WIDTH_CUSTOMVALUE, 0L);
String type = properties.get(PN_WIDTH_CUSTOMTYPE, String.class);
if (value > 0 && StringUtils.isNotEmpty(type)) {
Expand All @@ -193,9 +193,6 @@ private String buildCustomMinHeight(ValueMap properties) {
if (StringUtils.equals(minHeight, PV_CUSTOM)) {
long value = properties.get(PN_MINHEIGHT_VALUE, 0L);
String type = properties.get(PN_MINHEIGHT_TYPE, String.class);
/*if (wcmModeEnabled) {
authorItemVh = StringUtils.equals("vh", type) ? Long.toString(value) : "0";
}*/
if (value > 0 && StringUtils.isNotEmpty(type)) {
return CSS_MIN_HEIGHT + value + type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class FlexModel {

public static final String PN_MINHEIGHT = "minHeight";
public static final String PN_MINHEIGHT_TYPE = PN_MINHEIGHT + "Type";
private static final String ID_PREFIX = "flex-";

@SlingObject
protected SlingHttpServletRequest request;
Expand All @@ -49,7 +48,7 @@ public class FlexModel {
@PostConstruct
void init() {
if (idTagger != null) {
id = ID_PREFIX + idTagger.computeComponentId(request, null);
id = idTagger.computeComponentId(request, null);
}
if (styleService != null) {
style = styleService.getInlineStyle(getId(), request);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private String generateSize(String image) {

private String generatePosition(String image, @Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
if (StringUtils.isNotBlank(image)) {
Long focusX = getFromRespProps(request, breakpoint, PN_FOCUSX, Long.class);
Long focusY = getFromRespProps(request, breakpoint, PN_FOCUSY, Long.class);
Long focusX = getFromRespProps(request, breakpoint, PN_FOCUSX);
Long focusY = getFromRespProps(request, breakpoint, PN_FOCUSY);
if (focusX != null && focusY != null) {
return POSITION_PREFIX + focusX + POSITION_UNIT + focusY + POSITION_UNIT;
}
Expand All @@ -96,11 +96,11 @@ private String generatePosition(String image, @Nullable Breakpoint breakpoint, S

@Override
public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
String bgColorKey = getFromRespProps(request, breakpoint, PN_BACKGROUNDCOLOR, String.class);
String bgColorKey = getFromRespProps(request, breakpoint, PN_BACKGROUNDCOLOR);
String bgColor = StyleGuideUtil.getColor(request, bgColorKey);
String gradientKey = getFromRespProps(request, breakpoint, PN_GRADIENT, String.class);
String gradientKey = getFromRespProps(request, breakpoint, PN_GRADIENT);
String gradient = StyleGuideUtil.getGradient(request, gradientKey);
String image = getFromRespProps(request, breakpoint, PN_IMAGE, String.class);
String image = getFromRespProps(request, breakpoint, PN_IMAGE);
if (bgColor != null || gradient != null || image != null) {
List<String> declarations = new ArrayList<>();
declarations.add(generateColorDeclaration(bgColor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.adobe.dx.responsive.Breakpoint;
import com.adobe.dx.inlinestyle.InlineStyleWorker;
import com.adobe.dx.styleguide.StyleGuideUtil;
import com.adobe.dx.utils.RequestUtil;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
public class Color implements InlineStyleWorker {
private final static String KEY = "color";
private static final String KEY = "color";

private final static String PN_COLOR = "foregroundColor";
private final static String FORMAT = "color: %s";
private static final String PN_COLOR = "foregroundColor";
private static final String FORMAT = "color: %s";

@Override
public String getKey() {
Expand All @@ -42,7 +42,7 @@ public String getKey() {

@Override
public @Nullable String getDeclaration(@Nullable Breakpoint breakpoint, SlingHttpServletRequest request) {
String colorKey = getFromRespProps(request, breakpoint, PN_COLOR, String.class);
String colorKey = getFromRespProps(request, breakpoint, PN_COLOR);
String color = StyleGuideUtil.getColor(request, colorKey);
if (StringUtils.isNotBlank(color)) {
return String.format(FORMAT, color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,29 @@ public class InlineStyleServiceImpl implements InlineStyleService {
cardinality= ReferenceCardinality.MULTIPLE,
policy= ReferencePolicy.DYNAMIC, policyOption= ReferencePolicyOption.GREEDY,
bind = "bindWorker", unbind = "unbindWorker")
volatile List<InlineStyleWorker> workers = new ArrayList<>();
final List<InlineStyleWorker> workers = new ArrayList<>();

Map<String, InlineStyleWorker> workerMap = MapUtils.EMPTY_MAP;

@FunctionalInterface
private interface StyleFunction<T1, T2, T3> {
T3 apply(T1 t1, T2 t2, T3 t3);
}

List<String> generateAndAppend(List<String> existing,
Breakpoint breakpoint, SlingHttpServletRequest request, String id,
StyleFunction<SlingHttpServletRequest, Breakpoint, String> function) {
String styleString = function.apply(request, breakpoint, id);
if (StringUtils.isNotBlank(styleString)) {
logger.debug("generated {}", styleString);
if (existing == null) {
existing = new ArrayList<>();
}
existing.add(styleString);
}
return existing;
}

String getStylePerBreakpoint(String id, Breakpoint breakpoint, String[] keys, SlingHttpServletRequest request) {
String returnValue = EMPTY;
List<String> declarations = null;
Expand All @@ -70,22 +89,10 @@ String getStylePerBreakpoint(String id, Breakpoint breakpoint, String[] keys, Sl
InlineStyleWorker worker = workerMap.get(workerKey);
if (worker != null) {
logger.debug("found {}", worker);
String declaration = worker.getDeclaration(breakpoint, request);
if (StringUtils.isNotBlank(declaration)) {
logger.debug("generated {}", declaration);
if (declarations == null) {
declarations = new ArrayList<>();
}
declarations.add(declaration);
}
String rule = worker.getRule(breakpoint, id, request);
if (StringUtils.isNotBlank(rule)) {
logger.debug("generated {}", rule);
if (rules == null) {
rules = new ArrayList<>();
}
rules.add(rule);
}
declarations = generateAndAppend(declarations, breakpoint, request, id,
(r, b, i) -> worker.getDeclaration(b, r));
rules = generateAndAppend(rules, breakpoint, request, id,
(r, b, i) -> worker.getRule(b, i, r));
}
}
if (declarations != null && !declarations.isEmpty()) {
Expand All @@ -105,15 +112,12 @@ public String getInlineStyle(String id, SlingHttpServletRequest request) {
String[] keys = getWorkerKeys(resource);
if (keys.length > 0) {
StringBuilder style = new StringBuilder();
List<Breakpoint> breakpoints = RequestUtil.getBreakpoints(request);
if (breakpoints != null) {
for (Breakpoint breakpoint : breakpoints) {
String bpStyle = getStylePerBreakpoint(id, breakpoint, keys, request);
if (StringUtils.isNotBlank(bpStyle)) {
style.append(StringUtils.isNotBlank(breakpoint.mediaQuery()) ?
String.format(FORMAT_BP, breakpoint.mediaQuery(), bpStyle):
bpStyle);
}
for (Breakpoint breakpoint : RequestUtil.getBreakpoints(request)) {
String bpStyle = getStylePerBreakpoint(id, breakpoint, keys, request);
if (StringUtils.isNotBlank(bpStyle)) {
style.append(StringUtils.isNotBlank(breakpoint.mediaQuery()) ?
String.format(FORMAT_BP, breakpoint.mediaQuery(), bpStyle):
bpStyle);
}
}
if (style.length() > 0) {
Expand Down
Loading

0 comments on commit ceec7ac

Please sign in to comment.