diff --git a/pom.xml b/pom.xml index fd538be..4c20d38 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,18 @@ commons-io commons-io + + com.guicedee.services + uadetector-core + 2.0.0-SNAPSHOT + compile + + + com.guicedee.services + uadetector-resources + 2.0.0-SNAPSHOT + compile + diff --git a/src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java b/src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java index 22ce8da..f200147 100644 --- a/src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java +++ b/src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java @@ -35,7 +35,8 @@ @SuppressWarnings("MissingClassJavaDoc") @CallScope public class AjaxResponse> - extends JavaScriptPart { + extends JavaScriptPart +{ /** * Whether or not the response is a success or not */ @@ -67,35 +68,40 @@ public class AjaxResponse> private Map properties = new HashMap<>(); - public Map getProperties() { + public Map getProperties() + { return properties; } @JsonProperty("data") private Map dataReturns = new HashMap<>(); - public J addDataResponse(String listener, IJsonRepresentation json) { + public J addDataResponse(String listener, IJsonRepresentation json) + { dataReturns.put(listener, json); return (J) this; } - - public J addDataResponse(String listener, Map json) throws Exception { + + public J addDataResponse(String listener, Map json) throws Exception + { dataReturns.put(listener, json); return (J) this; } - - public J addDataResponse(String listener, String result){ + + public J addDataResponse(String listener, String result) + { dataReturns.put(listener, result); return (J) this; } - + /** * Sets the properties for this response * * @param properties * @return */ - public AjaxResponse setProperties(Map properties) { + public AjaxResponse setProperties(Map properties) + { this.properties = properties; return this; } @@ -108,14 +114,15 @@ public AjaxResponse setProperties(Map properties) { @JsonProperty("features") @JsonInclude(JsonInclude.Include.NON_EMPTY) @SuppressWarnings("unused") - protected Set getFeatureQueries() { + protected Set getFeatureQueries() + { Set list = new LinkedHashSet<>(); getFeatures().forEach(feature -> - { - feature.preConfigure(); - list.add(feature.renderJavascript() - .toString()); - }); + { + feature.preConfigure(); + list.add(feature.renderJavascript() + .toString()); + }); return list; } @@ -124,8 +131,10 @@ protected Set getFeatureQueries() { * * @return */ - public Set> getFeatures() { - if (features == null) { + public Set> getFeatures() + { + if (features == null) + { features = new TreeSet<>(); } return features; @@ -136,7 +145,8 @@ protected Set getFeatureQueries() { * * @param features */ - public void setFeatures(Set> features) { + public void setFeatures(Set> features) + { this.features = features; } @@ -145,7 +155,8 @@ public void setFeatures(Set> features) { * * @return */ - public boolean isSuccess() { + public boolean isSuccess() + { return success; } @@ -154,7 +165,8 @@ public boolean isSuccess() { * * @param success */ - public void setSuccess(boolean success) { + public void setSuccess(boolean success) + { this.success = success; } @@ -165,7 +177,8 @@ public void setSuccess(boolean success) { * @return J Always this */ @SuppressWarnings("unchecked") - public J addFeature(IFeature feature) { + public J addFeature(IFeature feature) + { getFeatures().add(feature); return (J) this; } @@ -176,8 +189,9 @@ public J addFeature(IFeature feature) { * @param reaction */ @SuppressWarnings("unchecked") - - public J addReaction(AjaxResponseReaction reaction) { + + public J addReaction(AjaxResponseReaction reaction) + { getReactions().add(reaction); return (J) this; } @@ -187,8 +201,10 @@ public J addReaction(AjaxResponseReaction reaction) { * * @return */ - public Set> getReactions() { - if (reactions == null) { + public Set> getReactions() + { + if (reactions == null) + { reactions = new LinkedHashSet<>(); } return reactions; @@ -199,8 +215,10 @@ public Set> getReactions() { * * @return */ - public Map getLocalStorage() { - if (localStorage == null) { + public Map getLocalStorage() + { + if (localStorage == null) + { localStorage = new HashMap<>(); } return localStorage; @@ -211,7 +229,8 @@ public Map getLocalStorage() { * * @param localStorage */ - public void setLocalStorage(Map localStorage) { + public void setLocalStorage(Map localStorage) + { this.localStorage = localStorage; } @@ -220,8 +239,10 @@ public void setLocalStorage(Map localStorage) { * * @return */ - public Map getSessionStorage() { - if (sessionStorage == null) { + public Map getSessionStorage() + { + if (sessionStorage == null) + { sessionStorage = new HashMap<>(); } return sessionStorage; @@ -232,7 +253,8 @@ public Map getSessionStorage() { * * @param sessionStorage */ - public void setSessionStorage(Map sessionStorage) { + public void setSessionStorage(Map sessionStorage) + { this.sessionStorage = sessionStorage; } diff --git a/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientBinder.java b/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientBinder.java new file mode 100644 index 0000000..ea3883b --- /dev/null +++ b/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientBinder.java @@ -0,0 +1,55 @@ +package com.jwebmp.core.client.implementations; + +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.guicedee.client.IGuiceContext; +import com.guicedee.guicedinjection.interfaces.IGuiceModule; + +import com.guicedee.guicedservlets.servlets.services.scopes.CallScope; +import com.jwebmp.core.base.ajax.AjaxCall; +import com.jwebmp.core.base.ajax.AjaxResponse; +import com.jwebmp.interception.services.AjaxCallIntercepter; +import com.jwebmp.interception.services.DataCallIntercepter; +import com.jwebmp.interception.services.JWebMPInterceptionBinder; +import com.jwebmp.interception.services.SiteCallIntercepter; +import net.sf.uadetector.UserAgentStringParser; +import net.sf.uadetector.service.UADetectorServiceFactory; + +import java.util.ServiceLoader; + +@SuppressWarnings("unchecked") +public class JWebMPClientBinder extends AbstractModule implements IGuiceModule +{ + private static final UserAgentStringParser userAgentParser = UADetectorServiceFactory.getResourceModuleParser(); + + @Override + protected void configure() + { + bind(UserAgentStringParser.class) + .toInstance(userAgentParser); + + + bind(AjaxResponse.class) + .in(CallScope.class); + + bind(AjaxCall.class) + .in(CallScope.class); + + bind(JWebMPInterceptionBinder.AjaxCallInterceptorKey) + .toProvider(() -> IGuiceContext + .instance() + .getLoader(AjaxCallIntercepter.class, ServiceLoader.load(AjaxCallIntercepter.class))) + .in(Singleton.class); + + bind(JWebMPInterceptionBinder.DataCallInterceptorKey) + .toProvider(() -> IGuiceContext.instance() + .getLoader(DataCallIntercepter.class, ServiceLoader.load(DataCallIntercepter.class))) + .in(Singleton.class); + + bind(JWebMPInterceptionBinder.SiteCallInterceptorKey) + .toProvider(() -> IGuiceContext.instance() + .getLoader(SiteCallIntercepter.class, ServiceLoader.load(SiteCallIntercepter.class))) + .in(Singleton.class); + + } +} diff --git a/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientConfiguration.java b/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientConfiguration.java new file mode 100644 index 0000000..baa2045 --- /dev/null +++ b/src/main/java/com/jwebmp/core/client/implementations/JWebMPClientConfiguration.java @@ -0,0 +1,21 @@ +package com.jwebmp.core.client.implementations; + +import com.guicedee.guicedinjection.interfaces.IGuiceConfig; +import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator; + +public class JWebMPClientConfiguration implements IGuiceConfigurator +{ + @Override + public IGuiceConfig configure(IGuiceConfig config) + { + config = config.setClasspathScanning(true) + .setAllowPaths(true) + .setFieldInfo(true) + .setMethodInfo(true) + .setAnnotationScanning(true) + .setIgnoreClassVisibility(true) + .setIgnoreFieldVisibility(true) + .setIgnoreMethodVisibility(true); + return config; + } +} diff --git a/src/main/java/com/jwebmp/interception/services/JWebMPInterceptionBinder.java b/src/main/java/com/jwebmp/interception/services/JWebMPInterceptionBinder.java index 14358ad..63af9e1 100644 --- a/src/main/java/com/jwebmp/interception/services/JWebMPInterceptionBinder.java +++ b/src/main/java/com/jwebmp/interception/services/JWebMPInterceptionBinder.java @@ -5,6 +5,7 @@ import java.util.Set; +@SuppressWarnings("Convert2Diamond") public interface JWebMPInterceptionBinder { Key> AjaxCallInterceptorKey = Key.get(new TypeLiteral>() {}); diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index fdea5bb..24d76ab 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,4 +1,12 @@ +import com.guicedee.guicedinjection.interfaces.IGuiceConfigurator; +import com.guicedee.guicedinjection.interfaces.IGuiceModule; +import com.jwebmp.core.client.implementations.JWebMPClientBinder; +import com.jwebmp.core.client.implementations.JWebMPClientConfiguration; + module com.jwebmp.client { + uses com.jwebmp.interception.services.AjaxCallIntercepter; + uses com.jwebmp.interception.services.DataCallIntercepter; + uses com.jwebmp.interception.services.SiteCallIntercepter; exports com.jwebmp.core.base.ajax; exports com.jwebmp.core.base.client; exports com.jwebmp.core.base.html.attributes; @@ -34,6 +42,11 @@ requires static lombok; requires static org.apache.commons.lang3; + requires transitive net.sf.uadetector.core; + requires transitive net.sf.uadetector.resources; + + provides IGuiceModule with JWebMPClientBinder; + provides IGuiceConfigurator with JWebMPClientConfiguration; opens com.jwebmp.core.base.ajax to com.fasterxml.jackson.databind; opens com.jwebmp.core.base.client to com.fasterxml.jackson.databind; diff --git a/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceConfigurator b/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceConfigurator new file mode 100644 index 0000000..ba0cf47 --- /dev/null +++ b/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceConfigurator @@ -0,0 +1 @@ +com.jwebmp.core.client.implementations.JWebMPClientConfiguration \ No newline at end of file diff --git a/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceModule b/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceModule new file mode 100644 index 0000000..474486f --- /dev/null +++ b/src/main/resources/META-INF/services/com.guicedee.guicedinjection.interfaces.IGuiceModule @@ -0,0 +1 @@ +com.jwebmp.core.client.implementations.JWebMPClientBinder \ No newline at end of file