Example #1
0
 /* (non-Javadoc)
  * @see com.itextpdf.tool.xml.parser.State#process(int)
  */
 public virtual void Process(char character)
 {
     if (character == '/')
     {
         // self closing tag detected
         parser.SelectState().SelfClosing();
     }
     else if (character == '=')
     {
         this.parser.Memory().CurrentAttr(this.parser.BufferToString());
         this.parser.Flush();
         this.parser.SelectState().AttributeValue();
     }
     else if (HTMLUtils.IsWhiteSpace(character))
     {
         SetAttribute();
     }
     else if (character == '>')
     {
         CheckAttributeWithNoValue();
         this.parser.StartElement();
         this.parser.Flush();
         this.parser.SelectState().InTag();
     }
     else if (this.parser.Memory().HasCurrentAttribute() && !HTMLUtils.IsWhiteSpace(character))
     {
         // assume attribute with no value, example tag <?formServer defaultPDFRenderFormat acrobat8.1dynamic?>
         this.parser.Memory().PutCurrentAttrValue("");
         this.parser.Append(character);
     }
     else
     {
         this.parser.Append(character);
     }
 }
 /* (non-Javadoc)
  * @see com.itextpdf.tool.xml.parser.State#process(int)
  */
 public void Process(char character)
 {
     if (!HTMLUtils.IsWhiteSpace(character))
     {
         this.parser.Append(character);
     }
     else
     {
         this.parser.Memory().PutCurrentAttrValue(this.parser.BufferToString());
         this.parser.Flush();
         this.parser.SelectState().TagAttributes();
     }
 }
 /*
  * (non-Javadoc)
  *
  * @see com.itextpdf.tool.xml.parser.State#process(int)
  */
 public void Process(char character)
 {
     if (character == '<')
     {
         if (this.parser.BufferSize() > 0)
         {
             this.parser.Text(this.parser.Current());
         }
         this.parser.Flush();
         this.parser.SelectState().TagEncountered();
     }
     else if (character == '&')
     {
         this.parser.SelectState().SpecialChar();
     }
     else
     {
         String   tag   = this.parser.CurrentTag();
         TagState state = this.parser.CurrentTagState();
         if (noSanitize.Contains(tag) && TagState.OPEN == state)
         {
             this.parser.Append(character);
         }
         else
         {
             if (this.parser.Memory().WhitespaceTag().Length != 0)
             {
                 if (ignoreLastChars.Contains(this.parser.Memory().WhitespaceTag()))
                 {
                     parser.Memory().LastChar = ' ';
                 }
                 this.parser.Memory().WhitespaceTag("");
             }
             bool whitespace   = HTMLUtils.IsWhiteSpace(parser.Memory().LastChar);
             bool noWhiteSpace = !HTMLUtils.IsWhiteSpace(character);
             if (!whitespace || (whitespace && noWhiteSpace))
             {
                 if (noWhiteSpace)
                 {
                     this.parser.Append(character);
                 }
                 else
                 {
                     this.parser.Append(' ');
                 }
             }
             parser.Memory().LastChar = character;
         }
     }
 }
