File Source: ProcessTopic.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ProcessTopic__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.parser.irc;
    24  
    25  /**
    26   * Process a topic change.
    27   */
    28  public class ProcessTopic extends IRCProcessor {
    29  	/**
    30  	 * Process a topic change.
    31  	 *
    32  	 * @param sParam Type of line to process ("TOPIC", "332", "333")
    33  	 * @param token IRCTokenised line to process
    34  	 */
    35  	@Override
    36  	public void process(final String sParam, final String[] token) {
    37  		ChannelInfo iChannel;
        		 /* 
    P/P 		  *  Method: void process(String, String[])
        		  * 
        		  *  Preconditions:
        		  *    sParam != null
        		  *    token != null
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) token[0] != null
        		  *    (soft) this.myParser != null
        		  *    (soft) this.myParser.hChannelList != null
        		  *    (soft) this.myParser.hClientList != null
        		  *    (soft) this.myParser.myCallbackManager != null
        		  *    (soft) this.myParser.myCallbackManager.callbackHash != null
        		  *    (soft) this.myParser.stringConverter.lowercase != null
        		  *    ...
        		  * 
        		  *  Presumptions:
        		  *    iClient.sHost != null
        		  *    this.myParser.stringConverter.lowercase != null
        		  * 
        		  *  Postconditions:
        		  *    init'ed(java.lang.String:substring(...)._tainted)
        		  *    init'ed(this.myParser.stringConverter)
        		  *    token[0] == One-of{old token[0], &java.lang.String:substring(...)}
        		  *    token[0] != null
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects == 0
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
        		  *    new char[](IRCStringConverter#1) num objects <= 1
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    token.length: {3}, {4}, {5}, {6..232}
        		  *    java.lang.String:charAt(...)@62: {0..57, 59..216-1}, {58}
        		  *    java.lang.String:equals(...)@38: {0}, {1}
        		  *    java.lang.String:equals(...)@42: {0}, {1}
        		  *    java.lang.String:isEmpty(...)@57: {0}, {1}
        		  */
    38  		if (sParam.equals("332")) {
    39  			iChannel = getChannelInfo(token[3]);
    40  			if (iChannel == null) { return; }
    41  			iChannel.setTopic(token[token.length-1]);
    42  		} else if (sParam.equals("333")) {
    43  			if (token.length > 3) {
    44  				iChannel = getChannelInfo(token[3]);
    45  				if (iChannel == null) { return; }
    46  				if (token.length > 4) {
    47  					iChannel.setTopicUser(token[4]);
    48  					if (token.length > 5) {
    49  						iChannel.setTopicTime(Long.parseLong(token[5]));
    50  					}
    51  				}
    52  				callChannelTopic(iChannel,true);
    53  			}
    54  		} else {
    55  			if (IRCParser.ALWAYS_UPDATECLIENT) {
    56  				final ClientInfo iClient = getClientInfo(token[0]);
    57  				if (iClient != null && iClient.getHost().isEmpty()) {iClient.setUserBits(token[0],false); }
    58  			}
    59  			iChannel = getChannelInfo(token[2]);
    60  			if (iChannel == null) { return; }
    61  			iChannel.setTopicTime(System.currentTimeMillis() / 1000);
    62  			if (token[0].charAt(0) == ':') { token[0] = token[0].substring(1); }
    63  			iChannel.setTopicUser(token[0]);
    64  			iChannel.setTopic(token[token.length-1]);
    65  			callChannelTopic(iChannel,false);
    66  		}
    67  	}
    68  	
    69  	/**
    70  	 * Callback to all objects implementing the ChannelTopic Callback.
    71  	 *
    72  	 * @see IChannelTopic
    73  	 * @param cChannel Channel that topic was set on
    74  	 * @param bIsJoinTopic True when getting topic on join, false if set by user/server
    75  	 * @return true if a method was called, false otherwise
    76  	 */
    77  	protected boolean callChannelTopic(final ChannelInfo cChannel, final boolean bIsJoinTopic) {
        		 /* 
    P/P 		  *  Method: bool callChannelTopic(ChannelInfo, bool)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    this.myParser.myCallbackManager != null
        		  *    this.myParser.myCallbackManager.callbackHash != null
        		  * 
        		  *  Presumptions:
        		  *    getCallbackManager(...)@78 init'ed
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
    78  		return getCallbackManager().getCallbackType("OnChannelTopic").call(cChannel, bIsJoinTopic);
    79  	}
    80  	
    81  	/**
    82  	 * What does this IRCProcessor handle.
    83  	 *
    84  	 * @return String[] with the names of the tokens we handle.
    85  	 */
    86  	@Override
    87  	public String[] handles() {
        		 /* 
    P/P 		  *  Method: String[] handles()
        		  * 
        		  *  Postconditions:
        		  *    return_value == &amp;new String[](handles#1)
        		  *    new String[](handles#1) num objects == 1
        		  *    return_value.length == 3
        		  *    return_value[0] == &amp;"TOPIC"
        		  *    return_value[1] == &amp;"332"
        		  *    return_value[2] == &amp;"333"
        		  */
    88  		return new String[]{"TOPIC", "332", "333"};
    89  	} 
    90  	
    91  	/**
    92  	 * Create a new instance of the IRCProcessor Object.
    93  	 *
    94  	 * @param parser IRCParser That owns this IRCProcessor
    95  	 * @param manager ProcessingManager that is in charge of this IRCProcessor
    96  	 */
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ProcessTopic(IRCParser, ProcessingManager)
        	  * 
        	  *  Postconditions:
        	  *    this.myManager == manager
        	  *    init'ed(this.myManager)
        	  *    this.myParser == parser
        	  *    init'ed(this.myParser)
        	  */
    97  	protected ProcessTopic (IRCParser parser, ProcessingManager manager) { super(parser, manager); }
    98  
    99  }








SofCheck Inspector Build Version : 2.17854
ProcessTopic.java 2009-Jun-25 01:54:24
ProcessTopic.class 2009-Sep-02 17:04:16