Example #1
0
        /// <summary> Test whether the input i is unique;
        /// if not, insert into the hash table and return false
        /// otherwise, return true
        /// </summary>
        public bool isUnique(int i)
        {
            int temp = i & mask1;

            if (temp > maxDepth)
            {
                maxDepth = temp;
            }
            if (storage[temp] == null)
            {
                storage[temp] = new FastIntBuffer(pageSizeE);
                storage[temp].append(i);
                return(true);
            }
            else
            {
                int size = storage[temp].size_Renamed_Field;
                for (int j = 0; j < size; j++)
                {
                    if (i == storage[temp].intAt(j))
                    {
                        return(false);
                    }
                }
                storage[temp].append(i);
                return(true);
            }
        }
Example #2
0
		/// <summary> Test whether the input i is unique; 
		/// if not, insert into the hash table and return false
		/// otherwise, return true
		/// </summary>
		public bool isUnique(int i)
		{
			int temp = i & mask1;
			if (temp > maxDepth)
			{
				maxDepth = temp;
			}
			if (storage[temp] == null)
			{
				storage[temp] = new FastIntBuffer(pageSizeE);
				storage[temp].append(i);
				return true;
			}
			else
			{
				int size = storage[temp].size();
				for (int j = 0; j < size; j++)
				{
					if (i == storage[temp].intAt(j))
					{
						return false;
					}
				}
				storage[temp].append(i);
				return true;
			}
		}
Example #3
0
        /// <summary> constructor</summary>
        /// <param name="l">
        /// </param>
        /// <param name="o">
        /// </param>
        /// <param name="r">
        /// </param>
        public BinaryExpr(Expr l, int o, Expr r)
        {
            op = o;
            left = l;
            right = r;
            fib1 = null;
            switch (op)
            {

                case ADD:
                case SUB:
                case MULT:
                case DIV:
                case MOD: isNumerical_Renamed_Field = true; isBoolean_Renamed_Field = false; break;

                case OR:
                case AND:
                case EQ:
                case NE:
                case LE:
                case GE:
                case LT:
                case GT: isNumerical_Renamed_Field = false; isBoolean_Renamed_Field = true;
                    goto default;

                default:
                    break;

            }
        }
Example #4
0
 protected internal ElementFragmentNs(VTDNav vn1, long l1, FastIntBuffer fib1, int len)
 {
     vn = vn1;
     l = l1;
     fib = fib1;
     stLen = len;
 }
Example #5
0
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
        /// <summary> constructor</summary>
        /// <param name="l">
        /// </param>
        /// <param name="o">
        /// </param>
        /// <param name="r">
        /// </param>
        public BinaryExpr(Expr l, int o, Expr r)
        {
            op    = o;
            left  = l;
            right = r;
            fib1  = null;
            switch (op)
            {
            case ADD:
            case SUB:
            case MULT:
            case DIV:
            case MOD: isNumerical_Renamed_Field = true; isBoolean_Renamed_Field = false; break;

            case OR:
            case AND:
            case EQ:
            case NE:
            case LE:
            case GE:
            case LT:
            case GT: isNumerical_Renamed_Field = false; isBoolean_Renamed_Field = true;
                goto default;

            default:
                break;
            }
            compType = computeCompType();
        }
Example #6
0
 internal static byte[] ws; // a few byte patterns for white space and '='
 protected internal ElementFragmentNs(VTDNav vn1, long l1, FastIntBuffer fib1, int len)
 {
     vn    = vn1;
     l     = l1;
     fib   = fib1;
     stLen = len;
 }
Example #7
0
 public CachedExpr(Expr e1)
 {
     e = e1;
     cached = false;
     ens = null;
     count = 0;
     vn1 = null;
 }
Example #8
0
 public CachedExpr(Expr e1)
 {
     e      = e1;
     cached = false;
     ens    = null;
     count  = 0;
     vn1    = null;
 }
Example #9
0
        private bool compNodeSetNodeSet(Expr left, Expr right, VTDNav vn, int op)
        {
            int i, i1 = 0, stackSize, s1;

            try
            {
                if (fib1 == null)
                {
                    fib1 = new FastIntBuffer(BUF_SZ_EXP);
                }
                vn.push2();
                stackSize = vn.contextStack2.size;
                while ((i = left.evalNodeSet(vn)) != -1)
                {
                    i1 = getStringVal(vn, i);
                    if (i1 != -1)
                    {
                        fib1.append(i1);
                    }
                }
                left.reset(vn);
                vn.contextStack2.size = stackSize;
                vn.pop2();
                vn.push2();
                stackSize = vn.contextStack2.size;
                while ((i = right.evalNodeSet(vn)) != -1)
                {
                    i1 = getStringVal(vn, i);
                    if (i1 != -1)
                    {
                        s1 = fib1.size_Renamed_Field;
                        for (int k = 0; k < s1; k++)
                        {
                            bool b = compareVV(fib1.intAt(k), vn, i1, op);
                            if (b)
                            {
                                fib1.size_Renamed_Field = 0;
                                vn.contextStack2.size   = stackSize;
                                vn.pop2();
                                right.reset(vn);
                                return(true);
                            }
                        }
                    }
                }
                vn.contextStack2.size = stackSize;
                vn.pop2();
                right.reset(vn);
                fib1.size_Renamed_Field = 0;
                return(false);
            }
            catch (Exception e)
            {
                fib1.size_Renamed_Field = 0;
                throw new System.SystemException("Undefined behavior");
            }
        }
