Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: AbstractTagProcessor.java 364 2012-08-29 09:28:23Z achingarev $
   *
   * This file is part of the iText (R) project.
   * Copyright (c) 1998-2012
   * 1T3XT BVBA Authors: Balder Van Camp, Emiel Ackermann, et al.
   *
   * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General
   * Public License version 3 as published by the Free Software Foundation with the addition of the following permission
  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
  * 1T3XT, 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  * details. You should have received a copy of the GNU Affero General Public License along with this program; if not,
  * see http://www.gnu.org/licenses or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA, 02110-1301 USA, or download the license from the following URL: http://itextpdf.com/terms-of-use/
  *
  * The interactive user interfaces in modified source and object code versions of this program must display Appropriate
  * Legal Notices, as required under Section 5 of the GNU Affero General Public License.
  *
  * In accordance with Section 7(b) of the GNU Affero General Public License, a covered work must retain the producer
  * line in every PDF that is created or manipulated using iText.
  *
  * You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is
  * mandatory as soon as you develop commercial activities involving the iText software without disclosing the source
  * code of your own applications. These activities include: offering paid services to customers as an ASP, serving PDFs
  * on the fly in a web application, shipping iText with a closed source product.
  *
  * For more information, please contact iText Software Corp. at this address: sales@itextpdf.com
  */
 package com.itextpdf.tool.xml.html;
 
 
 import java.util.List;

Abstract TagProcessor that allows setting the configuration object to a protected member variable.
Implements TagProcessor.startElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag) and TagProcessor.endElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag,java.util.List) to calculate font sizes and add new pages if needed.
Extend from this class instead of implementing TagProcessor to benefit from auto fontsize metric conversion to pt and page-break-before/after insertion. Override start(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag) and end(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag,java.util.List) in your extension.

