Ejemplo n.º 1
0
        /**
         * Dispatch the token to the correct control word handling object.
         *
         * @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
         * @param groupLevel The current document group parsing level
         * @return errOK if ok, otherwise an error code.
         */
        private int DispatchKeyword(RtfCtrlWordData ctrlWordData, int groupLevel)
        {
            int result = RtfParser.errOK;

            if (ctrlWordData != null)
            {
                RtfCtrlWordHandler ctrlWord = ctrlWordMap.GetCtrlWordHandler(ctrlWordData.ctrlWord);
                if (ctrlWord != null)
                {
                    ctrlWord.HandleControlword(ctrlWordData);
                    if (debug && debugFound)
                    {
                        Console.Out.WriteLine("Keyword found:" +
                                              " New:" + ctrlWordData.ctrlWord +
                                              " Param:" + ctrlWordData.param +
                                              " bParam=" + ctrlWordData.hasParam.ToString());
                    }
                }
                else
                {
                    result = RtfParser.errCtrlWordNotFound;
                    //result = RtfParser2.errAssertion;
                    if (debug && debugNotFound)
                    {
                        Console.Out.WriteLine("Keyword unknown:" +
                                              " New:" + ctrlWordData.ctrlWord +
                                              " Param:" + ctrlWordData.param +
                                              " bParam=" + ctrlWordData.hasParam.ToString());
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
 private bool AfterCtrlWord(RtfCtrlWordData ctrlWordData)
 {
     foreach (IRtfCtrlWordListener listener in listeners)
     {
         listener.AfterCtrlWord(ctrlWordData);
     }
     return(true);
 }
Ejemplo n.º 3
0
        /**
         * Internal to control word manager class.
         *
         * @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
         * @param groupLevel The current document group parsing level
         * @return errOK if ok, otherwise an error code.
         */
        public int HandleKeyword(RtfCtrlWordData ctrlWordData, int groupLevel)
        {
            //TODO: May be used for event handling.
            int result = RtfParser.errOK;

            // Call before handler event here
            BeforeCtrlWord(ctrlWordData);

            result = DispatchKeyword(ctrlWordData, groupLevel);

            // call after handler event here
            AfterCtrlWord(ctrlWordData);

            return(result);
        }
Ejemplo n.º 4
0
        /**
         * The primary control word handler method.
         * Called by the parser once it has a control word and parameter if applicable.
         *
         * @param ctrlWordDataIn
         *      The control word and associated parameter if applicable.
         * @return
         *      <code>true</code> or <code>false</code> if the control word was handled.
         * @since 2.0.8
         */
        public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn)
        {
            bool result = false;

            this.ctrlWordData = ctrlWordDataIn;
            RtfDestination dest    = null;
            bool           handled = false;

            this.ctrlWordData.prefix         = this.ctrlWordPrefix;
            this.ctrlWordData.suffix         = this.ctrlWordSuffix;
            this.ctrlWordData.newGroup       = this.rtfParser.GetState().newGroup;
            this.ctrlWordData.ctrlWordType   = this.ctrlWordType;
            this.ctrlWordData.specialHandler = this.specialHandler;

            if (!this.ctrlWordData.hasParam && this.passDefaultParameterValue)
            {
                this.ctrlWordData.hasParam = true;
                this.ctrlWordData.param    = this.defaultParameterValue.ToString();
            }

            if (debug)
            {
                PrintDebug("handleKeyword: [" + this.ctrlWordData.ctrlWord + "] param=" + ctrlWordDataIn.param);
                RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug Start: " + this.ctrlWordData.ctrlWord + " ");
            }
            if (this.ctrlWordData.ctrlWord.Equals("*"))
            {
                return(true);
            }

            if (!BeforeControlWord())
            {
                return(true);
            }

            switch (this.ctrlWordType)
            {
            case RtfCtrlWordType.FLAG:
            case RtfCtrlWordType.TOGGLE:
            case RtfCtrlWordType.VALUE:
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    handled = dest.HandleControlWord(this.ctrlWordData);
                }
                break;

            case RtfCtrlWordType.SYMBOL:
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    String data = null;
                    // if doing an import, then put the control word in the output stream through the character handler
                    if (this.rtfParser.IsImport())
                    {
                        data = this.ctrlWordPrefix + this.ctrlWordData.ctrlWord + this.ctrlWordSuffix;
                    }
                    if (this.rtfParser.IsConvert())
                    {
                        data = this.specialHandler;
                    }

                    // If there is a substitute character, process the character.
                    // If no substitute character, then provide special handling in the destination for the ctrl word.
                    if (data != null)
                    {
                        foreach (char cc in data.ToCharArray())
                        {
                            handled = dest.HandleCharacter((int)cc);
                        }
                    }
                    else
                    {
                        handled = dest.HandleControlWord(this.ctrlWordData);
                    }
                }
                break;

            case RtfCtrlWordType.DESTINATION_EX:
            case RtfCtrlWordType.DESTINATION:
                // set the destination
                int x = 0;
                if (this.ctrlWord == "shppict" || this.ctrlWord == "nonshppict")
                {
                    x++;
                }
                handled = this.rtfParser.SetCurrentDestination(this.ctrlWord);
                // let destination handle the ctrl word now.
                dest = this.rtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    if (dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT)
                    {
                        handled = dest.HandleControlWord(this.ctrlWordData);
                    }
                    else
                    {
                        this.rtfParser.SetTokeniserState(dest.GetNewTokeniserState());
                    }
                }
                break;
            }

            AfterControlWord();

            if (debug)
            {
                RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug End: " + this.ctrlWordData.ctrlWord + " ");
            }

            return(result);
        }