package jtwitter;
import java.net.MalformedURLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TwitterEntry {
// Twitter Entry Nodes (each corresponds to a XML node with the same
name)
public static final String CREATED_AT = "created_at";
public static final String ID = "id";
public static final String TEXT = "text";
public static final String SOURCE = "source";
private Date createdAt;
private int id;
private String text;
private String source;
private TwitterUser user;
//This is currently the date format used by twitter
public static final String TWITTER_DATE_FORMAT = "EEE MMM dd kk:mm:ss
Z yyyy";
public TwitterEntry(Date createdAt, int id, String text, String
source, TwitterUser user) {
super();
this.createdAt = createdAt;
this.id = id;
this.text = text;
this.source = source;
this.user = user;
}
public TwitterEntry() {
this.user = new TwitterUser();
}
public Date getCreatedAt()
{
return createdAt;
}
public void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getText()
{
return text;
}
public void setText(String text)
{
this.text = text;
}
public String getSource()
{
return source;
}
public void setSource(String source)
{
this.source = source;
}
public TwitterUser getUser()
{
return user;
}
public void setUser(TwitterUser user)
{
this.user = user;
}
@Override
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + id;
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final TwitterEntry other = (TwitterEntry) obj;
if (id != other.id)
return false;
return true;
}
public void addAttribute(String key, String value)
throws ParseException, MalformedURLException {
if(key.equals(CREATED_AT))
this.setCreatedAt(makeDate(value));
else if(key.equals(ID))
this.setId(Integer.parseInt(value));
else if (key.equals(TEXT))
this.setText(value);
else if (key.equals(SOURCE))
this.setSource(value);
else if (key.equals(TwitterUser.NAME))
this.getUser().setName(value);
else if (key.equals(TwitterUser.SCREEN_NAME))
this.getUser().setScreenName(value);
else if (key.equals(TwitterUser.LOCATION))
this.getUser().setLocation(value);
else if (key.equals(TwitterUser.DESCRIPTION))
this.getUser().setDescription(value);
else if (key.equals(TwitterUser.PROFILE_IMAGE_URL))
this.getUser().setProfileImageURL(value);
else if (key.equals(TwitterUser.URL))
this.getUser().setUrl(value);
else if (key.equals(TwitterUser.IS_PROTECTED))
this.getUser().setProtected(Boolean.parseBoolean(value));
}
public String toString() {
return "Created At: " + this.getCreatedAt() + "; "
+ "Status: " + this.getText() + "; "
+ "User: " + this.getUser();
}
private Date makeDate(String date)
throws ParseException {
return new SimpleDateFormat(TWITTER_DATE_FORMAT,
Locale.US).parse
(date);
}
}
On Apr 16, 7:41 am, Cameron Kaiser <[email protected]> wrote:
> > I have a Twitter application that I created in Java and I am able to
> > get the source parameter by using XMLParser.
>
> > I have my application to where it displays "Username from Source,
> > Status Text"
>
> > Username works perfectly, but source only displays when a user updates
> > from the web, if they updated from a different application, all it
> > displays is "<".
>
> > Can anyone shed some light on this?
>
> A relevant section of code is always helpful.
>
> --
> ------------------------------------ personal:http://www.cameronkaiser.com/--
> Cameron Kaiser * Floodgap Systems *www.floodgap.com* [email protected]
> -- Put down your guns, it's Weasel Stomping Day!
> ------------------------------