Page 2 of 10 FirstFirst 1234 ... LastLast
Results 21 to 40 of 186
  1. #21
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Thanks Tolls, I get what your saying but im still not having much luck if im reading in my file

    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    File myhtml = new File("C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html");
    FileInputStream fileinput = null;
    BufferedInputStream mybuffer = null;
    DataInputStream datainput = null;

    fileinput = new FileInputStream(myhtml);
    mybuffer = new BufferedInputStream(fileinput);
    datainput = new DataInputStream(mybuffer);

    while (datainput.available() != 0) {
    System.out.println(datainput.readLine());
    }

    myHTML.close();
    mybuffer.close();
    datainput.close();

    //then i need to call in my strings so and there is only one instance on a line :)
    //i realise this is probably going to all be wrong but again this is the first time ive used java, other than doing the old hello world and other silly tutorials everyone does earlier today.

    IndexOf(str, <@dynamichtml )
    indexOf(str, @>)
    substring(int beginIndex)
    "dynamichtml ".substring(13, 40) returns ""

    but then my array needs to autopopulate, I cannot assign the values directly, I have no idea about that and then obv just write out the output i guess.

  2. #22
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    File myhtml = new File("C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html");
    FileInputStream fileinput = null;
    // you'll have to excuse me, other than writing a few hello world programs etc which is pretty much all of the java i've done EVER, earlier this morning this is what im doing.

    //read in the file

    BufferedInputStream mybuffer = null;
    DataInputStream datainput = null;

    fileinput = new FileInputStream(myhtml);
    mybuffer = new BufferedInputStream(fileinput);
    datainput = new DataInputStream(mybuffer);

    while (datainput.available() != 0) {
    System.out.println(datainput.readLine());
    }

    myHTML.close();
    mybuffer.close();
    datainput.close();

    IndexOf(str, <@dynamichtml ) //look for string containing dynamic html ///////////////////////////////within the document
    indexOf(str, @>) //look for the end of that string
    substring(int beginIndex)
    "dynamichtml ".substring(13, 40) returns ""
    //look for anything after dynamichtml and return the value???

    however once the value is returned i need to loop it until the end of the doc and create an array accordingly, basically an auto array which automatically assigns the value after dynamichtml.

    I know this is probably retarded to you guys but im really stuck and i dont normally work on java. I'll be back working on js later lol. Defo gna book a course tho, this is silly. But still here i am :) stuck at my lovely desk lol

  3. #23
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    BufferedReader and FileReader, for starters.
    You don't need the DataInputStream either.

    So (and use code tags when posting code to retain formatting):
    Java Code:
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(your file in here));
        String line = null;
        while ((line = br.readLine) !=  null) {
            // Process the line.
        }
    } catch (whatever exceptions it is this throws) {
        ex.printStackTrace();
    } finally {
        if (br != null) {
            br.close();  // I suspect this needs to be in a try/catch
        }
    }
    Hope that helps as a startpoint. I don't usually post this much code, but you were almost there, just had the wrong type of thing for reading lines from a text file.

    ETA: The exceptions are FileNotFoundException and IOException I think.

  4. #24
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Thanks Tolls :)

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    As a heads up, make the processLine() a method, that takes a String (the line) and adds the result to your array if it's the right sort of line. Just helps to break it up a bit, and separates the line processing from the file reading.

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Just to be a nitpicker (I love that role): this is not the way to approach html files; what if the opening part of the tag is on a previous line from the closing tag? What if the opening (or closing) tag also happens to be part of the CDATA (text) part of the file. What if the text file is not well formed? btw regular expressions are also not a solution to this little problem.

    kind regards,

    Jos

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    I'm still not sure what the OP wants. Given his html as shown above, what string(s) does he want to parse out?
    Is it just and only this: "TimelineManager_quicksearch_form"

    An example is worth a lot of posts

  8. #28
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    Hi guys,

    sorry about the late reply, yes the "TimelineManager_quicksearch_form" is the only part that I need to store and print out.

    With regards to opening and closing tags they are on the same line, everything relating to each resource is laid out pretty much exactly the same, many are standard ucm resource files minor a few schema adaptations.

    Its b nice to actually find a working model of a string being pulled and stored tbh, every web site i find doesn't have the best examples.

    really greatful for all your input guys it is helping. Friday im on a new project hopefully, just want to get this out the way and done with & take a few asperin lol :)

  9. #29
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Default

    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    //read from html file // is it the line above where i change the null value to dynamichtml?
    while ((line = br.readLine) != null) {
    // Process the line.// here and then Im guessing I need to add a while line =true capture string?

    }
    } catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    } finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }


    ////////////////////////////////////////////////////////////////////////////////////

    Looking around online tonight at string methods etc im getting a bit confused where & how do i implement the search for dynamichtml in here becuase I need to do that before I can do an If string is equal to dynamichtml then add an index of to capture the bit after and add to an array?

    Also why when compared to sites like tizag.com. w3schools etc where they really make learning web/programming languages easy are Java help sites so pants, i mean you guys are awesome but seriously, no one not even Oracle have bothered to actually make life easy for anyone lol. Someone should they'd make a bundle.
    Last edited by nickrowe_2k; 05-20-2010 at 12:49 AM.

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    The String class has all the methods you need. If the data does not span a line, then
    read the html file line by line and use the indexOf() method to find the beginning part of the string, then use indexOf() again to find the end of the string and then use substring() to remove the desired part.

    Looking back at your code you already have this.

    So what more do you need?

  11. #31
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    Just to be a nitpicker (I love that role): this is not the way to approach html files; what if the opening part of the tag is on a previous line from the closing tag? What if the opening (or closing) tag also happens to be part of the CDATA (text) part of the file. What if the text file is not well formed? btw regular expressions are also not a solution to this little problem.

    kind regards,

    Jos
    You may as well tell a three-year-old not to touch a hot stove, Jos. They won't learn until they have been burned. :)

    -Gary-

  12. #32
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by gcalvin View Post
    You may as well tell a three-year-old not to touch a hot stove, Jos. They won't learn until they have been burned. :)
    Ok, who sets the OP on fire? ;-)

    kind regards,

    Jos

  13. #33
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by JosAH View Post
    Just to be a nitpicker (I love that role): this is not the way to approach html files; what if the opening part of the tag is on a previous line from the closing tag? What if the opening (or closing) tag also happens to be part of the CDATA (text) part of the file. What if the text file is not well formed? btw regular expressions are also not a solution to this little problem.

    kind regards,

    Jos
    The problem is that their HTML has these extra lumps in...the <@...@> bits. I would suspect that an html parser would choke on those, or not pick them out neatly.

    This, to me, means that this is not html at the point of parsing, so...

    ETA: Put it this way, they have a file that has this data in it in several places:
    <@dynamichtml something_they_want_to_find@>

    At this point this is not an html file...it's just text that has lines like the above in it. At least that's what I'm getting from this, since they say there's a processing stage that takes these placeholders and turns the file into something the client browser can then display...ie html. In other words, this is no more html than a JSP page is.
    Last edited by Tolls; 05-20-2010 at 08:55 AM.

  14. #34
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Java Code:
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren McDonald\Desktop\Nick\Java\my.html"));
        String line = null;
    	//read from html file // is it the line above where i change the null value to dynamichtml?
        while ((line = br.readLine) !=  null) {
            // Process the line.// here and then Im guessing I need to add a while line =true capture string?
    		
        }
    } catch (whatever exceptions it is this throws) {
        ex.printStackTrace();
    } finally {
    try {
    	if (br != null) {
        }
    } catch (br.close();
    }
    All this bit of code here does is read a line at a time from the file.
    That's it.
    The bit you now need to do is write the code that figures out whether that line is something you're interested in (indexOf() returns something useful) and, if it is, then write the bit that gets hold of the part of that line you want. That's the "Process line" part.

    ETA: Actually that code there won't compile, but you'd find that out pretty quickly...:)

  15. #35
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Smile

    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(your file in here"C:\Documents and Settings\Kieren

    McDonald\Desktop\Nick\Java\my.html"));
    String line = null;
    //read from html file //
    while ((line = br.readLine) != null) {
    // Process the line.//


    var resourceStart="dynamichtml "//variable for start of resource
    var resourceEnd="@>" //variable for end of resource
    if(resourceStart.indexOf("dynamichtml ") !=-1) //if statement to find resource
    {

    //now if true HOW do i capture the string between the start and end variables, looking online I have only

    //found examples of searching for something within the same string which is simple but nothing for using

    //two and cutting whats in between.
    }



    }
    } catch (whatever exceptions it is this throws) {
    ex.printStackTrace();
    } finally {
    try {
    if (br != null) {
    }
    } catch (br.close();
    }
    Last edited by nickrowe_2k; 05-20-2010 at 01:16 PM.

  16. #36
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    That's some bizarre cross between Java and Javascript.
    And please use code tags!
    Unformatted code is really difficult to read.

    ...and your requirement has changed.
    Earlier on you said you just wanted the string after the "<@dynamichtml".
    Now you want the html between those markers?

    OK. How do you think you can find the stuff after the above marker, and until you hit an "<@end@>" marker? You don't need the web for this if you've programmed in other languages...this is not a Java problem at the moment.

    You've found a marker that, to you, says "start grabbing lines here"...so what do you do now?

    And I really would suggest using methods, rather than doing this in a single method.

  17. #37
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Smile

    I found an example from a Java site, i thought it was a bit too similar but thought that i must just be being silly.

    Thats right I would like to capture the string resource name after dynamichtml however attached to the end of that string on the end of that line is "@> so surely if i return the rest of the line I will also return that end part of the string aswel?

    Basically I found an example that says start grabbing lines at dynamichtml and then I want to stop at "@>" and repeat the scan for each line after.

    Please feel free to correct me if im wrong but the way im thinking of things program wise is doing something along the lines of


    Search line for string "dynamichtml" && string "@>"
    If "dynamichtml" && "@>" == TRUE
    Then capture value between "dynamichtml" && "@>"
    store in array
    repeat for next line
    Last edited by nickrowe_2k; 05-20-2010 at 01:29 PM. Reason: update

  18. #38
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    imho the OP is just obscuring the problem with all that html hullabaloo. It is just a String searching problem where your search for a String beg and a String end in another String; everything in between those Strings needs to be returned; here's a regexp solution:

    Java Code:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class Find {
    
    	public static String find(String beg, String end, String line) {
    		
    		Pattern p=Pattern.compile(beg+"(.*)"+end);
    		Matcher m= p.matcher(line);
    		
    		return m.find()?line.substring(m.start(1), m.end(1)):null;
    	
    	}
    	public static void main(String[] args) {
    		
    		System.out.println(find("<@dynamichtml", "@>", "This is <@dynamichtml foo @>; so there"));
    		System.out.println(find("<@dynamichtml", "@>", "This isn't <dynamichtml foo >; so there"));
    	}
    }
    kind regards,

    Jos
    Last edited by JosAH; 05-20-2010 at 01:40 PM.

  19. #39
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Which is what I was saying, almost from the beginning...

    Except that they seem to want the stuff between the open (ie "<@dynamichtml @>") and close (ie "<@end@>") markers, which are on separate lines. As well as the bit in the first marker.

    I know how to do it, but I'm not going to code dump here.

    And I did say someone would do a regex for it...:)

  20. #40
    nickrowe_2k is offline Member
    Join Date
    May 2010
    Location
    Buckinghamshire
    Posts
    77
    Rep Power
    0

    Smile

    Hi JosAh will that work with the code from earlier for reading in a file? Im only asking as I dont know anything about regex.

    Also in your code, please correct me if im wrong you have created a class that searches for the beginning and end of a string using a wild card?

    you are then printing out,

    System.out.println(find("<@dynamichtml", "@>", "This is <@dynamichtml foo @>; so there"));
    System.out.println(find("<@dynamichtml", "@>", "This isn't <dynamichtml foo >; so there"));

    so where are "<@dynamichtml", and "@>" defined within the string variables "beg" & "end" and also where does the value between them "unknown string" print out.

    regards Nick

Page 2 of 10 FirstFirst 1234 ... LastLast

Similar Threads

  1. How can I include a html file in html textarea?
    By surya_dks in forum New To Java
    Replies: 2
    Last Post: 10-04-2008, 07:20 AM
  2. get data from servlet to html
    By lema in forum Java Servlet
    Replies: 7
    Last Post: 05-22-2008, 04:00 PM
  3. get data from html to servlet
    By lema in forum Java Servlet
    Replies: 66
    Last Post: 04-09-2008, 02:43 PM
  4. Replies: 0
    Last Post: 04-04-2008, 09:36 AM
  5. how to upload a file along with html form data
    By pranith in forum Java Servlet
    Replies: 3
    Last Post: 07-30-2007, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •