* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public class RtfException extends java.io.IOException
-{
- public RtfException(String reason)
- {
+public class RtfException extends java.io.IOException {
+ public RtfException(String reason) {
super(reason);
}
}
\ No newline at end of file
*/
public class RtfStructureException
-extends RtfException
-{
- public RtfStructureException(String reason)
- {
+extends RtfException {
+ public RtfStructureException(String reason) {
super(reason);
}
}
\ No newline at end of file
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public interface ITableColumnsInfo
-{
+public interface ITableColumnsInfo {
float INVALID_COLUM_WIDTH = 200f;
/** reset the column iteration index, meant to be called when creating a new row */
*/
float getColumnWidth();
- /** return current column iteration index */
+ /** @return current column iteration index */
int getColumnIndex();
- /** return number of columns */
+ /** @return number of columns */
int getNumberOfColumns();
}
\ No newline at end of file
String BORDER_SINGLE_THICKNESS = "brdrs";
String BORDER_DOUBLE_THICKNESS = "brdrth";
- String BORDER_SHADOWED ="brdrsh";
- String BORDER_DOUBLE ="brdrdb";
- String BORDER_DOTTED ="brdrdot";
- String BORDER_DASH ="brdrdash";
- String BORDER_HAIRLINE ="brdrhair";
- String BORDER_DASH_SMALL ="brdrdashsm";
+ String BORDER_SHADOWED = "brdrsh";
+ String BORDER_DOUBLE = "brdrdb";
+ String BORDER_DOTTED = "brdrdot";
+ String BORDER_DASH = "brdrdash";
+ String BORDER_HAIRLINE = "brdrhair";
+ String BORDER_DASH_SMALL = "brdrdashsm";
String BORDER_DOT_DASH = "brdrdashd";
String BORDER_DOT_DOT_DASH = "brdrdashdd";
String BORDER_TRIPLE = "brdrtriple";
import java.io.IOException;
/** interface for RTF objects that can contain footers */
-public interface IRtfAfterContainer
-{
- public RtfAfter newAfter(RtfAttributes attrs) throws IOException;
+public interface IRtfAfterContainer {
+ RtfAfter newAfter(RtfAttributes attrs) throws IOException;
}
\ No newline at end of file
import java.io.IOException;
-public interface IRtfBeforeContainer
-{
- public RtfBefore newBefore(RtfAttributes attrs) throws IOException;
+public interface IRtfBeforeContainer {
+ RtfBefore newBefore(RtfAttributes attrs) throws IOException;
}
\ No newline at end of file
* RTF Bookmark container interface.
* @author <a href="mailto:a.putz@skynamics.com">Andreas Putz</a>
*/
-public interface IRtfBookmarkContainer
-{
+public interface IRtfBookmarkContainer {
/**
* Create a new RTF bookmark.
import java.io.IOException;
-public interface IRtfExternalGraphicContainer
-{
+public interface IRtfExternalGraphicContainer {
/**
* Creates a new image on external graphic base.
/** interface for RtfElements that can contain RtfHyperLinks
* @author Andreas Putz a.putz@skynamics.com
*/
-public interface IRtfHyperLinkContainer extends IRtfTextContainer
-{
+public interface IRtfHyperLinkContainer extends IRtfTextContainer {
/**
* Creates a new hyperlink.
*
* @exception IOException on error
*/
- public RtfHyperLink newHyperLink (String str, RtfAttributes attr) throws IOException;
+ RtfHyperLink newHyperLink (String str, RtfAttributes attr) throws IOException;
}
\ No newline at end of file
import java.io.IOException;
public interface IRtfJforCmdContainer {
- public RtfJforCmd newJforCmd(RtfAttributes attr) throws IOException;
+ RtfJforCmd newJforCmd(RtfAttributes attr) throws IOException;
}
\ No newline at end of file
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public interface IRtfListContainer
-{
+public interface IRtfListContainer {
/** close current list if any and start a new one */
- public RtfList newList(RtfAttributes attrs) throws IOException;
+ RtfList newList(RtfAttributes attrs) throws IOException;
}
\ No newline at end of file
/**
* Options for configuring the rtf elements.
*/
-public interface IRtfOptions
-{
+public interface IRtfOptions {
/**
* Sets the compression rate for the external graphic in percent.
* @param percent Compression rate
*/
- public void setRtfExternalGraphicCompressionRate (int percent);
+ void setRtfExternalGraphicCompressionRate (int percent);
/**
* Gets the compression rate for the external graphic in percent.
* @return Compression rate
*/
- public int getRtfExternalGraphicCompressionRate ();
+ int getRtfExternalGraphicCompressionRate ();
}
\ No newline at end of file
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public interface IRtfPageBreakContainer
-{
+public interface IRtfPageBreakContainer {
/** add a page break */
- public void newPageBreak() throws IOException;
+ void newPageBreak() throws IOException;
}
\ No newline at end of file
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public interface IRtfPageContainer
-{
+public interface IRtfPageContainer {
/** close current text run if any and start a new one with specified attributes
* @param str if not null, added to the RtfText created
*/
- public RtfPage newPage(RtfAttributes attrs) throws IOException;
+ RtfPage newPage(RtfAttributes attrs) throws IOException;
}
package org.apache.fop.rtf.rtflib.rtfdoc;
-import java.io.*;
-import java.util.Iterator;
+import java.io.Writer;
+import java.io.IOException;
import org.apache.fop.rtf.rtflib.interfaces.ITableColumnsInfo;
/** Container for RtfRow elements
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public class RtfTable extends RtfContainer
-{
+public class RtfTable extends RtfContainer {
private RtfTableRow m_row;
- private int highestRow=0;
+ private int highestRow = 0;
- /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
+ /** Added by Boris Poudérous on 07/22/2002 in order to process
+ * number-columns-spanned attribute */
private ITableColumnsInfo m_table_context;
/** Create an RTF element as a child of given container */
- RtfTable(IRtfTableContainer parent, Writer w, ITableColumnsInfo tc) throws IOException
- {
- super((RtfContainer)parent,w);
+ RtfTable(IRtfTableContainer parent, Writer w, ITableColumnsInfo tc)
+ throws IOException {
+ super((RtfContainer)parent, w);
// Line added by Boris Poudérous on 07/22/2002
m_table_context = tc;
}
/** Create an RTF element as a child of given container
* Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute
*/
- RtfTable(IRtfTableContainer parent, Writer w, RtfAttributes attrs, ITableColumnsInfo tc) throws IOException
- {
- super((RtfContainer)parent,w,attrs);
+ RtfTable(IRtfTableContainer parent, Writer w, RtfAttributes attrs,
+ ITableColumnsInfo tc) throws IOException {
+ super((RtfContainer)parent, w, attrs);
// Line added by Boris Poudérous on 07/22/2002
m_table_context = tc;
}
/** close current row if any and start a new one */
- public RtfTableRow newTableRow() throws IOException
- {
- if(m_row != null) m_row.close();
+ public RtfTableRow newTableRow() throws IOException {
+ if (m_row != null) {
+ m_row.close();
+ }
highestRow++;
- m_row = new RtfTableRow(this,m_writer,m_attrib,highestRow);
+ m_row = new RtfTableRow(this, m_writer, m_attrib, highestRow);
return m_row;
}
/** close current row if any and start a new one */
- public RtfTableRow newTableRow(RtfAttributes attrs) throws IOException
- {
+ public RtfTableRow newTableRow(RtfAttributes attrs) throws IOException {
RtfAttributes attr = null;
- if (m_attrib != null)
- {
+ if (m_attrib != null) {
attr = (RtfAttributes) m_attrib.clone ();
attr.set (attrs);
- }
- else
+ } else {
attr = attrs;
- if(m_row != null) m_row.close();
+ }
+ if (m_row != null) {
+ m_row.close();
+ }
highestRow++;
- m_row = new RtfTableRow(this,m_writer,attr,highestRow);
+ m_row = new RtfTableRow(this, m_writer, attr, highestRow);
return m_row;
}
/** overridden to write RTF prefix code, what comes before our children */
- protected void writeRtfPrefix() throws IOException
- {
+ protected void writeRtfPrefix() throws IOException {
writeGroupMark(true);
}
/** overridden to write RTF suffix code, what comes after our children */
- protected void writeRtfSuffix() throws IOException
- {
+ protected void writeRtfSuffix() throws IOException {
writeGroupMark(false);
}
- public boolean isHighestRow(int id)
- {
+ public boolean isHighestRow(int id) {
return (highestRow == id) ? true : false;
}
/** Added by Boris Poudérous on 07/22/2002 */
- public ITableColumnsInfo getITableColumnsInfo()
- {
+ public ITableColumnsInfo getITableColumnsInfo() {
return this.m_table_context;
}
// Added by Normand Masse
// Support for table-header attributes (used instead of table attributes
- public void setHeaderAttribs( RtfAttributes attrs ) {
+ public void setHeaderAttribs(RtfAttributes attrs) {
m_header_attribs = attrs;
}
// Returns the table-header attributes if they are present, otherwise the
// parent's attributes are returned normally.
public RtfAttributes getRtfAttributes() {
- if ( m_header_attribs != null ) {
+ if (m_header_attribs != null) {
return m_header_attribs;
}
package org.apache.fop.rtf.rtflib.rtfdoc;
-import java.io.*;
-import java.util.*;
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Iterator;
import org.apache.fop.rtf.rtflib.interfaces.ITableColumnsInfo;
/** A cell in an RTF table, container for paragraphs, lists, etc.
public class RtfTableCell
extends RtfContainer
-implements IRtfParagraphContainer,IRtfListContainer,IRtfTableContainer,IRtfExternalGraphicContainer {
+implements IRtfParagraphContainer, IRtfListContainer, IRtfTableContainer,
+ IRtfExternalGraphicContainer {
private RtfParagraph m_paragraph;
private RtfList m_list;
private RtfTable m_table;
private int m_hMerge = NO_MERGE;
/** cell merging: this cell is not merged */
- public final static int NO_MERGE = 0;
+ public static final int NO_MERGE = 0;
/** cell merging: this cell is the start of a range of merged cells */
- public final static int MERGE_START = 1;
+ public static final int MERGE_START = 1;
/** cell merging: this cell is part of (but not the start of) a range of merged cells */
- public final static int MERGE_WITH_PREVIOUS = 2;
+ public static final int MERGE_WITH_PREVIOUS = 2;
/** Create an RTF element as a child of given container */
- RtfTableCell(RtfTableRow parent, Writer w,int cellWidth, int idNum) throws IOException {
- super(parent,w);
+ RtfTableCell(RtfTableRow parent, Writer w, int cellWidth, int idNum) throws IOException {
+ super(parent, w);
id = idNum;
m_parentRow = parent;
m_cellWidth = cellWidth;
}
/** Create an RTF element as a child of given container */
- RtfTableCell(RtfTableRow parent, Writer w,int cellWidth, RtfAttributes attrs, int idNum) throws IOException {
- super(parent,w,attrs);
+ RtfTableCell(RtfTableRow parent, Writer w, int cellWidth, RtfAttributes attrs,
+ int idNum) throws IOException {
+ super(parent, w, attrs);
id = idNum;
m_parentRow = parent;
m_cellWidth = cellWidth;
- /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
+ /** Added by Boris Poudérous on 07/22/2002 in order to process
+ * number-columns-spanned attribute */
// If the cell is spanned horizontally
- if (attrs.getValue("number-columns-spanned") != null)
- {
+ if (attrs.getValue("number-columns-spanned") != null) {
// Start horizontal merge
this.setHMerge(MERGE_START);
// Get the number of columns spanned
int nbMergedCells = ((Integer)attrs.getValue("number-columns-spanned")).intValue();
- if (parent.m_parent instanceof RtfTable)
- {
+ if (parent.m_parent instanceof RtfTable) {
// Get the context of the current table in order to get the width of each column
- ITableColumnsInfo ITableColumnsInfo = ((RtfTable)parent.m_parent).getITableColumnsInfo();
+ ITableColumnsInfo ITableColumnsInfo =
+ ((RtfTable)parent.m_parent).getITableColumnsInfo();
ITableColumnsInfo.selectFirstColumn();
// Reach the column index in table context corresponding to the current column cell
// id is the index of the current cell (it begins at 1)
// getColumnIndex() is the index of the current column in table context (it begins at 0)
// => so we must widthdraw 1 when comparing these two variables.
- while ((this.id-1) != ITableColumnsInfo.getColumnIndex())
+ while ((this.id - 1) != ITableColumnsInfo.getColumnIndex()) {
ITableColumnsInfo.selectNextColumn();
+ }
- // We widthdraw one cell because the first cell is already created (it's the current cell) !
+ // We widthdraw one cell because the first cell is already created
+ // (it's the current cell) !
int i = nbMergedCells - 1;
- while (i > 0)
- {
+ while (i > 0) {
ITableColumnsInfo.selectNextColumn();
// Added by Normand Masse
// Pass in the current cell's attributes so the 'merged' cell has the
// same display attributes.
- parent.newTableCellMergedHorizontally((int)ITableColumnsInfo.getColumnWidth(), attrs);
+ parent.newTableCellMergedHorizontally((int)ITableColumnsInfo.getColumnWidth(),
+ attrs);
i--;
}
closeAll();
// in tables, RtfParagraph must have the intbl attribute
- if(attrs==null) attrs = new RtfAttributes();
+ if (attrs == null) {
+ attrs = new RtfAttributes();
+ }
attrs.set("intbl");
- m_paragraph = new RtfParagraph(this,m_writer,attrs);
+ m_paragraph = new RtfParagraph(this, m_writer, attrs);
- if(m_paragraph.m_attrib.isSet("qc"))
- {
- set_center=true;
+ if (m_paragraph.m_attrib.isSet("qc")) {
+ set_center = true;
attrs.set("qc");
- }
- else if(m_paragraph.m_attrib.isSet("qr"))
- {
- set_right=true;
+ } else if (m_paragraph.m_attrib.isSet("qr")) {
+ set_right = true;
attrs.set("qr");
- }
- else
- {
+ } else {
attrs.set("ql");
}
attrs.set("intbl");
/** start a new external graphic after closing current paragraph, list and table */
public RtfExternalGraphic newImage() throws IOException {
closeAll();
- m_externalGraphic = new RtfExternalGraphic(this,m_writer);
+ m_externalGraphic = new RtfExternalGraphic(this, m_writer);
return m_externalGraphic;
}
/** start a new list after closing current paragraph, list and table */
public RtfList newList(RtfAttributes attrib) throws IOException {
closeAll();
- m_list = new RtfList(this,m_writer,attrib);
+ m_list = new RtfList(this, m_writer, attrib);
return m_list;
}
/** start a new nested table after closing current paragraph, list and table */
public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
closeAll();
- m_table = new RtfTable(this,m_writer,tc);
+ m_table = new RtfTable(this, m_writer, tc);
return m_table;
}
- /** start a new nested table after closing current paragraph, list and table */ // Modified by Boris Poudérous on 07/22/2002
+ /** start a new nested table after closing current paragraph, list and table */
+ // Modified by Boris Poudérous on 07/22/2002
public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException
{
closeAll();
m_widthOffset = widthOffset;
// vertical cell merge codes
- if(m_vMerge == MERGE_START) {
+ if (m_vMerge == MERGE_START) {
writeControlWord("clvmgf");
- } else if(m_vMerge == MERGE_WITH_PREVIOUS) {
+ } else if (m_vMerge == MERGE_WITH_PREVIOUS) {
writeControlWord("clvmrg");
}
// horizontal cell merge codes
- if(m_hMerge == MERGE_START) {
+ if (m_hMerge == MERGE_START) {
writeControlWord("clmgf");
- } else if(m_hMerge == MERGE_WITH_PREVIOUS) {
+ } else if (m_hMerge == MERGE_WITH_PREVIOUS) {
writeControlWord("clmrg");
}
//these lines added by Chris Scott, Westinghouse
//some attributes need to be writting before opening block
- if(set_center)
- {
+ if (set_center) {
writeControlWord("qc");
- }
- else if (set_right)
- {
+ } else if (set_right) {
writeControlWord("qr");
- }
- else
- {
+ } else {
writeControlWord("ql");
}
writeControlWord("cellx" + xPos);
- writeControlWord( "ql" );
+ writeControlWord("ql");
return xPos;
/** the "cell" control word marks the end of a cell */
protected void writeRtfSuffix() throws IOException {
// word97 hangs if cell does not contain at least one "par" control word
- // TODO this is what causes the extra spaces in nested table of test 004-spacing-in-tables.fo,
+ // TODO this is what causes the extra spaces in nested table of test
+ // 004-spacing-in-tables.fo,
// but if is not here we generate invalid RTF for word97
- if(set_center)
- {
+ if (set_center) {
writeControlWord("qc");
- }
- else if (set_right)
- {
+ } else if (set_right) {
writeControlWord("qr");
- }
- else
- {
+ } else {
writeControlWord("ql");
}
- if(!containsText()) {
+ if (!containsText()) {
writeControlWord("intbl");
//R.Marra this create useless paragraph
//modified by Chris Scott, Westinghouse
private void closeCurrentParagraph() throws IOException {
- if(m_paragraph!=null)
- {
+ if (m_paragraph != null) {
m_paragraph.close();
}
}
private void closeCurrentList() throws IOException {
- if(m_list!=null) m_list.close();
+ if (m_list != null) {
+ m_list.close();
+ }
}
private void closeCurrentTable() throws IOException {
- if(m_table!=null) m_table.close();
+ if (m_table != null) {
+ m_table.close();
+ }
}
private void closeCurrentExternalGraphic() throws IOException {
- if(m_externalGraphic!=null) m_externalGraphic.close();
+ if (m_externalGraphic != null) {
+ m_externalGraphic.close();
+ }
}
private void closeAll()
int extraRowIndex = 0;
RtfTableCell extraCell = null;
- for(Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
final RtfElement e = (RtfElement)it.next();
- if(e instanceof RtfTable) {
+ if (e instanceof RtfTable) {
// nested table - render its cells in supplementary rows after current row,
// and put the remaining content of this cell in a new cell after nested table
// Line added by Boris Poudérous
m_parentRow.getExtraRowSet().setParentITableColumnsInfo(((RtfTable)this.getParentOfClass(e.getClass())).getITableColumnsInfo());
- extraRowIndex = m_parentRow.getExtraRowSet().addTable((RtfTable)e,extraRowIndex,m_widthOffset);
- // Boris Poudérous added the passing of the current cell attributes to the new cells (in order not to have cell without border for example)
- extraCell = m_parentRow.getExtraRowSet().createExtraCell(extraRowIndex,m_widthOffset,this.getCellWidth(), m_attrib);
+ extraRowIndex = m_parentRow.getExtraRowSet().addTable((RtfTable)e,
+ extraRowIndex, m_widthOffset);
+ // Boris Poudérous added the passing of the current cell
+ // attributes to the new cells (in order not to have cell without
+ // border for example)
+ extraCell = m_parentRow.getExtraRowSet().createExtraCell(extraRowIndex,
+ m_widthOffset, this.getCellWidth(), m_attrib);
extraRowIndex++;
- } else if(extraCell!=null) {
+ } else if (extraCell != null) {
// we are after a nested table, add elements to the extra cell created for them
extraCell.addChild(e);
* Use containsText() to find out if there is really some useful content in the cell.
* TODO: containsText could use the original isEmpty implementation?
*/
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
return false;
}
/** true if the "par" control word must be written for given RtfParagraph
* (which is not the case for the last non-empty paragraph of the cell)
*/
- boolean paragraphNeedsPar(RtfParagraph p)
- {
+ boolean paragraphNeedsPar(RtfParagraph p) {
// true if there is at least one non-empty paragraph after p in our children
boolean pFound = false;
boolean result = false;
- for(Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
final Object o = it.next();
- if(!pFound) {
+ if (!pFound) {
// set pFound when p is found in the list
pFound = (o == p);
} else {
if (o instanceof RtfParagraph) {
final RtfParagraph p2 = (RtfParagraph)o;
- if(!p2.isEmpty()) {
+ if (!p2.isEmpty()) {
// found a non-empty paragraph after p
result = true;
break;
}
- }
- else if (o instanceof RtfTable) {
+ } else if (o instanceof RtfTable) {
break;
}
}
package org.apache.fop.rtf.rtflib.rtfdoc;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
/** Container for RtfTableCell elements
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
private RtfTableCell m_cell;
private RtfExtraRowSet m_extraRowSet;
private int id;
- private int highestCell=0;
+ private int highestCell = 0;
/** Create an RTF element as a child of given container */
RtfTableRow(RtfTable parent, Writer w, int idNum) throws IOException {
- super(parent,w);
+ super(parent, w);
id = idNum;
}
/** Create an RTF element as a child of given container */
RtfTableRow(RtfTable parent, Writer w, RtfAttributes attrs, int idNum) throws IOException {
- super(parent,w,attrs);
- id=idNum;
+ super(parent, w, attrs);
+ id = idNum;
}
/** close current cell if any and start a new one */
public RtfTableCell newTableCell(int cellWidth) throws IOException {
highestCell++;
- m_cell = new RtfTableCell(this,m_writer,cellWidth,highestCell);
+ m_cell = new RtfTableCell(this, m_writer, cellWidth, highestCell);
return m_cell;
}
/** close current cell if any and start a new one */
public RtfTableCell newTableCell(int cellWidth, RtfAttributes attrs) throws IOException {
highestCell++;
- m_cell = new RtfTableCell(this,m_writer,cellWidth, attrs,highestCell);
+ m_cell = new RtfTableCell(this, m_writer, cellWidth, attrs, highestCell);
return m_cell;
}
* in order to add an empty cell that is merged with the cell above.
* This cell is placed before or after the nested table.
*/
- public RtfTableCell newTableCellMergedVertically(int cellWidth, RtfAttributes attrs) throws IOException {
+ public RtfTableCell newTableCellMergedVertically(int cellWidth,
+ RtfAttributes attrs) throws IOException {
highestCell++;
m_cell = new RtfTableCell (this, m_writer, cellWidth, attrs, highestCell);
m_cell.setVMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
* Added by Boris POUDEROUS on 07/02/2002
* in order to add an empty cell that is merged with the previous cell.
*/
- public RtfTableCell newTableCellMergedHorizontally (int cellWidth, RtfAttributes attrs) throws IOException {
+ public RtfTableCell newTableCellMergedHorizontally (int cellWidth,
+ RtfAttributes attrs) throws IOException {
highestCell++;
// Added by Normand Masse
// Inherit attributes from base cell for merge
RtfAttributes wAttributes = (RtfAttributes)attrs.clone();
- wAttributes.unset( "number-columns-spanned" );
+ wAttributes.unset("number-columns-spanned");
- m_cell = new RtfTableCell(this,m_writer,cellWidth,wAttributes,highestCell);
+ m_cell = new RtfTableCell(this, m_writer, cellWidth, wAttributes, highestCell);
m_cell.setHMerge(RtfTableCell.MERGE_WITH_PREVIOUS);
return m_cell;
}
writeControlWord("trowd");
//check for keep-together
- if(m_attrib != null && m_attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
+ if (m_attrib != null && m_attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
writeControlWord(ROW_KEEP_TOGETHER);
}
// if we have attributes, manipulate border properties
final RtfTable parentTable = (RtfTable) m_parent;
- if(m_attrib != null && parentTable != null) {
+ if (m_attrib != null && parentTable != null) {
//if table is only one row long
- if(isFirstRow() && parentTable.isHighestRow(id)){
+ if (isFirstRow() && parentTable.isHighestRow(id)) {
m_attrib.unset(ITableAttributes.ROW_BORDER_HORIZONTAL);
//or if row is the first row
- }else if(isFirstRow()){
+ } else if (isFirstRow()) {
m_attrib.unset(ITableAttributes.ROW_BORDER_BOTTOM);
//or if row is the last row
- }else if(parentTable.isHighestRow(id)){
+ } else if (parentTable.isHighestRow(id)) {
m_attrib.unset(ITableAttributes.ROW_BORDER_TOP);
//else the row is an inside row
- }else{
+ } else {
m_attrib.unset(ITableAttributes.ROW_BORDER_BOTTOM);
m_attrib.unset(ITableAttributes.ROW_BORDER_TOP);
}
}
- writeAttributes(m_attrib,ITableAttributes.ROW_BORDER);
- writeAttributes(m_attrib,ITableAttributes.CELL_BORDER);
- writeAttributes(m_attrib,BorderAttributesConverter.BORDERS);
+ writeAttributes(m_attrib, ITableAttributes.ROW_BORDER);
+ writeAttributes(m_attrib, ITableAttributes.CELL_BORDER);
+ writeAttributes(m_attrib, BorderAttributesConverter.BORDERS);
/**
* Added by Boris POUDEROUS on 07/02/2002
int numberOfCellsBeforeNestedTable = 0;
java.util.Vector indexesFound = new java.util.Vector();
- for (Iterator it = getChildren().iterator(); it.hasNext(); )
- {
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
final RtfElement e = (RtfElement)it.next();
- if (e instanceof RtfTableCell)
- {
- if (!nestedTableFound)
- ++numberOfCellsBeforeNestedTable;
-
- for (Iterator it2 = ((RtfTableCell)e).getChildren().iterator(); it2.hasNext(); )
- {
+ if (e instanceof RtfTableCell) {
+ if (!nestedTableFound) {
+ ++numberOfCellsBeforeNestedTable;
+ }
+ for (Iterator it2 = ((RtfTableCell)e).getChildren().iterator(); it2.hasNext();) {
final RtfElement subElement = (RtfElement)it2.next();
- if (subElement instanceof RtfTable)
- {
+ if (subElement instanceof RtfTable) {
nestedTableFound = true;
indexesFound.addElement(new Integer(index));
- }
- else if (subElement instanceof RtfParagraph)
- {
- for (Iterator it3 = ((RtfParagraph)subElement).getChildren().iterator(); it3.hasNext(); )
+ } else if (subElement instanceof RtfParagraph) {
+ for (Iterator it3 =
+ ((RtfParagraph)subElement).getChildren().iterator(); it3.hasNext();)
{
final RtfElement subSubElement = (RtfElement)it3.next();
- if (subSubElement instanceof RtfTable)
- {
+ if (subSubElement instanceof RtfTable) {
nestedTableFound = true;
indexesFound.addElement(new Integer(index));
}
// write X positions of our cells
int xPos = 0;
index = 0; // Line added by Boris POUDEROUS on 07/02/2002
- for(Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ for (Iterator it = getChildren().iterator(); it.hasNext();) {
final RtfElement e = (RtfElement)it.next();
- if(e instanceof RtfTableCell) {
+ if (e instanceof RtfTableCell) {
/**
* Added by Boris POUDEROUS on 2002/07/02
*/
// If one of the row's child cells contains a nested table :
- if (!indexesFound.isEmpty())
- {
- for (int i = 0; i < indexesFound.size(); i++)
- {
+ if (!indexesFound.isEmpty()) {
+ for (int i = 0; i < indexesFound.size(); i++) {
// If the current cell index is equals to the index of the cell that
// contains a nested table => NO MERGE
- if (index == ((Integer)indexesFound.get(i)).intValue())
- break;
+ if (index == ((Integer)indexesFound.get(i)).intValue()) {
+ break;
// If the current cell index is lower than the index of the cell that
// contains a nested table => START VERTICAL MERGE
- else if (index < ((Integer)indexesFound.get(i)).intValue())
- {
+ } else if (index < ((Integer)indexesFound.get(i)).intValue()) {
((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
break;
- }
// If the current cell index is greater than the index of the cell that
// contains a nested table => START VERTICAL MERGE
- else if (index > ((Integer)indexesFound.get(i)).intValue())
- {
+ } else if (index > ((Integer)indexesFound.get(i)).intValue()) {
((RtfTableCell)e).setVMerge(RtfTableCell.MERGE_START);
break;
}
// Adjust the cell's display attributes so the table's/row's borders
// are drawn properly.
RtfTableCell cell = (RtfTableCell)e;
- if ( index == 0 ) {
- if ( !cell.getRtfAttributes().isSet( ITableAttributes.CELL_BORDER_LEFT ) ) {
- cell.getRtfAttributes().set( ITableAttributes.CELL_BORDER_LEFT,
- (String)m_attrib.getValue( ITableAttributes.ROW_BORDER_LEFT ));
+ if (index == 0) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_LEFT)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_LEFT,
+ (String)m_attrib.getValue(ITableAttributes.ROW_BORDER_LEFT));
}
}
- if ( index == this.getChildCount() -1 ) {
- if ( !cell.getRtfAttributes().isSet( ITableAttributes.CELL_BORDER_RIGHT ) ) {
- cell.getRtfAttributes().set( ITableAttributes.CELL_BORDER_RIGHT,
- (String)m_attrib.getValue( ITableAttributes.ROW_BORDER_RIGHT ));
+ if (index == this.getChildCount() - 1) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_RIGHT)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_RIGHT,
+ (String)m_attrib.getValue(ITableAttributes.ROW_BORDER_RIGHT));
}
}
- if ( isFirstRow() ) {
- if ( !cell.getRtfAttributes().isSet( ITableAttributes.CELL_BORDER_TOP ) ) {
- cell.getRtfAttributes().set( ITableAttributes.CELL_BORDER_TOP,
- (String)m_attrib.getValue( ITableAttributes.ROW_BORDER_TOP ));
+ if (isFirstRow()) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_TOP)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
+ (String)m_attrib.getValue(ITableAttributes.ROW_BORDER_TOP));
}
}
- if ( parentTable.isHighestRow(id) ) {
- if ( !cell.getRtfAttributes().isSet( ITableAttributes.CELL_BORDER_BOTTOM ) ) {
- cell.getRtfAttributes().set( ITableAttributes.CELL_BORDER_BOTTOM,
- (String)m_attrib.getValue( ITableAttributes.ROW_BORDER_BOTTOM ));
+ if (parentTable.isHighestRow(id)) {
+ if (!cell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_BOTTOM)) {
+ cell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_BOTTOM,
+ (String)m_attrib.getValue(ITableAttributes.ROW_BORDER_BOTTOM));
}
}
private void writePaddingAttributes()
throws IOException {
// Row padding attributes generated in the converter package
- // use RTF 1.6 definitions - try to compute a reasonable RTF 1.5 value out of them if present
+ // use RTF 1.6 definitions - try to compute a reasonable RTF 1.5 value
+ // out of them if present
// how to do vertical padding with RTF 1.5?
- if(m_attrib != null && !m_attrib.isSet(ATTR_RTF_15_TRGAPH)) {
+ if (m_attrib != null && !m_attrib.isSet(ATTR_RTF_15_TRGAPH)) {
int gaph = -1;
try {
// set (RTF 1.5) gaph to the average of the (RTF 1.6) left and right padding values
final Integer leftPadStr = (Integer)m_attrib.getValue(ATTR_ROW_PADDING_LEFT);
- if(leftPadStr != null) gaph = leftPadStr.intValue();
+ if (leftPadStr != null) {
+ gaph = leftPadStr.intValue();
+ }
final Integer rightPadStr = (Integer)m_attrib.getValue(ATTR_ROW_PADDING_RIGHT);
- if(rightPadStr != null) gaph = (gaph + rightPadStr.intValue()) / 2;
- } catch(Exception e) {
+ if (rightPadStr != null) {
+ gaph = (gaph + rightPadStr.intValue()) / 2;
+ }
+ } catch (Exception e) {
final String msg = "RtfTableRow.writePaddingAttributes: " + e.toString();
// getRtfFile().getLog().logWarning(msg);
}
- if(gaph >= 0) {
- m_attrib.set(ATTR_RTF_15_TRGAPH,gaph);
+ if (gaph >= 0) {
+ m_attrib.set(ATTR_RTF_15_TRGAPH, gaph);
}
}
writeAttributes(m_attrib, ATTRIB_ROW_PADDING);
}
- public boolean isFirstRow(){
- if(id == 1)
+ public boolean isFirstRow() {
+ if (id == 1) {
return true;
- else
+ } else {
return false;
+ }
}
public boolean isHighestCell(int id) {
package org.apache.fop.rtf.rtflib.rtfdoc;
-import java.util.*;
-import java.io.Writer;
import java.io.IOException;
-import java.io.File;
/**
* Singelton of the RTF style template
/**
* Constructor.
*/
- private RtfTemplate ()
- {
+ private RtfTemplate () {
}
*
* @return The instance of RtfTemplate
*/
- public static RtfTemplate getInstance ()
- {
+ public static RtfTemplate getInstance () {
if (instance == null) {
instance = new RtfTemplate();
}
**/
public void setTemplateFilePath(String templateFilePath) throws IOException {
// no validity checks here - leave this to the RTF client
- if(templateFilePath == null) {
+ if (templateFilePath == null) {
this.templateFilePath = null;
} else {
this.templateFilePath = templateFilePath.trim();
* @param header Rtf header is the parent
* @throws IOException On write error
*/
- public void writeTemplate (RtfHeader header) throws IOException
- {
- if (templateFilePath == null || templateFilePath.length() == 0) return;
+ public void writeTemplate (RtfHeader header) throws IOException {
+ if (templateFilePath == null || templateFilePath.length() == 0) {
+ return;
+ }
header.writeGroupMark (true);
header.writeControlWord ("template");
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
*/
-public class RtfText extends RtfElement
-{
+public class RtfText extends RtfElement {
// char code for non-breakable space
private static final int CHAR_NBSP = 160;
private static final int CHAR_TAB = 137;
private final RtfAttributes m_attr;
- /** RtfText attributes: attribute names are RTF control word names to avoid additional mapping */
+ /** RtfText attributes: attribute names are RTF control word names to avoid
+ * additional mapping */
public static final String ATTR_BOLD = "b";
public static final String ATTR_ITALIC = "i";
public static final String ATTR_UNDERLINE = "ul";
//this line added by Chris Scott, Westinghouse
public static String[] BORDER = new String []
{
- BDR_BOTTOM_SINGLE,BDR_BOTTOM_DOUBLE,BDR_BOTTOM_EMBOSS,BDR_BOTTOM_DOTTED,BDR_BOTTOM_DASH
+ BDR_BOTTOM_SINGLE, BDR_BOTTOM_DOUBLE, BDR_BOTTOM_EMBOSS, BDR_BOTTOM_DOTTED,
+ BDR_BOTTOM_DASH
};
public static String[] INDENT = new String []
public static String[] TABS = new String []
{
- TAB_CENTER ,TAB_RIGHT,TAB_LEADER_DOTS,TAB_LEADER_HYPHEN,TAB_LEADER_UNDER,
- TAB_LEADER_THICK,TAB_LEADER_EQUALS
+ TAB_CENTER, TAB_RIGHT, TAB_LEADER_DOTS, TAB_LEADER_HYPHEN, TAB_LEADER_UNDER,
+ TAB_LEADER_THICK, TAB_LEADER_EQUALS
};
/** Create an RtfText in given IRtfTextContainer.
* @param str optional initial text content
*/
- RtfText(IRtfTextContainer parent,Writer w,String str,RtfAttributes attr) throws IOException
- {
- super((RtfContainer)parent,w);
+ RtfText(IRtfTextContainer parent, Writer w, String str, RtfAttributes attr)
+ throws IOException {
+ super((RtfContainer)parent, w);
m_text = str;
m_attr = attr;
}
/** write our text to the RTF stream */
- public void writeRtfContent() throws IOException
- {
+ public void writeRtfContent() throws IOException {
writeChars: {
//these lines were added by Boris Pouderous
if (m_attr != null) {
- writeAttributes(m_attr,new String[] {RtfText.SPACE_BEFORE});
- writeAttributes(m_attr,new String[] {RtfText.SPACE_AFTER});
+ writeAttributes(m_attr, new String[] {RtfText.SPACE_BEFORE});
+ writeAttributes(m_attr, new String[] {RtfText.SPACE_AFTER});
}
- if(isTab()){
+ if (isTab()) {
writeControlWord("tab");
- }else if(isNewLine()){
+ } else if (isNewLine()) {
break writeChars;
- }else if(isBold(true)){
+ } else if (isBold(true)) {
writeControlWord("b");
- }else if(isBold(false)){
+ } else if (isBold(false)) {
writeControlWord("b0");
- }
- // TODO not optimal, consecutive RtfText with same attributes could be written without group marks
- else{
+ // TODO not optimal, consecutive RtfText with same attributes
+ // could be written without group marks
+ } else {
writeGroupMark(true);
- if(m_attr != null && mustWriteAttributes()) {
- writeAttributes(m_attr,RtfText.ATTR_NAMES);
+ if (m_attr != null && mustWriteAttributes()) {
+ writeAttributes(m_attr, RtfText.ATTR_NAMES);
}
- RtfStringConverter.getInstance().writeRtfString(m_writer,m_text);
+ RtfStringConverter.getInstance().writeRtfString(m_writer, m_text);
writeGroupMark(false);
}
}
/** true if our text attributes must be written */
- private boolean mustWriteAttributes()
- {
+ private boolean mustWriteAttributes() {
return !isEmpty() && !isNbsp();
}
- /** IRtfTextContainer requirement: return a copy of our attributes */
+ /** IRtfTextContainer requirement:
+ * @return a copy of our attributes */
public RtfAttributes getTextContainerAttributes() {
- if(m_attrib == null) return null;
+ if (m_attrib == null) {
+ return null;
+ }
return (RtfAttributes)this.m_attrib.clone();
}
/** direct access to our text */
- String getText()
- {
+ String getText() {
return m_text;
}
/** direct access to our text */
- void setText(String str)
- {
+ void setText(String str) {
m_text = str;
}
/**
* Checks whether the text is empty.
*
- * @return
- * true If m_text is null\n
- * false m_text is set
+ * @return true If m_text is null\n
+ * false m_text is set
*/
- public boolean isEmpty ()
- {
+ public boolean isEmpty () {
return m_text == null || m_text.trim().length() == 0;
}
/**
* True if text contains a single non-breaking space (#160).
- * TODO make this more general and/or merge with isEmpty? <-- what happen with empty paragraphs, if they will be removed, than NO, else ok
+ * TODO make this more general and/or merge with isEmpty? <-- what happen
+ * with empty paragraphs, if they will be removed, than NO, else ok
*
- * @return
- * true If m_text is character 160\n
- * false m_text is not a nbsp
+ * @return true If m_text is character 160\n
+ * false m_text is not a nbsp
*/
- public boolean isNbsp ()
- {
- if (! isEmpty ())
- if (m_text.trim ().length () == 1 && m_text.charAt (0) == CHAR_NBSP)
+ public boolean isNbsp () {
+ if (!isEmpty ()) {
+ if (m_text.trim ().length () == 1 && m_text.charAt (0) == CHAR_NBSP) {
return true;
+ }
+ }
return false;
}
- public boolean isTab()
- {
- if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_TAB)
+ public boolean isTab() {
+ if (m_text.trim().length() == 1 && m_text.charAt(0) == CHAR_TAB) {
return true;
- else
+ } else {
return false;
+ }
}
- public boolean isNewLine()
- {
- if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_NEW_LINE)
+ public boolean isNewLine() {
+ if (m_text.trim().length() == 1 && m_text.charAt(0) == CHAR_NEW_LINE) {
return true;
- else
+ } else {
return false;
+ }
}
- public boolean isBold(boolean isStart)
- {
- if(isStart){
- if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_START)
+ public boolean isBold(boolean isStart) {
+ if (isStart) {
+ if (m_text.trim().length() == 1 && m_text.charAt(0) == CHAR_BOLD_START) {
return true;
- }else{
- if(m_text.trim().length()==1 && m_text.charAt(0)== CHAR_BOLD_END)
+ }
+ } else {
+ if (m_text.trim().length() == 1 && m_text.charAt(0) == CHAR_BOLD_END) {
return true;
- else
+ } else {
return false;
+ }
}
return false;
}
- /** get the attributes of our text */
- public RtfAttributes getTextAttributes(){
+ /** @return the attributes of our text */
+ public RtfAttributes getTextAttributes() {
return m_attr;
}
}
*/
class WhitespaceCollapser {
- private final static String SPACE = " ";
- private boolean m_lastEndSpace = true;
+ private static final String SPACE = " ";
+ private boolean lastEndSpace = true;
/** remove extra whitespace in RtfText elements that are inside c */
WhitespaceCollapser(RtfContainer c) {
// process all texts
- for(Iterator it = c.getChildren().iterator(); it.hasNext(); ) {
+ for (Iterator it = c.getChildren().iterator(); it.hasNext();) {
RtfText current = null;
final Object kid = it.next();
- if(kid instanceof RtfText) {
+ if (kid instanceof RtfText) {
current = (RtfText)kid;
processText(current);
} else {
// if there is something between two texts, it counts for a space
- m_lastEndSpace = true;
+ lastEndSpace = true;
}
}
}
// tokenize the text based on whitespace and regenerate it so as
// to collapse multiple spaces into one
- if(orig != null && orig.length() > 0) {
+ if (orig != null && orig.length() > 0) {
final boolean allSpaces = orig.trim().length() == 0;
- final boolean endSpace = allSpaces || Character.isWhitespace(orig.charAt(orig.length() - 1));
+ final boolean endSpace = allSpaces
+ || Character.isWhitespace(orig.charAt(orig.length() - 1));
final boolean beginSpace = Character.isWhitespace(orig.charAt(0));
final StringBuffer sb = new StringBuffer(orig.length());
// if text contains spaces only, keep at most one
- if(allSpaces) {
- if(!m_lastEndSpace) sb.append(SPACE);
+ if (allSpaces) {
+ if (!lastEndSpace) {
+ sb.append(SPACE);
+ }
} else {
// TODO to be compatible with different Locales, should use Character.isWhitespace
// instead of this limited list
boolean first = true;
- final StringTokenizer stk = new StringTokenizer(txt.getText()," \t\n\r");
- while(stk.hasMoreTokens()) {
- if(first && beginSpace && !m_lastEndSpace) {
+ final StringTokenizer stk = new StringTokenizer(txt.getText(), " \t\n\r");
+ while (stk.hasMoreTokens()) {
+ if (first && beginSpace && !lastEndSpace) {
sb.append(SPACE);
}
first = false;
sb.append(stk.nextToken());
- if(stk.hasMoreTokens() || endSpace) {
+ if (stk.hasMoreTokens() || endSpace) {
sb.append(SPACE);
}
}
}
txt.setText(sb.toString());
- m_lastEndSpace = endSpace;
+ lastEndSpace = endSpace;
}
}
}
\ No newline at end of file