Skip to content

Commit

Permalink
Base Servlet support for JWebMP
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Apr 26, 2024
1 parent 63d9ad4 commit b487a49
Show file tree
Hide file tree
Showing 38 changed files with 1,008 additions and 214 deletions.
13 changes: 3 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@
</dependency>

<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
</dependency>
<dependency>
<groupId>com.jwebmp.core</groupId>
<artifactId>jwebmp-testlib</artifactId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/jwebmp/core/annotations/PageConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 GedMarc
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jwebmp.core.annotations;

import com.guicedee.services.jsonrepresentation.json.StaticStrings;

import java.lang.annotation.*;

/**
* @author GedMarc
* @since 05 Apr 2017
*/
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface PageConfiguration
{
/**
* Specifies the URL that this page serves
*
* @return
*/
String url() default StaticStrings.STRING_FORWARD_SLASH;

/**
* Specifies the type this page serves (best to leave it alone - or only use one page for error types etc)
*
* @return
*/
PageTypes type() default PageTypes.Default;

/**
* If this configuration should be ignored on deployed
*
* @return
*/
boolean ignore() default false;
}
58 changes: 58 additions & 0 deletions src/main/java/com/jwebmp/core/annotations/PageTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2017 GedMarc
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jwebmp.core.annotations;

/**
* @author GedMarc
* @since 05 Apr 2017
*/
public enum PageTypes
{
Default,
Mobile,
Error;
/**
* Any sub data
*/
private String data;

/**
* A new PageTypes
*/
PageTypes()
{

}

/**
* Returns the name or the data contained within
*
* @return
*/
@Override
public String toString()
{
if (data != null && !data.isEmpty())
{
return data;
}
else
{
return name();
}
}
}
95 changes: 3 additions & 92 deletions src/main/java/com/jwebmp/core/base/ajax/AjaxCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.OutOfScopeException;
import com.google.inject.ProvisionException;
import com.google.inject.name.Names;
import com.guicedee.client.IGuiceContext;
import com.guicedee.guicedinjection.interfaces.ObjectBinderKeys;
import com.guicedee.guicedservlets.servlets.services.scopes.CallScope;
import com.jwebmp.core.base.interfaces.IComponentHierarchyBase;
import com.jwebmp.core.htmlbuilder.javascript.JavaScriptPart;
import com.jwebmp.core.services.IEventTypes;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import jakarta.websocket.Session;

import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -110,16 +102,6 @@ public class AjaxCall<J extends AjaxCall<J>>
* The given path route for the application
*/
private String route;
/**
* If this call originates through a web socket (so there is no request or session scope),
* or if it is a direct page call
*/
private boolean isWebSocketCall;
/**
* The web socket session for this call
*/
@JsonIgnore
private Session websocketSession;

/**
* If this is a page or a supporting servlet call
Expand All @@ -137,28 +119,6 @@ public AjaxCall()
//set nothing
}

@Inject
void configure()
{
try
{
//@see guiced-servlets, this is a default key
HttpServletRequest request = IGuiceContext.get(Key.get(HttpServletRequest.class, Names.named("Servlet")));
for (Map.Entry<String, String[]> entry : request.getParameterMap()
.entrySet())
{
String key = entry.getKey();
String[] value = entry.getValue();
getParameters()
.put(key, value[0]);
}
}
catch (OutOfScopeException | ProvisionException e)
{
//ignore
}
}

public String getAttribute(String attribute)
{
if (getAttributes() != null && getAttributes()
Expand Down Expand Up @@ -239,8 +199,6 @@ public J fromCall(AjaxCall<?> incoming)
setLocalStorage(incoming.getLocalStorage());
setSessionStorage(incoming.getSessionStorage());
setHashBang(incoming.getHashBang());
setWebsocketSession(incoming.getWebsocketSession());
setWebSocketCall(incoming.isWebSocketCall());
unknownFields = Map.copyOf(incoming.unknownFields);

return (J) this;
Expand Down Expand Up @@ -296,55 +254,8 @@ public J setEventType(IEventTypes<?> eventType)
return (J) this;
}

/**
* If this call originates through a web socket (so there is no request or session scope),
* * or if it is a direct page call
*
* @return
*/
public boolean isWebSocketCall()
{
return isWebSocketCall;
}

