2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpeclipse.obfuscator;
8 import java.io.InputStream;
10 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
12 import org.eclipse.core.resources.IProject;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.jface.dialogs.ErrorDialog;
18 * <code>ObfuscatorIgnores</code> gives access to the available templates.
20 public class ObfuscatorIgnores extends ObfuscatorIgnoreSet {
22 private static final String DEFAULT_FILE = "default-obfuscator.xml"; //$NON-NLS-1$
24 private static final String TEMPLATE_FILE = "obfuscator.xml"; //$NON-NLS-1$
27 //private static ObfuscatorIgnores fgIgnores;
29 private IProject fProject;
31 public ObfuscatorIgnores(IProject project) {
34 File templateFile = getTemplateFile();
35 if (templateFile.exists()) {
36 addFromFile(templateFile);
38 addFromStream(getDefaultsAsStream());
39 saveToFile(templateFile);
42 } catch (CoreException e) {
43 PHPeclipsePlugin.log(e);
44 ErrorDialog.openError(null, ObfuscatorMessages
45 .getString("Obfuscator.error.title"), //$NON-NLS-1$
46 e.getMessage(), e.getStatus());
53 * Returns an instance of templates.
55 // public static ObfuscatorIgnores getInstance() {
56 // if (fgIgnores == null)
57 // fgIgnores = create();
62 // private static ObfuscatorIgnores create() {
63 // ObfuscatorIgnores templates = new ObfuscatorIgnores();
66 // File templateFile = getTemplateFile();
67 // if (templateFile.exists()) {
68 // templates.addFromFile(templateFile);
70 // templates.addFromStream(getDefaultsAsStream());
71 // templates.saveToFile(templateFile);
74 // } catch (CoreException e) {
75 // PHPeclipsePlugin.log(e);
76 // ErrorDialog.openError(null,
77 // ObfuscatorMessages.getString("Templates.error.title"), //$NON-NLS-1$
78 // e.getMessage(), e.getStatus());
86 * Resets the template set.
88 public void reset() throws CoreException {
90 addFromFile(getTemplateFile());
94 * Resets the template set with the default templates.
96 public void restoreDefaults() throws CoreException {
98 addFromStream(getDefaultsAsStream());
102 * Saves the template set.
104 public void save() throws CoreException {
105 saveToFile(getTemplateFile());
108 private InputStream getDefaultsAsStream() {
109 return ObfuscatorIgnores.class.getResourceAsStream(DEFAULT_FILE);
112 private File getTemplateFile() {
113 IPath path = fProject.getFullPath();
114 // PHPeclipsePlugin.getDefault().getStateLocation();
115 path = path.append(TEMPLATE_FILE);
117 return path.toFile();