1 package com.eviware.soapui.support.components;
2
3 import com.eviware.soapui.SoapUI;
4 import com.eviware.soapui.support.DefaultHyperlinkListener;
5 import com.eviware.soapui.support.UISupport;
6
7 import javax.swing.*;
8 import javax.swing.text.html.HTMLEditorKit;
9 import java.awt.*;
10 import java.io.ByteArrayInputStream;
11 import java.io.IOException;
12 import java.net.NoRouteToHostException;
13 import java.net.URL;
14
15 public class BrowserComponent
16 {
17 private JEditorPane editorPane;
18 private JScrollPane scrollPane;
19
20
21
22
23
24
25
26
27 public BrowserComponent()
28 {
29 editorPane = new JEditorPane();
30 editorPane.setEditorKit( new HTMLEditorKit() );
31 editorPane.setEditable( false );
32 editorPane.addHyperlinkListener( new DefaultHyperlinkListener( editorPane ) );
33 }
34
35 public Component getComponent()
36 {
37
38
39
40
41
42
43 if( scrollPane == null )
44 {
45 scrollPane = new JScrollPane( editorPane );
46 UISupport.addPreviewCorner( scrollPane, false );
47 }
48 return scrollPane;
49 }
50
51 private void initBrowser()
52 {
53
54
55
56
57
58
59
60
61
62
63
64
65 }
66
67 public void release()
68 {
69
70
71
72
73 }
74
75 public void setContent( String contentAsString, String contentType, String contextUri )
76 {
77 editorPane.setContentType( contentType );
78 try
79 {
80 editorPane.read( new ByteArrayInputStream( contentAsString.getBytes() ), editorPane.getEditorKit().createDefaultDocument() );
81 }
82 catch( IOException e )
83 {
84 e.printStackTrace();
85 }
86
87
88
89
90
91
92 }
93
94 public void setContent( String content, String contentType )
95 {
96 setContent( content, contentType, null );
97
98
99
100
101
102
103 }
104
105 public boolean navigate( String url )
106 {
107 try
108 {
109 editorPane.setPage( new URL( url ) );
110 return true;
111 }
112 catch( NoRouteToHostException e )
113 {
114 SoapUI.log.warn( "Failed to access [" + url + "]" );
115 }
116 catch( Exception e )
117 {
118 SoapUI.logError( e );
119 }
120
121 return false;
122
123
124
125
126
127
128
129 }
130
131 public String getContent()
132 {
133
134 return editorPane.getText();
135 }
136 }