1 package org.columba.core.htmlviewer; 19 20 import java.io.BufferedInputStream ; 21 import java.io.ByteArrayInputStream ; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.PrintWriter ; 24 import java.net.URL ; 25 26 import javax.swing.BorderFactory ; 27 import javax.swing.JComponent ; 28 import javax.swing.JScrollPane ; 29 30 import org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin; 31 import org.columba.core.io.DiskIO; 32 import org.w3c.tidy.Tidy; 33 import org.xhtmlrenderer.simple.XHTMLPanel; 34 35 36 public class FlyingSaucerViewerPlugin extends JScrollPane implements 37 IHTMLViewerPlugin { 38 39 private XHTMLPanel panel = new XHTMLPanel(); 40 41 URL baseUrl = DiskIO.getResourceURL("org/columba/core/icons/MISC/"); 42 43 public FlyingSaucerViewerPlugin() { 44 super(); 45 46 setViewportView(panel); 47 48 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 49 50 setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 51 52 getVerticalScrollBar().setUnitIncrement(15); 53 54 } 55 56 public void view(String body) { 57 if (body == null) 58 return; 59 try { 60 61 Tidy tidy = new Tidy(); 62 63 BufferedInputStream sourceIn = new BufferedInputStream ( 64 new ByteArrayInputStream (body.getBytes("ISO-8859-1"))); 65 66 ByteArrayOutputStream out = new ByteArrayOutputStream (); 67 68 tidy.setQuiet(false); 70 tidy.setShowWarnings(true); 71 tidy.setIndentContent(true); 72 tidy.setSmartIndent(true); 73 tidy.setIndentAttributes(false); 74 tidy.setWraplen(1024); 75 tidy.setXHTML(true); 76 tidy.setXmlOut(true); 77 78 tidy.setMakeClean(true); 79 80 tidy.setErrout(new PrintWriter (System.out)); 81 82 tidy.parse(sourceIn, out); 83 84 panel.setDocument(new ByteArrayInputStream (out.toByteArray()), baseUrl.toExternalForm()); 85 86 } catch (Exception e) { 87 e.printStackTrace(); 88 } 89 } 90 91 public String getSelectedText() { 92 return ""; 93 } 94 95 public boolean initialized() { 96 return true; 97 } 98 99 public JComponent getComponent() { 100 return panel; 101 } 102 103 public JComponent getContainer() { 104 return this; 105 } 106 107 public String getText() { 108 return ""; 109 } 110 111 114 public void setCaretPosition(int position) { 115 } 117 118 121 public void moveCaretPosition(int position) { 122 } 124 125 126 } 127 | Popular Tags |