From 8a7530ee04c39d6f30f9bb8be1558730bfcc2d41 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 24 Dec 2014 21:43:47 +0100 Subject: [PATCH] cleanup --- .../application/ex/DecodeDefaultsUtil.java | 48 +++++++------------ .../impl/stores/ApplicationStoreImpl.java | 7 ++- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/ex/DecodeDefaultsUtil.java b/platform/platform-impl/src/com/intellij/openapi/application/ex/DecodeDefaultsUtil.java index f57812afca18..88f74955f8e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/ex/DecodeDefaultsUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/ex/DecodeDefaultsUtil.java @@ -15,11 +15,12 @@ */ package com.intellij.openapi.application.ex; +import com.intellij.openapi.components.impl.stores.DirectoryStorageData; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.io.URLUtil; import gnu.trove.THashMap; -import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -32,46 +33,33 @@ public class DecodeDefaultsUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.ex.DecodeDefaultsUtil"); private static final Map RESOURCE_CACHE = Collections.synchronizedMap(new THashMap()); - @NonNls private static final String XML_EXTENSION = ".xml"; - - public static URL getDefaults(Object requestor, final String componentResourcePath) { - if (RESOURCE_CACHE.containsKey(componentResourcePath)) { - return RESOURCE_CACHE.get(componentResourcePath); + public static URL getDefaults(Object requestor, @NotNull String componentResourcePath) { + URL url = RESOURCE_CACHE.get(componentResourcePath); + if (url == null) { + Class requestorClass = requestor.getClass(); + if (StringUtil.startsWithChar(componentResourcePath, '/')) { + url = requestorClass.getResource(componentResourcePath + DirectoryStorageData.DEFAULT_EXT); + } + else { + url = requestorClass.getResource('/' + ApplicationManagerEx.getApplicationEx().getName() + '/' + componentResourcePath + DirectoryStorageData.DEFAULT_EXT); + if (url == null) { + url = requestorClass.getResource('/' + componentResourcePath + DirectoryStorageData.DEFAULT_EXT); + } + } + RESOURCE_CACHE.put(componentResourcePath, url); } - - URL url = getDefaultsImpl(requestor, componentResourcePath); - RESOURCE_CACHE.put(componentResourcePath, url); return url; } - private static URL getDefaultsImpl(final Object requestor, final String componentResourcePath) { - boolean isPathAbsolute = StringUtil.startsWithChar(componentResourcePath, '/'); - if (isPathAbsolute) { - return requestor.getClass().getResource(componentResourcePath + XML_EXTENSION); - } - else { - return getResourceByRelativePath(requestor, componentResourcePath, XML_EXTENSION); - } - } - @Nullable - public static InputStream getDefaultsInputStream(Object requestor, final String componentResourcePath) { + public static InputStream getDefaultsInputStream(Object requestor, @NotNull String componentResourcePath) { try { final URL defaults = getDefaults(requestor, componentResourcePath); - return defaults != null ? URLUtil.openStream(defaults) : null; + return defaults == null ? null : URLUtil.openStream(defaults); } catch (IOException e) { LOG.error(e); return null; } } - - private static URL getResourceByRelativePath(Object requestor, final String componentResourcePath, String resourceExtension) { - String appName = ApplicationManagerEx.getApplicationEx().getName(); - URL result = requestor.getClass().getResource("/" + appName + "/" + componentResourcePath + resourceExtension); - if (result == null) { - result = requestor.getClass().getResource("/" + componentResourcePath + resourceExtension); - } - return result; - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java index 4d34e071993b..638cbf993cde 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java @@ -33,8 +33,7 @@ import java.io.IOException; class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationStore { private static final Logger LOG = Logger.getInstance(ApplicationStoreImpl.class); - private static final String XML_EXTENSION = ".xml"; - private static final String DEFAULT_STORAGE_SPEC = StoragePathMacros.APP_CONFIG + "/" + PathManager.DEFAULT_OPTIONS_FILE_NAME + XML_EXTENSION; + private static final String DEFAULT_STORAGE_SPEC = StoragePathMacros.APP_CONFIG + "/" + PathManager.DEFAULT_OPTIONS_FILE_NAME + DirectoryStorageData.DEFAULT_EXT; private static final String ROOT_ELEMENT_NAME = "application"; private final ApplicationImpl myApplication; @@ -59,7 +58,7 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto @Override protected String getOldStorageSpec(@NotNull Object component, @NotNull String componentName, @NotNull StateStorageOperation operation) { if (component instanceof NamedJDOMExternalizable) { - return StoragePathMacros.APP_CONFIG + "/" + ((NamedJDOMExternalizable)component).getExternalFileName() + XML_EXTENSION; + return StoragePathMacros.APP_CONFIG + '/' + ((NamedJDOMExternalizable)component).getExternalFileName() + DirectoryStorageData.DEFAULT_EXT; } else { return DEFAULT_STORAGE_SPEC; @@ -68,7 +67,7 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto @Override protected TrackingPathMacroSubstitutor getMacroSubstitutor(@NotNull final String fileSpec) { - if (fileSpec.equals(StoragePathMacros.APP_CONFIG + "/" + PathMacrosImpl.EXT_FILE_NAME + XML_EXTENSION)) return null; + if (fileSpec.equals(StoragePathMacros.APP_CONFIG + '/' + PathMacrosImpl.EXT_FILE_NAME + DirectoryStorageData.DEFAULT_EXT)) return null; return super.getMacroSubstitutor(fileSpec); }