/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.catalog;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class DefaultRuntimeProvider implements RuntimeProvider {

    private static final String COMPONENT_DIR = "org/apache/camel/catalog/components";
    private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/dataformats";
    private static final String LANGUAGE_DIR = "org/apache/camel/catalog/languages";
    private static final String OTHER_DIR = "org/apache/camel/catalog/others";
    private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
    private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
    private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
    private static final String OTHER_CATALOG = "org/apache/camel/catalog/others.properties";

    private CamelCatalog camelCatalog;

    public DefaultRuntimeProvider() {
    }

    public DefaultRuntimeProvider(CamelCatalog camelCatalog) {
        this.camelCatalog = camelCatalog;
    }

    @Override
    public CamelCatalog getCamelCatalog() {
        return camelCatalog;
    }

    @Override
    public void setCamelCatalog(CamelCatalog camelCatalog) {
        this.camelCatalog = camelCatalog;
    }

    @Override
    public String getProviderName() {
        return "default";
    }

    @Override
    public String getProviderGroupId() {
        return "org.apache.camel";
    }

    @Override
    public String getProviderArtifactId() {
        return "camel-catalog";
    }

    @Override
    public String getComponentJSonSchemaDirectory() {
        return COMPONENT_DIR;
    }

    @Override
    public String getDataFormatJSonSchemaDirectory() {
        return DATAFORMAT_DIR;
    }

    @Override
    public String getLanguageJSonSchemaDirectory() {
        return LANGUAGE_DIR;
    }

    @Override
    public String getOtherJSonSchemaDirectory() {
        return OTHER_DIR;
    }

    @Override
    public List<String> findComponentNames() {
        List<String> names = new ArrayList<String>();
        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);
        if (is != null) {
            try {
                CatalogHelper.loadLines(is, names);
            } catch (IOException e) {
                // ignore
            }
        }
        return names;
    }

    @Override
    public List<String> findDataFormatNames() {
        List<String> names = new ArrayList<String>();
        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(DATA_FORMATS_CATALOG);
        if (is != null) {
            try {
                CatalogHelper.loadLines(is, names);
            } catch (IOException e) {
                // ignore
            }
        }
        return names;
    }

    @Override
    public List<String> findLanguageNames() {
        List<String> names = new ArrayList<String>();
        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(LANGUAGE_CATALOG);
        if (is != null) {
            try {
                CatalogHelper.loadLines(is, names);
            } catch (IOException e) {
                // ignore
            }
        }
        return names;
    }

    @Override
    public List<String> findOtherNames() {
        List<String> names = new ArrayList<String>();
        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(OTHER_CATALOG);
        if (is != null) {
            try {
                CatalogHelper.loadLines(is, names);
            } catch (IOException e) {
                // ignore
            }
        }
        return names;
    }
}

@@ -2848,32 +2848,373 @@
 HER_DIR;%0A    %7D%0A%0A
+    protected String getComponentsCatalog() %7B%0A        return COMPONENTS_CATALOG;%0A    %7D%0A%0A    protected String getDataFormatsCatalog() %7B%0A        return DATA_FORMATS_CATALOG;%0A    %7D%0A%0A    protected String getLanguageCatalog() %7B%0A        return LANGUAGE_CATALOG;%0A    %7D%0A%0A    protected String getOtherCatalog() %7B%0A        return OTHER_CATALOG;%0A    %7D%0A%0A
     @Override%0A  
@@ -3329,33 +3329,36 @@
 nputStream is = 
-c
+getC
 amelCatalog.getV
@@ -3344,32 +3344,34 @@
  getCamelCatalog
+()
 .getVersionManag
@@ -3395,34 +3395,38 @@
 sStream(
-COMPONENTS_CATALOG
+getComponentsCatalog()
 );%0A     
@@ -3766,33 +3766,36 @@
 nputStream is = 
-c
+getC
 amelCatalog.getV
@@ -3781,32 +3781,34 @@
  getCamelCatalog
+()
 .getVersionManag
@@ -3832,36 +3832,39 @@
 sStream(
-DATA_FORMATS_CATALOG
+getDataFormatsCatalog()
 );%0A     
@@ -4202,33 +4202,36 @@
 nputStream is = 
-c
+getC
 amelCatalog.getV
@@ -4217,32 +4217,34 @@
  getCamelCatalog
+()
 .getVersionManag
@@ -4268,32 +4268,36 @@
 sStream(
-LANGUAGE_CATALOG
+getLanguageCatalog()
 );%0A     
@@ -4640,17 +4640,20 @@
 am is = 
-c
+getC
 amelCata
@@ -4655,16 +4655,18 @@
 lCatalog
+()
 .getVers
@@ -4698,29 +4698,33 @@
 sStream(
-OTHER_CATALOG
+getOtherCatalog()
 );%0A     

Improve DefaultRuntimeProvider abstraction