Пример #1
0
        public static bool AddDestination(String destination, Object[] args)
        {
            if (destinations.ContainsKey(destination))
            {
                return(true);
            }

            String thisClass = "iTextSharp.text.rtf.parser.destinations." + (String)args[0];

            if (thisClass.IndexOf("RtfDestinationNull") >= 0)
            {
                destinations[destination] = RtfDestinationNull.GetInstance();
                return(true);
            }

            Type value = null;

            try {
                value = Type.GetType(thisClass);
            } catch {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }

            RtfDestination c = null;

            if (destinationObjects.ContainsKey(value.Name))
            {
                c = (RtfDestination)destinationObjects[value.Name];
            }
            else
            {
                try {
                    c = (RtfDestination)value.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null).Invoke(null);
                } catch  {
                    return(false);
                }
            }

            c.SetParser(rtfParser);

            if (value.Equals(typeof(RtfDestinationInfo)))
            {
                ((RtfDestinationInfo)c).SetElementName(destination);
            }

            if (value.Equals(typeof(RtfDestinationStylesheetTable)))
            {
                ((RtfDestinationStylesheetTable)c).SetElementName(destination);
                ((RtfDestinationStylesheetTable)c).SetType((String)args[1]);
            }

            destinations[destination]      = c;
            destinationObjects[value.Name] = c;
            return(true);
        }
        /// <summary>
        /// listener methods
        /// </summary>
        /// <summary>
        /// Removes a  RtfDestinationListener  from the appropriate  RtfDestination .
        /// the RtfCtrlWordListener that has to be removed.
        /// </summary>
        /// <param name="destination">the destination string for the listener</param>
        /// <param name="listener"></param>
        public static bool RemoveListener(string destination, IRtfDestinationListener listener)
        {
            RtfDestination dest = GetDestination(destination);

            if (dest != null)
            {
                return(dest.RemoveListener(listener));
            }
            return(false);
        }
Пример #3
0
        public static RtfDestination GetDestination(String destination)
        {
            RtfDestination dest = null;

            if (destinations.ContainsKey(destination))
            {
                dest = (RtfDestination)destinations[destination];
            }
            else
            {
                if (ignoreUnknownDestinations)
                {
                    dest = (RtfDestination)destinations[DESTINATION_NULL];
                }
                else
                {
                    dest = (RtfDestination)destinations[DESTINATION_DOCUMENT];
                }
            }
            dest.SetParser(RtfDestinationMgr.rtfParser);
            return(dest);
        }
Пример #4
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;
 }
Пример #5
0
 /**
 * Default constructor
 *
 */
 public RtfParserState()
 {
     this.text = new StringBuilder();
     this.ctrlWordHandlers = new Stack();
     this.properties = new RtfProperty();
     this.destination = RtfDestinationNull.GetInstance();
     this.newGroup = false;
 }
        public static bool AddDestination(string destination, object[] args)
        {
            if (_destinations.ContainsKey(destination))
            {
                return(true);
            }

            string thisClass = $"iTextSharp.text.rtf.parser.destinations.{(string) args[0]}";

            if (thisClass.IndexOf("RtfDestinationNull", StringComparison.Ordinal) >= 0)
            {
                _destinations[destination] = RtfDestinationNull.GetInstance();
                return(true);
            }

            Type value = null;

            try
            {
                value = Type.GetType(thisClass);
            }
            catch
            {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }

            RtfDestination c = null;

            if (_destinationObjects.ContainsKey(value.Name))
            {
                c = (RtfDestination)_destinationObjects[value.Name];
            }
            else
            {
                try
                {
                    c = (RtfDestination)Activator.CreateInstance(value);
                }
                catch
                {
                    return(false);
                }
            }

            c.SetParser(_rtfParser);

            if (value == typeof(RtfDestinationInfo))
            {
                ((RtfDestinationInfo)c).SetElementName(destination);
            }

            if (value == typeof(RtfDestinationStylesheetTable))
            {
                ((RtfDestinationStylesheetTable)c).SetElementName(destination);
                ((RtfDestinationStylesheetTable)c).SetType((string)args[1]);
            }

            _destinations[destination]      = c;
            _destinationObjects[value.Name] = c;
            return(true);
        }