Skip to content

Instantly share code, notes, and snippets.

@SergioLarios
Created November 18, 2014 20:42
Show Gist options
  • Save SergioLarios/bdaefa616cc8354f3445 to your computer and use it in GitHub Desktop.
Save SergioLarios/bdaefa616cc8354f3445 to your computer and use it in GitHub Desktop.
public static List<String> generateLayoutTree(RenderRequest renderRequest, String fUrl) {
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.
getAttribute(WebKeys.THEME_DISPLAY);
List<String> options = new ArrayList<>();
try {
List<Layout> parents = themeDisplay.getLayouts();
for (Layout parent : parents) {
options = getLayoutTree(options, parent, fUrl, 0);
}
} catch (Exception e) {
log.error(e);
}
return options;
}
public static List<String> getLayoutTree(List<String> options, Layout ly, String selectedFurl, int depth) {
String tabs = StringPool.BLANK;
for (int i = 0; i < depth; i++) {
tabs = tabs + StringPool.NBSP + StringPool.NBSP;
}
tabs = tabs + StringPool.MINUS + StringPool.SPACE;
if (Validator.equals(ly.getFriendlyURL(), selectedFurl)) {
options.add(String.format(OPTION_SELECTED_TMPL,
String.valueOf(ly.getFriendlyURL()),
tabs + ly.getName(ly.getDefaultLanguageId())));
}
else {
options.add(String.format(OPTION_TMPL,
String.valueOf(ly.getFriendlyURL()),
tabs +ly.getName(ly.getDefaultLanguageId())));
}
try {
if (ly.hasChildren()) {
for (Layout child : ly.getChildren()) {
options = getLayoutTree(options, child, selectedFurl, depth + 1);
}
}
} catch (Exception e) {
log.error(e);
}
return options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment