Search in sources :

Example 1 with TemplateReaderWriter

use of org.eclipse.jface.text.templates.persistence.TemplateReaderWriter in project dbeaver by serge-rider.

the class SQLTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
    if (file != null) {
        Bundle plugin = Platform.getBundle(contributorId);
        URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
        if (url != null) {
            ResourceBundle bundle = null;
            if (translations != null) {
                URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
                if (bundleURL != null) {
                    InputStream bundleStream = bundleURL.openStream();
                    try {
                        bundle = new PropertyResourceBundle(bundleStream);
                    } finally {
                        ContentUtils.close(bundleStream);
                    }
                }
            }
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                TemplateReaderWriter reader = new TemplateReaderWriter();
                TemplatePersistenceData[] datas = reader.read(stream, bundle);
                for (TemplatePersistenceData data : datas) {
                    if (data.isCustom()) {
                        if (data.getId() == null)
                            log.error("No template id specified");
                        else
                            log.error("Template " + data.getTemplate().getName() + " deleted");
                    } else if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } finally {
                ContentUtils.close(stream);
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

URL (java.net.URL)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)1 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)1 Bundle (org.osgi.framework.Bundle)1