Example #10
0
 /// <summary> Use this constructor for delayed binding to VTDNav
 /// which allows the reuse of XPath expression
 ///
 /// </summary>
 public AutoPilot()
 {
     name = null;
     //vn = v;
     //depth = v.getCurrentDepth();
     iter_type      = UNDEFINED;        // not defined
     ft             = true;
     size           = 0;
     special        = false;
     xpe            = null;
     symbolHash     = new System.Collections.Hashtable();
     fib            = null;
     cachingEnabled = true;
 }
Example #11
0
        public override int evalNodeSet(VTDNav vn)
        {
            // TODO Auto-generated method stub
            int i = -1;

            if (cached)
            {
                if (count < ens.size_Renamed_Field)
                {
                    i = ens.intAt(count);
                    vn.recoverNode(i);
                    count++;
                    return(i);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                cached = true;

                if (ens == null)
                {
                    ens = new FastIntBuffer(8);//page size 64
                }
                //record node set
                while ((i = e.evalNodeSet(vn)) != -1)
                {
                    ens.append(i);
                }
                e.reset(vn);
                if (ens.size_Renamed_Field > 0)
                {
                    i = ens.intAt(count);//count should be zero
                    vn.recoverNode(i);
                    count++;
                    return(i);
                }
                else
                {
                    return(-1);
                }
            }
        }
Example #12
0
 /// <summary> AutoPilot constructor comment.</summary>
 /// <exception cref="ArgumentException">If the VTDNav object is null
 /// </exception>
 public AutoPilot(VTDNav v)
 {
     if (v == null)
     {
         throw new System.ArgumentException(" instance of VTDNav can't be null ");
     }
     name = null;
     vn   = v;
     //depth = v.getCurrentDepth();
     iter_type      = UNDEFINED;        // not defined
     ft             = true;
     size           = 0;
     special        = false;
     xpe            = null;
     symbolHash     = new System.Collections.Hashtable();
     fib            = null;
     cachingEnabled = true;
     //p = null;
 }
Example #13
0
/// <summary>
///
/// </summary>
/// <param name="en"></param>
        protected internal void selectNameSpace(String en)
        {
            if (en == null)
            {
                throw new ArgumentException("namespace name can't be null");
            }
            iter_type = NAME_SPACE;
            ft        = true;
            size      = vn.getTokenCount();
            name      = en;
            if (!en.Equals("*"))
            {
                name2 = "xmlns:" + en;
            }
            if (fib == null)
            {
                fib = new FastIntBuffer(4);
            }
            else
            {
                fib.size_Renamed_Field = 0;
            }
        }
Example #14
0
        /// <summary> This is for debugging purpose</summary>
        /// <param name="fib">
        /// </param>

        public void sampleState(FastIntBuffer fib)
        {
            //		for(int i=0;i<context.)
            //			context[i] = -1;
            //		fib.append(context);
            if (context[0] >= 1)
                fib.append(l1index);


            if (context[0] >= 2)
            {
                fib.append(l2index);
                fib.append(l2lower);
                fib.append(l2upper);
            }

            if (context[0] >= 3)
            {
                fib.append(l3index);
                fib.append(l3lower);
                fib.append(l3upper);
            }
        }
Example #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ElementFragmentNs getElementFragmentNs()
        {
            if (this.ns == false)
                throw new NavException("getElementFragmentNS can only be called ");

            FastIntBuffer fib = new FastIntBuffer(3); // init size 8

            //fill the fib with integer 
            // first get the list of name space nodes 
            int[] ia = context;
            int d = ia[0]; // -1 for document node, 0 for root element;
            int c = getCurrentIndex2();


            int len = (c == 0 || c == rootIndex) ? 0 :
                (getTokenLength(c) & 0xffff); // get the length of qualified node

            // put the neighboring ATTR_NS nodes into the array
            // and record the total # of them	     
            int i = 0;
            int count = 0;
            if (d > 0)
            { // depth > 0 every node except document and root element
                int k = getCurrentIndex2() + 1;
                if (k < this.vtdSize)
                {
                    while (k < this.vtdSize)
                    {
                        int type = this.getTokenType(k);
                        if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                        {
                            if (type == VTDNav.TOKEN_ATTR_NS)
                            {
                                fib.append(k);
                                //System.out.println(" ns name ==>" + toString(k));
                            }
                            k += 2;
                        }
                        else
                            break;
                        
                        //type = this.getTokenType(k);
                    }
                }
                count = fib.size_Renamed_Field;
                d--;
                while (d >= 0)
                {
                    // then search for ns node in the vinicity of the ancestor nodes
                    if (d > 0)
                    {
                        // starting point
                        k = ia[d] + 1;
                    }
                    else
                    {
                        // starting point
                        k = this.rootIndex + 1;
                    }
                    if (k < this.vtdSize)
                    {
                        while (k < this.vtdSize)
                        {
                            int type = this.getTokenType(k);
                            if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                            {
                                bool unique = true;
                                if (type == VTDNav.TOKEN_ATTR_NS)
                                {
                                    for (int z = 0; z < fib.size_Renamed_Field; z++)
                                    {
                                        //System.out.println("fib size ==> "+fib.size_Renamed_Field);
                                        //if (fib.size_Renamed_Field == 4) ;
                                        if (matchTokens(fib.intAt(z), this, k))
                                        {
                                            unique = false;
                                            break;
                                        }

                                    }
                                    if (unique)
                                        fib.append(k);
                                }
                            }
                            k += 2;
                            //type = this.getTokenType(k);
                        }
                    }
                    d--;
                }
                // System.out.println("count ===> "+count);
                // then restore the name space node by shifting the array
                int newSz = fib.size_Renamed_Field - count;
                for (i = 0; i < newSz; i++)
                {
                    fib.modifyEntry(i, fib.intAt(i + count));
                }
                fib.size_Renamed_Field = newSz;
            }

            long l = getElementFragment();
            return new ElementFragmentNs(this, l, fib, len);
        }
Example #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="indexBuffer"></param>
        /// <param name="countBuffer"></param>
        public void fillXPathString(FastIntBuffer indexBuffer, FastIntBuffer countBuffer)
        {
            //int count = 0;
            int index = getCurrentIndex() + 1;
            int tokenType, depth, t = 0, length, i = 0;
            int dp = context[0];
            //int size = vtdBuffer.size;
            // store all text tokens underneath the current element node
            while (index < vtdSize)
            {
                tokenType = getTokenType(index);
                depth = getTokenDepth(index);
                if (depth < dp ||
                        (depth == dp && tokenType == VTDNav.TOKEN_STARTING_TAG))
                {
                    break;
                }

                if (tokenType == VTDNav.TOKEN_CHARACTER_DATA
                        || tokenType == VTDNav.TOKEN_CDATA_VAL)
                {
                    length = getTokenLength(index);
                    t += length;
                    fib.append(index);
                    if (length > VTDGen.MAX_TOKEN_LENGTH)
                    {
                        while (length > VTDGen.MAX_TOKEN_LENGTH)
                        {
                            length -= VTDGen.MAX_TOKEN_LENGTH;
                            i++;
                        }
                        index += i + 1;
                    }
                    else
                        index++;
                    continue;
                    //
                }
                else if (tokenType == VTDNav.TOKEN_ATTR_NAME
                      || tokenType == VTDNav.TOKEN_ATTR_NS)
                {
                    index = index + 2;
                    continue;
                }
                index++;
            }
        }
Example #17
0
 /// <summary>
 /// The constructor that binds the instance of VTDNav
 /// </summary>
 /// <param name="vn1"></param>
 public NodeRecorder(VTDNav vn1)
 {
     bind(vn1);
     size = position = count = 0;
     fib  = new FastIntBuffer(BUF_SZ_EXPO);
 }
Example #18
0
        /// <summary> This is for debugging purpose</summary>
        /// <param name="fib">
        /// </param>

        public virtual void sampleState(FastIntBuffer fib)
        {
            //		for(int i=0;i<context.)
            //			context[i] = -1;
            //		fib.append(context);
            for (int i = 0; i <= context[0]; i++)
                fib.append(context[i]);
            if (atTerminal) fib.append(LN);
            if (context[0] >= 1)
                fib.append(l1index);


            if (context[0] >= 2)
            {
                fib.append(l2index);
                fib.append(l2lower);
                fib.append(l2upper);
            }

            if (context[0] >= 3)
            {
                fib.append(l3index);
                fib.append(l3lower);
                fib.append(l3upper);
            }
        }
Example #19
0
 /// <summary>
 /// The constructor that binds the instance of VTDNav
 /// </summary>
 /// <param name="vn1"></param>
 public NodeRecorder(VTDNav vn1)
 {
     bind(vn1);
     size = position = count = 0;
     fib = new FastIntBuffer(BUF_SZ_EXPO);
 }
Example #20
0
        // lengnth of the XML document (in byte))
        /**
         * Initialize the VTD navigation object.
         *
         * @param RootIndex
         *            int
         * @param maxDepth
         *            int
         * @param encoding
         *            int
         * @param NS
         *            boolean
         * @param x
         *            byte[]
         * @param vtd
         *            com.ximpleware.ILongBuffer
         * @param l1
         *            com.ximpleware.ILongBuffer
         * @param l2
         *            com.ximpleware.ILongBuffer
         * @param l3
         *            com.ximpleware.IIntBuffer
         * @param so
         *            int starting offset of the document(in byte)
         * @param length
         *            int length of the document (in byte)
         */
        protected internal VTDNav_L5(
            int RootIndex,
            int enc,
            bool NS,
            int depth,
            IByteBuffer x,
            FastLongBuffer vtd,
            FastLongBuffer l1,
            FastLongBuffer l2,
            FastLongBuffer l3,
            FastLongBuffer l4,
            FastIntBuffer l5,
            int so, // start offset of the starting offset(in byte)
            int length)
        {
            //super();
            // initialize all buffers
            if (l1 == null
                || l2 == null
                || l3 == null
                || vtd == null
                || x == null
                || depth < 0
                || RootIndex < 0 //|| encoding <= FORMAT_UTF8
                //|| encoding >= FORMAT_ISO_8859_1
                || so < 0
                || length < 0)
            {
                throw new System.ArgumentException();
            }

            count = 0;
            l1Buffer = l1;
            l2Buffer = l2;
            l3Buffer = l3;
            l4Buffer = l4;
            l5Buffer = l5;
            vtdBuffer = vtd;
            XMLDoc = x;

            encoding = enc;
            //System.out.println("encoding " + encoding);
            rootIndex = RootIndex;
            nestingLevel = depth + 1;
            ns = NS; // namespace aware or not
            if (ns == false)
                MASK_TOKEN_OFFSET = 0x000000007fffffffL; // this allows xml size to
            // be 2GB
            else // if there is no namespace
                MASK_TOKEN_OFFSET = 0x000000003fffffffL;

            atTerminal = false; //this variable will only change value during XPath
            // eval

            // initialize the context object
            this.context = new int[nestingLevel];
            //depth value is the first entry in the context because root is
            // singular.
            context[0] = 0;
            //set the value to zero
            for (int i = 1; i < nestingLevel; i++)
            {
                context[i] = -1;
            }
            //currentOffset = 0;
            //contextStack = new ContextBuffer(1024, nestingLevel + 7);
            contextStack = new ContextBuffer(10, nestingLevel + 15);
            contextStack2 = new ContextBuffer(10, nestingLevel + 15);
            stackTemp = new int[nestingLevel + 15];

            // initial state of LC variables
            l1index = l2index = l3index = l4index = l5index = -1;
            l2lower = l3lower = l4lower = l5lower = -1;
            l2upper = l3upper = l4upper = l5upper = -1;
            docOffset = so;
            docLen = length;
            //System.out.println("offset " + offset + " length " + length);
            //printL2Buffer();
            vtdSize = vtd.size_Renamed_Field;
            //writeOffsetAdjustment = false;
            //recentNS = -1;
            name = null;
            nameIndex = -1;
            localName = null;
            localNameIndex = -1;
            fib = new FastIntBuffer(5); // page size is 32 ints
            shallowDepth = false;
            maxLCDepthPlusOne = 6;
        }
Example #21
0
        public override int evalNodeSet(VTDNav vn)
        {
            // TODO Auto-generated method stub
            int i = -1;
            if (cached)
            {
                if (count < ens.size_Renamed_Field)
                {
                    i = ens.intAt(count);
                    vn.recoverNode(i);
                    count++;
                    return i;
                }
                else
                    return -1;

            }
            else
            {
                cached = true;

                if (ens == null)
                {
                    ens = new FastIntBuffer(8);//page size 64
                }
                //record node set
                while ((i = e.evalNodeSet(vn)) != -1)
                {
                    ens.append(i);
                }
                e.reset(vn);
                if (ens.size_Renamed_Field > 0)
                {
                    i = ens.intAt(count);//count should be zero
                    vn.recoverNode(i);
                    count++;
                    return i;
                }
                else
                    return -1;
            }
        }
Example #22
0
		/// <summary> Use this constructor for delayed binding to VTDNav
		/// which allows the reuse of XPath expression 
		/// 
		/// </summary>
		public AutoPilot()
		{
			name = null;
			//vn = v;
			//depth = v.getCurrentDepth();
			iter_type = UNDEFINED; // not defined
			ft = true;
			size = 0;
			special = false;
			xpe = null;
            symbolHash = new System.Collections.Hashtable();
            fib = null;
            cachingEnabled = true;
		}
Example #23
0
        /// <summary> Set the XMLDoc container. Also set the offset and len of the document 
        /// with respect to the container.
        /// </summary>
        /// <param name="ba">byte[]
        /// </param>
        /// <param name="os">int (in byte)
        /// </param>
        /// <param name="len">int (in byte)
        /// </param>
        public void setDoc(byte[] ba, int os, int len)
        {
            int a;
            br = false;
            depth = -1;
            increment = 1;
            BOM_detected = false;
            must_utf_8 = false;
            ch = ch_temp = 0;
            temp_offset = 0;
            XMLDoc = ba;
            docOffset = offset = os;
            docLen = len;
            endOffset = os + len;
            last_l1_index = last_l2_index = last_l3_index = last_depth = 0;
            int i1 = 7, i2 = 9, i3 = 11;
            if (docLen <= 1024)
            {
                //a = 1024; //set the floor
                a = 6; i1 = 5; i2 = 5; i3 = 5;
            }
            else if (docLen <= 4096)
            {
                a = 7; i1 = 6; i2 = 6; i3 = 6;
            }
            else if (docLen <= 1024 * 16)
            {
                a = 8; i1 = 7; i2 = 7; i3 = 7;
            }
            else if (docLen <= 1024 * 16 * 4)
            {
                //a = 2048;
                a = 11;
            }
            else if (docLen <= 1024 * 256)
            {
                //a = 1024 * 4;
                a = 12;
            }
            else if (docLen <= (1 << 26))
            {
                //a = 1 << 15;
                i1 = i2 = i3 = 12;
                a = 15;
            }
            else if (docLen <= (1 << 30))
            {
                //a = 1 << 15;
                i1 = i2 = i3 = 13;
                a = 19;
            }
            else
            {
                i1 = i2 = i3 = 16;
                a = 23;
            }

            VTDBuffer = new FastLongBuffer(a, len >> (a + 1));
            l1Buffer = new FastLongBuffer(i1);
            l2Buffer = new FastLongBuffer(i2);
            l3Buffer = new FastIntBuffer(i3);
            ;
        }
Example #24
0
        /// <summary> Clear internal states so VTDGEn can process the next file.</summary>
        public void clear()
        {
            if (br == false)
            {
                VTDBuffer = null;
                l1Buffer = null;
                l2Buffer = null;
                l3Buffer = null;
            }
            XMLDoc = null;
            offset = temp_offset = 0;
            last_depth = last_l1_index = last_l2_index = 0;
            rootIndex = 0;

            depth = -1;
            increment = 1;
            BOM_detected = false;
            must_utf_8 = false;
            ch = ch_temp = 0;
        }
Example #25
0
        /// <summary> Set the XMLDoc container. Also set the offset and len of the document
        /// with respect to the container.
        /// 
        /// </summary>
        /// <param name="ba">byte[]
        /// </param>
        /// <param name="os">int (in byte)
        /// </param>
        /// <param name="len">int (in byte)
        /// </param>
        public void setDoc(byte[] ba, int os, int len)
        {

            int a;
            br = false;
            depth = -1;
            increment = 1;
            BOM_detected = false;
            must_utf_8 = false;
            ch = ch_temp = 0;
            temp_offset = 0;
            XMLDoc = ba;
            docOffset = offset = os;
            docLen = len;
            endOffset = os + len;
            last_l1_index = last_l2_index = last_l3_index = last_depth = 0;
            if (docLen <= 1024)
            {
                //a = 1024; //set the floor
                a = 7;
            }
            else if (docLen <= 4096 * 2)
            {
                a = 9;
            }
            else if (docLen <= 1024 * 16 * 4)
            {
                //a = 2048;
                a = 10;
            }
            else if (docLen <= 1024 * 256)
            {
                //a = 1024 * 4;
                a = 12;
            }
            else
            {
                //a = 1 << 15;
                a = 15;
            }
            //		VTDBuffer = new FastLongBuffer(a);
            //		l1Buffer = new FastLongBuffer(128);
            //		l2Buffer = new FastLongBuffer(512);
            //		l3Buffer = new FastIntBuffer(2048);

            VTDBuffer = new FastLongBuffer(a, len >> (a + 1));
            l1Buffer = new FastLongBuffer(7);
            l2Buffer = new FastLongBuffer(9);
            l3Buffer = new FastIntBuffer(11);
        }
Example #26
0
        /// <summary>
        /// This function is called within VTDGen and 
        /// VTDNav's writeIndex
        /// </summary>
        /// <param name="version"></param>
        /// <param name="encodingType"></param>
        /// <param name="ns"></param>
        /// <param name="byteOrder"></param>
        /// <param name="nestDepth"></param>
        /// <param name="LCLevel"></param>
        /// <param name="rootIndex"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="docOffset"></param>
        /// <param name="docLen"></param>
        /// <param name="vtdBuffer"></param>
        /// <param name="l1Buffer"></param>
        /// <param name="l2Buffer"></param>
        /// <param name="l3Buffer"></param>
        /// <param name="os"></param>
        /// <returns></returns>
        public static void writeIndex_L3(byte version,
            int encodingType,
            bool ns,
            bool byteOrder,
            int nestDepth,
            int LCLevel,
            int rootIndex,
            byte[] xmlDoc,
            int docOffset,
            int docLen,
            FastLongBuffer vtdBuffer,
            FastLongBuffer l1Buffer,
            FastLongBuffer l2Buffer,
            FastIntBuffer l3Buffer,
            System.IO.Stream os)
        {
            if (xmlDoc == null
                || docLen <= 0
                || vtdBuffer == null
                || l1Buffer == null
                || l2Buffer == null
                || l3Buffer == null
                || LCLevel != 3)
            {
                throw new System.ArgumentException("Invalid argument for writeIndex ");
            }
            if (vtdBuffer.size_Renamed_Field == 0)
            {
                throw new IndexWriteException("VTDBuffer can't be zero length");
            }
            int i;

            System.IO.BinaryWriter dos = new System.IO.BinaryWriter(os);
            // first 4 bytes
            byte[] ba = new byte[4];
            ba[0] = (byte)version; // version # is 1 
            ba[1] = (byte)encodingType;
            if (BitConverter.IsLittleEndian == false)
                ba[2] = (byte)(ns ? 0xe0 : 0xa0); // big endien
            else
                ba[2] = (byte)(ns ? 0xc0 : 0x80);
            ba[3] = (byte)nestDepth;
            dos.Write(ba);
            // second 4 bytes
            ba[0] = 0;
            ba[1] = 4;
            ba[2] = (byte)((rootIndex & 0xff00) >> 8);
            ba[3] = (byte)(rootIndex & 0xff);
            dos.Write(ba);
            // 2 reserved 32-bit words set to zero
            ba[1] = ba[2] = ba[3] = 0;
            dos.Write(ba);
            dos.Write(ba);
            dos.Write(ba);
            dos.Write(ba);
            // write XML doc in bytes
            dos.Write((long)docLen);
            dos.Write(xmlDoc, docOffset, docLen);
            //dos.Write(xmlDoc, docOffset, docLen);
            // zero padding to make it integer multiple of 64 bits
            if ((docLen & 0x07) != 0)
            {
                int t = (((docLen >> 3) + 1) << 3) - docLen;
                for (; t > 0; t--)
                    dos.Write((System.Byte)0);
            }
            // write VTD

            dos.Write((long)vtdBuffer.size_Renamed_Field);
            if (docOffset != 0)
            {
                for (i = 0; i < vtdBuffer.size_Renamed_Field; i++)
                {
                    dos.Write(adjust(vtdBuffer.longAt(i), -docOffset));
                }
            }
            else
            {
                for (i = 0; i < vtdBuffer.size_Renamed_Field; i++)
                {
                    dos.Write(vtdBuffer.longAt(i));
                }
            }
            // write L1 
            dos.Write((long)l1Buffer.size_Renamed_Field);
            for (i = 0; i < l1Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l1Buffer.longAt(i));
            }
            // write L2
            dos.Write((long)l2Buffer.size_Renamed_Field);
            for (i = 0; i < l2Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l2Buffer.longAt(i));
            }
            // write L3
            dos.Write((long)l3Buffer.size_Renamed_Field);
            for (i = 0; i < l3Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l3Buffer.intAt(i));
            }
            // pad zero if # of l3 entry is odd
            if ((l3Buffer.size_Renamed_Field & 1) != 0)
                dos.Write(0);
            dos.Close();
        }
