Skip to content

Commit

Permalink
CAMEL-8232: Camel Toolbox - Include documentation about data formats
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Jan 13, 2015
1 parent 109285c commit d809f46
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 14 deletions.
3 changes: 2 additions & 1 deletion platforms/catalog/pom.xml
Expand Up @@ -34,7 +34,8 @@
<camel.osgi.export.pkg>
org.apache.camel.catalog,
org.apache.camel.catalog.models,
org.apache.camel.catalog.components
org.apache.camel.catalog.components,
org.apache.camel.catalog.dataformats
</camel.osgi.export.pkg>
</properties>

Expand Down
Expand Up @@ -29,20 +29,46 @@ public interface CamelComponentCatalog {
*/
List<String> findComponentNames();

/**
* Find all the data format names from the Camel catalog
*/
List<String> findDataFormatNames();

/**
* Find all the model names from the Camel catalog
*/
List<String> findModelNames();

/**
* Find all the component names from the Camel catalog that matches the label
*/
List<String> findComponentNames(String filter);

/**
* Find all the data format names from the Camel catalog that matches the label
*/
List<String> findDataFormatNames(String filter);

/**
* Find all the model names from the Camel catalog that matches the label
*/
List<String> findModelNames(String label);
List<String> findModelNames(String filter);

/**
* Find all the component names from the Camel catalog that matches the label
* Returns the component information as JSon format.
*
* @param name the component name
* @return component details in JSon
*/
List<String> findComponentNames(String label);
String componentJSonSchema(String name);

/**
* Returns the data format information as JSon format.
*
* @param name the data format name
* @return data format details in JSon
*/
String dataFormatJSonSchema(String name);

/**
* Returns the model information as JSon format.
Expand All @@ -53,24 +79,23 @@ public interface CamelComponentCatalog {
String modelJSonSchema(String name);

/**
* Returns the component information as JSon format.
* Find all the unique label names all the components are using.
*
* @param name the component name
* @return component details in JSon
* @return a set of all the labels.
*/
String componentJSonSchema(String name);
Set<String> findComponentLabels();

/**
* Find all the unique label names all the models are using.
* Find all the unique label names all the data formats are using.
*
* @return a set of all the labels.
*/
Set<String> findModelLabels();
Set<String> findDataFormatLabels();

/**
* Find all the unique label names all the components are using.
* Find all the unique label names all the models are using.
*
* @return a set of all the labels.
*/
Set<String> findComponentLabels();
Set<String> findModelLabels();
}
Expand Up @@ -36,8 +36,10 @@ public class DefaultCamelComponentCatalog implements CamelComponentCatalog {

private static final String MODELS_CATALOG = "org/apache/camel/catalog/models.properties";
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 MODEL_JSON = "org/apache/camel/catalog/models";
private static final String COMPONENTS_JSON = "org/apache/camel/catalog/components";
private static final String DATA_FORMATS_JSON = "org/apache/camel/catalog/dataformats";

@Override
public List<String> findComponentNames() {
Expand All @@ -54,6 +56,21 @@ public List<String> findComponentNames() {
return names;
}

@Override
public List<String> findDataFormatNames() {
List<String> names = new ArrayList<String>();

InputStream is = DefaultCamelComponentCatalog.class.getClassLoader().getResourceAsStream(DATA_FORMATS_CATALOG);
if (is != null) {
try {
loadLines(is, names);
} catch (IOException e) {
// ignore
}
}
return names;
}

@Override
public List<String> findModelNames() {
List<String> names = new ArrayList<String>();
Expand Down Expand Up @@ -129,6 +146,36 @@ public List<String> findComponentNames(String filter) {
return answer;
}

@Override
public List<String> findDataFormatNames(String filter) {
List<String> answer = new ArrayList<String>();

List<String> names = findDataFormatNames();
for (String name : names) {
String json = dataFormatJSonSchema(name);
if (json != null) {
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
for (Map<String, String> row : rows) {
if (row.containsKey("label")) {
String label = row.get("label");
String[] parts = label.split(",");
for (String part : parts) {
try {
if (part.equalsIgnoreCase(filter) || matchWildcard(part, filter) || part.matches(filter)) {
answer.add(name);
}
} catch (PatternSyntaxException e) {
// ignore as filter is maybe not a pattern
}
}
}
}
}
}

return answer;
}

@Override
public String modelJSonSchema(String name) {
String file = MODEL_JSON + "/" + name + ".json";
Expand Down Expand Up @@ -161,6 +208,22 @@ public String componentJSonSchema(String name) {
return null;
}

@Override
public String dataFormatJSonSchema(String name) {
String file = DATA_FORMATS_JSON + "/" + name + ".json";

InputStream is = DefaultCamelComponentCatalog.class.getClassLoader().getResourceAsStream(file);
if (is != null) {
try {
return loadText(is);
} catch (IOException e) {
// ignore
}
}

return null;
}

@Override
public Set<String> findModelLabels() {
SortedSet<String> answer = new TreeSet<String>();
Expand Down Expand Up @@ -209,6 +272,30 @@ public Set<String> findComponentLabels() {
return answer;
}

@Override
public Set<String> findDataFormatLabels() {
SortedSet<String> answer = new TreeSet<String>();

List<String> names = findDataFormatNames();
for (String name : names) {
String json = dataFormatJSonSchema(name);
if (json != null) {
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
for (Map<String, String> row : rows) {
if (row.containsKey("label")) {
String label = row.get("label");
String[] parts = label.split(",");
for (String part : parts) {
answer.add(part);
}
}
}
}
}

return answer;
}

/**
* Loads the entire stream into memory as a String and returns it.
* <p/>
Expand Down

0 comments on commit d809f46

Please sign in to comment.