/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/

#include <dditemlink.h>
#include <stdexcept>
#include <ddwebpage.h>

using namespace std;


/**
	Default constructor.
*/

dditemlink::dditemlink()
{

}

/**
	Default constructor.
*/

dditemlink::dditemlink( const ddstring& name )
: dditem( name )
{


}

dditemlink::dditemlink( const ddstring& name, const ddstring& value, const ddstring& call, size_t access )
:	dditem( name, value, call, access )
{

}
/**
	Copy constructor.
*/

dditemlink::dditemlink( const dditemlink& src )
: dditem()
{
	*this = src;
}


/**
	Assignment operator.
*/

dditemlink& dditemlink::operator=( const dditemlink& src )
{
	if( this == &src )
		return *this;

  _access = src._access;
	_name = src._name;
	_value = src._value;
	_link = src._link;
  _class = src._class;
  _title = src._title;
  
	return *this;
}



/**
	Destructor.
*/

dditemlink::~dditemlink()
{

}
	

dditem* dditemlink::clone() const
{  
  dditemlink* newlink = new dditemlink( _name, _value, _param );		
	newlink->_link = _link;
	newlink->_class = _class;	
	newlink->_title = _title;	
	return newlink;
}



dditem& dditemlink::set_link( const ddstring& value, const ddstring& link, const ddstring& lclass, const ddstring& title )
{
	_link = link;
	_class = lclass;
	_title = title;
	return from_string( value );
}


/**
	Create a string representation of this item.
	If get_link() is empty, dditem::to_string is returned.
	Else, a html link is created.
*/

ddstring dditemlink::to_string() const
{
  if( _link.empty() )
		return dditem::to_string();
  
  // prefix & link part.
  ddstring result =  "<a href=\'";
  result += _link;
  result += "'";
  // class part
  if( !_class.empty() )
  {
		result += " class=\'";
    result += _class;
    result += "'";
  }
  if( !_title.empty() )
  {
		result += " title=\'";
    result += _title;
    result += "'";
  }
  result += '>';
  // body part
  result += get_value();
  result += "</a>";
  
  return result;
}






