Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
60b94b7c
Commit
60b94b7c
authored
Nov 09, 2013
by
Matija Obreza
Browse files
Added a filter to add variables to requests (GA)
parent
9ebad3c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/servlet/filter/EnvVariablesFilter.java
0 → 100644
View file @
60b94b7c
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed 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.genesys2.server.servlet.filter
;
import
java.io.IOException
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.filter.OncePerRequestFilter
;
@Component
(
"envVarFilter"
)
public
class
EnvVariablesFilter
extends
OncePerRequestFilter
{
@Value
(
"${google.analytics.account}"
)
private
String
googleAnalyticsAccount
;
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
filterChain
)
throws
ServletException
,
IOException
{
if
(
StringUtils
.
isNotBlank
(
googleAnalyticsAccount
))
{
request
.
setAttribute
(
"googleAnalyticsAccount"
,
googleAnalyticsAccount
);
}
filterChain
.
doFilter
(
request
,
response
);
}
}
\ No newline at end of file
src/main/resources/spring/servlet.xml
View file @
60b94b7c
...
...
@@ -45,7 +45,7 @@
<mvc:default-servlet-handler/>
<!--Controllers-->
<context:component-scan
base-package=
"org.genesys2.server.servlet.controller"
/>
<context:component-scan
base-package=
"org.genesys2.server.servlet.
filter,org.genesys2.server.servlet.
controller"
/>
<aop:aspectj-autoproxy/>
...
...
src/main/webapp/WEB-INF/decorator/footer.jsp
View file @
60b94b7c
...
...
@@ -29,6 +29,19 @@
</div>
</div>
<c:if
test=
"
${
googleAnalyticsAccount
ne
null
}
"
>
<script
type=
"text/javascript"
>
var
_gaq
=
_gaq
||
[];
_gaq
.
push
([
'
_setAccount
'
,
'
${googleAnalyticsAccount}
'
]);
_gaq
.
push
([
'
_trackPageview
'
]);
(
function
()
{
var
ga
=
document
.
createElement
(
'
script
'
);
ga
.
type
=
'
text/javascript
'
;
ga
.
async
=
true
;
ga
.
src
=
(
'
https:
'
==
document
.
location
.
protocol
?
'
https://ssl
'
:
'
http://www
'
)
+
'
.google-analytics.com/ga.js
'
;
var
s
=
document
.
getElementsByTagName
(
'
script
'
)[
0
];
s
.
parentNode
.
insertBefore
(
ga
,
s
);
})();
</script>
</c:if>
<!-- Processing time:
<div class="footer clearfix" style="font-size: 80%">
<spring:message
code=
"page.rendertime"
arguments=
"
${
springExecuteTime
}
"
/>
</div>
...
...
src/main/webapp/WEB-INF/web.xml
View file @
60b94b7c
...
...
@@ -42,6 +42,16 @@
<filter-name>
org.springframework.security.filterChainProxy
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<filter>
<filter-name>
envVarFilter
</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<description>
Adds variables to all requests
</description>
</filter>
<filter-mapping>
<filter-name>
envVarFilter
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<filter>
<filter-name>
sitemesh
</filter-name>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment