Neep help with infinite loop! Please Help
I currently have a program that allows a user to enter a password protected site and it will return all the images on that page.
I�m trying to allow the user to type in the root URL, i.e. http://stage.diabetescontrolforlife.com/ and have the program pull all the images in all of the child directories. i.e. http://stage.diabetescontrolforlife.com/tool.aspx
I got an inner class similar to the one pulling the <IMG> tag, that pulls the <A> tag. The class adds all the links to a linkList Arraylist. In my main method I call image.getInfo(image.getLinkList()); hoping that I can just pass all the links back through the program and find all the <IMG> tags.
The problem is that, I get the desired output but it displays in an infinite loop, and the program never ends as it searches linkList over and over for <IMG> tags.
So, I tried to adding two different Do, While loops.
Main Method:
do
image.getInfo(image.getLinkList());
test=1;
}while(test != 1);This one does not change the output. Infinite loop continues.
Inner Class:
HTMLEditorKit.ParserCallback callback;
callback = new HTMLEditorKit.ParserCallback ()
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes, int position)
do
if (tag == HTML.Tag.A)
link = (String)attributes.getAttribute (HTML.Attribute.HREF);
if(link != null && !link.startsWith("javascript") && !link.startsWith("#") && link.startsWith("/"))
link = root + link;
linkList.add(link);
test=1;
}while(test!=1);
public void handleSimpleTag (HTML.Tag tag,MutableAttributeSet aset,int pos)
{if (tag == HTML.Tag.IMG )This one never allows the first URL to be checked, and the program just sits there.
Do you see anything I�m doing wrong, or anyway I can stop the infinite loop?
I think the problem is that both of the searching tag classes are inner classes but I don�t know how to make them their own classes without messing up the whole password checking.
Any advice would be helpful!
HTMLEditorKit.ParserCallback callback;
callback = new HTMLEditorKit.ParserCallback ()
public void handleSimpleTag (HTML.Tag tag,MutableAttributeSet aset,int pos)
if (tag == HTML.Tag.IMG )
src = (String)
aset.getAttribute (HTML.Attribute.SRC);
alt = (String)
aset.getAttribute (HTML.Attribute.ALT);
height = (String)
aset.getAttribute (HTML.Attribute.HEIGHT);
width = (String)
aset.getAttribute (HTML.Attribute.WIDTH);
//System.out.println("SRC = " + src);
//System.out.println("ALT = " + alt);
System.out.println("ROOT2"+root);
System.out.println("SRC1"+src);
if(src.startsWith("http"))
else
if(src.startsWith("../"))
src = src.replace("../", "");
src = root +"/"+ src;
else
if(src.startsWith("/"))
src = root + src;
else
src = root +"/"+ src;
System.out.println("SRC2"+src);
altList.add(alt);
srcList.add(src);
heightList.add(height);
widthList.add(width);
currentUrl.add(passUrl);
if(alt == null)
altPresent.add("No");
else
altPresent.add("Yes");
URI uri = null;
try
if (!uriBase.toString ().endsWith ("/") &&
!src.startsWith ("/"))
src = "/" + src;
uri = new URI (src);
uri = uriBase.resolve (uri);
System.out.println("URL"+passUrl);
System.out.println ("uri being " +
"processed ... " + uri);
System.out.println("ROOT3"+root);
catch (URISyntaxException e)
System.err.println ("Bad URI");
return;
// Convert the URI to a URL so that its input
// stream can be obtained.
URL url = null;
try
url = uri.toURL ();
catch (MalformedURLException e)
System.err.println ("Bad URL");
return;
//InputStream is;
//String filename = url.getFile ();
//int i = filename.lastIndexOf ('/');
//if (i != -1)
// filename = filename.substring (i+1);
@Override
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes, int position)
//while(test!=1)
System.out.println("TEST"+test);
if (tag == HTML.Tag.A)
link = (String)
attributes.getAttribute (HTML.Attribute.HREF);
if(link != null && !link.startsWith("javascript") && !link.startsWith("#") && link.startsWith("/"))
/*if(link.startsWith("/"))
link = root + link;
else
if(!link.startsWith("http"))
link = root +"/"+ link;
//if(link.contains(root))
link = root + link;
test=1;
linkList.add(link);
try
HttpURLConnection urlConn = null;
//URL url = new URL(server);
// Build the string to be used for Basic Authentication <username>:<password>
String userPassword = "testmlr" + ":" + "stage1-7000";
// Base64 encode the authentication string
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
//URLConnection
urlConn = (HttpURLConnection) url.openConnection();
// Enable writing to server ( to write request )
urlConn.setDoOutput(true);
// Enable reading from server ( to read response )
urlConn.setDoInput(true);
// Disable cache
urlConn.setUseCaches(false);
urlConn.setDefaultUseCaches(false);
// Set Basic Authentication parameters
urlConn.setRequestProperty ("Authorization", "Basic " + encoding);
// test(server);
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
new ParserDelegator().parse(in, callback, false);
System.out.println(in + "test123412341234");
catch (ChangedCharSetException e)
String csspec = e.getCharSetSpec ();
Pattern p = Pattern.compile ("charset=\"?(.+)\"?\\s*;?",
Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher (csspec);
String charset = m.find () ? m.group (1) : "ISO-8859-1";
// Read and parse HTML document using appropriate character set.
public ArrayList getLinkList()
return linkList;
}
Similar Messages
-
Need help with infinite loop in recovery mode in Creative Zen 20
hi,
I'm having this problem with my Creative Zen 20 GB:
When I turned it on, it goes immediately to the rescue/recovery mode. Not sure why. Will do that even when I reset the device.
So, I selected cleanup. After cleanup, it remained showing the menu of the recovery mode. I selected reboot. After reboot, it went back to the rescue/recovery mode. And it goes on and on like an infinite loop.
Finally, I decided to do a formatAll. Again, it remained in the recovery mode menu after the formatAll action. After reboot, it again went back to the rescue/recovery mode.
I have never updated the firmware. So, I thought maybe that will help. However, when I connected the device to my PC, the device went to rescue/recovery mode and the PC could not detect the device connected via USB. In short, I am currently not able to do anything at all with the device except charging it.
Would appreciate help/advise.
Tks in advance.huggiebear wrote:
I connected the device to the PC and after the PC tried to load the library, it said "Player is not connected".
What library are you loading? After you have run that reload os option, you need to connect the player to the computer and run the firmware update software. If you haven't download that, you can go to the download section and download it. If all else fail, the player is probably faulty and you would need to get in contact with Customer Support then.
Jason -
Need help with Portal Themes -- Please help
I need help with Portal Themes. I have read every document I can find but I am having no luck. All I want to do is change the colors for the Exceptions on one of my queries. I have created my own Portal Theme where I have changed the colors but I do not know how to assign my newly-created Portal Theme to my query. Can someone please give me the detailed steps on how to do this? Please help because this is driving me crazy.
Thanks.
RyanHi,
Refer
Exceptions - How to change the colors
This may help.
Thanks,
JituK -
Problem with while loops, please help!
I am having quite a bit of trouble with a program im working on. What i am doing is reading files from a directory in a for loop, in this loop the files are being broken into words and entered into a while loop where they are counted, the problem is i need to count the words in each file seperately and store each count in an array list or something similar. I also want to store the words in each file onto a seperate list
for(...)
read in files...
//Go through each line of the first file
while(matchLine1.find()) {
CharSequence line1 = matchLine1.group();
//Get the words in the line
String words1[] = wordBreak.split(line1);
for (int i1 = 0, n = words1.length; i1 < n; i1++) {
if(words1[i1].length() > 0) {
int count= 0;
count++;
list1.add(words1[i1]);
}This is what i have been doing, but with this method count stores the number of words in all files combined, not each individual file, and similarly list1 stores the words in all the files not in each individual file. Does anybody know how i could change this or what datastructures i could use that would allow me to store each file seperately. I would appreciate any help on this topic, Thanks!Don't try to construct complicated nested loops, it makes things a
tangled mess. You want a collection of words per file. You have at least
zero files. Given a file (or its name), you want to add a word to a collection
associated with that file, right?
A Map is perfect for this, i.e. the file's name can be the key and the
associated value can be the collection of words. A separate simple class
can be a 'MapManager' (ahem) that controls the access to this master
map. This MapManager doesn't know anything about what type of
collection is supposed to store all those words. Maybe you want to
store just the unique words, maybe you want to store them all, including
the duplicates etc. etc. The MapManager depends on a CollectionBuilder,
i.e. a simple thing that is able to deliver a new collection to be associated
with a file name. Here's the CollectionBuilder:public interface CollectionBuilder {
Collection getCollection();
}Because I'm feeling lazy today, I won't design an interface for a MapManager,
so I simply make it a class; here it is:public class MapManager {
private Map map= new HashMap(); // file/words association
CollectionBuilder cb; // delivers Collections per file
// constructor
public MapManager(CollectionBuilder cb) { this.cb= cb; }
// add a word 'word' given a filename 'name'
public boolean addWord(String name, String word) {
Collection c= map.get(name);
if (c == null) { // nothing found for this file
c= cb.getCollection(); // get a new collection
map.put(name, c); // and associate it with the filename
return c.add(word); // return whatever the collection returns
// get the collection associated with a filename
public Collection getCollection(String name) { return map.get(name); }
}... now simply keep adding words from a file to this MapManager and
retrieve the collections afterwards.
kind regards,
Jos -
Need help with a BR - Please help !
Hi,
I would please request you to help me with your ideas on achievening the below requirement. I have ideas on doing this but I am not able to put together everything to make it work. Please let me know your thoughts. Will be a great help.
Requirement:
The requirement is that if the user enters a data value for Account member "P" on the data form at any level (Top most parent level, intermediate parent levels or 0 level) it should work in the following way.
1) It needs to check at which level the user entered the value for "P". We have a relation that V = P * T. So what I thought is if I dynamically calculate the "V" value everytime for every product I should know at which place they changed it as if they change the "P" value it would change the "V" value too as both are linked. So, basically I am comparing the stored "V" value with dynamically calculated "V" value.
2) If the "V" value has been changed at that level (i.e. if stored V Dyn. V) and this condition is met then, all the descendants of that current member should get the same P value as entered by the user for the current member.
3) This should work irrespective of which parent level they enter and should start filling in the values from that level. And if they enter "P" value at 0 level members, then it should leave them as it is without overriding it and should be used in consolidation.
This is what I could think -
Please suggest changes as this is not working still as per the requirement.
FIX(..........)
IF (@ISDESC ("LB") AND "V"->@PARENT(@CURRMBR(Product)) P->@PARENT(@CURRMBR(Product)) * T->@PARENT(@CURRMBR(Product)))
P->@CURRMBR(Product) = @PARENTVAL (Product,P);
Similarly IFELSE for another condition
ENDIF
ENDFIX;
But this is not working for all the cases. Lets say I have 3 levels in my hierarchy for Product and if the users are entering at level 2 it is not working and replacing the input value with its parent value which I am not sure why as it should in first place not enter the loop only as the condition wont be met. Reason, the user changed at level 2 and not 3 so it should do nothing from what I understand.
Please let me know your thoughts.
Thanks.You can try something like this. Instead of dynamic V account add "P_Stored" member. If "P" account has data copy that data to "P_Stored" at all levels of the Product hierarchy. Based on your post I understand that Product hierarchy is evenly distributed than business rule can be like this:
FIX(@LEVMBRS("Product",2))
"P_Stored" (
IF("P_Stored" != @PARENTVAL("Product","P")
"P_Stored"=@PARENTVAL("Product","P");
"P"=@PARENTVAL("Product","P");
ENDIF
END
FIX(@LEVMBRS("Product",1))
"P_Stored" (
IF("P_Stored" != @PARENTVAL("Product","P")
"P_Stored"=@PARENTVAL("Product","P");
"P"=@PARENTVAL("Product","P");
ENDIF
END
FIX(@LEVMBRS("Product",0))
"P_Stored" (
IF("P_Stored" = "P")
/* I believe do nothing */
1==1
ELSEIF("P_Stored" != @PARENTVAL("Product","P")
"P_Stored"=@PARENTVAL("Product","P");
"P"=@PARENTVAL("Product","P");
ENDIF
END
FIX(@LEVMBRS("Product",3))
"P_Stored" (
IF("P_Stored" != "P")
"P_Stored"="P";
ENDIF
END
If Product hierarchy is ragged then code should be changed...
Regards,
Yuri
Edited by: yrozen on Oct 26, 2011 6:48 AM -
SQL I need help with this query Please help
List the names of all the products whose weight unit measure is “Gram”. Order the list by product name. Do not use JOINS, but use the IN clause with a sub-query.
select Name
from UnitMeasure
where Name= 'Gram'
order by Name
I did this, but it seem that the requirement is different.As a guess:
Select Name from Product
where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
"Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
Need help with an RMA - please help
Mt Zen Micro 5GB is busted - the headphone jack issue...yuk So I attempted to fix this using the online guide and it did not work. I am certain that the solder connections are solid now, but still only one channel will play. I am willing to pay to have this fixed, but Creative tech support is ignoring my question as to how to get an RMA and they are sending me email that says I can pay $2.99 for a support session and speak with someone. All I want to do is get an RMA so I can send them the money and the unit for them to fix! If someone could buy those tiny circuit boards for the Zen Micro they would make a mint selling them - it seems like there are a lot of busted Zen Micro's floating around out there.
Please - someone help me figure out how to get an RMA and a price to repair the Zen Micro - I am missing my tunes....you ant get a rma u broke the waranty contract if yoy try fixing the player your self the warranty is then invalid you can still pay for them to fix it or you can get a new mp3 player rma only works if your warranty is still valid not valid is torugh normal tear and wear tampering breaks the contract
-
Need help with case structures- please help :)
Hey all.
I'm currently trying to program a infrared furnace. I'm setting a temperature, subtracted my set temperature from the actual temperature (thermocouple hooked up to SCB-68), and voltage is being sent to the controller of the furnace accordingly. However, I need to hold the set temperature for a certain amount of time. I need help programming this: when the VI reads the set temperature from the thermocouple, it results in a timer running down. When the timer runs down to 0, the While Loop ends. I'm thinking case structures is most appropriate, but if you have a better suggestion, please let me know.
ThanksYou should probably implement a state machine.
The state machine would keep track of the temperature and making ajustments on a timely basis.
There is a template of a state machine is you select under the File menu > New > From Template.
You can also look under Help > Find Example > and do a search for state machine.
There are lots of state machine examples on this forum, some of which may be quite useful.
RayR -
Help with JEditorPane :). Please help...
Hi there,
I can not find out how the JEditorPane get's its' information on which Text to show.
I know that there is a Document, representing the text information and an EditorKit, offering main functionality for editing, but what methods are actually called from where to get the text that is stored in the document?
What methods are called from where?
Could anyone help me please, I am rather desperate.
Thank you very much
CharlyHere is a link to a section in the Swing tutorial that shows you how to use text components (JTextField, JTextArea, JEditorPane, JTextPane):
http://java.sun.com/docs/books/tutorial/uiswing/components/text.html -
Need Help with random numbers, please help
Hi guys;
I need your help for a school project. I need to generate a random number from 1.0 to 2.0. How would I do that?
Regards,http://java.sun.com/j2se/1.3/docs/api/java/util/Random.html#nextFloat()
-
Need Help with Typography. Please Help.
I have final cut studio 3 and want to do some typography, I can only find tutorials on how to do it in after effects. I do not have after effects and do not have that kind of money to buy it. I know motion 4 is capable of doing typography but how. I need someone to explain how exactly to do it or can someone give me a link to a tutorial of how to do typography in apple motion 4 (or 3). Please I really need to do do a typography project. How can I do this in motion 4.
Check out Mark Spencer's website. I believe he has a tutorial on typography there.
[AppleMotion.net|http://www.applemotion.net]
It's bascially the same idea in Motion as it is in AE. It's not that complicated; it just takes a lot of work.
Andy -
I'm a beginner. I'm trying to get this output
Initial number of stars:
7
Here's my program. What's wrong with it? Please help
import java.io.*;
class starWedge
public static void main (String[] args ) throws IOException
int numStars; // the number of stars
int row ; // current row number
int star; // the number of stars in this row so far
BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
String inputData;
// collect input data from user
System.out.println( "Initial number of stars:" );
inputData = userin.readLine();
numStars = Integer.parseInt( inputData );
row = 1;
while ( row <= numStars )
star = 1;
star = numStars - star;
System.out.print("*");
star = star + 1;
System.out.println(); // end each line
row = row + 1;Okay the one thing that I see immediately is that your while loop never actully exits. Not once. Why? Well simple your exit condition is the row <= numStars, yet nither numStars nor row actually change their values within the loop. In short row always equals 1 and thus never is equal to greater than numStars and the while loop does not terminate.
Second thing is that your star drawing logic is not correct. Meaning you have not told to draw the specific number of stars in one given line. For starters the System.out.println() command should be in the loop not outside it. For your purposes a for-loop nested within a while-loop is much better.
If you think you know what's wrong your program than read no further and go try it on your own. But if you still have no clue below is my modification of your code that actually produces the pattern you want, it might provide you with more hints.
import java.io.*;
class starWedge{
public static void main (String[] args ) throws IOException{
int numStars; // the number of stars
int row ; // current row number
int star; // the number of stars in this row so far
BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
String inputData;
// collect input data from user
System.out.println( "Initial number of stars:" );
inputData = userin.readLine();
numStars = Integer.parseInt( inputData );
row = 1;
while (numStars > 0){
for(star = 1; star<=numStars; star++){
System.out.print("*");
numStars = numStars - 1;
System.out.println(); // end each line
} -
do{
if((orderType != 'g') || (orderType != 'w')){
System.out.println("Please enter g or w only.");
}while((orderType == 'g') || (orderType == 'w'));
I need help with this loop... I have to make sure it will be able to pop the input back after the invalid input... i tried to fix it...wont stop and stay in same loop till it gets the valid before go to other loop... how? am i missing something?I know you've already been answered, but just a bit more...
if((orderType != 'g') || (orderType != 'w'))That would always be true. All characters are either not equal to 'g' or not equal to 'w'.
'x' : neither 'g' nor 'w'. Evaluates to true.
'g' : not 'w', still evaluates to true.
'w': not 'g', still evaluates to true. -
my ipod generation 5 will not come out of recovery mode. i was simply updating my software and this happened. it will not let me restore it comes up with and error. please help, thanks.
Hey erinoneill24,
Thanks for using Apple Support Communities.
Sounds like you can't update your device. You don't mention an error that it gives you. Take a look at both of these articles to troubleshoot.
iPod displays "Use iTunes to restore" message
http://support.apple.com/kb/ts1441?viewlocale=it_it
If you can't update or restore your iOS device
http://support.apple.com/kb/HT1808?viewlocale=de_DE_1
If you started your device in recovery mode by mistake, restart it to exit recovery mode. Or you can just wait—after 15 minutes the device will exit recovery mode by itself.
Have a nice day,
Mario -
iPhone not being recognized and cannot be activated for service--what does this mean? I can't sync with iTunes. Please help.
When I connect iPhone to USB iTunes is giving me the above message. Please advise if you know the fix.
Thanks,
Lina1116did you find a fix?
Maybe you are looking for
-
IMovie HD 6 won'c import from Sony DCR-PC109
So I am among the legion of folks on here, it seems, that are having an issue with iMovie HD not able to import my video from my camera -- Sony DCR-PC109. 1] It worked on my last movie in August (cords, camera, etc) 2] NO, I did not put the plug in u
-
Nokia music activation problam
I have problam for nokia music activation problam.so please help me nd send my phone voucher code..
-
is moving to iCloud free: my iPhone is showing a 20GB storage plan for $40 a year?
-
Entry Point Drop Site Key (to 9 chars) = LOCY11740 has no effect
We have the following entry in two places within our .PST file. Entry Point Drop Site Key (to 9 chars) = LOCY11740 I am expecting to see "LOCY11740" in position 52 of the .CSM mail.dat file. Instead I see "ORIGIN". We are testing using Presort rel
-
Mount ocfs2 error in oracle 10g installation on vmware
Dear All this is very urgent.....kindly help me... i m running this command for mount ocfs folder but not run gives error below....... [root@rac1 ~]#mount -t ocfs2 -o datavolume,nointr /dev/sda1 /ocfs ocfs2_hb_ctl: Bad magic number in superblock whil