Search in sources :

Example 1 with TemplateReaderWriter

use of org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter in project che by eclipse.

the class ContributionTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(Collection templates, /*, IConfigurationElement element*/
String file) throws IOException {
    //		String file= element.getAttribute(FILE);
    if (file != null) {
        //			Bundle plugin = Platform.getBundle(element.getContributor().getName());
        //			URL url= FileLocator.find(plugin, Path.fromOSString(file), null);
        URL url = ContributionTemplateStore.class.getResource(file);
        if (url != null) {
            ResourceBundle bundle = null;
            InputStream bundleStream = null;
            InputStream stream = null;
            try {
                //					String translations= element.getAttribute(TRANSLATIONS);
                //					if (translations != null) {
                //file.substring(0, file.lastIndexOf('.'));
                String props = "/org/eclipse/templates/default-templates.properties";
                URL bundleURL = ContributionTemplateStore.class.getResource(props);
                if (bundleURL != null) {
                    bundleStream = bundleURL.openStream();
                    bundle = new PropertyResourceBundle(bundleStream);
                }
                //					}
                stream = new BufferedInputStream(url.openStream());
                TemplateReaderWriter reader = new TemplateReaderWriter();
                TemplatePersistenceData[] datas = reader.read(stream, bundle);
                for (int i = 0; i < datas.length; i++) {
                    TemplatePersistenceData data = datas[i];
                    if (data.isCustom()) {
                        if (data.getId() == null)
                            JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it has no id.");
                        else
                            JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it is deleted.");
                    } else if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } finally {
                try {
                    if (bundleStream != null)
                        bundleStream.close();
                } catch (IOException x) {
                } finally {
                    try {
                        if (stream != null)
                            stream.close();
                    } catch (IOException x) {
                    }
                }
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) TemplateReaderWriter(org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 TemplatePersistenceData (org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData)1 TemplateReaderWriter (org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter)1