Example #27
0
        /// <summary>
        /// This function is called within VTDGen and
        /// VTDNav's writeIndex
        /// </summary>
        /// <param name="version"></param>
        /// <param name="encodingType"></param>
        /// <param name="ns"></param>
        /// <param name="byteOrder"></param>
        /// <param name="nestDepth"></param>
        /// <param name="LCLevel"></param>
        /// <param name="rootIndex"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="docOffset"></param>
        /// <param name="docLen"></param>
        /// <param name="vtdBuffer"></param>
        /// <param name="l1Buffer"></param>
        /// <param name="l2Buffer"></param>
        /// <param name="l3Buffer"></param>
        /// <param name="os"></param>
        /// <returns></returns>
        public static void writeIndex_L3(byte version,
                                         int encodingType,
                                         bool ns,
                                         bool byteOrder,
                                         int nestDepth,
                                         int LCLevel,
                                         int rootIndex,
                                         byte[] xmlDoc,
                                         int docOffset,
                                         int docLen,
                                         FastLongBuffer vtdBuffer,
                                         FastLongBuffer l1Buffer,
                                         FastLongBuffer l2Buffer,
                                         FastIntBuffer l3Buffer,
                                         System.IO.Stream os)
        {
            if (xmlDoc == null ||
                docLen <= 0 ||
                vtdBuffer == null ||
                l1Buffer == null ||
                l2Buffer == null ||
                l3Buffer == null ||
                LCLevel != 3)
            {
                throw new System.ArgumentException("Invalid argument for writeIndex ");
            }
            if (vtdBuffer.size_Renamed_Field == 0)
            {
                throw new IndexWriteException("VTDBuffer can't be zero length");
            }
            int i;

            System.IO.BinaryWriter dos = new System.IO.BinaryWriter(os);
            // first 4 bytes
            byte[] ba = new byte[4];
            ba[0] = (byte)version; // version # is 1
            ba[1] = (byte)encodingType;
            if (BitConverter.IsLittleEndian == false)
            {
                ba[2] = (byte)(ns ? 0xe0 : 0xa0); // big endien
            }
            else
            {
                ba[2] = (byte)(ns ? 0xc0 : 0x80);
            }
            ba[3] = (byte)nestDepth;
            dos.Write(ba);
            // second 4 bytes
            ba[0] = 0;
            ba[1] = 4;
            ba[2] = (byte)((rootIndex & 0xff00) >> 8);
            ba[3] = (byte)(rootIndex & 0xff);
            dos.Write(ba);
            // 2 reserved 32-bit words set to zero
            ba[1] = ba[2] = ba[3] = 0;
            dos.Write(ba);
            dos.Write(ba);
            dos.Write(ba);
            dos.Write(ba);
            // write XML doc in bytes
            dos.Write((long)docLen);
            dos.Write(xmlDoc, docOffset, docLen);
            //dos.Write(xmlDoc, docOffset, docLen);
            // zero padding to make it integer multiple of 64 bits
            if ((docLen & 0x07) != 0)
            {
                int t = (((docLen >> 3) + 1) << 3) - docLen;
                for (; t > 0; t--)
                {
                    dos.Write((System.Byte) 0);
                }
            }
            // write VTD

            dos.Write((long)vtdBuffer.size_Renamed_Field);
            if (docOffset != 0)
            {
                for (i = 0; i < vtdBuffer.size_Renamed_Field; i++)
                {
                    dos.Write(adjust(vtdBuffer.longAt(i), -docOffset));
                }
            }
            else
            {
                for (i = 0; i < vtdBuffer.size_Renamed_Field; i++)
                {
                    dos.Write(vtdBuffer.longAt(i));
                }
            }
            // write L1
            dos.Write((long)l1Buffer.size_Renamed_Field);
            for (i = 0; i < l1Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l1Buffer.longAt(i));
            }
            // write L2
            dos.Write((long)l2Buffer.size_Renamed_Field);
            for (i = 0; i < l2Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l2Buffer.longAt(i));
            }
            // write L3
            dos.Write((long)l3Buffer.size_Renamed_Field);
            for (i = 0; i < l3Buffer.size_Renamed_Field; i++)
            {
                dos.Write(l3Buffer.intAt(i));
            }
            // pad zero if # of l3 entry is odd
            if ((l3Buffer.size_Renamed_Field & 1) != 0)
            {
                dos.Write(0);
            }
            dos.Close();
        }
