2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpeclipse.mover.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$
23 private static final String TEMPLATE_FILE = "obfuscator.xml"; //$NON-NLS-1$
26 private static ObfuscatorIgnores fgIgnores;
27 private IProject fProject;
29 public ObfuscatorIgnores(IProject project) {
32 File templateFile = getTemplateFile();
33 if (templateFile.exists()) {
34 addFromFile(templateFile);
36 addFromStream(getDefaultsAsStream());
37 saveToFile(templateFile);
40 } catch (CoreException e) {
41 PHPeclipsePlugin.log(e);
42 ErrorDialog.openError(null, ObfuscatorMessages.getString("Obfuscator.error.title"), //$NON-NLS-1$
43 e.getMessage(), e.getStatus());
49 * Returns an instance of templates.
51 // public static ObfuscatorIgnores getInstance() {
52 // if (fgIgnores == null)
53 // fgIgnores = create();
58 // private static ObfuscatorIgnores create() {
59 // ObfuscatorIgnores templates = new ObfuscatorIgnores();
62 // File templateFile = getTemplateFile();
63 // if (templateFile.exists()) {
64 // templates.addFromFile(templateFile);
66 // templates.addFromStream(getDefaultsAsStream());
67 // templates.saveToFile(templateFile);
70 // } catch (CoreException e) {
71 // PHPeclipsePlugin.log(e);
72 // ErrorDialog.openError(null, ObfuscatorMessages.getString("Templates.error.title"), //$NON-NLS-1$
73 // e.getMessage(), e.getStatus());
82 * Resets the template set.
84 public void reset() throws CoreException {
86 addFromFile(getTemplateFile());
90 * Resets the template set with the default templates.
92 public void restoreDefaults() throws CoreException {
94 addFromStream(getDefaultsAsStream());
98 * Saves the template set.
100 public void save() throws CoreException {
101 saveToFile(getTemplateFile());
104 private InputStream getDefaultsAsStream() {
105 return ObfuscatorIgnores.class.getResourceAsStream(DEFAULT_FILE);
108 private File getTemplateFile() {
109 IPath path = fProject.getLocation();
110 // PHPeclipsePlugin.getDefault().getStateLocation();
111 path = path.append(TEMPLATE_FILE);
113 return path.toFile();