Package org.htmlparser

Examples of org.htmlparser.Attribute


     * @return The value associated with the attribute or null if it does
     * not exist, or is a stand-alone or
     */
    public String getAttribute (String name)
    {
        Attribute attribute;
        String ret;

        ret = null;

        attribute = getAttributeEx (name);
        if (null != attribute)
            ret = attribute.getValue ();

        return (ret);
    }
View Full Code Here


        boolean singleq;
        boolean doubleq;
        String ref;
        StringBuffer buffer;
        char quote;
        Attribute attribute;

        // first determine if there's whitespace in the value
        // and while we'return at it find a suitable quote character
        needed = false;
        singleq = true;
        doubleq = true;
        if (null != value)
            for (int i = 0; i < value.length (); i++)
            {
                ch = value.charAt (i);
                if (Character.isWhitespace (ch))
                    needed = true;
                else if ('\'' == ch)
                    singleq  = false;
                else if ('"' == ch)
                    doubleq = false;
            }

        // now apply quoting
        if (needed)
        {
            if (doubleq)
                quote = '"';
            else if (singleq)
                quote = '\'';
            else
            {
                // uh-oh, we need to convert some quotes into character references
                // convert all double quotes into &#34;
                quote = '"';
                ref = "&quot;"; // Translate.encode (quote);
                // JDK 1.4: value = value.replaceAll ("\"", ref);
                buffer = new StringBuffer (value.length() * 5);
                for (int i = 0; i < value.length (); i++)
                {
                    ch = value.charAt (i);
                    if (quote == ch)
                        buffer.append (ref);
                    else
                        buffer.append (ch);
                }
                value = buffer.toString ();
            }
        }
        else
            quote = 0;
        attribute = getAttributeEx (key);
        if (null != attribute)
        {   // see if we can splice it in rather than replace it
            attribute.setValue (value);
            if (0 != quote)
                attribute.setQuote (quote);
        }
        else
            setAttribute (key, value, quote);
    }
View Full Code Here

     * Remove the attribute with the given key, if it exists.
     * @param key The name of the attribute.
     */
    public void removeAttribute (String key)
    {
        Attribute attribute;

        attribute = getAttributeEx (key);
        if (null != attribute)
            getAttributesEx ().remove (attribute);
    }
View Full Code Here

     * @param quote The quote character to be used around value.
     * If zero, it is an unquoted value.
     */
    public void setAttribute (String key, String value, char quote)
    {
        setAttribute (new Attribute (key, value, quote));
    }
View Full Code Here

     */
    public Attribute getAttributeEx (String name)
    {
        Vector attributes;
        int size;
        Attribute attribute;
        String string;
        Attribute ret;

        ret = null;

        attributes = getAttributesEx ();
        if (null != attributes)
View Full Code Here

    {
        boolean replaced;
        Vector attributes;
        int length;
        String name;
        Attribute test;
        String test_name;

        replaced = false;
        attributes = getAttributesEx ();
        length =  attributes.size ();
        if (0 < length)
        {
            name = attribute.getName ();
            for (int i = 1; i < attributes.size (); i++)
            {
                test = (Attribute)attributes.elementAt (i);
                test_name = test.getName ();
                if (null != test_name)
                    if (test_name.equalsIgnoreCase (name))
                    {
                        attributes.setElementAt (attribute, i);
                        replaced = true;
                    }
            }
        }
        if (!replaced)
        {
            // add whitespace between attributes
            if ((0 != length) && !((Attribute)attributes.elementAt (length - 1)).isWhitespace ())
                attributes.addElement (new Attribute (" "));
            attributes.addElement (attribute);
        }
    }
View Full Code Here

     * zeroth element of the attribute vector).
     * @param name The tag name.
     */
    public void setTagName (String name)
    {
        Attribute attribute;
        Vector attributes;
        Attribute zeroth;

        attribute = new Attribute (name, null, (char)0);
        attributes = getAttributesEx ();
        if (null == attributes)
        {
            attributes = new Vector ();
            setAttributesEx (attributes);
        }
        if (0 == attributes.size ())
            // nothing added yet
            attributes.addElement (attribute);
        else
        {
            zeroth = (Attribute)attributes.elementAt (0);
            // check for attribute that looks like a name
            if ((null == zeroth.getValue ()) && (0 == zeroth.getQuote ()))
                attributes.setElementAt (attribute, 0);
            else
                attributes.insertElementAt (attribute, 0);
        }
    }
View Full Code Here

    public String toHtml (boolean verbatim)
    {
        int length;
        int size;
        Vector attributes;
        Attribute attribute;
        StringBuffer ret;

        length = 2;
        attributes = getAttributesEx ();
        size = attributes.size ();
        for (int i = 0; i < size; i++)
        {
            attribute = (Attribute)attributes.elementAt (i);
            length += attribute.getLength ();
        }
        ret = new StringBuffer (length);
        ret.append ("<");
        for (int i = 0; i < size; i++)
        {
            attribute = (Attribute)attributes.elementAt (i);
            attribute.toString (ret);
        }
        ret.append (">");

        return (ret.toString ());
    }
View Full Code Here

     */
    public boolean isEmptyXmlTag ()
    {
        Vector attributes;
        int size;
        Attribute attribute;
        String name;
        int length;
        boolean ret;

        ret = false;

        attributes = getAttributesEx ();
        size = attributes.size ();
        if (0 < size)
        {
            attribute = (Attribute)attributes.elementAt (size - 1);
            name = attribute.getName ();
            if (null != name)
            {
                length = name.length ();
                ret = name.charAt (length - 1) == '/';
            }
View Full Code Here

     */
    public void setEmptyXmlTag (boolean emptyXmlTag)
    {
        Vector attributes;
        int size;
        Attribute attribute;
        String name;
        String value;
        int length;
       
        attributes = getAttributesEx ();
        size = attributes.size ();
        if (0 < size)
        {
            attribute = (Attribute)attributes.elementAt (size - 1);
            name = attribute.getName ();
            if (null != name)
            {
                length = name.length ();
                value = attribute.getValue ();
                if (null == value)
                    if (name.charAt (length - 1) == '/')
                    {
                        // already exists, remove if requested
                        if (!emptyXmlTag)
                            if (1 == length)
                                attributes.removeElementAt (size - 1);
                            else
                            {
                                // this shouldn't happen, but covers the case
                                // where no whitespace separates the slash
                                // from the previous attribute
                                name = name.substring (0, length - 1);
                                attribute = new Attribute (name, null);
                                attributes.removeElementAt (size - 1);
                                attributes.addElement (attribute);
                            }
                    }
                    else
                    {
                        // ends with attribute, add whitespace + slash if requested
                        if (emptyXmlTag)
                        {
                            attribute = new Attribute (" ");
                            attributes.addElement (attribute);
                            attribute = new Attribute ("/", null);
                            attributes.addElement (attribute);
                        }
                    }
                else
                {
                    // some valued attribute, add whitespace + slash if requested
                    if (emptyXmlTag)
                    {
                        attribute = new Attribute (" ");
                        attributes.addElement (attribute);
                        attribute = new Attribute ("/", null);
                        attributes.addElement (attribute);
                    }
                }
            }
            else
            {
                // ends with whitespace, add if requested
                if (emptyXmlTag)
                {
                    attribute = new Attribute ("/", null);
                    attributes.addElement (attribute);
                }
            }
        }
        else
            // nothing there, add if requested
            if (emptyXmlTag)
            {
                attribute = new Attribute ("/", null);
                attributes.addElement (attribute);
            }
    }
View Full Code Here

TOP

Related Classes of org.htmlparser.Attribute

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.