package caida.otter;
import java.awt.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
/*****************************************************************************
* File: URLDialog.java Name:URLDialog
* Goal: To create a FilenameDialog that works for URLs.
* it list the contains of a url and the allow the user to
* select a given file out of those in the URL of a dir.
*
* Written: Bradley Huffaker
* For: Cooperative Association for Internet Data Analysis
******************************************************************************
******************************************************************************
* By accessing this software, URLDIALOG, you are duly informed of
* and agree to be bound by the conditions described below in
* this notice:
*
* This software product, URLDIALOG, is developed by Bradley Huffaker, and
* copyrighted(C) 1998 by the University of California, San Diego (UCSD),
* with all rights reserved. UCSD administers the NSF grant to CAIDA,
* number NCR-9711092, under which this code was developed.
*
* URLDIALOG is a free software. You can redistribute it and/or modify it
* under the terms of the GNU Public License v.2 as
* published by UCSD and is incorporated by reference herein. URLDIALOG is
* distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
* OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
* infringe on any third party's intellectual property rights.
*
* You should have received a copy of the CAIDA General Public
* License v.1 along with the URLDIALOG program. If for any reason you
* have not received a copy, please write to
*
* University of California, San Diego
* SDSC/CAIDA
* 9500 Gilman Dr., MS-0505
* La Jolla, CA 92093 - 0505 USA
*
* Or contact INFO@CAIDA.ORG
*****************************************************************************/
public class URLDialog extends Dialog
{
// Filter that test for acceptable names.
NameFilter filter = new NameFilter();
// The List that will display and allow for selection of files
List list = new List();
// The List that will display directories
List dirList = new List();
// Holds the file they selected
String file_address = null;
// Holds the url of the directory in which to look
String address = null;
String full_address;
// Displays the current directory
TextField current_dir = new TextField(" ");
String[] dirs = new String[20];
int dir_index = 0;
// Control Buttons
Button Accept = new Button("Accept");
Button Cancel = new Button("Cancel");
// Flags if a error_occured
boolean error_occured = false;
// Flag for accepted or not
boolean accpted = false;
// The number of lines read
int linenum = 0;
FileInterface parent;
public URLDialog(FileInterface parent_input, String address_input)
{
super((Frame)parent_input,"Choose Data File",true);
parent = parent_input;
address = address_input;
resize(250,200);
current_dir.setEditable(false);
Panel buttons = new Panel();
buttons.setLayout(new BorderLayout());
buttons.add("West",Accept);
buttons.add("East",Cancel);
Panel dir_panel = new Panel();
Label dir_label = new Label("Directories");
dir_panel.setLayout(new BorderLayout());
dir_panel.add("North",dir_label);
dir_panel.add("Center",dirList);
Panel file_panel = new Panel();
Label file_label = new Label("Files");
file_panel.setLayout(new BorderLayout());
file_panel.add("North",file_label);
file_panel.add("Center",list);
setLayout(new BorderLayout());
add("North",current_dir);
add("Center",file_panel);
add("West",dir_panel);
add("South",buttons);
}
public void Show()
{
setUp();
((Window)this).show();
}
protected void setUp()
{
if (list.countItems() > 0)
list.clear();
if (dirList.countItems() > 0)
dirList.clear();
URL url = null;
InputStream is = null;
if (address == null)
{
Error("address is null");
}
else
{
full_address = "";
for(int index=0;index < dir_index;index++)
{
full_address = full_address +"/"
+ dirs[index];
}
current_dir.setText(full_address);
full_address = address + full_address + "/";
try {
url = new URL(full_address);
URLConnection uc = url.openConnection();
System.err.println(uc.getDefaultAllowUserInteraction());
is = url.openStream();
/*
} catch (MalformedURLException e0) {
Error(e0.toString());
*/
} catch (IOException e1) {
Error(e1.toString());
}
}
if (is == null)
return;
if (dir_index > 0)
dirList.addItem("..");
error_occured = false;
int length = 0;
int current_length = 0;
byte[] bytes = new byte[256];
char[] buffer = new char[256];
boolean working = true;
linenum = 0;
try {
do {
length =is.read(bytes);
//System.err.println("length:" + length + "<>" + bytes.length);
if (length < 0)
{
length = 0;
bytes[length++] = (byte)'\n';
working = false;
}
for (int offset=0; offset < length; offset++)
{
if (current_length > buffer.length)
{
char[] temp = new char[(int)(buffer.length*1.1)];
for (int index=0;index < buffer.length;index++)
temp[index] = buffer[index];
buffer = temp;
}
buffer[current_length] = (char) bytes[offset];
if (buffer[current_length] == '\n')
{
ParseString(current_length,buffer);
current_length = 0;
linenum++;
}
else
current_length++;
}
} while (working);
} catch (IOException e1) {
Error(e1.toString());
}
}
public void ParseString(int length, char[] buffer)
{
//System.err.println( "PraseString:"+length);
// Current possition in the string
int index;
// Attempt to find a directory
// a tag for 'alt="[dir]"'
boolean isDir = false;
final char[] DIR= {'a', 'l', 't', '=', '"', '[', 'd', 'i'
,'r' ,']' ,'"'};
index = match(length,buffer,0,DIR);
if (index == length)
{
index = 0;
isDir = false;
}
else
isDir = true;
// Attempt to find the HTMP tag for 0)
list.clear();
list.addItem(msg);
}
public boolean handleEvent (Event event)
{
if (event.id == Event.ACTION_EVENT)
{
if (event.target == dirList)
{
String dir = dirList.getSelectedItem();
if (dir.equals(".."))
{
if (dir_index > 0)
{
dir_index--;
setUp();
}
}
else
{
if (dir_index == dirs.length)
{
String[] temp = new String[
(int)(dirs.length*1.1)];
for(int i=0;iHoME小明看看台湾视频发布
ENTER NUMBET 0017
www.ydtc.net.cn
www.aa6l6.com.cn
www.syqg.org.cn
www.esws.com.cn
putongla.com.cn
shula9.net.cn
zhouhs.com.cn
faguo1.com.cn
www.70yk.org.cn
www.huimu3.net.cn