1 50 51 package com.lowagie.text.rtf.style; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 import java.util.HashMap ; 57 import java.util.Iterator ; 58 59 import com.lowagie.text.rtf.RtfBasicElement; 60 import com.lowagie.text.rtf.RtfElement; 61 import com.lowagie.text.rtf.RtfExtendedElement; 62 import com.lowagie.text.rtf.document.RtfDocument; 63 64 71 public class RtfStylesheetList extends RtfElement implements RtfExtendedElement { 72 73 76 private HashMap styleMap = null; 77 80 private boolean defaultsLoaded = false; 81 82 87 public RtfStylesheetList(RtfDocument doc) { 88 super(doc); 89 this.styleMap = new HashMap (); 90 } 91 92 96 public byte[] write() 97 { 98 return(new byte[0]); 99 } 100 103 public void writeContent(OutputStream out) throws IOException 104 { 105 } 106 107 112 public void registerParagraphStyle(RtfParagraphStyle rtfParagraphStyle) { 113 RtfParagraphStyle tempStyle = new RtfParagraphStyle(this.document, rtfParagraphStyle); 114 tempStyle.setStyleNumber(this.styleMap.size()); 115 tempStyle.handleInheritance(); 116 this.styleMap.put(tempStyle.getStyleName(), tempStyle); 117 } 118 119 123 private void registerDefaultStyles() { 124 defaultsLoaded = true; 125 if(!this.styleMap.containsKey(RtfParagraphStyle.STYLE_NORMAL.getStyleName())) { 126 registerParagraphStyle(RtfParagraphStyle.STYLE_NORMAL); 127 } 128 if(!this.styleMap.containsKey(RtfParagraphStyle.STYLE_HEADING_1.getStyleName())) { 129 registerParagraphStyle(RtfParagraphStyle.STYLE_HEADING_1); 130 } 131 if(!this.styleMap.containsKey(RtfParagraphStyle.STYLE_HEADING_2.getStyleName())) { 132 registerParagraphStyle(RtfParagraphStyle.STYLE_HEADING_2); 133 } 134 if(!this.styleMap.containsKey(RtfParagraphStyle.STYLE_HEADING_3.getStyleName())) { 135 registerParagraphStyle(RtfParagraphStyle.STYLE_HEADING_3); 136 } 137 } 138 139 146 public RtfParagraphStyle getRtfParagraphStyle(String styleName) { 147 if(!defaultsLoaded) { 148 registerDefaultStyles(); 149 } 150 if(this.styleMap.containsKey(styleName)) { 151 return (RtfParagraphStyle) this.styleMap.get(styleName); 152 } else { 153 return null; 154 } 155 } 156 157 161 public byte[] writeDefinition() { 162 ByteArrayOutputStream result = new ByteArrayOutputStream (); 163 try { 164 writeDefinition(result); 165 } catch(IOException ioe) { 166 ioe.printStackTrace(); 167 } 168 return result.toByteArray(); 169 } 170 171 174 public void writeDefinition(final OutputStream result) throws IOException 175 { 176 result.write("{".getBytes()); 177 result.write("\\stylesheet".getBytes()); 178 result.write(RtfBasicElement.DELIMITER); 179 if(this.document.getDocumentSettings().isOutputDebugLineBreaks()) { 180 result.write("\n".getBytes()); 181 } 182 Iterator it = this.styleMap.values().iterator(); 183 while(it.hasNext()) { 184 RtfParagraphStyle rps = (RtfParagraphStyle)it.next(); 185 rps.writeDefinition(result); 187 } 188 result.write("}".getBytes()); 189 if(this.document.getDocumentSettings().isOutputDebugLineBreaks()) { 190 result.write('\n'); 191 } 192 } 193 } 194 | Popular Tags |