下面列出了怎么用org.eclipse.jface.text.templates.persistence.TemplateReaderWriter的API类实例代码及写法,或者点击链接到github查看源代码。
@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.getMessage(), e);
}
}
/**
* 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);
}
}
}
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;
}