From 928a7bdbd17f541e4495a514df128061beda2c4e Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Mon, 30 Jun 2003 06:10:05 +0000 Subject: [PATCH] style changes only git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196543 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/rtf/rtflib/rtfdoc/RtfAttributes.java | 91 +++++----- .../fop/rtf/rtflib/rtfdoc/RtfBefore.java | 8 +- .../fop/rtf/rtflib/rtfdoc/RtfBookmark.java | 36 ++-- .../rtfdoc/RtfBookmarkContainerImpl.java | 12 +- .../fop/rtf/rtflib/rtfdoc/RtfColorTable.java | 70 +++----- .../fop/rtf/rtflib/rtfdoc/RtfContainer.java | 49 +++--- .../rtf/rtflib/rtfdoc/RtfDocumentArea.java | 17 +- .../fop/rtf/rtflib/rtfdoc/RtfElement.java | 72 ++++---- .../rtf/rtflib/rtfdoc/RtfExternalGraphic.java | 157 ++++++++---------- .../fop/rtf/rtflib/rtfdoc/RtfExtraRowSet.java | 126 ++++++++------ .../apache/fop/rtf/rtflib/rtfdoc/RtfFile.java | 73 ++++---- .../fop/rtf/rtflib/rtfdoc/RtfFontManager.java | 37 ++--- .../fop/rtf/rtflib/rtfdoc/RtfFontTable.java | 14 +- .../fop/rtf/rtflib/rtfdoc/RtfHeader.java | 23 ++- .../fop/rtf/rtflib/rtfdoc/RtfHyperLink.java | 52 +++--- .../fop/rtf/rtflib/rtfdoc/RtfJforCmd.java | 20 +-- .../fop/rtf/rtflib/rtfdoc/RtfLineBreak.java | 14 +- .../apache/fop/rtf/rtflib/rtfdoc/RtfList.java | 30 ++-- .../fop/rtf/rtflib/rtfdoc/RtfListItem.java | 19 ++- .../fop/rtf/rtflib/rtfdoc/RtfListTable.java | 57 +++---- .../apache/fop/rtf/rtflib/rtfdoc/RtfNull.java | 6 +- .../fop/rtf/rtflib/rtfdoc/RtfOptions.java | 7 +- .../fop/rtf/rtflib/rtfdoc/RtfPageArea.java | 19 +-- .../fop/rtf/rtflib/rtfdoc/RtfPageBreak.java | 14 +- .../fop/rtf/rtflib/rtfdoc/RtfPageNumber.java | 21 +-- .../rtflib/rtfdoc/RtfPageNumberCitation.java | 32 ++-- .../fop/rtf/rtflib/rtfdoc/RtfParagraph.java | 109 +++++++----- .../rtfdoc/RtfParagraphKeepTogether.java | 19 +-- .../fop/rtf/rtflib/rtfdoc/RtfSection.java | 54 +++--- .../rtf/rtflib/rtfdoc/RtfStringConverter.java | 40 +++-- .../rtf/rtflib/rtfdoc/RtfStyleSheetTable.java | 70 ++++---- 31 files changed, 657 insertions(+), 711 deletions(-) diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfAttributes.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfAttributes.java index ae1d0efa8..6bd6e10bc 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfAttributes.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfAttributes.java @@ -58,7 +58,8 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; @@ -68,42 +69,39 @@ import org.xml.sax.helpers.AttributesImpl; */ public class RtfAttributes -implements java.lang.Cloneable -{ +implements java.lang.Cloneable { private HashMap m_values = new HashMap(); /** set attributes from a other attributes object. * @return this object, for chaining calls */ - public RtfAttributes set (RtfAttributes attrs) - { - if (attrs != null) - { + public RtfAttributes set (RtfAttributes attrs) { + if (attrs != null) { Iterator it = attrs.nameIterator (); - while (it.hasNext ()) - { + while (it.hasNext ()) { String name = (String) it.next (); - if (attrs.getValue(name) instanceof Integer){ + if (attrs.getValue(name) instanceof Integer) { Integer value = (Integer)attrs.getValue (name); - if (value == null) + if (value == null) { set (name); - else + } else { set (name, value.intValue ()); - } - else if(attrs.getValue(name) instanceof String){ + } + } else if (attrs.getValue(name) instanceof String) { String value = (String)attrs.getValue (name); - if (value == null) + if (value == null) { set (name); - else + } else { set (name, value); - }else{ + } + } else { set (name); } } // indicate the XSL attributes used to build the Rtf attributes - setXslAttributes( attrs.getXslAttributes() ); + setXslAttributes(attrs.getXslAttributes()); } return this; } @@ -111,37 +109,33 @@ implements java.lang.Cloneable /** set an attribute that has no value. * @return this object, for chaining calls */ - public RtfAttributes set(String name) - { - m_values.put(name,null); + public RtfAttributes set(String name) { + m_values.put(name, null); return this; } /** unset an attribute that has no value * @return this object, for chaining calls */ - public RtfAttributes unset(String name) - { + public RtfAttributes unset(String name) { m_values.remove(name); return this; } /** debugging log */ - public String toString() - { + public String toString() { return m_values.toString() + "(" + super.toString() + ")"; } /** implement cloning */ - public Object clone() - { + public Object clone() { final RtfAttributes result = new RtfAttributes(); result.m_values = (HashMap)m_values.clone(); // Added by Normand Masse // indicate the XSL attributes used to build the Rtf attributes - if ( m_xsl_attributes != null ) { - result.m_xsl_attributes = new org.xml.sax.helpers.AttributesImpl( m_xsl_attributes ); + if (m_xsl_attributes != null) { + result.m_xsl_attributes = new org.xml.sax.helpers.AttributesImpl(m_xsl_attributes); } return result; @@ -150,33 +144,28 @@ implements java.lang.Cloneable /** set an attribute that has an integer value * @return this object, for chaining calls */ - public RtfAttributes set(String name,int value) - { - m_values.put(name,new Integer(value)); + public RtfAttributes set(String name, int value) { + m_values.put(name, new Integer(value)); return this; } - public RtfAttributes set(String name, String type) - { - m_values.put(name,type); + public RtfAttributes set(String name, String type) { + m_values.put(name, type); return this; } /** get the value of an attribute, null if not found */ - public Object getValue(String name) - { + public Object getValue(String name) { return m_values.get(name); } /** true if given attribute is set */ - public boolean isSet(String name) - { + public boolean isSet(String name) { return m_values.containsKey(name); } /** return an Iterator on all names that are set */ - public Iterator nameIterator() - { + public Iterator nameIterator() { return m_values.keySet().iterator(); } @@ -190,27 +179,27 @@ implements java.lang.Cloneable // Added by Normand Masse // Used for attribute inheritance - public void setXslAttributes( Attributes pAttribs ) { - if ( pAttribs == null ) { + public void setXslAttributes(Attributes pAttribs) { + if (pAttribs == null) { return; } // copy/replace the xsl attributes into the current attributes - if ( m_xsl_attributes != null ) { - for ( int i = 0; i < pAttribs.getLength(); i++ ) { - String wKey = pAttribs.getQName( i ); - int wPos = m_xsl_attributes.getIndex( wKey ); - if ( wPos == -1 ) { - ((AttributesImpl)m_xsl_attributes).addAttribute( pAttribs.getURI( i ), + if (m_xsl_attributes != null) { + for (int i = 0; i < pAttribs.getLength(); i++) { + String wKey = pAttribs.getQName(i); + int wPos = m_xsl_attributes.getIndex(wKey); + if (wPos == -1) { + ((AttributesImpl)m_xsl_attributes).addAttribute(pAttribs.getURI(i), pAttribs.getLocalName(i), pAttribs.getQName(i), pAttribs.getType(i), pAttribs.getValue(i)); } else { - ((AttributesImpl)m_xsl_attributes).setAttribute( wPos, pAttribs.getURI( i ), + ((AttributesImpl)m_xsl_attributes).setAttribute(wPos, pAttribs.getURI(i), pAttribs.getLocalName(i), pAttribs.getQName(i), pAttribs.getType(i), pAttribs.getValue(i)); } } } else { - m_xsl_attributes = new org.xml.sax.helpers.AttributesImpl( pAttribs ); + m_xsl_attributes = new org.xml.sax.helpers.AttributesImpl(pAttribs); } } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBefore.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBefore.java index 2c9112887..2fca7cde6 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBefore.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBefore.java @@ -64,17 +64,17 @@ import java.io.IOException; /** The opposite of RtfAfter */ public class RtfBefore extends RtfAfterBeforeBase { /**RtfBefore attributes*/ - public final static String HEADER = "header"; + public static final String HEADER = "header"; - public final static String[] HEADER_ATTR = new String[]{ + public static final String[] HEADER_ATTR = new String[]{ HEADER }; RtfBefore(RtfSection parent, Writer w, RtfAttributes attrs) throws IOException { - super(parent,w,attrs); + super(parent, w, attrs); } protected void writeMyAttributes() throws IOException { - writeAttributes(m_attrib,HEADER_ATTR); + writeAttributes(m_attrib, HEADER_ATTR); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java index 9ffc08188..d13129880 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmark.java @@ -67,8 +67,7 @@ import java.io.IOException; * This class belongs to the "id" attribute processing. * @author Andreas Putz */ -public class RtfBookmark extends RtfElement -{ +public class RtfBookmark extends RtfElement { ////////////////////////////////////////////////// // @@ Members ////////////////////////////////////////////////// @@ -92,15 +91,14 @@ public class RtfBookmark extends RtfElement * @param writer a Writer value * @param bookmark Name of the bookmark */ - RtfBookmark (IRtfBookmarkContainer parent, Writer w, String bookmark) throws IOException - { + RtfBookmark (IRtfBookmarkContainer parent, Writer w, String bookmark) throws IOException { super ((RtfContainer) parent, w); int now = bookmark.length (); this.bookmark = bookmark.substring (0, now < maxBookmarkLength ? now : maxBookmarkLength); - this.bookmark = this.bookmark.replace ('.',replaceCharacter); - this.bookmark = this.bookmark.replace (' ',replaceCharacter); + this.bookmark = this.bookmark.replace ('.', replaceCharacter); + this.bookmark = this.bookmark.replace (' ', replaceCharacter); } @@ -113,8 +111,7 @@ public class RtfBookmark extends RtfElement * * @throws IOException On Error */ - public void writeRtfPrefix () throws IOException - { + public void writeRtfPrefix () throws IOException { startBookmark (); } @@ -123,8 +120,7 @@ public class RtfBookmark extends RtfElement * * @exception IOException On error */ - public void writeRtfContent () throws IOException - { + public void writeRtfContent () throws IOException { // this.getRtfFile ().getLog ().logInfo ("Write bookmark '" + bookmark + "'."); // No content to write } @@ -134,8 +130,7 @@ public class RtfBookmark extends RtfElement * * @throws IOException On Error */ - public void writeRtfSuffix () throws IOException - { + public void writeRtfSuffix () throws IOException { endBookmark (); } @@ -149,8 +144,7 @@ public class RtfBookmark extends RtfElement * * @throws IOException On error */ - private void startBookmark () throws IOException - { + private void startBookmark () throws IOException { // {\*\bkmkstart test} writeRtfBookmark ("bkmkstart"); @@ -161,8 +155,7 @@ public class RtfBookmark extends RtfElement * * @throws IOException On error */ - private void endBookmark () throws IOException - { + private void endBookmark () throws IOException { // {\*\bkmkend test} writeRtfBookmark ("bkmkend"); @@ -175,10 +168,8 @@ public class RtfBookmark extends RtfElement * * @throws IOException On error */ - private void writeRtfBookmark (String tag) throws IOException - { - if (bookmark == null) - { + private void writeRtfBookmark (String tag) throws IOException { + if (bookmark == null) { return; } @@ -193,8 +184,7 @@ public class RtfBookmark extends RtfElement } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { - return bookmark==null || bookmark.trim().length() == 0; + public boolean isEmpty() { + return bookmark == null || bookmark.trim().length() == 0; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java index 32acde52f..d5f2f5649 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfBookmarkContainerImpl.java @@ -67,8 +67,7 @@ import java.io.IOException; * implemented as stand alone. * @author Andreas Putz */ -public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookmarkContainer -{ +public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookmarkContainer { ////////////////////////////////////////////////// // @@ Members ////////////////////////////////////////////////// @@ -90,8 +89,7 @@ public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookma * * @exception IOException On error */ - RtfBookmarkContainerImpl (RtfContainer parent, Writer w) throws IOException - { + RtfBookmarkContainerImpl (RtfContainer parent, Writer w) throws IOException { super (parent, w, null); } @@ -124,10 +122,8 @@ public class RtfBookmarkContainerImpl extends RtfContainer implements IRtfBookma * * @throws IOException On eror */ - public RtfBookmark newBookmark (String bookmark) throws IOException - { - if (mBookmark != null) - { + public RtfBookmark newBookmark (String bookmark) throws IOException { + if (mBookmark != null) { mBookmark.close (); } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java index 9caae552a..2b1bce0ef 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfColorTable.java @@ -60,7 +60,6 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.util.Vector; import java.util.Hashtable; -import java.awt.Color; import java.io.IOException; /** @@ -69,8 +68,7 @@ import java.io.IOException; * @author Andreas Putz */ -public class RtfColorTable -{ +public class RtfColorTable { ////////////////////////////////////////////////// // @@ Symbolic constants ////////////////////////////////////////////////// @@ -103,8 +101,7 @@ public class RtfColorTable /** * Constructor. */ - private RtfColorTable () - { + private RtfColorTable () { colorTable = new Vector (); colorIndex = new Hashtable (); namedColors = new Hashtable (); @@ -117,10 +114,8 @@ public class RtfColorTable * * @return The instance of RTFColorTable */ - public static RtfColorTable getInstance () - { - if (instance == null) - { + public static RtfColorTable getInstance () { + if (instance == null) { instance = new RtfColorTable (); } @@ -135,16 +130,15 @@ public class RtfColorTable /** * Initialize the color table. */ - private void init () - { - addNamedColor("black",getColorNumber (0, 0, 0)); - addNamedColor("white",getColorNumber (255, 255, 255)); - addNamedColor("red",getColorNumber (255, 0, 0)); - addNamedColor("green",getColorNumber (0, 255, 0)); - addNamedColor("blue",getColorNumber (0, 0, 255)); - addNamedColor("cyan",getColorNumber (0, 255, 255)); - addNamedColor("magenta",getColorNumber (255, 0, 255)); - addNamedColor("yellow",getColorNumber (255, 255, 0)); + private void init () { + addNamedColor("black", getColorNumber (0, 0, 0)); + addNamedColor("white", getColorNumber (255, 255, 255)); + addNamedColor("red", getColorNumber (255, 0, 0)); + addNamedColor("green", getColorNumber (0, 255, 0)); + addNamedColor("blue", getColorNumber (0, 0, 255)); + addNamedColor("cyan", getColorNumber (0, 255, 255)); + addNamedColor("magenta", getColorNumber (255, 0, 255)); + addNamedColor("yellow", getColorNumber (255, 255, 0)); getColorNumber (0, 0, 128); getColorNumber (0, 128, 128); @@ -156,15 +150,14 @@ public class RtfColorTable // Added by Normand Masse // Gray color added - addNamedColor( "gray", getColorNumber( 128, 128, 128 ) ); + addNamedColor("gray", getColorNumber(128, 128, 128)); getColorNumber (192, 192, 192); } /** define a named color for getColorNumber(String) */ - private void addNamedColor(String name,int colorNumber) - { - namedColors.put(name.toLowerCase(),new Integer(colorNumber)); + private void addNamedColor(String name, int colorNumber) { + namedColors.put(name.toLowerCase(), new Integer(colorNumber)); } ////////////////////////////////////////////////// @@ -174,8 +167,7 @@ public class RtfColorTable /** get the RTF number of a named color * @return null if name not found */ - public Integer getColorNumber (String name) - { + public Integer getColorNumber (String name) { return (Integer)namedColors.get(name.toLowerCase()); } @@ -188,20 +180,16 @@ public class RtfColorTable * * @return The number of the color in the table */ - public int getColorNumber (int red, int green, int blue) - { + public int getColorNumber (int red, int green, int blue) { Integer identifier = new Integer (determineIdentifier (red, green, blue)); Object o = colorIndex.get (identifier); int retVal; - if (o == null) - { + if (o == null) { addColor (identifier); retVal = colorTable.size (); - } - else - { + } else { retVal = ((Integer) o).intValue (); } @@ -215,10 +203,8 @@ public class RtfColorTable * * @throws IOException On error */ - public void writeColors (RtfHeader header) throws IOException - { - if (colorTable == null || colorTable.size () == 0) - { + public void writeColors (RtfHeader header) throws IOException { + if (colorTable == null || colorTable.size () == 0) { return; } @@ -227,8 +213,7 @@ public class RtfColorTable int len = colorTable.size (); - for (int i = 0; i < len; i++) - { + for (int i = 0; i < len; i++) { int identifier = ((Integer) colorTable.get (i)).intValue (); header.write ("\\red" + determineColorLevel (identifier, RED)); @@ -249,8 +234,7 @@ public class RtfColorTable * * @param i Identifier of color */ - private void addColor (Integer i) - { + private void addColor (Integer i) { colorIndex.put (i, new Integer (colorTable.size () + 1)); colorTable.addElement (i); } @@ -264,8 +248,7 @@ public class RtfColorTable * * @return Unique identifier of color */ - private int determineIdentifier (int red, int green, int blue) - { + private int determineIdentifier (int red, int green, int blue) { int c = red << RED; c += green << GREEN; @@ -282,8 +265,7 @@ public class RtfColorTable * * @return Color level in byte size */ - private int determineColorLevel (int identifier, int color) - { + private int determineColorLevel (int identifier, int color) { int retVal = (byte) (identifier >> color); return retVal < 0 ? retVal + 256 : retVal; diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfContainer.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfContainer.java index a661da11f..566986fcf 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfContainer.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfContainer.java @@ -59,7 +59,9 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; -import java.util.*; +import java.util.LinkedList; +import java.util.List; +import java.util.Iterator; import java.io.IOException; import org.apache.fop.rtf.rtflib.exceptions.RtfStructureException; @@ -74,12 +76,12 @@ public class RtfContainer extends RtfElement { /** Create an RTF container as a child of given container */ RtfContainer(RtfContainer parent, Writer w) throws IOException { - this(parent,w,null); + this(parent, w, null); } /** Create an RTF container as a child of given container with given attributes */ - RtfContainer(RtfContainer parent, Writer w,RtfAttributes attr) throws IOException { - super(parent,w,attr); + RtfContainer(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException { + super(parent, w, attr); m_children = new LinkedList(); } @@ -91,7 +93,7 @@ public class RtfContainer extends RtfElement { /** add a child element to this */ protected void addChild(RtfElement e) throws RtfStructureException { - if(isClosed()) { + if (isClosed()) { // No childs should be added to a container that has been closed final StringBuffer sb = new StringBuffer(); sb.append("addChild: container already closed (parent="); @@ -132,10 +134,8 @@ public class RtfContainer extends RtfElement { * Add by Boris Poudérous on 07/22/2002 * Set the children list */ - public boolean setChildren (List children) - { - if (children instanceof LinkedList) - { + public boolean setChildren (List children) { + if (children instanceof LinkedList) { this.m_children = (LinkedList)children; return true; } @@ -146,7 +146,7 @@ public class RtfContainer extends RtfElement { /** write RTF code of all our children */ protected void writeRtfContent() throws IOException { - for(Iterator it = m_children.iterator(); it.hasNext(); ) { + for (Iterator it = m_children.iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); e.writeRtf(); } @@ -160,27 +160,29 @@ public class RtfContainer extends RtfElement { /** true if this (recursively) contains at least one RtfText object */ boolean containsText() { boolean result = false; - for(Iterator it = m_children.iterator(); it.hasNext(); ) { + for (Iterator it = m_children.iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); - if(e instanceof RtfText) { + if (e instanceof RtfText) { result = !e.isEmpty(); - } else if(e instanceof RtfContainer) { - if(((RtfContainer)e).containsText()) { + } else if (e instanceof RtfContainer) { + if (((RtfContainer)e).containsText()) { result = true; } } - if(result) break; + if (result) { + break; + } } return result; } /** debugging to given Writer */ - void dump(Writer w,int indent) + void dump(Writer w, int indent) throws IOException { - super.dump(w,indent); - for(Iterator it = m_children.iterator(); it.hasNext(); ) { + super.dump(w, indent); + for (Iterator it = m_children.iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); - e.dump(w,indent + 1); + e.dump(w, indent + 1); } } @@ -192,7 +194,7 @@ public class RtfContainer extends RtfElement { /** don't write any RTF if empty of if our options block it */ protected boolean okToWriteRtf() { boolean result = super.okToWriteRtf() && !isEmpty(); - if(result && !m_options.renderContainer(this)) { + if (result && !m_options.renderContainer(this)) { result = false; } return result; @@ -201,12 +203,11 @@ public class RtfContainer extends RtfElement { /** true if this element would generate no "useful" RTF content. * For an RtfContainer, true if it has no children where isEmpty() is false */ - public boolean isEmpty() - { + public boolean isEmpty() { boolean result = true; - for(Iterator it = m_children.iterator(); it.hasNext(); ) { + for (Iterator it = m_children.iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); - if(!e.isEmpty()) { + if (!e.isEmpty()) { result = false; break; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfDocumentArea.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfDocumentArea.java index a08e542cc..1da3472c5 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfDocumentArea.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfDocumentArea.java @@ -66,21 +66,20 @@ import java.io.IOException; */ public class RtfDocumentArea -extends RtfContainer -{ +extends RtfContainer { private RtfSection m_currentSection; /** Create an RTF element as a child of given container */ - RtfDocumentArea(RtfFile f,Writer w) throws IOException - { - super(f,w); + RtfDocumentArea(RtfFile f, Writer w) throws IOException { + super(f, w); } /** close current RtfSection if any and create a new one */ - public RtfSection newSection() throws IOException - { - if(m_currentSection != null) m_currentSection.close(); - m_currentSection = new RtfSection(this,m_writer); + public RtfSection newSection() throws IOException { + if (m_currentSection != null) { + m_currentSection.close(); + } + m_currentSection = new RtfSection(this, m_writer); return m_currentSection; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfElement.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfElement.java index 421ec2a31..f87621306 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfElement.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfElement.java @@ -58,10 +58,10 @@ 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.jfor.main.JForVersionInfo; -import org.xml.sax.Attributes; /** Base class for all elements of an RTF file. * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch @@ -77,18 +77,20 @@ public abstract class RtfElement { private static int m_idCounter; /** Create an RTF element as a child of given container */ - RtfElement(RtfContainer parent,Writer w) throws IOException { - this(parent,w,null); + RtfElement(RtfContainer parent, Writer w) throws IOException { + this(parent, w, null); } /** Create an RTF element as a child of given container with given attributes */ - RtfElement(RtfContainer parent,Writer w,RtfAttributes attr) throws IOException { + RtfElement(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException { m_id = m_idCounter++; m_parent = parent; m_attrib = (attr != null ? attr : new RtfAttributes()); - if(m_parent != null) m_parent.addChild(this); + if (m_parent != null) { + m_parent.addChild(this); + } m_writer = w; m_written = false; } @@ -101,9 +103,9 @@ public abstract class RtfElement { /** write the RTF code of this element to our Writer */ public final void writeRtf() throws IOException { - if(!m_written) { + if (!m_written) { m_written = true; - if(okToWriteRtf()) { + if (okToWriteRtf()) { writeRtfPrefix(); writeRtfContent(); writeRtfSuffix(); @@ -162,49 +164,51 @@ public abstract class RtfElement { /** write given attribute values to our Writer * @param nameList if given, only attribute names from this list are considered */ - protected void writeAttributes(RtfAttributes attr,String [] nameList) + protected void writeAttributes(RtfAttributes attr, String [] nameList) throws IOException { - if(attr==null) return; + if (attr == null) { + return; + } - if(nameList != null) { + if (nameList != null) { // process only given attribute names - for(int i=0; i < nameList.length; i++) { + for (int i = 0; i < nameList.length; i++) { final String name = nameList[i]; - if(attr.isSet(name)) { - writeOneAttribute(name,attr.getValue(name)); + if (attr.isSet(name)) { + writeOneAttribute(name, attr.getValue(name)); } } } else { // process all defined attributes - for(Iterator it = attr.nameIterator(); it.hasNext(); ) { + for (Iterator it = attr.nameIterator(); it.hasNext();) { final String name = (String)it.next(); - if(attr.isSet(name)) { - writeOneAttribute(name,attr.getValue(name)); + if (attr.isSet(name)) { + writeOneAttribute(name, attr.getValue(name)); } } } } /** write one attribute to our Writer */ - protected void writeOneAttribute(String name,Object value) + protected void writeOneAttribute(String name, Object value) throws IOException { String cw = name; - if(value instanceof Integer) { + if (value instanceof Integer) { // attribute has integer value, must write control word + value cw += value; - }else if(value instanceof String){ + } else if (value instanceof String) { cw += value; } writeControlWord(cw); } /** write one attribute to our Writer without a space*/ - protected void writeOneAttributeNS(String name,Object value) + protected void writeOneAttributeNS(String name, Object value) throws IOException { String cw = name; - if(value instanceof Integer) { + if (value instanceof Integer) { // attribute has integer value, must write control word + value cw += value; - }else if(value instanceof String){ + } else if (value instanceof String) { cw += value; } writeControlWordNS(cw); @@ -216,9 +220,9 @@ public abstract class RtfElement { } /** debugging to given PrintWriter */ - void dump(Writer w,int indent) + void dump(Writer w, int indent) throws IOException { - for(int i=0; i < indent; i++) { + for (int i = 0; i < indent; i++) { w.write(' '); } w.write(this.toString()); @@ -240,7 +244,7 @@ public abstract class RtfElement { RtfFile getRtfFile() { // go up the chain of parents until we find the topmost one RtfElement result = this; - while(result.m_parent != null) { + while (result.m_parent != null) { result = result.m_parent; } @@ -252,13 +256,12 @@ public abstract class RtfElement { /** find the first parent where c.isAssignableFrom(parent.getClass()) is true * @return null if not found */ - RtfElement getParentOfClass(Class c) - { + RtfElement getParentOfClass(Class c) { RtfElement result = null; RtfElement current = this; - while(current.m_parent != null) { + while (current.m_parent != null) { current = current.m_parent; - if(c.isAssignableFrom(current.getClass())) { + if (c.isAssignableFrom(current.getClass())) { result = current; break; } @@ -277,11 +280,12 @@ public abstract class RtfElement { // make the exception message stand out so that the problem is visible writeControlWord("fs48"); -// RtfStringConverter.getInstance().writeRtfString(m_writer,JForVersionInfo.getShortVersionInfo() + ": "); - RtfStringConverter.getInstance().writeRtfString(m_writer,ie.getClass().getName()); +// RtfStringConverter.getInstance().writeRtfString(m_writer, +// JForVersionInfo.getShortVersionInfo() + ": "); + RtfStringConverter.getInstance().writeRtfString(m_writer, ie.getClass().getName()); writeControlWord("fs20"); - RtfStringConverter.getInstance().writeRtfString(m_writer," " + ie.toString()); + RtfStringConverter.getInstance().writeRtfString(m_writer, " " + ie.toString()); writeControlWord("par"); writeGroupMark(false); diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java index c9fe0b7eb..988efc2cd 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExternalGraphic.java @@ -58,28 +58,20 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import org.apache.fop.rtf.rtflib.rtfdoc.RtfElement; -import org.apache.fop.rtf.rtflib.rtfdoc.RtfContainer; -import org.apache.fop.rtf.rtflib.rtfdoc.RtfAttributes; - import org.apache.fop.rtf.rtflib.tools.ImageConstants; import org.apache.fop.rtf.rtflib.tools.ImageUtil; //import org.apache.fop.rtf.rtflib.tools.jpeg.Encoder; //import org.apache.fop.rtf.rtflib.tools.jpeg.JPEGException; import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.InputStreamReader; import java.io.ByteArrayOutputStream; -import java.io.InputStream; import java.io.IOException; import java.io.Writer; import java.io.File; import java.net.URL; import java.net.MalformedURLException; -import java.util.Hashtable; /** * Creates an RTF image from an external graphic file. @@ -101,13 +93,10 @@ import java.util.Hashtable; * @author Gianugo Rabellino gianugo@rabellino.it */ -public class RtfExternalGraphic extends RtfElement -{ +public class RtfExternalGraphic extends RtfElement { /** Exception thrown when an image file/URL cannot be read */ - public static class ExternalGraphicException extends IOException - { - ExternalGraphicException(String reason) - { + public static class ExternalGraphicException extends IOException { + ExternalGraphicException(String reason) { super(reason); } } @@ -212,7 +201,7 @@ public class RtfExternalGraphic extends RtfElement protected void writeRtfContent() throws IOException { try { writeRtfContentWithException(); - } catch(ExternalGraphicException ie) { + } catch (ExternalGraphicException ie) { writeExceptionInRtf(ie); } } @@ -230,17 +219,17 @@ public class RtfExternalGraphic extends RtfElement if (url == null) { - throw new ExternalGraphicException("The attribute 'url' of is null."); + throw new ExternalGraphicException("The attribute 'url' of " + + " is null."); } - String linkToRoot = System.getProperty( "jfor_link_to_root" ); - if (linkToRoot != null) - { - m_writer.write( "{\\field {\\* \\fldinst { INCLUDEPICTURE \"" ); - m_writer.write( linkToRoot ); - File urlFile = new File( url.getFile() ); - m_writer.write( urlFile.getName() ); - m_writer.write( "\" \\\\* MERGEFORMAT \\\\d }}}" ); + String linkToRoot = System.getProperty("jfor_link_to_root"); + if (linkToRoot != null) { + m_writer.write("{\\field {\\* \\fldinst { INCLUDEPICTURE \""); + m_writer.write(linkToRoot); + File urlFile = new File(url.getFile()); + m_writer.write(urlFile.getName()); + m_writer.write("\" \\\\* MERGEFORMAT \\\\d }}}"); return; } @@ -248,21 +237,23 @@ public class RtfExternalGraphic extends RtfElement byte[] data = null; - try - { - // image reading patch provided by Michael Krause - final BufferedInputStream bin = new BufferedInputStream(url.openStream()); - final ByteArrayOutputStream bout = new ByteArrayOutputStream(); - while (true) { - final int datum = bin.read(); - if (datum == -1) break; - bout.write(datum); + try { + // image reading patch provided by Michael Krause + final BufferedInputStream bin = new BufferedInputStream(url.openStream()); + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + while (true) { + final int datum = bin.read(); + if (datum == -1) { + break; + } + bout.write(datum); } bout.flush(); data = bout.toByteArray(); - } - catch (Exception e) { - throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + url + "' (" + e + ")"); + } catch (Exception e) { + throw new ExternalGraphicException("The attribute 'src' of " + + " has a invalid value: '" + + url + "' (" + e + ")"); } if (data == null) { @@ -288,20 +279,23 @@ public class RtfExternalGraphic extends RtfElement // type = to; // } // catch (JPEGException e) { -// e.setMessage("Image from tag could not be created (src = '" + url + "'"); +// e.setMessage("Image from tag could " +// + "not be created (src = '" + url + "'"); // } // finally { out.close(); // } - } - else { + } else { type = ImageConstants.I_NOT_SUPPORTED; } } if (type == ImageConstants.I_NOT_SUPPORTED) { - throw new ExternalGraphicException("The tag does not support " + file.substring(file.lastIndexOf(".") + 1) + " - image type."); + throw new ExternalGraphicException("The tag " + + "does not support " + + file.substring(file.lastIndexOf(".") + 1) + + " - image type."); } String rtfImageCode = ImageConstants.RTF_TAGS [type]; @@ -320,20 +314,22 @@ public class RtfExternalGraphic extends RtfElement if (type == ImageConstants.I_PNG) { width = ImageUtil.getIntFromByteArray(data, 16, 4, true); height = ImageUtil.getIntFromByteArray(data, 20, 4, true); - } - else if (type == ImageConstants.I_JPG) { + } else if (type == ImageConstants.I_JPG) { int basis = -1; byte ff = (byte) 0xff; byte c0 = (byte) 0xc0; for (int i = 0; i < data.length; i++) { byte b = data[i]; - if (b != ff) + if (b != ff) { continue; - if (i == data.length - 1) + } + if (i == data.length - 1) { continue; + } b = data[i + 1]; - if (b != c0) + if (b != c0) { continue; + } basis = i + 5; break; } @@ -342,8 +338,7 @@ public class RtfExternalGraphic extends RtfElement width = ImageUtil.getIntFromByteArray(data, basis + 2, 2, true); height = ImageUtil.getIntFromByteArray(data, basis, 2, true); } - } - else if (type == ImageConstants.I_EMF) { + } else if (type == ImageConstants.I_EMF) { width = ImageUtil.getIntFromByteArray(data, 151, 4, false); height = ImageUtil.getIntFromByteArray(data, 155, 4, false); } @@ -359,18 +354,15 @@ public class RtfExternalGraphic extends RtfElement if (widthDesired != -1) { if (perCentW) { writeControlWord("picscalex" + widthDesired); - } - else { + } else { writeControlWord("picscalex" + widthDesired * 100 / width); } writeControlWord("picwgoal" + widthDesired); - } - else if (scaleUniform && heightDesired != -1) { + } else if (scaleUniform && heightDesired != -1) { if (perCentH) { writeControlWord("picscalex" + heightDesired); - } - else { + } else { writeControlWord("picscalex" + heightDesired * 100 / height); } } @@ -378,18 +370,15 @@ public class RtfExternalGraphic extends RtfElement if (heightDesired != -1) { if (perCentH) { writeControlWord("picscaley" + heightDesired); - } - else { + } else { writeControlWord("picscaley" + heightDesired * 100 / height); } writeControlWord("pichgoal" + heightDesired); - } - else if (scaleUniform && widthDesired != -1) { + } else if (scaleUniform && widthDesired != -1) { if (perCentW) { writeControlWord("picscaley" + widthDesired); - } - else { + } else { writeControlWord("picscaley" + widthDesired * 100 / width); } } @@ -398,8 +387,9 @@ public class RtfExternalGraphic extends RtfElement int iData = data [i]; // Make positive byte - if (iData < 0) + if (iData < 0) { iData += 256; + } if (iData < 16) { // Set leading zero and append @@ -465,22 +455,17 @@ public class RtfExternalGraphic extends RtfElement * @param urlString Image url like "file://..." * @throws IOException On error */ - public void setURL(String urlString) throws IOException - { + public void setURL(String urlString) throws IOException { URL tmpUrl = null; - try - { + try { tmpUrl = new URL (urlString); - } - catch (MalformedURLException e) - { - try - { + } catch (MalformedURLException e) { + try { tmpUrl = new File (urlString).toURL (); - } - catch (MalformedURLException ee) - { - throw new ExternalGraphicException("The attribute 'src' of has a invalid value: '" + urlString + "' (" + ee + ")"); + } catch (MalformedURLException ee) { + throw new ExternalGraphicException("The attribute 'src' of " + + " has a invalid value: '" + + urlString + "' (" + ee + ")"); } } this.url = tmpUrl; @@ -490,8 +475,7 @@ public class RtfExternalGraphic extends RtfElement * Gets the compression rate for the image in percent. * @return Compression rate */ - public int getCompressionRate () - { + public int getCompressionRate () { return graphicCompressionRate; } @@ -503,10 +487,10 @@ public class RtfExternalGraphic extends RtfElement * true: The compression rate is valid (0..100)\n * false: The compression rate is invalid */ - public boolean setCompressionRate (int percent) - { - if (percent < 1 || percent > 100) + public boolean setCompressionRate (int percent) { + if (percent < 1 || percent > 100) { return false; + } graphicCompressionRate = percent; return true; @@ -611,17 +595,13 @@ public class RtfExternalGraphic extends RtfElement if (isPNG(data)) { type = ImageConstants.I_PNG; - } - else if (isJPEG(data)) { + } else if (isJPEG(data)) { type = ImageConstants.I_JPG_C; - } - else if (isEMF(data)) { + } else if (isEMF(data)) { type = ImageConstants.I_EMF; - } - else if (isGIF(data)) { + } else if (isGIF(data)) { type = ImageConstants.I_GIF; - } - else { + } else { Object tmp = ImageConstants.SUPPORTED_IMAGE_TYPES.get(ext.toLowerCase()); if (tmp != null) { type = ((Integer) tmp).intValue(); @@ -632,8 +612,7 @@ public class RtfExternalGraphic extends RtfElement } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { - return url==null; + public boolean isEmpty() { + return url == null; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExtraRowSet.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExtraRowSet.java index de7069dd8..6c326a224 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExtraRowSet.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfExtraRowSet.java @@ -58,8 +58,13 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.io.*; -import java.util.*; +//import java.io.*; +import java.io.Writer; +import java.io.IOException; +import java.util.List; +import java.util.LinkedList; +import java.util.Iterator; +import java.util.Collections; import org.apache.fop.rtf.rtflib.interfaces.ITableColumnsInfo; @@ -95,7 +100,7 @@ public class RtfExtraRowSet extends RtfContainer { final int xOffset; final int rowIndex; - PositionedCell(RtfTableCell c,int index,int offset) { + PositionedCell(RtfTableCell c, int index, int offset) { cell = c; xOffset = offset; rowIndex = index; @@ -109,19 +114,19 @@ public class RtfExtraRowSet extends RtfContainer { /** cells need to be sorted by row index and then by x offset */ public int compareTo(Object o) { int result = 0; - if(o==null) { + if (o == null) { result = 1; - } else if( !(o instanceof PositionedCell)) { + } else if (!(o instanceof PositionedCell)) { result = 1; } else { final PositionedCell pc = (PositionedCell)o; - if(this.rowIndex < pc.rowIndex) { + if (this.rowIndex < pc.rowIndex) { result = -1; - } else if(this.rowIndex > pc.rowIndex) { + } else if (this.rowIndex > pc.rowIndex) { result = 1; - } else if(this.xOffset < pc.xOffset) { + } else if (this.xOffset < pc.xOffset) { result = -1; - } else if(this.xOffset > pc.xOffset) { + } else if (this.xOffset > pc.xOffset) { result = 1; } } @@ -130,7 +135,7 @@ public class RtfExtraRowSet extends RtfContainer { } public boolean equals(Object o) { - return o!=null && this.compareTo(o) == 0; + return o != null && this.compareTo(o) == 0; } } @@ -142,7 +147,7 @@ public class RtfExtraRowSet extends RtfContainer { */ RtfExtraRowSet(Writer w) throws IOException { - super(null,w); + super(null, w); } /** Add all cells of given Table to this set for later rendering in extra rows @@ -150,38 +155,41 @@ public class RtfExtraRowSet extends RtfContainer { * @param rowIndex index of first extra row to create to hold cells of tbl * @param xOffset horizontal position of left edge of first column of tbl */ - int addTable(RtfTable tbl,int rowIndex,int xOffset) { + int addTable(RtfTable tbl, int rowIndex, int xOffset) { // process all rows of the table - for(Iterator it = tbl.getChildren().iterator(); it.hasNext(); ) { + for (Iterator it = tbl.getChildren().iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); - if(e instanceof RtfTableRow) { - addRow((RtfTableRow)e,rowIndex,xOffset); + if (e instanceof RtfTableRow) { + addRow((RtfTableRow)e, rowIndex, xOffset); rowIndex++; - m_maxRowIndex = Math.max(rowIndex,m_maxRowIndex); + m_maxRowIndex = Math.max(rowIndex, m_maxRowIndex); } } return rowIndex; } /** add all cells of given row to this set */ - private void addRow(RtfTableRow row,int rowIndex,int xOffset) { - for(Iterator it = row.getChildren().iterator(); it.hasNext(); ) { + private void addRow(RtfTableRow row, int rowIndex, int xOffset) { + for (Iterator it = row.getChildren().iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); - if(e instanceof RtfTableCell) { + if (e instanceof RtfTableCell) { final RtfTableCell c = (RtfTableCell)e; - m_cells.add(new PositionedCell(c,rowIndex,xOffset)); + m_cells.add(new PositionedCell(c, rowIndex, xOffset)); xOffset += c.getCellWidth(); } } } /** create an extra cell to hold content that comes after a nested table in a cell - * Modified by Boris Poudérous in order to permit the extra cell to have the attributes of its parent cell + * Modified by Boris Poudérous in order to permit the extra cell to have + * the attributes of its parent cell */ - RtfTableCell createExtraCell(int rowIndex,int xOffset,int cellWidth,RtfAttributes parentCellAttributes) + RtfTableCell createExtraCell(int rowIndex, int xOffset, int cellWidth, + RtfAttributes parentCellAttributes) throws IOException { - final RtfTableCell c = new RtfTableCell(null,m_writer,cellWidth,parentCellAttributes,DEFAULT_IDNUM); - m_cells.add(new PositionedCell(c,rowIndex,xOffset)); + final RtfTableCell c = new RtfTableCell(null, m_writer, cellWidth, + parentCellAttributes, DEFAULT_IDNUM); + m_cells.add(new PositionedCell(c, rowIndex, xOffset)); return c; } @@ -193,11 +201,13 @@ public class RtfExtraRowSet extends RtfContainer { // process all extra cells by rendering them into extra rows List rowCells = null; int rowIndex = -1; - for(Iterator it = m_cells.iterator(); it.hasNext(); ) { + for (Iterator it = m_cells.iterator(); it.hasNext();) { final PositionedCell pc = (PositionedCell)it.next(); - if(pc.rowIndex != rowIndex) { + if (pc.rowIndex != rowIndex) { // starting a new row, render previous one - if(rowCells!=null) writeRow(rowCells); + if (rowCells != null) { + writeRow(rowCells); + } rowIndex = pc.rowIndex; rowCells = new LinkedList(); } @@ -205,15 +215,19 @@ public class RtfExtraRowSet extends RtfContainer { } // render last row - if(rowCells!=null) writeRow(rowCells); + if (rowCells != null) { + writeRow(rowCells); + } } /** write one RtfTableRow containing given PositionedCells */ private void writeRow(List cells) throws IOException { - if(allCellsEmpty(cells)) return; + if (allCellsEmpty(cells)) { + return; + } - final RtfTableRow row = new RtfTableRow(null,m_writer,DEFAULT_IDNUM); + final RtfTableRow row = new RtfTableRow(null, m_writer, DEFAULT_IDNUM); int cellIndex = 0; // Get the context of the table that holds the nested table @@ -224,25 +238,27 @@ public class RtfExtraRowSet extends RtfContainer { float xOffset = 0; float xOffsetOfLastPositionedCell = 0; - for(Iterator it = cells.iterator(); it.hasNext(); ) { + for (Iterator it = cells.iterator(); it.hasNext();) { final PositionedCell pc = (PositionedCell)it.next(); // if first cell is not at offset 0, add placeholder cell // TODO should be merged with the cell that is above it - if(cellIndex==0 && pc.xOffset > 0) { + if (cellIndex == 0 && pc.xOffset > 0) { /** * Added by Boris Poudérous */ // Add empty cells merged vertically with the cells above and with the same widths // (BEFORE the cell that contains the nested table) - for (int i = 0; (xOffset < pc.xOffset) && (i < parentITableColumnsInfo.getNumberOfColumns()); i++) { - // Get the width of the cell above - xOffset += parentITableColumnsInfo.getColumnWidth(); - // Create the empty cell merged vertically - row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(), pc.cell.m_attrib); - // Select next column in order to have its width - parentITableColumnsInfo.selectNextColumn(); - } + for (int i = 0; (xOffset < pc.xOffset) + && (i < parentITableColumnsInfo.getNumberOfColumns()); i++) { + // Get the width of the cell above + xOffset += parentITableColumnsInfo.getColumnWidth(); + // Create the empty cell merged vertically + row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(), + pc.cell.m_attrib); + // Select next column in order to have its width + parentITableColumnsInfo.selectNextColumn(); + } } row.addChild(pc.cell); @@ -254,18 +270,22 @@ public class RtfExtraRowSet extends RtfContainer { /** * Added by Boris Poudérous */ - // Add empty cells merged vertically with the cells above AFTER the cell that contains the nested table + // Add empty cells merged vertically with the cells above AFTER the cell + // that contains the nested table // The cells added have the same widths than the cells above. - if (parentITableColumnsInfo.getColumnIndex() < (parentITableColumnsInfo.getNumberOfColumns() - 1)) - { + if (parentITableColumnsInfo.getColumnIndex() + < (parentITableColumnsInfo.getNumberOfColumns() - 1)) { parentITableColumnsInfo.selectNextColumn(); - while (parentITableColumnsInfo.getColumnIndex() < parentITableColumnsInfo.getNumberOfColumns()) - { + while (parentITableColumnsInfo.getColumnIndex() + < parentITableColumnsInfo.getNumberOfColumns()) { // Create the empty cell merged vertically - // TODO : the new cells after the extra cell don't have its attributes as we did for the previous cells. - // => in fact the m_attrib below (last argument) is empty => should be the attributes of the above cells. - row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(), m_attrib); + // TODO : the new cells after the extra cell don't have its + // attributes as we did for the previous cells. + // => in fact the m_attrib below (last argument) is + // empty => should be the attributes of the above cells. + row.newTableCellMergedVertically((int)parentITableColumnsInfo.getColumnWidth(), + m_attrib); // Select next column in order to have its width parentITableColumnsInfo.selectNextColumn(); } @@ -279,9 +299,9 @@ public class RtfExtraRowSet extends RtfContainer { */ private static boolean allCellsEmpty(List cells) { boolean empty = true; - for(Iterator it = cells.iterator(); it.hasNext(); ) { + for (Iterator it = cells.iterator(); it.hasNext();) { final PositionedCell pc = (PositionedCell)it.next(); - if(pc.cell.containsText()) { + if (pc.cell.containsText()) { empty = false; break; } @@ -301,13 +321,11 @@ public class RtfExtraRowSet extends RtfContainer { * @return The table context of the parent table * Added by Boris Poudérous on july 2002 in order to process nested tables */ - public ITableColumnsInfo getParentITableColumnsInfo() - { + public ITableColumnsInfo getParentITableColumnsInfo() { return this.parentITableColumnsInfo; } - public void setParentITableColumnsInfo (ITableColumnsInfo parentITableColumnsInfo) - { + public void setParentITableColumnsInfo (ITableColumnsInfo parentITableColumnsInfo) { this.parentITableColumnsInfo = parentITableColumnsInfo; } /** - end - */ diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java index 969c867e7..8e2d78f29 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFile.java @@ -60,7 +60,12 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import org.apache.fop.rtf.rtflib.exceptions.RtfStructureException; //import org.apache.fop.rtf.rtflib.jfor.converter.ConverterLogChannel; -import java.io.*; +//import java.io.*; +import java.io.Writer; +import java.io.IOException; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.OutputStreamWriter; /** Models the top-level structure of an RTF file. * @see RtfFileExample @@ -77,11 +82,11 @@ extends RtfContainer { private RtfDocumentArea m_docArea; // private ConverterLogChannel m_log; private RtfContainer m_listTableContainer; - private int listNum=0; + private int listNum = 0; /** Create an RTF file that outputs to the given Writer */ public RtfFile(Writer w) throws IOException { - super(null,w); + super(null, w); } /** optional log channel */ @@ -104,17 +109,19 @@ extends RtfContainer { /** If called, must be called before startDocumentArea */ public RtfHeader startHeader() throws IOException { - if(m_header!=null) throw new RtfStructureException("startHeader called more than once"); - m_header = new RtfHeader(this,m_writer); - m_listTableContainer = new RtfContainer(this,m_writer); + if (m_header != null) { + throw new RtfStructureException("startHeader called more than once"); + } + m_header = new RtfHeader(this, m_writer); + m_listTableContainer = new RtfContainer(this, m_writer); return m_header; } /** Creates the list table.*/ public RtfListTable startListTable(RtfAttributes attr) - throws IOException{ + throws IOException { listNum++; - m_listTable = new RtfListTable(this,m_writer,new Integer(listNum),attr); + m_listTable = new RtfListTable(this, m_writer, new Integer(listNum), attr); m_listTableContainer.addChild(m_listTable); return m_listTable; } @@ -124,20 +131,26 @@ extends RtfContainer { must be able to have multiple page definition, and corresponding Document areas */ public RtfPageArea startPageArea() - throws IOException,RtfStructureException { - if(m_pageArea!=null) throw new RtfStructureException("startPageArea called more than once"); + throws IOException, RtfStructureException { + if (m_pageArea != null) { + throw new RtfStructureException("startPageArea called more than once"); + } // create an empty header if there was none - if(m_header==null) startHeader(); + if (m_header == null) { + startHeader(); + } m_header.close(); - m_pageArea = new RtfPageArea(this,m_writer); + m_pageArea = new RtfPageArea(this, m_writer); addChild(m_pageArea); return m_pageArea; } /** Call startPageArea if needed and return the page area object. */ public RtfPageArea getPageArea() - throws IOException,RtfStructureException { - if(m_pageArea== null) return startPageArea(); + throws IOException, RtfStructureException { + if (m_pageArea == null) { + return startPageArea(); + } return m_pageArea; } @@ -145,12 +158,16 @@ extends RtfContainer { * Must be called once only. */ public RtfDocumentArea startDocumentArea() - throws IOException,RtfStructureException { - if(m_docArea!=null) throw new RtfStructureException("startDocumentArea called more than once"); + throws IOException, RtfStructureException { + if (m_docArea != null) { + throw new RtfStructureException("startDocumentArea called more than once"); + } // create an empty header if there was none - if(m_header==null) startHeader(); + if (m_header == null) { + startHeader(); + } m_header.close(); - m_docArea = new RtfDocumentArea(this,m_writer); + m_docArea = new RtfDocumentArea(this, m_writer); addChild(m_docArea); return m_docArea; } @@ -159,21 +176,21 @@ extends RtfContainer { /** Call startDocumentArea if needed and return the document area object. */ public RtfDocumentArea getDocumentArea() - throws IOException,RtfStructureException { - if(m_docArea == null) return startDocumentArea(); + throws IOException, RtfStructureException { + if (m_docArea == null) { + return startDocumentArea(); + } return m_docArea; } /** overridden to write RTF prefix code, what comes before our children */ - protected void writeRtfPrefix() throws IOException - { + protected void writeRtfPrefix() throws IOException { writeGroupMark(true); writeControlWord("rtf1"); } /** overridden to write RTF suffix code, what comes after our children */ - protected void writeRtfSuffix() throws IOException - { + protected void writeRtfSuffix() throws IOException { writeGroupMark(false); } @@ -187,7 +204,7 @@ extends RtfContainer { public static void main(String args[]) throws Exception { Writer w = null; - if(args.length != 0) { + if (args.length != 0) { final String outFile = args[0]; System.err.println("Outputting RTF to file '" + outFile + "'"); w = new BufferedWriter(new FileWriter(outFile)); @@ -200,12 +217,12 @@ extends RtfContainer { final RtfSection sect = f.startDocumentArea().newSection(); final RtfParagraph p = sect.newParagraph(); - p.newText("Hello, RTF world.\n",null); + p.newText("Hello, RTF world.\n", null); final RtfAttributes attr = new RtfAttributes(); attr.set(RtfText.ATTR_BOLD); attr.set(RtfText.ATTR_ITALIC); - attr.set(RtfText.ATTR_FONT_SIZE,36); - p.newText("This is bold, italic, 36 points",attr); + attr.set(RtfText.ATTR_FONT_SIZE, 36); + p.newText("This is bold, italic, 36 points", attr); f.flush(); System.err.println("RtfFile test: all done."); diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java index 92d7a9555..e17f219c6 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontManager.java @@ -66,8 +66,7 @@ import java.util.Vector; * RTF font table * @author Andreas Putz a.putz@skynamics.com */ -public class RtfFontManager -{ +public class RtfFontManager { ////////////////////////////////////////////////// // @@ Members ////////////////////////////////////////////////// @@ -88,8 +87,7 @@ public class RtfFontManager /** * Constructor. */ - private RtfFontManager () - { + private RtfFontManager () { fontTable = new Vector (); fontIndex = new Hashtable (); @@ -101,10 +99,8 @@ public class RtfFontManager * * @return The instance of RtfFontManager */ - public static RtfFontManager getInstance () - { - if (instance == null) - { + public static RtfFontManager getInstance () { + if (instance == null) { instance = new RtfFontManager (); } @@ -119,8 +115,7 @@ public class RtfFontManager /** * Initialize the font table. */ - private void init () - { + private void init () { // getFontNumber ("Helvetica"); //Chanded by R.Marra default font Arial @@ -152,21 +147,17 @@ public class RtfFontManager * * @return The number of the font in the table */ - public int getFontNumber (String family) - { + public int getFontNumber (String family) { family = family.toLowerCase (); Object o = fontIndex.get (family); int retVal; - if (o == null) - { + if (o == null) { addFont (family); retVal = fontTable.size () - 1; - } - else - { + } else { retVal = ((Integer) o).intValue (); } @@ -180,10 +171,8 @@ public class RtfFontManager * * @throws IOException On error */ - public void writeFonts (RtfHeader header) throws IOException - { - if (fontTable == null || fontTable.size () == 0) - { + public void writeFonts (RtfHeader header) throws IOException { + if (fontTable == null || fontTable.size () == 0) { return; } @@ -192,8 +181,7 @@ public class RtfFontManager int len = fontTable.size (); - for (int i = 0; i < len; i++) - { + for (int i = 0; i < len; i++) { header.writeGroupMark (true); header.write ("\\f" + i); header.write (" " + (String) fontTable.elementAt (i)); @@ -213,8 +201,7 @@ public class RtfFontManager * * @param i Identifier of font */ - private void addFont (String family) - { + private void addFont (String family) { fontIndex.put (family, new Integer (fontTable.size ())); fontTable.addElement (family); } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java index 76220713c..bd85d7d84 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfFontTable.java @@ -66,23 +66,19 @@ import java.io.IOException; * @author Andreas Putz a.putz@skynamics.com */ -class RtfFontTable extends RtfElement -{ +class RtfFontTable extends RtfElement { /** Create an RTF header */ - RtfFontTable(RtfHeader h, Writer w) throws IOException - { - super(h,w); + RtfFontTable(RtfHeader h, Writer w) throws IOException { + super(h, w); } /** write our contents to m_writer. */ - protected void writeRtfContent() throws IOException - { + protected void writeRtfContent() throws IOException { RtfFontManager.getInstance ().writeFonts ((RtfHeader)m_parent); } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java index abd5121c0..559e927b1 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHeader.java @@ -58,7 +58,10 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.util.*; +//import java.util.*; +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; import java.io.Writer; import java.io.IOException; //import org.apache.fop.rtf.rtflib.jfor.main.JForVersionInfo; @@ -73,9 +76,9 @@ class RtfHeader extends RtfContainer { private final Map m_userProperties = new HashMap(); /** Create an RTF header */ - RtfHeader(RtfFile f,Writer w) throws IOException { - super(f,w); - new RtfFontTable(this,w); + RtfHeader(RtfFile f, Writer w) throws IOException { + super(f, w); + new RtfFontTable(this, w); // m_userProperties.put("jforVersion",JForVersionInfo.getLongVersionInfo()); } @@ -92,19 +95,21 @@ class RtfHeader extends RtfContainer { /** write user properties if any */ private void writeUserProperties() throws IOException { - if(m_userProperties.size() > 0) { + if (m_userProperties.size() > 0) { writeGroupMark(true); writeStarControlWord("userprops"); - for(Iterator it = m_userProperties.entrySet().iterator(); it.hasNext(); ) { + for (Iterator it = m_userProperties.entrySet().iterator(); it.hasNext();) { final Map.Entry entry = (Map.Entry)it.next(); writeGroupMark(true); writeControlWord("propname"); - RtfStringConverter.getInstance().writeRtfString(m_writer,entry.getKey().toString()); + RtfStringConverter.getInstance().writeRtfString(m_writer, + entry.getKey().toString()); writeGroupMark(false); writeControlWord("proptype30"); writeGroupMark(true); writeControlWord("staticval"); - RtfStringConverter.getInstance().writeRtfString(m_writer,entry.getValue().toString()); + RtfStringConverter.getInstance().writeRtfString(m_writer, + entry.getValue().toString()); writeGroupMark(false); } writeGroupMark(false); @@ -121,6 +126,6 @@ class RtfHeader extends RtfContainer { /** write to our Writer using an RtfStringConverter */ void writeRtfString(String toWrite) throws IOException { - RtfStringConverter.getInstance().writeRtfString(m_writer,toWrite); + RtfStringConverter.getInstance().writeRtfString(m_writer, toWrite); } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java index 191853965..1cbf01bbc 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfHyperLink.java @@ -68,8 +68,7 @@ import java.io.IOException; * * {\field {\*\fldinst HYPERLINK "http://www.test.de" }{\fldrslt Joe Smith}} */ -public class RtfHyperLink extends RtfContainer implements IRtfTextContainer -{ +public class RtfHyperLink extends RtfContainer implements IRtfTextContainer { ////////////////////////////////////////////////// // @@ Members @@ -94,8 +93,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * @param attributes a RtfAttributes value */ public RtfHyperLink (IRtfTextContainer parent, Writer writer, String str, RtfAttributes attr) - throws IOException - { + throws IOException { super ((RtfContainer) parent, writer, attr); new RtfText (this, writer, str, attr); } @@ -110,8 +108,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * * @exception IOException On error */ - public void writeRtfPrefix () throws IOException - { + public void writeRtfPrefix () throws IOException { super.writeGroupMark (true); super.writeControlWord ("field"); @@ -125,8 +122,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer super.writeControlWord ("fldrslt"); // start a group for this paragraph and write our own attributes if needed - if (m_attrib != null && m_attrib.isSet ("cs")) - { + if (m_attrib != null && m_attrib.isSet ("cs")) { writeGroupMark (true); writeAttributes(m_attrib, new String [] {"cs"}); } @@ -137,10 +133,8 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * * @exception IOException On error */ - public void writeRtfSuffix () throws IOException - { - if (m_attrib != null && m_attrib.isSet ("cs")) - { + public void writeRtfSuffix () throws IOException { + if (m_attrib != null && m_attrib.isSet ("cs")) { writeGroupMark (false); } super.writeGroupMark (false); @@ -156,30 +150,29 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * @param str if not null, added to the RtfText created */ public RtfText newText (String str) throws IOException { - return newText (str,null); + return newText (str, null); } /** close current text run if any and start a new one * @param str if not null, added to the RtfText created */ - public RtfText newText (String str,RtfAttributes attr) throws IOException - { + public RtfText newText (String str, RtfAttributes attr) throws IOException { closeAll (); mText = new RtfText (this, m_writer, str, attr); return mText; } /** IRtfTextContainer requirement: return a copy of our attributes */ - public RtfAttributes getTextContainerAttributes() - { - if (m_attrib == null) return null; + public RtfAttributes getTextContainerAttributes() { + if (m_attrib == null) { + return null; + } return (RtfAttributes) this.m_attrib.clone (); } /** add a line break */ - public void newLineBreak () throws IOException - { + public void newLineBreak () throws IOException { new RtfLineBreak (this, m_writer); } @@ -188,13 +181,13 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer // @@ Common container methods ////////////////////////////////////////////////// - private void closeCurrentText () throws IOException - { - if (mText != null) mText.close (); + private void closeCurrentText () throws IOException { + if (mText != null) { + mText.close (); + } } - private void closeAll () throws IOException - { + private void closeAll () throws IOException { closeCurrentText(); } @@ -208,8 +201,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * * @param url Link url like "http://..." */ - public void setExternalURL (String url) - { + public void setExternalURL (String url) { this.url = url; } @@ -218,8 +210,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer * * @param jumpTo Name of the text mark */ - public void setInternalURL (String jumpTo) - { + public void setInternalURL (String jumpTo) { int now = jumpTo.length (); int max = RtfBookmark.maxBookmarkLength; this.url = "#" + jumpTo.substring (0, now > max ? max : now); @@ -227,8 +218,7 @@ public class RtfHyperLink extends RtfContainer implements IRtfTextContainer this.url = this.url.replace (' ', RtfBookmark.replaceCharacter); } - public boolean isEmpty () - { + public boolean isEmpty () { return false; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java index 72743bd18..19ff483db 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfJforCmd.java @@ -60,8 +60,7 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; -import java.io.*; -import java.util.*; +import java.util.Iterator; import java.io.IOException; /* @@ -70,8 +69,8 @@ import java.io.IOException; */ public class RtfJforCmd extends RtfContainer { - private final String PARA_KEEP_ON ="para-keep:on"; - private final String PARA_KEEP_OFF ="para-keep:off"; + private final String PARA_KEEP_ON = "para-keep:on"; + private final String PARA_KEEP_OFF = "para-keep:off"; private final RtfAttributes m_attrib; private ParagraphKeeptogetherContext m_paragraphKeeptogetherContext; @@ -79,9 +78,9 @@ public class RtfJforCmd extends RtfContainer { RtfJforCmd(RtfContainer parent, Writer w, RtfAttributes attrs) throws IOException { - super((RtfContainer)parent,w); + super((RtfContainer)parent, w); m_attrib = attrs; - m_paragraphKeeptogetherContext=ParagraphKeeptogetherContext.getInstance(); + m_paragraphKeeptogetherContext = ParagraphKeeptogetherContext.getInstance(); } @@ -96,15 +95,16 @@ public class RtfJforCmd extends RtfContainer { //Execute all jfor-cmd commands //TODO create one class for each jfor command ? - for(Iterator it = m_attrib.nameIterator(); it.hasNext(); ) { + for (Iterator it = m_attrib.nameIterator(); it.hasNext();) { final String cmd = (String)it.next(); if (cmd.equals(PARA_KEEP_ON)) { m_paragraphKeeptogetherContext.KeepTogetherOpen(); - }else if (cmd.equals(PARA_KEEP_OFF)) { + } else if (cmd.equals(PARA_KEEP_OFF)) { m_paragraphKeeptogetherContext.KeepTogetherClose(); - }else { -// this.getRtfFile ().getLog ().logInfo ("JFOR-CMD ignored, command not recognised:"+cmd); + } else { +// this.getRtfFile ().getLog ().logInfo +// ("JFOR-CMD ignored, command not recognised:"+cmd); } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfLineBreak.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfLineBreak.java index 2acf5ed29..59b709fcb 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfLineBreak.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfLineBreak.java @@ -65,23 +65,19 @@ import java.io.IOException; * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch */ -public class RtfLineBreak extends RtfElement -{ +public class RtfLineBreak extends RtfElement { /** Create an RTF paragraph as a child of given container with default attributes */ - RtfLineBreak(IRtfTextContainer parent, Writer w) throws IOException - { - super((RtfContainer)parent,w); + RtfLineBreak(IRtfTextContainer parent, Writer w) throws IOException { + super((RtfContainer)parent, w); } /** overridden to write our attributes before our content */ - protected void writeRtfContent() throws IOException - { + protected void writeRtfContent() throws IOException { writeControlWord("line"); } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfList.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfList.java index 9018b0f37..31cd36918 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfList.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfList.java @@ -81,7 +81,7 @@ public class RtfList extends RtfContainer { /** Create an RTF list as a child of given container with given attributes */ RtfList(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException { - super((RtfContainer)parent,w,attr); + super((RtfContainer)parent, w, attr); m_numberingStyle = new NumberingStyle(); //create a new list table entry for the list m_listTable = (getRtfFile()).startListTable(attr); @@ -99,10 +99,12 @@ public class RtfList extends RtfContainer { /** overridden to setup the list: start a group with appropriate attributes */ protected void writeRtfPrefix() throws IOException { // pard causes word97 (and sometimes 2000 too) to crash if the list is nested in a table - if(!m_hasTableParent) writeControlWord("pard"); + if (!m_hasTableParent) { + writeControlWord("pard"); + } - writeOneAttribute(RtfText.LEFT_INDENT_FIRST,m_attrib.getValue(RtfListTable.LIST_INDENT)); - writeOneAttribute(RtfText.LEFT_INDENT_BODY,m_attrib.getValue(RtfText.LEFT_INDENT_BODY)); + writeOneAttribute(RtfText.LEFT_INDENT_FIRST, m_attrib.getValue(RtfListTable.LIST_INDENT)); + writeOneAttribute(RtfText.LEFT_INDENT_BODY, m_attrib.getValue(RtfText.LEFT_INDENT_BODY)); // put the whole list in a group writeGroupMark(true); @@ -114,7 +116,7 @@ public class RtfList extends RtfContainer { //Modified by Chris Scott //fixes second line indentation - if(m_numberingStyle.isBulletedList) { + if (m_numberingStyle.isBulletedList) { // bulleted list writeControlWord("pnlvlblt"); writeControlWord("ilvl0"); @@ -125,7 +127,7 @@ public class RtfList extends RtfContainer { writeControlWord("pnf1"); writeGroupMark(true); writeControlWord("pndec"); - writeOneAttribute(RtfListTable.LIST_FONT_TYPE,"2"); + writeOneAttribute(RtfListTable.LIST_FONT_TYPE, "2"); writeControlWord("pntxtb"); writeControlWord("'b7"); writeGroupMark(false); @@ -153,15 +155,21 @@ public class RtfList extends RtfContainer { // close group that encloses the whole list writeGroupMark(false); - // reset paragraph defaults to make sure list ends - // but pard causes word97 (and sometimes 2000 too) to crash if the list is nested in a table - if(!m_hasTableParent) writeControlWord("pard"); + /* reset paragraph defaults to make sure list ends + * but pard causes word97 (and sometimes 2000 too) to crash if the list + * is nested in a table + */ + if (!m_hasTableParent) { + writeControlWord("pard"); + } } /** close current list item and start a new one */ public RtfListItem newListItem() throws IOException { - if(m_item != null) m_item.close(); - m_item = new RtfListItem(this,m_writer); + if (m_item != null) { + m_item.close(); + } + m_item = new RtfListItem(this, m_writer); return m_item; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java index 2577f21fd..fc88e859b 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListItem.java @@ -60,7 +60,6 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; import java.io.IOException; -import java.io.*; /** Model of an RTF list item, which can contain RTF paragraphs * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch @@ -75,22 +74,22 @@ implements IRtfParagraphContainer { /** special RtfParagraph that writes list item setup code before its content */ private class RtfListItemParagraph extends RtfParagraph { - RtfListItemParagraph(RtfListItem rli,RtfAttributes attrs) + RtfListItemParagraph(RtfListItem rli, RtfAttributes attrs) throws IOException { - super(rli,rli.m_writer,attrs); + super(rli, rli.m_writer, attrs); } protected void writeRtfPrefix() throws IOException { super.writeRtfPrefix(); // for bulleted list, add list item setup group before paragraph contents - if(m_parentList.isBulletedList()) { + if (m_parentList.isBulletedList()) { writeGroupMark(true); writeControlWord("pntext"); writeControlWord("f" + RtfFontManager.getInstance().getFontNumber("Symbol")); writeControlWord("'b7"); writeControlWord("tab"); writeGroupMark(false); - }else{ + } else { writeGroupMark(true); writeControlWord("pntext"); writeGroupMark(false); @@ -101,21 +100,23 @@ implements IRtfParagraphContainer { /** Create an RTF list item as a child of given container with default attributes */ RtfListItem(RtfList parent, Writer w) throws IOException { - super((RtfContainer)parent,w); + super((RtfContainer)parent, w); m_parentList = parent; } /** Create an RTF list item as a child of given container with given attributes */ RtfListItem(RtfList parent, Writer w, RtfAttributes attr) throws IOException { - super((RtfContainer)parent,w,attr); + super((RtfContainer)parent, w, attr); m_parentList = parent; } /** close current paragraph and start a new one */ /** close current paragraph if any and start a new one */ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { - if(m_paragraph != null) m_paragraph.close(); - m_paragraph = new RtfListItemParagraph(this,attrs); + if (m_paragraph != null) { + m_paragraph.close(); + } + m_paragraph = new RtfListItemParagraph(this, attrs); return m_paragraph; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java index 5fe03d8e0..4545e9f0e 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfListTable.java @@ -58,7 +58,8 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.util.*; +import java.util.Date; +import java.util.Random; import java.io.Writer; import java.io.IOException; //import org.apache.fop.rtf.rtflib.jfor.main.JForVersionInfo; @@ -68,7 +69,7 @@ import java.io.IOException; * esp. Adobe FrameMaker read lists from RTF. * @author Christopher Scott, scottc@westinghouse.com */ -public class RtfListTable extends RtfContainer{ +public class RtfListTable extends RtfContainer { //number of list in document private Integer listNum; @@ -91,7 +92,7 @@ public class RtfListTable extends RtfContainer{ public static final String LIST_NUM_POSITION = "levelnumbers"; public static final String LIST_NAME = "listname ;"; public static final String LIST_ID = "listid"; - public static final String LIST_FONT_TYPE ="f"; + public static final String LIST_FONT_TYPE = "f"; public static final String LIST_OVR_TABLE = "listoverridetable"; public static final String LIST_OVR = "listoverride"; @@ -110,16 +111,16 @@ public class RtfListTable extends RtfContainer{ /**RtfListTable Constructor: sets the number of the list, and allocates * for the RtfAttributes */ public RtfListTable(RtfContainer parent, Writer w, Integer num, RtfAttributes attrs) - throws IOException{ + throws IOException { super(parent, w, attrs); listNum = new Integer(num.intValue()); //random number generator for ids Date runTime = new Date(); Random listIdGenerator = new Random(runTime.getTime()); listId = new Integer(listIdGenerator.nextInt()); - m_attrib.set(LIST_ID,listId.toString()); + m_attrib.set(LIST_ID, listId.toString()); listTemplateId = new Integer(listIdGenerator.nextInt()); - m_attrib.set(LIST_NUMBER_TYPE,0); + m_attrib.set(LIST_NUMBER_TYPE, 0); } public void setParentList(RtfList parent) { @@ -133,19 +134,19 @@ public class RtfListTable extends RtfContainer{ /** Set whether the list is a bulleted list not, and set attributes * accordingly */ private void setListType() { - if(parentList.isBulletedList()){ + if (parentList.isBulletedList()) { // bullet definition for bulleted lists // Chris Scott's version was "\\\'01\\u-3913 ?;" // 'b7 is what was used in jfor V0.5.2 - m_attrib.set(LIST_TEXT_FORM,"\\\'01\\'b7 ?;"); + m_attrib.set(LIST_TEXT_FORM, "\\\'01\\'b7 ?;"); m_attrib.set(LIST_NUM_POSITION); - m_attrib.set(LIST_NUMBER_TYPE,23); - m_attrib.set(LIST_FONT_TYPE,2); - }else{ + m_attrib.set(LIST_NUMBER_TYPE, 23); + m_attrib.set(LIST_FONT_TYPE, 2); + } else { m_attrib.set(LIST_TEXT_FORM, "\\\'03\\\'00. ;"); m_attrib.set(LIST_NUM_POSITION, "\\\'01;"); - m_attrib.set(LIST_NUMBER_TYPE,0); - m_attrib.set(LIST_FONT_TYPE,0); + m_attrib.set(LIST_NUMBER_TYPE, 0); + m_attrib.set(LIST_FONT_TYPE, 0); } } @@ -156,37 +157,37 @@ public class RtfListTable extends RtfContainer{ writeGroupMark(true); writeControlWordNS(LIST); - writeOneAttributeNS(LIST_TEMPLATE_ID,listTemplateId.toString()); - writeOneAttributeNS(LIST,m_attrib.getValue(LIST)); + writeOneAttributeNS(LIST_TEMPLATE_ID, listTemplateId.toString()); + writeOneAttributeNS(LIST, m_attrib.getValue(LIST)); writeGroupMark(true); writeControlWordNS(LIST_LEVEL); - writeOneAttributeNS(LIST_NUMBER_TYPE,m_attrib.getValue(LIST_NUMBER_TYPE)); - writeOneAttributeNS(LIST_JUSTIFICATION,m_attrib.getValue(LIST_JUSTIFICATION)); - writeOneAttributeNS(LIST_FOLLOWING_CHAR,m_attrib.getValue(LIST_FOLLOWING_CHAR)); - writeOneAttributeNS(LIST_START_AT,m_attrib.getValue(LIST_START_AT)); - writeOneAttributeNS(LIST_SPACE,new Integer(0)); - writeOneAttributeNS(LIST_INDENT,m_attrib.getValue(LIST_INDENT)); + writeOneAttributeNS(LIST_NUMBER_TYPE, m_attrib.getValue(LIST_NUMBER_TYPE)); + writeOneAttributeNS(LIST_JUSTIFICATION, m_attrib.getValue(LIST_JUSTIFICATION)); + writeOneAttributeNS(LIST_FOLLOWING_CHAR, m_attrib.getValue(LIST_FOLLOWING_CHAR)); + writeOneAttributeNS(LIST_START_AT, m_attrib.getValue(LIST_START_AT)); + writeOneAttributeNS(LIST_SPACE, new Integer(0)); + writeOneAttributeNS(LIST_INDENT, m_attrib.getValue(LIST_INDENT)); writeGroupMark(true); - writeOneAttributeNS(LIST_TEXT_FORM,m_attrib.getValue(LIST_TEXT_FORM)); + writeOneAttributeNS(LIST_TEXT_FORM, m_attrib.getValue(LIST_TEXT_FORM)); writeGroupMark(false); writeGroupMark(true); - writeOneAttributeNS(LIST_NUM_POSITION,m_attrib.getValue(LIST_NUM_POSITION)); + writeOneAttributeNS(LIST_NUM_POSITION, m_attrib.getValue(LIST_NUM_POSITION)); writeGroupMark(false); - writeOneAttributeNS(LIST_FONT_TYPE,m_attrib.getValue(LIST_FONT_TYPE)); + writeOneAttributeNS(LIST_FONT_TYPE, m_attrib.getValue(LIST_FONT_TYPE)); writeGroupMark(false); writeGroupMark(true); writeControlWordNS(LIST_NAME); writeGroupMark(false); - writeOneAttributeNS(LIST_ID,listId.toString()); + writeOneAttributeNS(LIST_ID, listId.toString()); writeGroupMark(false); writeGroupMark(false); writeGroupMark(true); writeStarControlWordNS(LIST_OVR_TABLE); writeGroupMark(true); writeControlWordNS(LIST_OVR); - writeOneAttributeNS(LIST_ID,listId.toString()); - writeOneAttributeNS(LIST_OVR_COUNT,new Integer(0)); - writeOneAttributeNS(LIST_NUMBER,listNum.toString()); + writeOneAttributeNS(LIST_ID, listId.toString()); + writeOneAttributeNS(LIST_OVR_COUNT, new Integer(0)); + writeOneAttributeNS(LIST_NUMBER, listNum.toString()); writeGroupMark(false); writeGroupMark(false); } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java index da1ece236..1c5576aae 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfNull.java @@ -59,16 +59,14 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; -import java.io.*; -import java.util.*; import java.io.IOException; /* @author Christopher Scott, scottc@westinghouse.com */ public class RtfNull -extends RtfContainer{ +extends RtfContainer { RtfNull(RtfPage parent, Writer w) throws IOException { - super((RtfContainer)parent,w); + super((RtfContainer)parent, w); } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfOptions.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfOptions.java index 0e3f3c188..ca7ca4e19 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfOptions.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfOptions.java @@ -58,16 +58,11 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.io.Writer; -import java.util.*; -import java.io.IOException; - /** Simplistic options definitions for RTF generation * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch */ -public class RtfOptions -{ +public class RtfOptions { /** if true, RtfParagraphs that have no children do not generate any RTF code */ public boolean ignoreEmptyParagraphs() { return true; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java index 7cd2f0a00..1cc87e303 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageArea.java @@ -60,36 +60,31 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; import java.io.IOException; -import java.io.*; /* @author Christopher Scott, scottc@westinghouse.com */ public class RtfPageArea -extends RtfContainer -{ +extends RtfContainer { private RtfPage m_currentPage; private RtfNull nullChild; private RtfAttributes childAttributes; /** Create an RTF element as a child of given container */ - RtfPageArea(RtfFile f,Writer w) throws IOException - { - super(f,w); + RtfPageArea(RtfFile f, Writer w) throws IOException { + super(f, w); } /** close current Rtfpage if any and create a new one */ - public RtfPage newPage(RtfAttributes attr) throws IOException - { - if(m_currentPage != null){ + public RtfPage newPage(RtfAttributes attr) throws IOException { + if (m_currentPage != null) { m_currentPage.close(); } - m_currentPage = new RtfPage(this,m_writer,attr); + m_currentPage = new RtfPage(this, m_writer, attr); return m_currentPage; } - protected boolean okToWriteRtf() - { + protected boolean okToWriteRtf() { return true; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageBreak.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageBreak.java index d02349c32..e5fbcc05f 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageBreak.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageBreak.java @@ -65,23 +65,19 @@ import java.io.IOException; * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch */ -public class RtfPageBreak extends RtfElement -{ +public class RtfPageBreak extends RtfElement { /** Create an RTF paragraph as a child of given container with default attributes */ - RtfPageBreak(IRtfPageBreakContainer parent, Writer w) throws IOException - { - super((RtfContainer)parent,w); + RtfPageBreak(IRtfPageBreakContainer parent, Writer w) throws IOException { + super((RtfContainer)parent, w); } /** overridden to write our attributes before our content */ - protected void writeRtfContent() throws IOException - { + protected void writeRtfContent() throws IOException { writeControlWord("page"); } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } } \ No newline at end of file diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java index 73296ce71..e134f61b3 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumber.java @@ -62,8 +62,7 @@ import java.io.Writer; import java.io.IOException; /* @author Christopher Scott, scottc@westinghouse.com */ -public class RtfPageNumber extends RtfContainer -{ +public class RtfPageNumber extends RtfContainer { /** RtfText attributes: fields */ //must be carefull of group markings and star control //ie page field: @@ -73,18 +72,16 @@ public class RtfPageNumber extends RtfContainer public static String RTF_FIELD_RESULT = "fldrslt"; /** Create an RTF paragraph as a child of given container with default attributes */ - RtfPageNumber(IRtfPageNumberContainer parent, Writer w) throws IOException - { - super((RtfContainer)parent,w); + RtfPageNumber(IRtfPageNumberContainer parent, Writer w) throws IOException { + super((RtfContainer)parent, w); } /** Create an RTF page number as a child of given paragraph, * copying the paragraph attributes */ - RtfPageNumber(RtfParagraph parent, Writer w) throws IOException - { + RtfPageNumber(RtfParagraph parent, Writer w) throws IOException { // Adds the attributes of the parent paragraph - super((RtfContainer)parent,w, parent.m_attrib); + super((RtfContainer)parent, w, parent.m_attrib); // copy parent's text attributes if (parent.getTextAttributes() != null) { @@ -93,12 +90,11 @@ public class RtfPageNumber extends RtfContainer } /** write our attributes and content */ - protected void writeRtfContent() throws IOException - { + protected void writeRtfContent() throws IOException { writeGroupMark(true); writeControlWord(RTF_FIELD); writeGroupMark(true); - writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous + writeAttributes(m_attrib, RtfText.ATTR_NAMES); // Added by Boris Poudérous writeStarControlWord(RTF_FIELD_PAGE); writeGroupMark(false); writeGroupMark(true); @@ -108,8 +104,7 @@ public class RtfPageNumber extends RtfContainer } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java index b1598025c..a0ee579cd 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfPageNumberCitation.java @@ -66,8 +66,7 @@ import java.io.IOException; * @author Boris Pouderous, boris.pouderous@free.fr */ -public class RtfPageNumberCitation extends RtfContainer -{ +public class RtfPageNumberCitation extends RtfContainer { // Page field : // "{\field {\*\fldinst {PAGEREF xx}} {\fldrslt}}" where xx represents the // 'id' of the referenced page @@ -79,34 +78,32 @@ public class RtfPageNumberCitation extends RtfContainer private String id = null; /** Create an RTF page number citation as a child of given container with default attributes */ - RtfPageNumberCitation (IRtfPageNumberCitationContainer parent, Writer w, String id) throws IOException - { - super((RtfContainer)parent,w); + RtfPageNumberCitation (IRtfPageNumberCitationContainer parent, Writer w, String id) + throws IOException { + super((RtfContainer)parent, w); this.id = id; } /** Create an RTF page number citation as a child of given * paragraph, copying its attributes */ RtfPageNumberCitation (RtfParagraph parent, Writer w, String id) - throws IOException - { + throws IOException { // add the attributes ant text attributes of the parent paragraph - super((RtfContainer)parent,w, parent.m_attrib); + super((RtfContainer)parent, w, parent.m_attrib); if (parent.getTextAttributes() != null) { m_attrib.set(parent.getTextAttributes()); } this.id = id; } - protected void writeRtfContent() throws IOException - { + protected void writeRtfContent() throws IOException { // If we have a valid ID if (isValid()) { // Build page reference field String pageRef = RTF_FIELD_PAGEREF_MODEL; final int insertionIndex = pageRef.indexOf("}"); pageRef = - pageRef.substring(0,insertionIndex) + "\"" + id + "\"" + " " + pageRef.substring(0, insertionIndex) + "\"" + id + "\"" + " " + pageRef.substring(insertionIndex, pageRef.length()) ; id = null; @@ -115,7 +112,7 @@ public class RtfPageNumberCitation extends RtfContainer writeGroupMark(true); writeControlWord(RTF_FIELD); writeGroupMark(true); - writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous + writeAttributes(m_attrib, RtfText.ATTR_NAMES); // Added by Boris Poudérous writeStarControlWord(pageRef); writeGroupMark(false); writeGroupMark(true); @@ -126,17 +123,16 @@ public class RtfPageNumberCitation extends RtfContainer } /** checks that the 'ref-id' attribute exists */ - private boolean isValid() - { - if (id != null) + private boolean isValid() { + if (id != null) { return true; - else + } else { return false; + } } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java index 5e5e1e758..82c7fd1f6 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraph.java @@ -69,15 +69,17 @@ import java.util.List; */ public class RtfParagraph extends RtfBookmarkContainerImpl -implements IRtfTextContainer,IRtfPageBreakContainer,IRtfHyperLinkContainer,IRtfExternalGraphicContainer, -IRtfPageNumberContainer,IRtfPageNumberCitationContainer { +implements IRtfTextContainer, IRtfPageBreakContainer, IRtfHyperLinkContainer, + IRtfExternalGraphicContainer, IRtfPageNumberContainer, + IRtfPageNumberCitationContainer { private RtfText m_text; private RtfHyperLink m_hyperlink; private RtfExternalGraphic m_externalGraphic; private RtfPageNumber m_pageNumber; - private RtfPageNumberCitation m_pageNumberCitation; // Line added by Boris POUDEROUS on 2002/07/09 - private boolean m_keepn=false; - private boolean m_resetProperties=false; + private RtfPageNumberCitation m_pageNumberCitation; + // Above line added by Boris POUDEROUS on 2002/07/09 + private boolean m_keepn = false; + private boolean m_resetProperties = false; /* needed for importing Rtf into FrameMaker FrameMaker is not as forgiving as word in rtf @@ -92,31 +94,33 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { /** Create an RTF paragraph as a child of given container with default attributes */ RtfParagraph(IRtfParagraphContainer parent, Writer w) throws IOException { - super((RtfContainer)parent,w); + super((RtfContainer)parent, w); } /** Create an RTF paragraph as a child of given container with given attributes */ - RtfParagraph(IRtfParagraphContainer parent, Writer w,RtfAttributes attr) throws IOException { - super((RtfContainer)parent,w,attr); + RtfParagraph(IRtfParagraphContainer parent, Writer w, RtfAttributes attr) throws IOException { + super((RtfContainer)parent, w, attr); } - public String getText(){ - return(m_text.getText()); + public String getText() { + return (m_text.getText()); } /** Set the keepn attribute for this paragraph */ public void setKeepn() { - this.m_keepn=true; + this.m_keepn = true; } /** Force reset properties */ public void setResetProperties() { - this.m_resetProperties=true; + this.m_resetProperties = true; } /** 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(); } @@ -124,45 +128,49 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { protected void writeRtfPrefix() throws IOException { // collapse whitespace before writing out // TODO could be made configurable - if(m_attrib != null && m_attrib.isSet("WhiteSpaceFalse")){ + if (m_attrib != null && m_attrib.isSet("WhiteSpaceFalse")) { m_attrib.unset("WhiteSpaceFalse"); } else { new WhitespaceCollapser(this); } //Reset paragraph properties if needed - if(m_resetProperties) { + if (m_resetProperties) { writeControlWord("pard"); } // do not write text attributes here, they are handled // by RtfText - writeAttributes(m_attrib,PARA_ATTRIBUTES); + writeAttributes(m_attrib, PARA_ATTRIBUTES); // Added by Normand Masse // Write alignment attributes after \intbl for cells - if ( m_attrib.isSet( "intbl" ) && mustWriteAttributes() ) { + if (m_attrib.isSet("intbl") && mustWriteAttributes()) { writeAttributes(m_attrib, RtfText.ALIGNMENT); } //Set keepn if needed (Keep paragraph with the next paragraph) - if(m_keepn) writeControlWord("keepn"); + if (m_keepn) { + writeControlWord("keepn"); + } // start a group for this paragraph and write our own attributes if needed - if(mustWriteGroupMark()) writeGroupMark(true); + if (mustWriteGroupMark()) { + writeGroupMark(true); + } - if(mustWriteAttributes()) { + if (mustWriteAttributes()) { // writeAttributes(m_attrib, new String [] {"cs"}); // Added by Normand Masse // If \intbl then attributes have already been written (see higher in method) - if ( !m_attrib.isSet( "intbl" ) ) { + if (!m_attrib.isSet("intbl")) { writeAttributes(m_attrib, RtfText.ALIGNMENT); } //this line added by Chris Scott, Westinghouse writeAttributes(m_attrib, RtfText.BORDER); writeAttributes(m_attrib, RtfText.INDENT); writeAttributes(m_attrib, RtfText.TABS); - if(writeForBreak){ + if (writeForBreak) { writeControlWord("pard\\par"); } } @@ -173,14 +181,16 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { protected void writeRtfSuffix() throws IOException { // sometimes the end of paragraph mark must be suppressed in table cells boolean writeMark = true; - if(m_parent instanceof RtfTableCell) { + if (m_parent instanceof RtfTableCell) { writeMark = ((RtfTableCell)m_parent).paragraphNeedsPar(this); } - if(writeMark) { + if (writeMark) { writeControlWord("par"); } - if(mustWriteGroupMark()) writeGroupMark(false); + if (mustWriteGroupMark()) { + writeGroupMark(false); + } } @@ -189,40 +199,39 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { * @param str if not null, added to the RtfText created */ public RtfText newText(String str) throws IOException { - return newText(str,null); + return newText(str, null); } /** close current text run if any and start a new one * @param str if not null, added to the RtfText created */ - public RtfText newText(String str,RtfAttributes attr) throws IOException { + public RtfText newText(String str, RtfAttributes attr) throws IOException { closeAll(); - m_text = new RtfText(this,m_writer,str,attr); + m_text = new RtfText(this, m_writer, str, attr); return m_text; } /** add a page break */ public void newPageBreak() throws IOException { writeForBreak = true; - new RtfPageBreak(this,m_writer); + new RtfPageBreak(this, m_writer); } /** add a line break */ public void newLineBreak() throws IOException { - new RtfLineBreak(this,m_writer); + new RtfLineBreak(this, m_writer); } public RtfPageNumber newPageNumber()throws IOException { - m_pageNumber = new RtfPageNumber(this,m_writer); + m_pageNumber = new RtfPageNumber(this, m_writer); return m_pageNumber; } /** * Added by Boris POUDEROUS on 2002/07/09 */ - public RtfPageNumberCitation newPageNumberCitation(String id) throws IOException - { - m_pageNumberCitation = new RtfPageNumberCitation(this,m_writer, id); + public RtfPageNumberCitation newPageNumberCitation(String id) throws IOException { + m_pageNumberCitation = new RtfPageNumberCitation(this, m_writer, id); return m_pageNumberCitation; } @@ -235,16 +244,20 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { /** start a new external graphic after closing all other elements */ public RtfExternalGraphic newImage() throws IOException { closeAll(); - m_externalGraphic = new RtfExternalGraphic(this,m_writer); + m_externalGraphic = new RtfExternalGraphic(this, m_writer); return m_externalGraphic; } private void closeCurrentText() throws IOException { - if(m_text != null) m_text.close(); + if (m_text != null) { + m_text.close(); + } } private void closeCurrentHyperLink() throws IOException { - if(m_hyperlink != null) m_hyperlink.close(); + if (m_hyperlink != null) { + m_hyperlink.close(); + } } private void closeAll() throws IOException { @@ -256,7 +269,7 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { protected boolean okToWriteRtf() { boolean result = super.okToWriteRtf(); - if(m_parent.getOptions().ignoreEmptyParagraphs() && getChildCount() == 0) { + if (m_parent.getOptions().ignoreEmptyParagraphs() && getChildCount() == 0) { // TODO should test that this is the last RtfParagraph in the cell instead // of simply testing for last child?? result = false; @@ -273,15 +286,14 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { final List childList = getChildren(); for (int i = 0; i < children; i++) { final RtfElement el = (RtfElement) childList.get(i); - if (! el.isEmpty()) { - if (el.getClass() == RtfText.class ) { + if (!el.isEmpty()) { + if (el.getClass() == RtfText.class) { boolean tmp = ((RtfText) el).isNbsp(); - if (! tmp) { + if (!tmp) { writeAttributes = true; break; } - } - else { + } else { writeAttributes = true; break; } @@ -292,15 +304,20 @@ IRtfPageNumberContainer,IRtfPageNumberCitationContainer { } /** true if we must write a group mark around this paragraph - * TODO is this correct, study interaction with mustWriteAttributes() <-- On implementation i have noticed if the groupmark set, the format attributes are only for this content, i think this implementation is ok + * TODO is this correct, study interaction with mustWriteAttributes() + * <-- On implementation i have noticed if the groupmark set, the + * format attributes are only for this content, i think this + * implementation is ok */ private boolean mustWriteGroupMark() { return getChildCount() > 0; } /** get the attributes of our text */ - public RtfAttributes getTextAttributes(){ - if(m_text == null) return null; + public RtfAttributes getTextAttributes() { + if (m_text == null) { + return null; + } return m_text.getTextAttributes(); } } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java index 660a5b553..c09d96e33 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfParagraphKeepTogether.java @@ -60,21 +60,19 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; -import java.io.*; -import java.util.*; import java.io.IOException; -public class RtfParagraphKeepTogether extends RtfContainer{ +public class RtfParagraphKeepTogether extends RtfContainer { - public static final int STATUS_NULL=0; - public static final int STATUS_OPEN_PARAGRAPH=1; - public static final int STATUS_CLOSE_PARAGRAPH=2; - private int m_status =STATUS_NULL; + public static final int STATUS_NULL = 0; + public static final int STATUS_OPEN_PARAGRAPH = 1; + public static final int STATUS_CLOSE_PARAGRAPH = 2; + private int m_status = STATUS_NULL; /** RtfParagraphKeepTogether*/ RtfParagraphKeepTogether(IRtfParagraphContainer parent, Writer w) throws IOException { - super((RtfContainer)parent,w); + super((RtfContainer)parent, w); } @@ -82,7 +80,7 @@ public class RtfParagraphKeepTogether extends RtfContainer{ //First reet paragraph properties // create a new one with keepn - if (m_status==STATUS_OPEN_PARAGRAPH) { + if (m_status == STATUS_OPEN_PARAGRAPH) { writeControlWord("pard"); writeControlWord("par"); writeControlWord("keepn"); @@ -105,8 +103,7 @@ public class RtfParagraphKeepTogether extends RtfContainer{ } /** true if this element would generate no "useful" RTF content */ - public boolean isEmpty() - { + public boolean isEmpty() { return false; } diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java index f42a65f2d..22ca605df 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfSection.java @@ -59,8 +59,6 @@ package org.apache.fop.rtf.rtflib.rtfdoc; import java.io.Writer; -import java.io.*; -import java.util.*; import java.io.IOException; import org.apache.fop.rtf.rtflib.interfaces.ITableColumnsInfo; @@ -78,8 +76,7 @@ implements IRtfBeforeContainer, IRtfParagraphKeepTogetherContainer, IRtfAfterContainer, - IRtfJforCmdContainer -{ + IRtfJforCmdContainer { private RtfParagraph m_paragraph; private RtfTable m_table; private RtfList m_list; @@ -90,20 +87,20 @@ implements /** Create an RTF container as a child of given container */ RtfSection(RtfDocumentArea parent, Writer w) throws IOException { - super(parent,w); + super(parent, w); } /** 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 paragraph after closing current paragraph, list and table */ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { closeAll(); - m_paragraph = new RtfParagraph(this,m_writer,attrs); + m_paragraph = new RtfParagraph(this, m_writer, attrs); return m_paragraph; } @@ -114,52 +111,53 @@ implements /** close current paragraph if any and start a new one */ public RtfParagraphKeepTogether newParagraphKeepTogether() throws IOException { - return new RtfParagraphKeepTogether(this,m_writer); + return new RtfParagraphKeepTogether(this, m_writer); } /** start a new table after closing current paragraph, list and table - * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002) + * @param tc Table context used for number-columns-spanned attribute (added by + * Boris Poudérous on july 2002) */ 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 table after closing current paragraph, list and table - * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002) + * @param tc Table context used for number-columns-spanned attribute (added by + * Boris Poudérous on july 2002) */ - public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException - { + public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException { closeAll(); - m_table = new RtfTable(this,m_writer, attrs, tc); + m_table = new RtfTable(this, m_writer, attrs, tc); return m_table; } /** start a new list after closing current paragraph, list and table */ public RtfList newList(RtfAttributes attrs) throws IOException { closeAll(); - m_list = new RtfList(this,m_writer, attrs); + m_list = new RtfList(this, m_writer, attrs); return m_list; } /** IRtfBeforeContainer */ public RtfBefore newBefore(RtfAttributes attrs) throws IOException { closeAll(); - m_before = new RtfBefore(this,m_writer,attrs); + m_before = new RtfBefore(this, m_writer, attrs); return m_before; } /** IRtfAfterContainer */ public RtfAfter newAfter(RtfAttributes attrs) throws IOException { closeAll(); - m_after = new RtfAfter(this,m_writer,attrs); + m_after = new RtfAfter(this, m_writer, attrs); return m_after; } public RtfJforCmd newJforCmd(RtfAttributes attrs) throws IOException { - m_jforCmd = new RtfJforCmd(this,m_writer,attrs); + m_jforCmd = new RtfJforCmd(this, m_writer, attrs); return m_jforCmd; } @@ -176,23 +174,33 @@ implements } private void closeCurrentTable() throws IOException { - if(m_table != null) m_table.close(); + if (m_table != null) { + m_table.close(); + } } private void closeCurrentParagraph() throws IOException { - if(m_paragraph!=null) m_paragraph.close(); + 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 closeCurrentExternalGraphic() throws IOException { - if(m_externalGraphic!=null) m_externalGraphic.close(); + if (m_externalGraphic != null) { + m_externalGraphic.close(); + } } private void closeCurrentBefore() throws IOException { - if(m_before!=null) m_before.close(); + if (m_before != null) { + m_before.close(); + } } private void closeAll() diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStringConverter.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStringConverter.java index 52ffe6e67..c8b87595d 100755 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStringConverter.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStringConverter.java @@ -58,7 +58,8 @@ package org.apache.fop.rtf.rtflib.rtfdoc; -import java.util.*; +import java.util.Map; +import java.util.HashMap; import java.io.IOException; import java.io.Writer; @@ -77,13 +78,13 @@ public class RtfStringConverter { /** List of characters to escape with corresponding replacement strings */ static { m_specialChars = new HashMap(); - m_specialChars.put(new Character('\t'),"tab"); - m_specialChars.put(new Character('\n'),"line"); - m_specialChars.put(new Character('\''),"rquote"); - m_specialChars.put(new Character('\"'),"rdblquote"); - m_specialChars.put(new Character('\\'),"\\"); - m_specialChars.put(new Character('{'),"{"); - m_specialChars.put(new Character('}'),"}"); + m_specialChars.put(new Character('\t'), "tab"); + m_specialChars.put(new Character('\n'), "line"); + m_specialChars.put(new Character('\''), "rquote"); + m_specialChars.put(new Character('\"'), "rdblquote"); + m_specialChars.put(new Character('\\'), "\\"); + m_specialChars.put(new Character('{'), "{"); + m_specialChars.put(new Character('}'), "}"); } /** singleton pattern */ @@ -96,37 +97,40 @@ public class RtfStringConverter { } /** write given String to given Writer, converting characters as required by RTF spec */ - public void writeRtfString(Writer w,String str) throws IOException { - if(str == null) return; + public void writeRtfString(Writer w, String str) throws IOException { + if (str == null) { + return; + } // TODO: could be made more efficient (binary lookup, etc.) - for(int i=0; i < str.length(); i++) { + for (int i = 0; i < str.length(); i++) { final Character c = new Character(str.charAt(i)); Character d; String replacement; - if(i!= 0) { - d=new Character(str.charAt(i-1)); + if (i != 0) { + d = new Character(str.charAt(i - 1)); } else { - d=new Character(str.charAt(i)); + d = new Character(str.charAt(i)); } //This section modified by Chris Scott //add "smart" quote recognition - if(c.equals((Object)DBLQUOTE) && d.equals((Object)SPACE)) { + if (c.equals((Object)DBLQUOTE) && d.equals((Object)SPACE)) { replacement = "ldblquote"; - } else if(c.equals((Object)QUOTE) && d.equals((Object)SPACE)) { + } else if (c.equals((Object)QUOTE) && d.equals((Object)SPACE)) { replacement = "lquote"; } else { replacement = (String)m_specialChars.get(c); } - if(replacement != null) { + if (replacement != null) { // RTF-escaped char w.write('\\'); w.write(replacement); w.write(' '); } else if (c.charValue() > 255) { - // write unicode representation - contributed by Michel Jacobson + // write unicode representation - contributed by Michel Jacobson + // w.write("\\u"); w.write(Integer.toString((int)c.charValue())); w.write("\\\'3f"); diff --git a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java index d274be636..0bca97a7e 100644 --- a/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java +++ b/src/java/org/apache/fop/rtf/rtflib/rtfdoc/RtfStyleSheetTable.java @@ -68,8 +68,7 @@ import java.util.Iterator; * This class belongs to the tag processing. * @author Andreas Putz */ -public class RtfStyleSheetTable -{ +public class RtfStyleSheetTable { ////////////////////////////////////////////////// // @@ Symbolic constants ////////////////////////////////////////////////// @@ -120,8 +119,7 @@ public class RtfStyleSheetTable /** * Constructor. */ - private RtfStyleSheetTable () - { + private RtfStyleSheetTable () { styles = new Hashtable (); attrTable = new Hashtable (); nameTable = new Vector (); @@ -132,10 +130,8 @@ public class RtfStyleSheetTable * * @return The instance of RtfStyleSheetTable */ - public static RtfStyleSheetTable getInstance () - { - if (instance == null) - { + public static RtfStyleSheetTable getInstance () { + if (instance == null) { instance = new RtfStyleSheetTable (); } @@ -151,8 +147,7 @@ public class RtfStyleSheetTable * Sets the default style. * @param styleName Name of the default style, defined in the stylesheet */ - public void setDefaultStyle (String styleName) - { + public void setDefaultStyle (String styleName) { this.defaultStyleName = styleName; } @@ -160,13 +155,12 @@ public class RtfStyleSheetTable * Gets the name of the default style. * @return Default style name. */ - public String getDefaultStyleName () - { - if (attrTable.get (defaultStyleName) != null) + public String getDefaultStyleName () { + if (attrTable.get (defaultStyleName) != null) { return defaultStyleName; + } - if (attrTable.get (STANDARD_STYLE) != null) - { + if (attrTable.get (STANDARD_STYLE) != null) { defaultStyleName = STANDARD_STYLE; return defaultStyleName; } @@ -184,30 +178,28 @@ public class RtfStyleSheetTable * @param name Name of style to add * @param attrs Rtf attributes which defines the style */ - public void addStyle (String name, RtfAttributes attrs) - { + public void addStyle (String name, RtfAttributes attrs) { nameTable.addElement (name); - if (attrs != null) + if (attrs != null) { attrTable.put (name, attrs); + } styles.put (name, new Integer (nameTable.size () - 1 + startIndex)); } /** * Adds the style attributes to the given attributes. * @param name Name of style, of which the attributes will copied to attr - * @param attrs Default rtf attributes + * @param attr Default rtf attributes * @return Status value */ - public int addStyleToAttributes (String name, RtfAttributes attr) - { + public int addStyleToAttributes (String name, RtfAttributes attr) { // Sets status to ok int status = STATUS_OK; // Gets the style number from table Integer style = (Integer) styles.get (name); - if (style == null && !name.equals (defaultStyleName)) - { + if (style == null && !name.equals (defaultStyleName)) { // If style not found, and style was not the default style, try the default style name = defaultStyleName; style = (Integer) styles.get (name); @@ -216,27 +208,26 @@ public class RtfStyleSheetTable } // Returns the status for invalid styles - if (style == null) + if (style == null) { return status; + } // Adds the attributes to default attributes, if not available in default attributes attr.set ("cs", style.intValue ()); Object o = attrTable.get (name); - if (o != null) - { + if (o != null) { RtfAttributes rtfAttr = (RtfAttributes) o; - for (Iterator names = rtfAttr.nameIterator (); names.hasNext ();) - { + for (Iterator names = rtfAttr.nameIterator (); names.hasNext ();) { String attrName = (String) names.next (); - if (! attr.isSet (attrName)) - { + if (!attr.isSet (attrName)) { Integer i = (Integer) rtfAttr.getValue (attrName); - if (i == null) + if (i == null) { attr.set (attrName); - else + } else { attr.set (attrName, i.intValue ()); + } } } } @@ -248,25 +239,21 @@ public class RtfStyleSheetTable * @param header Rtf header is the parent * @throws IOException On write error */ - public void writeStyleSheet (RtfHeader header) throws IOException - { - if (styles == null || styles.size () == 0) - { + public void writeStyleSheet (RtfHeader header) throws IOException { + if (styles == null || styles.size () == 0) { return; } header.writeGroupMark (true); header.writeControlWord ("stylesheet"); int number = nameTable.size (); - for (int i = 0; i < number; i++) - { + for (int i = 0; i < number; i++) { String name = (String) nameTable.elementAt (i); header.writeGroupMark (true); header.writeControlWord ("*\\" + this.getRtfStyleReference (name)); Object o = attrTable.get (name); - if (o != null) - { + if (o != null) { header.writeAttributes ((RtfAttributes) o, RtfText.ATTR_NAMES); header.writeAttributes ((RtfAttributes) o, RtfText.ALIGNMENT); } @@ -282,8 +269,7 @@ public class RtfStyleSheetTable * @param name Name of Style * @return Rtf attribute of the style reference */ - private String getRtfStyleReference (String name) - { + private String getRtfStyleReference (String name) { return "cs" + styles.get (name).toString (); } } \ No newline at end of file -- 2.39.5