示例#1
0
 /**
  * Copy constructor
  * @param orig The object to copy
  */
 public RtfParserState(RtfParserState orig)
 {
     this.properties       = orig.properties;
     this.parserState      = orig.parserState;
     this.tokeniserState   = orig.tokeniserState;
     this.groupHandler     = null;
     this.destination      = orig.destination;
     this.text             = new StringBuilder();
     this.ctrlWordHandlers = new Stack();
     this.destination      = orig.destination;
     this.newGroup         = false;
 }
示例#2
0
 /**
 * Copy constructor
 * @param orig The object to copy
 */
 public RtfParserState(RtfParserState orig)
 {
     this.properties = orig.properties;
     this.parserState = orig.parserState;
     this.tokeniserState = orig.tokeniserState;
     this.groupHandler = null;
     this.destination = orig.destination;
     this.text = new StringBuilder();
     this.ctrlWordHandlers = new Stack();
     this.destination = orig.destination;
     this.newGroup = false;
 }
示例#3
0
        /**
        * Handles close group tokens. (})
        *
        * @return errOK if ok, other if an error occurred.
        */
        public int HandleCloseGroup()
        {
            int result = errOK;
            this.closeGroupCount++; // stats

            if (this.GetTokeniserState() != TOKENISER_SKIP_GROUP) {
                if (debugParser) {
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: HandleCloseGroup()");
                    if (this.lastCtrlWordParam != null)
                        RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: LastCtrlWord=" + this.lastCtrlWordParam.ctrlWord);
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: grouplevel=" + groupLevel.ToString());
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: destination=" + this.GetCurrentDestination().ToString());
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "");
                }
                RtfDestination dest = this.GetCurrentDestination();
                bool handled = false;

                if (dest != null) {
                    handled = dest.HandleCloseGroup();
                }
                if (debugParser) {
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: After dest.HandleCloseGroup(); handled = " + handled.ToString());
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "");
                }
            }

            if (this.stackState.Count >0 ) {
                this.currentState = (RtfParserState)this.stackState.Pop();
            } else {
                result = errStackUnderflow;
            }

            this.docGroupLevel--;
            this.groupLevel--;

            if (this.GetTokeniserState() == TOKENISER_SKIP_GROUP && this.groupLevel < this.skipGroupLevel) {
                this.SetTokeniserState(TOKENISER_NORMAL);
            }

            return result;
        }
示例#4
0
        /* *****************************************
        *   DOCUMENT CONTROL METHODS
        *
        *   Handles -
        *   handleOpenGroup:    Open groups     - '{'
        *   handleCloseGroup:   Close groups    - '}'
        *   handleCtrlWord:     Ctrl Words      - '\...'
        *   handleCharacter:    Characters      - Plain Text, etc.
        *
        */
        /**
        * Handles open group tokens. ({)
        *
        * @return errOK if ok, other if an error occurred.
        */
        public int HandleOpenGroup()
        {
            int result = errOK;
            this.openGroupCount++;  // stats
            this.groupLevel++;      // current group level in tokeniser
            this.docGroupLevel++;   // current group level in document
            if (this.GetTokeniserState() == TOKENISER_SKIP_GROUP) {
                this.groupSkippedCount++;
            }

            RtfDestination dest = this.GetCurrentDestination();
            bool handled = false;

            if (dest != null) {
                if (debugParser) {
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: before dest.HandleOpeningSubGroup()");
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: destination=" + dest.ToString());
                }
                handled = dest.HandleOpeningSubGroup();
                if (debugParser) {
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: after dest.HandleOpeningSubGroup()");
                }
            }

            this.stackState.Push(this.currentState);
            this.currentState = new RtfParserState(this.currentState);
            // do not set this true until after the state is pushed
            // otherwise it inserts a { where one does not belong.
            this.currentState.newGroup = true;
            dest = this.GetCurrentDestination();

            if (debugParser) {
                RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: HandleOpenGroup()");
                if (this.lastCtrlWordParam != null)
                    RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: LastCtrlWord=" + this.lastCtrlWordParam.ctrlWord);
                RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: grouplevel=" + groupLevel.ToString());
                RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: destination=" + dest.ToString());
            }

            if (dest != null) {
                handled = dest.HandleOpenGroup();
            }

            if (debugParser) {
                RtfParser.OutputDebug(this.rtfDoc, groupLevel, "DEBUG: after dest.HandleOpenGroup(); handled=" + handled.ToString());
            }

            return result;
        }
