harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r507006 [1/5] - in /harmony/enhanced/classlib/trunk/modules/swing: ./ src/main/java/common/javax/swing/text/html/parser/
Date Tue, 13 Feb 2007 14:02:58 GMT
Author: ayza
Date: Tue Feb 13 06:02:55 2007
New Revision: 507006

URL: http://svn.apache.org/viewvc?view=rev&rev=507006
Log:
Initial commit of the HTML parser contribution from HARMONY-2829

Added:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLAttributeList.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLComment.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLErrorType.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLMarkup.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLObject.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLTag.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLTagType.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLText.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/LexerTextStateType.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/LexerTextType.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Pair.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ParserCup.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ParserHandler.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ParserSym.java   (with props)
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/html32.bdtd   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/swing/build.xml
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/AttributeList.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ContentModel.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/DTD.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/DTDConstants.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/DTDUtilities.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/DocumentParser.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Element.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ElementsHandler.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/EntitiesHandler.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Entity.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/HTMLConstants.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Parser.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/ParserDelegator.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/TagElement.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/transitional401.bdtd

Modified: harmony/enhanced/classlib/trunk/modules/swing/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/build.xml?view=diff&rev=507006&r1=507005&r2=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/build.xml (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/build.xml Tue Feb 13 06:02:55 2007
@@ -49,6 +49,14 @@
         </or>
     </fileset>
 
+    <!-- List of private classes that cannot be mapped by above mappers -->
+    <fileset id="hidden.classes" dir="${hy.build}">
+        <include name="javax/swing/text/html/parser/ModelElement.class"/>
+        <include name="javax/swing/text/html/parser/Asn1ModelElement.class"/>
+        <include name="javax/swing/text/html/parser/Asn1ModelElement$1.class"/>
+        <include name="javax/swing/text/html/parser/CUP$ParserCup$actions.class"/>
+    </fileset>
+
     <property file="../../make/depends.properties" />
 
     <property name="swing.exclude.file" location="${hy.hdk}/build/swing.exclude" />
@@ -119,6 +127,7 @@
         <jar destfile="${hy.jdk}/jre/lib/boot/${hy.swing.packaging.jarname}.jar"
              manifest="${hy.swing}/META-INF/MANIFEST.MF">
             <fileset refid="classes" />
+            <fileset refid="hidden.classes" />
             <manifest>
                 <attribute name="Implementation-Version" value="${svn.info}"/> 
             </manifest>

Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java?view=auto&rev=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java Tue Feb 13 06:02:55 2007
@@ -0,0 +1,292 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * It implements ASN.1 codification tools for
+ * <code>javax.swing.text.html.parser.AttributeList</code>. Given an
+ * <code>AttributeList</code>, its values are codified in ASN.1 according to
+ * the following rule:
+ *
+ * <pre>
+ * HTMLElementAttributes ::= SEQUENCE {
+ *      Name UTF8String,
+ *      Type INTEGER,
+ *      Modifier INTEGER,
+ *      DefaultValue UTF8String OPTIONAL,
+ *      PossibleValues SET OF UTF8String OPTIONAL
+ * }
+ * </pre>
+ *
+ * The class can be used to obtain a byte array representing the codification of
+ * an <code>AttributeList</code>, as well as an <code>AttributeList</code>
+ * from a byte array (previously obtained codifying an <code>AttributeList</code>).
+ * In fact, it serves as a wrapper for the codification and the
+ * <code>AttributeList</code> itself.
+ * 
+ * @author Alejandro Sánchez
+ * @author Diego Raúl Mercado
+ * @author Alejandro Barturen 
+ * @version $Revision: 1.6 $
+ */
+class Asn1Attributes {
+
+    /**
+     * It stores the definition of an <code>AttributeList</code> as an ASN.1
+     * valid type according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_ATTRIBUTES;
+
+    /**
+     * The definition of the ASN1_ATTRIBUTES type according to the rule defined
+     * for an <code>AttributeList</code>. It also defines a custom
+     * encoder/decoder for this type.
+     */
+    static {
+        ASN1_ATTRIBUTES = new ASN1Sequence(new ASN1Type[] {
+                ASN1StringType.UTF8STRING, // 0 Name
+                ASN1Integer.getInstance(), // 1 Type
+                ASN1Integer.getInstance(), // 2 Modifier
+                ASN1StringType.UTF8STRING, // 3 DefaultValue
+                new ASN1SetOf(ASN1StringType.UTF8STRING) // 4 PosibleValues
+                }) {
+
+            {
+                setOptional(3);
+                setOptional(4);
+            }
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents an <code>AttributeList</code>. It makes a completely
+             * new <code>AttributeList</code> with the information interpreted
+             * from the stream.
+             * <p>
+             * Note that the information related with the next
+             * <code>AttributeList</code> in the chain is managed in the
+             * <code>Asn1Element</code> class. For this reason, from this
+             * method, the <code>next</code> field is always set to null.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codified information will be read from.
+             * @return An <code>AttributeList</code> filled with the
+             *         information read from the stream.
+             */
+            public Object getDecodedObject(BerInputStream in) {
+                Object values[] = (Object[]) in.content;
+
+                String name = (String) values[0]; // Name
+                int type = new BigInteger((byte[]) values[1]).intValue(); // Type
+                int modifier = new BigInteger((byte[]) values[2]).intValue(); // Modifier
+                String defValue = (String) values[3]; // DefValue
+                Vector vecValues = values[4] != null ?
+                        lst2vector((List) values[4]) : null;
+
+                // XXX next value modified in Asn1Element...
+                return new AttributeList(name, type, modifier, defValue,
+                        vecValues, null);
+            }
+
+            /**
+             * Overrided method used to codify the information stored in an
+             * <code>AttributeList</code> into an array of bytes, according to
+             * its ASN.1 specification.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of an
+             *            <code>Asn1Attributes</code> object which contains
+             *            the <code>AttributeList</code> to be codified.
+             * 
+             * @param values
+             *            An array of objects where the attributes' name, type,
+             *            modifier, default value and possibles allowed values
+             *            information will be stored, ready for codification.
+             */
+            public void getValues(Object object, Object values[]) {
+                Asn1Attributes asn1 = (Asn1Attributes) object;
+
+                try {
+                    values[0] = asn1.getAttributeList().getName();
+                    values[1] = BigInteger.valueOf(
+                            asn1.getAttributeList().getType()).toByteArray();
+                    values[2] = BigInteger.valueOf(
+                            asn1.getAttributeList().getModifier())
+                            .toByteArray();
+                    values[3] = asn1.getAttributeList().getValue();
+
+                    if (asn1.getAttributeList().values != null) {
+                        ArrayList<String> lst = new ArrayList<String>();
+                        for (Enumeration e = asn1.getAttributeList()
+                                .getValues(); e.hasMoreElements();) {
+                            lst.add((String) e.nextElement());
+                        }
+                        values[4] = lst;
+                    }
+                } catch (IOException e) {
+                    throw new AssertionError(e); // this should not happen
+                }
+            }
+        };
+    }
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for an <code>AttributeList</code> with its encoder
+     * and decoder.
+     * <p>
+     * Among other things, this method can be used to declare the types of new
+     * fields in other structures, as for example, in an
+     * <code>Asn1Element</code>.
+     * 
+     * @return The value that defines an ASN.1 <code>AttributeList</code>
+     *         representation with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_ATTRIBUTES;
+    }
+
+    /**
+     * An internal copy of the <code>AttributeList</code> to be codified.
+     */
+    private AttributeList att;
+
+    /**
+     * An internal copy of the byte array which contains the codification of an
+     * <code>AttributeList</code>. From this variable, the information used
+     * to decodify an <code>AttributeList</code> is read from.
+     */
+    private byte[] encoded;
+
+    /**
+     * Constructs a new instance of an <code>Asn1Attributes</code> class from
+     * a byte array. The byte array received as argument can be later decodified
+     * into an <code>AttributeList</code>.
+     * 
+     * @param encoded
+     *            A byte array containing the codified information of an
+     *            <code>AttributeList</code>.
+     */
+    public Asn1Attributes(byte[] encoded) {
+        byte[] copy = new byte[encoded.length];
+        System.arraycopy(encoded, 0, copy, 0, copy.length);
+        this.encoded = copy;
+    }
+
+    /**
+     * Constructs a new instance of an <code>Asn1Attributes</code> class from
+     * an <code>AttributeList</code>. The <code>AttributeList</code>
+     * received as argument can be then codified into a byte array.
+     * <p>
+     * The value received as argument should not be null. If so, a
+     * <code>NullPointerException</code> is thrown.
+     * 
+     * @param att
+     *            The <code>AttributeList</code> to be codified.
+     */
+    public Asn1Attributes(AttributeList att) {
+        if (att == null) {
+            throw new NullPointerException();
+        }
+        this.att = att;
+    }
+
+    /**
+     * Returns the representation of an <code>AttributeList</code> in ASN.1
+     * codification.
+     * <p>
+     * If the <code >Asn1Attributes</code> object was created with an
+     * <code>AttributeList</code>, then the <code>AttributeList</code> is
+     * codified and returned as a byte array. On the other hand, if the instance
+     * was created using a byte array, then no codification process is made.
+     * 
+     * @return If at construction time an <code>AttributeList</code> was
+     *         given, its representation in ASN.1 codification. If at
+     *         construction time a byte array was given, a copy of the same
+     *         array is returned.
+     */
+    public byte[] getEncoded() {
+        if (encoded == null) {
+            return ASN1_ATTRIBUTES.encode(att);
+        } else {
+            return encoded;
+        }
+    }
+
+    /**
+     * Returns the <code>AttributeList</code> obtained from the decodification
+     * of an ASN.1 codified byte array.
+     * <p>
+     * If the <code>Asn1Attributes</code> was created giving an
+     * <code>AttributeList</code>, a reference to the same
+     * <code>AttributeList</code> is obtained. Otherwise, the byte array given
+     * at construction time is decodificated into a new
+     * <code>AttributeList</code> object.
+     * 
+     * @return If at construction time an <code>AttributeList</code> was
+     *         given, the same <code>AttributeList</code> is returned. If at
+     *         construction time a byte array was given, an
+     *         <code>AttributeList</code> constructed with the information
+     *         stored in that byte array is returned.
+     * @throws IOException
+     *             If the decodification process could not be carried out
+     *             properly.
+     */
+    public AttributeList getAttributeList() throws IOException {
+        if (att == null) {
+            return (AttributeList) ASN1_ATTRIBUTES.decode(encoded);
+        } else {
+            return att;
+        }
+    }
+
+    /**
+     * Converts a list of <code>String</code> into a vector of
+     * <code>String</code>.
+     * 
+     * @param lst
+     *            The list of <code>String</code> to be converted.
+     * @return A <code>Vector</code> containing the <code>String</code>s
+     *         stored in the <code>List</code> received as argument.
+     */
+    private static Vector lst2vector(List lst) {
+        Vector<String> vecValues = new Vector<String>();
+        for (Iterator iter = lst.iterator(); iter.hasNext();) {
+            String element = (String) iter.next();
+            vecValues.addElement(element);
+        }
+        return vecValues;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Attributes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java?view=auto&rev=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java Tue Feb 13 06:02:55 2007
@@ -0,0 +1,626 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SequenceOf;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * It implements ASN.1 codification tools for
+ * <code>javax.swing.text.html.parser.ContentModel</code>. Given a
+ * <code>ContentModel</code>, its values are codified in ASN.1 according to
+ * the following rule:
+ * 
+ * <pre>
+ * HTMLContentModel ::= SEQUENCE OF SEQUENCE {
+ *      Type INTEGER,
+ *      Index INTEGER
+ * }
+ * </pre>
+ * 
+ * The structure used to store the <code>ContentModel</code> is a sort of
+ * binary tree that imitate the internal structure of a
+ * <code>ContentModel</code>.
+ * <p>
+ * As you may know, a <code>ContentModel</code> can be represented by a binary
+ * tree where each node denotes one of the following possible values:
+ * <ul>
+ * <li> A binary relation between its children.
+ * <li> A unary relation applied only to its left child.
+ * <li> An element.
+ * <li> A null value.
+ * </ul>
+ * <p>
+ * So, depending on each of those possible values, a different node is created
+ * to summarize that information. We will denote each node as a pair of (type,
+ * index). Therefore, according to the representation of a ContentModel,we have
+ * the following conversions:
+ * <p>
+ * 
+ * <b>CASE 1: A binary relation between its children</b>
+ * 
+ * <pre>
+ *                    B
+ *                   /               =&gt;         [B,-1]
+ *                 C1   
+ *                  \
+ *                   C2
+ *                    \
+ *                    ...
+ *                      \
+ *                      Cn
+ *                 
+ *                 
+ * </pre>
+ * 
+ * 
+ * <b>CASE 2: A unary relation applied inly to its left child</b>
+ * 
+ * <pre>
+ *                    U
+ *                   /               =&gt;         [U,-1]
+ *                 C1    
+ * </pre>
+ * 
+ * 
+ * <b>CASE 3: An element</b>
+ * 
+ * <pre>
+ *                   ELEM            =&gt;         [-2, ELEM.getIndex()]
+ * </pre>
+ * 
+ * 
+ * <b>CASE 4: A null value</b>
+ * 
+ * <pre>
+ *                   NULL            =&gt;         [-1,-1]  
+ * </pre>
+ * 
+ * 
+ * 
+ * For example, lets take the <code>ContentModel</code>'s tree for the HEAD
+ * <code>Element<code>. The <code>ContentModel</code> is defined as:
+ * 
+ * <pre>
+ *              TITLE &amp; ISINDEX? &amp; BASE?
+ * </pre>
+ * 
+ * And the <code>ContentModel</code> tree for this case is then:
+ * 
+ * <pre>
+ *                                      &amp;
+ *                                      |
+ *                    +-----------------+-----------------+
+ *                    |                                   |
+ *                    0                                 NULL
+ *          +---------+---------+
+ *          |                   |
+ *        TITLE                 ?
+ *                    +---------+---------+
+ *                    |                   |
+ *                    0                   ?
+ *               +----+----+         +----+----+
+ *               |         |         |         |
+ *            ISINDEX    NULL        0       NULL
+ *                             +-----+-----+
+ *                             |           |
+ *                            BASE       NULL
+ *          
+ * </pre>
+ * 
+ * Then, this representation translated into our tree representation looks like:
+ * 
+ * 
+ * <pre>
+ *                                  ['&amp;',-1]
+ *                                      |
+ *                    +-----------------+-----------------+
+ *                    |                                   |
+ *                  [0,-1]                             [-1,-1]
+ *          +---------+---------+
+ *          |                   |
+ *      [-2,TITLE]          ['?',-1]
+ *                    +---------+---------+
+ *                    |                   |
+ *                  [0,-1]            ['?',-1]
+ *               +----+----+         +----+----+
+ *               |         |         |         |
+ *          [-2,ISINDEX][-1,-1]    [0,-1]   [-1,-1]
+ *                             +-----+-----+
+ *                             |           |
+ *                         [-2,BASE]    [-1,-1]
+ * </pre>   
+ * 
+ * So then, this simpler tree can be stored as a sequence of pairs (type,index),
+ * and reconstructing it again is straightforward if both, the storage and
+ * recovery of information, are made is BSF mode.
+ * <p>
+ * Then, this tree will be represented by the sequence:
+ * <p> 
+ * ['&',-1] , [0,-1], [-1,-1], [-2,TITLE], ['?',-1], [0,-1], ['?',-1],
+ * [-2,ISINDEX], [-1,-1], [0,-1], [-1,-1], [-2,BASE], [-1,-1]
+ * <p> 
+ * And the relation among nodes can be restored if we consider that if the
+ * sequence is numerated from 0, we maintain the number of processed
+ * <tt>relation nodes (rn)</tt> and we read the stored nodes in order, for any
+ * relational node, its sons are stored ad positions 2*rn+1 and 2*rn+2.
+ * 
+ * The class can be used to obtain a byte array representing the codification of
+ * a <code>ContentModel</code>, as well as a <code>ContentModel</code> from
+ * a byte array (previously obtained codifying a <code>ContentModel</code>).
+ * In fact, it serves as a wrapper for the codification and the
+ * <code>ContentModel</code> itself.
+ * 
+ * @author Alejandro Sánchez
+ * @author Diego Raúl Mercado
+ * @author Alejandro Barturen
+ * @version $Revision: 1.9 $
+ */
+class Asn1ContentModel {
+
+    /**
+     * It stores the definition of a <code>ContentModel</code> as an ASN.1
+     * valid type according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_CONTENT_MODEL;
+
+    /**
+     * The definition of the ASN1_CONTENT_MODEL type according to the rule
+     * defined for a <code>ContentModel</code>. It also defines a custom
+     * encoder/decoder for this type.
+     */
+    static {
+        ASN1_CONTENT_MODEL = new ASN1SequenceOf(Asn1ModelElement.getInstance()) {
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents a <code>ContentModel</code>. It makes a completely
+             * new <code>ContentModel</code> with the information interpreted
+             * from the stream.
+             * <p>
+             * As at this point no information about other <code>Element</code>s
+             * is available, a partial empty <code>Element</code> is used to
+             * denote the presence of other elements in the
+             * <code>ContentModel</code>.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codificated information will be read from.
+             * @return A <code>ContentModel</code> filled with the information
+             *         read from the stream.
+             */
+            public Object getDecodedObject(BerInputStream in) {
+                Object values = in.content;
+
+                int pos = 0;
+                ArrayList mLst = (ArrayList) values;
+                ArrayList<Object> queue = new ArrayList<Object>();
+                ContentModel rootModel = (ContentModel)ModelElement.makeContent(
+                                            (ModelElement)mLst.get(0));
+                ContentModel actualModel = null;
+                if (rootModel != null) {
+                    queue.add(rootModel);
+                }
+
+                while (!queue.isEmpty()) {
+                    actualModel = (ContentModel)queue.remove(0);
+                    actualModel.content = ModelElement.makeContent(
+                                                (ModelElement)mLst
+                            .get(pos * 2 + 1));
+                    actualModel.next = (ContentModel)ModelElement.makeContent(
+                                                (ModelElement)mLst
+                            .get(pos * 2 + 2));
+                    if ( actualModel.content instanceof ContentModel) {
+                        queue.add(actualModel.content);
+                    }
+                    if (actualModel.next != null) {
+                        queue.add(actualModel.next);
+                    }
+                    pos++;
+                }
+
+                return rootModel;
+            }
+
+            /**
+             * Overrided method used to codify the information stored in an
+             * <code>ContentModel</code> into an array of bytes, according to
+             * its ASN.1 specification.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of an
+             *            <code>Asn1ContentModel</code> object which contains
+             *            the <code>ContentModel</code> to be codified.
+             * 
+             * @return A collection with the information of the nodes that
+             *         compose the <code>ContentModel</code>, ready to be
+             *         codified.
+             */
+            public Collection getValues(Object object) {
+                ArrayList<Object> queue = new ArrayList<Object>();
+                ArrayList<ModelElement> mLst = new ArrayList<ModelElement>();
+                Asn1ContentModel asn1 = (Asn1ContentModel) object;
+                ContentModel model = asn1.getWrappedContentModel();
+                
+                mLst.add(new ModelElement(model));
+                if (model != null) {
+                    queue.add(model);
+                }
+                while (!queue.isEmpty()) {
+                    model = (ContentModel)queue.remove(0);
+                        mLst.add(new ModelElement(
+                                        (model.content)));
+                        mLst.add(new ModelElement(model.next));
+                        if ((model.content) instanceof ContentModel) {
+                            queue.add(model.content);
+                        }
+                        if (model.next != null) {
+                            queue.add(model.next);
+                        }
+                }
+                
+                return mLst;
+            }
+        };
+    }
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for a <code>ContentModel</code> with its encoder and
+     * decoder.
+     * <p>
+     * Among other things, this method can be used to declare the types of new
+     * fields in other structures, as for example, in an
+     * <code>Asn1Element</code>.
+     * 
+     * @return The value that defines an ASN.1 <code>ContentModel</code>
+     *         representation with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_CONTENT_MODEL;
+    }
+
+    /**
+     * An internal copy of the <code>ContentModel</code> to be codified.
+     */
+    private ContentModel contentModel;
+
+    /**
+     * An internal copy of the byte array which contains the codification of an
+     * <code>ContentModel</code>. From this variable, the information used to
+     * decodify a <code>ContentModel</code> is read from.
+     */
+    private byte[] encoded;
+
+    /**
+     * Constructs a new instance of an <code>Asn1ContentModel</code> class
+     * from a byte array. The byte array received as argument can be later
+     * decodified into a <code>ContentModel</code>.
+     * 
+     * @param encoded
+     *            A byte array containing the codified information of a
+     *            <code>ContentModel</code>.
+     */
+    public Asn1ContentModel(byte[] encoded) {
+        byte[] copy = new byte[encoded.length]; 
+        System.arraycopy(encoded, 0, copy, 0, copy.length);
+        this.encoded = copy;
+    }
+
+    /**
+     * Constructs a new instance of an <code>Asn1ContentModel</code> class
+     * from a <code>ContentModel</code>. The <code>ContentModel</code>
+     * received as argument can be then codified into a byte array.
+     * 
+     * @param contentModel
+     *            The <code>ContentModel</code> to be codified.
+     */
+    public Asn1ContentModel(ContentModel contentModel) {
+        this.contentModel = contentModel;
+    }
+
+    /**
+     * Returns the representation of a <code>ContentModel</code> in ASN.1
+     * codification.
+     * <p>
+     * If the <code >Asn1ContentModel</code> object was created with a
+     * <code>ContentModel</code>, then the <code>ContentModel</code> is
+     * codified and returned as a byte array. On the other hand, if the instance
+     * was created using a byte array, then no codification process is made.
+     * 
+     * @return If at construction time a <code>ContentModel</code> was given,
+     *         its representation in ASN.1 codification. If at construction time
+     *         a byte array was given, a copy of the same array is returned.
+     */
+    public byte[] getEncoded() {
+        if (encoded == null) {
+            return ASN1_CONTENT_MODEL.encode(contentModel);
+        } else {
+            byte[] copy = new byte[encoded.length]; 
+            System.arraycopy(encoded, 0, copy, 0, copy.length);
+            return copy;
+        }
+    }
+
+    /**
+     * Returns the <code>ContentModel</code> obtained from the decodification
+     * of an ASN.1 codified byte array.
+     * <p>
+     * If the <code>Asn1ContentModel</code> was created giving an
+     * <code>ContentModel</code>, a reference to the same
+     * <code>ContentModel</code> is obtained. Otherwise, the byte array given
+     * at construction time is decodificated into a new
+     * <code>ContentModel</code> object.
+     * 
+     * @return If at construction time a <code>ContentModel</code> was given,
+     *         the same <code>ContentModel</code> is returned. If at
+     *         construction time a byte array was given, a
+     *         <code>ContentModel</code> constructed with the information
+     *         stored in that byte array is returned.
+     * @throws IOException
+     *             If the decodification process could not be carried out
+     *             properly.
+     */
+    public ContentModel getContentModel() throws IOException {
+        if (contentModel == null) {
+            return (ContentModel) ASN1_CONTENT_MODEL.decode(encoded);
+        } else {
+            return contentModel;
+        }
+    }
+
+    /**
+     * Returns the <code>ContentModel</code> wrapped into the
+     * <code>Asn1ContentModel</code> object.
+     * 
+     * @return The wrapped <code>ContentModel</code>, if one was used at
+     *         construction time, or null if the object was created using a byte
+     *         array.
+     */
+    public ContentModel getWrappedContentModel() {
+        return contentModel;
+    }
+}
+
+/**
+ * It implements the elements that compose the sequence that defines a
+ * <code>ContentModel</code>.
+ * <p>
+ * When the ASN.1 representation for the <code>ContentModel</code> was given,
+ * it was defined as a "SEQUENCE OF" some structures, thus the purpose of this
+ * class is to define the "SEQUENCE" that implements that structures. Such
+ * structures will be denoted by the name <code>ModelElement</code>.
+ * <p>
+ * When defined the codification of a <code>ContentModel</code>, its tree
+ * structure was established. This class just defines the node's structure of
+ * such tree.
+ */
+class ModelElement {
+
+    /**
+     * It stores the type of the node.
+     */
+    private int type;
+
+    /**
+     * It stores the index of the <code>Element</code> that codify the node.
+     */
+    private int index;
+
+    /**
+     * Sets the values of the node.
+     * 
+     * @param type
+     *            The type set to the node
+     * @param index
+     *            The index of the <code>Element</code> that the node is
+     *            codifying.
+     */
+    private void setValues(int type, int index) {
+        this.type = type;
+        this.index = index;
+    }
+
+    /**
+     * Returns the type of the node.
+     * 
+     * @return The integer representation of the symbol that denote the unary
+     *         ('*', '+', '?') or binary ('|', '&', ',') relation that relates
+     *         the two children of this node. 0 if the node represents an
+     *         <code>Element</code> or -1 if the node represents a null value.
+     */
+    public int getType() {
+        return type;
+    }
+
+    /**
+     * Returns the index of the <code>Element</code> that the node is
+     * codifying.
+     * 
+     * @return The index of the codified <code>Element</code> or -1 if no
+     *         <code>Element</code> is codified.
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * Constructs a new <code>ModelElement</code> given a type and index
+     * value.
+     * 
+     * @param type
+     *            The node type. Any <code>int</code> value is possible.
+     * @param index
+     *            The node index. Any <code>int</code> value is possible.
+     */
+    public ModelElement(final int type, final int index) {
+        setValues(type, index);
+    }
+
+    /**
+     * Constructs a new <code>ModelElement</code> given a
+     * <code>ContentModel</code>. The information used to define the
+     * <code>ModelElement</code> is retrieved from the
+     * <code>ContentModel</code>.
+     * 
+     * @param obj
+     *            The <code>ContentModel</code> from where the information
+     *            used to define the <code>ModelElement</code> is retrieved.
+     */
+    public ModelElement(Object obj) {
+        if (obj == null) {
+            setValues(-1, -1);
+        } else {
+            if (obj instanceof Element) {
+                setValues(-2, ((Element)obj).index);
+            } else {
+                setValues(((ContentModel)obj).type, -1);
+            }
+        }
+    }
+
+    /**
+     * Constructs a <code>ContentModel</code> using the information stored
+     * into a <code>ModelElement</code>. If the <code>ModelElement</code>
+     * denoted an <code>Element</code>, an <code>Element</code> with only
+     * its index and a suitable name will be returned.
+     * 
+     * @param me
+     *            The <code>ModelElement</code> from where the information to
+     *            construct the <code>ContentModel</code> is retrieved.
+     * @return A <code>ContentModel</code> or <code>Element</code> 
+     *         initialized with the information
+     *         stored in the <code>ModelElement<code> given as argument.
+     */
+    public static Object makeContent(ModelElement me) {
+        Object obj;
+        switch (me.getType()) {
+        case -1:
+            obj = null;
+            break;
+        case -2:
+            obj = new Element(me.getIndex(), "ELEMENT "
+                    + me.getIndex(), false, false, null, null, 1, null, null,
+                    null);
+            break;
+        default:
+            obj = new ContentModel();
+            ((ContentModel)obj).type = me.getType();
+            break;
+        }
+        return obj;
+    }
+}
+
+/**
+ * It implements ASN.1 codification tools for the nodes that conforms the
+ * <code>ContentModel</code> tree representation.
+ * <p>
+ * The class can be used to obtain a byte array representing the codification of
+ * a <code>ModelElement</code>, as well as a <code>ModelElement</code> from
+ * a byte array (previously obtained codifying a <code>ModelElement</code>).
+ */
+class Asn1ModelElement {
+
+    /**
+     * It stores the definition of a <code>ModelElement</code> as an ASN.1
+     * valid type according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_MODEL_ELEMENT;
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for a <code>ModelElement</code> with its encoder and
+     * decoder.
+     * <p>
+     * Among other things, this method can be used to declare the types of new
+     * fields in other structures, as for example, in an
+     * <code>Asn1ContentModel</code>.
+     * 
+     * @return The value that defines an ASN.1 <code>ModelElement</code>
+     *         representation with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_MODEL_ELEMENT;
+    }
+
+    /**
+     * The definition of the ASN1_MODEL_ELEMENT type according to the rule
+     * defined for a <code>ModelElement</code>. It also defines a custom
+     * encoder/decoder for this type.
+     */
+    static {
+        ASN1_MODEL_ELEMENT = new ASN1Sequence(new ASN1Type[] {
+                ASN1Integer.getInstance(), // Type
+                ASN1Integer.getInstance() // Index
+                }) {
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents a <code>ModelElement</code>. It makes a completely
+             * new <code>ModelElement</code> with the information interpreted
+             * from the stream.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codificated information will be read from.
+             * @return A <code>ModelElement</code> filled with the information
+             *         read from the stream.
+             */
+            public Object getDecodedObject(BerInputStream in) {
+                Object values[] = (Object[]) in.content;
+
+                int type = new BigInteger((byte[]) values[0]).intValue();
+                int index = new BigInteger((byte[]) values[1]).intValue();
+
+                return new ModelElement(type, index);
+            }
+
+            /**
+             * Overrided method used to codify the information stored in an
+             * <code>ModelElement</code> into an array of bytes, according to
+             * its ASN.1 specification.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of a
+             *            <code>ModelElement</code>.
+             * 
+             * @param values
+             *            An array of objects where the model node's type and
+             *            index information will be stored, ready for
+             *            codification.
+             */
+            public void getValues(Object object, Object values[]) {
+                ModelElement me = (ModelElement) object;
+
+                values[0] = BigInteger.valueOf(me.getType()).toByteArray();
+                values[1] = BigInteger.valueOf(me.getIndex()).toByteArray();
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1ContentModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java?view=auto&rev=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java Tue Feb 13 06:02:55 2007
@@ -0,0 +1,338 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * It implements ASN.1 codification tools for
+ * <code>javax.swing.text.html.parser.DTD</code>. Given an <code>DTD</code>,
+ * its values are codified in ASN.1 according to the following rule:
+ * 
+ * <pre>
+ * BDTD ::= SEQUENCE {
+ *      Name UTF8String,    
+ *      Entity SET OF HTMLEntity,
+ *      Element SET OF HTMLElement
+ * }
+ * </pre>
+ * 
+ * The class can be used to obtain a byte array representing the codification of
+ * a <code>DTD</code>, as well as a <code>DTD</code> from a byte array
+ * (previously obtained codifying a <code>DTD</code>). In fact, it serves as a
+ * wrapper for the codification and the <code>DTD</code> itself.
+ * 
+ * @author Alejandro Sánchez
+ * @author Diego Raúl Mercado
+ * @author Alejandro Barturen 
+ * @version $Revision: 1.11 $
+ */
+class Asn1Dtd {
+
+    /**
+     * It stores the definition of a <code>DTD</code> as an ASN.1 valid type
+     * according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_DTD;
+
+    /**
+     * The definition of the ASN1_DTD type according to the rule defined for a
+     * <code>DTD</code>. It also defines a custom encoder/decoder for this
+     * type.
+     */
+    static {
+        ASN1_DTD = new ASN1Sequence(new ASN1Type[] { ASN1StringType.UTF8STRING, // NAME
+                new ASN1SetOf(Asn1Entity.getInstance()), // ENTITY
+                new ASN1SetOf(Asn1Element.getInstance()) // ELEMENT
+                }) {
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents a <code>DTD</code>. It makes a completely new
+             * <code>DTD</code> with the information interpreted from the
+             * stream.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codificated information will be read from.
+             * @return A <code>DTD</code> filled with the information read
+             *         from the stream.
+             */
+            protected Object getDecodedObject(BerInputStream in) {
+                Object values[] = (Object[]) in.content;
+                DTD dtd = new DTD("");
+                dtd.setReading(true);
+
+                // Name
+                dtd.name = String.valueOf(values[0]);
+
+                // Entities
+                List lstEntities = (ArrayList) values[1];
+                Entity entity;
+                for (int i=0; i<lstEntities.size(); i++) {
+                    entity = (Entity)lstEntities.get(i);
+                    dtd.defineEntity(entity.getName(), entity.type, entity
+                            .getData());
+                }
+
+                // Elements
+                List lstElements = (ArrayList) values[2];
+                Element element;
+                for (int i=0; i<lstElements.size(); i++) {
+                    element = (Element) lstElements.get(i);
+                    dtd.defineElement(element.getName(), element.getType(),
+                            element.omitStart(), element.omitEnd(), element
+                                    .getContent(), element.exclusions,
+                            element.inclusions, element.getAttributes());
+                }
+                return dtd;
+            }
+
+            /**
+             * Overrided method used to codify the information stored in a
+             * <code>DTD</code> into an array of bytes, according to its ASN.1
+             * specification.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of a <code>DTD</code>.
+             * 
+             * @param values
+             *            An array of objects where the dtd's name, entities and
+             *            elements information will be stored, ready for
+             *            codification.
+             */
+            protected void getValues(Object object, Object[] values) {
+                DTD dtd = (DTD) object;
+
+                // Name
+                values[0] = dtd.getName();
+
+                // Entities
+                ArrayList<Asn1Entity> lstEntity = new ArrayList<Asn1Entity>();
+                Iterator itr = dtd.entityHash.values().iterator();
+                while (itr.hasNext()) {
+                    lstEntity.add(new Asn1Entity((Entity) itr.next()));
+                }
+                values[1] = lstEntity;
+
+                // Elements
+                ArrayList<Asn1Element> lstElement = new ArrayList<Asn1Element>();
+                itr = dtd.elements.iterator();
+                while (itr.hasNext()) {
+                    lstElement.add(new Asn1Element((Element) itr.next()));
+                }
+                values[2] = lstElement;
+            }
+
+        };
+    }
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for a <code>DTD</code> with its encoder and decoder.
+     * 
+     * @return The value that defines an ASN.1 <code>DTD</code> representation
+     *         with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_DTD;
+    }
+
+    /**
+     * An internal copy of the <code>DTD</code> to be codified.
+     */
+    private DTD dtd;
+
+    /**
+     * An internal copy of the byte array which contains the codification of a
+     * <code>DTD</code>. From this variable, the information used to decodify
+     * a <code>DTD</code> is read from.
+     */
+    private byte[] encoded;
+    
+    
+    /**
+     * An internal copy of the {@link DTD} on which the encoded information
+     * will be extracted to. 
+     */
+    private DTD refDTD;
+
+    /**
+     * Constructs a new instance of a <code>Asn1Dtd</code> class from a byte
+     * array. The byte array received as argument can be later decodified into a
+     * <code>DTD</code>.
+     * 
+     * @param encoded
+     *            A byte array containing the codified information of a
+     *            <code>DTD</code>.
+     */
+    public Asn1Dtd(byte[] encoded) {
+        byte[] copy = new byte[encoded.length];
+        System.arraycopy(encoded, 0, copy, 0, encoded.length);
+        this.encoded = copy;
+    }
+
+    /**
+     * Constructs a new instance of an <code>Asn1Dtd</code> class from a
+     * <code>DTD</code>. The <code>DTD</code> received as argument can be
+     * then codified into a byte array.
+     * <p>
+     * The value received as argument should not be null. If so, a
+     * <code>NullPointerException</code> is thrown.
+     * 
+     * @param dtd
+     *            The <code>DTD</code> to be codified.
+     */
+    public Asn1Dtd(DTD dtd) {
+        if (dtd == null) {
+            throw new NullPointerException();
+        }
+        this.dtd = dtd;
+    }
+
+    /**
+     * Returns the representation of a <code>DTD</code> in ASN.1 codification.
+     * <p>
+     * If the <code >Asn1Dtd</code> object was created with a <code>DTD</code>,
+     * then the <code>DTD</code> is codified and returned as a byte array. On
+     * the other hand, if the instance was created using a byte array, then no
+     * codification process is made.
+     * 
+     * @return If at construction time a <code>DTD</code> was given, its
+     *         representation in ASN.1 codification. If at construction time a
+     *         byte array was given, a copy of the same array is returned.
+     */
+    public byte[] getEncoded() {
+        if (encoded == null) {
+            return ASN1_DTD.encode(dtd);
+        } else {
+            return encoded;
+        }
+    }
+
+    /**
+     * Returns the <code>DTD</code> obtained from the decodification of an
+     * ASN.1 codified byte array.
+     * <p>
+     * If the <code>Asn1Dtd</code> was created giving a <code>DTD</code>, a
+     * reference to the same <code>DTD</code> is obtained. Otherwise, the byte
+     * array given at construction time is decodificated into a new
+     * <code>DTD</code> object.
+     * 
+     * @return If at construction time a <code>DTD</code> was given, the same
+     *         <code>DTD</code> is returned. If at construction time a byte
+     *         array was given, a <code>DTD</code> constructed with the
+     *         information stored in that byte array is returned.
+     * @throws IOException
+     *             If the decodification process could not be carried out
+     *             properly.
+     */
+    public DTD getDTD(DTD refDTD) throws IOException {
+        this.refDTD = refDTD;
+        if (dtd == null) {
+            return restoreElements(updateInfo((DTD) ASN1_DTD.decode(encoded), refDTD));
+        } else {
+            return dtd;
+        }
+    }
+
+    /**
+     * Updates the information of the <code>Element</code>'s reference stored
+     * in the <code>ContentModel</code>s.
+     * <p>
+     * When the <code>ContentModel</code> is reconstructed from its ASN.1
+     * codification, no information about other <code>Element</code> is
+     * available at that moment, so information about them must be updated
+     * before returning the whole <code>DTD</code>.
+     * 
+     * @param dtd
+     *            The <code>DTD</code> whose
+     *            <code>Element<code>'s <code>ContentModel</code>s information
+     *            must be updated.
+     * @return The <code>DTD</code> with the information updated.
+     */
+    private DTD restoreElements(DTD dtd) {
+        ContentModel model = null;
+        Element tmpElem = null;
+        ArrayList<ContentModel> queue = new ArrayList<ContentModel>();
+        Enumeration itr = dtd.elements.elements();
+        Element e;
+        while (itr.hasMoreElements()) {
+            e = (Element)itr.nextElement();
+            model = e.getContent();
+            if (model != null) {
+                queue.add(model);
+                while (!queue.isEmpty()) {
+                    model = queue.remove(0);
+                    if (model.content instanceof ContentModel) {
+                        queue.add((ContentModel) model.content);
+                    } else {
+                        tmpElem = dtd.elements.get(
+                                ((Element)model.content).getIndex());
+                        model.content = tmpElem;
+                    }
+                    if (model.next != null) {
+                        queue.add(model.next);
+                    }
+                }
+            }
+        }
+        return dtd;
+    }
+    
+    
+    /**
+     * Updates the information of a {@link DTD} using the information stored in
+     * the previosly decoded {@link DTD}
+     * 
+     * @param readDTD the decoded {@link DTD}
+     * @param refDTD the {@link DTD} where the decoded information will be
+     *               updated.
+     * @return a reference to the updated {@link DTD}
+     */
+    private DTD updateInfo (DTD readDTD, DTD refDTD) {
+        refDTD.name = readDTD.name;
+        refDTD.entityHash = readDTD.entityHash;
+        
+        for (Element e : readDTD.elements) {
+            if (refDTD.elementHash.containsKey(e.getName())) {
+                Element modifyElem = refDTD.elementHash.get(e.getName());
+                modifyElem.updateElement(e.getIndex(),
+                        e.getName(), e.omitStart(), e.omitEnd(),
+                        e.exclusions, e.inclusions, e.getType(),
+                        e.getContent(), e.getAttributes(), e.data);
+            } else {
+                refDTD.elementHash.put(e.getName(), e);
+                refDTD.elements.add(e);
+            }
+        }
+        
+        return refDTD;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Dtd.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java?view=auto&rev=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java Tue Feb 13 06:02:55 2007
@@ -0,0 +1,378 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.harmony.security.asn1.ASN1Boolean;
+import org.apache.harmony.security.asn1.ASN1Implicit;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1SetOf;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * It implements ASN.1 codification tools for
+ * <code>javax.swing.text.html.parser.Element</code>. Given an
+ * <code>Element</code>, its values are codified in ASN.1 according to the
+ * following rule:
+ * 
+ * <pre>
+ *  HTMLElement ::= SEQUENCE {
+ *      index INTEGER, 
+ *      name UTF8String,
+ *      type INTEGER,
+ *      oStart BOOLEAN,
+ *      oEnd BOOLEAN,
+ *      exclusions [0] IMPLICIT SET OF INTEGER OPTIONAL,
+ *      inclusions [1] IMPLICIT SET OF INTEGER OPTIONAL,
+ *      attributes SET OF HTMLElementAttributes OPTIONAL,
+ *      contentModel HTMLContentModel
+ * }
+ * </pre>
+ * 
+ * The class can be used to obtain a byte array representing the codification of
+ * an <code>Element</code>, as well as an <code>Element</code> from a byte
+ * array (previously obtained codifying an <code>Element</code>). In fact, it
+ * serves as a wrapper for the codification and the <code>Element</code>
+ * itself.
+ * 
+ * @author Alejandro Sánchez
+ * @author Diego Raúl Mercado
+ * @author Alejandro Barturen
+ * @version $Revision: 1.6 $
+ */
+class Asn1Element {
+
+    /**
+     * It stores the definition of an <code>Element</code> as an ASN.1 valid
+     * type according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_ELEMENT;
+
+    /**
+     * The definition of the ASN1_ELEMENT type according to the rule defined for
+     * an <code>Element</code>. It also defines a custom encoder/decoder for
+     * this type.
+     */
+    static {
+        ASN1_ELEMENT = new ASN1Sequence(new ASN1Type[] {
+                ASN1Integer.getInstance(), // 0 Index
+                ASN1StringType.UTF8STRING, // 1 Name
+                ASN1Integer.getInstance(), // 2 Type
+                ASN1Boolean.getInstance(), // 3 OStart
+                ASN1Boolean.getInstance(), // 4 OEnd
+                new ASN1Implicit(0, new ASN1SetOf(ASN1Integer.getInstance())), // 5 Exclusions
+                new ASN1Implicit(1, new ASN1SetOf(ASN1Integer.getInstance())), // 6 Inclusions
+                new ASN1SetOf(Asn1Attributes.getInstance()), // 7 Attributes
+                Asn1ContentModel.getInstance() // 8 ContentModel
+        }) {
+
+            {
+                setOptional(5); // Exclusions Optional
+                setOptional(6); // Inclusions Optional
+                setOptional(7); // Attributes Optional
+            }
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents an <code>Element</code>. It makes a completely new
+             * <code>Element</code> with the information interpreted from the
+             * stream.
+             * <p>
+             * Note that the data field is ignored, and thus always set to null.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codificated information will be read from.
+             * @return An <code>Element</code> filled with the information
+             *         read from the stream.
+             */
+            public Object getDecodedObject(BerInputStream in) {
+                Object values[] = (Object[]) in.content;
+
+                int index = new BigInteger((byte[]) values[0]).intValue();
+                String name = (String) values[1];
+                int type = new BigInteger((byte[]) values[2]).intValue();
+                boolean oStart = ((Boolean) values[3]).booleanValue();
+                boolean oEnd = ((Boolean) values[4]).booleanValue();
+                BitSet exclusions = values[5] != null ? list2bitset(((List) values[5]))
+                        : null;
+                BitSet inclusions = values[6] != null ? list2bitset(((List) values[6]))
+                        : null;
+                AttributeList att = values[7] != null ? list2att((List) values[7])
+                        : null;
+                ContentModel model = values[8] == null ? null
+                        : ((ContentModel) values[8]);
+
+                // XXX data is always null, we ignore it
+                return new Element(index, name, oStart, oEnd, exclusions,
+                        inclusions, type, model, att, null);
+            }
+
+            /**
+             * Overrided method used to codify the information stored in an
+             * <code>Element</code> into an array of bytes, according to its
+             * ASN.1 specification.
+             * <p>
+             * Note that the <code>data</code> field is not taken in
+             * consideration.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of an
+             *            <code>Asn1Element</code> object which contains the
+             *            <code>Element</code> to be codified.
+             * 
+             * @param values
+             *            An array of objects where the element's index, name,
+             *            type, omitting properties, attribute list, element
+             *            inclusions and exclusions and its content model
+             *            information will be stored, ready for codification.
+             */
+            public void getValues(Object object, Object values[]) {
+                Asn1Element asn1 = (Asn1Element) object;
+
+                try {
+                    values[0] = BigInteger
+                            .valueOf(asn1.getElement().getIndex())
+                            .toByteArray(); // Index
+                    values[1] = asn1.getElement().getName(); // Name
+                    values[2] = BigInteger.valueOf(asn1.getElement().getType())
+                            .toByteArray(); // Type
+                    values[3] = Boolean.valueOf(asn1.getElement().omitStart()); // OStart
+                    values[4] = Boolean.valueOf(asn1.getElement().omitEnd()); // OEnd
+                    values[5] = asn1.getElement().exclusions != null ? // Exclusions
+                            bitset2list(asn1.getElement().exclusions) : new ArrayList();
+                    values[6] = asn1.getElement().inclusions != null ? // Inclusions
+                            bitset2list(asn1.getElement().inclusions) : new ArrayList();
+                    values[7] = asn1.getElement().getAttributes() != null ? // AttributeList
+                            att2list(asn1.getElement().getAttributes()) : null;
+                    values[8] = new Asn1ContentModel(asn1.getElement()
+                            .getContent());
+
+                } catch (IOException e) {
+                    throw new AssertionError(e); // this should not happen
+                }
+            }
+        };
+    }
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for an <code>Element</code> with its encoder and
+     * decoder.
+     * <p>
+     * Among other things, this method can be used to declare the types of new
+     * fields in other structures, as for example, in an <code>Asn1DTD</code>.
+     * 
+     * @return The value that defines an ASN.1 <code>Element</code>
+     *         representation with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_ELEMENT;
+    }
+
+    /**
+     * An internal copy of the <code>Element</code> to be codified.
+     */
+    private Element element;
+
+    /**
+     * An internal copy of the byte array which contains the codification of an
+     * <code>Element</code>. From this variable, the information used to
+     * decodify an <code>Element</code> is read from.
+     */
+    private byte[] encoded;
+
+    /**
+     * Constructs a new instance of an <code>Asn1Element</code> class from a
+     * byte array. The byte array received as argument can be later decodified
+     * into an <code>Element</code>.
+     * 
+     * @param encoded
+     *            A byte array containing the codified information of an
+     *            <code>Element</code>.
+     */
+    public Asn1Element(byte[] encoded) {
+        byte[] copy = new byte[encoded.length];
+        System.arraycopy(encoded, 0, copy, 0, copy.length);
+        this.encoded = copy;
+    }
+
+    /**
+     * Constructs a new instance of an <code>Asn1Element</code> class from an
+     * <code>Element</code>. The <code>Element</code> received as argument
+     * can be then codified into a byte array.
+     * <p>
+     * The value received as argument should not be null. If so, a
+     * <code>NullPointerException</code> is thrown.
+     * 
+     * @param element
+     *            The <code>Element</code> to be codified.
+     */
+    public Asn1Element(Element element) {
+        if (element == null) {
+            throw new NullPointerException();
+        }
+        this.element = element;
+    }
+
+    /**
+     * Returns the representation of an <code>Element</code> in ASN.1
+     * codification.
+     * <p>
+     * If the <code >Asn1Element</code> object was created with an
+     * <code>Element</code>, then the <code>Element</code> is codified and
+     * returned as a byte array. On the other hand, if the instance was created
+     * using a byte array, then no codification process is made.
+     * 
+     * @return If at construction time an <code>Element</code> was given, its
+     *         representation in ASN.1 codification. If at construction time a
+     *         byte array was given, a copy of the same array is returned.
+     */
+    public byte[] getEncoded() {
+        if (encoded == null) {
+            return ASN1_ELEMENT.encode(element);
+        } else {
+            return encoded;
+        }
+    }
+
+    /**
+     * Returns the <code>Element</code> obtained from the decodification of an
+     * ASN.1 codified byte array.
+     * <p>
+     * If the <code>Asn1Element</code> was created giving an
+     * <code>Element</code>, a reference to the same <code>Element</code>
+     * is obtained. Otherwise, the byte array given at construction time is
+     * decodificated into a new <code>Element</code> object.
+     * 
+     * @return If at construction time an <code>Element</code> was given, the
+     *         same <code>Element</code> is returned. If at construction time
+     *         a byte array was given, an <code>Element</code> constructed
+     *         with the information stored in that byte array is returned.
+     * @throws IOException
+     *             If the decodification process could not be carried out
+     *             properly.
+     */
+    public Element getElement() throws IOException {
+        if (element == null) {
+            return (Element) ASN1_ELEMENT.decode(encoded);
+        } else {
+            return element;
+        }
+    }
+
+    /**
+     * Converts an <code>AttributeList</code> into a <code>List</code>.
+     * 
+     * @param att
+     *            The <code>AttributeList</code> to be converted.
+     * @return A <code>List</code> with the same nodes that composed the
+     *         <code>AttributeList</code>, ordered by the
+     *         <code>AttributeList</code>'s next field.
+     */
+    private static List att2list(AttributeList att) {
+        ArrayList<Asn1Attributes> lstAttribute = new ArrayList<Asn1Attributes>();
+        for (AttributeList attNext = att; attNext != null; attNext = attNext
+                .getNext()) {
+            lstAttribute.add(new Asn1Attributes(attNext));
+        }
+        return lstAttribute;
+    }
+
+    /**
+     * Converts a <code>List</code> into an <code>AttributeList</code>
+     * 
+     * @param lst
+     *            The <code>List</code> to be converted.
+     * @return An <code>AttributeList</code> made of the nodes contained in
+     *         the <code>List</code> given as argument. The
+     *         <code>AttributeList</code>'s <code>next</code> field is set
+     *         according to <code>List</code> order.
+     */
+    private static AttributeList list2att(List lst) {
+        AttributeList attReturn;
+        attReturn = (AttributeList) lst.get(0);
+        for (int i = 0; i < lst.size(); i++) {
+            AttributeList first = (AttributeList) lst.get(i);
+            if (i != lst.size() - 1) { // last element ?
+                AttributeList second = (AttributeList) lst.get(i + 1);
+                first.next = second;
+            }
+        }
+        return attReturn;
+    }
+
+    /**
+     * Converts a <code>BitSet</code> into a <code>List</code> of
+     * <code>byte[]</code>. The elements that compose the <code>List</code>
+     * are actually byte arrays that represents the values of the
+     * <code>BitSet</code> which were set.
+     * <p>
+     * For example, if the <code>BitSet</code> has its <code>i</code>
+     * position set, then the <code>List</code> will contain as element the
+     * value: <code>BigInteger.valueOf(i).toByteArray()</code>.
+     * 
+     * @param bs
+     *            The <code>BitSet</code> to be converted.
+     * @return A <code>List</code> with each of the <code>BitSet</code>
+     *         values which were set, codified as a byte array.
+     */
+    private static List bitset2list(BitSet bs) {
+        ArrayList<byte[]> lst = new ArrayList<byte[]>();
+        for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
+            lst.add(BigInteger.valueOf(i).toByteArray());
+        }
+        return lst;
+    }
+
+    /**
+     * Converts a <code>List</code> of <code>byte[]</code> into a
+     * <code>BitSet</code>.
+     * <p>
+     * The byte array contained into the <code>List</code> are representations
+     * of the values which should be set in the <code>BitSet</code>.
+     * 
+     * @param lst
+     *            The <code>List</code> of <code>byte[]</code> to be
+     *            converted.
+     * @return A <code>BitSet</code> with the values specified by the nodes of
+     *         the <code>List</code>.
+     */
+    private static BitSet list2bitset(List lst) {
+        BitSet bs = null;
+        if (!lst.isEmpty()) { 
+            bs = new BitSet();
+        }
+        for (Iterator iter = lst.iterator(); iter.hasNext();) {
+            byte[] element = (byte[]) iter.next();
+            BigInteger bi = new BigInteger(element);
+            bs.set(bi.intValue());
+        }
+        return bs;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Element.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java?view=auto&rev=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java (added)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java Tue Feb 13 06:02:55 2007
@@ -0,0 +1,249 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+import org.apache.harmony.security.asn1.ASN1Boolean;
+import org.apache.harmony.security.asn1.ASN1Implicit;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * It implements ASN.1 codification tools for
+ * <code>javax.swing.text.html.parser.Entity</code>. Given an
+ * <code>Entity</code>, its values are codified in ASN.1 according to the
+ * following rule:
+ * 
+ * <pre>
+ * HTMLEntity ::= SEQUENCE {
+ *     name UTF8String,
+ *     value INTEGER,
+ *     general [0] IMPLICIT BOOLEAN DEFAULT FALSE,
+ *     parameter [1] IMPLICIT BOOLEAN DEFAULT FALSE,
+ *     data UTF8String
+ * }
+ * </pre>
+ * 
+ * The class can be used to obtain a byte array representing the codification of
+ * an <code>Entity</code>, as well as an <code>Entity</code> from a byte
+ * array (previously obtained codifying an <code>Entity</code>). In fact, it
+ * serves as a wrapper for the codification and the <code>Entity</code>
+ * itself.
+ * 
+ * @author Alejandro Sánchez
+ * @author Diego Raúl Mercado
+ * @author Alejandro Barturen 
+ * @version $Revision: 1.5 $
+ */
+class Asn1Entity {
+
+    /**
+     * It stores the definition of an <code>Entity</code> as an ASN.1 valid
+     * type according to the ASN.1 framework.
+     */
+    private static ASN1Type ASN1_ENTITY;
+
+    /**
+     * The definition of the ASN1_ENTITY type according to the rule defined for
+     * an <code>Entity</code>. It also defines a custom encoder/decoder for
+     * this type.
+     */
+    static {
+        ASN1_ENTITY = new ASN1Sequence(new ASN1Type[] {
+                ASN1StringType.UTF8STRING, // Name
+                ASN1Integer.getInstance(), // Value
+                new ASN1Implicit(0, ASN1Boolean.getInstance()), // General
+                new ASN1Implicit(1, ASN1Boolean.getInstance()), // Parameter
+                ASN1StringType.UTF8STRING // UTF8String
+                }) {
+
+            {
+                setDefault(Boolean.FALSE, 2); // GENERAL default value
+                setDefault(Boolean.FALSE, 3); // PARAMETER default value
+            }
+
+            /**
+             * Overrided method used to decodified the information that
+             * represents an <code>Entity</code>. It makes a completely new
+             * <code>Entity</code> with the information interpreted from the
+             * stream.
+             * 
+             * @param in
+             *            The <code>BerInputStream</code> where the
+             *            codificated information will be read from.
+             * @return An <code>Entity</code> filled with the information read
+             *         from the stream.
+             */
+            public Object getDecodedObject(BerInputStream in) {
+                Object values[] = (Object[]) in.content;
+
+                String name = (String) values[0];
+                int type = new BigInteger((byte[]) values[1]).intValue();
+                boolean general = ((Boolean) values[2]).booleanValue();
+                boolean parameter = ((Boolean) values[3]).booleanValue();
+                String data = (String) values[4];
+
+                return new Entity(name, type, data, general, parameter);
+            }
+
+            /**
+             * Overrided method used to codify the information stored in an
+             * <code>Entity</code> into an array of bytes, according to its
+             * ASN.1 specification.
+             * 
+             * @param object
+             *            The object where the information to be codified is
+             *            stored. It actually consists of an
+             *            <code>Asn1Entity</code> object which contains the
+             *            <code>Entity</code> to be codified.
+             * 
+             * @param values
+             *            An array of objects where the entity's name, type,
+             *            data, and isGeneral and isParameter information will
+             *            be stored, ready for codification.
+             */
+            public void getValues(Object object, Object values[]) {
+                Asn1Entity asn1 = (Asn1Entity) object;
+
+                try {
+                    values[0] = asn1.getEntity().getName();
+                    values[1] = BigInteger.valueOf(asn1.getEntity().getType())
+                            .toByteArray();
+                    values[2] = Boolean.valueOf(asn1.getEntity().isGeneral());
+                    values[3] = Boolean.valueOf(asn1.getEntity().isParameter());
+                    values[4] = String.valueOf(asn1.getEntity().getData());
+                } catch (IOException e) {
+                    throw new AssertionError(e); // this should not happen
+                }
+            }
+        };
+    }
+
+    /**
+     * It returns an <code>ASN1Type</code> value that contains the ASN.1
+     * codification rules for an <code>Entity</code> with its encoder and
+     * decoder.
+     * <p>
+     * Among other things, this method can be used to declare the types of new
+     * fields in other structures, as for example, in an <code>Asn1DTD</code>.
+     * 
+     * @return The value that defines an ASN.1 <code>Entity</code>
+     *         representation with its encoder/decoder.
+     */
+    static ASN1Type getInstance() {
+        return ASN1_ENTITY;
+    }
+
+    /**
+     * An internal copy of the <code>Entity</code> to be codified.
+     */
+    private Entity entity;
+
+    /**
+     * An internal copy of the byte array which contains the codification of an
+     * <code>Entity</code>. From this variable, the information used to
+     * decodify an <code>Entity</code> is read from.
+     */
+    private byte[] encoded;
+
+    /**
+     * Constructs a new instance of an <code>Asn1Entity</code> class from a
+     * byte array. The byte array received as argument can be later decodified
+     * into an <code>Entity</code>.
+     * 
+     * @param encoded
+     *            A byte array containing the codified information of an
+     *            <code>Entity</code>.
+     */
+    public Asn1Entity(byte[] encoded) {
+        byte[] copy = new byte[encoded.length];
+        System.arraycopy(encoded, 0, copy, 0, copy.length);
+        this.encoded = copy;
+    }
+
+    /**
+     * Constructs a new instance of an <code>Asn1Entity</code> class from an
+     * <code>Entity</code>. The <code>Entity</code> received as argument
+     * can be then codified into a byte array.
+     * <p>
+     * The value received as argument should not be null. If so, a
+     * <code>NullPointerException</code> is thrown.
+     * 
+     * @param entity
+     *            The <code>Entity</code> to be codified.
+     */
+    public Asn1Entity(Entity entity) {
+        if (entity == null) {
+            throw new NullPointerException();
+        }
+        this.entity = entity;
+    }
+
+    /**
+     * Returns the representation of an <code>Entity</code> in ASN.1
+     * codification.
+     * <p>
+     * If the <code >Asn1Entity</code> object was created with an
+     * <code>Entity</code>, then the <code>Entity</code> is codified and
+     * returned as a byte array. On the other hand, if the instance was created
+     * using a byte array, then no codification process is made.
+     * 
+     * @return If at construction time an <code>Entity</code> was given, its
+     *         representation in ASN.1 codification. If at construction time a
+     *         byte array was given, a copy of the same array is returned.
+     */
+    public byte[] getEncoded() {
+        if (encoded == null) {
+            return ASN1_ENTITY.encode(entity);
+        } else {
+            byte[] copy = new byte[encoded.length];
+            System.arraycopy(encoded, 0, copy, 0, copy.length);
+            return copy;
+        }
+    }
+
+    /**
+     * Returns the <code>Entity</code> obtained from the decodification of an
+     * ASN.1 codified byte array.
+     * <p>
+     * If the <code>Asn1Entity</code> was created giving an
+     * <code>Entity</code>, a reference to the same <code>Entity</code> is
+     * obtained. Otherwise, the byte array given at construction time is
+     * decodificated into a new <code>Entity</code> object.
+     * 
+     * @return If at construction time an <code>Entity</code> was given, the
+     *         same <code>Entity</code> is returned. If at construction time a
+     *         byte array was given, an <code>Entity</code> constructed with
+     *         the information stored in that byte array is returned.
+     * @throws IOException
+     *             If the decodification process could not be carried out
+     *             properly.
+     */
+    public Entity getEntity() throws IOException {
+        if (entity == null) {
+            return (Entity) ASN1_ENTITY.decode(encoded);
+        } else {
+            return entity;
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Asn1Entity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/AttributeList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/AttributeList.java?view=diff&rev=507006&r1=507005&r2=507006
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/AttributeList.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/AttributeList.java Tue Feb 13 06:02:55 2007
@@ -16,7 +16,7 @@
  */
 /**
  * @author Evgeniya G. Maenkova
- * @version $Revision$
+ * @version $Revision: 1.8 $
  */
 package javax.swing.text.html.parser;
 
@@ -29,19 +29,20 @@
 
     public int type;
 
-    public Vector<?> values;
+    public Vector values;
 
     public int modifier;
 
     public String value;
 
     public AttributeList next;
+    
     //TODO It need check type FIXED, IMPLIED, REQUIRED?
     public AttributeList(final String name,
                          final int type,
                          final int modifier,
                          final String value,
-                         final Vector<?> values,
+                         final Vector values,
                          final AttributeList next) {
         this.name = name;
         this.type = type;
@@ -53,7 +54,7 @@
 
     public static String type2name(final int type) {
         init();
-        return type < names.length ? names[type] : null;
+        return type >= 0 && type < names.length ? names[type] : null;
     }
 
     public static int name2type(final String name) {
@@ -131,7 +132,7 @@
         return value;
     }
 
-    public Enumeration<?> getValues() {
+    public Enumeration getValues() {
         // avoids a NullPointerException if values is null (same as RI)
         return values == null ? null : values.elements();
     }



Mime
View raw message