Package org.htmlparser.util

Examples of org.htmlparser.util.ParserException


                    cursor.advance ();
                }
            }
            catch (IOException ioe)
            {
                throw new ParserException (
                    "problem reading a character at position "
                    + cursor.getPosition (), ioe);
            }
        else if (offset > i)
        {
            // historic read
            try
            {
                ret = mSource.getCharacter (i);
            }
            catch (IOException ioe)
            {
                throw new ParserException (
                    "can't read a character at position "
                    + i, ioe);
            }
            cursor.advance ();
        }
        else
            // hmmm, we could skip ahead, but then what about the EOL index
            throw new ParserException (
                "attempt to read future characters from source "
                + i + " > " + mSource.offset ());

        // handle \r
        if ('\r' == ret)
        {   // switch to single character EOL
            ret = '\n';

            // check for a \n in the next position
            if (mSource.offset () == cursor.getPosition ())
                try
                {
                    i = mSource.read ();
                    if (Source.EOF == i)
                    {
                        // do nothing
                    }
                    else if ('\n' == (char)i)
                        cursor.advance ();
                    else
                        try
                        {
                            mSource.unread ();
                        }
                        catch (IOException ioe)
                        {
                            throw new ParserException (
                                "can't unread a character at position "
                                + cursor.getPosition (), ioe);
                        }
                }
                catch (IOException ioe)
                {
                    throw new ParserException (
                        "problem reading a character at position "
                        + cursor.getPosition (), ioe);
                }
            else
                try
                {
                    if ('\n' == mSource.getCharacter (cursor.getPosition ()))
                        cursor.advance ();
                }
                catch (IOException ioe)
                {
                    throw new ParserException (
                        "can't read a character at position "
                        + cursor.getPosition (), ioe);
                }
        }
        if ('\n' == ret)
View Full Code Here


                    cursor.retreat ();
            }
        }
        catch (IOException ioe)
        {
            throw new ParserException (
                "can't read a character at position "
                + cursor.getPosition (), ioe);
        }
    }
View Full Code Here

                        }
                    }
                    catch (UnknownHostException uhe)
                    {
                        int message = (int)(Math.random () * FOUR_OH_FOUR.length);
                        throw new ParserException (FOUR_OH_FOUR[message], uhe);
                    }
                    catch (IOException ioe)
                    {
                        throw new ParserException (ioe.getMessage (), ioe);
                    }
                }
                finally
                {
                    if ((null != getProxyHost ()) && (0 != getProxyPort ()))
                    {
                        sysprops = System.getProperties ();
                        if (null != set)
                            sysprops.put ("proxySet", set);
                        else
                            sysprops.remove ("proxySet");
                        if (null != host)
                            sysprops.put ("proxyHost", host);
                        else
                            sysprops.remove ("proxyHost");
                        if (null != port)
                            sysprops.put ("proxyPort", port);
                        else
                            sysprops.remove ("proxyPort");
                        if (null != host2)
                            sysprops.put ("http.proxyHost", host2);
                        else
                            sysprops.remove ("http.proxyHost");
                        if (null != port2)
                            sysprops.put ("http.proxyPort", port2);
                        else
                            sysprops.remove ("http.proxyPort");
                        System.setProperties (sysprops);
                    }
                }
            }
            catch (IOException ioe)
            {
                String msg = "Error in opening a connection to "
                    + url.toExternalForm ();
                ParserException ex = new ParserException (msg, ioe);
                throw ex;
            }
        }
        while (repeat);

View Full Code Here

                ret = openConnection (url);
            }
            catch (MalformedURLException murle2)
            {
                String msg = "Error in opening a connection to " + string;
                ParserException ex = new ParserException (msg, murle2);
                throw ex;
            }
            catch (IOException ioe)
            {
                String msg = "Error in opening a connection to " + string;
                ParserException ex = new ParserException (msg, ioe);
                throw ex;
            }
        }

        return (ret);
