Skip to content

Commit

Permalink
Fixes piranhacloud#4184 - Refactor web.xml processing to hide WebXmlX…
Browse files Browse the repository at this point in the history
…XX as internal API (piranhacloud#4443)
  • Loading branch information
mnriem authored Dec 30, 2024
1 parent b191881 commit 486ed85
Show file tree
Hide file tree
Showing 43 changed files with 97 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
*/
package cloud.piranha.extension.webxml;

import cloud.piranha.extension.webxml.internal.InternalWebXmlParser;
import cloud.piranha.extension.webxml.internal.InternalWebXmlProcessor;
import cloud.piranha.extension.webxml.internal.InternalWebXmlManager;
import cloud.piranha.extension.webxml.internal.WebXmlParser;
import cloud.piranha.extension.webxml.internal.WebXmlProcessor;
import cloud.piranha.extension.webxml.internal.WebXmlManager;
import cloud.piranha.core.api.WebApplication;
import cloud.piranha.extension.webxml.internal.WebXmlManager;
import cloud.piranha.extension.webxml.internal.WebXmlParser;
import cloud.piranha.extension.webxml.internal.WebXmlProcessor;
import cloud.piranha.extension.webxml.internal.WebXml;
import cloud.piranha.extension.webxml.internal.WebXmlServletMapping;
import jakarta.servlet.ServletContainerInitializer;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -76,10 +81,10 @@ public void onStartup(Set<Class<?>> classes, ServletContext servletContext) thro

try {
WebApplication webApplication = (WebApplication) servletContext;
InternalWebXmlManager manager = new InternalWebXmlManager();
WebXmlManager manager = new WebXmlManager();
webApplication.setAttribute("cloud.piranha.extension.webxml.WebXmlManager", manager);

InternalWebXmlParser parser = new InternalWebXmlParser();
WebXmlParser parser = new WebXmlParser();
InputStream inputStream = servletContext.getResourceAsStream("WEB-INF/web.xml");
if (inputStream != null) {
WebXml webXml = parser.parse(servletContext.getResourceAsStream("WEB-INF/web.xml"));
Expand All @@ -106,7 +111,7 @@ public void onStartup(Set<Class<?>> classes, ServletContext servletContext) thro

if (manager.getWebXml() != null) {
WebXml webXml = manager.getWebXml();
InternalWebXmlProcessor processor = new InternalWebXmlProcessor();
WebXmlProcessor processor = new WebXmlProcessor();

processor.process(webXml, webApplication);

Expand Down Expand Up @@ -134,7 +139,7 @@ public void onStartup(Set<Class<?>> classes, ServletContext servletContext) thro
* @param webApp the web application.
* @param manager the web.xml manager.
*/
private void removeExistingServletMappings(WebApplication webApp, InternalWebXmlManager manager) {
private void removeExistingServletMappings(WebApplication webApp, WebXmlManager manager) {
for(WebXmlServletMapping mapping : manager.getWebXml().getServletMappings()) {
for(WebXml fragment : manager.getOrderedFragments()) {
ArrayList<WebXmlServletMapping> candidateList = new ArrayList<>(fragment.getServletMappings());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A context-param inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* An error-page inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A filter init-param inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A taglib inside jsp-config of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A listener inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A login-config inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
*/
package cloud.piranha.extension.webxml.internal;

import cloud.piranha.extension.webxml.WebXml;
import static cloud.piranha.extension.webxml.WebXml.OTHERS_TAG;
import cloud.piranha.extension.webxml.WebXmlManager;
import static cloud.piranha.extension.webxml.internal.WebXml.OTHERS_TAG;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -47,7 +45,7 @@
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class InternalWebXmlManager implements WebXmlManager {
public class WebXmlManager {

/**
* Stores the initial web.xml
Expand Down Expand Up @@ -96,7 +94,11 @@ public void setWebFragments(List<WebXml> webFragments) {
this.webFragments = webFragments;
}

@Override
/**
* Get the web.xml.
*
* @return the web.xml.
*/
public WebXml getWebXml() {
return webXml;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A mime-mapping inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package cloud.piranha.extension.webxml.internal;

import static cloud.piranha.extension.webxml.WebXml.OTHERS_TAG;
import static cloud.piranha.extension.webxml.internal.WebXml.OTHERS_TAG;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.WARNING;
import static java.util.regex.Pattern.quote;
Expand Down Expand Up @@ -55,31 +55,13 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import cloud.piranha.extension.webxml.WebXml;
import cloud.piranha.extension.webxml.WebXmlContextParam;
import cloud.piranha.extension.webxml.WebXmlDataSource;
import cloud.piranha.extension.webxml.WebXmlErrorPage;
import cloud.piranha.extension.webxml.WebXmlFilter;
import cloud.piranha.extension.webxml.WebXmlFilterInitParam;
import cloud.piranha.extension.webxml.WebXmlFilterMapping;
import cloud.piranha.extension.webxml.WebXmlJspConfigTaglib;
import cloud.piranha.extension.webxml.WebXmlListener;
import cloud.piranha.extension.webxml.WebXmlLoginConfig;
import cloud.piranha.extension.webxml.WebXmlMimeMapping;
import cloud.piranha.extension.webxml.WebXmlSecurityConstraint;
import cloud.piranha.extension.webxml.WebXmlServlet;
import cloud.piranha.extension.webxml.WebXmlServletInitParam;
import cloud.piranha.extension.webxml.WebXmlServletMapping;
import cloud.piranha.extension.webxml.WebXmlServletMultipartConfig;
import cloud.piranha.extension.webxml.WebXmlServletSecurityRoleRef;
import cloud.piranha.extension.webxml.WebXmlSessionConfig;

/**
* The web.xml / web-fragment.xml parser.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class InternalWebXmlParser {
public class WebXmlParser {

/**
* Stores the 'location/text()' selector.
Expand All @@ -89,7 +71,7 @@ public class InternalWebXmlParser {
/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(InternalWebXmlParser.class.getName());
private static final Logger LOGGER = System.getLogger(WebXmlParser.class.getName());

/**
* Stores the 'param-name/text()' selector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,9 @@
import cloud.piranha.core.api.SecurityRoleReference;
import cloud.piranha.core.api.SecurityWebResourceCollection;
import cloud.piranha.core.api.WebApplication;
import cloud.piranha.extension.webxml.WebXml;
import cloud.piranha.extension.webxml.WebXmlContextParam;
import cloud.piranha.extension.webxml.WebXmlDataSource;
import cloud.piranha.extension.webxml.WebXmlErrorPage;
import cloud.piranha.extension.webxml.WebXmlFilterInitParam;
import cloud.piranha.extension.webxml.WebXmlJspConfigTaglib;
import cloud.piranha.extension.webxml.WebXmlListener;
import cloud.piranha.extension.webxml.WebXmlLoginConfig;
import cloud.piranha.extension.webxml.WebXmlServlet;
import cloud.piranha.extension.webxml.WebXmlServletMapping;
import cloud.piranha.extension.webxml.WebXmlServletMultipartConfig;
import cloud.piranha.extension.webxml.WebXmlSessionConfig;
import cloud.piranha.core.api.WelcomeFileManager;
import cloud.piranha.core.impl.DefaultJspConfigDescriptor;
import cloud.piranha.core.impl.DefaultTaglibDescriptor;
import cloud.piranha.extension.webxml.WebXmlSecurityConstraint;
import cloud.piranha.extension.webxml.WebXmlServletSecurityRoleRef;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import jakarta.servlet.MultipartConfigElement;
Expand All @@ -81,12 +67,12 @@
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class InternalWebXmlProcessor {
public class WebXmlProcessor {

/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(InternalWebXmlProcessor.class.getName());
private static final Logger LOGGER = System.getLogger(WebXmlProcessor.class.getName());

/**
* Stores the empty string array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A servlet init-param inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A servlet-mapping inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A servlet multipart-config inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A servlet security-role-ref inside of web.xml/web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A session-config inside of web.xml or web-fragment.xml.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.webxml;
package cloud.piranha.extension.webxml.internal;

/**
* A session-config cookie-config inside of web.xml/web-fragment.xml.
Expand Down
Loading

0 comments on commit 486ed85

Please sign in to comment.