Example #28
0
        int count; // in # of ints

        /// <summary>
        /// Argumentless constructor
        /// </summary>
        public NodeRecorder()
        {
            vn = null;
            size = position = 0;
            fib = new FastIntBuffer(BUF_SZ_EXPO);
        }
Example #29
0
        int count;                        // in # of ints

        /// <summary>
        /// Argumentless constructor
        /// </summary>
        public NodeRecorder()
        {
            vn   = null;
            size = position = count = 0;
            fib  = new FastIntBuffer(BUF_SZ_EXPO);
        }
Example #30
0
        /**
         * This is for debugging purpose
         *
         * @param fib
         */
        public override void sampleState(FastIntBuffer fib)
        {
            //		for(int i=0;i<context.)
            //			context[i] = -1;
            //		fib.append(context);
            if (context[0] >= 1)
                fib.append(l1index);
            else return;

            if (context[0] >= 2)
            {
                fib.append(l2index);
                fib.append(l2lower);
                fib.append(l2upper);
            }
            else return;

            if (context[0] >= 3)
            {
                fib.append(l3index);
                fib.append(l3lower);
                fib.append(l3upper);
            }
            else return;

            if (context[0] >= 4)
            {
                fib.append(l4index);
                fib.append(l4lower);
                fib.append(l4upper);
            }
            else return;

            if (context[0] >= 5)
            {
                fib.append(l5index);
                fib.append(l5lower);
                fib.append(l5upper);
            }
        }
