org.htmlparser.Node - java examples

Here are the examples of the java api org.htmlparser.Node taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

125 Examples 7

19 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Returns the node number of the first node containing the given text.
 * This can be useful to index into the composite tag and get other children.
 * Text is compared without case sensitivity and conversion to uppercase
 * uses the supplied locale.
 * @return int The node index in the children list of the node containing
 * the text or -1 if not found.
 * @param locale The locale to use in converting to uppercase.
 * @param text The text to search for.
 */
public int findPositionOf(String text, Locale locale) {
    Node node;
    int loc;
    loc = 0;
    text = text.toUpperCase(locale);
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        if (-1 != node.toPlainTextString().toUpperCase(locale).indexOf(text))
            return loc;
        loc++;
    }
    return -1;
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
private void adjustVectorCapacity() {
    capacity += capacityIncrement;
    capacityIncrement *= 2;
    Node[] oldData = nodeData;
    nodeData = newNodeArrayFor(capacity);
    System.arraycopy(oldData, 0, nodeData, 0, size);
    numberOfAdjustments++;
}

19 View Complete Implementation : StringFilter.java
Copyright Apache License 2.0
Author : bbossgroups
// 
// NodeFilter interface
// 
/**
 * Accept string nodes that contain the string.
 * @param node The node to check.
 * @return <code>true</code> if <code>node</code> is a {@link Text} node
 * and contains the pattern string, <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    String string;
    boolean ret;
    ret = false;
    if (node instanceof Text) {
        string = ((Text) node).getText();
        if (!getCaseSensitive())
            string = string.toUpperCase(getLocale());
        ret = (-1 != string.indexOf(mUpperPattern));
    }
    return (ret);
}

19 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Returns the node number of a child node given the node object.
 * This would typically be used in conjuction with digUpStringNode,
 * after which the string node's parent can be used to find the
 * string node's position. Faster than calling findPositionOf(text)
 * again. Note that the position is at a linear level alone - there
 * is no recursion in this method.
 * @param searchNode The child node to find.
 * @return The offset of the child tag or -1 if it was not found.
 */
public int findPositionOf(Node searchNode) {
    Node node;
    int loc = 0;
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        if (node == searchNode) {
            return loc;
        }
        loc++;
    }
    return -1;
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
public clreplaced NodeList implements Serializable {

    private static final int INITIAL_CAPACITY = 10;

    // private static final int CAPACITY_INCREMENT=20;
    private Node[] nodeData;

    private int size;

    private int capacity;

    private int capacityIncrement;

    private int numberOfAdjustments;

    public NodeList() {
        size = 0;
        capacity = INITIAL_CAPACITY;
        nodeData = newNodeArrayFor(capacity);
        capacityIncrement = capacity * 2;
        numberOfAdjustments = 0;
    }

    /**
     * Create a one element node list.
     * @param node The initial node to add.
     */
    public NodeList(Node node) {
        this();
        add(node);
    }

    public void add(Node node) {
        if (size == capacity)
            adjustVectorCapacity();
        nodeData[size++] = node;
    }

    /**
     * Add another node list to this one.
     * @param list The list to add.
     */
    public void add(NodeList list) {
        for (int i = 0; i < list.size; i++) add(list.nodeData[i]);
    }

    /**
     * Insert the given node at the head of the list.
     * @param node The new first element.
     */
    public void prepend(Node node) {
        if (size == capacity)
            adjustVectorCapacity();
        System.arraycopy(nodeData, 0, nodeData, 1, size);
        size++;
        nodeData[0] = node;
    }

    private void adjustVectorCapacity() {
        capacity += capacityIncrement;
        capacityIncrement *= 2;
        Node[] oldData = nodeData;
        nodeData = newNodeArrayFor(capacity);
        System.arraycopy(oldData, 0, nodeData, 0, size);
        numberOfAdjustments++;
    }

    private Node[] newNodeArrayFor(int capacity) {
        return new Node[capacity];
    }

    public int size() {
        return size;
    }

    public Node elementAt(int i) {
        return nodeData[i];
    }

    public int getNumberOfAdjustments() {
        return numberOfAdjustments;
    }

    public SimpleNodeIterator elements() {
        return new SimpleNodeIterator() {

            int count = 0;

            public boolean hasMoreNodes() {
                return count < size;
            }

            public Node nextNode() {
                synchronized (NodeList.this) {
                    if (count < size) {
                        return nodeData[count++];
                    }
                }
                throw new NoSuchElementException("Vector Enumeration");
            }
        };
    }

    public Node[] toNodeArray() {
        Node[] nodeArray = newNodeArrayFor(size);
        System.arraycopy(nodeData, 0, nodeArray, 0, size);
        return nodeArray;
    }

    public void copyToNodeArray(Node[] array) {
        System.arraycopy(nodeData, 0, array, 0, size);
    }

    public String replacedtring() {
        StringBuilder buff = new StringBuilder();
        for (int i = 0; i < size; i++) buff.append(nodeData[i].toPlainTextString());
        return buff.toString();
    }

    /**
     * Convert this nodelist into the equivalent HTML.
     * @deprecated Use {@link #toHtml}.
     * @return The contents of the list as HTML text.
     */
    public String asHtml() {
        return (toHtml());
    }

    /**
     * Convert this nodelist into the equivalent HTML.
     * @return The contents of the list as HTML text.
     */
    public String toHtml() {
        StringBuilder buff = new StringBuilder();
        for (int i = 0; i < size; i++) buff.append(nodeData[i].toHtml());
        return buff.toString();
    }

    public Node remove(int index) {
        Node ret;
        ret = nodeData[index];
        System.arraycopy(nodeData, index + 1, nodeData, index, size - index - 1);
        nodeData[size - 1] = null;
        size--;
        return (ret);
    }

    public void removeAll() {
        size = 0;
        capacity = INITIAL_CAPACITY;
        nodeData = newNodeArrayFor(capacity);
        capacityIncrement = capacity * 2;
        numberOfAdjustments = 0;
    }

    /**
     * Return the contents of the list as a string.
     * Suitable for debugging.
     * @return A string representation of the list.
     */
    public String toString() {
        StringBuilder text = new StringBuilder();
        for (int i = 0; i < size; i++) text.append(nodeData[i]);
        return (text.toString());
    }

    /**
     * Filter the list with the given filter non-recursively.
     * @param filter The filter to use.
     * @return A new node array containing the nodes accepted by the filter.
     * This is a linear list and preserves the nested structure of the returned
     * nodes only.
     */
    public NodeList extractAllNodesThatMatch(NodeFilter filter) {
        return (extractAllNodesThatMatch(filter, false));
    }

    /**
     * Filter the list with the given filter.
     * @param filter The filter to use.
     * @param recursive If <code>true<code> digs into the children recursively.
     * @return A new node array containing the nodes accepted by the filter.
     * This is a linear list and preserves the nested structure of the returned
     * nodes only.
     */
    public NodeList extractAllNodesThatMatch(NodeFilter filter, boolean recursive) {
        Node node;
        NodeList children;
        NodeList ret;
        ret = new NodeList();
        for (int i = 0; i < size; i++) {
            node = nodeData[i];
            if (filter.accept(node))
                ret.add(node);
            if (recursive) {
                children = node.getChildren();
                if (null != children)
                    ret.add(children.extractAllNodesThatMatch(filter, recursive));
            }
        }
        return (ret);
    }

    /**
     * Remove nodes not matching the given filter non-recursively.
     * @param filter The filter to use.
     */
    public void keepAllNodesThatMatch(NodeFilter filter) {
        keepAllNodesThatMatch(filter, false);
    }

    /**
     * Remove nodes not matching the given filter.
     * @param filter The filter to use.
     * @param recursive If <code>true<code> digs into the children recursively.
     */
    public void keepAllNodesThatMatch(NodeFilter filter, boolean recursive) {
        Node node;
        NodeList children;
        for (int i = 0; i < size; ) {
            node = nodeData[i];
            if (!filter.accept(node))
                remove(i);
            else {
                if (recursive) {
                    children = node.getChildren();
                    if (null != children)
                        children.keepAllNodesThatMatch(filter, recursive);
                }
                i++;
            }
        }
    }

    /**
     * Convenience method to search for nodes of the given type non-recursively.
     * @param clreplacedType The clreplaced to search for.
     */
    public NodeList searchFor(Clreplaced clreplacedType) {
        return (searchFor(clreplacedType, false));
    }

    /**
     * Convenience method to search for nodes of the given type.
     * @param clreplacedType The clreplaced to search for.
     * @param recursive If <code>true<code> digs into the children recursively.
     */
    public NodeList searchFor(Clreplaced clreplacedType, boolean recursive) {
        return (extractAllNodesThatMatch(new NodeClreplacedFilter(clreplacedType), recursive));
    }

    /**
     * Utility to apply a visitor to a node list.
     * Provides for a visitor to modify the contents of a page and get the
     * modified HTML as a string with code like this:
     * <pre>
     * Parser parser = new Parser ("http://whatever");
     * NodeList list = parser.parse (null); // no filter
     * list.visitAllNodesWith (visitor);
     * System.out.println (list.toHtml ());
     * </pre>
     */
    public void visitAllNodesWith(NodeVisitor visitor) throws ParserException {
        Node node;
        visitor.beginParsing();
        for (int i = 0; i < size; i++) nodeData[i].accept(visitor);
        visitor.finishedParsing();
    }
}

