Esempio n. 1
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.pipeline.IPipeline#close(com.itextpdf.tool
         * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po)
        {
            HtmlPipelineContext hcc = (HtmlPipelineContext)GetLocalContext(context);
            ITagProcessor       tp;

            try {
                if (t.LastMarginBottom != null)
                {
                    hcc.GetMemory()[HtmlPipelineContext.LAST_MARGIN_BOTTOM] = t.LastMarginBottom;
                }
                else
                {
                    hcc.GetMemory().Remove(HtmlPipelineContext.LAST_MARGIN_BOTTOM);
                }
                tp = hcc.ResolveProcessor(t.Name, t.NameSpace);
                IList <IElement> elems = null;
                if (tp.IsStackOwner())
                {
                    // remove the element from the StackKeeper Queue if end tag is
                    // found
                    StackKeeper tagStack;
                    try {
                        tagStack = hcc.Poll();
                    } catch (NoStackException e) {
                        throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.STACK_404), t.ToString()), e);
                    }
                    elems = tp.EndElement(context, t, tagStack.GetElements());
                }
                else
                {
                    elems = tp.EndElement(context, t, hcc.CurrentContent());
                    hcc.CurrentContent().Clear();
                }
                if (elems.Count > 0)
                {
                    StackKeeper stack = hcc.Peek();

                    if (stack != null)
                    {
                        foreach (IElement elem in elems)
                        {
                            stack.Add(elem);
                        }
                    }
                    else
                    {
                        WritableElement writableElement = new WritableElement();
                        po.Add(writableElement);
                        writableElement.AddAll(elems);
                    }
                }
            } catch (NoTagProcessorException e) {
                if (!hcc.AcceptUnknown())
                {
                    throw e;
                }
            }
            return(GetNext());
        }
 /**
  * Retrieves and removes the top of the stack.
  * @return a StackKeeper
  * @throws NoStackException if there are no elements on the stack
  */
 protected internal StackKeeper Poll()
 {
     try {
         StackKeeper sk = this.queue.First.Value;
         this.queue.RemoveFirst();
         return(sk);
     } catch (InvalidOperationException) {
         throw new NoStackException();
     }
 }
Esempio n. 3
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.pipeline.IPipeline#open(com.itextpdf.tool.
         * xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po)
        {
            HtmlPipelineContext hcc = (HtmlPipelineContext)GetLocalContext(context);

            try {
                Object lastMarginBottom = null;
                if (hcc.GetMemory().TryGetValue(HtmlPipelineContext.LAST_MARGIN_BOTTOM, out lastMarginBottom))
                {
                    t.LastMarginBottom = lastMarginBottom;
                    hcc.GetMemory().Remove(HtmlPipelineContext.LAST_MARGIN_BOTTOM);
                }
                ITagProcessor tp = hcc.ResolveProcessor(t.Name, t.NameSpace);
                AddStackKeeper(t, hcc, tp);
                IList <IElement> content = tp.StartElement(context, t);
                if (content.Count > 0)
                {
                    if (tp.IsStackOwner())
                    {
                        StackKeeper peek = hcc.Peek();
                        if (peek == null)
                        {
                            throw new PipelineException(String.Format(LocaleMessages.STACK_404, t.ToString()));
                        }
                        foreach (IElement elem in content)
                        {
                            peek.Add(elem);
                        }
                    }
                    else
                    {
                        foreach (IElement elem in content)
                        {
                            hcc.CurrentContent().Add(elem);
                            if (elem.Type == Element.BODY)
                            {
                                WritableElement writableElement = new WritableElement();
                                writableElement.Add(elem);
                                po.Add(writableElement);
                                hcc.CurrentContent().Remove(elem);
                            }
                        }
                    }
                }
            } catch (NoTagProcessorException e) {
                if (!hcc.AcceptUnknown())
                {
                    throw e;
                }
            }
            return(GetNext());
        }
Esempio n. 4
0
        /*
         * (non-Javadoc)
         *
         * @see com.itextpdf.tool.xml.pipeline.IPipeline#content(com.itextpdf.tool
         * .xml.Tag, java.lang.String, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Content(IWorkerContext context, Tag t, string text, ProcessObject po)
        {
            HtmlPipelineContext hcc = (HtmlPipelineContext)GetLocalContext(context);
            ITagProcessor       tp;

            try {
                tp = hcc.ResolveProcessor(t.Name, t.NameSpace);
                //String ctn = null;
                //if (null != hcc.CharSet()) {
                //    ctn = hcc.CharSet().GetString(b);
                //} else {
                //    ctn = Encoding.Default.GetString(b);
                //}
                IList <IElement> elems = tp.Content(context, t, text);
                if (elems.Count > 0)
                {
                    StackKeeper peek = hcc.Peek();
                    if (peek != null)
                    {
                        foreach (IElement e in elems)
                        {
                            peek.Add(e);
                        }
                    }
                    else
                    {
                        WritableElement writableElement = new WritableElement();
                        foreach (IElement elem in elems)
                        {
                            writableElement.Add(elem);
                        }
                        po.Add(writableElement);
                    }
                }
            } catch (NoTagProcessorException e) {
                if (!hcc.AcceptUnknown())
                {
                    throw e;
                }
            }
            return(GetNext());
        }
 /**
  * Add a {@link StackKeeper} to the top of the stack list.
  * @param stackKeeper the {@link StackKeeper}
  */
 protected internal void AddFirst(StackKeeper stackKeeper)
 {
     this.queue.AddFirst(stackKeeper);
 }