Example #31
0
 /// <summary> Clear internal states so VTDGEn can process the next file.</summary>
 public void clear()
 {
     if (br == false)
     {
         VTDBuffer = null;
         l1Buffer = null;
         l2Buffer = null;
         l3Buffer = null;
         _l3Buffer = null;
         _l4Buffer = null;
         _l5Buffer = null;
     }
     XMLDoc = null;
     offset = temp_offset = 0;
     last_depth = last_l1_index = last_l2_index = last_l3_index = last_l4_index = 0;
     rootIndex = 0;
     depth = -1;
     increment = 1;
     BOM_detected = false;
     must_utf_8 = false;
     ch = ch_temp = 0;
     r = new UTF8Reader(this);
     nsBuffer1.size_Renamed_Field = 0;
     nsBuffer2.size_Renamed_Field = 0;
     nsBuffer3.size_Renamed_Field = 0;
     currentElementRecord = 0;
 }
Example #32
0
        /// <summary> Initialize the VTD navigation object.</summary>
        /// <param name="RootIndex">int
        /// </param>
        /// <param name="maxDepth">int
        /// </param>
        /// <param name="encoding">int
        /// </param>
        /// <param name="NS"> boolean
        /// </param>
        /// <param name="x">byte[]
        /// </param>
        /// <param name="vtd">com.ximpleware.ILongBuffer
        /// </param>
        /// <param name="l1">com.ximpleware.ILongBuffer
        /// </param>
        /// <param name="l2">com.ximpleware.ILongBuffer
        /// </param>
        /// <param name="l3">com.ximpleware.IIntBuffer
        /// </param>
        /// <param name="so">int  starting offset of the document(in byte)
        /// </param>
        /// <param name="length">int length of the document (in byte)
        /// </param>
        protected internal VTDNav(int RootIndex, int enc, bool NS, int depth, IByteBuffer x, FastLongBuffer vtd, FastLongBuffer l1, FastLongBuffer l2, FastIntBuffer l3, int so, int length)
        {
            // initialize all buffers
            if (l1 == null || l2 == null || l3 == null || vtd == null || x == null || depth < 0 || RootIndex < 0 || so < 0 || length < 0)
            {
                throw new System.ArgumentException();
            }
            count = 0;
            l1Buffer = l1;
            l2Buffer = l2;
            l3Buffer = l3;
            vtdBuffer = vtd;
            XMLDoc = x;

            encoding = enc;
            //System.out.println("encoding " + encoding);
            rootIndex = RootIndex;
            nestingLevel = depth + 1;
            ns = NS; // namespace aware or not
            if (ns == false)
                MASK_TOKEN_OFFSET = 0x000000007fffffff;
            // this allows xml size to be 2GB 
            // if there is no namespace
            else
                MASK_TOKEN_OFFSET = 0x000000003fffffff;


            atTerminal = false; //this variable will only change value during XPath eval

            // initialize the context object
            context = new int[nestingLevel];
            //depth value is the first entry in the context because root is singular.
            context[0] = 0;
            //set the value to zero
            for (int i = 1; i < nestingLevel; i++)
            {
                context[i] = -1;
            }
            // currentOffset = 0;
            //contextStack = new ContextBuffer(1024, nestingLevel + 7);
            contextStack = new ContextBuffer(10, nestingLevel + 9);
            contextStack2 = new ContextBuffer(10, nestingLevel + 9);
            stackTemp = new int[nestingLevel + 9];

            // initial state of LC variables
            l1index = l2index = l3index = -1;
            l2lower = l3lower = -1;
            l2upper = l3upper = -1;
            docOffset = so;
            docLen = length;
            //System.out.println("offset " + offset + "  length " + length);
            //printL2Buffer();
            vtdSize = vtd.size_Renamed_Field;
            name = null;
            nameIndex = -1;
            localName = null;
            localNameIndex = -1;
            fib = new FastIntBuffer(5);
            shallowDepth = true;
            //recentNS = -1;
        }
