1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.corext.template.php;
14 import java.io.InputStream;
15 import java.util.ResourceBundle;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
24 * <code>Templates</code> gives access to the available templates.
26 * @deprecated As of 3.0, replaced by {@link org.eclipse.jface.text.templates.persistence.TemplateStore}
28 public class Templates extends net.sourceforge.phpdt.internal.corext.template.php.TemplateSet {
30 private static final String DEFAULT_FILE= "default-templates.xml"; //$NON-NLS-1$
31 private static final String TEMPLATE_FILE= "templates.xml"; //$NON-NLS-1$
32 private static final ResourceBundle fgResourceBundle= ResourceBundle.getBundle(JavaTemplateMessages.class.getName());
35 private static Templates fgTemplates;
38 * Returns an instance of templates.
40 * @deprecated As of 3.0, replaced by {@link net.sourceforge.phpdt.internal.ui.JavaPlugin#getTemplateStore()}
42 public static Templates getInstance() {
43 if (fgTemplates == null)
44 fgTemplates= new Templates();
50 super("template", PHPeclipsePlugin.getDefault().getTemplateContextRegistry()); //$NON-NLS-1$
55 private void create() {
58 File templateFile= getTemplateFile();
59 if (templateFile.exists()) {
60 addFromFile(templateFile, true, fgResourceBundle);
63 } catch (CoreException e) {
64 PHPeclipsePlugin.log(e);
71 * Resets the template set.
73 public void reset() throws CoreException {
75 addFromFile(getTemplateFile(), true, fgResourceBundle);
79 * Resets the template set with the default templates.
81 public void restoreDefaults() throws CoreException {
83 addFromStream(getDefaultsAsStream(), true, true, fgResourceBundle);
87 * Saves the template set.
89 public void save() throws CoreException {
90 saveToFile(getTemplateFile());
93 private static InputStream getDefaultsAsStream() {
94 return Templates.class.getResourceAsStream(DEFAULT_FILE);
97 private static File getTemplateFile() {
98 IPath path= PHPeclipsePlugin.getDefault().getStateLocation();
99 path= path.append(TEMPLATE_FILE);
101 return path.toFile();