do not hardcode webhelp URL
[fedora-idea.git] / platform / platform-impl / src / com / intellij / help / impl / HelpManagerImpl.java
blob9003f935cf996664bb15dfc371810e6a4abfaec3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.help.impl;
18 import com.intellij.CommonBundle;
19 import com.intellij.ide.BrowserUtil;
20 import com.intellij.ide.IdeBundle;
21 import com.intellij.ide.plugins.HelpSetPath;
22 import com.intellij.ide.plugins.IdeaPluginDescriptor;
23 import com.intellij.openapi.application.Application;
24 import com.intellij.openapi.application.ApplicationInfo;
25 import com.intellij.openapi.application.ApplicationManager;
26 import com.intellij.openapi.application.impl.ApplicationInfoImpl;
27 import com.intellij.openapi.diagnostic.Logger;
28 import com.intellij.openapi.help.HelpManager;
29 import com.intellij.openapi.ui.Messages;
30 import org.jetbrains.annotations.NonNls;
31 import org.jetbrains.annotations.Nullable;
33 import javax.help.BadIDException;
34 import javax.help.HelpSet;
35 import javax.help.HelpSetException;
36 import java.awt.*;
37 import java.net.URL;
39 public class HelpManagerImpl extends HelpManager {
40 private static final Logger LOG = Logger.getInstance("#com.intellij.help.impl.HelpManagerImpl");
42 private HelpSet myHelpSet = null;
43 private IdeaHelpBroker myBroker = null;
44 @NonNls private static final String HELP_HS = "Help.hs";
46 public void invokeHelp(String id) {
47 if (myHelpSet == null) {
48 try {
49 myHelpSet = createHelpSet();
51 catch (Exception ex) {
52 // Ignore, will fallback to use web help
56 if (myHelpSet == null) {
57 BrowserUtil.launchBrowser(ApplicationInfoImpl.getInstanceEx().getWebHelpUrl() + "?" + id);
58 return;
61 if (myBroker == null) {
62 myBroker = new IdeaHelpBroker(myHelpSet);
65 Window activeWindow=KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
66 myBroker.setActivationWindow(activeWindow);
68 if (id != null) {
69 try {
70 myBroker.setCurrentID(id);
72 catch (BadIDException e) {
73 Messages.showMessageDialog(IdeBundle.message("help.topic.not.found.error", id),
74 CommonBundle.getErrorTitle(), Messages.getErrorIcon());
75 return;
78 myBroker.setDisplayed(true);
81 @Nullable
82 private static HelpSet createHelpSet() {
83 String urlToHelp = ApplicationInfo.getInstance().getHelpURL() + "/" + HELP_HS;
85 try {
86 HelpSet helpSet = new HelpSet(null, new URL (urlToHelp));
88 // merge plugins help sets
89 final Application app = ApplicationManager.getApplication();
90 IdeaPluginDescriptor[] pluginDescriptors = app.getPlugins();
91 for (IdeaPluginDescriptor pluginDescriptor : pluginDescriptors) {
92 HelpSetPath[] sets = pluginDescriptor.getHelpSets();
93 for (HelpSetPath hsPath : sets) {
94 URL hsURL =
95 new URL("jar:file:///" + pluginDescriptor.getPath().getAbsolutePath() + "/help/" + hsPath.getFile() + "!" + hsPath.getPath());
96 try {
97 HelpSet pluginHelpSet = new HelpSet(null, hsURL);
98 helpSet.add(pluginHelpSet);
100 catch (HelpSetException e) {
101 LOG.error(e);
106 return helpSet;
108 catch (Exception ee) {
109 return null;