Skip to content

Commit

Permalink
Merge branch 'skarp-master' into standalone-request
Browse files Browse the repository at this point in the history
  • Loading branch information
millevlada committed Dec 17, 2024
2 parents 924ef7e + b2fd4b9 commit 05d368d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package to.etc.domui.component.layout;

import org.eclipse.jdt.annotation.NonNull;
import to.etc.domui.dom.html.*;

/**
Expand All @@ -12,4 +13,10 @@ public class ContentPanel extends Div {
public ContentPanel() {
setCssClass("ui-cpnl");
}

@NonNull
@Override
public ContentPanel css(@NonNull String... classNames) {
return (ContentPanel) super.css(classNames);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* DomUI Java User Interface library
* Copyright (c) 2010 by Frits Jalvingh, Itris B.V.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* See the "sponsors" file for a list of supporters.
*
* The latest version of DomUI and related code, support and documentation
* can be found at http://www.domui.org/
* The contact for the project is Frits Jalvingh <[email protected]>.
*/
package to.etc.domui.dom.header;

import org.eclipse.jdt.annotation.NonNull;
import to.etc.domui.dom.IContributorRenderer;
import to.etc.domui.state.AppSession;

final public class RandomCssContributor extends HeaderContributor {

public static final String KEY = "RandomCssCon";

private final int m_maxVariants;

private final boolean m_offline;

private final String[] m_options;

private String m_path;

public RandomCssContributor(int maxVariants, @NonNull String path, boolean offline, String... options) {
m_maxVariants = maxVariants;
m_offline = offline;
m_options = options;
if(path == null || path.isEmpty())
throw new IllegalArgumentException("Null path not allowed");
m_path = path;
}

@Override public boolean isOfflineCapable() {
return m_offline;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + m_path.hashCode();
result = prime * result + m_maxVariants;
return result;
}

@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
RandomCssContributor other = (RandomCssContributor) obj;
if(m_path == null) {
return other.m_path == null;
} else if(m_maxVariants != other.m_maxVariants) {
return false;
} else {
return m_path.equals(other.m_path);
}
}

@Override
public void contribute(IContributorRenderer r) throws Exception {
//-- Get a random int if not yet known in the session
AppSession session = r.ctx().getSession();
Integer key;
if(null != session) {
key = (Integer) session.getAttribute(KEY);
if(null == key) {
key = (int) (Math.random() * m_maxVariants);
session.setAttribute(KEY, key);
}
} else {
key = 0;
}
StringBuilder sb = new StringBuilder(m_path);
if(m_path.contains("?"))
sb.append("&");
else
sb.append("?");
sb.append("__r=").append(key);

r.renderLoadCSS(sb.toString(), m_options);
}

@Override public String toString() {
return m_path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ protected String generateParameterFile() {
}

//-- Now do the same for application level things
DomApplication.get().getThemeProperties().forEach((name, value) -> {
Map<String, String> themeProperties = new HashMap<>(DomApplication.get().getThemeProperties());

Map<String, String> calculatedMap = DomApplication.get().getThemeVariablesCalculator().calculate(m_params);
themeProperties.putAll(calculatedMap);

themeProperties.forEach((name, value) -> {
if(value.startsWith("$")) {
value = StringTool.strToJavascriptString(value.substring(1), true);
}
Expand Down
11 changes: 11 additions & 0 deletions to.etc.domui/src/main/java/to/etc/domui/server/DomApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import to.etc.domui.themes.ThemePartFactory;
import to.etc.domui.themes.ThemeResourceFactory;
import to.etc.domui.themes.fragmented.FragmentedThemeFactory;
import to.etc.domui.themes.sass.IThemeVariablesCalculator;
import to.etc.domui.themes.sass.SassThemeFactory;
import to.etc.domui.themes.simple.SimpleThemeFactory;
import to.etc.domui.trouble.DataAccessViolationException;
Expand Down Expand Up @@ -318,6 +319,8 @@ public abstract class DomApplication {
@NonNull
private volatile String m_defaultTheme = "";

private IThemeVariablesCalculator m_themeVariablesCalculator = parameters -> Map.of();

private ConfigParameters m_configParameters;

@Nullable
Expand Down Expand Up @@ -2266,6 +2269,14 @@ final public void setDefaultThemeFactory(@NonNull IThemeFactory themer) {
m_defaultTheme = themer.getDefaultThemeName();
}

public IThemeVariablesCalculator getThemeVariablesCalculator() {
return m_themeVariablesCalculator;
}

public void setThemeVariablesCalculator(IThemeVariablesCalculator themeVariablesCalculator) {
m_themeVariablesCalculator = themeVariablesCalculator;
}

/**
* Get an ITheme instance for the default theme manager and theme.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package to.etc.domui.themes.sass;

import to.etc.domui.state.IPageParameters;

import java.util.Map;

public interface IThemeVariablesCalculator {
Map<String, String> calculate(IPageParameters parameters);

}

0 comments on commit 05d368d

Please sign in to comment.