19 View Complete Implementation : NotFilter.java
Copyright Apache License 2.0
Author : bbossgroups
// 
// NodeFilter interface
// 
/**
 * Accept nodes that are not acceptable to the predicate filter.
 * @param node The node to check.
 * @return <code>true</code> if the node is not acceptable to the
 * predicate filter, <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    return ((null != mPredicate) && !mPredicate.accept(node));
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
public void add(Node node) {
    if (size == capacity)
        adjustVectorCapacity();
    nodeData[size++] = node;
}

19 View Complete Implementation : IsEqualFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept the node.
 * @param node The node to check.
 * @return <code>false</code> unless <code>node</code> is the one and only.
 */
public boolean accept(Node node) {
    return (mNode == node);
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
public Node remove(int index) {
    Node ret;
    ret = nodeData[index];
    System.arraycopy(nodeData, index + 1, nodeData, index, size - index - 1);
    nodeData[size - 1] = null;
    size--;
    return (ret);
}

19 View Complete Implementation : AbstractNodeDecorator.java
Copyright Apache License 2.0
Author : bbossgroups
public void setParent(Node node) {
    delegate.setParent(node);
}

19 View Complete Implementation : JasmineTestInterpreter.java
Copyright MIT License
Author : solita
private NodeList findChildren(NodeList nodes, Clreplaced<? extends Tag> tagClreplaced) {
    SimpleNodeIterator iter = nodes.elements();
    while (iter.hasMoreNodes()) {
        Node n = iter.nextNode();
        if (n.getClreplaced().equals(tagClreplaced)) {
            return n.getChildren();
        }
    }
    throw new IllegalArgumentException(String.format("No tag %s found", tagClreplaced));
}

19 View Complete Implementation : NodeUtils.java
Copyright Apache License 2.0
Author : iipc
public static boolean isRemarkNode(Node node) {
    return (node instanceof RemarkNode);
}

19 View Complete Implementation : HasParentFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept tags with parent acceptable to the filter.
 * If recursion is enabled, each parent in turn up to
 * the topmost enclosing node is checked.
 * Recursion only proceeds while no parent satisfies the
 * filter.
 * @param node The node to check.
 * @return <code>true</code> if the node has an acceptable parent,
 * <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    Node parent;
    boolean ret;
    ret = false;
    if (!(node instanceof Tag) || !((Tag) node).isEndTag()) {
        parent = node.getParent();
        if ((null != parent) && (null != getParentFilter())) {
            ret = getParentFilter().accept(parent);
            if (!ret && getRecursive())
                ret = accept(parent);
        }
    }
    return (ret);
}

19 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Return a string representation of the contents of this tag, it's children and it's end tag suitable for debugging.
 * @param level The indentation level to use.
 * @param buffer The buffer to append to.
 */
public void toString(int level, StringBuilder buffer) {
    Node node;
    for (int i = 0; i < level; i++) buffer.append("  ");
    buffer.append(super.toString());
    buffer.append(System.getProperty("line.separator"));
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        if (node instanceof CompositeTag)
            ((CompositeTag) node).toString(level + 1, buffer);
        else {
            for (int i = 0; i <= level; i++) buffer.append("  ");
            buffer.append(node);
            buffer.append(System.getProperty("line.separator"));
        }
    }
    if (// 2nd guard handles <tag/>
    (null != getEndTag()) && (this != getEndTag())) // eliminate virtual tags
    // if (!(getEndTag ().getStartPosition () == getEndTag ().getEndPosition ()))
    {
        for (int i = 0; i <= level; i++) buffer.append("  ");
        buffer.append(getEndTag().toString());
        buffer.append(System.getProperty("line.separator"));
    }
}

19 View Complete Implementation : AndFilter.java
Copyright Apache License 2.0
Author : bbossgroups
// 
// NodeFilter interface
// 
/**
 * Accept nodes that are acceptable to all of it's predicate filters.
 * @param node The node to check.
 * @return <code>true</code> if all the predicate filters find the node
 * is acceptable, <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    boolean ret;
    ret = true;
    for (int i = 0; ret && (i < mPredicates.length); i++) if (!mPredicates[i].accept(node))
        ret = false;
    return (ret);
}

19 View Complete Implementation : LinkTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Return the contents of this link node as a string suitable for debugging.
 * @return A string representation of this node.
 */
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Link to : " + getLink() + "; replacedled : " + getLinkText() + "; begins at : " + getStartPosition() + "; ends at : " + getEndPosition() + ", AccessKey=");
    if (getAccessKey() == null)
        sb.append("null\n");
    else
        sb.append(getAccessKey() + "\n");
    if (null != getChildren()) {
        sb.append("  " + "LinkData\n");
        sb.append("  " + "--------\n");
        Node node;
        int i = 0;
        for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
            node = e.nextNode();
            sb.append("   " + (i++) + " ");
            sb.append(node.toString() + "\n");
        }
    }
    sb.append("  " + "*** END of LinkData ***\n");
    return sb.toString();
}

19 View Complete Implementation : OrFilter.java
Copyright Apache License 2.0
Author : bbossgroups
// 
// NodeFilter interface
// 
/**
 * Accept nodes that are acceptable to any of it's predicate filters.
 * @param node The node to check.
 * @return <code>true</code> if any of the predicate filters find the node
 * is acceptable, <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    boolean ret;
    ret = false;
    for (int i = 0; !ret && (i < mPredicates.length); i++) if (mPredicates[i].accept(node))
        ret = true;
    return (ret);
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
public Node[] toNodeArray() {
    Node[] nodeArray = newNodeArrayFor(size);
    System.arraycopy(nodeData, 0, nodeArray, 0, size);
    return nodeArray;
}

19 View Complete Implementation : IsEqualFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * This clreplaced accepts only one specific node.
 */
public clreplaced IsEqualFilter implements NodeFilter {

    /**
     * The node to match.
     */
    protected Node mNode;

    /**
     * Creates a new IsEqualFilter that accepts only the node provided.
     * @param node The node to match.
     */
    public IsEqualFilter(Node node) {
        mNode = node;
    }

    /**
     * Accept the node.
     * @param node The node to check.
     * @return <code>false</code> unless <code>node</code> is the one and only.
     */
    public boolean accept(Node node) {
        return (mNode == node);
    }
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
public void copyToNodeArray(Node[] array) {
    System.arraycopy(nodeData, 0, array, 0, size);
}

19 View Complete Implementation : TagNameFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept nodes that are tags and have a matching tag name.
 * This discards non-tag nodes and end tags.
 * The end tags are available on the enclosing non-end tag.
 * @param node The node to check.
 * @return <code>true</code> if the tag name matches,
 * <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    return ((node instanceof Tag) && !((Tag) node).isEndTag() && ((Tag) node).getTagName().equals(mName));
}