Example #33
0
 private bool compNodeSetNodeSet(Expr left, Expr right, VTDNav vn, int op)
 {
     int i, i1 = 0, stackSize, s1;
     try
     {
         if (fib1 == null)
             fib1 = new FastIntBuffer(BUF_SZ_EXP);
         vn.push2();
         stackSize = vn.contextStack2.size;
         while ((i = left.evalNodeSet(vn)) != -1)
         {
             i1 = getStringVal(vn, i);
             if (i1 != -1)
                 fib1.append(i1);
         }
         left.reset(vn);
         vn.contextStack2.size = stackSize;
         vn.pop2();
         vn.push2();
         stackSize = vn.contextStack2.size;
         while ((i = right.evalNodeSet(vn)) != -1)
         {
             i1 = getStringVal(vn, i);
             if (i1 != -1)
             {
                 s1 = fib1.size_Renamed_Field;
                 for (int k = 0; k < s1; k++)
                 {
                     bool b = compareVV(fib1.intAt(k), vn, i1, op);
                     if (b)
                     {
                         fib1.size_Renamed_Field=0;
                         vn.contextStack2.size = stackSize;
                         vn.pop2();
                         right.reset(vn);
                         return true;
                     }
                 }
             }
         }
         vn.contextStack2.size = stackSize;
         vn.pop2();
         right.reset(vn);
         fib1.size_Renamed_Field=0;
         return false;
     }
     catch (Exception e)
     {
         fib1.size_Renamed_Field=0;
         throw new System.SystemException("Undefined behavior");
     }
 }
