PHP obfuscator gets it's ignored identifiers from an "obfuscator.xml" file
authorkhartlage <khartlage>
Wed, 30 Jul 2003 20:24:55 +0000 (20:24 +0000)
committerkhartlage <khartlage>
Wed, 30 Jul 2003 20:24:55 +0000 (20:24 +0000)
21 files changed:
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/TemplateSet.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/Templates.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPObfuscatorAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/IFilter.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnoreSet.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnores.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.properties [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPIdentifier.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/PHPObfuscatorMover.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/default-obfuscator.xml [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSyntaxRdr.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormattingStrategy.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPConstant.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPFunction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeyword.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPType.java

index 8f88d1a..7e17912 100644 (file)
@@ -36,7 +36,7 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 /**
- * <code>TemplateSet</code> manages a collection of templates and makes them
+ * <code>ObfuscatorIgnoreSet</code> manages a collection of templates and makes them
  * persistent.
  */
 public class TemplateSet {
@@ -228,14 +228,14 @@ public class TemplateSet {
        private static void throwReadException(Throwable t) throws CoreException {
     PHPeclipsePlugin.log(t);
 //             IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-//                     TemplateMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
+//                     ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
 //             throw new JavaUIException(status);
        }
        
        private static void throwWriteException(Throwable t) throws CoreException {
     PHPeclipsePlugin.log(t);
 //             IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-//                     TemplateMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
+//                     ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
 //             throw new JavaUIException(status);
        }
 
index 03d47d4..84cddff 100644 (file)
@@ -14,7 +14,7 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.dialogs.ErrorDialog;
 
 /**
- * <code>Templates</code> gives access to the available templates.
+ * <code>ObfuscatorIgnores</code> gives access to the available templates.
  */
 public class Templates extends TemplateSet {
 
index c250488..d719efe 100644 (file)
@@ -262,7 +262,7 @@ public class TemplatePreferencePage
     fPatternViewer = createViewer(parent);
 
     //         fFormatButton= new Button(parent, SWT.CHECK);
-    //         fFormatButton.setText(TemplateMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$
+    //         fFormatButton.setText(ObfuscatorMessages.getString("TemplatePreferencePage.use.code.formatter")); //$NON-NLS-1$
     //        GridData gd1= new GridData();
     //        gd1.horizontalSpan= 2;
     //        fFormatButton.setLayoutData(gd1);
index c4867d7..98abc27 100644 (file)
@@ -150,7 +150,7 @@ public class BuiltInProposal implements IPHPCompletionProposal {
    */
   public String getDisplayString() {
     return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ //$NON-NLS-1$
-    //         return fTemplate.getName() + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$
+    //         return fTemplate.getName() + ObfuscatorMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$
   }
 
   /*
@@ -213,7 +213,7 @@ public class BuiltInProposal implements IPHPCompletionProposal {
   private void handleException(CoreException e) {
     Shell shell = fViewer.getTextWidget().getShell();
     PHPeclipsePlugin.log(e);
-    //         ExceptionHandler.handle(e, shell, TemplateMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
+    //         ExceptionHandler.handle(e, shell, ObfuscatorMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
   }
 
   /*
index ddf59dc..c6ca983 100644 (file)
@@ -151,7 +151,7 @@ public class IdentifierProposal implements IPHPCompletionProposal {
    */
   public String getDisplayString() {
     return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ //$NON-NLS-1$
-    //         return fTemplate.getName() + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$
+    //         return fTemplate.getName() + ObfuscatorMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$
   }
 
   /*
@@ -217,7 +217,7 @@ public class IdentifierProposal implements IPHPCompletionProposal {
   private void handleException(CoreException e) {
     Shell shell = fViewer.getTextWidget().getShell();
     PHPeclipsePlugin.log(e);
-    //         ExceptionHandler.handle(e, shell, TemplateMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
+    //         ExceptionHandler.handle(e, shell, ObfuscatorMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
   }
 
   /*
index d261dc7..cf5c204 100644 (file)
@@ -213,7 +213,7 @@ public class TemplateProposal implements IPHPCompletionProposal {
        private void handleException(CoreException e) {
                Shell shell= fViewer.getTextWidget().getShell();
     PHPeclipsePlugin.log(e);
-//             ExceptionHandler.handle(e, shell, TemplateMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
+//             ExceptionHandler.handle(e, shell, ObfuscatorMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
        }
 
        /*
index 222b3a8..1a24c29 100644 (file)
@@ -19,10 +19,10 @@ import net.sourceforge.phpeclipse.mover.DefaultFilter;
 import net.sourceforge.phpeclipse.mover.DirectoryWalker;
 import net.sourceforge.phpeclipse.mover.IFilter;
 import net.sourceforge.phpeclipse.mover.IMover;
+import net.sourceforge.phpeclipse.mover.obfuscator.ObfuscatorIgnores;
 import net.sourceforge.phpeclipse.mover.obfuscator.PHPAnalyzer;
-import net.sourceforge.phpeclipse.mover.obfuscator.PHPIdentifier;
 import net.sourceforge.phpeclipse.mover.obfuscator.PHPObfuscatorMover;
-import net.sourceforge.phpeclipse.preferences.IObfuscatorPreferences;
+import net.sourceforge.phpeclipse.preferences.ProjectProperties;
 import net.sourceforge.phpeclipse.views.PHPConsole;
 
 import org.eclipse.core.resources.IFile;
@@ -39,54 +39,22 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 
+/**
+ * 
+ * @author khartlage
+ *
+ * Run the PHP Obfuscator 
+ */
 public class PHPObfuscatorAction implements IObjectActionDelegate {
-  private static String[] PREDEFINED_PHP_VARIABLES =
-  {
-    "$this",
-    "$AUTH_TYPE",
-    "$CONTENT_LENGTH",
-    "$CONTENT_TYPE",
-    "$GATEWAY_INTERFACE",
-    "$GLOBALS",
-    "$HTTP_ACCEPT",
-    "$HTTP_COOKIE",
-    "$HTTP_COOKIE_VARS",
-    "$HTTP_POST_VARS",
-    "$HTTP_REFERER",
-    "$HTTP_USER_AGENT",
-    "$PATH_INFO",
-    "$PATH_TRANSLATED",
-    "$PHP_AUTH_PW",
-    "$PHP_AUTH_USER",
-    "$PHP_ERRORMSG",
-    "$PHP_SELF",
-    "$QUERY_STRING",
-    "$REMOTE_ADDR",
-    "$REMOTE_HOST",
-    "$REMOTE_IDENT",
-    "$REMOTE_USER",
-    "$REQUEST_METHOD",
-    "$SCRIPT_NAME",
-    "$SERVER_NAME",
-    "$SERVER_PORT",
-    "$SERVER_PROTOCOL",
-    "$SERVER_SOFTWARE"
-  };
+
   private IWorkbenchPart workbenchPart;
   /**
-   * Constructor for Action1.
+   * Constructor for PHPObfuscatorAction.
    */
   public PHPObfuscatorAction() {
     super();
   }
 
-  /**
-   * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
-   */
-  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-    workbenchPart = targetPart;
-  }
-
   public void run(IAction action) {
     ISelectionProvider selectionProvider = null;
     selectionProvider = workbenchPart.getSite().getSelectionProvider();
@@ -95,7 +63,11 @@ public class PHPObfuscatorAction implements IObjectActionDelegate {
     selection = (StructuredSelection) selectionProvider.getSelection();
     PHPConsole console = PHPConsole.getInstance();
 
-    IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+    //   HashMap identifierMap = new HashMap(8096);
+    //   for (int i=0;i<PREDEFINED_PHP_VARIABLES.length;i++) {
+    //         identifierMap.put(PREDEFINED_PHP_VARIABLES[i], new PHPIdentifier(PREDEFINED_PHP_VARIABLES[i],PHPIdentifier.VARIABLE) );
+    //   }
+    HashMap identifierMap = null;
 
     Shell shell = null;
     Iterator iterator = null;
@@ -106,28 +78,44 @@ public class PHPObfuscatorAction implements IObjectActionDelegate {
 
       // is it a resource
       if (obj instanceof IResource) {
+
         IResource resource = (IResource) obj;
         IProject proj = resource.getProject();
         String sourcePath;
-      //  String publishPath = "c:\\temp";
+
+        if (identifierMap == null) {
+          IPreferenceStore store =
+            PHPeclipsePlugin.getDefault().getPreferenceStore();
+          ObfuscatorIgnores ignore = new ObfuscatorIgnores(proj);
+          identifierMap = ignore.getIdentifierMap();
+        }
+
         String publishPath;
         try {
-          publishPath = proj.getPersistentProperty(IObfuscatorPreferences.PUBLISH_PROPERTY_NAME);
-        } catch (CoreException e) {
+          ProjectProperties properties = new ProjectProperties(proj);
+          publishPath = properties.getPublish();
+        } catch (CoreException e1) {
           return;
+          //                                   e1.printStackTrace();
         }
-        HashMap identifierMap = new HashMap(8096);
-        for (int i=0;i<PREDEFINED_PHP_VARIABLES.length;i++) {
-          identifierMap.put(PREDEFINED_PHP_VARIABLES[i], new PHPIdentifier(PREDEFINED_PHP_VARIABLES[i],PHPIdentifier.VARIABLE) );
-        }
-        DefaultFilter[] filter = {
-          IFilter.PHP_FILTER,
-          IFilter.DEFAULT_FILTER,
-        };
+        //        try {
+        //          publishPath = proj.getPersistentProperty(IObfuscatorPreferences.PUBLISH_PROPERTY_NAME);
+        //        } catch (CoreException e) {
+        //          return;
+        //        }
+
+        DefaultFilter[] filter =
+          { IFilter.PHP_FILTER, IFilter.DEFAULT_FILTER, };
         IMover[] mover =
           {
-            new PHPAnalyzer(PHPConsole.getInstance(), new Scanner(false, false), identifierMap),
-            new PHPObfuscatorMover(PHPConsole.getInstance(), new Scanner(true, true), identifierMap)};
+            new PHPAnalyzer(
+              PHPConsole.getInstance(),
+              new Scanner(false, false),
+              identifierMap),
+            new PHPObfuscatorMover(
+              PHPConsole.getInstance(),
+              new Scanner(true, true),
+              identifierMap)};
         DirectoryWalker walker = new DirectoryWalker(mover, filter);
         switch (resource.getType()) {
           case IResource.PROJECT :
@@ -165,4 +153,11 @@ public class PHPObfuscatorAction implements IObjectActionDelegate {
   public void selectionChanged(IAction action, ISelection selection) {
   }
 
+  /**
+   * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+   */
+  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+    workbenchPart = targetPart;
+  }
+
 }
index 77b7f3f..15cfc03 100644 (file)
@@ -6,7 +6,7 @@ import java.io.File;
  * @author khartlage
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnoreSet.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnoreSet.java
new file mode 100644 (file)
index 0000000..bd853fc
--- /dev/null
@@ -0,0 +1,314 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package net.sourceforge.phpeclipse.mover.obfuscator;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.Serializer;
+import org.apache.xml.serialize.SerializerFactory;
+import org.eclipse.core.runtime.CoreException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * <code>ObfuscatorIgnoreSet</code> manages a collection of templates and makes them
+ * persistent.
+ */
+public class ObfuscatorIgnoreSet {
+
+       //      private static class TemplateComparator implements Comparator {
+       //              public int compare(Object arg0, Object arg1) {
+       //                      if (arg0 == arg1)
+       //                              return 0;
+       //                      
+       //                      if (arg0 == null)
+       //                              return -1;
+       //                              
+       //                      Template template0= (Template) arg0;
+       //                      Template template1= (Template) arg1;
+       //                      
+       //                      return template0.getName().compareTo(template1.getName());
+       //              }
+       //      }
+
+       private static final String TEMPLATE_TAG = "ignore"; //$NON-NLS-1$
+       //      private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
+       //      private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
+       //      private static final String CONTEXT_ATTRIBUTE= "context"; //$NON-NLS-1$
+       //      private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
+
+       //      private List fTemplates= new ArrayList();
+       private HashMap fIdentifierMap = new HashMap();
+       //      private Comparator fTemplateComparator= new TemplateComparator();
+       //      private Template[] fSortedTemplates= new Template[0];
+
+       /**
+        * Convenience method for reading templates from a file.
+        * 
+        * @see #addFromStream(InputStream)
+        */
+       public void addFromFile(File file) throws CoreException {
+               InputStream stream = null;
+
+               try {
+                       stream = new FileInputStream(file);
+                       addFromStream(stream);
+
+               } catch (IOException e) {
+                       throwReadException(e);
+
+               } finally {
+                       try {
+                               if (stream != null)
+                                       stream.close();
+                       } catch (IOException e) {
+                       }
+               }
+       }
+
+       /**
+        * Reads templates from a XML stream and adds them to the template set.
+        */
+       public void addFromStream(InputStream stream) throws CoreException {
+               try {
+                       DocumentBuilderFactory factory =
+                               DocumentBuilderFactory.newInstance();
+                       DocumentBuilder parser = factory.newDocumentBuilder();
+                       Document document = parser.parse(new InputSource(stream));
+                       NodeList elements = document.getElementsByTagName(TEMPLATE_TAG);
+
+                       int count = elements.getLength();
+                       for (int i = 0; i != count; i++) {
+                               Node node = elements.item(i);
+                               NamedNodeMap attributes = node.getAttributes();
+
+                               if (attributes == null)
+                                       continue;
+
+                               //                              String name= getAttributeValue(attributes, NAME_ATTRIBUTE);
+                               //                              String description= getAttributeValue(attributes, DESCRIPTION_ATTRIBUTE);
+                               //                              String context= getAttributeValue(attributes, CONTEXT_ATTRIBUTE);
+                               //                              Node enabledNode= attributes.getNamedItem(ENABLED_ATTRIBUTE);
+
+                               //                              if (name == null || description == null || context == null)
+                               //                                      throw new SAXException(ObfuscatorMessages.getString("TemplateSet.error.missing.attribute")); //$NON-NLS-1$
+
+                               //                              boolean enabled= true; //(enabledNode == null) || (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
+
+                               StringBuffer buffer = new StringBuffer();
+                               NodeList children = node.getChildNodes();
+                               for (int j = 0; j != children.getLength(); j++) {
+                                       String value = children.item(j).getNodeValue();
+                                       if (value != null)
+                                               buffer.append(value);
+                               }
+                               String pattern = buffer.toString().trim();
+                               fIdentifierMap.put(pattern, new PHPIdentifier(pattern, PHPIdentifier.VARIABLE) );
+                               //                              Template template= new Template(name, description, context, pattern);   
+                               //                              template.setEnabled(enabled);
+                               //                              add(template);
+                       }
+
+                       //                      sort();
+
+               } catch (ParserConfigurationException e) {
+                       throwReadException(e);
+               } catch (IOException e) {
+                       throwReadException(e);
+               } catch (SAXException e) {
+                       throwReadException(e);
+               }
+       }
+
+       private String getAttributeValue(NamedNodeMap attributes, String name) {
+               Node node = attributes.getNamedItem(name);
+
+               return node == null ? null : node.getNodeValue();
+       }
+
+       /**
+        * Convenience method for saving to a file.
+        * 
+        * @see #saveToStream(OutputStream)
+        */
+       public void saveToFile(File file) throws CoreException {
+               OutputStream stream = null;
+
+               try {
+                       stream = new FileOutputStream(file);
+                       saveToStream(stream);
+
+               } catch (IOException e) {
+                       throwWriteException(e);
+
+               } finally {
+                       try {
+                               if (stream != null)
+                                       stream.close();
+                       } catch (IOException e) {
+                       }
+               }
+       }
+
+       /**
+        * Saves the template set as XML.
+        */
+       public void saveToStream(OutputStream stream) throws CoreException {
+               try {
+                       DocumentBuilderFactory factory =
+                               DocumentBuilderFactory.newInstance();
+                       DocumentBuilder builder = factory.newDocumentBuilder();
+                       Document document = builder.newDocument();
+
+                       Node root = document.createElement("obfuscator"); // $NON-NLS-1$ //$NON-NLS-1$
+                       document.appendChild(root);
+                       Iterator iter = fIdentifierMap.keySet().iterator();
+                       while (iter.hasNext()) {
+                               //                      for (int i= 0; i != fTemplates.size(); i++) {
+                               //                              Template template= (Template) fTemplates.get(i);
+
+                               Node node = document.createElement("ignore"); // $NON-NLS-1$ //$NON-NLS-1$
+                               root.appendChild(node);
+
+                               //                              NamedNodeMap attributes= node.getAttributes();
+                               //                              
+                               //                              Attr name= document.createAttribute(NAME_ATTRIBUTE);
+                               //                              name.setValue(template.getName());
+                               //                              attributes.setNamedItem(name);
+                               //      
+                               //                              Attr description= document.createAttribute(DESCRIPTION_ATTRIBUTE);
+                               //                              description.setValue(template.getDescription());
+                               //                              attributes.setNamedItem(description);
+                               //      
+                               //                              Attr context= document.createAttribute(CONTEXT_ATTRIBUTE);
+                               //                              context.setValue(template.getContextTypeName());
+                               //                              attributes.setNamedItem(context);                       
+                               //
+                               //                              Attr enabled= document.createAttribute(ENABLED_ATTRIBUTE);
+                               //                              enabled.setValue(template.isEnabled() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
+                               //                              attributes.setNamedItem(enabled);
+
+                               Text pattern = document.createTextNode((String) iter.next());
+                               node.appendChild(pattern);
+                       }
+
+                       OutputFormat format = new OutputFormat();
+                       format.setPreserveSpace(true);
+                       Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format); //$NON-NLS-1$
+                       serializer.asDOMSerializer().serialize(document);
+
+               } catch (ParserConfigurationException e) {
+                       throwWriteException(e);
+               } catch (IOException e) {
+                       throwWriteException(e);
+               }
+       }
+
+       private static void throwReadException(Throwable t) throws CoreException {
+               PHPeclipsePlugin.log(t);
+               //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
+               //                      ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
+               //              throw new JavaUIException(status);
+       }
+
+       private static void throwWriteException(Throwable t) throws CoreException {
+               PHPeclipsePlugin.log(t);
+               //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
+               //                      ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
+               //              throw new JavaUIException(status);
+       }
+
+       /**
+        * Adds a template to the set.
+        */
+       //      public void add(Template template) {
+       //              if (exists(template))
+       //                      return; // ignore duplicate
+       //              
+       //              fTemplates.add(template);
+       //              sort();
+       //      }
+
+       //      private boolean exists(Template template) {
+       //              for (Iterator iterator = fTemplates.iterator(); iterator.hasNext();) {
+       //                      Template anotherTemplate = (Template) iterator.next();
+       //
+       //                      if (template.equals(anotherTemplate))
+       //                              return true;
+       //              }
+       //              
+       //              return false;
+       //      }
+       //      
+       //      /**
+       //       * Removes a template to the set.
+       //       */     
+       //      public void remove(Template template) {
+       //              fTemplates.remove(template);
+       //              sort();
+       //      }
+       //
+               /**
+                * Empties the set.
+                */             
+               public void clear() {
+                       fIdentifierMap.clear();
+       //              fTemplates.clear();
+       //              sort();
+               }
+       //      
+       //      /**
+       //       * Returns all templates.
+       //       */
+       //      public Template[] getTemplates() {
+       //              return (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
+       //      }
+
+       /**
+        * Returns all templates with a given name.
+        */
+       //      public Template[] getTemplates(String name) {
+       //              ArrayList res= new ArrayList();
+       //              for (Iterator iterator= fTemplates.iterator(); iterator.hasNext();) {
+       //                      Template curr= (Template) iterator.next();
+       //                      if (curr.getName().equals(name)) {
+       //                              res.add(curr);
+       //                      }
+       //              }
+       //              return (Template[]) res.toArray(new Template[res.size()]);
+       //      }       
+       //      
+       //      private void sort() {
+       //              fSortedTemplates= (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
+       //              Arrays.sort(fSortedTemplates, fTemplateComparator);
+       //      }
+
+       /**
+        * @return
+        */
+       public HashMap getIdentifierMap() {
+               return fIdentifierMap;
+       }
+
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnores.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorIgnores.java
new file mode 100644 (file)
index 0000000..ff888c8
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package net.sourceforge.phpeclipse.mover.obfuscator;
+
+import java.io.File;
+import java.io.InputStream;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.ErrorDialog;
+
+/**
+ * <code>ObfuscatorIgnores</code> gives access to the available templates.
+ */
+public class ObfuscatorIgnores extends ObfuscatorIgnoreSet {
+
+  private static final String DEFAULT_FILE = "default-obfuscator.xml"; //$NON-NLS-1$
+  private static final String TEMPLATE_FILE = "obfuscator.xml"; //$NON-NLS-1$
+
+  /** Singleton. */
+  private static ObfuscatorIgnores fgIgnores;
+       private IProject fProject;
+
+  public ObfuscatorIgnores(IProject project) {
+       fProject = project;
+    try {
+      File templateFile = getTemplateFile();
+      if (templateFile.exists()) {
+        addFromFile(templateFile);
+      } else {
+        addFromStream(getDefaultsAsStream());
+        saveToFile(templateFile);
+      }
+
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+      ErrorDialog.openError(null, ObfuscatorMessages.getString("Templates.error.title"), //$NON-NLS-1$
+      e.getMessage(), e.getStatus());
+
+      clear();
+    }
+  }
+  /**
+   * Returns an instance of templates.
+   */
+//  public static ObfuscatorIgnores getInstance() {
+//    if (fgIgnores == null)
+//      fgIgnores = create();
+//
+//    return fgIgnores;
+//  }
+//
+//  private static ObfuscatorIgnores create() {
+//    ObfuscatorIgnores templates = new ObfuscatorIgnores();
+//
+//    try {
+//      File templateFile = getTemplateFile();
+//      if (templateFile.exists()) {
+//        templates.addFromFile(templateFile);
+//      } else {
+//        templates.addFromStream(getDefaultsAsStream());
+//        templates.saveToFile(templateFile);
+//      }
+//
+//    } catch (CoreException e) {
+//      PHPeclipsePlugin.log(e);
+//      ErrorDialog.openError(null, ObfuscatorMessages.getString("Templates.error.title"), //$NON-NLS-1$
+//      e.getMessage(), e.getStatus());
+//
+//      templates.clear();
+//    }
+//
+//    return templates;
+//  }
+
+  /**
+   * Resets the template set.
+   */
+  public void reset() throws CoreException {
+    clear();
+    addFromFile(getTemplateFile());
+  }
+
+  /**
+   * Resets the template set with the default templates.
+   */
+  public void restoreDefaults() throws CoreException {
+    clear();
+    addFromStream(getDefaultsAsStream());
+  }
+
+  /**
+   * Saves the template set.
+   */
+  public void save() throws CoreException {
+    saveToFile(getTemplateFile());
+  }
+
+  private InputStream getDefaultsAsStream() {
+    return ObfuscatorIgnores.class.getResourceAsStream(DEFAULT_FILE);
+  }
+
+  private File getTemplateFile() {
+    IPath path = fProject.getLocation(); 
+    // PHPeclipsePlugin.getDefault().getStateLocation();
+    path = path.append(TEMPLATE_FILE);
+
+    return path.toFile();
+  }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.java
new file mode 100644 (file)
index 0000000..2d6e1c2
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package net.sourceforge.phpeclipse.mover.obfuscator;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class ObfuscatorMessages {
+
+       private static final String RESOURCE_BUNDLE= ObfuscatorMessages.class.getName();
+       private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+       private ObfuscatorMessages() {
+       }
+
+       public static String getString(String key) {
+               try {
+                       return fgResourceBundle.getString(key);
+               } catch (MissingResourceException e) {
+                       return '!' + key + '!';
+               }
+       }
+       
+       /**
+        * Gets a string from the resource bundle and formats it with the argument
+        * 
+        * @param key   the string used to get the bundle value, must not be null
+        */
+       public static String getFormattedString(String key, Object arg) {
+               return MessageFormat.format(getString(key), new Object[] { arg });
+       }
+
+
+       /**
+        * Gets a string from the resource bundle and formats it with arguments
+        */     
+       public static String getFormattedString(String key, Object[] args) {
+               return MessageFormat.format(getString(key), args);
+       }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/ObfuscatorMessages.properties
new file mode 100644 (file)
index 0000000..3c085d0
--- /dev/null
@@ -0,0 +1,94 @@
+#########################################
+# (c) Copyright IBM Corp. 2000, 2001.
+# All Rights Reserved.
+#########################################
+
+# preference page
+TemplatePreferencePage.error.import=Failed to import templates.
+TemplatePreferencePage.error.export=Failed to export templates.
+TemplatePreferencePage.error.read.title=Reading Templates
+TemplatePreferencePage.error.write.title=Reading Templates
+TemplatePreferencePage.message=&Create, edit or remove templates:
+TemplatePreferencePage.title=Templates
+
+TemplatePreferencePage.new=&New...
+TemplatePreferencePage.edit=&Edit...
+TemplatePreferencePage.import=&Import...
+TemplatePreferencePage.export=E&xport...
+TemplatePreferencePage.export.all=Ex&port All...
+TemplatePreferencePage.remove=&Remove
+TemplatePreferencePage.enable.all=Ena&ble All
+TemplatePreferencePage.disable.all=Di&sable All
+TemplatePreferencePage.editor=Template
+
+TemplatePreferencePage.column.name=Name
+TemplatePreferencePage.column.context=Context
+TemplatePreferencePage.column.description=Description
+
+TemplatePreferencePage.use.code.formatter=Use Code &Formatter
+
+TemplatePreferencePage.import.title=Importing Templates
+TemplatePreferencePage.import.extension=*.xml
+
+TemplatePreferencePage.export.title=Exporting {0} Templates
+TemplatePreferencePage.export.filename=templates.xml
+TemplatePreferencePage.export.extension=*.xml
+
+TemplatePreferencePage.export.exists.title=Exporting Templates
+TemplatePreferencePage.export.exists.message={0} already exists.\nDo you want to replace it?
+
+TemplatePreferencePage.question.create.new.title=Edit Template
+TemplatePreferencePage.question.create.new.message=The name of the template was changed.\nDo you want to create a new template?
+
+TemplatePreferencePage.preview=Preview:
+
+# edit template dialog
+EditTemplateDialog.error.noname=Template name must not be empty.
+EditTemplateDialog.error.adjacent.variables=Template pattern has adjacent variables.
+EditTemplateDialog.title.new=New Template
+EditTemplateDialog.title.edit=Edit Template
+
+EditTemplateDialog.name=&Name:
+EditTemplateDialog.description=&Description:
+EditTemplateDialog.context=&Context:
+EditTemplateDialog.pattern=&Pattern:
+EditTemplateDialog.insert.variable=Insert &Variable...
+
+EditTemplateDialog.undo=&Undo@Ctrl+Z
+EditTemplateDialog.cut=Cu&t@Ctrl+X
+EditTemplateDialog.copy=&Copy@Ctrl+C
+EditTemplateDialog.paste=&Paste@Ctrl+V
+EditTemplateDialog.select.all=Select &All@Ctrl+A
+EditTemplateDialog.content.assist=Insert &Variable...@Ctrl+Space
+
+# template variable dialog
+TemplateVariableDialog.title=Select a template variable.
+TemplateVariableDialog.column.name=Name
+TemplateVariableDialog.column.description=Description
+TemplateVariableDialog.insert=&Insert
+
+TemplateVariableProposal.error.title=Error applying template variable proposal
+TemplateVariableProcessor.error.title=Error creating template variable proposals
+
+# template set
+TemplateSet.error.read=Error occurred while reading templates.
+TemplateSet.error.write=Error occurred while writing templates.
+
+# templates
+Templates.error.title=Error accessing templates.
+Templates.error.read=Error occurred while reading templates.
+Templates.error.write=Error occurred while writing templates.
+
+# template engine
+TemplateEngine.error.title=Could not create template proposals.
+
+# template proposal
+TemplateProposal.delimiter=\ - 
+
+# template evaluator
+TemplateEvaluator.error.title=Template Evaluation Error
+
+# template translator
+TemplateTranslator.error.incomplete.variable=Template has incomplete variables.
+TemplateTranslator.error.invalid.identifier=Template has invalid variable identifiers.
+TemplateSet.error.missing.attribute=Missing required attribute
index 1f391dd..a097a2e 100644 (file)
@@ -4,7 +4,7 @@ package net.sourceforge.phpeclipse.mover.obfuscator;
  * @author khartlage
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
index 19c439b..9df47df 100644 (file)
@@ -8,8 +8,8 @@ import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+//import java.security.MessageDigest;
+//import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -30,7 +30,7 @@ public class PHPObfuscatorMover extends DefaultMover implements ITerminalSymbols
 
   private Scanner fScanner;
   private int fToken;
-  private MessageDigest fAlgorithm;
+ // private MessageDigest fAlgorithm;
   private int fCounter;
 
   protected HashMap fIdentifierMap;
@@ -49,11 +49,11 @@ public class PHPObfuscatorMover extends DefaultMover implements ITerminalSymbols
     this.fScanner = scanner;
     this.fIdentifierMap = identifierMap;
     this.fCounter = 0;
-    try {
-      this.fAlgorithm = MessageDigest.getInstance("MD5");
-    } catch (NoSuchAlgorithmException e) {
-      System.out.println(e.toString());
-    }
+//    try {
+//      this.fAlgorithm = MessageDigest.getInstance("MD5");
+//    } catch (NoSuchAlgorithmException e) {
+//      System.out.println(e.toString());
+//    }
   }
 
   /**
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/default-obfuscator.xml b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/mover/obfuscator/default-obfuscator.xml
new file mode 100644 (file)
index 0000000..7800312
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<obfuscator>
+    <ignore>$this</ignore>
+    <ignore>$_SERVER</ignore>
+    <ignore>$AUTH_TYPE</ignore>
+    <ignore>$CONTENT_LENGTH</ignore>
+    <ignore>$CONTENT_TYPE</ignore>
+    <ignore>$GATEWAY_INTERFACE</ignore>
+    <ignore>$GLOBALS</ignore>
+    <ignore>$HTTP_ACCEPT</ignore>
+    <ignore>$HTTP_COOKIE</ignore>
+    <ignore>$HTTP_COOKIE_VARS</ignore>
+    <ignore>$HTTP_POST_VARS</ignore>
+    <ignore>$HTTP_REFERER</ignore>
+    <ignore>$HTTP_USER_AGENT</ignore>
+    <ignore>$PATH_INFO</ignore>
+    <ignore>$PATH_TRANSLATED</ignore>
+    <ignore>$PHP_AUTH_PW</ignore>
+    <ignore>$PHP_AUTH_USER</ignore>
+    <ignore>$PHP_ERRORMSG</ignore>
+    <ignore>$PHP_SELF</ignore>
+    <ignore>$QUERY_STRING</ignore>
+    <ignore>$REMOTE_ADDR</ignore>
+    <ignore>$REMOTE_HOST</ignore>
+    <ignore>$REMOTE_IDENT</ignore>
+    <ignore>$REMOTE_USER</ignore>
+    <ignore>$REQUEST_METHOD</ignore>
+    <ignore>$SCRIPT_NAME</ignore>
+    <ignore>$SERVER_NAME</ignore>
+    <ignore>$SERVER_PORT</ignore>
+    <ignore>$SERVER_PROTOCOL</ignore>
+    <ignore>$SERVER_SOFTWARE</ignore>
+</obfuscator>
\ No newline at end of file
index 20f6404..a9b162e 100644 (file)
@@ -298,14 +298,14 @@ public class PHPSyntaxRdr {
        private static void throwReadException(Throwable t) throws CoreException {
                PHPeclipsePlugin.log(t);
                //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-               //                      TemplateMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
+               //                      ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
                //              throw new JavaUIException(status);
        }
 
        private static void throwWriteException(Throwable t) throws CoreException {
                PHPeclipsePlugin.log(t);
                //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-               //                      TemplateMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
+               //                      ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
                //              throw new JavaUIException(status);
        }
 
index a57fd08..17d4095 100644 (file)
@@ -13,7 +13,7 @@ import org.eclipse.jface.text.source.SourceViewer;
  * @author chrisl
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
index 6e09389..6f5b1f9 100644 (file)
@@ -4,7 +4,7 @@ package net.sourceforge.phpeclipse.phpeditor.php;
  * @author Choochter
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
index be5fb49..4bdbca8 100644 (file)
@@ -4,7 +4,7 @@ package net.sourceforge.phpeclipse.phpeditor.php;
  * @author Choochter
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
index a478a01..f12544a 100644 (file)
@@ -4,7 +4,7 @@ package net.sourceforge.phpeclipse.phpeditor.php;
  * @author Choochter
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */
index 9880c6e..701ba82 100644 (file)
@@ -4,7 +4,7 @@ package net.sourceforge.phpeclipse.phpeditor.php;
  * @author Choochter
  *
  * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
+ * Window>Preferences>Java>ObfuscatorIgnores.
  * To enable and disable the creation of type comments go to
  * Window>Preferences>Java>Code Generation.
  */