summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/javax/swing/text/html/parser/models
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/gnu/javax/swing/text/html/parser/models
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/classpath/gnu/javax/swing/text/html/parser/models')
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java62
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java77
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/list.java384
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/noTagModel.java75
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/node.java339
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/package.html53
-rw-r--r--libjava/classpath/gnu/javax/swing/text/html/parser/models/transformer.java201
7 files changed, 1191 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java
new file mode 100644
index 000000000..5a19a1bc1
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java
@@ -0,0 +1,62 @@
+/* PCDATAonly_model.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import java.io.Serializable;
+
+/**
+ * The model, allowing only PCDATA in it (like for element OPTION).
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class PCDATAonly_model
+ extends node
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ public PCDATAonly_model()
+ {
+ super((char) 0, (char) 0, null);
+ }
+
+ public Object show(Object x)
+ {
+ return x.toString().equalsIgnoreCase("#pcdata") ? Boolean.TRUE : Boolean.FALSE;
+ }
+}
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java
new file mode 100644
index 000000000..14514d584
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java
@@ -0,0 +1,77 @@
+/* TableRowContentModel.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import java.io.Serializable;
+
+import javax.swing.text.html.parser.DTD;
+import javax.swing.text.html.parser.Element;
+
+/**
+ * Table row content model.
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class TableRowContentModel
+ extends node
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+ final Element TD;
+
+ public TableRowContentModel(DTD dtd)
+ {
+ super((char) 0, (char) 0, null);
+ TD = dtd.getElement("TD");
+ }
+
+ public Object show(Object x)
+ {
+ // Always accept TD and TH
+ String s = x.toString();
+ if (s.equalsIgnoreCase("TD") || s.equalsIgnoreCase("TH"))
+ return Boolean.TRUE;
+
+ // Suggest closing in response to TR:
+ if (s.equalsIgnoreCase("TR"))
+ return Boolean.FALSE;
+
+ // Recommend TD for other cases:
+ return TD;
+ }
+}
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/list.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/list.java
new file mode 100644
index 000000000..1ff22f8cd
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/list.java
@@ -0,0 +1,384 @@
+/* list.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import gnu.java.lang.CPStringBuilder;
+
+import java.io.Serializable;
+
+/**
+ * Part of the internal representation of the content model.
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class list
+ extends node
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Setting to true means that the list nodes must always be connected
+ * by the same operation. This is far safer and clearer, but not
+ * required by default standard.
+ */
+ public static boolean CLEAR;
+
+ /**
+ * A list of nodes.
+ */
+ public final node[] nodes;
+
+ /**
+ * Creates a new model list that is a member of some enclosing list.
+ * @param binary_operator An operator with that this list is connected
+ * with other members of the enclosing list.
+ * @param unary_operator The unary operator for this list.
+ * @param a_nodes The nodes inside this list.
+ */
+ public list(char binary_operator, char unary_operator, node[] a_nodes)
+ {
+ super(binary_operator, unary_operator, a_nodes);
+ nodes = a_nodes;
+ }
+
+ /**
+ * Creates a new model list. Assigns the previous field.
+ * @param a_nodes The nodes for this list.
+ * @throws an error if the node elements are connected by the
+ * different operations. This is not supported, use grouping.
+ */
+ public list(node[] a_nodes)
+ throws Error
+ {
+ this(',', (char) 0, a_nodes);
+
+ int operation = nodes [ 0 ].binary;
+
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (CLEAR && nodes [ i ].binary != operation)
+ throw new Error("List members can only be connected by " +
+ "the same operation, use grouping"
+ );
+
+ if (i > 0)
+ nodes [ i ].previous = nodes [ i - 1 ];
+ }
+ }
+
+ /**
+ * Returns true if all members in the list are closed.
+ */
+ public boolean isClosed()
+ {
+ if (super.isClosed())
+ return true;
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (!nodes [ i ].isClosed())
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Find the token that could match as the next token in
+ * the token list.
+ *
+ * @return Such token object or null if none is found.
+ */
+ public Object findFreeNode()
+ {
+ Object fn;
+ for (int j = 0; j < nodes.length; j++)
+ {
+ if (!nodes [ j ].isClosed())
+ {
+ fn = nodes [ j ].findFreeNode();
+ if (fn != null)
+ return fn;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Tries to match this list agains the given token sequence.
+ * @param tokens the sequence of the tokens to match.
+ * @return true if the valid match is found.
+ */
+ public boolean matches(Object[] tokens)
+ {
+ reset();
+
+ Object x;
+ boolean m;
+ boolean matched = false;
+
+ for (int i = 0; i < tokens.length; i++)
+ {
+ matched = false;
+ x = tokens [ i ];
+
+ nodescan:
+ for (int j = 0; j < nodes.length; j++)
+ {
+ if (!nodes [ j ].isClosed())
+ {
+ m = nodes [ j ].performMatch(x);
+
+ if (m)
+ {
+ matched = true;
+ break nodescan;
+ }
+ }
+ }
+ if (!matched)
+ return false;
+ }
+
+ boolean valid = true;
+
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (!nodes [ i ].valid())
+ valid = false;
+ }
+
+ return valid;
+ }
+
+ /**
+ * The list never closes, despite it is trated as closed
+ * if all members in the list are closed.
+ * @return false.
+ */
+ public boolean mustClose()
+ {
+ return false;
+ }
+
+ /**
+ * Perform a match operation for the single token
+ * against this list.
+ * @param token a token to match.
+ * @return true if the match is found.
+ */
+ public boolean performMatch(Object token)
+ {
+ boolean ok = false;
+ Matching:
+ for (int i = 0; i < nodes.length; i++)
+ {
+ ok = nodes [ i ].performMatch(token);
+
+ if (ok)
+ break Matching;
+ }
+
+ if (ok)
+ matches();
+
+ return ok;
+ }
+
+ /**
+ * Prepeares the list for the next matching operation.
+ */
+ public void reset()
+ {
+ super.reset();
+ for (int i = 0; i < nodes.length; i++)
+ nodes [ i ].reset();
+ }
+
+ /**
+ * Check if the provided token can match as a next token in the
+ * list. In the case of match, the list state changes, moving
+ * current position after the matched token. However if this method
+ * returns a suggested new token to insert before the provided one,
+ * the state of the list does not change.
+ * @return Boolean.TRUE if the match is found,
+ * Boolean.FALSE if the match is not possible and no token can be
+ * inserted to make the match valid. Otherwise, returns the
+ * token object that can be inserted before the last token in the
+ * list, probably (not for sure) making the match valid.
+ * If the object is an instance of Element or TagElement,
+ * it is first ensured that the object flag "omit start" is set.
+ */
+ public Object show(Object x)
+ {
+ boolean m;
+ boolean matched = false;
+
+ nodescan:
+ for (int j = 0; j < nodes.length; j++)
+ {
+ if (!nodes [ j ].isClosed())
+ {
+ m = nodes [ j ].performMatch(x);
+
+ if (m)
+ {
+ matched = true;
+ break nodescan;
+ }
+ else
+ {
+ // For comma operation, only first not closed
+ // node must be tested for a match.
+ // unless it allows matching zero times.
+ if (binary == ',' &&
+ !(nodes [ j ].unary == '?' || nodes [ j ].unary == '*')
+ )
+ break nodescan;
+ }
+ }
+ }
+
+ if (!matched)
+ {
+ // Find and return that would be matched.
+ Object freeNode = findFreeNode();
+ if (freeNode == null)
+ return Boolean.FALSE;
+ else
+ return freeNode;
+ }
+
+ for (int i = 0; i < nodes.length; i++)
+ if (!nodes [ i ].validPreliminary())
+ {
+ return Boolean.FALSE;
+ }
+
+ return Boolean.TRUE;
+ }
+
+ /**
+ * Returns a string representation of the list.
+ * @return String representation, similar to BNF expression.
+ */
+ public String toString()
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ b.append(" ( ");
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (i > 0)
+ b.append(" " + (char) nodes [ i ].binary + " ");
+ b.append(nodes [ i ]);
+ }
+
+ b.append(" )");
+ if (unary != 0)
+ b.append((char) unary);
+ else
+ b.append(' ');
+ return b.toString();
+ }
+
+ /**
+ * Returns true if all memebers in the list are valid.
+ */
+ public boolean valid()
+ {
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (!nodes [ i ].valid())
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns true if all memebers in the list are either valid
+ * or unvisited. The unvisited members can become valid after
+ * more tokens will be shown.
+ */
+ public boolean validPreliminary()
+ {
+ if (silenceAllowed())
+ {
+ boolean everVisited = false;
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (nodes [ i ].visits > 0)
+ {
+ everVisited = true;
+ break;
+ }
+ }
+ if (!everVisited)
+ return true;
+ }
+
+ for (int i = 0; i < nodes.length; i++)
+ {
+ if (!nodes [ i ].validPreliminary())
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Closes all members in the list.
+ */
+ protected void close()
+ {
+ super.close();
+ for (int i = 0; i < nodes.length; i++)
+ {
+ nodes [ i ].close();
+ }
+ }
+
+ /**
+ * Compare given token with the token of this node.
+ * If the token represents a <code>list</code>, the call may be
+ * delegeted to the child subnodes.
+ * @param a_token A token to compare.
+ * @return True if the token matches the token of this node.
+ */
+ protected boolean compare(Object a_token)
+ {
+ return performMatch(a_token);
+ }
+}
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/noTagModel.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/noTagModel.java
new file mode 100644
index 000000000..8aac14d8e
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/noTagModel.java
@@ -0,0 +1,75 @@
+/* noTagModel.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import java.io.Serializable;
+
+/**
+ * Disallows a single given tag at the current content level only.
+ * <p>@author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)</p>
+ */
+public class noTagModel
+ extends node
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+ final String[] no;
+
+ public noTagModel(String[] noTag)
+ {
+ super((char) 0, (char) 0, null);
+ no = noTag;
+ }
+
+ public noTagModel(String noTag)
+ {
+ super((char) 0, (char) 0, null);
+ no = new String[] { noTag };
+ }
+
+ public Object show(Object x)
+ {
+ for (int i = 0; i < no.length; i++)
+ {
+ if (x.toString().equalsIgnoreCase(no [ i ]))
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ }
+}
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/node.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/node.java
new file mode 100644
index 000000000..f45a13b3e
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/node.java
@@ -0,0 +1,339 @@
+/* node.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import gnu.java.lang.CPStringBuilder;
+
+import java.io.Serializable;
+
+/**
+ * Part of the internal representation of the content model.
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class node
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ /**
+ * The token to match (can be instance of list).
+ */
+ public Object token;
+
+ /**
+ * True for the node that cannot be visited again.
+ */
+ public boolean _closed;
+
+ /**
+ * The binary operation for this node.
+ */
+ public char binary;
+
+ /**
+ * The unary opeation for this node.
+ */
+ public char unary;
+
+ /**
+ * The number of times the node already was visited.
+ */
+ public int visits;
+
+ /**
+ * The previous node in content model (used for closing nodes).
+ */
+ public node previous;
+
+ /**
+ * Creates a new node.
+ * @param binary_operator The operator, connecting all nodes in the list.
+ * The nodes, connected by the different operators, must be arranged into
+ * the different lists.
+ * @param unary_operator The unary operator for this node or zero if
+ * no such was specified.
+ * @param token The token to match. This can be either a string or
+ * the new instance of the list.
+ * @param a_previous The previous node in the list, null for the first
+ * node. This is used for propagating the closing operation for the
+ * comma delimited list.
+ */
+ public node(char binary_operator, char unary_operator, Object a_token)
+ {
+ if (a_token != null)
+ if (a_token.getClass().equals(node.class))
+ throw new Error("Creating node in node is redundant and ineffective.");
+
+ binary = binary_operator;
+ unary = unary_operator;
+ token = a_token;
+ }
+
+ /**
+ * Checks if this node is in the closed state.
+ * @return True if the node is closed.
+ */
+ public boolean isClosed()
+ {
+ return _closed;
+ }
+
+ /**
+ * Check if closing this node means closing the previous node.
+ */
+ public boolean closePrevious()
+ {
+ return binary == ',';
+ }
+
+ /**
+ * Return the token object if it could match as a next token in
+ * a token list of null if it could not.
+ * @return
+ */
+ public Object findFreeNode()
+ {
+ boolean ok;
+ if (isClosed() || silenceAllowed())
+ return null;
+
+ // Try if the node would stay valid after a one more visit.
+ visits++;
+ ok = valid();
+ visits--;
+
+ if (ok)
+ {
+ if (token instanceof node)
+ return ((node) token).findFreeNode();
+ else
+ return token;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Check if the current situation is such that the node must be closed
+ * now.
+ */
+ public boolean mustClose()
+ {
+ switch (unary)
+ {
+ case 0 :
+ return true;
+
+ case '*' :
+ return false;
+
+ case '+' :
+ return false;
+
+ case '?' :
+ return visits <= 1;
+
+ default :
+ throw new Error("Invalid unary operation " + unary + " ( '" +
+ (char) unary + "' )"
+ );
+ }
+ }
+
+ /**
+ * Do the match operation with the given token. This sets various
+ * flags.
+ * @param a_token The token to match.
+ * @return true if the the token matches node, false if it does not match
+ * or if the node is closed.
+ */
+ public boolean performMatch(Object a_token)
+ {
+ if (isClosed())
+ return false;
+
+ boolean matches = compare(a_token);
+ if (matches)
+ matches();
+
+ return matches;
+ }
+
+ /**
+ * Prepares the node for matching against a new list of tokens.
+ */
+ public void reset()
+ {
+ _closed = false;
+ visits = 0;
+ }
+
+ /**
+ * Check if the provided token can match this node.
+ * In the case of match, the node state changes, moving
+ * current position after the matched token. However if this method
+ * returns a suggested new token to insert before the provided one,
+ * the state of the list does not change.
+ * @return Boolean.TRUE if the match is found,
+ * Boolean.FALSE if the match is not possible and no token can be
+ * inserted to make the match valid. Otherwise, returns the
+ * token object that can be inserted before the last token in the
+ * list, probably (not for sure) making the match valid.
+ */
+ public Object show(Object x)
+ {
+ if (compare(x))
+ return performMatch(x) ? Boolean.TRUE : Boolean.FALSE;
+
+ Object recommended = findFreeNode();
+ return recommended != null ? recommended : Boolean.FALSE;
+ }
+
+ /**
+ * Check if it would be a valid case if this node is visited zero times.
+ * Nodes with unary operator * or ? need not be matched to make a
+ * model valid.
+ */
+ public boolean silenceAllowed()
+ {
+ return unary == '?' || unary == '*';
+ }
+
+ /**
+ * Returns a string representation of the list.
+ * @return String representation, similar to BNF expression.
+ */
+ public String toString()
+ {
+ CPStringBuilder b = new CPStringBuilder();
+
+ b.append(token);
+ if (unary != 0)
+ b.append((char) unary);
+ else
+ b.append('\'');
+
+ return b.toString();
+ }
+
+ /**
+ * Check if the node state is valid.
+ */
+ public boolean valid()
+ {
+ switch (unary)
+ {
+ case 0 :
+ if (binary == '|')
+ return true;
+ else
+ return visits == 1;
+
+ case '*' :
+ return true;
+
+ case '+' :
+ return visits > 0;
+
+ case '?' :
+ return visits <= 1;
+
+ default :
+ throw new Error("Invalid unary operation " + unary + " ( '" +
+ (char) unary + "' )"
+ );
+ }
+ }
+
+ public boolean validPreliminary()
+ {
+ return visits == 0 || valid();
+ }
+
+ /**
+ * Closes this node and, if closePrevious() returs true, calls close() for
+ * the previous node.
+ */
+ protected void close()
+ {
+ _closed = true;
+ if (previous != null && closePrevious())
+ previous.close();
+ }
+
+ /**
+ * Compare the provided token object with the token object of this node.
+ */
+ protected boolean compare(Object a_token)
+ {
+ if (token instanceof Object[])
+ throw new Error("Invalid token object, probably the 'list' " +
+ "should be used. "
+ );
+
+ if (token instanceof node[])
+ throw new Error("Do not use 'node' for the array of nodes, use 'list'. ");
+
+ if (token instanceof node)
+ {
+ return ((node) token).performMatch(a_token);
+ }
+
+ boolean rt = false;
+
+ if (token == a_token)
+ rt = true;
+ if (token.equals(a_token))
+ rt = true;
+ if (token.toString().equalsIgnoreCase(a_token.toString()))
+ rt = true;
+
+ return rt;
+ }
+
+ /**
+ * Fire the changes that must happen then the token matches this node.
+ */
+ protected void matches()
+ {
+ visits++;
+ if (mustClose())
+ close();
+ }
+}
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/package.html b/libjava/classpath/gnu/javax/swing/text/html/parser/models/package.html
new file mode 100644
index 000000000..18e61aede
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/package.html
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.text.html.parser package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - gnu.javax.swing.text.html.parser.models</title></head>
+
+<body>
+<p>This package contains classes for working with content models. In this implementation, the
+standardized content model is pre-processed by <code>transformer</code> into an instance of
+<code>node</code>. Node holds a single element of the content model with the optional unary operation.
+The derived class <code>list</code> holds multiple nodes connected by the same binary operation.
+As the members of this <code>list</code> can also be lists itself, these structures support
+the most of required operations. Several cases when the model cannot be expressed using
+BNF syntax are handled providing specialised classes that are also derived from <code>node</code>.
+</p>
+@author Audrius Meskauskas, Lithuania
+</body>
+</html>
diff --git a/libjava/classpath/gnu/javax/swing/text/html/parser/models/transformer.java b/libjava/classpath/gnu/javax/swing/text/html/parser/models/transformer.java
new file mode 100644
index 000000000..22ae3c3fa
--- /dev/null
+++ b/libjava/classpath/gnu/javax/swing/text/html/parser/models/transformer.java
@@ -0,0 +1,201 @@
+/* transformer.java -- Content model transforms.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser.models;
+
+import java.io.Serializable;
+
+import javax.swing.text.html.parser.ContentModel;
+import javax.swing.text.html.parser.DTD;
+
+/**
+ * Transforms the standard ContentModel tree into the internal representation,
+ * used in this implementation.
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class transformer
+ implements Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ /**
+ * All binary operators.
+ */
+ protected static String binary = "&|,";
+
+ /**
+ * All unary operators.
+ */
+ protected static String unary = "+*?";
+
+ /**
+ * Measure length of the linked list of the content models.
+ * @param c The heading element of the linked list.
+ * @return the length of the list (0 for null 1 if c!=null and c.next==null,
+ * etc.
+ */
+ public static int measureChainLength(ContentModel c)
+ {
+ if (c == null)
+ return 0;
+ else
+ return measureChainLength(c.next) + 1;
+ }
+
+ /**
+ * Transform into internal representation without usind dtd.
+ * This should be used only for testing.
+ */
+ public static node transform(ContentModel c)
+ {
+ return transform(c, null);
+ }
+
+ /**
+ * Transform into internal representation.
+ * @param c a model to transform
+ * @return a transformed model
+ * @throws Error if the model structure contains errors.
+ */
+ public static node transform(ContentModel c, DTD dtd)
+ {
+ // Handle the special cases first.
+ if (c.content instanceof node)
+ return (node) c.content;
+
+ // Do the typical transform.
+ node n;
+
+ /* Case with the single token */
+ if (c.next == null)
+ {
+ n = optionalTransform(c, dtd);
+ }
+ else /* Case with the chain of the multiple tokens. */
+ {
+ node[] l = new node[ measureChainLength(c) ];
+ ContentModel m = c;
+ for (int i = 0; i < l.length; i++)
+ {
+ if (m.content instanceof ContentModel)
+ {
+ ContentModel nested = (ContentModel) m.content;
+ if (nested.next == null &&
+ !(nested.content instanceof ContentModel)
+ )
+ {
+ l [ i ] =
+ new node((char) m.type, (char) nested.type, nested.content);
+ }
+ else
+ {
+ l [ i ] = transform(nested, dtd);
+ }
+ }
+ else
+ l [ i ] = new node((char) 0, (char) 0, m.content);
+ addtype(l [ i ], (char) m.type);
+ m = m.next;
+ }
+
+ if (isBinary(c.type))
+ for (int i = 0; i < l.length; i++)
+ {
+ l [ i ].binary = (char) c.type;
+ }
+
+ n = new list(l);
+ }
+
+ addtype(n, (char) c.type);
+
+ return n;
+ }
+
+ /**
+ * True for binary operator
+ * @param c a character to test
+ * @return true for [ ,&| ], false otherwise.
+ */
+ private static boolean isBinary(int c)
+ {
+ return binary.indexOf((char) c) >= 0;
+ }
+
+ /**
+ * True for unary operator.
+ * @param c a character to test
+ * @return true for [ +?* ], false otherwise.
+ */
+ private static boolean isUnary(int c)
+ {
+ return unary.indexOf((char) c) >= 0;
+ }
+
+ /**
+ * Assign an operation type for the given node.
+ * @param n A node to set the operation to.
+ * @param type Either binary or unary operation, is assigned to the
+ * corresponding field of the node.
+ * @throws error if the operation type is not
+ * representing a valid unary or binary operation.
+ */
+ private static void addtype(node n, char type)
+ {
+ if (isBinary(type))
+ n.binary = type;
+
+ else if (isUnary(type))
+ n.unary = type;
+
+ else if (type != 0)
+ throw new Error("Invalid operation '" + (char) type + "'");
+ }
+
+ private static node optionalTransform(ContentModel c, DTD dtd)
+ {
+ node n;
+ if (c.content instanceof ContentModel)
+ n = transform((ContentModel) c.content, dtd);
+ else
+
+ /* A single token with the specified operation */
+ n = new node((char) 0, (char) 0, c.content);
+ return n;
+ }
+}