Example #34
0
		/// <summary> AutoPilot constructor comment.</summary>
		/// <exception cref="ArgumentException">If the VTDNav object is null 
		/// </exception>
		public AutoPilot(VTDNav v)
		{
			if (v == null)
				throw new System.ArgumentException(" instance of VTDNav can't be null ");
			name = null;
			vn = v;
			//depth = v.getCurrentDepth();
			iter_type = UNDEFINED; // not defined
			ft = true;
			size = 0;
			special = false;
			xpe = null;
            symbolHash = new System.Collections.Hashtable();
            fib = null;
            cachingEnabled= true;
			//p = null;       
		}
Example #35
0
        /// <summary> The buffer-reuse version of setDoc
        /// The concept is to reuse LC and VTD buffer for 
        /// XML parsing, instead of allocating every time
        /// </summary>
        /// <param name="ba">byte[]
        /// </param>
        /// <param name="os">int (in byte)
        /// </param>
        /// <param name="len">int (in byte)
        /// 
        /// </param>
        public void setDoc_BR(byte[] ba, int os, int len)
        {
            int a;
            br = true;
            depth = -1;
            increment = 1;
            BOM_detected = false;
            must_utf_8 = false;
            ch = ch_temp = 0;
            temp_offset = 0;
            XMLDoc = ba;
            docOffset = offset = os;
            docLen = len;
            endOffset = os + len;
            last_l1_index = last_l2_index = last_l3_index = last_depth = 0;
            //int i1 = 7, i2 = 9, i3 = 11;
            currentElementRecord = 0;
            nsBuffer1.size_Renamed_Field = 0;
            nsBuffer2.size_Renamed_Field = 0;
            nsBuffer3.size_Renamed_Field = 0;
            r = new UTF8Reader(this);
            if (shallowDepth)
            {
                int i1 = 7, i2 = 9, i3 = 11;
                if (docLen <= 1024)
                {
                    // a = 1024; //set the floor
                    a = 6;
                    i1 = 5;
                    i2 = 5;
                    i3 = 5;
                }
                else if (docLen <= 4096)
                {
                    a = 7;
                    i1 = 6;
                    i2 = 6;
                    i3 = 6;
                }
                else if (docLen <= 1024 * 16)
                {
                    a = 8;
                    i1 = 7;
                    i2 = 7;
                    i3 = 7;
                }
                else if (docLen <= 1024 * 16 * 4)
                {
                    // a = 2048;
                    a = 11;
                }
                else if (docLen <= 1024 * 256)
                {
                    // a = 1024 * 4;
                    a = 12;
                }
                else
                {
                    // a = 1 << 15;
                    a = 15;
                }

                VTDBuffer = new FastLongBuffer(a, len >> (a + 1));
                l1Buffer = new FastLongBuffer(i1);
                l2Buffer = new FastLongBuffer(i2);
                l3Buffer = new FastIntBuffer(i3);
            }
            else
            {

                int i1 = 7, i2 = 9, i3 = 11, i4 = 11, i5 = 11;
                if (docLen <= 1024)
                {
                    // a = 1024; //set the floor
                    a = 6;
                    i1 = 5;
                    i2 = 5;
                    i3 = 5;
                    i4 = 5;
                    i5 = 5;
                }
                else if (docLen <= 4096)
                {
                    a = 7;
                    i1 = 6;
                    i2 = 6;
                    i3 = 6;
                    i4 = 6;
                    i5 = 6;
                }
                else if (docLen <= 1024 * 16)
                {
                    a = 8;
                    i1 = 7;
                    i2 = 7;
                    i3 = 7;
                    i4 = 7;
                    i5 = 7;
                }
                else if (docLen <= 1024 * 16 * 4)
                {
                    // a = 2048;
                    a = 11;
                    i2 = 8;
                    i3 = 8;
                    i4 = 8;
                    i5 = 8;
                }
                else if (docLen <= 1024 * 256)
                {
                    // a = 1024 * 4;
                    a = 12;
                    i1 = 8;
                    i2 = 9;
                    i3 = 9;
                    i4 = 9;
                    i5 = 9;
                }
                else
                {
                    // a = 1 << 15;
                    a = 15;
                }

                VTDBuffer = new FastLongBuffer(a, len >> (a + 1));
                l1Buffer = new FastLongBuffer(i1);
                l2Buffer = new FastLongBuffer(i2);
                _l3Buffer = new FastLongBuffer(i3);
                _l4Buffer = new FastLongBuffer(i4);
                _l5Buffer = new FastIntBuffer(i5);
            }
        }