19 View Complete Implementation : NodeList.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Insert the given node at the head of the list.
 * @param node The new first element.
 */
public void prepend(Node node) {
    if (size == capacity)
        adjustVectorCapacity();
    System.arraycopy(nodeData, 0, nodeData, 1, size);
    size++;
    nodeData[0] = node;
}

19 View Complete Implementation : HTMLForm.java
Copyright GNU General Public License v3.0
Author : aalhuz
public void setForm(Node form) {
    this.form = form;
}

19 View Complete Implementation : GridUtils.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : dhis2
/**
 * Returns the number of columns/cells in the given row, including cell spacing.
 */
private static int getColumnCount(TableRow row) {
    Node[] cells = row.getChildren().extractAllNodesThatMatch(HTML_ROW_FILTER).toNodeArray();
    int cols = 0;
    for (Node cell : cells) {
        Integer colSpan = MathUtils.parseInt(((TagNode) cell).getAttribute("colspan"));
        cols += colSpan != null ? colSpan : 1;
    }
    return cols;
}

19 View Complete Implementation : AbstractNode.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Sets the parent of this node.
 * @param node The node that contains this node. Must be a <code>CompositeTag</code>.
 */
public void setParent(Node node) {
    parent = node;
}

19 View Complete Implementation : CDATALexer.java
Copyright Apache License 2.0
Author : iipc
public clreplaced CDATALexer extends Lexer {

    private static final long serialVersionUID = -8513653556979405106L;

    private Node cached;

    private boolean inCSS;

    private boolean inJS;

    private boolean cachedJS = false;

    @Override
    public Node nextNode() throws ParserException {
        inJS = false;
        inCSS = false;
        if (cached != null) {
            Node tmp = cached;
            cached = null;
            inJS = cachedJS;
            inCSS = !cachedJS;
            return tmp;
        }
        Node got = super.nextNode();
        if (NodeUtils.isNonEmptyOpenTagNodeNamed(got, "SCRIPT")) {
            cached = super.parseCDATA(true);
            cachedJS = true;
        } else if (NodeUtils.isNonEmptyOpenTagNodeNamed(got, "STYLE")) {
            cached = super.parseCDATA(true);
            cachedJS = false;
        }
        return got;
    }

    public boolean inJS() {
        return inJS;
    }

    public boolean inCSS() {
        return inCSS;
    }
}

19 View Complete Implementation : NodeUtils.java
Copyright Apache License 2.0
Author : iipc
public static boolean isTagNode(Node node) {
    return (node instanceof TagNode);
}

19 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Add the textual contents of the children of this node to the buffer.
 * @param sb The buffer to append to.
 */
protected void putChildrenInto(StringBuilder sb) {
    Node node;
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        // eliminate virtual tags
        // if (!(node.getStartPosition () == node.getEndPosition ()))
        sb.append(node.toHtml());
    }
}

19 View Complete Implementation : NodeClassFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept nodes that are replacedignable from the clreplaced provided in
 * the constructor.
 * @param node The node to check.
 * @return <code>true</code> if the node is the right clreplaced,
 * <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    return ((null != mClreplaced) && mClreplaced.isreplacedignableFrom(node.getClreplaced()));
}

19 View Complete Implementation : CssSelectorNodeFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept nodes that match the selector expression.
 * @param node The node to check.
 * @return <code>true</code> if the node matches,
 * <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    return (therule.accept(node));
}

19 View Complete Implementation : LinkStringFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept nodes that are a LinkTag and
 * have a URL that matches the pattern supplied in the constructor.
 * @param node The node to check.
 * @return <code>true</code> if the node is a link with the pattern.
 */
public boolean accept(Node node) {
    boolean ret;
    ret = false;
    if (LinkTag.clreplaced.isreplacedignableFrom(node.getClreplaced())) {
        String link = ((LinkTag) node).getLink();
        if (mCaseSensitive) {
            if (link.indexOf(mPattern) > -1)
                ret = true;
        } else {
            if (link.toUpperCase().indexOf(mPattern.toUpperCase()) > -1)
                ret = true;
        }
    }
    return (ret);
}

19 View Complete Implementation : AndFilterWrapper.java
Copyright Apache License 2.0
Author : bbossgroups
// 
// NodeFilter interface
// 
/**
 * Predicate to determine whether or not to keep the given node.
 * The behaviour based on this outcome is determined by the context
 * in which it is called. It may lead to the node being added to a list
 * or printed out. See the calling routine for details.
 * @return <code>true</code> if the node is to be kept, <code>false</code>
 * if it is to be discarded.
 * @param node The node to test.
 */
public boolean accept(Node node) {
    return (mFilter.accept(node));
}

19 View Complete Implementation : NodeUtils.java
Copyright Apache License 2.0
Author : iipc
public static boolean isTextNode(Node node) {
    return (node instanceof TextNode);
}

18 View Complete Implementation : HTMLForm.java
Copyright GNU General Public License v3.0
Author : aalhuz
/*
 * @author: Abeer Alhuzali and NoTamper.
 * For more information, please read "NAVEX: Precise and Scalable Exploit Generation for Dynamic Web Applications"
 *
 */
