|
3 | 3 | */ |
4 | 4 | package io.snyk.eclipse.plugin.views.snyktoolview; |
5 | 5 |
|
| 6 | +import java.io.ByteArrayOutputStream; |
| 7 | +import java.io.InputStream; |
| 8 | +import java.net.URL; |
| 9 | +import java.util.Base64; |
| 10 | + |
6 | 11 | import javax.inject.Inject; |
7 | 12 |
|
| 13 | +import org.eclipse.core.runtime.FileLocator; |
| 14 | +import org.eclipse.core.runtime.Path; |
| 15 | +import org.eclipse.core.runtime.Platform; |
8 | 16 | import org.eclipse.jface.action.Action; |
9 | 17 | import org.eclipse.jface.preference.PreferenceDialog; |
10 | 18 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
23 | 31 | import org.eclipse.ui.PlatformUI; |
24 | 32 | import org.eclipse.ui.dialogs.PreferencesUtil; |
25 | 33 | import org.eclipse.ui.part.ViewPart; |
| 34 | +import org.osgi.framework.Bundle; |
26 | 35 |
|
27 | 36 | /** |
28 | 37 | * The view will replace the old SnykView. TODO move the snyktoolview classes |
@@ -101,21 +110,26 @@ private String generateHtmlContent(TreeNode node) { |
101 | 110 | } |
102 | 111 |
|
103 | 112 | private String generateHtmlContent(String text) { |
104 | | - return "<html><body><h1>" + "</h1><p>Content for " + "</p></body></html>"; |
| 113 | + return "<html><body<p>" + text + "</p></body></html>"; |
105 | 114 | } |
106 | 115 |
|
107 | 116 | private void initBrowserText() { |
| 117 | + String snykWarningText = Platform.getResourceString(Platform.getBundle("io.snyk.eclipse.plugin"), |
| 118 | + "%snyk.trust.dialog.warning.text"); |
| 119 | + |
| 120 | + Bundle bundle = Platform.getBundle("io.snyk.eclipse.plugin"); |
| 121 | + URL imageUrl = FileLocator.find(bundle, new Path("icons/logo_snyk.png"), null); |
| 122 | + |
| 123 | + byte[] imageData = getImageDataFromUrl(imageUrl); |
108 | 124 |
|
109 | | - browser.setText("<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n" |
110 | | - + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" |
111 | | - + " <title>Snyk for JetBrains</title>\n" + "</head>\n" + "<body>\n" |
112 | | - + " <p><strong>Welcome to Snyk for JetBrains</strong></p>\n" + "\n" + " <ol>\n" |
113 | | - + " <li align=\"left\">Authenticate to Snyk.io</li>\n" |
114 | | - + " <li align=\"left\">Analyze code for issues and vulnerabilities</li>\n" |
115 | | - + " <li align=\"left\">Improve your code and upgrade dependencies</li>\n" + " </ol>\n" + "\n" |
116 | | - + " <p>\n" |
117 | | - + " When scanning project files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br><br>You should only scan projects you trust.<br><br>\n" |
118 | | - + "</body>\n" + "</html>"); |
| 125 | + String base64Image = Base64.getEncoder().encodeToString(imageData); |
| 126 | + |
| 127 | + browser.setText("<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> " |
| 128 | + + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> " |
| 129 | + + "<title>Snyk for JetBrains</title> <style> .container { display: flex; align-items: center; } .logo { margin-right: 20px; } " |
| 130 | + + "</style> </head> <body> <div class=\"container\"> " + "<img src='data:image/png;base64," |
| 131 | + + base64Image + "' alt='Snyk Logo'>" + "<div> <p><strong>Welcome to Snyk for JetBrains</strong></p>" |
| 132 | + + " <p>\n" + snykWarningText + "</body>\n" + "</html>"); |
119 | 133 | } |
120 | 134 |
|
121 | 135 | private Object createTreeInput() { |
@@ -153,6 +167,25 @@ public void run() { |
153 | 167 |
|
154 | 168 | } |
155 | 169 |
|
| 170 | + public byte[] getImageDataFromUrl(URL imageUrl) { |
| 171 | + try { |
| 172 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 173 | + |
| 174 | + try (InputStream inputStream = imageUrl.openStream()) { |
| 175 | + int n = 0; |
| 176 | + byte[] buffer = new byte[1024]; |
| 177 | + while (-1 != (n = inputStream.read(buffer))) { |
| 178 | + output.write(buffer, 0, n); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + return output.toByteArray(); |
| 183 | + } catch (Exception e) { |
| 184 | + e.printStackTrace(); |
| 185 | + return null; |
| 186 | + } |
| 187 | + } |
| 188 | + |
156 | 189 | private static Shell getShell() { |
157 | 190 | var activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
158 | 191 | if (activeWorkbenchWindow == null) |
|
0 commit comments