|
Does anyone know what am i supposed to do to write xml attribute in java?
example
<body id="Content">Text</body>
|
|
|
|
|
i have got a code for Web Crawler in java language....
Following is applet code...
import java.applet.Applet;
import java.text.*;
import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import java.util.*;
import java.util.*;
import java.net.*;
import java.io.*;
public class WebCrawler extends Applet implements ActionListener, Runnable {
public static final String SEARCH = "Search";
public static final String STOP = "Stop";
public static final String DISALLOW = "Disallow:";
public static final int SEARCH_LIMIT = 50;
Panel panelMain;
List listMatches;
Label labelStatus;
Vector vectorToSearch;
Vector vectorSearched;
Vector vectorMatches;
Thread searchThread;
TextField textURL;
Choice choiceType;
public void init() {
panelMain = new Panel();
panelMain.setLayout(new BorderLayout(5, 5));
Panel panelEntry = new Panel();
panelEntry.setLayout(new BorderLayout(5, 5));
Panel panelURL = new Panel();
panelURL.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
Label labelURL = new Label("Starting URL: ", Label.RIGHT);
panelURL.add(labelURL);
textURL = new TextField("", 40);
panelURL.add(textURL);
panelEntry.add("North", panelURL);
Panel panelType = new Panel();
panelType.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
Label labelType = new Label("Content type: ", Label.RIGHT);
panelType.add(labelType);
choiceType = new Choice();
choiceType.addItem("text/html");
choiceType.addItem("audio/basic");
choiceType.addItem("audio/au");
choiceType.addItem("audio/aiff");
choiceType.addItem("audio/wav");
choiceType.addItem("video/mpeg");
choiceType.addItem("video/x-avi");
panelType.add(choiceType);
panelEntry.add("South", panelType);
panelMain.add("North", panelEntry);
Panel panelListButtons = new Panel();
panelListButtons.setLayout(new BorderLayout(5, 5));
Panel panelList = new Panel();
panelList.setLayout(new BorderLayout(5, 5));
Label labelResults = new Label("Search results");
panelList.add("North", labelResults);
Panel panelListCurrent = new Panel();
panelListCurrent.setLayout(new BorderLayout(5, 5));
listMatches = new List(10);
panelListCurrent.add("North", listMatches);
labelStatus = new Label("");
panelListCurrent.add("South", labelStatus);
panelList.add("South", panelListCurrent);
panelListButtons.add("North", panelList);
Panel panelButtons = new Panel();
Button buttonSearch = new Button(SEARCH);
buttonSearch.addActionListener(this);
panelButtons.add(buttonSearch);
Button buttonStop = new Button(STOP);
buttonStop.addActionListener(this);
panelButtons.add(buttonStop);
panelListButtons.add("South", panelButtons);
panelMain.add("South", panelListButtons);
add(panelMain);
setVisible(true);
repaint();
vectorToSearch = new Vector();
vectorSearched = new Vector();
vectorMatches = new Vector();
URLConnection.setDefaultAllowUserInteraction(false);
}
public void start() {
}
public void stop() {
if (searchThread != null) {
setStatus("stopping...");
searchThread = null;
}
}
public void destroy() {
}
boolean robotSafe(URL url) {
String strHost = url.getHost();
String strRobot = "http://" + strHost + "/robots.txt";
URL urlRobot;
try {
urlRobot = new URL(strRobot);
} catch (MalformedURLException e) {
return false;
}
String strCommands;
try {
InputStream urlRobotStream = urlRobot.openStream();
byte b[] = new byte[1000];
int numRead = urlRobotStream.read(b);
strCommands = new String(b, 0, numRead);
while (numRead != -1) {
if (Thread.currentThread() != searchThread)
break;
numRead = urlRobotStream.read(b);
if (numRead != -1) {
String newCommands = new String(b, 0, numRead);
strCommands += newCommands;
}
}
urlRobotStream.close();
} catch (IOException e) {
return true;
}
String strURL = url.getFile();
int index = 0;
while ((index = strCommands.indexOf(DISALLOW, index)) != -1) {
index += DISALLOW.length();
String strPath = strCommands.substring(index);
StringTokenizer st = new StringTokenizer(strPath);
if (!st.hasMoreTokens())
break;
String strBadPath = st.nextToken();
if (strURL.indexOf(strBadPath) == 0)
return false;
}
return true;
}
public void paint(Graphics g) {
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
panelMain.paint(g);
panelMain.paintComponents(g);
}
public void run() {
String strURL = textURL.getText();
String strTargetType = choiceType.getSelectedItem();
int numberSearched = 0;
int numberFound = 0;
if (strURL.length() == 0) {
setStatus("ERROR: must enter a starting URL");
return;
}
vectorToSearch.removeAllElements();
vectorSearched.removeAllElements();
vectorMatches.removeAllElements();
listMatches.removeAll();
vectorToSearch.addElement(strURL);
while ((vectorToSearch.size() > 0)
&& (Thread.currentThread() == searchThread)) {
strURL = (String) vectorToSearch.elementAt(0);
setStatus("searching " + strURL);
URL url;
try {
url = new URL(strURL);
} catch (MalformedURLException e) {
setStatus("ERROR: invalid URL " + strURL);
break;
}
vectorToSearch.removeElementAt(0);
vectorSearched.addElement(strURL);
if (url.getProtocol().compareTo("http") != 0)
break;
if (!robotSafe(url))
break;
try {
URLConnection urlConnection = url.openConnection();
urlConnection.setAllowUserInteraction(false);
InputStream urlStream = url.openStream();
String type
= urlConnection.guessContentTypeFromStream(urlStream);
if (type == null)
break;
if (type.compareTo("text/html") != 0)
break;
byte b[] = new byte[1000];
int numRead = urlStream.read(b);
String content = new String(b, 0, numRead);
while (numRead != -1) {
if (Thread.currentThread() != searchThread)
break;
numRead = urlStream.read(b);
if (numRead != -1) {
String newContent = new String(b, 0, numRead);
content += newContent;
}
}
urlStream.close();
if (Thread.currentThread() != searchThread)
break;
String lowerCaseContent = content.toLowerCase();
int index = 0;
while ((index = lowerCaseContent.indexOf("<a", index)) != -1)
{
if ((index = lowerCaseContent.indexOf("href", index)) == -1)
break;
if ((index = lowerCaseContent.indexOf("=", index)) == -1)
break;
if (Thread.currentThread() != searchThread)
break;
index++;
String remaining = content.substring(index);
StringTokenizer st
= new StringTokenizer(remaining, "\t\n\r\">#");
String strLink = st.nextToken();
URL urlLink;
try {
urlLink = new URL(url, strLink);
strLink = urlLink.toString();
} catch (MalformedURLException e) {
setStatus("ERROR: bad URL " + strLink);
continue;
}
if (urlLink.getProtocol().compareTo("http") != 0)
break;
if (Thread.currentThread() != searchThread)
break;
try {
URLConnection urlLinkConnection
= urlLink.openConnection();
urlLinkConnection.setAllowUserInteraction(false);
InputStream linkStream = urlLink.openStream();
String strType
= urlLinkConnection.guessContentTypeFromStream(linkStream);
linkStream.close();
if (strType == null)
break;
if (strType.compareTo("text/html") == 0) {
if ((!vectorSearched.contains(strLink))
&& (!vectorToSearch.contains(strLink))) {
if (robotSafe(urlLink))
vectorToSearch.addElement(strLink);
}
}
if (strType.compareTo(strTargetType) == 0) {
if (vectorMatches.contains(strLink) == false) {
listMatches.add(strLink);
vectorMatches.addElement(strLink);
numberFound++;
if (numberFound >= SEARCH_LIMIT)
break;
}
}
} catch (IOException e) {
setStatus("ERROR: couldn't open URL " + strLink);
continue;
}
}
} catch (IOException e) {
setStatus("ERROR: couldn't open URL " + strURL);
break;
}
numberSearched++;
if (numberSearched >= SEARCH_LIMIT)
break;
}
if (numberSearched >= SEARCH_LIMIT || numberFound >= SEARCH_LIMIT)
setStatus("reached search limit of " + SEARCH_LIMIT);
else
setStatus("done");
searchThread = null;
}
void setStatus(String status) {
labelStatus.setText(status);
}
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.compareTo(SEARCH) == 0) {
setStatus("searching...");
if (searchThread == null) {
searchThread = new Thread(this);
}
searchThread.start();
}
else if (command.compareTo(STOP) == 0) {
stop();
}
}
public static void main (String argv[])
{
Frame f = new Frame("WebFrame");
WebCrawler applet = new WebCrawler();
f.add("Center", applet);
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "webcache-cup");
props.put("http.proxyPort", "8080");
Properties newprops = new Properties(props);
System.setProperties(newprops);
applet.init();
applet.start();
f.pack();
f.show();
}
}
But when i run it, and enter any URL it shows Following error in Cmd
Exception in thread "AWT-EventQueue-1" java.lang.IllegalThreadStateExcepti
at java.lang.Thread.start(Thread.java:571)
at WebCrawler.actionPerformed(WebCrawler.java:388)
at java.awt.Button.processActionEvent(Button.java:388)
at java.awt.Button.processEvent(Button.java:356)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDisp
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispat
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.jav
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.jav
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Please look at it...please tell what i need to do in it....
and what i need to edit in this Code of webcrawler
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "webcache-cup");
props.put("http.proxyPort", "8080");
Please help me out....
Please help.....
|
|
|
|
|
This is far too much code for anyone to read through. Please identifiy the line of code where the error occurs and post only the small amount of code near that line. Have you looked at the documentation to see what an IllegalThreadStateException is, and what may be its causes?
|
|
|
|
|
public static void main (String argv[])
{
Frame f = new Frame("WebFrame");
WebCrawler applet = new WebCrawler();
f.add("Center", applet);
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "webcache-cup");
props.put("http.proxyPort", "8080");
Properties newprops = new Properties(props);
System.setProperties(newprops);
applet.init();
applet.start();
f.pack();
f.show();
}
}
Ok ..just look at this MAIN
is there something needed to be done at
Properties prop=new Properties(System.getProperties());
Please compile it at your side ....and look at error..
there are some errors which i cannot explain...
please just once run it at your side...and put the inputs
and see what is that i am missing....
Please help me...
|
|
|
|
|
sangeeta2009 wrote: Please compile it at your side ....and look at error..
Well once I had commented out all the irrelevant code I could not see anything wrong; it compiles and runs. However, I don't see what this has to do with your original problem which as I recall, was some sort of ThreadException. My only suggestion is that you use whatever debug tools you have and try to step through your code. Assuming you wrote this code in the first place you should be able to extract small parts of it to test in isolation until you can at least narrow it down to a specific area of code.
|
|
|
|
|
Richard MacCutchan wrote: Assuming you wrote this code in the first place [...]
#wistles#
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Someone must have written it!
|
|
|
|
|
Ok if Possible please help me out...
I have run that code without any compilation error...
But when i input the url int the first Text box..
say: http://java.sun.com
in command prompt it give me errors..and doesn't display me any
of the Url's related to that site..
Hope you get it...Please help and see if that works on your side...
And please all other guys..stop commenting about the code....
I haven't written that code, i have taken it form Sun.com
So if Somebody is interested in helping someone whose is in need...
|
|
|
|
|
sangeeta2009 wrote: I haven't written that code, i have taken it form Sun.com
Well I suggest you go back to Sun and ask them to fix it. I don't have the skills to work on a piece of code this complex, and as you haven't written it yourself I doubt that you have much understanding of it either.
|
|
|
|
|
Ohhh..!!!
That means you cannot help ..except fake posting...
If i will be knowing that...it will be better that
i will not be here..asking for help!!!
well thanks for time wasting...
|
|
|
|
|
sangeeta2009 wrote: That means you cannot help ..except fake posting.
On the contrary, I have tried to help, but you seem incapable of doing anything for yourself, even answering a simple question.
sangeeta2009 wrote: well thanks for time wasting
Yes, I am sorry that I have wasted my time trying to assist you. I thought you were a serious programmer who wanted to learn something. Obviously I was mistaken.
|
|
|
|
|
Please can somebody help me to find the source code for creating a routing table in java.. i googled but couldn't find anything useful there..
|
|
|
|
|
vidzdas wrote: i googled but couldn't find anything useful there..
I googled and found lots of examples; why do think they are not useful?
|
|
|
|
|
They do not describe how these tables are implemented. It only describes the nature of these tables..
|
|
|
|
|
|
Thanks a lot..
I think this should solve my problem.
I'l keep u updated..
|
|
|
|
|
Hi
Can anyone send a sample code to serialize & deserialize excel file?
Thanks in Advance.
|
|
|
|
|
|
Danmed you me nemesis! You beat me by a click!
Do you start work at the same time as me then?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Nagy Vilmos wrote: You beat me by a click!
Two clicks, I believe.
Nagy Vilmos wrote: Do you start work at the same time as me then?
I haven't 'worked' for about three years. That is to say I haven't received any remuneration for my efforts in that time; details here[^].
|
|
|
|
|
I'm sorry, but that's not really the way we do things.
First, you TRY to do it. THEN you ask with help for a SPECIFIC problem. If you just want code, there are several options:
- search for an article,
- search here[^], or
- pay for it here[^].
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
can anyone tell me what this package contains and i have searched net.
package no.geosoft.cc.io;
what contens in this package and gve its solution
|
|
|
|
|
Well, I can only say that you don't seem to have searched the net particularly hard. I googled the package name and got a hit straight away:
http://geosoft.no/software/[^]
It's in the list under filemonitor.
|
|
|
|
|
hi
(sorry, again me!)
do you know how can i get computer name with java?
thanks
|
|
|
|
|
Okay. This and your previous question can be answered with the javadac supplied with the SDK. If you can't navigate this, try google.
After you have had a try, come back if you still have a problem. Which of these is likely to garner a response:
How do I join two strings?
or
I tried:
String x = "This";
String y = x;
x = x + " that";
why isn't x == y still true?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|