/**
* If this call originates through a web socket (so there is no request or session scope),
* * or if it is a direct page call
*
* @param webSocketCall
*/
@SuppressWarnings("unchecked")
public J setWebSocketCall(boolean webSocketCall)
{
isWebSocketCall = webSocketCall;
return (J) this;
}

/**
* The web socket session for this call
*
* @return
*/
public Session getWebsocketSession()
{
return websocketSession;
}

/**
* The web socket session for this call
*
* @param websocketSession
* @return
*/
@SuppressWarnings("unchecked")
public J setWebsocketSession(Session websocketSession)
{
this.websocketSession = websocketSession;
return (J) this;
}

@Override
@NotNull

public Map<String, String> getParameters()
{
if (parameters == null)
Expand All @@ -363,14 +274,14 @@ public J setParameters(Map<String, String> parameters)
}

@Override
@NotNull

public String getClassName()
{
return className;
}

@Override
@NotNull

@SuppressWarnings("unchecked")
public J setClassName(String className)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package com.jwebmp.core.base.ajax;

import com.fasterxml.jackson.annotation.*;
import com.jwebmp.core.base.interfaces.*;
import com.jwebmp.core.htmlbuilder.javascript.*;
import jakarta.validation.constraints.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jwebmp.core.base.interfaces.IComponentHierarchyBase;
import com.jwebmp.core.htmlbuilder.javascript.JavaScriptPart;


/**
* A JSON Class for component updates
Expand Down Expand Up @@ -72,7 +72,7 @@ public String getHtml()
* @param html
*/
@SuppressWarnings("unchecked")
@NotNull

public J setHtml(String html)
{
this.html = html;
Expand All @@ -95,7 +95,7 @@ public String getId()
* @param id
*/
@SuppressWarnings("unchecked")
@NotNull

public J setId(String id)
{
this.id = id;
Expand All @@ -118,7 +118,7 @@ public AjaxComponentInsertType getInsertType()
* @param insertType
*/
@SuppressWarnings("unchecked")
@NotNull

public J setInsertType(AjaxComponentInsertType insertType)
{
this.insertType = insertType;
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/jwebmp/core/base/ajax/AjaxResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/
package com.jwebmp.core.base.ajax;

import com.fasterxml.jackson.annotation.*;
import com.guicedee.guicedservlets.servlets.services.scopes.*;
import com.guicedee.services.jsonrepresentation.*;
import com.jwebmp.core.base.servlets.interfaces.*;
import com.jwebmp.core.htmlbuilder.javascript.*;
import jakarta.validation.constraints.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.guicedee.guicedservlets.servlets.services.scopes.CallScope;
import com.guicedee.services.jsonrepresentation.IJsonRepresentation;
import com.jwebmp.core.base.servlets.interfaces.IFeature;
import com.jwebmp.core.htmlbuilder.javascript.JavaScriptPart;

import java.util.*;

Expand Down Expand Up @@ -175,7 +176,7 @@ public J addFeature(IFeature<?, ?> feature) {
* @param reaction
*/
@SuppressWarnings("unchecked")
@NotNull

public J addReaction(AjaxResponseReaction<?> reaction) {
getReactions().add(reaction);
return (J) this;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/jwebmp/core/base/ajax/IAjaxCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package com.jwebmp.core.base.ajax;

import com.guicedee.services.jsonrepresentation.*;
import com.jwebmp.core.base.interfaces.*;
import com.jwebmp.core.services.*;
import jakarta.validation.constraints.*;
import com.guicedee.services.jsonrepresentation.IJsonRepresentation;
import com.jwebmp.core.base.interfaces.IComponentHierarchyBase;
import com.jwebmp.core.services.IEventTypes;

import java.util.*;
import java.util.Date;
import java.util.Map;

public interface IAjaxCall<J extends AjaxCall<J>> extends IJsonRepresentation<J>
{
Expand Down Expand Up @@ -99,7 +99,7 @@ public interface IAjaxCall<J extends AjaxCall<J>> extends IJsonRepresentation<J>
*
* @return
*/
@NotNull

Map<String, String> getParameters();

/**
Expand All @@ -115,15 +115,15 @@ public interface IAjaxCall<J extends AjaxCall<J>> extends IJsonRepresentation<J>
*
* @return
*/
@NotNull

String getClassName();

/**
* Sets the class name this event is associated with
*
* @param className
*/
@NotNull


J setClassName(String className);
}
Loading

0 comments on commit b487a49

Please sign in to comment.