Skip to content

Commit

Permalink
Minor refactoring about package names
Browse files Browse the repository at this point in the history
Added comments
  • Loading branch information
antoinesd committed Mar 16, 2011
1 parent ad798d8 commit 2466694
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 69 deletions.
@@ -1,15 +1,31 @@
/**
*
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.seam.social.linkedin.model;

import org.jboss.seam.social.oauth.OAuthUser;
import org.jboss.seam.social.oauth.User;

/**
* @author antoine
*
* Implementation of this interface will contain a LinkedIn Profile
*
* @author Antoine Sabot-Durand
*
*/
public interface LinkedInProfile extends OAuthUser
public interface LinkedInProfile extends User
{

public void setHeadline(String headline);
Expand Down
Expand Up @@ -30,7 +30,7 @@ public interface OAuthServiceHandler
*
* @return the access token for the OAuth service
*/
public String getAccessToken();
public OAuthToken getAccessToken();

/**
* Returns the url to the OAuth service to ask an authorization to access the service.
Expand Down Expand Up @@ -104,7 +104,13 @@ public interface OAuthServiceHandler

public Boolean isConnected();

public OAuthUser getUser();
public User getUser();

public String getType();

public void setAccessToken(String api, String secret);

public void setAccessToken(OAuthToken token);


}
Expand Up @@ -17,8 +17,8 @@
package org.jboss.seam.social.oauth;

/**
* Interface for model containing settings to access to an OAuth 1.0a service
* It's used by {@link OAuthServiceHandler} to setup connexion to OAuth Service
* Interface for model containing settings needed to access to an OAuth 1.0a service
* It's used by {@link OAuthServiceHandler} to setup connection to OAuth Service
*
* @author Antoine Sabot-Durand
* @see OAuthServiceHandler
Expand Down
Expand Up @@ -13,12 +13,18 @@
* 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.jboss.seam.social.oauth;
*/
package org.jboss.seam.social.oauth;

import org.jboss.seam.social.twitter.TwitterHandler;


public interface OAuthUser
/**
*
* Interface defining an user
*
* @author Antoine Sabot-Durand
*
*/
public interface User
{

public String getFullName();
Expand Down
Expand Up @@ -16,9 +16,9 @@
*/
package org.jboss.seam.social.twitter;

import org.jboss.seam.social.oauth.OAuthUser;
import org.jboss.seam.social.oauth.User;
import org.jboss.seam.social.oauth.OAuthServiceHandler;
import org.jboss.seam.social.twitter.domain.Tweet;
import org.jboss.seam.social.twitter.model.Tweet;


/**
Expand Down Expand Up @@ -47,6 +47,6 @@ public interface TwitterHandler extends OAuthServiceHandler
*
* @return the crendential of the user
*/
public OAuthUser verifyCrendentials();
public User verifyCrendentials();

}
Expand Up @@ -13,7 +13,7 @@
* 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.jboss.seam.social.twitter.domain;
*/package org.jboss.seam.social.twitter.model;

import java.util.List;

Expand Down
Expand Up @@ -13,7 +13,7 @@
* 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.jboss.seam.social.twitter.domain;
*/package org.jboss.seam.social.twitter.model;


/**
Expand Down
@@ -1,9 +1,9 @@
/**
*
*/
package org.jboss.seam.social.twitter.domain;
package org.jboss.seam.social.twitter.model;

import org.jboss.seam.social.oauth.OAuthUser;
import org.jboss.seam.social.oauth.User;
import org.jboss.seam.social.twitter.TwitterHandler;

/**
Expand All @@ -14,7 +14,7 @@
* @author Antoine Sabot-Durand
*
*/
public interface TwitterCredential extends OAuthUser
public interface TwitterCredential extends User
{


Expand Down
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.seam.social.twitter.domain;
package org.jboss.seam.social.twitter.model;

/**
* This package contains model elements to store and send data to Twitter
Expand Down
Expand Up @@ -16,19 +16,25 @@
*/
package org.jboss.seam.social.example.webclient;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.seam.social.oauth.OAuthServiceHandler;
import org.jboss.seam.social.oauth.OAuthUser;
import org.jboss.seam.social.oauth.OAuthToken;
import org.jboss.seam.social.oauth.User;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;


Expand All @@ -51,26 +57,55 @@ public class SocialClient implements Serializable
private String status;



private List<OAuthServiceHandler> serviceHandlers;




public List<OAuthServiceHandler> getServiceHandlers()
{
return serviceHandlers;
}




@PostConstruct
public void init()
{

serviceHandlers=Lists.newArrayList(serviceHandlerInstances);

}


public List<OAuthServiceHandler> getConnectedServices()
{
return Lists.newArrayList(Iterables.filter(serviceHandlers, new Predicate<OAuthServiceHandler>()
{

public String getAccessToken()
@Override
public boolean apply(OAuthServiceHandler arg0)
{
return arg0.isConnected();
}
}));
}


public List<OAuthServiceHandler> getUnconnectedServices()
{
return Lists.newArrayList(Iterables.filter(serviceHandlers, new Predicate<OAuthServiceHandler>()
{

@Override
public boolean apply(OAuthServiceHandler arg0)
{
return !arg0.isConnected();
}
}));
}

public OAuthToken getAccessToken()
{
return currentServiceHdl.getAccessToken();
}
Expand All @@ -86,6 +121,8 @@ public void setVerifier(String verifier)
}




public String getAuthorizationURL()
{
return currentServiceHdl.getAuthorizationUrl();
Expand Down Expand Up @@ -119,7 +156,7 @@ public String updateStatus()
return "ok";
}*/

public OAuthUser getUser()
public User getUser()
{
return currentServiceHdl.getUser();
}
Expand All @@ -132,6 +169,18 @@ public OAuthServiceHandler getCurrentServiceHdl()



public void setCurrentServiceHdl(OAuthServiceHandler currentServiceHdl)
{
this.currentServiceHdl = currentServiceHdl;
}


public void gotoAuthorizationURL(OAuthServiceHandler service) throws IOException
{
setCurrentServiceHdl(service);
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect(getAuthorizationURL());
}



Expand Down
9 changes: 3 additions & 6 deletions examples/web-client/src/main/webapp/callback.xhtml
Expand Up @@ -12,12 +12,9 @@
<f:event type="preRenderView" listener="#{socialClient.initAccessToken}" />
</f:metadata>
<h:messages />
<h1>Seam Social Twitter client Example</h1>
<p>Getting Authorization from Twitter</p>

You're back and your verifier is #{socialClient.verifier} !
<br/>
You're ready to use Seam Social <h:link outcome="openclient">Twitter client</h:link>
<h1>Seam Social client Example</h1>
<p>Getting Authorization from #{socialClient.currentServiceHdl.type}</p>
You're ready to use Seam Social <h:link outcome="openclient">client</h:link>

</ui:define>
</ui:composition>
9 changes: 5 additions & 4 deletions examples/web-client/src/main/webapp/home.xhtml
Expand Up @@ -7,12 +7,13 @@
<ui:define name="content">
<h1>Seam Social client Example</h1>
<p>Please click on the button Below to connect Seam Social to your account on the given service</p>

<h:form>
<ui:repeat var="service" value="#{socialClient.serviceHandlers}">
<a href="#{service.authorizationUrl}"><img src="#{service.serviceLogo}" /></a>

<h:commandLink action="#{socialClient.gotoAuthorizationURL(service)}" >
<img src="#{service.serviceLogo}" />
</h:commandLink>
</ui:repeat>

</h:form>

</ui:define>
</ui:composition>
19 changes: 17 additions & 2 deletions examples/web-client/src/main/webapp/timeline.xhtml
Expand Up @@ -6,14 +6,29 @@
template="/WEB-INF/templates/default.xhtml">
<ui:define name="content">
<h:messages />
<h1>Seam Social Twitter client Example</h1>
<h1>Seam Social client Example</h1>
<p>Your (future) Timeline</p>
<h:form>
Welcome #{socialClient.cred.name}<br/>
Welcome #{socialClient.currentServiceHdl.user.fullName}<br/>
You can add those social network :
<ui:repeat var="service" value="#{socialClient.unconnectedServices}">
<h:commandLink action="#{socialClient.gotoAuthorizationURL(service)}" >
<img src="#{service.serviceLogo}" />
</h:commandLink>
</ui:repeat>

Or choose the Social network you want to work with :
<h:selectOneRadio value="#{socialClient.currentServiceHdl}" >
<f:selectItems value="#{socialClient.connectedServices}" var="serv" itemLabel="#{serv.type}"/>
<f:ajax execute="@this" event="valueChange"/>
</h:selectOneRadio>
<ui:remove>
<img src="#{socialClient.cred.profileImageUrl}" />

<h:inputTextarea value="#{socialClient.status}" cols="80" rows="5" />
<h:commandButton action="#{socialClient.updateStatus}"
value="Update your status" />
</ui:remove>
</h:form>
</ui:define>
</ui:composition>

0 comments on commit 2466694

Please sign in to comment.