Marking Files for Offline Use
Marking a file for offline use.
Code Samples
See the Java environment settings for details on setting the project environment.
Java_RemoteEngine_MarkFile
The following example demonstrates marking a T-Tag for use offline.
/*****************************************************************************************
*
* Java_RemoteEngine_MarkFile.java
*
******************************************************************************************/
import com.eruces.teadmin.LocalAdmin;
import com.eruces.teadmin.LocalKeyStatus;
import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.TEConnectionType;
import com.eruces.teagent.TEAuthenticationType;
import com.eruces.teagent.AuthenticationContext;
import com.eruces.teagent.CookieAuthenticationContext;
import com.eruces.teagent.UPAuthenticationContext;
import java.io.FileNotFoundException;
import java.util.Vector;
public class Java_RemoteEngine_MarkFile
{
final int UNMARK = 0;
final int MARK = 1;
private String m_strServerName;
private int m_nPort;
private String m_strNativeUsername; // Native user
private String m_strNativePassword;
private TEAgentConnection m_conn;
private String m_strCookie;
public void connect_native(String strServerName, int nPort, String strUsername, String strPasswd) throws TEAgentException
{
m_strServerName = strServerName;
m_nPort = nPort;
m_strNativeUsername = strUsername;
m_strNativePassword = strPasswd;
// Get a connection instance
m_conn = TEAgentConnectionFactory.getConnection(TEConnectionType.SECURE_SOCKET); // SSL connection
// Make connection
UPAuthenticationContext ctx = (UPAuthenticationContext)TEAgentConnectionFactory.getAuthenticationContext(TEAuthenticationType.USERANDPASSWORD);
ctx.setUser(m_strNativeUsername);
ctx.setPasswd(m_strNativePassword);
m_conn.open(m_strServerName, m_nPort, ctx);
m_strCookie = m_conn.getEncodedCookie();
System.out.println("Connected to " + m_strServerName + " at " + m_nPort + " as " + m_strNativeUsername);
System.out.println("Cookie = " + m_strCookie);
}
private TEAgentConnection getTEAgentConnectionWithCookie(String cookie) throws TEAgentException
{
//Construct connection with Cookie authentication:
TEAgentConnection conn = TEAgentConnectionFactory.getConnection(TEConnectionType.SECURE_SOCKET);
AuthenticationContext ctx = TEAgentConnectionFactory.getAuthenticationContext(TEAuthenticationType.COOKIE);
((CookieAuthenticationContext)ctx).setCookie(cookie);
conn.open(m_strServerName, m_nPort, ctx);
return conn;
}
public void disconnect() throws TEAgentException
{
// Close connection
m_conn.close();
System.out.println("Disconnected from " + m_strServerName);
}
public void setMarkedForCheckOut(Vector<String> hls, boolean mark) throws Exception {
//======================NEED TO BE IMPLEMNTED===========================
//Need to use LocalAdmin with regular TEAgentConnection
LocalAdmin localadmin = new com.eruces.teadmin.LocalAdmin();
localadmin.attachConnection(m_conn);
//Vector hls = collectHiddenLinks(files, recursive, 0);
Vector<LocalKeyStatus> v_hls = new Vector<LocalKeyStatus>();
for(int i=0; i< hls.size(); i++) {
v_hls.add( new LocalKeyStatus((String)hls.get(i), mark?MARK:UNMARK));
}
localadmin.setKeyStatus(v_hls);
}
public boolean isFileMarked(String hiddenlink) throws Exception{
//======================NEED TO BE IMPLEMNTED===========================
//Need to use LocalAdmin with regular TEAgentConnection
LocalAdmin localadmin = new com.eruces.teadmin.LocalAdmin();
localadmin.attachConnection(m_conn);
LocalKeyStatus status = new LocalKeyStatus(hiddenlink);
Vector<LocalKeyStatus> vStatus = new Vector<LocalKeyStatus>();
vStatus.add(status);
localadmin.getKeyStatus(vStatus);
if(status.getStatus() ==MARK)
return true;
return false;
}
public void TestMarkFilesForCheckout() throws TEAgentException, Exception
{
int i;
int nHLs = 10;
Vector<String> hiddenlinks = null;
String strHL = null;
java.util.Iterator<?> iter = null;
hiddenlinks = new Vector<String>();
for (i=0; i<nHLs; i++)
{
strHL = Java_HelperFunctions.generateHiddenLink(m_conn);
hiddenlinks.add(strHL);
}
// Mark for checkout
setMarkedForCheckOut(hiddenlinks, true);
iter = hiddenlinks.iterator();
while(iter.hasNext())
{
strHL = (String)iter.next();
System.out.println("Mark status of " + strHL + " = " + isFileMarked(strHL));
}
// Unmark for checkout
setMarkedForCheckOut(hiddenlinks, false);
iter = hiddenlinks.iterator();
while(iter.hasNext())
{
strHL = (String)iter.next();
System.out.println("Mark status of " + strHL + " = " + isFileMarked(strHL));
}
}
public static void main(String[] args)
{
try
{
Java_RemoteEngine_MarkFile markfile = new Java_RemoteEngine_MarkFile();
// Native user login
markfile.connect_native("localhost", 5050, "ls", "password1A");
// Test mark files for checkout.
markfile.TestMarkFilesForCheckout();
}
catch (TEAgentException te)
{
te.printStackTrace();
}
catch (FileNotFoundException fnfe)
{
fnfe.printStackTrace();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}