public clreplaced HTMLForm {

    private Node form;

    public int formId;

    public String formName;

    public String fileName;

    // where we extracted the form from
    private String url;

    /*
	 * from notamper
	 */
    // doreplacedent object (DOM) representation of the form
    public String domRepresentation;

    // window object's (top level browser window) representation of the page
    public String windowRepresentation;

    // define helper functions to enable symbolic execution e.g., alert
    private String helperFuns;

    // form specific JavaScript to validate input controls
    public String jsValidation;

    // JavaScript common to all forms, executed when page is loaded
    // this may initialize execution environment for the form validation script
    public String commonJS;

    // set this to true for using new Formula extractor and JS engine
    // with older (NoTamper) version of solver.
    public static boolean NEW_FE_JS_OLDER_SOLVER = true;

    private HashSet<Formula> z3FormFormulas;

    public Node getForm() {
        return form;
    }

    public void setForm(Node form) {
        this.form = form;
    }

    public int getFormId() {
        return formId;
    }

    public void setFormId(int formId) {
        this.formId = formId;
    }

    public String getFormName() {
        return formName;
    }

    public void setFormName(String formName) {
        this.formName = formName;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public HashSet<Formula> getZ3FormFormulas() {
        return z3FormFormulas;
    }

    public void setZ3FormFormulas(HashSet<Formula> z3FormFormulas) {
        this.z3FormFormulas = z3FormFormulas;
    }

    private static int formCounter = 1;

    public HTMLForm(Node form, String url, String commonJS) {
        this.form = form;
        this.formName = ((FormTag) form).getFormName();
        if (this.formName == null)
            this.formName = "form_" + Integer.toString(formCounter);
        this.url = url;
        this.z3FormFormulas = new HashSet<Formula>();
        this.commonJS = commonJS;
        this.jsValidation = new String("");
        this.domRepresentation = new String();
        this.windowRepresentation = new String();
        this.helperFuns = new String();
    }

    @Override
    public String toString() {
        return "HTMLForm [form=" + ((FormTag) this.form).extractFormLocn() + ", formId=" + formId + ", formName=" + formName + ", url=" + url + ", z3formulas=" + this.getZ3FormFormulas() + "]";
    }

    /*
	 * output HTML constraints in Z3 solver formate
	 * returns any extra copy of the form if there is more than one submit bottons.
	 */
    public HashSet<HTMLForm> processInputsForZ3() throws IOException, MimeTypeParseException {
        Hashtable<String, ArrayList<String>> domains = new Hashtable<String, ArrayList<String>>();
        Hashtable<String, ArrayList<String>> domainsDropDown = new Hashtable<String, ArrayList<String>>();
        Hashtable<String, Integer> arrayCounters = new Hashtable<String, Integer>();
        ArrayList<String> keys = new ArrayList<String>();
        FormTag form2 = (FormTag) form;
        String formName = this.formName;
        domRepresentation = ("// DOM Simulation\n");
        domRepresentation += ("function DOM()\n{\n");
        domRepresentation += ("\tvar " + formName + " = new Object();\n\n");
        String[] tags = { "input", "select", "textarea" };
        TagFindingVisitor tfv = new TagFindingVisitor(tags);
        form.accept(tfv);
        Node[] inputs = tfv.getTags(0);
        Node[] selects = tfv.getTags(1);
        Node[] textareas = tfv.getTags(2);
        System.out.println("form inputs name size  :" + inputs.length);
        HashMap<Node, Formula> submits = new HashMap<Node, Formula>();
        for (Node n : inputs) {
            InputTag input = (InputTag) n;
            String id = input.getAttribute("id");
            String name = input.getAttribute("name");
            String type = input.getAttribute("type");
            String disabled = input.getAttribute("disabled");
            if (name != null && name.contains("[]")) {
                String namePref = name.replace("[]", "");
                Integer counter = arrayCounters.get(namePref);
                if (counter == null)
                    counter = new Integer(0);
                else
                    counter = new Integer(counter.intValue() + 1);
                name = namePref + "[" + counter.intValue() + "]";
                arrayCounters.put(namePref, counter);
            }
            if (id != null && type != null && !type.equalsIgnoreCase("radio") && !type.equalsIgnoreCase("checkbox") && !type.equalsIgnoreCase("select") && !type.equalsIgnoreCase("file")) {
                domRepresentation += ("\t" + id + " = new Object();\n");
                if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                    domRepresentation += ("\t" + id + ".value = '?" + name + "_notamper_symbolic';\n");
                } else {
                    domRepresentation += ("\t" + id + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                }
                domRepresentation += ("\t" + formName + "." + id + " = " + id + ";\n\n");
            }
            if (disabled != null && disabled.equalsIgnoreCase("disabled"))
                continue;
            if (type == null) {
                String maxLen = input.getAttribute("maxlength");
                String size = input.getAttribute("size");
                String value = input.getAttribute("value");
                ArrayList<String> nameList = new ArrayList<String>();
                nameList.add(name);
                if (maxLen != null && !maxLen.isEmpty()) {
                    Formula f = new Formula(nameList, maxLen, "maxlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                } else if (size != null && !size.isEmpty()) {
                    Formula f = new Formula(nameList, size, "maxlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                } else {
                    Formula f = new Formula(nameList, "0", "minlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                }
                if (value != null && !value.isEmpty()) {
                    Formula f = new Formula(nameList, "\"" + value + "\"", "=", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                }
            } else if (type.equalsIgnoreCase("reset") || type.equalsIgnoreCase("button"))
                continue;
            else if (type.equalsIgnoreCase("submit")) {
                if (name == null)
                    continue;
                String value = input.getAttribute("value");
                ArrayList<String> nameList = new ArrayList<String>();
                nameList.add(name);
                Formula f = new Formula(nameList, "\"" + value + "\"", "=", "form-" + type, "FORM");
                submits.put(n, f);
                continue;
            } else if (type.equalsIgnoreCase("hidden")) {
                String value = input.getAttribute("value");
                // TODO: check infer type of value
                // TODO: for now I will consider this as string always.
                String sType = InferType.inferType(value);
                value = (value == null || value.isEmpty()) ? "\"\"" : "\"" + value + "\"";
                ArrayList<String> nameList = new ArrayList<String>();
                nameList.add(name);
                Formula f = new Formula(nameList, value, "=", "form-" + type, "FORM");
                this.z3FormFormulas.add(f);
            } else if (type.equalsIgnoreCase("text") || type.equalsIgnoreCase("preplacedword")) {
                String maxLen = input.getAttribute("maxlength");
                String size = input.getAttribute("size");
                String value = input.getAttribute("value");
                ArrayList<String> nameList = new ArrayList<String>();
                nameList.add(name);
                if (maxLen != null && !maxLen.isEmpty()) {
                    Formula f = new Formula(nameList, maxLen, "maxlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                } else if (size != null && !size.isEmpty()) {
                    Formula f = new Formula(nameList, size, "maxlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                } else {
                    Formula f = new Formula(nameList, "0", "minlen", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                }
                if (value != null && !value.isEmpty()) {
                    Formula f = new Formula(nameList, "\"" + value + "\"", "=", "form-" + type, "FORM");
                    this.z3FormFormulas.add(f);
                }
                domRepresentation += ("\tvar " + name + " = new Object();\n");
                if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                    domRepresentation += ("\t" + name + ".value = '?" + name + "_notamper_symbolic';\n");
                } else {
                    domRepresentation += ("\t" + name + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                }
                domRepresentation += ("\t" + formName + "." + name + " = " + name + ";\n\n");
            } else if (type.equalsIgnoreCase("file")) {
            } else if (type.equalsIgnoreCase("radio") || type.equalsIgnoreCase("checkbox")) {
                String value = input.getAttribute("value");
                if (value != null && name != null) {
                    ArrayList<String> domain = domains.get(name);
                    if (domain == null) {
                        domain = new ArrayList<String>();
                        keys.add(name);
                    }
                    domain.add(value);
                    domains.put(name, domain);
                }
                if (id != null) {
                    domRepresentation += ("\tvar " + id + " = new Object();\n");
                    if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                        domRepresentation += ("\t" + id + ".checked = '?" + name + "_notamper_symbolic';\n");
                        domRepresentation += ("\t" + id + ".value = '?" + name + "_notamper_symbolic';\n");
                    } else {
                        domRepresentation += ("\t" + id + ".checked = '(post \"" + name + "_notamper_symbolic\")';\n");
                        domRepresentation += ("\t" + id + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                    }
                    domRepresentation += ("\t" + formName + "." + id + " = " + id + ";\n\n");
                } else if (name != null) {
                    String s = "\tvar " + name + " = new Object();\n";
                    if (domRepresentation.indexOf(s) < 0) {
                        domRepresentation += s;
                        if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                            domRepresentation += ("\t" + name + ".checked = '?" + name + "_notamper_symbolic';\n");
                            // ("\t" + name + ".checked = '\"= (post \"" + name + "_notamper_symbolic\") \"" +
                            // (value == null ? "on" : value) + "\"';\n");
                            domRepresentation += ("\t" + name + ".value = '?" + name + "_notamper_symbolic';\n");
                        // ("\t" + name + ".value = '\"= (post \"" + name + "_notamper_symbolic\") \"" +
                        // (value == null ? "on" : value) + "\"';\n");
                        } else {
                            domRepresentation += ("\t" + name + ".checked = '(post \"" + name + "_notamper_symbolic\")';\n");
                            domRepresentation += ("\t" + name + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                        }
                        domRepresentation += ("\t" + formName + "." + name + " = " + name + ";\n\n");
                    }
                }
            }
        }
        // end for
        if (!domains.isEmpty()) {
            for (Entry<String, ArrayList<String>> map : domains.entrySet()) {
                // the formula her is reversed. It should be (key, list<value>, or).
                Formula f = new Formula(map.getValue(), map.getKey(), "or", "form-radio-checkbox", "FORM");
                this.z3FormFormulas.add(f);
            }
        }
        String[] optionTag = { "option" };
        for (Node n : selects) {
            SelectTag select = (SelectTag) n;
            OptionTag option;
            String name = select.getAttribute("name");
            String id = select.getAttribute("id");
            if (name == null)
                continue;
            ArrayList<String> domain = new ArrayList<String>();
            tfv = new TagFindingVisitor(optionTag);
            n.accept(tfv);
            Node[] options = tfv.getTags(0);
            domRepresentation += ("\tvar options = new Array();\n");
            int i = 0;
            for (Node m : options) {
                option = (OptionTag) m;
                String value = option.getAttribute("value");
                domain.add(value);
                String selected = option.getAttribute("selected");
                if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                    domRepresentation += ("\toptions[" + i + "].selected = '= ?" + name + "_notamper_symbolic \\'" + value + "\\'';\n");
                } else {
                    domRepresentation += ("\toptions[" + i + "].selected = '= (post \"" + name + "_notamper_symbolic\") \\'" + value + "\\'';\n");
                }
                i++;
            }
            // TODO: check fix#3 -- if id is null use the name in JS
            if (id == null) {
                id = name;
                domRepresentation += ("\tvar " + id + " = new Object();\n");
                domRepresentation += ("\t" + id + ".options = options;\n");
                domRepresentation += ("\t" + formName + "." + id + " = " + id + ";\n\n");
            }
            domainsDropDown.put(name, domain);
        }
        if (!domainsDropDown.isEmpty()) {
            for (Entry<String, ArrayList<String>> map : domainsDropDown.entrySet()) {
                // the formula her is reversed . it should be (key, list<value>, or).
                Formula f = new Formula(map.getValue(), map.getKey(), "or", "form-selects", "FORM");
                this.z3FormFormulas.add(f);
            }
        }
        for (Node t : textareas) {
            TextareaTag tat = (TextareaTag) t;
            String id = tat.getAttribute("id");
            String name = tat.getAttribute("name");
            String rows = tat.getAttribute("rows");
            String max = tat.getAttribute("maxlength");
            ArrayList<String> nameList = new ArrayList<String>();
            nameList.add(name);
            Formula f;
            if (max != null && !max.isEmpty()) {
                f = new Formula(nameList, max, "maxlen", "form-textarea", "FORM");
                this.z3FormFormulas.add(f);
            } else {
                f = new Formula(nameList, "0", "minlen", "form-stextarea", "FORM");
                this.z3FormFormulas.add(f);
            }
            if (name != null) {
                domRepresentation += ("\tvar " + name + " = new Object();\n");
                if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                    domRepresentation += ("\t" + name + ".value = '?" + name + "_notamper_symbolic';\n");
                } else {
                    domRepresentation += ("\t" + name + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                }
                domRepresentation += ("\t" + formName + "." + name + " = " + name + ";\n\n");
            }
            if (id != null) {
                domRepresentation += ("\t" + id + " = new Object();\n");
                if (HTMLForm.NEW_FE_JS_OLDER_SOLVER == true) {
                    domRepresentation += ("\t" + id + ".value = '?" + name + "_notamper_symbolic';\n");
                } else {
                    domRepresentation += ("\t" + id + ".value = '(post \"" + name + "_notamper_symbolic\")';\n");
                }
                domRepresentation += ("\t" + formName + "." + id + " = " + id + ";\n\n");
            }
        }
        domRepresentation += ("\tvar forms = new Array();\n");
        domRepresentation += ("\tforms[0] = " + formName + ";\n\n");
        domRepresentation += ("\tvar doc = new Object();\n");
        domRepresentation += ("\tdoc.forms = forms;\n");
        domRepresentation += ("\tdoc.") + formName + " = " + formName + ";\n";
        domRepresentation += ("\tdoc.getElementsByTagName = NT_gebtn;\n\n");
        domRepresentation += ("\tdoc.write = NT_w;\n\n");
        domRepresentation += ("\tdoc.frames = new Array();\n");
        domRepresentation += ("\tdoc.images = new Array();\n");
        domRepresentation += ("\tdoc.links = new Array();\n");
        domRepresentation += ("\tdoc.plugins = new Array();\n\n");
        domRepresentation += ("\tdoc.cookie = \"\";\n");
        domRepresentation += ("\treturn doc;\n}\n\n");
        domRepresentation += ("function NT_gebtn(elementName){\n");
        domRepresentation += ("    if(elementName == \"form\")\n");
        domRepresentation += ("        return this.forms; \n");
        domRepresentation += ("    else if(elementName == \"frame\")\n");
        domRepresentation += ("        return this.frames;\n");
        domRepresentation += ("    else if(elementName == \"images\")\n");
        domRepresentation += ("        return this.images; \n");
        domRepresentation += ("    else if(elementName == \"link\")\n");
        domRepresentation += ("        return this.links;\n");
        domRepresentation += ("    else if(elementName == \"plugin\")\n");
        domRepresentation += ("        return this.plugins;\n");
        domRepresentation += ("    else\n");
        domRepresentation += ("        return this;\n");
        domRepresentation += ("}\n");
        domRepresentation += ("\n");
        domRepresentation += ("function NT_w(msg){}\n");
        domRepresentation += ("\n");
        domRepresentation += ("\n\nvar doreplacedent = new DOM();\n\n");
        // create a window object
        windowRepresentation += "function WINDOW(){\n";
        windowRepresentation += "   \n";
        windowRepresentation += "   this.setTimeout = wsto;\n";
        windowRepresentation += "   this.addEventListener = wael;\n";
        windowRepresentation += "   this.attachEvent = wae;\n";
        windowRepresentation += "   this.onload = wol;\n";
        windowRepresentation += "   this.onunload = woul;\n";
        windowRepresentation += "   this.location = new Object();\n";
        windowRepresentation += "   this.location.pathname = \"\";\n";
        windowRepresentation += "}\n";
        windowRepresentation += "\n";
        windowRepresentation += "function wsto(fnToCall, time){\n";
        windowRepresentation += "   // do nothing.\n";
        windowRepresentation += "}\n";
        windowRepresentation += "function wael(eventName, eventHandler, bool){}\n";
        windowRepresentation += "function wae(eventName, eventHandler){}\n";
        windowRepresentation += "function wol(){}\n";
        windowRepresentation += "function woul(){}\n";
        windowRepresentation += "\n";
        windowRepresentation += "var window = new WINDOW();\n\n";
        domRepresentation += "function NAVIGATOR(){\n";
        domRepresentation += "    this.userAgent = 'mozilla';\n";
        domRepresentation += "    this.appVersion = '3.0';\n";
        domRepresentation += "}\n\n";
        domRepresentation += "var navigator = new NAVIGATOR();\n";
        domRepresentation += "var location = new Object(); \n" + "location.href = \"\"; \n ";
        // finally we replacedyze the submit buttons
        if (submits.size() > 1) {
            HashSet<HTMLForm> ret = new HashSet<HTMLForm>();
            HashSet<Formula> tempFormulas = new HashSet<Formula>();
            tempFormulas.addAll(this.z3FormFormulas);
            int i = 0;
            for (Entry<Node, Formula> map : submits.entrySet()) {
                if (i == 0)
                    this.z3FormFormulas.add(map.getValue());
                else {
                    HTMLForm hf = new HTMLForm(form, url, this.commonJS);
                    hf.z3FormFormulas.add(map.getValue());
                    hf.z3FormFormulas.addAll(tempFormulas);
                    ret.add(hf);
                }
                i++;
            }
            return ret;
        } else if (submits.size() == 1) {
            this.z3FormFormulas.add(submits.values().iterator().next());
            return null;
        } else
            return null;
    }

    public void simulateJSValidation() {
        FormTag form2 = (FormTag) form;
        String formName = form2.getFormName() == null ? "form1" : form2.getFormName();
        String onSubmit = form2.getAttribute("onSubmit");
        jsValidation = "";
        if (onSubmit != null && onSubmit != "") {
            onSubmit = onSubmit.replaceAll("&", "&");
            onSubmit = onSubmit.replaceAll(""", "\"");
            onSubmit = onSubmit.replaceAll("<", "<");
            onSubmit = onSubmit.replaceAll(">", ">");
            onSubmit = onSubmit.replaceAll("this\\.", "formThis\\.");
            onSubmit = onSubmit.replaceAll(" this ", " formThis ");
            onSubmit = onSubmit.replaceAll("(this)", " formThis");
            // now simulate this reference by initializing the formThis var;
            onSubmit = " var formThis = doreplacedent.forms[0]; \n " + onSubmit;
            jsValidation += ("\n// Event Simulation\n");
            jsValidation += ("function onSubmit_" + formName + "()\n{\n");
            jsValidation += ("\t" + onSubmit + ";\n}\n\n");
            jsValidation += ("onSubmit_" + formName + "();\n\n");
        }
        if (jsValidation == null || jsValidation.equals("") || jsValidation.trim() == "") {
            jsValidation = " DO_NOT_PROCESS_NOTAMPER";
        } else {
            jsValidation = ("notamper_execution_begins = true;\n\n") + jsValidation;
            jsValidation += ("notamper_execution_ends = true;\n\n");
        }
    }

    public String getHelperFuncs() {
        this.helperFuns += "function alert(msg){}\n";
        this.helperFuns += "function confirm(msg){}\n";
        this.helperFuns += "function prompt(msg){}\n";
        this.helperFuns += "function unescape(s){}\n";
        return this.helperFuns;
    }
}

18 View Complete Implementation : RegexFilter.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Accept string nodes that match the regular expression.
 * @param node The node to check.
 * @return <code>true</code> if the regular expression matches the
 * text of the node, <code>false</code> otherwise.
 */
public boolean accept(Node node) {
    String string;
    Matcher matcher;
    boolean ret;
    ret = false;
    if (node instanceof Text) {
        string = ((Text) node).getText();
        matcher = mPattern.matcher(string);
        switch(mStrategy) {
            case MATCH:
                ret = matcher.matches();
                break;
            case LOOKINGAT:
                ret = matcher.lookingAt();
                break;
            case FIND:
            default:
                ret = matcher.find();
                break;
        }
    }
    return (ret);
}

18 View Complete Implementation : AbstractNode.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * The concrete base clreplaced for all types of nodes (tags, text remarks).
 * This clreplaced provides basic functionality to hold the {@link Page}, the
 * starting and ending position in the page, the parent and the list of
 * {@link NodeList children}.
 */
public abstract clreplaced AbstractNode implements Node, Serializable {

    protected boolean isresource = false;

    /**
     * The page this node came from.
     */
    protected Page mPage;

    /**
     * The beginning position of the tag in the line
     */
    protected int nodeBegin;

    /**
     * The ending position of the tag in the line
     */
    protected int nodeEnd;

    /**
     * The parent of this node.
     */
    protected Node parent;

    /**
     * The children of this node.
     */
    protected NodeList children;

    /**
     * Create an abstract node with the page positions given.
     * Remember the page and start & end cursor positions.
     * @param page The page this tag was read from.
     * @param start The starting offset of this node within the page.
     * @param end The ending offset of this node within the page.
     */
    public AbstractNode(Page page, int start, int end) {
        mPage = page;
        nodeBegin = start;
        nodeEnd = end;
        parent = null;
        children = null;
    }

    /**
     * Clone this object.
     * Exposes java.lang.Object clone as a public method.
     * @return A clone of this object.
     * @exception CloneNotSupportedException This shouldn't be thrown since
     * the {@link Node} interface extends Cloneable.
     */
    public Object clone() throws CloneNotSupportedException {
        return (super.clone());
    }

    /**
     * Returns a string representation of the node.
     * It allows a simple string transformation
     * of a web page, regardless of node type.<br>
     * Typical application code (for extracting only the text from a web page)
     * would then be simplified to:<br>
     * <pre>
     * Node node;
     * for (Enumeration e = parser.elements (); e.hasMoreElements (); )
     * {
     *     node = (Node)e.nextElement();
     *     System.out.println (node.toPlainTextString ());
     *     // or do whatever processing you wish with the plain text string
     * }
     * </pre>
     * @return The 'browser' content of this node.
     */
    public abstract String toPlainTextString();

    /**
     * Return the HTML that generated this node.
     * This method will make it easier when using html parser to reproduce html
     * pages (with or without modifications).
     * Applications reproducing html can use this method on nodes which are to
     * be used or transferred as they were recieved, with the original html.
     * @return The HTML code for this node.
     */
    public abstract String toHtml();

    /**
     * Return a string representation of the node.
     * Subclreplacedes must define this method, and this is typically to be used in the manner<br>
     * <pre>System.out.println(node)</pre>
     * @return A textual representation of the node suitable for debugging
     */
    public abstract String toString();

    /**
     * Collect this node and its child nodes (if-applicable) into the collectionList parameter, provided the node
     * satisfies the filtering criteria.<P>
     *
     * This mechanism allows powerful filtering code to be written very easily,
     * without bothering about collection of embedded tags separately.
     * e.g. when we try to get all the links on a page, it is not possible to
     * get it at the top-level, as many tags (like form tags), can contain
     * links embedded in them. We could get the links out by checking if the
     * current node is a {@link org.htmlparser.tags.CompositeTag}, and going through its children.
     * So this method provides a convenient way to do this.<P>
     *
     * Using collectInto(), programs get a lot shorter. Now, the code to
     * extract all links from a page would look like:
     * <pre>
     * NodeList collectionList = new NodeList();
     * NodeFilter filter = new TagNameFilter ("A");
     * for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
     *      e.nextNode().collectInto(collectionList, filter);
     * </pre>
     * Thus, collectionList will hold all the link nodes, irrespective of how
     * deep the links are embedded.<P>
     *
     * Another way to accomplish the same objective is:
     * <pre>
     * NodeList collectionList = new NodeList();
     * NodeFilter filter = new TagClreplacedFilter (LinkTag.clreplaced);
     * for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
     *      e.nextNode().collectInto(collectionList, filter);
     * </pre>
     * This is slightly less specific because the LinkTag clreplaced may be
     * registered for more than one node name, e.g. <LINK> tags too.
     * @param list The node list to collect acceptable nodes into.
     * @param filter The filter to determine which nodes are retained.
     */
    public void collectInto(NodeList list, NodeFilter filter) {
        if (filter.accept(this))
            list.add(this);
    }

    /**
     * Get the page this node came from.
     * @return The page that supplied this node.
     */
    public Page getPage() {
        return (mPage);
    }

    public boolean isResource() {
        return this.isresource;
    }

    public void setResource(boolean isresource) {
        this.isresource = isresource;
    }

    /**
     * Set the page this node came from.
     * @param page The page that supplied this node.
     */
    public void setPage(Page page) {
        mPage = page;
    }

    /**
     * Gets the starting position of the node.
     * @return The start position.
     */
    public int getStartPosition() {
        return (nodeBegin);
    }

    /**
     * Sets the starting position of the node.
     * @param position The new start position.
     */
    public void setStartPosition(int position) {
        nodeBegin = position;
    }

    /**
     * Gets the ending position of the node.
     * @return The end position.
     */
    public int getEndPosition() {
        return (nodeEnd);
    }

    /**
     * Sets the ending position of the node.
     * @param position The new end position.
     */
    public void setEndPosition(int position) {
        nodeEnd = position;
    }

    /**
     * Visit this node.
     * @param visitor The visitor that is visiting this node.
     */
    public abstract void accept(NodeVisitor visitor);

    /**
     * Get the parent of this node.
     * This will always return null when parsing without scanners,
     * i.e. if semantic parsing was not performed.
     * The object returned from this method can be safely cast to a <code>CompositeTag</code>.
     * @return The parent of this node, if it's been set, <code>null</code> otherwise.
     */
    public Node getParent() {
        return (parent);
    }

    /**
     * Sets the parent of this node.
     * @param node The node that contains this node. Must be a <code>CompositeTag</code>.
     */
    public void setParent(Node node) {
        parent = node;
    }

    /**
     * Get the children of this node.
     * @return The list of children contained by this node, if it's been set, <code>null</code> otherwise.
     */
    public NodeList getChildren() {
        return (children);
    }

    /**
     * Set the children of this node.
     * @param children The new list of children this node contains.
     */
    public void setChildren(NodeList children) {
        this.children = children;
    }

    /**
     * Returns the text of the node.
     * @return The text of this node. The default is <code>null</code>.
     */
    public String getText() {
        return null;
    }

    /**
     * Sets the string contents of the node.
     * @param text The new text for the node.
     */
    public void setText(String text) {
    }

    /**
     * Perform the meaning of this tag.
     * The default action is to do nothing.
     * @exception ParserException <em>Not used.</em> Provides for subclreplacedes
     * that may want to indicate an exceptional condition.
     */
    public void doSemanticAction() throws ParserException {
    }
}

18 View Complete Implementation : HtmlTreeCellRenderer.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Render the node for the tree cell.
 * @see TreeCellRenderer#getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean)
 * @param tree {@inheritDoc}
 * @param value {@inheritDoc}
 * @param selected {@inheritDoc}
 * @param expanded {@inheritDoc}
 * @param leaf {@inheritDoc}
 * @param row {@inheritDoc}
 * @param hasFocus {@inheritDoc}
 * @return {@inheritDoc}
 */
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    Node node;
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    node = (Node) value;
    if (node instanceof TagNode)
        setText(toHtml((TagNode) node));
    else if (node instanceof TextNode)
        setText(toText((TextNode) node));
    else
        setText(node.toHtml());
    return (this);
}

18 View Complete Implementation : HtmlTreeModel.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Returns the child of parent at index index in the parent's child array.
 * @param parent {@inheritDoc}
 * @param index {@inheritDoc}
 * @return {@inheritDoc}
 */
public Object getChild(Object parent, int index) {
    Node node;
    NodeList list;
    Object ret;
    node = (Node) parent;
    list = node.getChildren();
    if (null == list)
        throw new IllegalArgumentException("invalid parent for getChild()");
    else
        ret = list.elementAt(index);
    return (ret);
}

18 View Complete Implementation : HtmlTreeModel.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Returns the index of child in parent.
 * @param parent {@inheritDoc}
 * @param child {@inheritDoc}
 * @return {@inheritDoc}
 */
public int getIndexOfChild(Object parent, Object child) {
    Node node;
    NodeList list;
    int count;
    int ret;
    ret = -1;
    node = (Node) parent;
    list = node.getChildren();
    if (null != list) {
        count = list.size();
        for (int i = 0; i < count; i++) if (child == list.elementAt(i)) {
            ret = i;
            break;
        }
    } else
        throw new IllegalArgumentException("invalid parent for getIndexOfChild()");
    if (0 > ret)
        throw new IllegalArgumentException("child not found in getIndexOfChild()");
    return (ret);
}

18 View Complete Implementation : HtmlTreeModel.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Returns the number of children of parent.
 * @param parent {@inheritDoc}
 * @return {@inheritDoc}
 */
public int getChildCount(Object parent) {
    Node node;
    NodeList list;
    int ret;
    ret = 0;
    node = (Node) parent;
    list = node.getChildren();
    if (null != list)
        ret = list.size();
    return (ret);
}

18 View Complete Implementation : HtmlTreeModel.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Quick and dirty tree model for HTML nodes.
 */
public clreplaced HtmlTreeModel implements TreeModel {

    /**
     * The list of tree listeners.
     */
    protected List mTreeListeners;

    /**
     * The root {@link Node}.
     */
    protected Node mRoot;

    /**
     * Create an HTML tree view.
     * @param root The nodes at the root of the tree
     * (the nodes are wrapped in an Html node that is never seen
     * because it's the root, but this makes all downstream processing
     * super-simple because every tree node is then a {@link Node},
     * not sometimes a {@link NodeList} at the root).
     */
    public HtmlTreeModel(NodeList root) {
        mTreeListeners = new ArrayList();
        // for simplicity we encapsulate the nodelist in a Html tag
        mRoot = new Html();
        mRoot.setChildren(root);
    }

    // 
    // TreeModel interface
    // 
    /**
     * Adds a listener for the TreeModelEvent posted after the tree changes.
     * @param l {@inheritDoc}
     */
    public void addTreeModelListener(TreeModelListener l) {
        synchronized (mTreeListeners) {
            if (!mTreeListeners.contains(l))
                mTreeListeners.add(l);
        }
    }

    /**
     * Removes a listener previously added with addTreeModelListener().
     * @param l {@inheritDoc}
     */
    public void removeTreeModelListener(TreeModelListener l) {
        synchronized (mTreeListeners) {
            mTreeListeners.remove(l);
        }
    }

    /**
     * Returns the child of parent at index index in the parent's child array.
     * @param parent {@inheritDoc}
     * @param index {@inheritDoc}
     * @return {@inheritDoc}
     */
    public Object getChild(Object parent, int index) {
        Node node;
        NodeList list;
        Object ret;
        node = (Node) parent;
        list = node.getChildren();
        if (null == list)
            throw new IllegalArgumentException("invalid parent for getChild()");
        else
            ret = list.elementAt(index);
        return (ret);
    }

    /**
     * Returns the number of children of parent.
     * @param parent {@inheritDoc}
     * @return {@inheritDoc}
     */
    public int getChildCount(Object parent) {
        Node node;
        NodeList list;
        int ret;
        ret = 0;
        node = (Node) parent;
        list = node.getChildren();
        if (null != list)
            ret = list.size();
        return (ret);
    }

    /**
     * Returns the index of child in parent.
     * @param parent {@inheritDoc}
     * @param child {@inheritDoc}
     * @return {@inheritDoc}
     */
    public int getIndexOfChild(Object parent, Object child) {
        Node node;
        NodeList list;
        int count;
        int ret;
        ret = -1;
        node = (Node) parent;
        list = node.getChildren();
        if (null != list) {
            count = list.size();
            for (int i = 0; i < count; i++) if (child == list.elementAt(i)) {
                ret = i;
                break;
            }
        } else
            throw new IllegalArgumentException("invalid parent for getIndexOfChild()");
        if (0 > ret)
            throw new IllegalArgumentException("child not found in getIndexOfChild()");
        return (ret);
    }

    /**
     * Returns the root of the tree.
     * @return {@inheritDoc}
     */
    public Object getRoot() {
        return (mRoot);
    }

    /**
     * Returns true if node is a leaf.
     * @param node {@inheritDoc}
     * @return {@inheritDoc}
     */
    public boolean isLeaf(Object node) {
        NodeList list;
        boolean ret;
        list = ((Node) node).getChildren();
        if (null == list)
            ret = true;
        else
            ret = 0 == list.size();
        return (ret);
    }

    /**
     * Messaged when the user has altered the value for the item identified by path to newValue.
     * @param path {@inheritDoc}
     * @param newValue {@inheritDoc}
     */
    public void valueForPathChanged(TreePath path, Object newValue) {
        TreeModelEvent event;
        List v;
        event = new TreeModelEvent(this, path);
        synchronized (mTreeListeners) {
            v = (List) ((ArrayList) mTreeListeners).clone();
        }
        for (int i = 0; i < v.size(); i++) {
            TreeModelListener listener = (TreeModelListener) v.get(i);
            listener.treeStructureChanged(event);
        }
    }
}

18 View Complete Implementation : CompositeTagScanner.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Add a child to the given tag.
 * @param parent The parent tag.
 * @param child The child node.
 */
protected void addChild(Tag parent, Node child) {
    if (null == parent.getChildren())
        parent.setChildren(new NodeList());
    child.setParent(parent);
    parent.getChildren().add(child);
}

18 View Complete Implementation : AppletTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Output a string representing this applet tag.
 * @return A string showing the contents of the applet tag.
 */
public String toString() {
    HashMap parameters;
    Iterator params;
    String paramName;
    String paramValue;
    boolean found;
    Node node;
    StringBuilder ret;
    ret = new StringBuilder(500);
    ret.append("Applet Tag\n");
    ret.append("**********\n");
    ret.append("Clreplaced Name = ");
    ret.append(getAppletClreplaced());
    ret.append("\n");
    ret.append("Archive = ");
    ret.append(getArchive());
    ret.append("\n");
    ret.append("Codebase = ");
    ret.append(getCodeBase());
    ret.append("\n");
    parameters = getAppletParams();
    params = parameters.entrySet().iterator();
    if (null == params)
        ret.append("No Params found.\n");
    else
        for (int cnt = 0; params.hasNext(); cnt++) {
            Map.Entry entry = (Entry) params.next();
            paramName = (String) entry.getKey();
            paramValue = (String) entry.getValue();
            ret.append(cnt);
            ret.append(": Parameter name = ");
            ret.append(paramName);
            ret.append(", Parameter value = ");
            ret.append(paramValue);
            ret.append("\n");
        }
    found = false;
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        if (node instanceof Tag)
            if (((Tag) node).getTagName().equals("PARAM"))
                continue;
        if (!found)
            ret.append("Miscellaneous items :\n");
        else
            ret.append(" ");
        found = true;
        ret.append(node.toString());
    }
    if (found)
        ret.append("\n");
    ret.append("End of Applet Tag\n");
    ret.append("*****************\n");
    return (ret.toString());
}

18 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Searches all children who for a name attribute. Returns first match.
 * @param name Attribute to match in tag
 * @return Tag Tag matching the name attribute
 */
public Tag searchByName(String name) {
    Node node;
    Tag tag = null;
    boolean found = false;
    for (SimpleNodeIterator e = children(); e.hasMoreNodes() && !found; ) {
        node = e.nextNode();
        if (node instanceof Tag) {
            tag = (Tag) node;
            String nameAttribute = tag.getAttribute("NAME");
            if (nameAttribute != null && nameAttribute.equals(name))
                found = true;
        }
    }
    if (found)
        return tag;
    else
        return null;
}

18 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Finds a text node, however embedded it might be, and returns
 * it. The text node will retain links to its parents, so
 * further navigation is possible.
 * @param searchText The text to search for.
 * @return The list of text nodes (recursively) found.
 */
public Text[] digupStringNode(String searchText) {
    NodeList nodeList = searchFor(searchText);
    NodeList stringNodes = new NodeList();
    for (int i = 0; i < nodeList.size(); i++) {
        Node node = nodeList.elementAt(i);
        if (node instanceof Text) {
            stringNodes.add(node);
        } else {
            if (node instanceof CompositeTag) {
                CompositeTag ctag = (CompositeTag) node;
                Text[] nodes = ctag.digupStringNode(searchText);
                for (int j = 0; j < nodes.length; j++) stringNodes.add(nodes[j]);
            }
        }
    }
    Text[] stringNode = new Text[stringNodes.size()];
    for (int i = 0; i < stringNode.length; i++) {
        stringNode[i] = (Text) stringNodes.elementAt(i);
    }
    return stringNode;
}

18 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Tag visiting code.
 * Invokes <code>accept()</code> on the start tag and then
 * walks the child list invoking <code>accept()</code> on each
 * of the children, finishing up with an <code>accept()</code>
 * call on the end tag. If <code>shouldRecurseSelf()</code>
 * returns true it then asks the visitor to visit itself.
 * @param visitor The <code>NodeVisitor</code> object to be signalled
 * for each child and possibly this tag.
 */
public void accept(NodeVisitor visitor) {
    SimpleNodeIterator children;
    Node child;
    if (visitor.shouldRecurseSelf())
        visitor.visitTag(this);
    if (visitor.shouldRecurseChildren()) {
        if (null != getChildren()) {
            children = children();
            while (children.hasMoreNodes()) {
                child = children.nextNode();
                child.accept(visitor);
            }
        }
        if (// 2nd guard handles <tag/>
        (null != getEndTag()) && (this != getEndTag()))
            getEndTag().accept(visitor);
    }
}

18 View Complete Implementation : CompositeTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Searches for all nodes whose text representation contains the search string.
 * Collects all nodes containing the search string into a NodeList.
 * For example, if you wish to find any textareas in a form tag containing
 * "hello world", the code would be:
 * <code>
 * NodeList nodeList = formTag.searchFor("Hello World");
 * </code>
 * @param searchString Search criterion.
 * @param caseSensitive If <code>true</code> this search should be case
 * sensitive. Otherwise, the search string and the node text are converted
 * to uppercase using the locale provided.
 * @param locale The locale for uppercase conversion.
 * @return A collection of nodes whose string contents or
 * representation have the <code>searchString</code> in them.
 */
public NodeList searchFor(String searchString, boolean caseSensitive, Locale locale) {
    Node node;
    String text;
    NodeList ret;
    ret = new NodeList();
    if (!caseSensitive)
        searchString = searchString.toUpperCase(locale);
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        text = node.toPlainTextString();
        if (!caseSensitive)
            text = text.toUpperCase(locale);
        if (-1 != text.indexOf(searchString))
            ret.add(node);
    }
    return (ret);
}

18 View Complete Implementation : FrameSetTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Gets a frame by name.
 * Names are checked without case sensitivity and conversion to uppercase
 * is performed with the locale provided.
 * @param name The name of the frame to retrieve.
 * @param locale The locale to use when converting to uppercase.
 * @return The specified frame or <code>null</code> if it wasn't found.
 */
public FrameTag getFrame(String name, Locale locale) {
    Node node;
    FrameTag ret;
    ret = null;
    name = name.toUpperCase(locale);
    for (SimpleNodeIterator e = getFrames().elements(); e.hasMoreNodes() && (null == ret); ) {
        node = e.nextNode();
        if (node instanceof FrameTag) {
            ret = (FrameTag) node;
            if (!ret.getFrameName().toUpperCase(locale).equals(name))
                ret = null;
        }
    }
    return (ret);
}

18 View Complete Implementation : ObjectTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Output a string representing this object tag.
 * @return A string showing the contents of the object tag.
 */
public String toString() {
    HashMap parameters;
    Iterator params;
    String paramName;
    String paramValue;
    boolean found;
    Node node;
    StringBuilder ret;
    ret = new StringBuilder(500);
    ret.append("Object Tag\n");
    ret.append("**********\n");
    ret.append("ClreplacedId = ");
    ret.append(getObjectClreplacedId());
    ret.append("\n");
    ret.append("CodeBase = ");
    ret.append(getObjectCodeBase());
    ret.append("\n");
    ret.append("CodeType = ");
    ret.append(getObjectCodeType());
    ret.append("\n");
    ret.append("Data = ");
    ret.append(getObjectData());
    ret.append("\n");
    ret.append("Height = ");
    ret.append(getObjectHeight());
    ret.append("\n");
    ret.append("Standby = ");
    ret.append(getObjectStandby());
    ret.append("\n");
    ret.append("Type = ");
    ret.append(getObjectType());
    ret.append("\n");
    ret.append("Width = ");
    ret.append(getObjectWidth());
    ret.append("\n");
    parameters = getObjectParams();
    params = parameters.entrySet().iterator();
    if (null == params)
        ret.append("No Params found.\n");
    else
        for (int cnt = 0; params.hasNext(); cnt++) {
            Map.Entry entry = (Entry) params.next();
            paramName = (String) entry.getKey();
            paramValue = (String) entry.getValue();
            ret.append(cnt);
            ret.append(": Parameter name = ");
            ret.append(paramName);
            ret.append(", Parameter value = ");
            ret.append(paramValue);
            ret.append("\n");
        }
    found = false;
    for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
        node = e.nextNode();
        if (node instanceof Tag)
            if (((Tag) node).getTagName().equals("PARAM"))
                continue;
        if (!found)
            ret.append("Miscellaneous items :\n");
        else
            ret.append(" ");
        found = true;
        ret.append(node.toString());
    }
    if (found)
        ret.append("\n");
    ret.append("End of Object Tag\n");
    ret.append("*****************\n");
    return (ret.toString());
}

18 View Complete Implementation : ScriptTag.java
Copyright Apache License 2.0
Author : bbossgroups
/**
 * Places the script contents into the provided buffer.
 * @param sb The buffer to add the script to.
 */
protected void putChildrenInto(StringBuilder sb) {
    Node node;
    if (null != getScriptCode())
        sb.append(getScriptCode());
    else
        for (SimpleNodeIterator e = children(); e.hasMoreNodes(); ) {
            node = e.nextNode();
            // eliminate virtual tags
            // if (!(node.getStartPosition () == node.getEndPosition ()))
            sb.append(node.toHtml());
        }
}