/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.core.impl;

import java.sql.SQLException;
import java.util.*;
import com.silverwrist.venice.core.*;

class TopicMessageFoundImpl implements TopicMessageFound
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private int cid;
  private int confid;
  private int topicid;
  private int topicnum;
  private long postid;
  private int postnum;
  private String ident;
  private int creator_uid;
  private String creator_name;
  private Date postdate;
  private int linecount;
  private String text;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  TopicMessageFoundImpl(TopicMessageFoundHelper helper, int cid, int confid, int topicid, int topicnum,
			long postid, int postnum, int creator_uid, Date postdate, int linecount, String text)
      throws SQLException
  {
    this.cid = cid;
    this.confid = confid;
    this.topicid = topicid;
    this.topicnum = topicnum;
    this.postid = postid;
    this.postnum = postnum;
    this.ident = helper.getCommunityAlias(cid) + "!" + helper.getConferenceAlias(confid) + "." + topicnum
               + "." + postnum;
    this.creator_uid = creator_uid;
    this.creator_name = helper.getUserName(creator_uid);
    this.postdate = postdate;
    this.linecount = linecount;
    this.text = transformText(text);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Internal operations
   *--------------------------------------------------------------------------------
   */

  private static final String transformText(String text)
  {
    // TEMPORARY IMPLEMENTATION
    if (text.length()<60)
      return text;
    return text.substring(0,60) + "...";

  } // end transformText

  /*--------------------------------------------------------------------------------
   * Implementations from interface TopicMessageFound
   *--------------------------------------------------------------------------------
   */

  public String getIdentifier()
  {
    return ident;

  } // end getIdentifier

  public String getAuthor()
  {
    return creator_name;

  } // end getAuthor

  public Date getPostDate()
  {
    return postdate;

  } // end getPostDate

  public int getLineCount()
  {
    return linecount;

  } // end getLineCount

  public String getText()
  {
    return text;

  } // end getText

} // end class TopicMessageFoundImpl