示例#5
0
        /**
        * Initialize the parser object values.
        *
        * @param type Type of conversion or import
        * @param rtfDoc The <code>RtfDocument</code>
        * @param readerIn The input stream
        * @param doc The iText <code>Document</code>
        */
        private void Init(int type, RtfDocument rtfDoc, Stream readerIn, Legacy.Text.Document doc, IElement elem)
        {
            Init_stats();
            // initialize reader to a PushbackReader
            this.pbReader = Init_Reader(readerIn);

            this.conversionType = type;
            this.rtfDoc = rtfDoc;
            this.document = doc;
            this.elem = elem;
            this.currentState = new RtfParserState();
            this.stackState = new Stack();
            this.SetParserState(PARSER_STARTSTOP);
            this.importMgr = new RtfImportMgr(this.rtfDoc, this.document);

            // get destination Mgr
            this.destinationMgr = RtfDestinationMgr.GetInstance(this);
            // set the parser
            RtfDestinationMgr.SetParser(this);

            // DEBUG INFO for timing and memory usage of RtfCtrlWordMgr object
            // create multiple new RtfCtrlWordMgr objects to check timing and memory usage
            //      System.Gc();
            //      long endTime = 0;
            //      Date endDate = null;
            //      long endFree = 0;
            //      DecimalFormat df = new DecimalFormat("#,##0");
            //      Date startDate = new Date();
            //      long startTime = System.CurrentTimeMillis();
            //      long startFree = Runtime.GetRuntime().FreeMemory();
            //      System.out.Println("1:");

            this.rtfKeywordMgr = new RtfCtrlWordMgr(this, this.pbReader);/////////DO NOT COMMENT OUT THIS LINE ///////////

            foreach (object listener in listeners) {
                if (listener is IRtfCtrlWordListener) {
                    this.rtfKeywordMgr.AddRtfCtrlWordListener((IRtfCtrlWordListener)listener);
                }
            }
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
            //
            //      System.Gc();
            //      System.out.Println("2:");
            //      startDate = new Date();
            //      startTime = System.CurrentTimeMillis();
            //      startFree = Runtime.GetRuntime().FreeMemory();
            //      RtfCtrlWordMgr rtfKeywordMgr2 = new RtfCtrlWordMgr(this, this.pbReader);
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
            //
            //      System.Gc();
            //      System.out.Println("3:");
            //      startDate = new Date();
            //      startTime = System.CurrentTimeMillis();
            //      startFree = Runtime.GetRuntime().FreeMemory();
            //      RtfCtrlWordMgr rtfKeywordMgr3 = new RtfCtrlWordMgr(this, this.pbReader);
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
            //
            //      System.Gc();
            //      System.out.Println("4:");
            //      startDate = new Date();
            //      startTime = System.CurrentTimeMillis();
            //      startFree = Runtime.GetRuntime().FreeMemory();
            //      RtfCtrlWordMgr rtfKeywordMgr4 = new RtfCtrlWordMgr(this, this.pbReader);
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
            //
            //      System.Gc();
            //      System.out.Println("5:");
            //      startDate = new Date();
            //      startTime = System.CurrentTimeMillis();
            //      startFree = Runtime.GetRuntime().FreeMemory();
            //      RtfCtrlWordMgr rtfKeywordMgr5 = new RtfCtrlWordMgr(this, this.pbReader);
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
            //      System.Gc();
            //      System.out.Println("At ed:");
            //      startDate = new Date();
            //      startTime = System.CurrentTimeMillis();
            //      startFree = Runtime.GetRuntime().FreeMemory();
            //      //RtfCtrlWordMgr rtfKeywordMgr6 = new RtfCtrlWordMgr(this, this.pbReader);
            //      endFree = Runtime.GetRuntime().FreeMemory();
            //      endTime = System.CurrentTimeMillis();
            //      endDate = new Date();
            //      System.out.Println("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
            //      System.out.Println("RtfCtrlWordMgr end date  : " + endDate.ToLocaleString());
            //      System.out.Println("  Elapsed time    : " + Long.ToString(endTime - startTime) + " milliseconds.");
            //      System.out.Println("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
            //      System.out.Println("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
            //      System.out.Println("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
        }