KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > htmlviewer > FlyingSaucerViewerPlugin


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.htmlviewer;
19
20 import java.io.BufferedInputStream JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import javax.swing.BorderFactory JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.JScrollPane JavaDoc;
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 JavaDoc implements
37         IHTMLViewerPlugin {
38
39     private XHTMLPanel panel = new XHTMLPanel();
40     
41     URL JavaDoc 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 JavaDoc body) {
57         if (body == null)
58             return;
59         try {
60
61             Tidy tidy = new Tidy();
62
63             BufferedInputStream JavaDoc sourceIn = new BufferedInputStream JavaDoc(
64                     new ByteArrayInputStream JavaDoc(body.getBytes("ISO-8859-1")));
65
66             ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
67             
68             // Set bean properties
69
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 JavaDoc(System.out));
81
82             tidy.parse(sourceIn, out);
83
84             panel.setDocument(new ByteArrayInputStream JavaDoc(out.toByteArray()), baseUrl.toExternalForm());
85
86         } catch (Exception JavaDoc e) {
87             e.printStackTrace();
88         }
89     }
90
91     public String JavaDoc getSelectedText() {
92         return "";
93     }
94
95     public boolean initialized() {
96         return true;
97     }
98
99     public JComponent JavaDoc getComponent() {
100         return panel;
101     }
102
103     public JComponent JavaDoc getContainer() {
104         return this;
105     }
106
107     public String JavaDoc getText() {
108         return "";
109     }
110     
111     /**
112      * @see org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin#setCaretPosition(int)
113      */

114     public void setCaretPosition(int position) {
115         // TODO
116
}
117
118     /**
119      * @see org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin#moveCaretPosition(int)
120      */

121     public void moveCaretPosition(int position) {
122         // TODO
123
}
124     
125
126 }
127
Popular Tags