diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.doc/src/org/eclipse/etrice/doc/KeywordHoverContentProvider.java')
-rw-r--r-- | plugins/org.eclipse.etrice.doc/src/org/eclipse/etrice/doc/KeywordHoverContentProvider.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.doc/src/org/eclipse/etrice/doc/KeywordHoverContentProvider.java b/plugins/org.eclipse.etrice.doc/src/org/eclipse/etrice/doc/KeywordHoverContentProvider.java new file mode 100644 index 000000000..b02bc56ff --- /dev/null +++ b/plugins/org.eclipse.etrice.doc/src/org/eclipse/etrice/doc/KeywordHoverContentProvider.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2015 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.doc; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.etrice.core.common.ui.hover.IKeywordHoverContentProvider; + + +public class KeywordHoverContentProvider implements IKeywordHoverContentProvider { + + private static final String CONTENT_DIR; + static { + if(ETriceHelp.DEV_MODE) + CONTENT_DIR = "/feature-gen/keyword-hover/"; + else + CONTENT_DIR = "/targets/keyword-hover/"; + } + + private final Map<String, String> cache = new HashMap<String, String>(); + + @Override + public String getHTMLContent(String name) { + if (!ETriceHelp.DEV_MODE && cache.containsKey(name)) { + return cache.get(name); + } + + URL fileURL = ETriceHelp.getDefault().getBundle().getEntry(CONTENT_DIR + name + ".html"); + String result = null; + if (fileURL != null) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(fileURL.openStream())); + StringBuffer buffer = new StringBuffer(1500); + String line = reader.readLine(); + while (line != null) { + buffer.append(line); + buffer.append('\n'); + line = reader.readLine(); + } + result = buffer.toString(); + } + catch (IOException ex) { + } + finally { + try { + if (reader != null) + reader.close(); + } + catch (IOException e) { + } + } + } + + cache.put(name, result); + return result; + } +} |