Skip to content
Browse files

Keep provider menu items from appearing if the user isn't connected t…

…o that provider.
  • Loading branch information...
1 parent 3431555 commit b267e7fe528b47c6448989c764f9412822a46ff8 Craig Walls committed Apr 23, 2011
View
43 ...va/org/springframework/social/showcase/facebook/FacebookConnectionHandlerInterceptor.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * 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.springframework.social.showcase.facebook;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.social.connect.ServiceProviderConnection;
+import org.springframework.social.connect.ServiceProviderConnectionRepository;
+import org.springframework.social.facebook.api.FacebookApi;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+public class FacebookConnectionHandlerInterceptor extends HandlerInterceptorAdapter {
+
+ private final ServiceProviderConnectionRepository connectionRepository;
+
+ @Inject
+ public FacebookConnectionHandlerInterceptor(ServiceProviderConnectionRepository connectionRepository) {
+ this.connectionRepository = connectionRepository;
+ }
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ ServiceProviderConnection<FacebookApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(FacebookApi.class);
+ request.setAttribute("connectedToFacebook", connection != null);
+ return true;
+ }
+
+}
View
43 ...java/org/springframework/social/showcase/twitter/TwitterConnectionHandlerInterceptor.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * 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.springframework.social.showcase.twitter;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.social.connect.ServiceProviderConnection;
+import org.springframework.social.connect.ServiceProviderConnectionRepository;
+import org.springframework.social.twitter.api.TwitterApi;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+public class TwitterConnectionHandlerInterceptor extends HandlerInterceptorAdapter {
+
+ private final ServiceProviderConnectionRepository connectionRepository;
+
+ @Inject
+ public TwitterConnectionHandlerInterceptor(ServiceProviderConnectionRepository connectionRepository) {
+ this.connectionRepository = connectionRepository;
+ }
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ ServiceProviderConnection<TwitterApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(TwitterApi.class);
+ request.setAttribute("connectedToTwitter", connection != null);
+ return true;
+ }
+
+}
View
6 spring-social-showcase/src/main/webapp/WEB-INF/layouts/menu.jsp
@@ -2,22 +2,24 @@
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<h4><a href="<c:url value="/twitter"/>">Twitter</a></h4>
-<%-- TODO: Keep provider-menu items from appearing unless the user is connected to that provider --%>
+<c:if test="${connectedToTwitter}">
<ul class="menu">
<li><a href="<c:url value="/twitter"/>">User Profile</a></li>
<li><a href="<c:url value="/twitter/timeline"/>">Timeline</a></li>
<li><a href="<c:url value="/twitter/friends"/>">Friends</a></li>
<li><a href="<c:url value="/twitter/followers"/>">Followers</a></li>
<li><a href="<c:url value="/twitter/messages"/>">Messages</a></li>
</ul>
+</c:if>
<h4><a href="<c:url value="/facebook"/>">Facebook</a></h4>
-<%-- TODO: Keep provider-menu items from appearing unless the user is connected to that provider --%>
+<c:if test="${connectedToFacebook}">
<ul class="menu">
<li><a href="<c:url value="/facebook"/>">User Profile</a></li>
<li><a href="<c:url value="/facebook/feed"/>">Feed</a></li>
<li><a href="<c:url value="/facebook/friends"/>">Friends</a></li>
<li><a href="<c:url value="/facebook/albums"/>">Albums</a></li>
</ul>
+</c:if>
<h4><a href="<c:url value="/tripit"/>">TripIt</a></h4>
View
5 spring-social-showcase/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -11,6 +11,11 @@
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
+ <interceptors>
+ <beans:bean class="org.springframework.social.showcase.twitter.TwitterConnectionHandlerInterceptor" />
+ <beans:bean class="org.springframework.social.showcase.facebook.FacebookConnectionHandlerInterceptor" />
+ </interceptors>
+
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
View
10 spring-social-showcase/src/main/webapp/WEB-INF/views/tripit/tripit.jsp
@@ -3,12 +3,8 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<%@ page session="false" %>
-<html>
-<head>
- <title>Spring Social Showcase: TripIt</title>
-</head>
-<body>
-<h1>Spring Social Showcase: TripIt</h1>
+
+<h3>Your TripIt Profile</h3>
<p>Hello <c:out value="${tripItUser.publicDisplayName}"/>!</p>
<p>Your TripIt profile:</p>
@@ -18,7 +14,7 @@
<li>Company: <c:out value="${tripItUser.company}"/></li>
</ul>
-<p>Your upcoming trips:</p>
+<h3>Your upcoming trips:</h3>
<ul>
<c:forEach items="${trips}" var="trip">
<li>"<c:out value="${trip.displayName}"/>" - Destination: <c:out value="${trip.primaryLocation}"/>;

0 comments on commit b267e7f

Please sign in to comment.
Something went wrong with that request. Please try again.