View Full Code Here

        {
            getConnection ().connect ();
        }
        catch (UnknownHostException uhe)
        {
            throw new ParserException ("Connect to "
                + mConnection.getURL ().toExternalForm () + " failed.", uhe);
        }
        catch (IOException ioe)
        {
            throw new ParserException ("Exception connecting to "
                + mConnection.getURL ().toExternalForm ()
                + " (" + ioe.getMessage () + ").", ioe);
        }
        type = getContentType ();
        charset = getCharset (type);
        try
        {
            contentEncoding = connection.getContentEncoding();
            if ((null != contentEncoding)
                && (-1 != contentEncoding.indexOf ("gzip")))
            {
                stream = new Stream (new GZIPInputStream (
                    getConnection ().getInputStream ()));
            }
            else if ((null != contentEncoding)
                && (-1 != contentEncoding.indexOf ("deflate")))
            {
                stream = new Stream (new InflaterInputStream (
                    getConnection ().getInputStream (), new Inflater (true)));
            }
            else
            {
                stream = new Stream (getConnection ().getInputStream ());
            }

            try
            {
                mSource = new InputStreamSource (stream, charset);
            }
            catch (UnsupportedEncodingException uee)
            {
//                StringBuffer msg;
//
//                msg = new StringBuffer (1024);
//                msg.append (getConnection ().getURL ().toExternalForm ());
//                msg.append (" has an encoding (");
//                msg.append (charset);
//                msg.append (") which is not supported, using ");
//                msg.append (DEFAULT_CHARSET);
//                System.out.println (msg.toString ());
                charset = DEFAULT_CHARSET;
                mSource = new InputStreamSource (stream, charset);
            }
        }
        catch (IOException ioe)
        {
            throw new ParserException ("Exception getting input stream from "
                + mConnection.getURL ().toExternalForm ()
                + " (" + ioe.getMessage () + ").", ioe);
        }
        mUrl = connection.getURL ().toExternalForm ();
        mIndex = new PageIndex (this);
View Full Code Here

                    cursor.advance ();
                }
            }
            catch (IOException ioe)
            {
                throw new ParserException (
                    "problem reading a character at position "
                    + cursor.getPosition (), ioe);
            }
        else if (offset > i)
        {
            // historic read
            try
            {
                ret = mSource.getCharacter (i);
            }
            catch (IOException ioe)
            {
                throw new ParserException (
                    "can't read a character at position "
                    + i, ioe);
            }
            cursor.advance ();
        }
        else
            // hmmm, we could skip ahead, but then what about the EOL index
            throw new ParserException (
                "attempt to read future characters from source "
                + i + " > " + mSource.offset ());

        // handle \r
        if ('\r' == ret)
        {   // switch to single character EOL
            ret = '\n';

            // check for a \n in the next position
            if (mSource.offset () == cursor.getPosition ())
                try
                {
                    i = mSource.read ();
                    if (Source.EOF == i)
                    {
                        // do nothing
                    }
                    else if ('\n' == (char)i)
                        cursor.advance ();
                    else
                        try
                        {
                            mSource.unread ();
                        }
                        catch (IOException ioe)
                        {
                            throw new ParserException (
                                "can't unread a character at position "
                                + cursor.getPosition (), ioe);
                        }
                }
                catch (IOException ioe)
                {
                    throw new ParserException (
                        "problem reading a character at position "
                        + cursor.getPosition (), ioe);
                }
            else
                try
                {
                    if ('\n' == mSource.getCharacter (cursor.getPosition ()))
                        cursor.advance ();
                }
                catch (IOException ioe)
                {
                    throw new ParserException (
                        "can't read a character at position "
                        + cursor.getPosition (), ioe);
                }
        }
        if ('\n' == ret)
View Full Code Here

                    cursor.retreat ();
            }
        }
        catch (IOException ioe)
        {
            throw new ParserException (
                "can't read a character at position "
                + cursor.getPosition (), ioe);
        }
    }
View Full Code Here

        Parser parser;
        try {
            parser = new Parser("http://www.google.com");
        }
        catch (Exception e ){
            throw new ParserException("You must be offline! This test needs you to be connected to the internet.",e);
        }

        Node[] node = new Node[500];
        int i = 0;
        for (NodeIterator e = parser.elements();e.hasMoreNodes();)
View Full Code Here

            parser = new Parser (connection);
            parser.setNodeFactory (new PrototypicalNodeFactory (true));
        }
        catch (Exception e)
        {
            throw new ParserException ("You must be offline! This test needs you to be connected to the internet.", e);
        }

        pass = false;
        for (enumeration = parser.elements (); enumeration.hasMoreNodes ();)
        {
View Full Code Here

                    mMark = -1;
                    if (0 != offset)
                    {
                        new_chars = new char[offset];
                        if (offset != read (new_chars))
                            throw new ParserException ("reset stream failed");
                        for (int i = 0; i < offset; i++)
                            if (new_chars[i] != buffer[i])
                                throw new EncodingChangeException ("character mismatch (new: "
                                + new_chars[i]
                                + " [0x"
                                + Integer.toString (new_chars[i], 16)
                                + "] != old: "
                                + " [0x"
                                + Integer.toString (buffer[i], 16)
                                + buffer[i]
                                + "]) for encoding change from "
                                + encoding
                                + " to "
                                + character_set
                                + " at character offset "
                                + i);
                    }
                }
                catch (IOException ioe)
                {
                    throw new ParserException (ioe.getMessage (), ioe);
                }
            }
            catch (IOException ioe)
            {   // bug #1044707 mark()/reset() issues
                throw new ParserException ("Stream reset failed ("
                    + ioe.getMessage ()
                    + "), try wrapping it with a org.htmlparser.lexer.Stream",
                    ioe);
            }
        }
View Full Code Here

TOP

Related Classes of org.htmlparser.util.ParserException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.