customizable URL for whatsnew action
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / application / impl / ApplicationInfoImpl.java
blob3a9061d4b63f652afed17f148308fc05661c6481
2 /*
3 * Copyright 2000-2009 JetBrains s.r.o.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package com.intellij.openapi.application.impl;
19 import com.intellij.openapi.application.ApplicationNamesInfo;
20 import com.intellij.openapi.application.PathManager;
21 import com.intellij.openapi.application.ex.ApplicationInfoEx;
22 import com.intellij.openapi.components.ApplicationComponent;
23 import com.intellij.openapi.diagnostic.Logger;
24 import com.intellij.openapi.util.*;
25 import org.jdom.Document;
26 import org.jdom.Element;
27 import org.jetbrains.annotations.NonNls;
28 import org.jetbrains.annotations.NotNull;
30 import java.awt.*;
31 import java.io.File;
32 import java.util.ArrayList;
33 import java.util.Calendar;
34 import java.util.GregorianCalendar;
35 import java.util.List;
37 public class ApplicationInfoImpl extends ApplicationInfoEx implements JDOMExternalizable, ApplicationComponent {
39 private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.impl.ApplicationInfoImpl");
41 @NonNls private static final String BUILD_STUB = "__BUILD_NUMBER__";
42 private String myCodeName = null;
43 private String myMajorVersion = null;
44 private String myMinorVersion = null;
45 private String myBuildNumber = null;
46 private String myLogoUrl = null;
47 private Color myLogoTextColor = new Color(0, 35, 135); // idea blue
48 private String myAboutLogoUrl = null;
49 @NonNls private String myIconUrl = "/icon.png";
50 @NonNls private String mySmallIconUrl = "/icon_small.png";
51 @NonNls private String myOpaqueIconUrl = "/icon.png";
52 @NonNls private String myToolWindowIconUrl = "/general/toolWindowProject.png";
53 private Calendar myBuildDate = null;
54 private String myPackageCode = null;
55 private boolean myShowLicensee = true;
56 private String myWelcomeScreenCaptionUrl;
57 private String myWelcomeScreenDeveloperSloganUrl;
58 private UpdateUrls myUpdateUrls;
59 private String myDocumentationUrl;
60 private String mySupportUrl;
61 private String myEAPFeedbackUrl;
62 private String myReleaseFeedbackUrl;
63 private String myPluginManagerUrl;
64 private String myPluginsListUrl;
65 private String myPluginsDownloadUrl;
66 private String myDefaultUpdateChannel;
67 private String myWhatsNewUrl;
68 private boolean myEAP;
69 @NonNls private String myHelpFileName = "ideahelp.jar";
70 @NonNls private String myHelpRootName = "idea";
71 @NonNls private String myWebHelpUrl = "http://www.jetbrains.com/idea/webhelp/";
72 private List<PluginChooserPage> myPluginChooserPages = new ArrayList<PluginChooserPage>();
74 @NonNls private static final String IDEA_PATH = "/idea/";
75 @NonNls private static final String ELEMENT_VERSION = "version";
76 @NonNls private static final String ATTRIBUTE_MAJOR = "major";
77 @NonNls private static final String ATTRIBUTE_MINOR = "minor";
78 @NonNls private static final String ATTRIBUTE_CODENAME = "codename";
79 @NonNls private static final String ELEMENT_BUILD = "build";
80 @NonNls private static final String ATTRIBUTE_NUMBER = "number";
81 @NonNls private static final String ATTRIBUTE_DATE = "date";
82 @NonNls private static final String ELEMENT_LOGO = "logo";
83 @NonNls private static final String ATTRIBUTE_URL = "url";
84 @NonNls private static final String ATTRIBUTE_TEXTCOLOR = "textcolor";
85 @NonNls private static final String ELEMENT_ABOUT = "about";
86 @NonNls private static final String ELEMENT_ICON = "icon";
87 @NonNls private static final String ATTRIBUTE_SIZE32 = "size32";
88 @NonNls private static final String ATTRIBUTE_SIZE16 = "size16";
89 @NonNls private static final String ATTRIBUTE_SIZE12 = "size12";
90 @NonNls private static final String ATTRIBUTE_SIZE32OPAQUE = "size32opaque";
91 @NonNls private static final String ELEMENT_PACKAGE = "package";
92 @NonNls private static final String ATTRIBUTE_CODE = "code";
93 @NonNls private static final String ELEMENT_LICENSEE = "licensee";
94 @NonNls private static final String ATTRIBUTE_SHOW = "show";
95 @NonNls private static final String WELCOME_SCREEN_ELEMENT_NAME = "welcome-screen";
96 @NonNls private static final String CAPTION_URL_ATTR = "caption-url";
97 @NonNls private static final String SLOGAN_URL_ATTR = "slogan-url";
98 @NonNls private static final String UPDATE_URLS_ELEMENT_NAME = "update-urls";
99 @NonNls private static final String XML_EXTENSION = ".xml";
100 @NonNls private static final String ATTRIBUTE_EAP = "eap";
101 @NonNls private static final String HELP_ELEMENT_NAME = "help";
102 @NonNls private static final String ATTRIBUTE_HELP_FILE = "file";
103 @NonNls private static final String ATTRIBUTE_HELP_ROOT = "root";
104 @NonNls private static final String PLUGINS_PAGE_ELEMENT_NAME = "plugins-page";
105 @NonNls private static final String ELEMENT_DOCUMENTATION = "documentation";
106 @NonNls private static final String ELEMENT_SUPPORT = "support";
107 @NonNls private static final String ELEMENT_FEEDBACK = "feedback";
108 @NonNls private static final String ATTRIBUTE_RELEASE_URL = "release-url";
109 @NonNls private static final String ATTRIBUTE_EAP_URL = "eap-url";
110 @NonNls private static final String ELEMENT_PLUGINS = "plugins";
111 @NonNls private static final String ATTRIBUTE_LIST_URL = "list-url";
112 @NonNls private static final String ATTRIBUTE_DOWNLOAD_URL = "download-url";
113 @NonNls private static final String ATTRIBUTE_WEBHELP_URL = "webhelp-url";
114 @NonNls private static final String ELEMENT_WHATSNEW = "whatsnew";
116 public void initComponent() { }
118 public void disposeComponent() {
121 public Calendar getBuildDate() {
122 return myBuildDate;
125 @Override
126 public BuildNumber getBuild() {
127 return BuildNumber.fromString(myBuildNumber);
130 public String getMajorVersion() {
131 return myMajorVersion;
134 public String getMinorVersion() {
135 return myMinorVersion;
138 public String getVersionName() {
139 final String fullName = ApplicationNamesInfo.getInstance().getFullProductName();
140 if (myEAP) {
141 return fullName + " (" + myCodeName + ")";
143 return fullName;
146 @NonNls
147 public String getHelpURL() {
148 return "jar:file:///" + getHelpJarPath() + "!/" + myHelpRootName;
151 @NonNls
152 private String getHelpJarPath() {
153 return PathManager.getHomePath() + File.separator + "help" + File.separator + myHelpFileName;
156 public String getLogoUrl() {
157 return myLogoUrl;
160 public Color getLogoTextColor() {
161 return myLogoTextColor;
164 public String getAboutLogoUrl() {
165 return myAboutLogoUrl;
168 public String getIconUrl() {
169 return myIconUrl;
172 public String getSmallIconUrl() {
173 return mySmallIconUrl;
176 public String getOpaqueIconUrl() {
177 return myOpaqueIconUrl;
180 public String getToolWindowIconUrl() {
181 return myToolWindowIconUrl;
184 public String getPackageCode() {
185 return myPackageCode;
188 public String getWelcomeScreenCaptionUrl() {
189 return myWelcomeScreenCaptionUrl;
192 public String getWelcomeScreenDeveloperSloganUrl() {
193 return myWelcomeScreenDeveloperSloganUrl;
196 public boolean isEAP() {
197 return myEAP;
200 public String getDefaultUpdateChannel() {
201 return myDefaultUpdateChannel;
204 public UpdateUrls getUpdateUrls() {
205 return myUpdateUrls;
208 public String getDocumentationUrl() {
209 return myDocumentationUrl;
212 public String getSupportUrl() {
213 return mySupportUrl;
216 public String getEAPFeedbackUrl() {
217 return myEAPFeedbackUrl;
220 public String getReleaseFeedbackUrl() {
221 return myReleaseFeedbackUrl;
224 @Override
225 public String getPluginManagerUrl() {
226 return myPluginManagerUrl;
229 public String getPluginsListUrl() {
230 return myPluginsListUrl;
233 public String getPluginsDownloadUrl() {
234 return myPluginsDownloadUrl;
237 public String getWebHelpUrl() {
238 return myWebHelpUrl;
241 public String getWhatsNewUrl() {
242 return myWhatsNewUrl;
245 public String getFullApplicationName() {
246 @NonNls StringBuilder buffer = new StringBuilder();
247 buffer.append(getVersionName());
248 buffer.append(" ");
249 if (getMajorVersion() != null && !isEAP()) {
250 buffer.append(getMajorVersion());
252 if (getMinorVersion() != null && getMinorVersion().length() > 0){
253 buffer.append(".");
254 buffer.append(getMinorVersion());
257 else {
258 String bn = getBuildNumber();
259 if (!BUILD_STUB.equals(bn)) {
260 buffer.append('#');
261 buffer.append(bn);
263 else {
264 buffer.append("DevVersion");
267 return buffer.toString();
270 public boolean showLicenseeInfo() {
271 return myShowLicensee;
274 private static ApplicationInfoImpl ourShadowInstance;
276 public static ApplicationInfoEx getShadowInstance() {
277 if (ourShadowInstance == null) {
278 ourShadowInstance = new ApplicationInfoImpl();
279 try {
280 Document doc = JDOMUtil.loadDocument(ApplicationInfoImpl.class.getResourceAsStream(IDEA_PATH +
281 ApplicationNamesInfo.getComponentName() +
282 XML_EXTENSION));
283 ourShadowInstance.readExternal(doc.getRootElement());
285 catch (Exception e) {
286 LOG.error(e);
289 return ourShadowInstance;
292 public void readExternal(Element parentNode) throws InvalidDataException {
293 Element versionElement = parentNode.getChild(ELEMENT_VERSION);
294 if (versionElement != null) {
295 myMajorVersion = versionElement.getAttributeValue(ATTRIBUTE_MAJOR);
296 myMinorVersion = versionElement.getAttributeValue(ATTRIBUTE_MINOR);
297 myCodeName = versionElement.getAttributeValue(ATTRIBUTE_CODENAME);
298 myEAP = Boolean.parseBoolean(versionElement.getAttributeValue(ATTRIBUTE_EAP));
299 myDefaultUpdateChannel = versionElement.getAttributeValue("update-channel");
302 Element buildElement = parentNode.getChild(ELEMENT_BUILD);
303 if (buildElement != null) {
304 myBuildNumber = buildElement.getAttributeValue(ATTRIBUTE_NUMBER);
305 String dateString = buildElement.getAttributeValue(ATTRIBUTE_DATE);
306 if (dateString.equals("__BUILD_DATE__")) {
307 myBuildDate = new GregorianCalendar();
309 else {
310 int year = 0;
311 int month = 0;
312 int day = 0;
313 try {
314 year = Integer.parseInt(dateString.substring(0, 4));
315 month = Integer.parseInt(dateString.substring(4, 6));
316 day = Integer.parseInt(dateString.substring(6, 8));
318 catch (Exception ex) {
319 //ignore
321 if (month > 0) {
322 month--;
324 myBuildDate = new GregorianCalendar(year, month, day);
328 Thread currentThread = Thread.currentThread();
329 currentThread.setName(currentThread.getName() + " " + myMajorVersion + "." + myMinorVersion + "#" + myBuildNumber + ", eap:"+myEAP);
331 Element logoElement = parentNode.getChild(ELEMENT_LOGO);
332 if (logoElement != null) {
333 myLogoUrl = logoElement.getAttributeValue(ATTRIBUTE_URL);
334 final int rgb = Integer.parseInt(logoElement.getAttributeValue(ATTRIBUTE_TEXTCOLOR), 16);
335 myLogoTextColor = new Color(rgb);
338 Element aboutLogoElement = parentNode.getChild(ELEMENT_ABOUT);
339 if (aboutLogoElement != null) {
340 myAboutLogoUrl = aboutLogoElement.getAttributeValue(ATTRIBUTE_URL);
343 Element iconElement = parentNode.getChild(ELEMENT_ICON);
344 if (iconElement != null) {
345 myIconUrl = iconElement.getAttributeValue(ATTRIBUTE_SIZE32);
346 mySmallIconUrl = iconElement.getAttributeValue(ATTRIBUTE_SIZE16);
347 myOpaqueIconUrl = iconElement.getAttributeValue(ATTRIBUTE_SIZE32OPAQUE);
348 final String toolWindowIcon = iconElement.getAttributeValue(ATTRIBUTE_SIZE12);
349 if (toolWindowIcon != null) {
350 myToolWindowIconUrl = toolWindowIcon;
354 Element packageElement = parentNode.getChild(ELEMENT_PACKAGE);
355 if (packageElement != null) {
356 myPackageCode = packageElement.getAttributeValue(ATTRIBUTE_CODE);
359 Element showLicensee = parentNode.getChild(ELEMENT_LICENSEE);
360 if (showLicensee != null) {
361 myShowLicensee = Boolean.valueOf(showLicensee.getAttributeValue(ATTRIBUTE_SHOW)).booleanValue();
364 Element welcomeScreen = parentNode.getChild(WELCOME_SCREEN_ELEMENT_NAME);
365 if (welcomeScreen != null) {
366 myWelcomeScreenCaptionUrl = welcomeScreen.getAttributeValue(CAPTION_URL_ATTR);
367 myWelcomeScreenDeveloperSloganUrl = welcomeScreen.getAttributeValue(SLOGAN_URL_ATTR);
370 Element helpElement = parentNode.getChild(HELP_ELEMENT_NAME);
371 if (helpElement != null) {
372 myHelpFileName = helpElement.getAttributeValue(ATTRIBUTE_HELP_FILE);
373 myHelpRootName = helpElement.getAttributeValue(ATTRIBUTE_HELP_ROOT);
374 final String webHelpUrl = helpElement.getAttributeValue(ATTRIBUTE_WEBHELP_URL);
375 if (webHelpUrl != null) {
376 myWebHelpUrl = webHelpUrl;
380 Element updateUrls = parentNode.getChild(UPDATE_URLS_ELEMENT_NAME);
381 myUpdateUrls = new UpdateUrlsImpl(updateUrls);
383 Element documentationElement = parentNode.getChild(ELEMENT_DOCUMENTATION);
384 if (documentationElement != null) {
385 myDocumentationUrl = documentationElement.getAttributeValue(ATTRIBUTE_URL);
388 Element supportElement = parentNode.getChild(ELEMENT_SUPPORT);
389 if (supportElement != null) {
390 mySupportUrl = supportElement.getAttributeValue(ATTRIBUTE_URL);
393 Element feedbackElement = parentNode.getChild(ELEMENT_FEEDBACK);
394 if (feedbackElement != null) {
395 myEAPFeedbackUrl = feedbackElement.getAttributeValue(ATTRIBUTE_EAP_URL);
396 myReleaseFeedbackUrl = feedbackElement.getAttributeValue(ATTRIBUTE_RELEASE_URL);
399 Element whatsnewElement = parentNode.getChild(ELEMENT_WHATSNEW);
400 if (whatsnewElement != null) {
401 myWhatsNewUrl = whatsnewElement.getAttributeValue(ATTRIBUTE_URL);
404 myPluginsListUrl = "http://plugins.intellij.net/plugins/list/";
405 myPluginsDownloadUrl = "http://plugins.intellij.net/pluginManager";
407 Element pluginsElement = parentNode.getChild(ELEMENT_PLUGINS);
408 if (pluginsElement != null) {
409 myPluginManagerUrl = pluginsElement.getAttributeValue(ATTRIBUTE_URL);
410 final String listUrl = pluginsElement.getAttributeValue(ATTRIBUTE_LIST_URL);
411 if (listUrl != null) {
412 myPluginsListUrl = listUrl;
414 final String downloadUrl = pluginsElement.getAttributeValue(ATTRIBUTE_DOWNLOAD_URL);
415 if (downloadUrl != null) {
416 myPluginsDownloadUrl = downloadUrl;
419 else {
420 myPluginManagerUrl = "http://plugins.intellij.net";
423 myPluginChooserPages = new ArrayList<PluginChooserPage>();
424 final List children = parentNode.getChildren(PLUGINS_PAGE_ELEMENT_NAME);
425 for(Object child: children) {
426 myPluginChooserPages.add(new PluginChooserPageImpl((Element) child));
430 public List<PluginChooserPage> getPluginChooserPages() {
431 return myPluginChooserPages;
434 public void writeExternal(Element element) throws WriteExternalException {
435 throw new WriteExternalException();
439 @NotNull
440 public String getComponentName() {
441 return ApplicationNamesInfo.getComponentName();
444 private static class UpdateUrlsImpl implements UpdateUrls {
445 private String myCheckingUrl;
446 private String myPatchesUrl;
448 private UpdateUrlsImpl(Element element) {
449 if (element != null) {
450 myCheckingUrl = element.getAttributeValue("check");
451 myPatchesUrl = element.getAttributeValue("patches");
455 public String getCheckingUrl() {
456 return myCheckingUrl;
459 public String getPatchesUrl() {
460 return myPatchesUrl;
464 private static class PluginChooserPageImpl implements PluginChooserPage {
465 private final String myTitle;
466 private final String myCategory;
467 private final String myDependentPlugin;
469 private PluginChooserPageImpl(Element e) {
470 myTitle = e.getAttributeValue("title");
471 myCategory = e.getAttributeValue("category");
472 myDependentPlugin = e.getAttributeValue("depends");
475 public String getTitle() {
476 return myTitle;
479 public String getCategory() {
480 return myCategory;
483 public String getDependentPlugin() {
484 return myDependentPlugin;