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;
23 * <code>Templates</code> gives access to the available templates.
25 * @deprecated As of 3.0, replaced by
26 * {@link org.eclipse.jface.text.templates.persistence.TemplateStore}
28 public class Templates extends
29 net.sourceforge.phpdt.internal.corext.template.php.TemplateSet {
31 private static final String DEFAULT_FILE = "default-templates.xml"; //$NON-NLS-1$
33 private static final String TEMPLATE_FILE = "templates.xml"; //$NON-NLS-1$
35 private static final ResourceBundle fgResourceBundle = ResourceBundle
36 .getBundle(JavaTemplateMessages.class.getName());
39 private static Templates fgTemplates;
42 * Returns an instance of templates.
44 * @deprecated As of 3.0, replaced by
45 * {@link net.sourceforge.phpdt.internal.ui.JavaPlugin#getTemplateStore()}
47 public static Templates getInstance() {
48 if (fgTemplates == null)
49 fgTemplates = new Templates();
56 "template", PHPeclipsePlugin.getDefault().getTemplateContextRegistry()); //$NON-NLS-1$
60 private void create() {
63 File templateFile = getTemplateFile();
64 if (templateFile.exists()) {
65 addFromFile(templateFile, true, fgResourceBundle);
68 } catch (CoreException e) {
69 PHPeclipsePlugin.log(e);
76 * Resets the template set.
78 public void reset() throws CoreException {
80 addFromFile(getTemplateFile(), true, fgResourceBundle);
84 * Resets the template set with the default templates.
86 public void restoreDefaults() throws CoreException {
88 addFromStream(getDefaultsAsStream(), true, true, fgResourceBundle);
92 * Saves the template set.
94 public void save() throws CoreException {
95 saveToFile(getTemplateFile());
98 private static InputStream getDefaultsAsStream() {
99 return Templates.class.getResourceAsStream(DEFAULT_FILE);
102 private static File getTemplateFile() {
103 IPath path = PHPeclipsePlugin.getDefault().getStateLocation();
104 path = path.append(TEMPLATE_FILE);
106 return path.toFile();