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;
18 import net.sourceforge.phpeclipse.ui.WebUI;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
24 * <code>Templates</code> gives access to the available templates.
26 * @deprecated As of 3.0, replaced by
27 * {@link org.eclipse.jface.text.templates.persistence.TemplateStore}
29 public class Templates extends
30 net.sourceforge.phpdt.internal.corext.template.php.TemplateSet {
32 //private static final String DEFAULT_FILE = "default-templates.xml"; //$NON-NLS-1$
34 private static final String TEMPLATE_FILE = "templates.xml"; //$NON-NLS-1$
36 private static final ResourceBundle fgResourceBundle = ResourceBundle
37 .getBundle(JavaTemplateMessages.class.getName());
40 private static Templates fgTemplates;
43 * Returns an instance of templates.
45 * @deprecated As of 3.0, replaced by
46 * {@link net.sourceforge.phpdt.internal.ui.JavaPlugin#getTemplateStore()}
48 public static Templates getInstance() {
49 if (fgTemplates == null)
50 fgTemplates = new Templates();
57 "template", WebUI.getDefault().getTemplateContextRegistry()); //$NON-NLS-1$
61 private void create() {
64 File templateFile = getTemplateFile();
65 if (templateFile.exists()) {
66 addFromFile(templateFile, true, fgResourceBundle);
69 } catch (CoreException e) {
70 PHPeclipsePlugin.log(e);
77 * Resets the template set.
79 public void reset() throws CoreException {
81 addFromFile(getTemplateFile(), true, fgResourceBundle);
85 * Resets the template set with the default templates.
87 // public void restoreDefaults() throws CoreException {
89 // addFromStream(getDefaultsAsStream(), true, true, fgResourceBundle);
93 * Saves the template set.
95 // public void save() throws CoreException {
96 // saveToFile(getTemplateFile());
99 // private static InputStream getDefaultsAsStream() {
100 // return Templates.class.getResourceAsStream(DEFAULT_FILE);
103 private static File getTemplateFile() {
104 IPath path = PHPeclipsePlugin.getDefault().getStateLocation();
105 path = path.append(TEMPLATE_FILE);
107 return path.toFile();