mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
major cleanup
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
package com.commafeed.frontend.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class MapToListModel<K, V> extends
|
||||
LoadableDetachableModel<List<Map.Entry<K, V>>> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IModel<Map<K, V>> model;
|
||||
|
||||
public MapToListModel(Map<K, V> map) {
|
||||
this.model = Model.ofMap(map);
|
||||
}
|
||||
|
||||
public MapToListModel(IModel<Map<K, V>> model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Entry<K, V>> load() {
|
||||
Map<K, V> map = model.getObject();
|
||||
return map == null ? null : Lists.newArrayList(map.entrySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
super.detach();
|
||||
model.detach();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.commafeed.frontend.utils;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -19,9 +18,6 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
|
||||
import org.apache.wicket.util.io.IOUtils;
|
||||
import org.apache.wicket.util.template.PackageTextTemplate;
|
||||
|
||||
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
|
||||
import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference;
|
||||
|
||||
public class WicketUtils {
|
||||
|
||||
public static void loadJQuery(IHeaderResponse response) {
|
||||
@@ -35,12 +31,6 @@ public class WicketUtils {
|
||||
.getSimpleName() + ".js"));
|
||||
}
|
||||
|
||||
public static JavaScriptHeaderItem buildJavaScriptWebJarHeaderItem(
|
||||
String name) {
|
||||
return JavaScriptHeaderItem
|
||||
.forReference(new WebjarsJavaScriptResourceReference(name));
|
||||
}
|
||||
|
||||
public static void loadJS(IHeaderResponse response, Class<?> klass) {
|
||||
response.render(buildJavaScriptHeaderItem(klass));
|
||||
}
|
||||
@@ -60,20 +50,11 @@ public class WicketUtils {
|
||||
response.render(result);
|
||||
}
|
||||
|
||||
public static void loadWebJarJS(IHeaderResponse response, String name) {
|
||||
response.render(buildJavaScriptWebJarHeaderItem(name));
|
||||
}
|
||||
|
||||
public static CssHeaderItem buildCssHeaderItem(Class<?> klass) {
|
||||
return CssHeaderItem.forReference(new CssResourceReference(klass, klass
|
||||
.getSimpleName() + ".css"));
|
||||
}
|
||||
|
||||
public static CssHeaderItem buildCssWebJarHeaderItem(String name) {
|
||||
return CssHeaderItem
|
||||
.forReference(new WebjarsCssResourceReference(name));
|
||||
}
|
||||
|
||||
public static void loadCSS(IHeaderResponse response, Class<?> klass) {
|
||||
response.render(buildCssHeaderItem(klass));
|
||||
}
|
||||
@@ -93,10 +74,6 @@ public class WicketUtils {
|
||||
response.render(result);
|
||||
}
|
||||
|
||||
public static void loadWebJarCSS(IHeaderResponse response, String name) {
|
||||
response.render(buildCssWebJarHeaderItem(name));
|
||||
}
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
ServletWebRequest servletWebRequest = (ServletWebRequest) RequestCycle
|
||||
.get().getRequest();
|
||||
@@ -108,28 +85,4 @@ public class WicketUtils {
|
||||
.getResponse();
|
||||
return (HttpServletResponse) webResponse.getContainerResponse();
|
||||
}
|
||||
|
||||
public static Principal getPrincipal() {
|
||||
return getHttpServletRequest().getUserPrincipal();
|
||||
}
|
||||
|
||||
public static String getPrincipalName() {
|
||||
Principal principal = getPrincipal();
|
||||
return principal == null ? null : principal.toString();
|
||||
}
|
||||
|
||||
public static boolean isUserInRole(String role) {
|
||||
return getHttpServletRequest().isUserInRole(role);
|
||||
}
|
||||
|
||||
public static boolean isUserInRoles(String... roles) {
|
||||
boolean inRoles = true;
|
||||
for (String role : roles) {
|
||||
if (!isUserInRole(role)) {
|
||||
inRoles = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return inRoles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
xmlns:wicket="http://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=blob_plain;f=wicket-core/src/main/resources/META-INF/wicket-1.5.xsd;hb=master">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
||||
<title>Error</title>
|
||||
</head>
|
||||
|
||||
@@ -27,5 +29,6 @@
|
||||
<pre wicket:id="stacktrace"></pre>
|
||||
</div>
|
||||
</div>
|
||||
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,12 +3,11 @@ package com.commafeed.frontend.utils.exception;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
||||
|
||||
import com.commafeed.frontend.pages.BasePage;
|
||||
|
||||
public class DisplayExceptionPage extends BasePage {
|
||||
public class DisplayExceptionPage extends WebPage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
|
||||
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
import de.agilecoders.wicket.markup.html.bootstrap.button.BootstrapAjaxButton;
|
||||
import de.agilecoders.wicket.markup.html.bootstrap.button.Buttons;
|
||||
|
||||
public abstract class BootstrapStatelessAjaxButton extends BootstrapAjaxButton {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PageParameters parameters;
|
||||
|
||||
public BootstrapStatelessAjaxButton(final String componentId,
|
||||
final Buttons.Type buttonType) {
|
||||
super(componentId, buttonType);
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxButton(final String componentId,
|
||||
final IModel<String> model, final Buttons.Type buttonType) {
|
||||
super(componentId, model, buttonType);
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxButton(final String componentId,
|
||||
final IModel<String> model, final Buttons.Type buttonType,
|
||||
PageParameters parameters) {
|
||||
super(componentId, model, buttonType);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxButton(String id, Form<?> form,
|
||||
Buttons.Type buttonType) {
|
||||
super(id, form, buttonType);
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxButton(String id, IModel<String> model,
|
||||
Form<?> form, Buttons.Type buttonType) {
|
||||
super(id, model, form, buttonType);
|
||||
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxButton(String id, IModel<String> model,
|
||||
Form<?> form, Buttons.Type buttonType, PageParameters parameters) {
|
||||
super(id, model, form, buttonType);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AjaxFormSubmitBehavior newAjaxFormSubmitBehavior(String event) {
|
||||
return new StatelessAjaxFormSubmitBehavior(getForm(), event) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void onSubmit(AjaxRequestTarget target) {
|
||||
BootstrapStatelessAjaxButton.this.onSubmit(target,
|
||||
BootstrapStatelessAjaxButton.this.getForm());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAfterSubmit(AjaxRequestTarget target) {
|
||||
BootstrapStatelessAjaxButton.this.onAfterSubmit(target,
|
||||
BootstrapStatelessAjaxButton.this.getForm());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onError(AjaxRequestTarget target) {
|
||||
BootstrapStatelessAjaxButton.this.onError(target,
|
||||
BootstrapStatelessAjaxButton.this.getForm());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
super.updateAjaxAttributes(attributes);
|
||||
BootstrapStatelessAjaxButton.this.updateAjaxAttributes(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDefaultProcessing() {
|
||||
return BootstrapStatelessAjaxButton.this.getDefaultFormProcessing();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PageParameters getPageParameters() {
|
||||
return parameters;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxEventBehavior;
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
import de.agilecoders.wicket.markup.html.bootstrap.button.BootstrapAjaxLink;
|
||||
import de.agilecoders.wicket.markup.html.bootstrap.button.Buttons;
|
||||
|
||||
public abstract class BootstrapStatelessAjaxLink<T> extends BootstrapAjaxLink<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PageParameters parameters;
|
||||
|
||||
public BootstrapStatelessAjaxLink(final String id, final Buttons.Type buttonType) {
|
||||
super(id, buttonType);
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxLink(String id, IModel<T> model,
|
||||
Buttons.Type buttonType) {
|
||||
super(id, model, buttonType);
|
||||
}
|
||||
|
||||
public BootstrapStatelessAjaxLink(String id, IModel<T> model,
|
||||
Buttons.Type buttonType, PageParameters parameters) {
|
||||
super(id, model, buttonType);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AjaxEventBehavior newAjaxEventBehavior(String event) {
|
||||
return new StatelessAjaxEventBehavior(event) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void onEvent(AjaxRequestTarget target) {
|
||||
BootstrapStatelessAjaxLink.this.onClick(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
super.updateAjaxAttributes(attributes);
|
||||
BootstrapStatelessAjaxLink.this.updateAjaxAttributes(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PageParameters getPageParameters() {
|
||||
return parameters;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.ajax.AjaxEventBehavior;
|
||||
import org.apache.wicket.request.Url;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
public abstract class StatelessAjaxEventBehavior extends AjaxEventBehavior {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public StatelessAjaxEventBehavior(final String event) {
|
||||
super(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCallbackUrl() {
|
||||
final Url url = Url.parse(super.getCallbackUrl().toString());
|
||||
final PageParameters params = getPageParameters();
|
||||
return StatelessEncoder.mergeParameters(url, params).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getStatelessHint(final Component component) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to pass the context of the current page to the behavior,
|
||||
* allowing it to recreate the context for the ajax request.
|
||||
*
|
||||
*/
|
||||
protected PageParameters getPageParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
|
||||
import org.apache.wicket.request.Url;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
public abstract class StatelessAjaxFormComponentUpdatingBehavior extends
|
||||
AjaxFormComponentUpdatingBehavior {
|
||||
|
||||
private static final long serialVersionUID = -286307141298283926L;
|
||||
|
||||
public StatelessAjaxFormComponentUpdatingBehavior(final String event) {
|
||||
super(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCallbackUrl() {
|
||||
final Url url = Url.parse(super.getCallbackUrl().toString());
|
||||
final PageParameters params = getPageParameters();
|
||||
return StatelessEncoder.mergeParameters(url, params).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getStatelessHint(final Component component) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to pass the context of the current page to the behavior,
|
||||
* allowing it to recreate the context for the ajax request.
|
||||
*
|
||||
*/
|
||||
protected PageParameters getPageParameters() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
|
||||
import org.apache.wicket.markup.html.form.Form;
|
||||
import org.apache.wicket.request.Url;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
public abstract class StatelessAjaxFormSubmitBehavior extends
|
||||
AjaxFormSubmitBehavior {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public StatelessAjaxFormSubmitBehavior(final String event) {
|
||||
super(event);
|
||||
}
|
||||
|
||||
public StatelessAjaxFormSubmitBehavior(Form<?> form, String event) {
|
||||
super(form, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCallbackUrl() {
|
||||
final Url url = Url.parse(super.getCallbackUrl().toString());
|
||||
final PageParameters params = getPageParameters();
|
||||
return StatelessEncoder.mergeParameters(url, params).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getStatelessHint(final Component component) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to pass the context of the current page to the behavior,
|
||||
* allowing it to recreate the context for the ajax request.
|
||||
*
|
||||
*/
|
||||
protected PageParameters getPageParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
|
||||
import org.apache.wicket.ajax.markup.html.IAjaxLink;
|
||||
import org.apache.wicket.markup.ComponentTag;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
public abstract class StatelessAjaxLink<T> extends StatelessLink<T>
|
||||
implements IAjaxLink {
|
||||
|
||||
private static final long serialVersionUID = -133600842398684777L;
|
||||
|
||||
public StatelessAjaxLink(final String id) {
|
||||
this(id, null, null);
|
||||
}
|
||||
|
||||
public StatelessAjaxLink(final String id,
|
||||
final PageParameters params) {
|
||||
this(id, null, params);
|
||||
}
|
||||
|
||||
public StatelessAjaxLink(final String id, final IModel<T> model) {
|
||||
this(id, model, null);
|
||||
}
|
||||
|
||||
public StatelessAjaxLink(final String id, final IModel<T> model,
|
||||
final PageParameters params) {
|
||||
super(id, model, params);
|
||||
|
||||
add(new StatelessAjaxEventBehavior("click") {
|
||||
private static final long serialVersionUID = -8445395501430605953L;
|
||||
|
||||
@Override
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
super.updateAjaxAttributes(attributes);
|
||||
StatelessAjaxLink.this.updateAjaxAttributes(attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PageParameters getPageParameters() {
|
||||
return StatelessAjaxLink.this.getPageParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onComponentTag(final ComponentTag tag) {
|
||||
if (isLinkEnabled()) {
|
||||
super.onComponentTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvent(final AjaxRequestTarget target) {
|
||||
onClick(target);
|
||||
target.add(StatelessAjaxLink.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onClick() {
|
||||
onClick(null);
|
||||
}
|
||||
|
||||
public abstract void onClick(final AjaxRequestTarget target);
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.wicket.request.Url;
|
||||
import org.apache.wicket.request.mapper.parameter.INamedParameters;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import org.apache.wicket.util.encoding.UrlEncoder;
|
||||
|
||||
final class StatelessEncoder {
|
||||
|
||||
static Url mergeParameters(final Url url, final PageParameters params) {
|
||||
if (params == null) {
|
||||
return url;
|
||||
}
|
||||
|
||||
Charset charset = url.getCharset();
|
||||
Url mergedUrl = Url.parse(url.toString(), charset);
|
||||
UrlEncoder urlEncoder = UrlEncoder.QUERY_INSTANCE;
|
||||
Set<String> setParameters = new HashSet<String>();
|
||||
|
||||
for (INamedParameters.NamedPair pair : params.getAllNamed()) {
|
||||
String key = urlEncoder.encode(pair.getKey(), charset);
|
||||
String value = urlEncoder.encode(pair.getValue(), charset);
|
||||
|
||||
if (setParameters.contains(key)) {
|
||||
mergedUrl.addQueryParameter(key, value);
|
||||
} else {
|
||||
mergedUrl.setQueryParameter(key, value);
|
||||
setParameters.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
return mergedUrl;
|
||||
}
|
||||
|
||||
private StatelessEncoder() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.commafeed.frontend.utils.stateless;
|
||||
|
||||
import org.apache.wicket.markup.html.link.Link;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.request.Url;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
public abstract class StatelessLink<T> extends Link<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final PageParameters parameters;
|
||||
|
||||
public StatelessLink(final String id) {
|
||||
this(id, null, null);
|
||||
}
|
||||
|
||||
public StatelessLink(final String id, final IModel<T> model) {
|
||||
this(id, model, null);
|
||||
}
|
||||
|
||||
public StatelessLink(final String id, final IModel<T> model,
|
||||
final PageParameters params) {
|
||||
super(id, model);
|
||||
setMarkupId(id);
|
||||
this.parameters = params;
|
||||
}
|
||||
|
||||
protected final PageParameters getPageParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getStatelessHint() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CharSequence getURL() {
|
||||
final Url url = Url.parse(super.getURL().toString());
|
||||
Url mergedUrl = StatelessEncoder.mergeParameters(url, parameters);
|
||||
return mergedUrl.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user