Author(s):
redlab_b
 
 public abstract class AbstractTagProcessor implements TagProcessorCssAppliersAware {
 
 	private final FontSizeTranslator fontsizeTrans;
 	private CssAppliers cssAppliers;

 
 	public AbstractTagProcessor() {
 		 = FontSizeTranslator.getInstance();
 	}

Utility method that fetches the CSSResolver from the if any and if it uses the default key.

Parameters:
context the WorkerContext
Returns:
CSSResolver
Throws:
com.itextpdf.tool.xml.NoCustomContextException if the context of the com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline could not be found.
 
 	@SuppressWarnings("unchecked")
 	public CSSResolver getCSSResolver(final WorkerContext contextthrows NoCustomContextException {
 		return ((ObjectContext<CSSResolver>)context.get(CssResolverPipeline.class.getName())).get();
 	}

Utility method that fetches the HtmlPipelineContext used if any and if it uses the default key.

Parameters:
context the WorkerContext
Returns:
a HtmlPipelineContext
Throws:
com.itextpdf.tool.xml.NoCustomContextException if the context of the com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext could not be found.
		return ((HtmlPipelineContextcontext.get(HtmlPipeline.class.getName()));
	}
Calculates any found font size to pt values and set it in the CSS before calling start(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag).
Checks for com.itextpdf.tool.xml.css.CSS.Property.PAGE_BREAK_BEFORE, if the value is always a Chunk.NEXTPAGE added before the implementors start(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag) method.
	public final List<ElementstartElement(final WorkerContext ctxfinal Tag tag) {
		float fontSize = .translateFontSize(tag);
        if (fontSize != .) {
		    tag.getCSS().put(..fontSize + "pt");
        }
		if (null != pagebreak && ...equalsIgnoreCase(pagebreak)) {
			List<Elementlist = new ArrayList<Element>(2);
			list.addAll(start(ctxtag));
			return list;
		}
		return start(ctxtag);
	}

Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.startElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag). The startElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag) calls this method after or before doing certain stuff, (see it's description).

Parameters:
ctx the WorkerContext
tag the tag
Returns:
an element to be added to current content, may be null
	public List<Elementstart(final WorkerContext ctxfinal Tag tag){ return new ArrayList<Element>(0); };
	/*
	 * (non-Javadoc)
	 *
	 * @see com.itextpdf.tool.xml.TagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String)
	 */
	public List<Elementcontent(final WorkerContext ctxfinal Tag tagfinal String content) {
		return new ArrayList<Element>(0);
	}
    protected List<ElementtextContent(final WorkerContext ctxfinal Tag tagfinal String content) {
		List<ChunksanitizedChunks = HTMLUtils.sanitize(contentfalse);
		List<Elementl = new ArrayList<Element>(1);
        for (Chunk sanitized : sanitizedChunks) {
            try {
                l.add(getCssAppliers().apply(sanitizedtaggetHtmlPipelineContext(ctx)));
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(e);
            }
        }
		return l;
	}

Checks for com.itextpdf.tool.xml.css.CSS.Property.PAGE_BREAK_AFTER, if the value is always a Chunk.NEXTPAGE is added to the currentContentList after calling end(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag,java.util.List).
	public final List<ElementendElement(final WorkerContext ctxfinal Tag tagfinal List<ElementcurrentContent) {
        List<Elementlist = new ArrayList<Element>();
        if (currentContent.isEmpty()) {
            list = end(ctxtagcurrentContent);
        } else {
            List<Elementelements = new ArrayList<Element>();
            for (Element el : currentContent) {
                if (el instanceof Chunk && ((Chunkel).hasAttributes() && ((Chunkel).getAttributes().containsKey(.)) {
                    if (elements.size() > 0) {
                        list.addAll(end(ctxtagelements));
                        elements.clear();
                    }
                    list.add(el);
                } else {
                    elements.add(el);
                }
            }
            if (elements.size() > 0) {
                list.addAll(end(ctxtagelements));
                elements.clear();
            }
        }
		if (null != pagebreak && ...equalsIgnoreCase(pagebreak)) {
		}
		return list;
	}

Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.endElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag,java.util.List). The endElement(com.itextpdf.tool.xml.WorkerContext,com.itextpdf.tool.xml.Tag,java.util.List) calls this method after or before doing certain stuff, (see it's description).

Parameters:
ctx the WorkerContext
tag the tag
currentContent the content created from e.g. inner tags, inner content and not yet added to document.
Returns:
a List containing iText Element objects
	public List<Elementend(final WorkerContext ctxfinal Tag tagfinal List<ElementcurrentContent) {
		return new ArrayList<Element>(currentContent);
	}

Defaults to false.

	public boolean isStackOwner() {
		return false;
	}

Adds currentContent list to a paragraph element. If addNewLines is true a Paragraph object is returned, else a NoNewLineParagraph object is returned.

Parameters:
currentContent List<Element> of the current elements to be added.
addNewLines boolean to declare which paragraph element should be returned, true if new line should be added or not.
applyCSS true if CSS should be applied on the paragraph.
tag the relevant tag.
ctx the WorkerContext.
Returns:
a List of paragraphs.
	public final List<ElementcurrentContentToParagraph(final List<ElementcurrentContent,
			final boolean addNewLinesfinal boolean applyCSSfinal Tag tagfinal WorkerContext ctx) {
		try {
			List<Elementlist = new ArrayList<Element>();
			if (currentContent.size() > 0) {
				if (addNewLines) {
                    p.setMultipliedLeading(1.2f);
					for (Element e : currentContent) {
                        if (e instanceof LineSeparator) {
                            try {
                                HtmlPipelineContext htmlPipelineContext = getHtmlPipelineContext(ctx);
                                Chunk newLine = (Chunk)getCssAppliers().apply(new Chunk(.), taghtmlPipelineContext);
                                p.add(newLine);
                            } catch (NoCustomContextException e1) {
                                throw new RuntimeWorkerException(LocaleMessages.getInstance().getMessage(.), e1);
                            }
                        }
						p.add(e);
					}
                    if (p.trim()) {
                        if (applyCSS) {
                            p = (ParagraphgetCssAppliers().apply(ptaggetHtmlPipelineContext(ctx));
                        }
                        list.add(p);
                    }
else {
                    p.setMultipliedLeading(1.2f);
					for (Element e : currentContent) {
						p.add(e);
					}
					list.add(p);
				}
			}
			return list;
catch (NoCustomContextException e) {
		}
	}

Default apply CSS to false and tag to null.

Parameters:
currentContent List<Element> of the current elements to be added.
addNewLines boolean to declare which paragraph element should be returned, true if new line should be added or not.
Returns:
a List with paragraphs
See also:
currentContentToParagraph(java.util.List,boolean,boolean,com.itextpdf.tool.xml.Tag,com.itextpdf.tool.xml.WorkerContext)
	public final List<ElementcurrentContentToParagraph(final List<ElementcurrentContent,
			final boolean addNewLines) {
		return this.currentContentToParagraph(currentContentaddNewLinesfalsenullnull);
	}
	/*
	 * (non-Javadoc)
	 *
	 * @see com.itextpdf.tool.xml.html.CssAppliersAware#setCssAppliers(com.itextpdf.tool.xml.html.CssAppliers)
	 */
	public void setCssAppliers(final CssAppliers cssAppliers) {
		this. = cssAppliers;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.itextpdf.tool.xml.html.CssAppliersAware#getCssAppliers()
	 */
		return ;
	}
    protected Paragraph createParagraph() {
        return new Paragraph(.);
    }
New to GrepCode? Check out our FAQ X