You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2019/06/05 20:37:24 UTC
[myfaces-tobago] branch master updated: TOBAGO-1633: TS hack to
serve the JS files without ".js" extension
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/master by this push:
new fc81028 TOBAGO-1633: TS hack to serve the JS files without ".js" extension
fc81028 is described below
commit fc8102891db8646c6bbc57615168acb085405996
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed Jun 5 22:37:15 2019 +0200
TOBAGO-1633: TS hack to serve the JS files without ".js" extension
---
.../facelets/HackResourceExtentionFilter.java | 75 ++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/HackResourceExtentionFilter.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/HackResourceExtentionFilter.java
new file mode 100644
index 0000000..68aa4e9
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/HackResourceExtentionFilter.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.facelets;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+
+// XXX hack, whould be nice to find a ES6/TypeScript conform way.
+
+@WebFilter(urlPatterns = "/*")
+public class HackResourceExtentionFilter implements Filter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private String prefix;
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Filter initialized.");
+ }
+ String version = Package.getPackage("org.apache.myfaces.tobago.component").getImplementationVersion();
+ prefix = "/tobago/standard/tobago-bootstrap/" + version + "/js/tobago-";
+ }
+
+ @Override
+ public void doFilter(
+ final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain)
+ throws IOException, ServletException {
+ if (servletRequest instanceof HttpServletRequest && servletResponse instanceof HttpServletResponse) {
+ final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+ final String requestUri = ((HttpServletRequest) servletRequest).getRequestURI();
+ if (requestUri.startsWith(prefix) && !requestUri.endsWith(".js")) {
+ ((HttpServletResponse) servletResponse).sendRedirect(requestUri + ".js");
+ } else {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+ } else {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ }
+}