Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 967CF10AC1 for ; Tue, 6 Jan 2015 17:11:44 +0000 (UTC) Received: (qmail 77439 invoked by uid 500); 6 Jan 2015 17:11:45 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 77386 invoked by uid 500); 6 Jan 2015 17:11:45 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 77365 invoked by uid 99); 6 Jan 2015 17:11:45 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Jan 2015 17:11:45 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5A607921A7F; Tue, 6 Jan 2015 17:11:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Tue, 06 Jan 2015 17:11:45 -0000 Message-Id: <7b6d6c0b545a4bffb03395d26c55001d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] camel git commit: CAMEL-7999: Use FactoryFinder to find component documentation location instead of having to maintain special naming code in camel-core. Repository: camel Updated Branches: refs/heads/master 5a276c3c9 -> 565764851 CAMEL-7999: Use FactoryFinder to find component documentation location instead of having to maintain special naming code in camel-core. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/95a24dfc Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/95a24dfc Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/95a24dfc Branch: refs/heads/master Commit: 95a24dfcc75257441be697bc1a12d957d4fb8df0 Parents: 5a276c3 Author: Claus Ibsen Authored: Tue Jan 6 16:16:49 2015 +0100 Committer: Claus Ibsen Committed: Tue Jan 6 16:16:49 2015 +0100 ---------------------------------------------------------------------- .../apache/camel/impl/DefaultCamelContext.java | 107 +++++++++---------- 1 file changed, 52 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/95a24dfc/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index fb42e4e..c492fcf 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -1138,35 +1138,65 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } public String getComponentDocumentation(String componentName) throws IOException { - String packageName = sanitizeComponentName(componentName); - String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + packageName + "/" + componentName + ".html"; - ClassResolver resolver = getClassResolver(); - InputStream inputStream = resolver.loadResourceAsStream(path); - log.debug("Loading component documentation for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream}); - if (inputStream != null) { - try { - return IOHelper.loadText(inputStream); - } finally { - IOHelper.close(inputStream); + // use the component factory finder to find the package name of the component class, which is the location + // where the documentation exists as well + FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH); + try { + Class clazz = finder.findClass(componentName); + if (clazz == null) { + return null; + } + + String packageName = clazz.getPackage().getName(); + packageName = packageName.replace('.', '/'); + String path = packageName + "/" + componentName + ".html"; + + ClassResolver resolver = getClassResolver(); + InputStream inputStream = resolver.loadResourceAsStream(path); + log.debug("Loading component documentation for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream}); + if (inputStream != null) { + try { + return IOHelper.loadText(inputStream); + } finally { + IOHelper.close(inputStream); + } } + return null; + + } catch (ClassNotFoundException e) { + return null; } - return null; } public String getComponentParameterJsonSchema(String componentName) throws IOException { - String packageName = sanitizeComponentName(componentName); - String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + packageName + "/" + componentName + ".json"; - ClassResolver resolver = getClassResolver(); - InputStream inputStream = resolver.loadResourceAsStream(path); - log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream}); - if (inputStream != null) { - try { - return IOHelper.loadText(inputStream); - } finally { - IOHelper.close(inputStream); + // use the component factory finder to find the package name of the component class, which is the location + // where the documentation exists as well + FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH); + try { + Class clazz = finder.findClass(componentName); + if (clazz == null) { + return null; + } + + String packageName = clazz.getPackage().getName(); + packageName = packageName.replace('.', '/'); + String path = packageName + "/" + componentName + ".json"; + + ClassResolver resolver = getClassResolver(); + InputStream inputStream = resolver.loadResourceAsStream(path); + log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream}); + if (inputStream != null) { + try { + return IOHelper.loadText(inputStream); + } finally { + IOHelper.close(inputStream); + } } + return null; + + } catch (ClassNotFoundException e) { + return null; } - return null; } public String getEipParameterJsonSchema(String eipName) throws IOException { @@ -1325,39 +1355,6 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } } - /** - * Sanitizes the component name by removing dash (-) in the name, when using the component name to load - * resources from the classpath. - */ - private static String sanitizeComponentName(String componentName) { - // the ftp components are in a special package - if ("ftp".equals(componentName) || "ftps".equals(componentName) || "sftp".equals(componentName)) { - return "file/remote"; - } else if ("cxfrs".equals(componentName)) { - return "cxf/jaxrs"; - } else if ("gauth".equals(componentName) || "ghttp".equals(componentName) || "glogin".equals(componentName) - || "gmail".equals(componentName) || "gtask".equals(componentName)) { - return "gae/" + componentName.substring(1); - } else if ("guava-eventbus".equals(componentName)) { - return "guava/eventbus"; - } else if ("atmosphere-websocket".equals(componentName)) { - return "atmosphere/websocket"; - } else if ("netty-http".equals(componentName)) { - return "netty/http"; - } else if ("netty4-http".equals(componentName)) { - return "netty4/http"; - } else if ("spring-event".equals(componentName)) { - return "event"; - } else if ("class".equals(componentName)) { - return "beanclass"; - } else if ("smtp".equals(componentName) || "smtps".equals(componentName) - || "imap".equals(componentName) || "imaps".equals(componentName) - || "pop3".equals(componentName) || "pop3s".equals(componentName)) { - return "mail"; - } - return componentName.replaceAll("-", ""); - } - public String explainEndpointJson(String uri, boolean includeAllOptions) { try { URI u = new URI(uri);