Java 类org.eclipse.jface.text.templates.persistence.TemplateReaderWriter 实例源码

项目:bts    文件:XtextTemplateStore.java   
@Override
protected void loadContributedTemplates() throws IOException {
    if (res==null)
        return;
    TemplateReaderWriter reader = new TemplateReaderWriter();
    InputStream openStream = null;
    try {
        openStream = res.openStream();
        try {
            TemplatePersistenceData[] read = reader.read(openStream, null);
            for (TemplatePersistenceData templatePersistenceData : read) {
                internalAdd(templatePersistenceData);
            }
        } finally {
            openStream.close();
        }
    } catch (IOException e) {
        log.error(e);
    }
}
项目:eclipse-silverstripedt    文件:SilverStripeTemplateStore.java   
/**
 * Saves the templates to the preferences.
 *
 * @throws IOException if the templates cannot be written
 */
public void save() throws IOException {
    ArrayList custom= new ArrayList();
    List<TemplatePersistenceData> fTemplates=Arrays.asList(this.getTemplateData(true));
    for (Iterator it= fTemplates.iterator(); it.hasNext();) {
        TemplatePersistenceData data= (TemplatePersistenceData) it.next();
        if (data.isCustom() && !(data.isUserAdded() && data.isDeleted())) // don't save deleted user-added templates
            custom.add(data);
    }

    StringWriter output= new StringWriter();
    TemplateReaderWriter writer= new SilverStripeTemplateReaderWriter();
    writer.save((TemplatePersistenceData[]) custom.toArray(new TemplatePersistenceData[custom.size()]), output);

    this.stopListeningForPreferenceChanges();
    try {
        fPreferenceStore.setValue(fKey, output.toString());
        if (fPreferenceStore instanceof IPersistentPreferenceStore)
            ((IPersistentPreferenceStore)fPreferenceStore).save();
    } finally {
        this.startListeningForPreferenceChanges();
    }
}
项目:dsl-devkit    文件:ConfigurableTemplateStore.java   
/**
 * Contribute templates defined in file with the give URL.
 * 
 * @param templates
 *          the URL of the file with templates
 */
private void addTemplatesFromFile(final URL templates) {
  if (templates != null) {
    TemplateReaderWriter reader = new TemplateReaderWriter();
    try {
      InputStream openStream = templates.openStream();
      try {
        TemplatePersistenceData[] datas = reader.read(openStream, null);
        int templateCounter = 0;
        for (TemplatePersistenceData data : datas) {
          if (data.getId() == null) {
            templateCounter++;
            TemplatePersistenceData dataWithGenId = new TemplatePersistenceData(data.getTemplate(), data.isEnabled(), templates.getPath() + "." //$NON-NLS-1$
                + templateCounter);
            dataWithGenId.setDeleted(data.isDeleted());
            internalAdd(dataWithGenId);
          } else {
            // if contributed template has an id
            internalAdd(data);
          }
        }
      } finally {
        openStream.close();
      }
    } catch (IOException e) {
      LOG.error(e);
    }
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:ProjectTemplateStore.java   
public static boolean hasProjectSpecificTempates(IProject project) {
    String pref= new ProjectScope(project).getNode(JavaUI.ID_PLUGIN).get(KEY, null);
    if (pref != null && pref.trim().length() > 0) {
        Reader input= new StringReader(pref);
        TemplateReaderWriter reader= new TemplateReaderWriter();
        TemplatePersistenceData[] datas;
        try {
            datas= reader.read(input);
            return datas.length > 0;
        } catch (IOException e) {
            // ignore
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProjectTemplateStore.java   
public static boolean hasProjectSpecificTempates(IProject project) {
    String pref= new ProjectScope(project).getNode(JavaUI.ID_PLUGIN).get(KEY, null);
    if (pref != null && pref.trim().length() > 0) {
        Reader input= new StringReader(pref);
        TemplateReaderWriter reader= new TemplateReaderWriter();
        TemplatePersistenceData[] datas;
        try {
            datas= reader.read(input);
            return datas.length > 0;
        } catch (IOException e) {
            // ignore
        }
    }
    return false;
}
项目:eclipse-silverstripedt    文件:SilverStripeTemplateStore.java   
private void loadCustomTemplates() throws IOException {
    String pref= fPreferenceStore.getString(fKey);
    if (pref != null && pref.trim().length() > 0) {
        Reader input= new StringReader(pref);
        TemplateReaderWriter reader= new SilverStripeTemplateReaderWriter();
        TemplatePersistenceData[] datas= reader.read(input);
        for (int i= 0; i < datas.length; i++) {
            TemplatePersistenceData data= datas[i];
            add(data);
        }
    }
}