/** * Twitterの取得 * * @throws IOException */ private String getMessage(ActivityModel activityModel, String shortUrl) throws Exception { String twitterMessage = null; // 再共有の場合 if (activityModel.getVerb().getCategory().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_SHARE)) { // 追加コメントが存在しない場合 if (activityModel.getAnnotationString() == null) { // タイトルが存在しない場合 if (activityModel.getTitleString() == null) { return "[ #PluCial " + shortUrl + " ]"; // タイトル存在する場合 } else { twitterMessage = activityModel.getTitleString(); } // 追加コメントが存在する場合 } else { twitterMessage = activityModel.getAnnotationString(); } // 通常投稿の場合 } else { // タイトルが存在しない場合 if (activityModel.getTitleString() == null) { // 添付コンテンツのタイトルが存在しない場合 if (activityModel.getAttachmentsDisplayNameString() == null) { return "[ #PluCial " + shortUrl + " ]"; // 添付コンテンツのタイトルが存在する場合 } else { twitterMessage = activityModel.getAttachmentsDisplayNameString(); } // タイトル存在する場合 } else { twitterMessage = activityModel.getTitleString(); } } if (twitterMessage == null) { return "[ #PluCial " + shortUrl + " ]"; } else { // リンクタグを削除 twitterMessage = Utils.removeLinkTags(twitterMessage); // 太文字を削除 twitterMessage = Utils.removeBTags(twitterMessage); // 改行の変換 twitterMessage = twitterMessage.replace("<br>", "\n"); // spanタグを削除 twitterMessage = Utils.removeSpanTags(twitterMessage); } String lastString = ("\n[ #PluCial " + shortUrl + " ]"); int limit_num = 100; // 画像の場合はTwitterメディア分の23文字を減らす if (activityModel.getAttachmentsType() != null && (activityModel .getAttachmentsType() .getCategory() .equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_PHOTO) || activityModel .getAttachmentsType() .getCategory() .equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ALBUM)) && activityModel.getVerb().getCategory().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_POST)) { limit_num = limit_num - 23; } // ドメイン分 の 23文字を削減 int domainCount = getDomainCount(twitterMessage); limit_num = limit_num - (domainCount * 23); // URL複数含まれる投稿はマイナスになる可能性がある if (limit_num < 0) return "[ #PluCial " + shortUrl + " ]"; // タイトルの文字数が問題ない場合 if (twitterMessage.length() <= limit_num) return twitterMessage + lastString; // タイトルの文字数が制限オーバーの場合 String message = twitterMessage.substring(0, limit_num - 3) + "..."; return message + lastString; }