001: /******************************************************************************
002: * $Source: /cvsroot/sshwebproxy/src/java/com/ericdaugherty/sshwebproxy/SshChannel.java,v $
003: * $Revision: 1.2 $
004: * $Author: edaugherty $
005: * $Date: 2003/11/23 00:18:10 $
006: ******************************************************************************
007: * Copyright (c) 2003, Eric Daugherty (http://www.ericdaugherty.com)
008: * All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * * Redistributions of source code must retain the above copyright notice,
014: * this list of conditions and the following disclaimer.
015: * * Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in the
017: * documentation and/or other materials provided with the distribution.
018: * * Neither the name of the Eric Daugherty nor the names of its
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
023: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
026: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
032: * THE POSSIBILITY OF SUCH DAMAGE.
033: * *****************************************************************************
034: * For current versions and more information, please visit:
035: * http://www.ericdaugherty.com/dev/sshwebproxy
036: *
037: * or contact the author at:
038: * web@ericdaugherty.com
039: *****************************************************************************/package com.ericdaugherty.sshwebproxy;
040:
041: /**
042: * Provides a base class for all Ssh Channels.
043: *
044: * @author Eric Daugherty
045: */
046: public abstract class SshChannel {
047:
048: //***************************************************************
049: // Variables
050: //***************************************************************
051:
052: /** The type of channel, Shell, SCP, etc */
053: private String channelType;
054:
055: /** The unique id of this ShellChannel */
056: private String channelId;
057:
058: /** The SshConnection this channel is using */
059: protected SshConnection sshConnection;
060:
061: //***************************************************************
062: // Constructor
063: //***************************************************************
064:
065: /**
066: * Create a new SshChannel of the specified type.
067: *
068: * @param channelType the type of channel.
069: * @param sshConnection the connection to the SSH Server.
070: */
071: public SshChannel(String channelType, SshConnection sshConnection) {
072: this .channelType = channelType;
073: this .sshConnection = sshConnection;
074: }
075:
076: //***************************************************************
077: // Abstract Methods
078: //***************************************************************
079:
080: /**
081: * Close the SessionChannelClient and all internal
082: * streams. This should only be called by the SshConnection
083: * class and never directly called by a SshChannel implementation.
084: * Channels should call SshConnection.closeChannel( this ) to close
085: * itself.
086: */
087: public abstract void close();
088:
089: /**
090: * Indicates whether this connection is still active.
091: *
092: * @return true if this connection is still active.
093: */
094: public abstract boolean isConnected();
095:
096: /**
097: * Returns the page that should be used to display this Channel.
098: *
099: * @return URL of the page used to display this channel.
100: */
101: public abstract String getPage();
102:
103: //***************************************************************
104: // Parameter Access Methods
105: //***************************************************************
106:
107: /** The type of channel, Shell, SCP, etc */
108: public String getChannelType() {
109: return channelType;
110: }
111:
112: /**
113: * The unique ID of this connection
114: *
115: * @return
116: */
117: public String getChannelId() {
118: return channelId;
119: }
120:
121: /**
122: * The unique ID of this connection
123: *
124: * @param channelId
125: */
126: protected void setChannelId(String channelId) {
127: this .channelId = channelId;
128: }
129:
130: //***************************************************************
131: // Public methods
132: //***************************************************************
133:
134: /**
135: * Replaces any HTML control characters with their escaped value.
136: *
137: * @param data the string to check
138: * @return the encoded string.
139: */
140: public String encodeHTML(String data) {
141: // Replace HTML Characters
142: data = data.replaceAll("<", "<");
143: data = data.replaceAll(">", ">");
144:
145: return data;
146: }
147: }
|