1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.rtfdoc; 21 22 28 29 import java.io.Writer ; 30 import java.io.IOException ; 31 32 39 public class RtfHyperLink 40 extends RtfContainer 41 implements IRtfTextContainer, 42 IRtfTextrunContainer { 43 44 48 49 protected String url = null; 50 51 52 protected RtfText mText = null; 53 54 58 59 68 public RtfHyperLink (IRtfTextContainer parent, Writer writer, String str, RtfAttributes attr) 69 throws IOException { 70 super ((RtfContainer) parent, writer, attr); 71 new RtfText (this, writer, str, attr); 72 } 73 74 public RtfHyperLink (RtfTextrun parent, Writer writer, RtfAttributes attr) 75 throws IOException { 76 super ((RtfContainer) parent, writer, attr); 77 } 78 79 80 84 89 public void writeRtfPrefix () throws IOException { 90 super.writeGroupMark (true); 91 super.writeControlWord ("field"); 92 93 super.writeGroupMark (true); 94 super.writeStarControlWord ("fldinst"); 95 96 writer.write ("HYPERLINK \"" + url + "\" "); 97 super.writeGroupMark (false); 98 99 super.writeGroupMark (true); 100 super.writeControlWord ("fldrslt"); 101 102 if (attrib != null && attrib.isSet ("cs")) { 104 writeGroupMark (true); 105 writeAttributes(attrib, new String [] {"cs"}); 106 } 107 } 108 109 114 public void writeRtfSuffix () throws IOException { 115 if (attrib != null && attrib.isSet ("cs")) { 116 writeGroupMark (false); 117 } 118 super.writeGroupMark (false); 119 super.writeGroupMark (false); 120 } 121 122 123 127 133 public RtfText newText (String str) throws IOException { 134 return newText (str, null); 135 } 136 137 144 public RtfText newText (String str, RtfAttributes attr) throws IOException { 145 closeAll (); 146 mText = new RtfText (this, writer, str, attr); 147 return mText; 148 } 149 150 154 public RtfAttributes getTextContainerAttributes() { 155 if (attrib == null) { 156 return null; 157 } 158 return (RtfAttributes) this.attrib.clone (); 159 } 160 161 162 166 public void newLineBreak () throws IOException { 167 new RtfLineBreak (this, writer); 168 } 169 170 171 175 private void closeCurrentText () throws IOException { 176 if (mText != null) { 177 mText.close (); 178 } 179 } 180 181 private void closeAll () throws IOException { 182 closeCurrentText(); 183 } 184 185 186 190 195 public void setExternalURL (String url) { 196 this.url = url; 197 } 198 199 204 public void setInternalURL (String jumpTo) { 205 int now = jumpTo.length (); 206 int max = RtfBookmark.MAX_BOOKMARK_LENGTH; 207 this.url = "#" + jumpTo.substring (0, now > max ? max : now); 208 this.url = this.url.replace ('.', RtfBookmark.REPLACE_CHARACTER); 209 this.url = this.url.replace (' ', RtfBookmark.REPLACE_CHARACTER); 210 } 211 212 216 public boolean isEmpty () { 217 return false; 218 } 219 220 public RtfTextrun getTextrun() 221 throws IOException { 222 RtfTextrun textrun = RtfTextrun.getTextrun(this, writer, null); 223 return textrun; 224 } 225 } 226 | Popular Tags |