★ wanayoo — archive 1999 http://java.webdeveloper.com/BMMenu/BookmarkParserJava.htmlNouvelle recherche | Portail wanayoo


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/ Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Business Search
Submit Your Site
Promote Your Website
Find a Consultant
Anti-Virus Software
Build Flash Online
Software Store
Register Domains
Fax to/from Your PC
Tech Magazines - FREE
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal The WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:



Bookmark Parser.java



import java.io.*;


public class BookmarkParser {

    public static final int EOF         = -1;
    public static final int UNKNOWN     =  0;
    public static final int BOOKMARK    =  1;
    public static final int FOLDER      =  2;
    public static final int FOLDER_END  =  3;
    public static final int SEPARATOR   =  4;

    int         type = UNKNOWN;
    TagGetter   t;
    String      name, link;


    public BookmarkParser(Reader r)
            throws IOException
    {
        t = new TagGetter(r);
    }

    public int    getType(){        return type;   }
    public String getName(){        return name;   }
    public String getLink(){        return link;   }


    public int next() throws IOException{
        String s = t.next();

        if( s == null ) return EOF;

        if( isItem(s) ){
            s = t.next();
            if( isFolder(s) )     return nextFolder(s);
            if( isBookmark(s))    return nextBookmark(s);
            error("ITEM: Unknown type: "+s);
            return UNKNOWN;
        }
        else if( isFolderEnd(s))  return nextFolderEnd(s);
        else if( isSeparator(s))  return nextSeparator(s);
        else                      return nextUnknown(s);
    }



    // ------------------- protected methods below -----------------//

    boolean isItem     (String s) { return s.equals("<DT>"); }
    boolean isFolder   (String s) { return s.startsWith("<H3"); }
    boolean isBookmark (String s) { return s.startsWith("<A HREF"); }
    boolean isFolderEnd(String s) { return s.equals("</DL>"); }
    boolean isSeparator(String s) { return s.equals("<HR>"); }

    int nextFolder   (String s)   throws IOException
    {
        name = t.next();    link = null;
        String folderEnd = t.next();
        if( !folderEnd.equals("</H3>") )
            error("FOLDER_END: expected </H3>, got "+folderEnd);
        return type = FOLDER;
    }

    int nextBookmark (String s) throws IOException
    {
        int firstQuote;
        link = s.substring(
                firstQuote = s.indexOf('"') + 1
           ,    s.indexOf('"', firstQuote)
        );
        name = t.next();
        if( name.equals("</A>") )                            // no bookmark name specified
            name = "";
        else {
            String bookmarkEnd = t.next();
            if( ! bookmarkEnd.equals("</A>") )              // clear until the end of <A ..>...</A>
                error("ITEM: Expected </A>, got "+bookmarkEnd
                    +", bookmark name=" + name);
        }
        return type = BOOKMARK;
    }

    int nextFolderEnd(String s){    return type = FOLDER_END;}
    int nextSeparator(String s){    return type = SEPARATOR;}
    int nextUnknown  (String s){    return type = UNKNOWN;}

/*

    public static void main(String args[])
        throws FileNotFoundException, IOException
    {
         if( args.length < 1 ){
            System.out.println("Usage: java BookmarkParser bookmark.htm");
            return;
        }

        System.out.println("Loading file "+args[0]);

        FileReader r = new FileReader(args[0]);
        BookmarkParser p = new BookmarkParser(r);

        while( p.next() != BookmarkParser.EOF ){
            switch(p.getType()){
            case p.BOOKMARK:
                print("BOOKMARK: " + p.getName() + " -> " + p.getLink());
                break;
            case p.FOLDER:
                print("FOLDER START ----" + p.getName() );
                break;
            case p.FOLDER_END:
                print("FOLDER END ----");
                break;
            default:
                break;
            }
        }    // while
    }
*/
    static void print(String s){ System.out.println(s); }
    static void error(String s){ System.out.println("*** " + s); }

}

Return to Bookmark Menu Applet

internet.com logo










WebDev News

News Server Glitch Angers AOL Customers

Open Source Group Issues Top Ten Web Vulnerabilities

What's in a Name for Microsoft? Not .NET





FastParser
FastParser is an XML parser for non validating XML processing, it is based on a Turing finite state automaton.
Download of the Week
MagicTrick
MagicTrick is reminiscent of everyone's childhood. Just like Daddy's magic tricks, this applet is able to pick your card,(out of 21),every time! Source code included.

JB User Poll
Certification vs. experience--what's your opinion?
The JavaBoutique Top 15:
1. DJPopMenu
2. NavBar
3. PingPong
4. AnimLetters_anim
5. RushHour
6. 3DMaze
7. AScroll2
8. ChompText
9. AnimatedTreeControl
10. Distorter
11. Encyclo
12. Viewer
13. TypoToolMotion11
14. Nibbly
15. Tsukoban
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Capellas Lays Out 100 Day Plan for WorldCom
WorldCom's new chairman and CEO Michael Cappellas charges out of the gates with a 100-day plan aimed at laying the foundation for the company's climb out of the largest bankruptcy in U.S. history.

Competition Heats Up Between DBS, Cable
Digital television is attracting millions of consumers, and satellite and cable operators are racing to grab the market share.

Web Conferencing Choices on the Rise
While corporate travel budgets have all but evaporated over the last two years, the use of Web conferencing has grown by leaps and bounds. Jacqueline Emigh takes a look at the options currently available and explores what's on the horizon for the Web conferencing software and services market.


Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/