Example #4
0
 /*
  * (non-Javadoc)
  *
  * @see com.itextpdf.tool.xml.parser.State#process(int)
  */
 virtual public void Process(char character)
 {
     if (character == '\'')
     {
         this.parser.SelectState().SingleQuotedAttr();
     }
     else if (character == '"')
     {
         this.parser.SelectState().DoubleQuotedAttr();
     }
     else if (!HTMLUtils.IsWhiteSpace(character))
     {
         this.parser.Append(character);
         this.parser.SelectState().UnquotedAttr();
     }
 }
 /* (non-Javadoc)
  * @see com.itextpdf.tool.xml.parser.State#process(int)
  */
 virtual public void Process(char character)
 {
     if (character == '>')
     {
         this.parser.Memory().CurrentTag(this.parser.BufferToString());
         this.parser.EndElement();
         this.parser.Flush();
         this.parser.Memory().FlushNameSpace();
         parser.SelectState().InTag();
     }
     else if (character == ':')
     {
         this.parser.Memory().Namespace(this.parser.BufferToString());
         this.parser.Flush();
     }
     else if (!HTMLUtils.IsWhiteSpace((char)character))
     {
         this.parser.Append(character);
     }
 }
        /*
         * (non-Javadoc)
         *
         * @see com.itextpdf.tool.xml.parser.State#process(int)
         */
        virtual public void Process(char character)
        {
            String tag = this.parser.BufferToString();

            if (HTMLUtils.IsWhiteSpace(character) || character == '>' || character == '/' || character == ':' || tag.Equals("!--") || tag.Equals("![CDATA") && character == '[' || character == '?')
            {
                // cope with <? xml and <! DOCTYPE
                if (tag.Length > 0)
                {
                    if (tag.Equals("!--"))
                    {
                        this.parser.Flush();
                        this.parser.Memory().Comment().Length = 0;
                        parser.SelectState().Comment();
                        // if else structure added to check for the presence of an empty comment without a space <!---->
                        // if this check isn't included it would add the third dash to the stringbuilder of XmlParser and
                        // not to memory().comment() which caused CloseCommentState to keep adding the rest of the document
                        // as a comment because it checked the closing tag on the length, which would be 1 in this case
                        // (the fourth dash)
                        if (character != '-')
                        {
                            this.parser.Append(character);
                        }
                        else
                        {
                            this.parser.Memory().Comment().Append(character);
                        }
                    }
                    else if (tag.Equals("![CDATA") && character == '[')
                    {
                        this.parser.Flush();
                        parser.SelectState().Cdata();
                    }
                    else if (tag.Equals("!DOCTYPE"))
                    {
                        this.parser.Flush();
                        parser.SelectState().Doctype();
                        this.parser.Append(character);
                    }
                    else if (HTMLUtils.IsWhiteSpace(character))
                    {
                        this.parser.Memory().CurrentTag(this.parser.BufferToString());
                        this.parser.Flush();
                        this.parser.SelectState().TagAttributes();
                    }
                    else if (character == '>')
                    {
                        this.parser.Memory().CurrentTag(tag);
                        this.parser.Flush();
                        this.parser.StartElement();
                        this.parser.SelectState().InTag();
                    }
                    else if (character == '/')
                    {
                        this.parser.Memory().CurrentTag(this.parser.BufferToString());
                        this.parser.Flush();
                        this.parser.SelectState().SelfClosing();
                    }
                    else if (character == ':')
                    {
                        this.parser.Memory().Namespace(tag);
                        this.parser.Flush();
                    }
                }
                else
                {
                    if (character == '/')
                    {
                        this.parser.SelectState().ClosingTag();
                    }
                    else if (character == '?')
                    {
                        this.parser.Append(character);
                        this.parser.SelectState().ProcessingInstructions();
                    }
                }
            }
            else
            {
                this.parser.Append(character);
            }
        }
Example #7
0
        /*
         * (non-Javadoc)
         *
         * @see com.itextpdf.tool.xml.parser.State#process(int)
         */
        public void Process(char character)
        {
            String tag = this.parser.BufferToString();

            if (HTMLUtils.IsWhiteSpace(character) || character == '>' || character == '/' || character == ':' || tag.Equals("!--") || tag.Equals("![CDATA["))
            {
                // cope with <? xml and <! DOCTYPE
                if (tag.Length > 0)
                {
                    if (tag.Equals("!--"))
                    {
                        this.parser.Flush();
                        this.parser.Memory().Comment().Length = 0;
                        parser.SelectState().Comment();
                        this.parser.Append(character);
                    }
                    else if (tag.Equals("![CDATA["))
                    {
                        this.parser.Flush();
                        parser.SelectState().Cdata();
                        this.parser.Append(character);
                    }
                    else if (tag.Equals("?xml"))
                    {
                        this.parser.Memory().CurrentTag("xml");
                        this.parser.Flush();
                        parser.SelectState().TagAttributes();
                        this.parser.Append(character);
                    }
                    else if (tag.Equals("!DOCTYPE"))
                    {
                        this.parser.Flush();
                        parser.SelectState().Doctype();
                        this.parser.Append(character);
                    }
                    else if (HTMLUtils.IsWhiteSpace(character))
                    {
                        this.parser.Memory().CurrentTag(this.parser.BufferToString());
                        this.parser.Flush();
                        this.parser.SelectState().TagAttributes();
                    }
                    else if (character == '>')
                    {
                        this.parser.Memory().CurrentTag(tag);
                        this.parser.Flush();
                        this.parser.StartElement();
                        this.parser.SelectState().InTag();
                    }
                    else if (character == '/')
                    {
                        this.parser.Memory().CurrentTag(this.parser.BufferToString());
                        this.parser.Flush();
                        this.parser.SelectState().SelfClosing();
                    }
                    else if (character == ':')
                    {
                        this.parser.Memory().Namespace(tag);
                        this.parser.Flush();
                    }
                }
                else if (character == '/')
                {
                    this.parser.SelectState().ClosingTag();
                }
            }
            else
            {
                this.parser.Append(character);
            }
        }