-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'skarp-master' into standalone-request
- Loading branch information
Showing
5 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
to.etc.domui/src/main/java/to/etc/domui/dom/header/RandomCssContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
to.etc.domui/src/main/java/to/etc/domui/themes/sass/IThemeVariablesCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |