001/** 002 * Copyright 2014 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package service.tut.pori.twitterjazz; 017 018import java.util.Date; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlRootElement; 024import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 025 026import twitter4j.Status; 027import core.tut.pori.utils.ISODateAdapter; 028 029/** 030 * A status message received from Twitter. 031 * 032 * <h3>XML Example</h3> 033 * 034 * {@doc.restlet service="[service.tut.pori.twitterjazz.reference.Definitions#SERVICE_TJ_REFERENCE_EXAMPLE]" method="[service.tut.pori.twitterjazz.Definitions#ELEMENT_STATUS_MESSAGE]" type="GET" query="" body_uri=""} 035 * 036 * @see twitter4j.Status 037 */ 038@XmlRootElement(name=Definitions.ELEMENT_STATUS_MESSAGE) 039@XmlAccessorType(XmlAccessType.NONE) 040public class TwitterStatusMessage { 041 @XmlElement(name = Definitions.ELEMENT_MESSAGE_POSTER) 042 private String _fromName = null; 043 @XmlElement(name = Definitions.ELEMENT_MESSAGE) 044 private String _message = null; 045 @XmlJavaTypeAdapter(ISODateAdapter.class) 046 @XmlElement(name = Definitions.ELEMENT_UPDATED_TIMESTAMP) 047 private Date _updatedTime = null; 048 049 /** 050 * 051 * @param status 052 * @return status message or null if the passed status was null 053 */ 054 public static TwitterStatusMessage getTwitterStatusMessage(Status status){ 055 if(status == null){ 056 return null; 057 } 058 TwitterStatusMessage message = new TwitterStatusMessage(); 059 message._fromName = status.getUser().getScreenName(); 060 message._message = status.getText(); 061 message._updatedTime = status.getCreatedAt(); 062 return message; 063 } 064 065 /** 066 * @see twitter4j.Status#getUser() 067 * @see twitter4j.User#getScreenName() 068 * @see #setFromName(String) 069 * 070 * @return the fromName 071 */ 072 public String getFromName() { 073 return _fromName; 074 } 075 076 /** 077 * @param fromName the fromName to set 078 * @see #getFromName() 079 */ 080 public void setFromName(String fromName) { 081 _fromName = fromName; 082 } 083 084 /** 085 * @see twitter4j.Status#getText() 086 * 087 * @return the message 088 * @see #setMessage(String) 089 */ 090 public String getMessage() { 091 return _message; 092 } 093 094 /** 095 * @param message the message to set 096 * @see #getMessage() 097 */ 098 public void setMessage(String message) { 099 _message = message; 100 } 101 102 /** 103 * @see twitter4j.Status#getCreatedAt() 104 * @see #setUpdatedTime(Date) 105 * 106 * @return the updatedTime 107 */ 108 public Date getUpdatedTime() { 109 return _updatedTime; 110 } 111 112 /** 113 * @param updatedTime the updatedTime to set 114 * @see #getUpdatedTime() 115 */ 116 public void setUpdatedTime(Date updatedTime) { 117 _updatedTime = updatedTime; 118 } 119}