class JSRegistry {

    public static String convertToJSRegistry(PluginSimpleContent plugin) {
        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        final StringBuilder sb = new StringBuilder();

        if (plugin.getCodeMap().containsKey(CodeType.MAIN)) {
            sb.append(plugin.getCodeMap().get(CodeType.MAIN));
        }

        if (plugin.getType().equals(PluginType.SCREEN)) {
            sb.append("$registerPlugin({");
        } else if (plugin.getType().equals(PluginType.SPLASH)) {
            sb.append("$registerSplashScreen({");
        } else if (plugin.getType().equals(PluginType.EDITOR)) {
            sb.append("$registerEditor({");
        } else if (plugin.getType().equals(PluginType.PERSPECTIVE)) {
            sb.append("$registerPerspective({");
        }

        sb.append("id:").append('"').append(plugin.getName()).append('"').append(",");

        if (plugin.getCodeMap().size() > 1) {
            //Order Code fragments in the same sequence as defined in the CodeType enum, to aid repeatable testing
            for (CodeType ct : CodeType.values()) {
                if (ct.equals(CodeType.MAIN)) {
                    continue;
                }
                if (plugin.getCodeMap().containsKey(ct)) {
                    sb.append(ct.toString().toLowerCase()).append(": ");
                    sb.append(prepareEntryValue(ct,
                                                plugin.getCodeMap().get(ct))).append(",");
                }
            }
        }

        if (plugin.getFrameworks() != null && !plugin.getFrameworks().isEmpty()) {
            final Framework fm = plugin.getFrameworks().iterator().next();
            sb.append("type: ").append('"').append(fm.getType()).append('"').append(',');
        }

        if (!plugin.getType().equals(PluginType.PERSPECTIVE)) {
            sb.append("template: ");

            gson.toJson(plugin.getTemplate(),
                        sb);
        } else {
            sb.append("view: {").append(plugin.getTemplate()).append("}");
        }

        sb.append("});");
        return sb.toString();
    }

}