Example #36
0
/// <summary>
/// 
/// </summary>
/// <param name="en"></param>
        protected internal void selectNameSpace(String en)
        {
            if (en == null)
                throw new ArgumentException("namespace name can't be null");
            iter_type = NAME_SPACE;
            ft = true;
            size = vn.getTokenCount();
            name = en;
            if (!en.Equals("*"))
                name2 = "xmlns:" + en;
            if (fib == null)
                fib = new FastIntBuffer(4);
            else
                fib.size_Renamed_Field=0;
        }
Example #37
0
        private bool ws; // to prserve whitespace or not, default to false

        #endregion Fields

        #region Constructors

        /// <summary> VTDGen constructor method.</summary>
        public VTDGen()
        {
            attr_name_array = new long[ATTR_NAME_ARRAY_SIZE];
            prefixed_attr_name_array = new long[ATTR_NAME_ARRAY_SIZE];
            prefix_URL_array = new int[ATTR_NAME_ARRAY_SIZE];
            tag_stack = new long[TAG_STACK_SIZE];
            //scratch_buffer = new int[10];
            VTDDepth = 0;
            LcDepth = 3;
            br = false;
            e = new EOFException("permature EOF reached, XML document incomplete");
            ws = false;
            nsBuffer1 = new FastIntBuffer(4);
            nsBuffer2 = new FastLongBuffer(4);
            nsBuffer3 = new FastLongBuffer(4);
            currentElementRecord = 0;
            singleByteEncoding = true;
            shallowDepth = true;
        }