001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.htmlviewer;
019:
020: import java.io.BufferedInputStream;
021: import java.io.ByteArrayInputStream;
022: import java.io.ByteArrayOutputStream;
023: import java.io.PrintWriter;
024: import java.net.URL;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.JComponent;
028: import javax.swing.JScrollPane;
029:
030: import org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin;
031: import org.columba.core.io.DiskIO;
032: import org.w3c.tidy.Tidy;
033: import org.xhtmlrenderer.simple.XHTMLPanel;
034:
035: public class FlyingSaucerViewerPlugin extends JScrollPane implements
036: IHTMLViewerPlugin {
037:
038: private XHTMLPanel panel = new XHTMLPanel();
039:
040: URL baseUrl = DiskIO.getResourceURL("org/columba/core/icons/MISC/");
041:
042: public FlyingSaucerViewerPlugin() {
043: super ();
044:
045: setViewportView(panel);
046:
047: setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
048:
049: setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
050:
051: getVerticalScrollBar().setUnitIncrement(15);
052:
053: }
054:
055: public void view(String body) {
056: if (body == null)
057: return;
058: try {
059:
060: Tidy tidy = new Tidy();
061:
062: BufferedInputStream sourceIn = new BufferedInputStream(
063: new ByteArrayInputStream(body
064: .getBytes("ISO-8859-1")));
065:
066: ByteArrayOutputStream out = new ByteArrayOutputStream();
067:
068: // Set bean properties
069: tidy.setQuiet(false);
070: tidy.setShowWarnings(true);
071: tidy.setIndentContent(true);
072: tidy.setSmartIndent(true);
073: tidy.setIndentAttributes(false);
074: tidy.setWraplen(1024);
075: tidy.setXHTML(true);
076: tidy.setXmlOut(true);
077:
078: tidy.setMakeClean(true);
079:
080: tidy.setErrout(new PrintWriter(System.out));
081:
082: tidy.parse(sourceIn, out);
083:
084: panel.setDocument(new ByteArrayInputStream(out
085: .toByteArray()), baseUrl.toExternalForm());
086:
087: } catch (Exception e) {
088: e.printStackTrace();
089: }
090: }
091:
092: public String getSelectedText() {
093: return "";
094: }
095:
096: public boolean initialized() {
097: return true;
098: }
099:
100: public JComponent getComponent() {
101: return panel;
102: }
103:
104: public JComponent getContainer() {
105: return this ;
106: }
107:
108: public String getText() {
109: return "";
110: }
111:
112: /**
113: * @see org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin#setCaretPosition(int)
114: */
115: public void setCaretPosition(int position) {
116: // TODO
117: }
118:
119: /**
120: * @see org.columba.core.gui.htmlviewer.api.IHTMLViewerPlugin#moveCaretPosition(int)
121: */
122: public void moveCaretPosition(int position) {
123: // TODO
124: }
125:
126: }
|