2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.template;
8 import java.io.InputStream;
10 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.jface.dialogs.ErrorDialog;
17 * <code>ObfuscatorIgnores</code> gives access to the available templates.
19 public class Templates extends TemplateSet {
21 private static final String DEFAULT_FILE= "default-templates.xml"; //$NON-NLS-1$
22 private static final String TEMPLATE_FILE= "templates.xml"; //$NON-NLS-1$
25 private static Templates fgTemplates;
28 * Returns an instance of templates.
30 public static Templates getInstance() {
31 if (fgTemplates == null)
32 fgTemplates= create();
37 private static Templates create() {
38 Templates templates= new Templates();
41 File templateFile= getTemplateFile();
42 if (templateFile.exists()) {
43 templates.addFromFile(templateFile);
45 templates.addFromStream(getDefaultsAsStream());
46 templates.saveToFile(templateFile);
49 } catch (CoreException e) {
50 PHPeclipsePlugin.log(e);
51 ErrorDialog.openError(null,
52 TemplateMessages.getString("Templates.error.title"), //$NON-NLS-1$
53 e.getMessage(), e.getStatus());
62 * Resets the template set.
64 public void reset() throws CoreException {
66 addFromFile(getTemplateFile());
70 * Resets the template set with the default templates.
72 public void restoreDefaults() throws CoreException {
74 addFromStream(getDefaultsAsStream());
78 * Saves the template set.
80 public void save() throws CoreException {
81 saveToFile(getTemplateFile());
84 private static InputStream getDefaultsAsStream() {
85 return Templates.class.getResourceAsStream(DEFAULT_FILE);
88 private static File getTemplateFile() {
89 IPath path= PHPeclipsePlugin.getDefault().getStateLocation();
90 path= path.append(TEMPLATE_FILE);