Save This Page
Home » iText-src-2.1.3 » com.lowagie » text » rtf » field » [javadoc | source]
    1   /*
    2    * $Id: RtfTOCEntry.java 3373 2008-05-12 16:21:24Z xlv $
    3    *
    4    * Copyright 2004 by Mark Hall
    5    * Uses code Copyright 2002
    6    *   Steffen.Stundzig (Steffen.Stundzig@smb-tec.com) 
    7    *
    8    * The contents of this file are subject to the Mozilla Public License Version 1.1
    9    * (the "License"); you may not use this file except in compliance with the License.
   10    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
   11    *
   12    * Software distributed under the License is distributed on an "AS IS" basis,
   13    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   14    * for the specific language governing rights and limitations under the License.
   15    *
   16    * The Original Code is 'iText, a free JAVA-PDF library'.
   17    *
   18    * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
   19    * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
   20    * All Rights Reserved.
   21    * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
   22    * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
   23    *
   24    * Contributor(s): all the names of the contributors are added in the source code
   25    * where applicable.
   26    *
   27    * Alternatively, the contents of this file may be used under the terms of the
   28    * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
   29    * provisions of LGPL are applicable instead of those above.  If you wish to
   30    * allow use of your version of this file only under the terms of the LGPL
   31    * License and not to allow others to use your version of this file under
   32    * the MPL, indicate your decision by deleting the provisions above and
   33    * replace them with the notice and other provisions required by the LGPL.
   34    * If you do not delete the provisions above, a recipient may use your version
   35    * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
   36    *
   37    * This library is free software; you can redistribute it and/or modify it
   38    * under the terms of the MPL as stated above or under the terms of the GNU
   39    * Library General Public License as published by the Free Software Foundation;
   40    * either version 2 of the License, or any later version.
   41    *
   42    * This library is distributed in the hope that it will be useful, but WITHOUT
   43    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   44    * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
   45    * details.
   46    *
   47    * If you didn't download this code from the following link, you should check if
   48    * you aren't using an obsolete version:
   49    * http://www.lowagie.com/iText/
   50    */
   51   
   52   package com.lowagie.text.rtf.field;
   53   
   54   import java.io.IOException;
   55   import java.io.OutputStream;
   56   
   57   import com.lowagie.text.Font;
   58   
   59   
   60   /**
   61    * The RtfTOCEntry is used together with the RtfTableOfContents to generate a table of
   62    * contents. Add the RtfTOCEntry in those locations in the document where table of
   63    * contents entries should link to 
   64    * 
   65    * @version $Id: RtfTOCEntry.java 3373 2008-05-12 16:21:24Z xlv $
   66    * @author Mark Hall (Mark.Hall@mail.room3b.eu)
   67    * @author Steffen.Stundzig (Steffen.Stundzig@smb-tec.com) 
   68    * @author Thomas Bickel (tmb99@inode.at)
   69    */
   70   public class RtfTOCEntry extends RtfField {
   71   
   72       /**
   73        * Constant for the beginning of hidden text
   74        */
   75       private static final byte[] TEXT_HIDDEN_ON = "\\v".getBytes();
   76       /**
   77        * Constant for the end of hidden text
   78        */
   79       private static final byte[] TEXT_HIDDEN_OFF = "\\v0".getBytes();
   80       /**
   81        * Constant for a TOC entry with page numbers
   82        */
   83       private static final byte[] TOC_ENTRY_PAGE_NUMBER = "\\tc".getBytes();
   84       /**
   85        * Constant for a TOC entry without page numbers
   86        */
   87       private static final byte[] TOC_ENTRY_NO_PAGE_NUMBER = "\\tcn".getBytes();
   88       
   89       /**
   90        * The entry text of this RtfTOCEntry
   91        */
   92       private String entry = "";
   93       /**
   94        * Whether to show page numbers in the table of contents
   95        */
   96       private boolean showPageNumber = true;
   97       
   98       /**
   99        * Constructs a RtfTOCEntry with a certain entry text.
  100        * 
  101        * @param entry The entry text to display
  102        */
  103       public RtfTOCEntry(String entry) {
  104           super(null, new Font());
  105           if(entry != null) {
  106               this.entry = entry;
  107           }
  108       }
  109       
  110       /**
  111        * Writes the content of the <code>RtfTOCEntry</code>.
  112        * 
  113        * @param result The <code>OutputStream</code> to write to.
  114        * @throws IOException on i/o errors.
  115        */ 
  116       public void writeContent(final OutputStream result) throws IOException
  117       {    	
  118           result.write(TEXT_HIDDEN_ON);
  119           result.write(OPEN_GROUP);
  120           if(this.showPageNumber) {
  121               result.write(TOC_ENTRY_PAGE_NUMBER);
  122           } else {
  123               result.write(TOC_ENTRY_NO_PAGE_NUMBER);
  124           }
  125           result.write(DELIMITER);
  126           this.document.filterSpecialChar(result, this.entry, true, false);
  127           result.write(CLOSE_GROUP);
  128           result.write(TEXT_HIDDEN_OFF);
  129       }
  130       
  131       /**
  132        * Sets whether to display a page number in the table of contents, or not
  133        * 
  134        * @param showPageNumber Whether to display a page number or not
  135        */
  136       public void setShowPageNumber(boolean showPageNumber) {
  137           this.showPageNumber = showPageNumber;
  138       }
  139       
  140       /**
  141        * unused
  142        */
  143       protected void writeFieldInstContent(OutputStream out) throws IOException 
  144       {
  145       }
  146   
  147       /**
  148        * unused
  149        */
  150       protected void writeFieldResultContent(OutputStream out) throws IOException
  151       {
  152       }
  153   
  154   }

Save This Page
Home » iText-src-2.1.3 » com.lowagie » text » rtf » field » [javadoc | source]