1  //!-- UTF8
     2  /*
     3  Oregano Multiuser Server - Version 1.2.0 - January 4th, 2005
     4   
     5  	Web:  www.oregano-server.org
     6  	Mail: info@oregano-server.org
     7   
     8  	Copyright 2003 - 2004 - 2004 Jens Halm / Cologne, Germany
     9   
    10   This library is free software; you can redistribute it and/or
    11   modify it under the terms of the GNU Lesser General Public
    12   License as published by the Free Software Foundation; either
    13   version 2.1 of the License, or (at your option) any later version.
    14   
    15   This library is distributed in the hope that it will be useful,
    16   but WITHOUT ANY WARRANTY; without even the implied warranty of
    17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    18   Lesser General Public License for more details.
    19   
    20   You should have received a copy of the GNU Lesser General Public
    21   License along with this library; if not, write to the Free Software
    22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23   */
    24  
    25  /*
    26  -------------------------------------------
    27  	Classe Message
    28  
    29  	@description :
    30  	Gestion de la création d'une enveloppe valide.
    31  
    32  
    33  	@author Jens Halm copyright http://www.spicefactory.org/
    34  	@author erixtekila copyleft http://www.v-i-a.net  
    35  -------------------------------------------
    36  	version history :
    37  	1.2.0 : 29/12/04
    38  			- Portage en actionscript 2 pour le
    39  			compile time type checking
    40  -------------------------------------------
    41  */
    42  
    43  import org.omus.data.DataParser;
    44  import org.omus.data.DataTransformer;
    45  
    46  import org.omus.core.User;
    47  
    48  /**
    49   *	Messages non persistant à envoyer à l'aide du Messenger.
    50   *
    51   *	@author Jens Halm copyright http://www.spicefactory.org/
    52   *	@author erixtekila copyleft http://www.v-i-a.net 
    53   *	@version 1.2.0
    54   */
    55  class org.omus.msg.Message
    56  {
    57  	//--------------------
    58  	// PROPRIETES
    59  	//--------------------
    60  	/**
    61  	 *	Sujet du message
    62  	 */
    63  	private var subject:String;
    64  	
    65  	/**
    66  	 *	Envoyeur du message.
    67  	 */
    68  	private var sender:String;
    69  	
    70  	/**
    71  	 *	Fichier joint du message.
    72  	 *	Peut transporter n'importe quel type d'objet reconnu par Oregano :
    73  	 *	boolean, number, String, Date, Object, Array, Table
    74  	 */
    75  	private var attach:Object;
    76  	
    77  	/**
    78  	 *	Une référence à DataParser.
    79  	 */
    80  	private var dataParser:DataParser;
    81  	
    82  	//--------------------
    83  	// CONSTRUCTEUR
    84  	//--------------------
    85  	/**
    86  	 *	Gestion de la création d'une enveloppe valide.
    87  	 */
    88  	public function Message(subj:String)
    89  	{
    90  		subject = subj;
    91  		// TODO : Accès Singleton
    92  		var user = User.getInstance();
    93  		sender = user.getName();
    94  		attach = new Object();
    95  		dataParser = null;
    96  		
    97  		// trace(this+ " installé.");
    98  	}
    99  	
   100  	//--------------------
   101  	// METHODES PUBLIQUES
   102  	//--------------------
   103  	/**
   104  	 *	Utilisé dans un contexte littéral
   105  	 *	@return	Une chaine définissant l'objet
   106  	 */
   107  	public function toString():String
   108  	{
   109  		var s = "[Object Message]";
   110  		s += "\norg.omus.Message:\n=============\nsender = " + sender;
   111  		s += "\nsubject = " + subject;
   112  		s += "\nattachment = " + org.omus.util.Log.formatObject(getAttachment(), 1);
   113  		return s;
   114  	}
   115  	
   116  	/**
   117  	 *	Renvoie le nom de l'envoyeur du message.
   118  	 *
   119  	 *	@return		Une chaine décrivant l'envoyeur.
   120  	 */
   121  	public function getSender ():String
   122  	{
   123  		return sender;
   124  	}
   125  	
   126  	/**
   127  	 *	Renvoie le sujet du message.
   128  	 *
   129  	 *	@return		Le sujet.
   130  	 */
   131  	public function getSubject ():String
   132  	{
   133  		return subject;
   134  	}
   135  	
   136  	/**
   137  	 *	Définit le nom de l'envoyeur
   138  	 *	Ne devrait pas être utilisé autre part que dans le framework.
   139  	 *
   140  	 *	@param snd		Nouvel envoyeur.
   141  	 */
   142  	public function setSender (snd:String):Void
   143  	{
   144  		sender = snd;
   145  	}
   146  	
   147  	/**
   148  	 *	Renvoie le fichier joint.
   149  	 *	Celui-ci peut être de n'importe quel type permis par Oregano soit :
   150  	 *	boolean, number, String, Date, Object, Array, Table
   151  	 */
   152  	public function getAttachment ():Object 
   153  	{
   154  		if (attach == null) unmarshal();
   155  		return attach;
   156  	}
   157  	
   158  	/**
   159  	 *	Joint une pièce au message.
   160  	 *
   161  	 *	@param str		Chaine à encodée.
   162  	 *	@param idx		Index ?
   163  	 */
   164  	public function setMarshalledAttachment (str:String, idx:Number):Void
   165  	{
   166  		attach = null;
   167  		dataParser = new DataParser(str, idx);
   168  	}
   169  	
   170  	/**
   171  	 *	Renvoie la pièce jointe du message.
   172  	 *
   173  	 *	@return		Une référence au conteneur de la pièce jointe.
   174  	 */
   175  	public function getMarshalledAttachment ():String
   176  	{
   177  		//  TODO : Accès Singleton
   178  		var transformer = DataTransformer.getInstance();
   179  		return transformer.marshal_object(attach);
   180  	}
   181  	
   182  	//--------------------
   183  	// METHODES PRIVEES
   184  	//--------------------
   185  	/**
   186  	 *	Décode la pièce jointe.
   187  	 */
   188  	private function unmarshal ():Void
   189  	{
   190  		attach = dataParser.nextObject(true);
   191  		if (attach == null) {
   192  			var dp = dataParser;
   193  			// Logs internes
   194  			_global.oregano.iLog.error("clj-068","error: " + dp.error + "\nindex: " + dp.idx + "\nmarshalled data: " + dp.data);
   195  		}
   196  	}
   197  	
   198  	//--------------------
   199  	// METHODES STATIQUES
   200  	//--------------------
   201  	/**
   202  	 *	Utilisé dans un contexte littéral
   203  	 *	@return	Une chaine définissant l'objet
   204  	 */
   205  	public static function toLog():String
   206  	{
   207  		return "[Object Message]";
   208  	}
   209  }
   210